<?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
*/
/**
  Index des article et rubrique
  Affichage list sur admin

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

*/

error_reporting(E_ALL);
class view_rub  extends db_rubrique{

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

    /**
      constructeur
    */
/*
    function view_rub(){

    }*/

    /**
      Construction de la vue , list des artcile avec liens pour affihce, modif etc ..
    */
    /*public*/ function draw_list(){
      error_reporting(E_ALL);

      global $cstr;

      $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 ;
        $titre_menu=($menu) ? '<th>'.T_ETAT_MENU_PRIMAIRE.'</th>' : '';

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

      function line_file($data,$i){
        return $data['line'];
      }
    $i=0;
      foreach( $cstr->_call('db_rubrique','db_cat') as $k => $v) {
          $f=$v; $i++;

          if($k !='racine')
          $block_action_rub=' <a class="button item " href="'._FILENAME_RUBRIQUES.'?cat='.$k.'&amp;action=edit">Modifier</a> '
                            .tep_links('btsupp',_FILENAME_RUBRIQUES."?cat=".$k."&amp;action=del",BT_SUPP,BT_SUPP, false,'', '',' style="color:red; " onclick="if(confirm(\''.JS_ALERT_SUPP.'\')){return true;} else { return false;}"',2)
                            .' <a class="button item " href="'.tep_url_link('', true, true,LANG_POST.((!empty($f['key'])) ? '/'.$f['path'] : '') ).'">'.BT_VIEW.'</a> ';

          $list[]['line']= php_f_checkbox('act_g['.$i.']', $k, false).'</td><td>'.$f['key'].'</a> '
                    .'</td><td> <a href="'._FILENAME_RUBRIQUES.'?">'.(isset($f['titre_'.LANG_POST]) ?$f['titre_'.LANG_POST]  :$f['key']).'</a>'
                      .' <div class="action view fils l" style="border:none;">'
                      .'<span style="display:inline-block;width:80%;">lien : '.tep_url_link('', true, true,LANG_POST.((!empty($f['key'])) ? '/'.$f['path'] : '') ).'</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;">'
                    .$this->aff_etat_menu_primaire($k)

                   .'</div>'
                   .'</td>';
      }

      $list=(isset($list) && is_array($list)) ? $list : array() ;
//       $nb=(isset($_GET['row_by_page']))?$_GET['row_by_page']:5;
      $nb=value_in_session('row_by_page') ;
      $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_KEY_RUBRIQUE.'</th><th>'.T_NOM_RUBRIQUE.'</th>'.$titre_menu.'</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 = '<h3>'.LIST_RUB.'</h3>';

      $s.= $objLum->drawPage()."\n\n";
      $s.= tep_form (_FILENAME_RUBRIQUES,'','action=up_posts',"thefom","thefom",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('','','',$nb).'</span>';
      $s.= $objLum->drawLinks('')."\n\n";
      $s.= '</div>';

      return $s;
    }

  /**
  */
  public function aff_etat_menu_primaire($nom_rub){
    $f="<p>%1\$s</p>";
    $g='<nobr>';
    static $config_menu;

    if(!is_array($config_menu))include (ADD_PATH_ADMIN.TBL_MODULE_CONFIG_MENU_INC);

    if ($config_menu['primaire']=='auto') $g.=MENU_MODE_AUTO;
    else{
      $query ='SELECT * FROM '.TBL_MODULE_MENU_INC.' WHERE  id= '.$nom_rub;
      $result_sql=sql ('',ADD_PATH_ADMIN.TBL_MODULE_MENU_INC,'menu_auto',$query,'');
      $result=each($result_sql);

      if (isset($result['value']['id'])) {
              $e=$result['value']['etat'];
              if ($e =='true' || $e =='false')$g.=sprintf("<div style=\"float:left;\">%1\$s</div>",NewFct('img_etat_active',false, ADD_PATH_ADMIN.TBL_MODULE_MENU_INC,/*'menu_auto'*/'', $nom_rub,'etat',$e,false) );

              $g.=form_rapid ("rubriques.php","conf=menu&amp;mode=mod",'post','POST',false," class='vue_rapid' onsubmit=\" "
                      .ajax_forms("include/inc/edit_entree_menu.inc", "edit_entree_menu", " '$nom_rub', '".TBL_MODULE_MENU_INC."', 'rubriques.php', 'conf=menu&amp;mode=up' , '"._USER_PERSO__PREF_LANGUAGE."/menu',  true ","rubriques.php","include/lib/lib.menu.php","txt_base","'txt_base'",RETOUR)
                      ."\" ", BT_EDITER ,array("menu_key"=>$nom_rub)  );
      }
      else $g.=INACTIF_DS_MENU_PRIMAIRE.form_rapid ("rubriques.php","conf=menu&amp;mode=add",'post','POST',false," class='vue_rapid' onsubmit=\" montre('onload');\"", BT_ACTIVER ,array("menu_key"=>$nom_rub,"etat"=>'true',"tri"=>0, "rub"=>'true', "rub_selected"=>'false', "href"=>$nom_rub, "html"=>'')  );
      $g.='</nobr>';
    }
    return $g;
  }

  /**
    Exe Up/add cat
    Recupere les _POST et renvoi vers fonction class parent
    @param
      @a array retour des post
  */
  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
      formulaire de saisies
  @param
    @a string $cat la lcef de la rubrique
    @a bollean mode (edit (defaut)|add)
  */
  /*public*/ function draw_form_edit($cat='',$mode=false){
      global $cstr;

      //! rappel obj
      $rubrique=$this->add_tbl_php(ADD_PATH_ADMIN.TBL_MODULE_RUBRIQUE_INC,'rubrique');
      $c=(!$mode)? $rubrique[$cat] : array();
      $p="<p>%1\$s</p>";
      //! Init def
      $arryData=array(
          "auto" =>FORM_S_OP_C_AUTO,
          "file" =>FORM_S_OP_C_FILE );
      $arryData1=array(
          "auto"=>FORM_S_OP_AUTO,
          "inv_auto"=>FORM_S_OP_INV_AUTO,
          "normal_key"=>FORM_S_OP_N_KEY,
          "inv_normal_key"=>FORM_S_OP_INV_N_KEY);
      $p="<dt style=\"width:250px;float:left;\">%2\$s</dt><dd style=\"width:50%;float:right\">%1\$s</dd>";
      $lg=appel_lang();

      $base=(!$mode)? $c['base'] : '';
      $ss_rubrique=(!$mode)? $c['ss_rubrique'] : '';
      $max=(!$mode)? $c['max'] : '';

      $s=NewFct('barre_h_box_ajax',RUBRIQUE,FORM_TITRE_MODIF_CONF_RUB,'',false);

      $s.= sprintf("<p>%1\$s</p>",option_deplie('help_form',HELP_PAGE,true));
      $s.='<div style="width:70%;margin:0 auto;">'."\n";

      $s.= sprintf("<p id='help_form' style='display:none;'>%1\$s</p>",FORM_TITRE_MODIF_CONF_RUB_TXT);
      $s.=tep_form (_FILENAME_RUBRIQUES,'','action=up',"post","POST",false," onsubmit=\" montre('onload');\"" );

      if (!$mode){
        $s.=sprintf($p,php_f_hidden("rubrique",$cat).php_f_hidden("rub_parent",substr($c['path'],0 ,(strlen($c['path']) - strlen($cat) - 1) ) ).php_f_textField("rubrique",50,50,$cat,'','disabled=disabled'),'&nbsp;');
      }else{
        $s.=sprintf($p,php_f_textField("rubrique",50,50,'',''," style=\"width:50%\" ".Toolip(T_NOM_RUBRIQUE_D)).FORM_CHAMPS_OBLIGATOIRE,NAME_RUB);
        $s.=sprintf($p,php_f_checkbox('creer_rep', true, true,10,Toolip(FORM_CREER_REP_D)),FORM_CREER_REP);
        $s.=sprintf($p,php_f_checkbox('add_menu_primaire', true, true,10,Toolip(FORM_ADD_MENU_PRIM_ENTREE_RUB_D)),FORM_ADD_MENU_PRIM_ENTREE_RUB);
        $s.=sprintf($p,input_select("rub_parent",$this->c_cat('','',true),''," style=\"width:50%\" ".Toolip(_RUB_CONF_PARENT_D)).FORM_CHAMPS_OBLIGATOIRE,_RUB_CONF_PARENT);
      }

      $s.=sprintf($p,input_select("base",$arryData1,$base," style=\"width:50%\" ".Toolip(_RUB_CONF_RUB_BASE_MOD_TXT_D)).FORM_CHAMPS_OBLIGATOIRE,_RUB_CONF_RUB_BASE_MOD_TXT);

      $s.=sprintf($p,input_select("ss_rubrique",$arryData,$ss_rubrique," style=\"width:50%\" ".Toolip(_RUB_CONF_SS_RUB_MOD_TXT_D)).FORM_CHAMPS_OBLIGATOIRE,_RUB_CONF_SS_RUB_MOD_TXT);

      $s.=sprintf($p,php_f_textField("max",50,5,'0',$max," style=\"width:50%\" ".Toolip(_RUB_CONF_MAX_D)).FORM_CHAMPS_OBLIGATOIRE,_RUB_CONF_MAX);
      while ($r=each($lg)){
        $s.=sprintf($p,php_f_textField("lang[".$r['key']."][titre]",50,150,(isset($c['titre_'.$r['key']]) ? $c['titre_'.$r['key']] : ''),''," style=\"width:50%\" ".Toolip(_RUB_CONF_TITRE_D)).FORM_CHAMPS_OBLIGATOIRE."(".$r['key'].")",_RUB_CONF_TITRE);
        $s.=sprintf($p,php_f_textField("lang[".$r['key']."][descri]",50,150,(isset($c['descri_'.$r['key']]) ? $c['descri_'.$r['key']]: '' ),''," style=\"width:50%\" ".Toolip(_RUB_CONF_DESCRI_D)).FORM_CHAMPS_OBLIGATOIRE."(".$r['key'].")",_RUB_CONF_DESCRI);
        $s.=sprintf($p,php_f_textField("lang[".$r['key']."][tag]",50,150,(isset($c['tag_'.$r['key']])? $c['tag_'.$r['key']] : ''),''," style=\"width:50%\" ".Toolip(_RUB_CONF_TAG_D)).FORM_CHAMPS_OBLIGATOIRE."(".$r['key'].")",_RUB_CONF_TAG);
      }
      $s.=sprintf("<p>%1\$s</p>",FORM_CHAMPS_OBLIGATOIRE_TXT);
      $s.=sprintf("<p>%1\$s</p>",input_button('submit',((!$mode) ? BT_MODIF_RUB : BT_CREER_RUB),'','',' class="button exe" ').input_button('reset',SUBMIT_RESET,'','',' class="button exe" ') );
      $s.="</form>\n"
            ."</div>\n";
      return $s;
  }


  /**
    Suppression recusrive d'un repertoire de cat
    prise en charge mutli langue
    @param
      @a string la lcef de cat
  */
  public function del_cat($cat){
    $rubrique=$this->add_tbl_php(ADD_PATH_ADMIN.TBL_MODULE_RUBRIQUE_INC,'rubrique');
    if(!isset($rubrique[$cat]))return false;

    $this->del_dir_cat($rubrique[$cat]['path']);
    $this->del_item_db($cat);
  }

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

}

?>