<?php
// kate: replace-trailing-space-save true; space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; word-wrap-marker-color #41C2A4

/**
  @class page
  @author oscim - LossimTeam
  @note construction des pages
$lang tableau de lang dispo; $ajax_dest> destination en ajax, si absent, prise en charge normal; $edit> mode edition, connecté dans l'adsmin, et visite site identifié; $debug (true, false) fait apparaitre meta de debug, sur la destination

Sortie Element page ex:
Array
(
    [type] => article
    [etat] => 1
    [keyrub] => asso
    [dest] => fr/asso
    [dest_ss_lg] => asso
    [arg] =>
    [ch_reel] => fr/asso
    [dest_err] =>
    [rubrique] => asso
    [lang_link] => Array
        (
            [fr] => fr/asso
        )

    [starttime] => 1253623433.36
)
*/

class page extends cstr{

  /**
      array, langues dispo
  */
  var $lang;
  /**
    string, destination de la page avec ajax
  */
  var $ajax_dest;
  /**
    Chargement dyn du parser
  */
  var $force_lib_dep_via_parser;
  /**
    tableau des key de traitement
  */
  var $rubri;
  /**
    Connesion admin active
  */
  var $edit;
  /**
    synthese du px_config_module pour la prise en charge des extensions
  */
  var $ext_activ;
  /**
    array des exe js
  */
  var $function_js_init;
  /**
    @author oscim - LossimTeam
    @note recup du dernier article
  */
  private  function der_article(){
    $i=array_reverse($this->i_links);
    $e=each($i);
    return $e['value']['href'];
  }


  /**
    @author oscim - LossimTeam
    @arg [[$value string path file],$key string type file in lossim ]
   Charge les include en focntion du type de fichier detecté
  */
  /*public static*/function include_file ($value,$key) {
    if (!tep_not_null($value)) return false;
    global $function_js_init;
    $long=strlen($value);

    if (substr($value,($long-3),$long)=='css') print "<link rel=\"stylesheet\" href=\"".URL_DU_SITE.$value."\"  type=\"text/css\" media=\"all\" />\n";
    elseif (substr($value,($long-2),$long)=='js') print '<script type="text/javascript" src="'.URL_DU_SITE.$value.'"></script>'."\n";
    elseif(substr($value,($long-3),$long)=='php'||substr($value,($long-3),$long)=='inc') include_once ($value);
    elseif(substr($key,0,5)=='init_') $function_js_init[]=$value;
  }


  /**
    @author oscim - LossimTeam
    @arg [[$lang array ],$desti array]
    @note Control destination + langue dipso pour destination. verife la présence de l'article correpsondant.
          Supporte les  redirections  en prennant en charge  la recherche du href ds index_link, sinon, shearch des files sur base chemins sans langue
  */
  /*private*/ function test_dest_lang($lang,$desti){
    $lang1=$lang;

      $lg_extract=@$desti['lang'];
      $dest=$desti['url'];

    while ($r = each($lang)) {
      if (tep_not_null($r['key'])){
        /* redirection */
        if (isset($this->i_links[md5($dest)]['href']) && file_exists(REP_DATA.$r['key']."/".$this->i_links[md5($dest)]['href'].".xml"))
          $lg[$r['key']]=$r['key']."/".$this->i_links[md5($dest)]['href'];
        /* article present */
        elseif (file_exists(REP_DATA.$r['key']."/"."$dest.xml"))
          $lg[$r['key']]=$r['key']."/".$dest;
        elseif(file_exists(REP_DATA.$r['key']."/".$dest.""))
          $lg[$r['key']]=$r['key']."/".$dest;
        else {
          while ($r2 = each($lang1))
            if (file_exists(REP_DATA.$r['key']."/".$dest.".xml") )
              $lg[$r['key']]=$r['key']."/".$dest.".xml";
        }
      }
    }

    if (isset($lg_extract)&& isset($lg[$lg_extract])&& tep_not_null($lg_extract) && tep_not_null($lg[$lg_extract]))
      define('LANG_VIEW',$lg_extract);
    elseif (isset($lg[LANG_POST])&&tep_not_null($lg[LANG_POST]))
      define('LANG_VIEW',LANG_POST);
    elseif (isset($lg[LANG])&&tep_not_null($lg[LANG]))
      define('LANG_VIEW',LANG);
    elseif(!defined('LANG_VIEW'))
      define('LANG_VIEW',LANG_POST);

    if (isset($lg) && count($lg)>0) {
      if( (count($lg)>1)OR( LANG_VIEW ==LANG) )  define('LANG_NAV',true);
      else define('LANG_NAV',false);
      return $lg;
    } else {
      return false;
      define('LANG_NAV',false);
    }
  }


