page.inc.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. $field_list = array(
  3. "visible" => array("label"=>"Visible Menu", "type"=>"bool"),
  4. "controller_id" => array("label"=>"Modèle de page", "type"=>"controller"),
  5. "parent_id" => array("label"=>"Page parente", "type"=>"page", "q"=>"id != '{page_id}' AND (parent_id IS NULL)"),
  6. "pos" => array("label"=>"Position", "type"=>"int"),
  7. "template" => array("label"=>"Template", "type"=>"text", "readonly"=>true),
  8. "css" => array("label"=>"CSS", "type"=>"text", "readonly"=>true),
  9. "js" => array("label"=>"JS", "type"=>"text", "readonly"=>true),
  10. "ref" => array("label"=>"REF", "type"=>"text", "readonly"=>true),
  11. "url" => array("label"=>"URL", "type"=>"text"),
  12. "sspage_default" => array("label"=>"Sous-page par défaut", "type"=>"page", "q"=>"parent_id = '{page_id}'"),
  13. "titre" => array("label"=>"Titre", "type"=>"text"),
  14. "header_title" => array("label"=>"Titre HTML", "type"=>"text"),
  15. "header_description" => array("label"=>"Description HTML", "type"=>"textarea"),
  16. );
  17. function page_list($parent_id=null, $add="")
  18. {
  19. $q = "SELECT page.*, parent_page.titre as parent_titre
  20. FROM page
  21. LEFT JOIN page AS parent_page ON parent_page.id = page.parent_id
  22. ".(is_numeric($parent_id)?"WHERE page.parent_id='".$parent_id."'":"WHERE page.parent_id IS NULL")."
  23. ORDER BY page.parent_id, page.`pos`";
  24. $query = mysql_query($q);
  25. while($row=mysql_fetch_assoc($query))
  26. {
  27. ?>
  28. <div class="<?php if (!$add) echo "rub"; elseif ($add == "=>&nbsp;") echo "srub"; ?>">
  29. <?php if ($add) echo "$add"; ?><a href="?page_id=<?php echo $row["id"]; ?>"><?php echo $row["titre"]; ?></a>
  30. </div>
  31. <?php
  32. page_list($row["id"], "=>&nbsp;$add");
  33. }
  34. //echo "$q : ".mysql_error()."</p>";
  35. }
  36. // ACTION
  37. if (isset($_POST["_page_update"]) && isset($_POST["page_id"]) && is_numeric($_POST["page_id"]))
  38. {
  39. $q_u = array();
  40. foreach($field_list as $name=>$field)
  41. {
  42. if (isset($_POST[$name]))
  43. {
  44. if ($field["type"]=="page")
  45. {
  46. if (is_numeric($_POST[$name]))
  47. $q_u[] = "`$name`='".$_POST[$name]."'";
  48. else
  49. $q_u[] = "`$name`=NULL";
  50. }
  51. elseif ($field["type"]=="controller")
  52. {
  53. if (is_numeric($_POST[$name]))
  54. $q_u[] = "`$name`='".$_POST[$name]."'";
  55. else
  56. $q_u[] = "`$name`=NULL";
  57. }
  58. elseif ($field["type"]=="text" || $field["type"]=="textarea")
  59. {
  60. $q_u[] = "`$name`='".mysql_real_escape_string($_POST[$name])."'";
  61. }
  62. elseif ($field["type"]=="bool" || ($field["type"]=="int"))
  63. {
  64. $q_u[] = "`$name`='".(int)($_POST[$name])."'";
  65. }
  66. }
  67. }
  68. if (count($q_u))
  69. {
  70. $q = "UPDATE page SET ".implode(", ", $q_u)." WHERE id='".$_POST["page_id"]."'";
  71. mysql_query($q);
  72. }
  73. }
  74. if (isset($_POST["_page_content_update"]) && isset($_POST["page_id"]) && is_numeric($_POST["page_id"]))
  75. {
  76. $q = "SELECT page.ref, page_content.*
  77. FROM page
  78. JOIN page_content ON page.id=page_content.page_id
  79. WHERE page_id='".$_POST["page_id"]."'";
  80. $r = mysql_query($q);
  81. while ($row=mysql_fetch_assoc($r))
  82. {
  83. $name = $row["name"];
  84. if ($row["type"]=="img")
  85. {
  86. $options = json_decode($row["options"], true);
  87. if (isset($_FILES[$name]) && $_FILES[$name]["tmp_name"])
  88. {
  89. //var_dump($options)
  90. $filename = str_replace(array("{ref}"), array($row["ref"]), $options["filename"]);
  91. move_uploaded_file($_FILES[$name]["tmp_name"], "../".$filename);
  92. }
  93. }
  94. else // texte
  95. {
  96. if (isset($_POST["content"][$name]) && is_string($_POST["content"][$name]))
  97. {
  98. $q = "UPDATE page_content SET `texte`='".mysql_real_escape_string($_POST["content"][$name])."' WHERE page_id='".$_POST["page_id"]."' AND `name`='".mysql_real_escape_string($name)."'";
  99. mysql_query($q);
  100. }
  101. }
  102. }
  103. }