<?php
/*
Copyright (C) 2008 by oscim   Project lossim  [ 15.09.2009, 09:17:59] @oscim
// kate: replace-trailing-space-save true; space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; word-wrap-marker-color #41C2A4
ENCODE UTF-8
*/
/**

  @package lossim <web http://www.lossim.org>
  @author oscim <mail dom@oscim.fr > <web http://www.oscim.fr>
  @class view_menu

*/

error_reporting(E_ALL);
class view_menu  extends db_menu{

    /**
      Tableau des fichier présents
    */
    var $files;

    /**
      constructeur
    */



  /**
    Construction de la vue , list des artcile avec liens pour affihce, modif etc ..
    @param
      @a string path table
  */
  public function draw_list($table){
    error_reporting(E_ALL);
    global $cstr;

    $this->calc_menu($table);
    $block_action_rub='';

    //! activation block menu non auto
    $config_menu=$this->add_tbl_php(ADD_PATH_ADMIN.TBL_MODULE_CONFIG_MENU_INC,'config_menu');
    $menu = ($config_menu['primaire']=='file') ? true : false ;

    require_once (ADD_PATH_ADMIN.REP_LIB_PARTAGE .'class.lum.php');

    function line_file($data,$i){
      return $data['line'];
    }
    $i=0;

      foreach( $this->db_m()/*$cstr->_call('db_menu','db_m')*/ as $k => $v) {
          $f=$v; $i++;
// print_r($v);
          $block_action_rub=' <a class="button item " href="'._FILENAME_MENU.'?table='.$this->table.'&amp;mID='.$f['id'].'&amp;action=edit">Modifier</a> '
//                             .tep_links('btsupp',_FILENAME_MODIFIER_UN_FICHIER."?cat=".$k."&amp;action=del",BT_SUPP,BT_SUPP, false,'', '',' class=" del  button item"  onclick="if(confirm(\''.JS_ALERT_SUPP.'\')){return true;} else { return false;}"',2)
                            .' <a class="button item " href="'.tep_url_link('', true, true,$f['href']  ).'">'.BT_VIEW.'</a> ';


          $list[]['line']= php_f_checkbox('act_g['.$i.']', $f['id'], false).'</td>'
                    .'<td>'.NewFct('img_etat_active',false, $this->table,'menu_auto', $f['id'],'etat',$f['etat'],false).'</a></td> '
                     .'<td>'.$f['tri'].'</td>'
                    .'<td> <a href="'._FILENAME_MENU.'?">'.$f['txt_'.LANG_POST].'</a>'
                      .' <div class="action view fils l" style="border:none;">'
                      .'<span style="display:inline-block;width:80%;">lien : '.tep_url_link('', true, true,$f['href'] ).'</span>'
                      .' </div>'
                      .' <div class="action view fils r" style="border:none;">'
                      .$block_action_rub
                      .'</div>'
                    .'</td>'
//                     .'<td>'
                    . ' <div class="action view fils r" style="border:none;">'
//                     .aff_etat_menu_primaire($k)
//                     .(!empty($f['keyrub']) ?' <a class="item titre" href="'._FILENAME_RUBRIQUES.'?cat='.ADD_PATH_ADMIN.REP_DATA.LANG_POST.'/'.$f['rub'].'"> Modifier </a> ': '')
    //                 .'<a class="item titre" href="'._FILENAME_MODIFIER_UN_FICHIER.'?file='.ADD_PATH_ADMIN.REP_DATA.LANG_POST.$f['rub'].$f['nom_complet'].'"> Supprimer </a> '
//                   .' <a class="item titre" href="'.URL_DU_SITE.'?'.LANG_POST.'/'.$f['rub'].'.html"> Afficher </a> '
                   .'</div>'
                   .'';

// 		$s.= sprintf($form_lg_tabl,$r['value']['id'],$r['value']['base'],aff_etat_rep($r['value']['id']),etat_rub_conf($r['value']['id']),aff_etat_menu_primaire($r['value']['id']),'');

      }


      $list=(isset($list) && is_array($list)) ? $list : array() ;
      $nb=(isset($_GET['row_by_page']))?$_GET['row_by_page']:5;
      $page=(isset($_GET['env']))?$_GET['env']:1;
      $objLum = new lum($page, 'line_file', $list, 0,$nb );
      $objLum->htmlHeader = '<table cellpadding="0" cellspacing="0" width="100%" border="1"><tr><th></th><th>'.T_ETAT.'</th><th>'.T_TRI.'</th><th>'.T_TEXT.'</th></tr>';
      $objLum->htmlLineStart = '<tr class="view parent">';
      $objLum->htmlColStart = '<td>';
      $objLum->htmlColEnd = '</td>';
      $objLum->htmlLineEnd = '</tr>';
      $objLum->htmlFooter = '</table>';
      $objLum->htmlLinksStart = '<span class="inline r" style="display:inline-block;padding-right:20px;line-height:30px;">';
      $objLum->htmlLinksEnd = '</span> ';


      /**
        Affichage
      */
      $s = (!isset($_GET['menu'])) ? "<h2>".EDITION_DE." PRIMAIRE </h2>" : "<h2>".EDITION_DE.strtoupper($_GET['menu'])."</h2>";

      $s.= $objLum->drawPage()."\n\n";
//       $s.= tep_form (_FILENAME_MENU,'','action=up_posts',"theform","POST",false,"" );
//       $s.= '<div class="actiongroup l" style="padding-left:30px;">'.input_select('exe_grp',$arryData,'','').' <input type="submit" value="'.BT_VALIDER.'" onclick="if(confirm(\''.TXT_CONFIRM.'\')) {return true;} else {return false; }"  /></div>';
//       $s.= '</form>';
      $s.= '<div class="split" style="clear:both; width:95%; height:25px;">';
      $s.= ' <span class="r">'.tep_row_by_page('','','').'</span>';
      $s.= $objLum->drawLinks('')."\n\n";
      $s.= '</div>';

      return $s;
    }