  /**
    @author oscim - LossimTeam
    @arg [[[$type string ],$rubri ],$_PX_config_module array]
    @note Appel des fichier php de la structure modulaire, inclusion des head, destination, footer
  */
  /*public*/ function appel_files_modules($type,$rubri,$_PX_config_module){
    global $function_js_init;
    if ($type =='PIparser')include (TBL_SYS_CONFIG_MODULES_INC);
    reset($_PX_config_module);
    while ($r=each($_PX_config_module))
      if ( (file_exists(CHEM_MODULES.$r['key']."/lib/".$type.".php"))AND($_PX_config_module[$r['key']]=='true') )
        include_once(CHEM_MODULES.$r['key']."/lib/".$type.".php");
      elseif ( (file_exists(REP_LIB_EXT.$r['key']."/lib/".$type.".php"))AND($_PX_config_module[$r['key']]=='true') )
        include_once(REP_LIB_EXT.$r['key']."/lib/".$type.".php");

    if ($type !='PIparser')return $function_js_init;
  }


  /**
      Calcul des lib chargée
      @param
        @a string nom de extension, module, plugins
        @a array result $rubri
  */
  /*private*/ function test_contrainte_lib_int($name,$res_dest){
    $d= (isset($res_dest['dest_ss_lg']))  ? trim($res_dest['dest_ss_lg']) : trim($res_dest['dest']) ;

    if (!isset($this->inc_contraintes[$d])) $tabl[]= true;
    else {
      reset($this->inc_contraintes[$d]);
      while ($r=each($this->inc_contraintes[$d]) ){
        if ( $r['key'] == $name){
          if (strtoupper($r['value']) =='FALSE') $tabl[]= false;
          else $tabl[]= true;
        }
        else $tabl[]= true;
      }
    }

    if (!in_array(false,$tabl)) return true;
    else return false;
  }


  /**
    @author oscim - LossimTeam
    @arg [[$res_dest] ,$t_dep array ]
    @note prend en charge le chargement des libaririe dans le coprs de page, aprs le contenu. autorise chargement d'un script, ou d'un fichier php. et  l'init de la function et les contraintes associé a une ou des pages, si pas de contrainte lib chargées peut charger une librairie sur un template données
  */
  /*private*/ function appel_libs_page($res_dest,$t_dep){
    global $function_js_init, $t_dep,$t_conflit;
    reset($this->inc_lib_i);
    while ($r=each($this->inc_lib_i)) {
//       if (!isset($t_dep[$r['key']])) { // verif si pas deja chargée
        if ( $this->test_contrainte_lib_int($r['key'],$res_dest))
          if (is_array($r['value'])){
            while ($f=each($this->inc_lib_i[$r['key']]))
              $this->include_file ($f['value'],$f['key']);
              $function_js_init=array_merge($function_js_init,$this->control_module_dep($f['key'],$t_dep,$t_conflit,$function_js_init));
          } else {
            $this->include_file ($r['value'],$r['key']);
            $function_js_init=array_merge($function_js_init,$this->control_module_dep($r['key'],$t_dep,$t_conflit,$function_js_init));
          }
//       }
    }
    return $function_js_init;
  }


  /**
    @author oscim - LossimTeam
    @arg [$s ]
    @note appel des fichier css de base, hors element modulaire
  */
  /*private*/   function appel_css($s){
    global $function_js_init;

    $format="template/".NOM_DU_THEME."/%s.css";
    if ( ($fi=$this->shearch_gabarit($format) ) !=false) $style=$fi;
    else $style=NOM_STYLES_CSS;

    if( (test_const('FERMETURE_DU_SITE')) && (!isset($_SESSION['hash_acces_utilisateur'])) ) $chemin_et_style = (file_exists("template/".NOM_DU_THEME."/maintenance.css")) ? NOM_DU_THEME."/maintenance.css" : "demo/maintenance.css" ;
    else $chemin_et_style = NOM_DU_THEME."/".$style.".css" ;
      page::include_file('template/'.$chemin_et_style,'');
    ?>
    <style type="text/css">  <?php if (test_const('DETECT_USER_AGENT')) NewFct('appel_UserAgent'); ?> </style>
    <?php
  }


