template.class.inc.php 2.8 KB

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