123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- /**
- * Gestion templates
- * @author mathieu
- * @package db_object
- *
- */
- class template_manager extends db_object_manager{
- public $DB_DEBUG = false;
- public $FILE_DEBUG = false;
- public $_fields = array(
- "ref" => array("label"=>"Référence courte", "type"=>"string", "readonly"=>true),
- "ref_right" => array("label"=>"Référence courte droite", "type"=>"string"),
- "ref_left" => array("label"=>"Référence courte gauche", "type"=>"string"),
- "description" => array("label"=>"Description", "type"=>"text"),
- "css" => array("label"=>"js", "type"=>"string"),
- "js" => array("label"=>"css", "type"=>"string"),
- //"params" => array("label"=>"Paramètres supplémentaires", "type"=>""),
- );
- public $_field_disp_list = array("ref", "css", "js");
- }
- class template extends db_object{
- public $controller;
- public $page;
- public $layout;
- public $template;
- public $menutop;
- public $header = array('js'=>array(), 'css'=>array());
- public $params = array();
- public function __tostring(){
- return $this->ref;
- }
- public function __construct($id=null, $info=null){
- return parent::__construct($id, $info);
- }
- /**
- * Menus
- */
- public function menu(){
- $menutop = array();
- $sql = "SELECT m.*
- FROM `menu` m
- JOIN `page` p ON p.`id`=m.`page_id`
- JOIN `controller` c ON c.`id`=p.`controller_id`
- WHERE m.`visible`=1
- ORDER BY m.`parent_id`, m.`pos`";
- $q = mysql_query($sql);
- //echo mysql_error();
- $row_parent = array();
- while($row=mysql_fetch_assoc($q)){
- $row['smenu'] = array();
- $row['params'] = array();
- if ($row["parent_id"]){
- if (isset($menutop[$row["parent_id"]])){
- $row_parent[$row["id"]] = $row["parent_id"];
- $menutop[$row["parent_id"]]["smenu"][$row["id"]] = $row;
- }
- // Pas de parent actif : on affiche pas
- else{
- }
- }
- else{
- $menutop[$row["id"]] = $row;
- }
- }
- $sql = "SELECT * FROM `menu_params` WHERE `value` IS NOT NULL";
- $q = mysql_query($sql);
- while($row=mysql_fetch_assoc($q)){
- if(isset($row_parent[$row['menu_id']]))
- $menutop[$row_parent[$row['menu_id']]]['smenu'][$row['menu_id']]['params'][$row['name']] = $row['value'];
- elseif(isset($menutop[$row['menu_id']]))
- $menutop[$row['menu_id']]['params'][$row['name']] = $row['value'];
- }
- //var_dump($menutop);
- $this->menutop = $menutop;
- }
- public function view_before(){
- $this->header['js'] = array_merge($this->header['js'], explode(',', $this->js));
- $this->header['css'] = array_merge($this->header['css'], explode(',', $this->css));
- //echo $this->css;
- //var_dump(explode(',', $this->css));
- $this->menu();
- }
- public function view(){
- }
- public function view_after(){
- }
- public function display(){
- $this->view_before();
- $this->view();
- $this->view_after();
- //var_dump($this->params);
- extract($this->params);
- if (file_exists($filename = PATH_TEMPLATE.'/'.$this->layout.'.tpl.php'))
- include $filename;
- else
- die('Layout '.$filename.' introuvable');
- }
- }
|