  /**
    @author oscim - LossimTeam
    @arg [$s ]
    @note Appel gabarit de page + lib specifique et angue du theme
  */
  /*private*/   function appel_template($s,$_PX_config_module,$_POST,$_GET){
    global $function_js_init, $cstr;
    $dest= $s['dest'];
    $dest_=str_replace("/","_",$dest );
    $cstr->_add_class('rubrique',"include/lib/class/class.rubrique.php");

    if(!empty($s['dest_err']))$dest_err=$s['dest_err'];
    $starttime= $s['starttime'];
    define('CHEMIN_THEME',URL_DU_SITE."template/".NOM_DU_THEME."/");
    /* element de langue du theme */
    if(file_exists("template/".NOM_DU_THEME."/inc/languages/".LANG_POST.".php"))
      include("template/".NOM_DU_THEME."/inc/languages/".LANG_POST.".php");
    if(file_exists("template/".NOM_DU_THEME."/inc/lib_theme_functions.php"))
      require("template/".NOM_DU_THEME."/inc/lib_theme_functions.php");

    if( (test_const('FERMETURE_DU_SITE'))/*AND(!isset($_SESSION['hash_acces_utilisateur'])) */) NewFct('fermeture_site','');
    else {
      if  (test_addon_activ('menu') ) {
        $cstr->_add_class('menu',"include/lib/class/class.menu.php");
        $config_menu=$this->add_tbl_php(TBL_MODULE_CONFIG_MENU_INC,'config_menu');
        var_config_cst($config_menu,'config_menu');
      }

      /**
        Gabarits
      */

      $format="template/".NOM_DU_THEME."/%s.php";
      if ( ($fi=$this->shearch_gabarit($format) ) !=false) {
        require(sprintf($format,$fi) );
        define ('NAME_GABARIT',$fi );
      }else {
        if(!defined('NAME_GABARIT')) define ('NAME_GABARIT','template' );
        if(!@include ("template/".NOM_DU_THEME."/template.php")){
          if(!@include ("template/demo/template.php"))die ("Erreur theme absent:".NOM_DU_THEME );
        }
      }
    }
  }

  /**
    Test et return le nom du fichier de gabarit ou css
    Les valeurs sont teste dans leur ordre
   @param
    @a array tableau de valeur des element a tester
    @a string pour printf, forme "/%s.php" | "/%s.css"
  */
  /*static private */function test_file($array,$format){
    for ($i=0, $n=sizeof($array); $i<$n; $i++) {
       if (file_exists(sprintf($format,$array[$i]))) return $array[$i];
    }
    return false;
  }

  /**
    Selectionne et return le gabarit de la page
    Ne calcul le gabarit qu'une fois!
    @param
      @a string format de recherche forme "/%s.php" | "/%s.css" + reperteoir
  */
  /*private*/ function shearch_gabarit($format){
    $fi='';
    static $fi;

    $array[]=@$this->rubri['dest_ss_lg']; /** gabarit.php */
    if (!empty($this->rubri['rubrique'])) $array[]=$this->rubri['rubrique']; /** Nom de la rubrique */
    $array[]=$this->rubri['type']; /** type.php (article/rub/mod/page)*/
    $array[]='template';

     if ($fi !='') return $fi;
     if ( ($fi=$this->test_file($array,$format) ) !=false)  return $fi;
  }