  /**
    Exe Up/add cat
    Recupere les _POST et renvoi vers fonction class parent
  */
//   public function  prepa_cat($post){
//     $this->up_cat(clean_for_name_files($post['rubrique']),clean_for_name_files($post['rubrique']),$post);
//   }


  /**
    Edit/add d'une rurbique
  @param
    @a string $cat la lcef de la rubrique
    @a bollean mode (edit (defaut)|add)
  */
  public function draw_form_edit($post,$mode=false){
      global $cstr;
//       print_r($post);
      //! Init def
      $p="<p>%1\$s</p>";
      $arryData=array(
          "true" =>FORM_MENU_ON,
          "false" =>FORM_MENU_OFF );
      $lg=appel_lang();
      $this->calc_menu($post['table']);
      if($mode !=false){
        $menu_key=count($this->db_m())+1;
        $menu=array('etat'=>'true',
                    'tri'=>10,
                    'rub'=>'true',
                    'rub_selected'=>'true',
                    'href'=>'');
      } else {
        $menu=$this->db_m($post['mID']);
        $menu_key=$post['mID'];
      }

      $s=NewFct('barre_h_box_ajax',RUBRIQUE,((!$mode) ? FORM_TITRE_MODIF_CONF_RUB : FORM_TITRE_ADD_CONF_MENU ),'',false);

      $format_ajax="<script type='text/javascript'> upload_ajax('%1\$s','%2\$s','%3\$s','%4\$s'); </script>";
      $h2="<h2>%1\$s</h2>";
      $p="<p>%1\$s</p>";


      $s=tep_form (_FILENAME_MENU,'','table='.$post['table'].'&mID='.$menu_key.'&action=up',"post","POST",false," onsubmit=\" montre('onload');\"" );
      $s.=NewFct('barre_h_box_ajax',MENU,FORM_TITRE_MODIF_CONF_MENU,'',false);

      $s.="<div id=\"form_ajax_txt_box_center\">\n";
      $s.=php_f_hidden("menu_key",$menu_key); //sprintf($p,php_f_textField("menu_key",50,50,$menu_key,'','disabled').php_f_hidden("menu_key",$menu_key));
      $s.=sprintf($p,php_f_combobox("etat",$arryData,$menu['etat'],'','','',Toolip(_MENU_ENTREE_ETAT_D))._MENU_ENTREE_ETAT.FORM_CHAMPS_OBLIGATOIRE);
      $s.=sprintf($p,php_f_textField("tri",50,10,$menu['tri'],'',Toolip(_MENU_ORDRE_TRIE_D))._MENU_ORDRE_TRIE.FORM_CHAMPS_OBLIGATOIRE);
      $s.=sprintf($p,php_f_combobox("rub",$arryData,$menu['rub'],'','','',Toolip(_MENU_ENTREE_RUB_D))._MENU_ENTREE_RUB.FORM_CHAMPS_OBLIGATOIRE);
      $s.=sprintf($p,php_f_combobox("rub_selected",$arryData,$menu['rub_selected'],'','','',Toolip(_MENU_ENTREE_RUB_SELECTED_D))._MENU_ENTREE_RUB_SELECTED.FORM_CHAMPS_OBLIGATOIRE);
      $s.='<p>'.option_deplie('link',_MENU_ENTREE_CHOIX_HREF,true).'</p>';
      $s.='<p id="link" style="display:none;">';
      $s.=NewFct('list_site_links_interne');
      $s.='</p>';
      $s.=sprintf($p,php_f_textField("href",50,150,$menu['href'],'', Toolip(_MENU_ENTREE_HREF_D).'  onfocus= "if (document.getElementById(\'url1\').value != \'\') {this.value = document.getElementById(\'url1\').value;}"')._MENU_ENTREE_HREF.FORM_CHAMPS_OBLIGATOIRE);

      while ($r=each($lg))  $s.=sprintf($p,php_f_textField("txt_".$r['key'],50,150,@$menu['txt_'.$r['key']],'',Toolip(_MENU_ENTREE_TXT_D))."(".$r['key'].")"._MENU_ENTREE_TXT);

      $s.=sprintf($p,php_f_textField("html",50,500,@$$menu['html'],'',Toolip(_MENU_ENTREE_HTML_D))._MENU_ENTREE_HTML);
      $s.=sprintf($p,FORM_CHAMPS_OBLIGATOIRE_TXT);
      $s.=sprintf($p,php_f_button('submit',BT_MODIF_MENU_ENTREE,'','').tep_bts_form('','','','','SB','','',true) );
      $s.="</form>\n";

      $s .="</div>\n";
      return $s;
  }


  /**
    Menu des menus fichier dispo
  */
  private function list_cat_m($params=''){
    $s='';
    foreach ($this->db_cat_m() as $k=>$v ) {
      $s .=' <a href="'._FILENAME_MENU.'?table='.$v['original'].'&amp;action=list" '.$params.'>'.$v['file'].'</a> ';
    }
    return $s;
  }


  /**
    Draw block action
  */
  public function draw_block_action(){

    $array[]= array( 'separator'=>array('div','h2','span'), 'text' => LIST_MENU );
    $array[]= array( 'separator'=>array('div','p','span'), 'text' => $this->list_cat_m() );


    return $array;
  }

  /**
    Exe Up/add cat
    Recupere les _POST et renvoi vers fonction class parent
  */
  public function  prepa_item($post){
    $this->up_item($post['mID'],$post);
  }



  /**
    Debugg
  */
  public function debugg(){
        print_r($this);
    }

}

?>