template.class.inc.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Gestion templates
  4. * @author mathieu
  5. * @package db_object
  6. *
  7. */
  8. class template_manager extends db_object_manager{
  9. public $DB_DEBUG = false;
  10. public $FILE_DEBUG = false;
  11. public $_label = "Template";
  12. public $_fields = array(
  13. "ref" => array("label"=>"Référence courte", "type"=>"string", "readonly"=>true),
  14. "ref_right" => array("label"=>"Référence courte droite", "type"=>"string"),
  15. "ref_left" => array("label"=>"Référence courte gauche", "type"=>"string"),
  16. "ref_footer" => array("label"=>"Référence courte footer", "type"=>"string"),
  17. "description" => array("label"=>"Description", "type"=>"text"),
  18. "css" => array("label"=>"js", "type"=>"string"),
  19. "js" => array("label"=>"css", "type"=>"string"),
  20. //"params" => array("label"=>"Paramètres supplémentaires", "type"=>""),
  21. );
  22. public $_field_disp_list = array("ref", "css", "js");
  23. }
  24. class template extends db_object{
  25. public $controller;
  26. public $page;
  27. public $layout;
  28. public $template;
  29. public $menutop;
  30. public $header = array('js'=>array(), 'css'=>array());
  31. public $params = array();
  32. public function __tostring(){
  33. return $this->ref;
  34. }
  35. public function __construct($id=null, $info=null){
  36. return parent::__construct($id, $info);
  37. }
  38. /**
  39. * Menus
  40. */
  41. public function menu(){
  42. $menutop = array();
  43. $sql = "SELECT m.*
  44. FROM `menu` m
  45. JOIN `page` p ON p.`id`=m.`page_id`
  46. JOIN `controller` c ON c.`id`=p.`controller_id`
  47. WHERE m.`visible`=1
  48. ORDER BY m.`parent_id`, m.`pos`";
  49. $q = mysql_query($sql);
  50. //echo mysql_error();
  51. $row_parent = array();
  52. while($row=mysql_fetch_assoc($q)){
  53. $row['smenu'] = array();
  54. $row['params'] = array();
  55. if ($row["parent_id"]){
  56. if (isset($menutop[$row["parent_id"]])){
  57. $row_parent[$row["id"]] = $row["parent_id"];
  58. $menutop[$row["parent_id"]]["smenu"][$row["id"]] = $row;
  59. }
  60. // Pas de parent actif : on affiche pas
  61. else{
  62. }
  63. }
  64. else{
  65. $menutop[$row["id"]] = $row;
  66. }
  67. }
  68. $sql = "SELECT * FROM `menu_params` WHERE `value` IS NOT NULL";
  69. $q = mysql_query($sql);
  70. while($row=mysql_fetch_assoc($q)){
  71. if(isset($row_parent[$row['menu_id']]))
  72. $menutop[$row_parent[$row['menu_id']]]['smenu'][$row['menu_id']]['params'][$row['name']] = $row['value'];
  73. elseif(isset($menutop[$row['menu_id']]))
  74. $menutop[$row['menu_id']]['params'][$row['name']] = $row['value'];
  75. }
  76. //var_dump($menutop);
  77. $this->menutop = $menutop;
  78. }
  79. public function view_before(){
  80. $this->header['js'] = array_merge($this->header['js'], explode(',', $this->js));
  81. $this->header['css'] = array_merge($this->header['css'], explode(',', $this->css));
  82. //echo $this->css;
  83. //var_dump(explode(',', $this->css));
  84. $this->menu();
  85. }
  86. public function view(){
  87. }
  88. public function view_after(){
  89. }
  90. public function display(){
  91. $this->view_before();
  92. $this->view();
  93. $this->view_after();
  94. //var_dump($this->params);
  95. extract($this->params);
  96. if (file_exists($filename = PATH_TEMPLATE.'/'.$this->layout.'.tpl.php'))
  97. include $filename;
  98. else
  99. die('Layout '.$filename.' introuvable');
  100. }
  101. }