  /**
    @author oscim - LossimTeam
    @arg $nom_module,$t_dep,$t_conflit,$function_js_init
    @note Calcul et control des dependance, et de leur priorité
  */
  /*private*/ function control_module_dep ($nom_module,$t_dep,$t_conflit,$function_js_init){
    global $t_dep,$t_conflit;
  // $dep=array_merge($dep,$lib_i);
    reset($this->inc_dep);
    if (isset($this->inc_dep[$nom_module])) {
      $t_dep[$nom_module]=$nom_module;
      $prio= 5;
      $this->tep_prio_dep ($prio,$nom_module,$nom_module);

      while ($r=each($this->inc_dep[$nom_module])){
        $gfr=extract_option($r['value']);
        $prio=(isset($gfr['exe_priorite']))? $gfr['exe_priorite'] : 5;

        if (@$gfr['type']=='dep') {
          if (/* !isset($t_dep[$r['key']])&&*/ isset($this->inc_dep[$nom_module][$r['key']])){
            $t_dep[$r['key']]=$r['value'];

            $this->tep_prio_dep ($prio,$r['key'],$r['value']);
            $this->control_module_dep ($gfr['name_dep'],$t_dep,$t_conflit ,$function_js_init);
          }else/*if (!isset($t_dep[$r['key']]))*/ {     /* Organisation fonction order priorite */
            $t_dep[$r['key']]=$r['value'];
            $this->tep_prio_dep ($prio,$r['key'],$r['value']);
          }
        } elseif (@$gfr['type']=='conf') {
          if ( !isset($t_conflit[$r['key']])) $t_conflit[$r['key']]=$r['value'];
        } elseif ( $gfr['type']=='init') {
          if ( !isset($function_js_init[$r['key']])) $function_js_init[$r['key']]=$r['value'];
        }
      }

    } else {
    // $prio=(isset($gfr['exe_priorite']))? $gfr['exe_priorite'] : 5;
      $prio= 5;
      $this->tep_prio_dep ($prio,$nom_module,$nom_module);
      $t_dep[$nom_module]['racine']=$nom_module;
    }
    if ( count(array_intersect($t_dep,$t_conflit))>0 ) {
      print ('conflit de dependance de module');print_r(array_intersect($t_dep,$t_conflit));
      exit;
    }
    else return $function_js_init;
  }


  /**
    @author oscim - LossimTeam
    @arg $nom_module,$t_dep,$t_conflit,$function_js_init
    @note calcul Repartitions des dependances et librarire par class d'order de priorite. 0 important, 9 pas important
  */
  /*private*/   function tep_prio_dep ($nub_order,$key,$value=''){
    $nub= '00'.$nub_order;
    static $ctr_dbl;

    if (isset($this->prio_dep[$nub])) $nub='00'.$nub_order++;

    if (!isset($ctr_dbl[$key])) $this->prio_dep[$nub][$key]=$value;
    $ctr_dbl[$key]=$value;
  }


  /**
    @author oscim - LossimTeam
    @arg $nom_module,$t_dep,$t_conflit,$function_js_init
    @note Calcul et control des dependance, et de leur priorité
  Chargement des element necessaire au control dep, lib
  */
  /*private*/   function init_ctr_dep(){
    $this->inc_LIB=$this->add_tbl_php("include/lib_ext.php",'LIB');
    $this->inc_lib_i=$this->add_tbl_php(TBL_LIB_INTERNE_INC,'lib_i');
    $this->inc_dep=$this->add_tbl_php(TBL_DEP_MODULES_INC,'dep');
    $this->inc_contraintes=$this->add_tbl_php(TBL_LIB_CONTRAINTE_INC,'contraintes');
  }


  /**
    @author oscim - LossimTeam
    @arg $rubri,$PX_config_module,$function_js_init, $t_dep,$t_conflit
    @note Control des dep, et appel reel des inclusion, system, parser et lib_i
  */
  /*private*/   function control_dep_modules($rubri,$PX_config_module,$function_js_init, $t_dep,$t_conflit){
//     $LIB=array_merge($this->inc_LIB,$this->inc_lib_i);
    foreach($this->inc_LIB as $k=>$v)
      $LIB[$k]=array_merge($v,(array)@$this->inc_lib_i[$k]);

    global $t_dep,$t_conflit;
    $t_dep=$t_conflit=array();
    reset($PX_config_module);
    while ($r = each($this->ext_activ))
      if ($r['value'] =='true' && ($this->test_contrainte_lib_int($r['key'],$rubri) ==true) ){
        ## control des dependances des modules
        $function_js_init=array_merge($function_js_init,$this->control_module_dep($r['key'],$t_dep,$t_conflit,$function_js_init));
      }

    /**
      Inclusion des element ext ()lightbox...) requis par le parser
    */
    if (is_array($this->force_lib_dep_via_parser)){
    reset($this->force_lib_dep_via_parser);
    while ($r = each($this->force_lib_dep_via_parser))
      if ($this->test_contrainte_lib_int($r['key'],$rubri) ==true)
        $function_js_init=array_merge($function_js_init,$this->control_module_dep($r['key'],$t_dep,$t_conflit,$function_js_init));
    }

    if (isset($this->prio_dep) && is_array($this->prio_dep)) {
            ksort($this->prio_dep);
//             print_r($LIB);
            ## chargement des dépenance et modules
            while($rs=each($this->prio_dep)){
              while ($r=each($rs['value'])) {
                if (isset($LIB[$r['key']])){
                  if (is_array($LIB[$r['key']])){
                    while ($f=each($LIB[$r['key']]))
                      $this->include_file($f['value'],$f['key']);
                  }else{
                    $this->include_file($r['value'],$r['key']);
                  }
                }
                ## appel file lang
                if(file_exists(CHEM_MODULES.$r['value']."/language/".LANG_POST.".php")) include_once(CHEM_MODULES.$r['value']."/language/".LANG_POST.".php");
              }
            }
    }
    return $function_js_init;
  }


