<?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
*/
/**
  Liste des articles
  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_posts  extends db_posts{

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


    /**
      recuperation des elements des categories, Liste complete
      @param
        @p array db_links
    */
    /*public*/ /*function db_posts(){
      return $this->db_links;
    }*/


  /**
    Affichage rubriques articles in select
    @param
      @a string key rubrique actuel (page edition uniquement)
      @a string params html
  */
  /*public*/ /*function c_cat($rep,$params=''){
  global $cstr;
   error_reporting(E_ALL);
    $etat='';$arryData='';
    foreach($cstr->_call('db_rubrique','db_cat') as $k=>$v){
      $arryData[$v['path']]=(isset($v['titre_'.LANG_POST]) && tep_not_null($v['titre_'.LANG_POST])) ? $v['titre_'.LANG_POST] : $k;
    }
//     if(empty($rep))$rep='racine';
    return input_select('file_rep',$arryData,$rep,$params);
  }*/


    /**
      Block des box optionnel
    @param
      @a array tableau des options actve/inactive
    */
//     function draw_block_box($opt,$params=''){
//     $cstr->_call('table_block','force_row_parameters',$params);
//     $cstr->_call('table_block','force_separator',array('separator'=>array('div','p','span')) );
// //     $array[0]['separator']=array('p','span','span');
//     $array[]['form']= $this->affactif($post['etat_page']);
//     $array[]['text']= $this->affrub($the_post['keyrub'],"post",' class="input_100p" ');
//     $array[]['text']= $this->afftype('les2',$_POST['date_publi'],$_POST['date_retrait']);
//     $array[]['text']= $this->nav_draw_lang('afflang');
//
// //     $array[]['text']= '<hr />'.mode_editions (ltrim($_POST['fixe_mod']));
//
//     print $cstr->_call('table_block','table_block',$array);
//     }


  /**
    Menu de nav  lang
  */
  /*private*/ function nav_draw_lang($id='afflang',$params=''){
    global $cstr;
    $cstr->_call('table_block','force_row_parameters',' class="'.$id.' lang post" '.$params);
    $cstr->_call('table_block','force_data_parameters',' class="'.$id.' lang post" '.$params);
    $cstr->_call('table_block','force_separator',array('separator'=>array('ul','li','span')) );
    $lg=$cstr->the_var('lg');
    if (count($lg)>0){
      while($r=each($lg)){
        $select= ($this->lang==$r['key']) ? ' select ' : '';
        $array[]['text']=tep_links('', _FILENAME_ADMIN.'?lang='.$r['key'],BT_EDITER,"<img src=\"".URL_DU_SITE.REP_LIB_PARTAGE.REP_IMG.$r['key'].".gif\" />", false,'', '',' class="'.$select.'" ',5);

      }
      return '<hr /><span class="'.$id.' label b ">'.AFFLANG.'</span><br />'.$cstr->_call('table_block','table_block',$array);
    }
    else return '';
  }


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

      //! recalcul en focntion de la langue
      $this->lang= (isset($post['lang'])) ? $post['lang'] : LANG_POST;
      $this->files=array();
      $this->browse_folder(ADD_PATH_ADMIN.REP_DATA.$this->lang);

      $arryData=array(''=>TXT_ACTION_GRP,
                      'P'=>TXT_ACTION_GRP_PUB,
                      'I'=>TXT_ACTION_GRP_PUB_OFF
                     );

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

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

      for ($i=0, $n=sizeof($this->files); $i<$n; $i++) { $sort[$i]=(empty($this->files[$i]['keyrub'])? 'aaaaa': $this->files[$i]['keyrub'] ); }
      asort($sort);


      foreach($sort as $i=>$value){

        $f=array_merge((array)$this->files[$i],(array)$this->this_posts($this->files[$i]['rub'].$this->files[$i]['nom_ss_ext']) );

//         print_r($this->this_posts($this->files[$i]['rub'].$this->files[$i]['nom_ss_ext']));
        // cat
        if(empty($f['keyrub'])) $cat= RACINE_DATA;
        else {
          $c=$cstr->_call('db_rubrique','db_cat',$f['keyrub']); //$this->db_cat($f['keyrub']);
          $cat= (isset($c['titre_'.$this->lang]) && tep_not_null($c['titre_'.$this->lang])) ? $c['titre_'.$this->lang]: $f['keyrub'];
        }
        // page par default
        $page_defaut= (PREM_PAGE == $f['rub'].$f['nom_ss_ext']) ?  '<img src="'."template/".TEMPLATE_ADMIN."/img/check_on.png".'" alt="'.HOME_POST.'" '.Toolip(HOME_POST).'/>': '';
        $titre_texte= (!empty($f['title_'.$this->lang])) ? $f['title_'.$this->lang] : (!empty($f['title_'.LANG_POST]) ? $f['title_'.LANG_POST] :$f['nom_ss_ext'] );


          $list[]['line']= php_f_checkbox('act_g['.$i.']', md5 ($f['rub'] . $f['nom_ss_ext']), false).'</td><td>'.$page_defaut.'<a class="item titre" href="'._FILENAME_MODIFIER_UN_FICHIER.'?file='.ADD_PATH_ADMIN.REP_DATA.$this->lang.'/'.$f['rub'].$f['nom_complet'].'&amp;action=edit"> '.$titre_texte.'</a> '
                    .' <div class="action view fils l" style="border:none;">'
                    .'<span style="display:inline-block;">lien : '.tep_url_link('', true, true,$this->lang.'/'.$f['rub'].$f['nom_ss_ext']).'</span>'
                    .' </div>'
                    .' <div class="action view fils r" style="border:none;">'
                    .' <a class="item titre" href="'._FILENAME_MODIFIER_UN_FICHIER.'?file='.ADD_PATH_ADMIN.REP_DATA.$this->lang.'/'.$f['rub'].$f['nom_complet'].'&amp;action=edit">'.BT_MODIF.'</a> '
                    .tep_links('btsupp',_FILENAME_MODIFIER_UN_FICHIER."?file=".ADD_PATH_ADMIN.REP_DATA.LANG_POST.'/'.$f['rub'].$f['nom_complet']."&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="item titre" href="'.tep_url_link('', true, true,$this->lang.'/'.$f['rub'].$f['nom_ss_ext']).'"> '.BT_VIEW.' </a> '
                    .'</div>'
                    .'</td>'
                    .'<td style="border:none;"> <span class=" date l"> le <span class="item ">'.$f['date_created'].'</span> </span> </td>'
                    .'<td style="border:none;"> <span class=" date l"> <span class="item ">'.(test_bool(@$f['etat'])?ARTICLE_ACTIF_P : ARTICLE_ACTIF_I).'</span> </span> </td>'
                    .'<td>'.$cat
                    . ' <div class="action view fils r" style="border:none;">'
                    .(!empty($f['keyrub']) ?' <a class="item titre" href="'._FILENAME_RUBRIQUES.'?cat='.ADD_PATH_ADMIN.REP_DATA.$this->lang.'/'.$f['rub'].'"> '.BT_MODIF.' </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="'.tep_url_link('', true, true,$this->lang.((!empty($f['rub'])) ? '/'.substr($f['rub'],0,-1) : '') ).'"> '.BT_VIEW.' </a> '
                   .'</div>'
                   .'';

      }


      $list=(isset($list) && is_array($list)) ? $list : array() ;
      $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>titre</th><th>date</th><th>publié</th><th>rubrique</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
      */

      echo '<h3>'.LIST_POSTS.'</h3>';
      echo $this->nav_draw_lang('afflang');

      echo tep_form (_FILENAME_ADMIN,'','action=up_posts',"post","POST",false,"" );
      echo $objLum->drawPage()."\n\n";
      echo '<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>';
      echo '</form>';
      echo '<div class="split" style="clear:both; width:95%; height:25px;">';
      echo ' <span class="r">'.tep_row_by_page('','','',$nb).'</span>';
      echo $objLum->drawLinks('')."\n\n";
      echo '</div>';
    }

}

?>