  /**
    @author oscim - LossimTeam
    @arg $dest (string),$r,$lang (array),$lang_ok,$PX_config_module (array)
    @note  Calcul de la destination en fct type de page
  */
  /*private*/function destination_final_plus_tag ($dest,$tabdest,$lang,$lang_ok,$PX_config_module){
  error_reporting(E_ALL);
    if  ( test_addon_activ('rubrique') ) $rubrique=$this->add_tbl_php(TBL_MODULE_RUBRIQUE_INC,'rubrique');

    $multi = (count($lang)>1) ? true: false ; // multilang
    $lang_default = $lang[LANG];
    /*  Chargement fichier langue generaux*/
    $reponse=@include_once("include/languages/".LANG_POST.".php");
    if (!$reponse) include ("include/languages/".LANG.".php");


    function erreur_de_destination($dest,$lang_ok){
      format_title(ERREUR_404,META_DESCRIPTION,META_KEYWORDS);
      $etat_404= false;
      $d_dest = '404';
      if (file_exists(REP_DATA.LANG_VIEW.'/404.xml')){ $etat_404 = true;  $d_dest = LANG_VIEW."/404" ; }
      return $s=array("type"=>'error',"etat"=>$etat_404,"dest"=>$d_dest,"dest_err"=>$dest, "dest_ss_lg"=>'404',"ch_reel"=>$dest,"arg"=>'',"rubrique"=>'','lang_link'=>$lang_ok);
    }

    /* suppression lang au debut de la dest pour rub*/
    if ($lang_ok ==false) $dest_sans_lg=str_replace(LANG_VIEW.'/','',$tabdest['url']);
    else $dest_sans_lg=str_replace(LANG_VIEW.'/','',$lang_ok[LANG_VIEW]);

    $rep_c=REP_DATA.LANG_VIEW."/";
    if (strpos($dest_sans_lg,'/')>0){
      $dest_key=$tabdest['keyrub'];
      $index_rub=$tabdest['keyrub'];
      $rub=$tabdest['rub'];
    }else   $dest_key=$index_rub=$rub=$dest_sans_lg;

    if ($this->debug==true)print ("<meta name=\"debug\" content=\"".$index_rub."\" />\n");

    /* Appel rubrique Si rubriques on  ET NOT fichier xml */
    if ((isset($rubrique[$dest_key]['path']))AND(trim($rubrique[$dest_key]['path'])=='/'.trim($index_rub))AND(!file_exists($rep_c.$dest_sans_lg.".xml"))AND(is_dir($rep_c.$dest_sans_lg))){
      format_title($rubrique[$dest_key]["titre_".LANG_VIEW],$rubrique[$dest_key]["descri_".LANG_VIEW]."|".META_DESCRIPTION,$rubrique[$dest_key]["tag_".LANG_VIEW]."|".META_KEYWORDS);
      return $s=array("type"=>'rub',
                      "etat"=>false,
                      "dest"=>"rubriques",
                      "rubrique"=> "".$rub."",
                      "keyrub"=> "".$index_rub."",
                      "dest_ss_lg"=>$dest_sans_lg,
                      "arg"=>$tabdest['arg'],
                      "ch_reel"=>$dest,
                      "dest_err"=>'');
    }
    /* Appel article  */
    elseif ( ( ($lang_ok !=false)) /*AND (file_exists($rep_c.$dest_sans_lg.".xml"))*/AND(test_file_name_dater($dest_sans_lg)!=false) ) {
      $key=md5($dest_sans_lg);
      format_title(@$this->i_links[$key]['title_'.LANG_VIEW],'','');
      if (LANG_VIEW !='false') {
        $file =$lang_ok[LANG_VIEW];
        $parse = $this->_add_class('titre',"include/lib/class/class.titre.php",REP_DATA.$file.".xml", $this);
        $this->_call('titre','analyser');
        $this->force_lib_dep_via_parser=$this->_call('titre','force_lib_dep');
        return $s=array("type"=>'article',
                        "etat"=>true ,
                        "keyrub"=> "".$index_rub."",
                        "dest"=>$file,
                        "dest_ss_lg"=>$tabdest['file'],
                        "arg"=>$tabdest['arg'],
                        "ch_reel"=>$file,
                        "dest_err"=>'',
                        "rubrique"=>(is_dir($rep_c.$dest_sans_lg))?$dest_sans_lg:($rub!=$dest_sans_lg)?$rub:'',
                        'lang_link'=>$lang_ok);
      }
      else erreur_de_destination($dest,$lang_ok);
    }
    else {
    /*  appel block specifique au module*/
      if (is_array($this->ext_activ))
      while ($r=each($this->ext_activ))
        if ( file_exists(CHEM_MODULES.$r['key']."/lib/destination.php") ) {
          include(CHEM_MODULES.$r['key']."/lib/destination.php");
          if (!empty($mod_dest)) return $s=array("type"=>'mod',"etat"=>$mod_etat,"dest"=>$mod_dest,"arg"=>$mod_arg,"ch_reel"=>$dest,"rubrique"=>$mod_rub,"dest_err"=>$mod_dest_err);
        }
    /*  PAGE PRIORIAIRE FIXE PHP Mot RESERVE  form, 404, rubriques,rubrique */
      if ( (file_exists("include/content/".$dest_sans_lg.".php"))AND(!file_exists($rep_c."/".$dest_sans_lg.".xml")) )  {
              format_title(@constant(strtoupper($dest_sans_lg)),META_DESCRIPTION,META_KEYWORDS);
              return $s=array("type"=>'page',"etat"=>false,"dest"=>$dest_sans_lg,"arg"=>$tabdest['arg'],"ch_reel"=>$dest,"rubrique"=>'',"dest_err"=>'');
      }
      elseif (!file_exists($rep_c.$dest_sans_lg.".xml"))return erreur_de_destination($dest,$lang_ok);
      else return erreur_de_destination($dest,$lang_ok);
    }
  }


  /**
    @author oscim - LossimTeam
    @arg $cache (object),$s,$function_js_init (array)
    @note
  */
  /*private*/function printFooter($s,$function_js_init){
    global $cstr;
    $function_js_init=$this->appel_files_modules('footer',$s,$this->ext_activ,$function_js_init); ?>
     <script type='text/javascript'>//<!--
      function init_load_array(){
      <?php if(isset($function_js_init)) while ($funct_js = each($function_js_init))
              print $funct_js['value']; ?>
      }
      window.onload=init_load_array;
    //--></script>
    <?php echo "</body>\n</html>";
    if  (test_const('CACHE_PUBLIC')) $cstr->_call('HDAcache','end_cache');
    else @ob_end_flush();
  }


  /**
    @author oscim - LossimTeam
    @arg $_PX_config_module (array)
    @note LA definition d'une class sur un paquets, rend celui ci d'une priorité plus faible que la class. Une foie la class activé, une recherche des elements de la class , puis l'activation de l'un de ces element. Une constante de Class, sous la même forme que les modules est creer et conteient soit false, soit le nom du module qui sera chargée
  */
  /*private*/   function module_actif_dyn($_PX_config_module){
    $cl=$class=array();
    while ($r=each($_PX_config_module)){
      if (isset($r['value']['class']))$class[$r['value']['class']][$r['key']]= $r['value']['etat'];
      else $this->ext_activ[$r['key']]=$r['value']['etat'];
    }
    if (is_array($class))
    while ($r2=each($class)){
      $r3=each($r2['value']);
      if (!isset($cl[$r2['key']])){
        $this->ext_activ[$r3['key']]=$r3['value'];
        $cl[$r2['key']]=$r3['key'];
      }
    }
    var_config_cst($cl,'PX_config_class');

    return  $this->ext_activ;
  }


  /**
  * constructeur
    @author oscim - LossimTeam
    @arg $lang,$ajax_dest,$edit,$debug,$not_sortie
        $not_sortie >> appel vers page qui recup ensemble strcuture mais sans sortie page
    @note

    @param
      @a array $lang
      @a string $ajax_dest
      @a bool $edit (mode edition, menu liée au backoffice)
      @a bool $debugg
      @a string/bool $not_sortie (true: retour bock info et not display )
  */
  function page($lang,$ajax_dest,$edit,$debug,$not_sortie=''){
    global $cstr;

    $this->debug= ($debug==true)? true : false;
    $this->edit= ($edit==true)? true : false;
    $this->force_lib_dep_via_parser=false;
    $this->lang = $lang;
    if (!empty($ajax_dest))$this->ajax_dest = $ajax_dest;
    global $t_dep,$t_conflit,$function_js_init;

    $function_js_init=array();
    $starttime=$s_p='';
    if($this->edit==true) define('MOD_EDIT_PHP', true);
    $mtime = microtime();
    $mtime = explode(" ",$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $starttime = $mtime;
    $_GET=construct_get();

    if  (test_const('MODULES')) {
      if (file_exists(TBL_SYS_CONFIG_MODULES_INC)) {
        $_PX_config_module=$this->add_tbl_php(TBL_SYS_CONFIG_MODULES_INC,'_PX_config_module');
        var_config_cst($this->module_actif_dyn($_PX_config_module),'PX_config_module');
        var_config_cst($this->add_tbl_php(TBL_CONFIG_GEN,'_Config_gen'),'CG');
      }
    }
  //!  prise en charge destination a affiché, soit par url, ou passage arg
    $this->extract_nom=$extract_nom= (!isset($this->ajax_dest)) ? NewFct('extract_nom','') : NewFct('extract_nom',$this->ajax_dest) ;
    if ( (!$extract_nom)OR (empty($extract_nom)) ) die(ERROR." function printHeader  ".EXTRACT_NOM_ALERTE);
    if (empty($extract_nom['url'])) {
      if (PREM_PAGE =='true') $extract_nom['url']=page::der_article();
      else $extract_nom['url']=PREM_PAGE;
    }
    $dest= /*(URL_FORMAT =='mod_rewrite') ?*/ $extract_nom['url']/* : $extract_nom['arg']*/ ;
  //! charge base de l'index des articles avec href
    $this->i_links=$this->add_tbl_php(TBL_INDEX_LINKS_INC,'i_links');
    $lang_ok=$this->test_dest_lang($this->lang ,$extract_nom);
  //! Pris en charge gestion identification user  tyep zone_membre
    if( test_const('SESSION_IDENTIFICATION')){
      include('include/lib/lib/lib.identification_public.php');
      include('include/languages/'.LANG_POST.'/identification.php');
      if( (isset($_POST['logout'])) AND (!empty($_POST['logout'])) ){
        @session_destroy();
        @session_unset();
      }
    }

  //! Block  Sortie pour charge unique structure  SOrtie Element Public
    if ($not_sortie == true) {
      $this->lang_ok=$lang_ok;
      $this->_PX_config_module=$_PX_config_module;
      $this->rubri=$this->destination_final_plus_tag ($dest,$extract_nom,$this->lang ,$lang_ok,$_PX_config_module);
      return;
    }

    /* Sortie */
    print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n"
            ."<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"".LANG_VIEW."\" xml:lang=\"".LANG_VIEW."\">\n"
            ."<head>\n";
    print "<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=".ENCODING."\" />\n";

    /* Calcul destination */
    $rubri=$this->destination_final_plus_tag ($dest,$extract_nom,$this->lang ,$lang_ok,$_PX_config_module);
//    print_r($rubri);
    /* Control identification */
    if( test_const('SESSION_IDENTIFICATION')){
            if (!verif_session($rubri)) define('SESSION_IDENT', 'false');
            elseif(!defined('SESSION_IDENT')) define('SESSION_IDENT', 'true');
    }

    $s_p .= "<meta http-equiv=\"Content-Type\" content=\"image/png\" />\n"
            ."<meta http-equiv=\"Content-Type\" content=\"image/jpg\" />\n"
            ."<meta http-equiv=\"Content-Type\" content=\"image/gif\" />\n"
            ."<meta http-equiv=\"Content-Script-Type\" content=\"text/css\" />\n"
            ."<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />\n"
            .'<meta name="generator" content="'.NOM_DU_PROJET.' ('.REVISION_DU_PROJET.') '.VERSION_DU_PROJET.'" />'."\n";
    if (test_const('META_PRAGMA')) $s_p .="<meta http-equiv=\"Pragma\" content=\"".META_PRAGMA."\" />\n";
    if (test_const('META_ROBOTS')) $s_p .= "<meta name=\"Robots\" content=\"".META_ROBOTS."\" />\n";
    if (test_const('RSS')) $s_p .= '<link rel="alternate" type="application/rss+xml" href="'.URL_DU_SITE.'rss/'.FILE_RSS.'.xml" />';
    if (file_exists("favicon.ico")) $s_p .="<link rel=\"shortcut icon\" href=\"".URL_DU_SITE."favicon.ico\" />\n";
    print $s_p;

    if($this->edit==true){
      _prefix_chemin();
      include ("admin/"."config/users/".$_SESSION['hash_acces_utilisateur'].".inc");
      $_user_perso_= $_perso_; // reatributoin des droit utilisateur
      var_config_cst($_perso_,'_user_perso_');
      /* parametre linguistique generaux BO */
      $reponse=@include_once("admin/"."include/language/".$_user_perso_['pref_language'].".php");
      if (!$reponse) include ("admin/"."include/language/english.php");
      ## def img menu
      include('admin/template/'.THEME_ADMIN.'/inc/def_icon.inc');
      $this->edit_icon=$_PX_icons;
      define ('MMENU_IMG_UP',$_PX_icons['51']);
      define ('MMENU_IMG_DOWN',$_PX_icons['52']);
    }

    $rubri['starttime']=$starttime;
   $this->rubri=$s=$rubri;

  $this->function_js_init=$function_js_init;
  $this->t_dep=$t_dep;
  $this->t_conflit=$t_conflit;
  }

  /**
  */
  /*private*/ function appel_cache($dest){
     global $cstr;
    if(test_const('CACHE_PUBLIC'))  {
      $cstr->_add_class('HDAcache',"include/lib/class/class.cache.php", 3600 ,$dest , 86400 );
      if ( ! $cstr->_call('HDAcache','start_cache') ) exit;
    }
  }


  /**
    Recuperation du tabelau de dest
  */
  public function arry_dest(){
    return $this->rubri;
  }


  /**
    Draw
  */
  public function draw(){

    global $t_dep,$t_conflit,$function_js_init;
    $this->init_ctr_dep();
    if (!isset($this->ajax_dest)){
      $this->appel_cache($this->rubri['dest']);
        if (test_const('FERMETURE_DU_SITE')) $this->appel_cache($this->rubri['dest']);
        $this->appel_css($this->rubri);
        if($this->edit==true)appel_css_e();

        $this->function_js_init=$this->control_dep_modules($this->rubri,$this->ext_activ,$this->function_js_init, $t_dep,$t_conflit);
        $this->appel_files_modules('head',$this->rubri,$this->ext_activ);
        print   '<script type="text/javascript">'
                .'var url_du_site = "'.URL_DU_SITE.'"; '
                .'</script>';
        define('SORTIE','true');
        print  "</head>\n<body>\n"
              ."<div id=\"global\">\n";
    }

    $this->appel_template($this->rubri,'',$_POST,$_GET);
    if (!isset($this->ajax_dest))echo "</div>\n";

    if($this->edit==false) $this->appel_libs_page($this->rubri,$t_dep);
    elseif($this->edit==true){
      $this->function_js_init=appel_js_page_e($s['dest'],$this->function_js_init);
      menu_e($s['dest'],$this->edit_icon);
      ?>
      <div id="form_ajax" style="display: none;">
        <div id="form_ajax_bar"> <a onclick="{cache('form_ajax'); cache('backgd'); document.getElementById('form_ajax_txt').innerHTML='';}"><img src="template/<?php print NOM_DU_THEME ?>/img/close.png" alt="Close" style="float:right;"/></a></div>
        <div id='form_ajax_txt'></div>
        <div id='form_ajax_nav'></div>
      </div>
      <?php
    }
    echo "<p id='hidden_title' style='display:none;'>conception,realisation, cms lossim sans base de donnée<a href='http://www.lossim.org'>lossim</a></p>";
    if (!isset($this->ajax_dest)) $this->printFooter($this->rubri,$this->function_js_init);
  }

  /**
    Sortie object debugg
  */
  function debugg(){
      print_r($this);
  }
}
?>