Browse Source

Initialisation

Moulin Mathieu 8 years ago
commit
4274b3f33d
100 changed files with 6134 additions and 0 deletions
  1. 0 0
      .gitkeep
  2. 27 0
      .htaccess
  3. 0 0
      admin/.gitkeep
  4. 39 0
      admin/account.php
  5. 39 0
      admin/activite.php
  6. 39 0
      admin/actualite.php
  7. 39 0
      admin/cat.php
  8. 39 0
      admin/commonval.php
  9. 39 0
      admin/controller.php
  10. 0 0
      admin/css/.gitkeep
  11. 68 0
      admin/css/common.css
  12. 49 0
      admin/db_object_ajax.php
  13. 39 0
      admin/evenement.php
  14. 0 0
      admin/images/.gitkeep
  15. BIN
      admin/images/copy.png
  16. BIN
      admin/images/delete.gif
  17. BIN
      admin/images/edit.png
  18. 0 0
      admin/include/.gitkeep
  19. 2 0
      admin/include/.htaccess
  20. 41 0
      admin/include/actions.inc.php
  21. 24 0
      admin/include/common.inc.php
  22. 111 0
      admin/include/page.inc.php
  23. 33 0
      admin/index.php
  24. 39 0
      admin/menu.php
  25. 39 0
      admin/miniature.php
  26. 39 0
      admin/page.php
  27. 36 0
      admin/page.php.old
  28. 39 0
      admin/partenaire.php
  29. 39 0
      admin/realisation.php
  30. 39 0
      admin/template.php
  31. 0 0
      admin/template/.gitkeep
  32. 2 0
      admin/template/.htaccess
  33. 0 0
      admin/template/form/.gitkeep
  34. 281 0
      admin/template/form/db_object.tpl.php
  35. 279 0
      admin/template/form/db_object.tpl.php.orig
  36. 298 0
      admin/template/form/db_object.tpl.php.sav
  37. 27 0
      admin/template/form/menu.tpl.php
  38. 26 0
      admin/template/form/page.tpl.php
  39. 155 0
      admin/template/form/page.tpl.php.old
  40. 0 0
      admin/template/inc/.gitkeep
  41. 8 0
      admin/template/inc/header.tpl.php
  42. 14 0
      admin/template/inc/menu.tpl.php
  43. 0 0
      admin/template/page/.gitkeep
  44. 1 0
      admin/template/page/accueil.tpl.php
  45. 23 0
      admin/template/page/login.tpl.php
  46. 49 0
      admin/template/page/page.tpl.php
  47. 3 0
      cache/.gitignore
  48. 0 0
      cache/.gitkeep
  49. 2 0
      cache/.htaccess
  50. 0 0
      cache/img/.gitkeep
  51. 0 0
      cache/template/.gitkeep
  52. 26 0
      captcha.php
  53. 1 0
      config/.gitignore
  54. 0 0
      config/.gitkeep
  55. 14 0
      config/config.inc.php.dist
  56. 2 0
      css/.gitignore
  57. 0 0
      css/.gitkeep
  58. 1 0
      docs/.gitignore
  59. 0 0
      docs/.gitkeep
  60. 208 0
      img.php
  61. 2 0
      img/.gitignore
  62. 0 0
      img/.gitkeep
  63. 0 0
      include/.gitkeep
  64. 118 0
      include/autoload.inc.php
  65. 0 0
      include/class/.gitkeep
  66. 44 0
      include/class/account.class.inc.php
  67. 421 0
      include/class/captcha.class.inc.php
  68. 158 0
      include/class/controller.class.inc.php
  69. 1000 0
      include/class/db_object.class.inc.php
  70. 1005 0
      include/class/db_object.class.inc.php.orig
  71. 97 0
      include/class/menu.class.inc.php
  72. 215 0
      include/class/page.class.inc.php
  73. 130 0
      include/class/template.class.inc.php
  74. 75 0
      include/common.inc.php
  75. 0 0
      include/controller/.gitkeep
  76. 2 0
      include/controller/.htaccess
  77. 19 0
      include/controller/accueil.inc.php
  78. 41 0
      include/controller/activite.inc.php
  79. 18 0
      include/controller/activite_index.inc.php
  80. 35 0
      include/controller/actualite.inc.php
  81. 6 0
      include/controller/actualite_index.inc.php
  82. 24 0
      include/controller/cat.inc.php
  83. 7 0
      include/controller/construction.inc.php
  84. 66 0
      include/controller/contact.inc.php
  85. 6 0
      include/controller/contenu.inc.php
  86. 35 0
      include/controller/evenement.inc.php
  87. 24 0
      include/controller/evenement.inc.php.orig
  88. 15 0
      include/controller/intranet.inc.php
  89. 12 0
      include/controller/introuvable.inc.php
  90. 6 0
      include/controller/mentions.inc.php
  91. 41 0
      include/controller/miniature.inc.php
  92. 24 0
      include/controller/partenaire.inc.php
  93. 24 0
      include/controller/partenaire_cat.inc.php
  94. 24 0
      include/controller/partenaire_cat.inc.php.orig
  95. 6 0
      include/controller/partenaire_index.inc.php
  96. 46 0
      include/controller/password.inc.php
  97. 20 0
      include/controller/realisation.inc.php
  98. 16 0
      include/controller/realisation_index.inc.php
  99. 20 0
      include/controller/realisation_projet.inc.php
  100. 14 0
      include/controller/societe.inc.php

+ 0 - 0
.gitkeep


+ 27 - 0
.htaccess

@@ -0,0 +1,27 @@
+RewriteEngine On
+
+# Redirections domaine
+RewriteCond %{HTTP_HOST} !^www\.ardeche\-miniatures\.com [NC]
+RewriteRule ^/(.*) http://www.ardeche-miniatures\.com/$1 [L,R=301]
+# Redirections manuelles
+RewriteRule ^(MJ12[.]*)$ $1 [L]
+RewriteRule ^presentation.htm$ /notre-parc-14.html [L,QSA,R=301]
+RewriteRule ^index.html$ / [L,QSA,R=301]
+RewriteRule ^coulisse/coulisse_curiosites.htm$ /activite-11/explorer-les-paysages-du-departement-4.html [L,QSA,R=301]
+RewriteRule ^coulisse/coulisse_mallet.htm$ /miniature-20/locomotive-mallet-1.html [L,QSA,R=301]
+RewriteRule ^renct_05juin.htm$ /evenement-13/week-end-train-passion-3.html [L,QSA,R=301]
+
+# Images redimentionnees
+RewriteRule ^img2/([0-9]*)x([0-9]*)/(.+)$ /img.php?width=$1&height=$2&src=$3 [L]
+RewriteRule ^img2/([0-9]*)/(.+)$ /img.php?width=$1&height&src=$2 [L]
+
+# Page principale
+RewriteRule ^[a-zA-Z\-0-9]+\-([0-9]+).html$ index.php?_page_id=$1 [L,QSA]
+RewriteRule ^[a-zA-Z\-0-9]+\-([0-9]+)/[a-zA-Z0-9][a-zA-Z0-9\-]*\-([0-9]+).html$ index.php?_page_id=$1&_param_id=$2 [L,QSA]
+# Sous-page
+RewriteRule ^[a-zA-Z\-]+\-([0-9]+)\/\-[a-zA-Z0-9\-]+\-([0-9]+).html$ index.php?_page_id=$1&_sspage_id=$2 [L,QSA]
+RewriteRule ^[a-zA-Z\-]+\-([0-9]+)\/\-[a-zA-Z0-9\-]+\-([0-9]+)\/[a-zA-Z0-9][a-zA-Z0-9\-]*\-([0-9]+).html$ index.php?_page_id=$1&_sspage_id=$2&_param_id=$3 [L,QSA]
+
+#Alias /images/captcha.jpg captcha.php
+RewriteRule ^images\/captcha\.jpg$ captcha.php [L]
+

+ 0 - 0
admin/.gitkeep


+ 39 - 0
admin/account.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "account";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "account";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/activite.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "activite";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "activite";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/actualite.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "actualite";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "actualite";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/cat.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "cat";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "cat";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/commonval.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include PATH_ROOT."/include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "commonval";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "commonval";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/controller.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include PATH_ROOT."/include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "controller";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "controller";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 0 - 0
admin/css/.gitkeep


+ 68 - 0
admin/css/common.css

@@ -0,0 +1,68 @@
+body{
+	background: #323232;
+	color: #cdcdcd;
+}
+h1{
+	text-align: center;
+	font-size: 1.2em;
+}
+h2{
+	text-align: center;
+	font-size: 1.2em;
+}
+h3{
+	text-align: center;
+}
+a{
+	color: inherit;
+}
+.login{
+}
+.login table{
+	background: white;
+	border: 1px #cdcdcd solid;
+	width: 350px;
+}
+.login table th{
+	width: 40%;
+	color: black;
+}
+.login input{
+}
+.login input.field{
+	width: 100%;
+	background: #cdcdcd;
+}
+.logout{
+	float: right;
+	height: 20px;
+}
+.logout input{
+	font-size: 10pt;
+	height: 20px;
+}
+.menu{
+}
+.menu a{
+	padding: 0 5px;
+	margin: 0 5px;
+	border: 1px transparent solid;
+	text-decoration: none;
+}
+.menu a:hover{
+}
+.menu a.selected{
+	border-color: black;
+}
+.liste a{
+	text-decoration: none;
+}
+.liste .rub{
+	margin-top: 20px;
+	font-weight: bold;
+	font-size: 1.2em;
+}
+.liste .srub{
+	margin-top: 5px;
+	font-weight: bold;
+}

+ 49 - 0
admin/db_object_ajax.php

@@ -0,0 +1,49 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+
+session_start();
+
+if (!isset($_SESSION["account_id"]) || $_SESSION["account_type"] != "admin")
+	die();
+
+//var_dump($_POST);
+
+if (!isset($_POST["classname"]) || !is_string($classname=$_POST["classname"]) || !isset($object_list[$_POST["classname"]]))
+	die("Mauvais type d'objet");
+if (!isset($_POST["q"]) || !is_string($q=$_POST["q"]))
+	die("No query");
+if (!isset($_POST["fieldname"]) || !is_string($_POST["fieldname"]))
+	$_POST["fieldname"] = "id";
+if (!isset($_POST["param"]) || !is_array($_POST["param"]))
+	$_POST["param"] = array();
+
+// Paramètres de la requête
+$params = null;
+switch($classname)
+{
+	case "marque";
+		$params = "nom LIKE '%".mysql_real_escape_string($q)."%'";
+		break;
+}
+
+// Comptage
+if (($num=$classname()->count($params)) == 0)
+	die("<i>Aucun résultat</i>");
+// Limite
+if (isset($_GET["limit"]) && is_numeric($_GET["limit"]) && $_GET["limit"] > 0)
+	$nbmax = (int)$_GET["limit"];
+else
+	$nbmax = 0;
+
+// Affichage
+?>
+<select name="<?php echo $_POST["fieldname"]; ?>"<?php if (isset($_POST["autosubmit"])) echo " onchange=\"this.form.submit()\""; ?>><option value="">-<?php if ($nbmax && $num>$nbmax) echo "- ($nbmax premiers / $num total) -"; ?>-</option><?php
+foreach($classname()->select($params, $nbmax) as $object)
+{
+	echo "<option value=\"".$object->id."\" title=\"".$object."\">".$object."</option>";
+}
+if ($nbmax && $num > $nbmax)
+	echo "<option value=\"\">...</option>";
+?></select><?php if (isset($_POST["submitbutton"])) { ?><input type="submit" value="Choisir" /><?php } ?>

+ 39 - 0
admin/evenement.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "evenement";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "evenement";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 0 - 0
admin/images/.gitkeep


BIN
admin/images/copy.png


BIN
admin/images/delete.gif


BIN
admin/images/edit.png


+ 0 - 0
admin/include/.gitkeep


+ 2 - 0
admin/include/.htaccess

@@ -0,0 +1,2 @@
+order deny,allow
+deny from all

+ 41 - 0
admin/include/actions.inc.php

@@ -0,0 +1,41 @@
+<?php
+
+//var_dump($_POST);
+
+if (!isset($classname))
+	die("Paramètres requis");
+
+if (isset($_POST["_update"]))
+{
+	if (isset($_POST["id"]) && is_numeric($_POST["id"]) && ($object=$classname()->get($_POST["id"])))
+	{
+		$object->update($_POST);
+	}
+}
+elseif (isset($_POST["_delete"]))
+{
+	if (isset($_POST["id"]) && is_numeric($_POST["id"]) && ($object=$classname()->get($_POST["id"])))
+	{
+		$object->delete();
+		$_GET = array("list"=>"");
+	}
+}
+elseif (isset($_GET["delete_id"]))
+{
+	if (is_numeric($_GET["delete_id"]) && ($object=$classname()->get($_GET["delete_id"])))
+	{
+		$object->delete();
+		$_GET = array("list"=>"");
+	}
+}
+elseif (isset($_POST["_insert"]))
+{
+	$object = new $classname();
+	$object->insert($_POST);
+}
+elseif (isset($_GET["copy_id"]) && is_numeric($_GET["copy_id"]) && ($object=$classname()->get($_GET["copy_id"])))
+{
+	$o = $object->duplicate();
+	$_GET = array("id"=>$o->id);
+}
+

+ 24 - 0
admin/include/common.inc.php

@@ -0,0 +1,24 @@
+<?php
+
+$admin_menu_list = array(
+	"commonval"=>array('label'=>"Registre", 'perms'=>array('root', 'admin')),
+	"controller"=>array('label'=>"Controlleurs", 'perms'=>array('root')),
+	"template"=>array('label'=>"Templates", 'perms'=>array('root')),
+	"page"=>array('label'=>"Pages", 'perms'=>array('root', 'admin')),
+	"menu"=>array('label'=>"Menus", 'perms'=>array('root', 'admin')),
+
+	"account"=>array('label'=>"Comptes utilisateur", 'perms'=>array('root', 'admin')),
+
+	"activite"=>array('label'=>"Activités", 'perms'=>array('root', 'admin', 'user')),
+	//"realisation"=>array('label'=>"Réalisations", 'perms'=>array('root', 'admin', 'user')),
+	"actualite"=>array('label'=>"Actualités", 'perms'=>array('root', 'admin', 'user')),
+	"evenement"=>array('label'=>"Evénements", 'perms'=>array('root', 'admin', 'user')),
+	"cat"=>array('label'=>"Rubriques", 'perms'=>array('root', 'admin', 'user')),
+	"partenaire"=>array('label'=>"Partenaires", 'perms'=>array('root', 'admin', 'user')),
+	"miniature"=>array('label'=>"Miniatures", 'perms'=>array('root', 'admin', 'user')),
+);
+$menu_ref = "";
+
+if (!isset($_GET["menu"]) || !is_string($menu_ref=$_GET["menu"]) || !isset($admin_menu_list[$menu_ref]))
+	$menu_ref = "acceuil";
+

+ 111 - 0
admin/include/page.inc.php

@@ -0,0 +1,111 @@
+<?php
+
+$field_list = array(
+	"visible" => array("label"=>"Visible Menu", "type"=>"bool"),
+	"controller_id" => array("label"=>"Modèle de page", "type"=>"controller"),
+	"parent_id" => array("label"=>"Page parente", "type"=>"page", "q"=>"id != '{page_id}' AND (parent_id IS NULL)"),
+	"pos" => array("label"=>"Position", "type"=>"int"),
+	"template" => array("label"=>"Template", "type"=>"text", "readonly"=>true),
+	"css" => array("label"=>"CSS", "type"=>"text", "readonly"=>true),
+	"js" => array("label"=>"JS", "type"=>"text", "readonly"=>true),
+	"ref" => array("label"=>"REF", "type"=>"text", "readonly"=>true),
+	"url" => array("label"=>"URL", "type"=>"text"),
+	"sspage_default" => array("label"=>"Sous-page par défaut", "type"=>"page", "q"=>"parent_id = '{page_id}'"),
+	"titre" => array("label"=>"Titre", "type"=>"text"),
+	"header_title" => array("label"=>"Titre HTML", "type"=>"text"),
+	"header_description" => array("label"=>"Description HTML", "type"=>"textarea"),
+);
+
+function page_list($parent_id=null, $add="")
+{
+
+$q = "SELECT page.*, parent_page.titre as parent_titre
+	FROM page
+	LEFT JOIN page AS parent_page ON parent_page.id = page.parent_id
+	".(is_numeric($parent_id)?"WHERE page.parent_id='".$parent_id."'":"WHERE page.parent_id IS NULL")."
+	ORDER BY page.parent_id, page.`pos`";
+$query = mysql_query($q);
+while($row=mysql_fetch_assoc($query))
+{
+?>
+<div class="<?php if (!$add) echo "rub"; elseif ($add == "=>&nbsp;") echo "srub"; ?>">
+<?php if ($add) echo "$add"; ?><a href="?page_id=<?php echo $row["id"]; ?>"><?php echo $row["titre"]; ?></a>
+</div>
+<?php
+page_list($row["id"], "=>&nbsp;$add");
+}
+//echo "$q : ".mysql_error()."</p>";
+
+}
+
+// ACTION
+
+if (isset($_POST["_page_update"]) && isset($_POST["page_id"]) && is_numeric($_POST["page_id"]))
+{
+	$q_u = array();
+	foreach($field_list as $name=>$field)
+	{
+		if (isset($_POST[$name]))
+		{
+			if ($field["type"]=="page")
+			{
+				if (is_numeric($_POST[$name]))
+					$q_u[] = "`$name`='".$_POST[$name]."'";
+				else
+					$q_u[] = "`$name`=NULL";
+			}
+			elseif ($field["type"]=="controller")
+			{
+				if (is_numeric($_POST[$name]))
+					$q_u[] = "`$name`='".$_POST[$name]."'";
+				else
+					$q_u[] = "`$name`=NULL";
+			}
+			elseif ($field["type"]=="text" || $field["type"]=="textarea")
+			{
+				$q_u[] = "`$name`='".mysql_real_escape_string($_POST[$name])."'";
+			}
+			elseif ($field["type"]=="bool" || ($field["type"]=="int"))
+			{
+				$q_u[] = "`$name`='".(int)($_POST[$name])."'";
+			}
+		}
+	}
+	if (count($q_u))
+	{
+		$q = "UPDATE page SET ".implode(", ", $q_u)." WHERE id='".$_POST["page_id"]."'";
+		mysql_query($q);
+	}
+}
+
+if (isset($_POST["_page_content_update"]) && isset($_POST["page_id"]) && is_numeric($_POST["page_id"]))
+{
+	$q = "SELECT page.ref, page_content.*
+		FROM page
+		JOIN page_content ON page.id=page_content.page_id
+		WHERE page_id='".$_POST["page_id"]."'";
+	$r = mysql_query($q);
+	while ($row=mysql_fetch_assoc($r))
+	{
+		$name = $row["name"];
+		if ($row["type"]=="img")
+		{
+			$options = json_decode($row["options"], true);
+			if (isset($_FILES[$name]) && $_FILES[$name]["tmp_name"])
+			{
+				//var_dump($options)
+				$filename = str_replace(array("{ref}"), array($row["ref"]), $options["filename"]);
+				move_uploaded_file($_FILES[$name]["tmp_name"], "../".$filename);
+			}
+		}
+		else // texte
+		{
+			if (isset($_POST["content"][$name]) && is_string($_POST["content"][$name]))
+			{
+				$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)."'";
+				mysql_query($q);
+			}
+		}
+	}
+}
+

+ 33 - 0
admin/index.php

@@ -0,0 +1,33 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], array('root', 'admin', 'user')))
+{
+
+include "template/inc/menu.tpl.php";
+include "template/page/accueil.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/menu.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include PATH_ROOT."/include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "menu";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "menu";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/miniature.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "miniature";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "miniature";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/page.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include PATH_ROOT."/include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "page";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "page";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 36 - 0
admin/page.php.old

@@ -0,0 +1,36 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && $_SESSION["account_type"] == "admin")
+{
+
+$menu_ref = "page";
+include "template/inc/menu.tpl.php";
+
+include "include/page.inc.php";
+include "template/page/page.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/partenaire.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "partenaire";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "partenaire";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/realisation.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include "../include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "realisation";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "realisation";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 39 - 0
admin/template.php

@@ -0,0 +1,39 @@
+<?php
+
+include "../config/config.inc.php";
+include PATH_ROOT."/include/common.inc.php";
+include "include/common.inc.php";
+
+$menu_ref = "template";
+$menu = $admin_menu_list[$menu_ref];
+
+?>
+<html>
+<head>
+<?php
+include "template/inc/header.tpl.php";
+?>
+</head>
+<body>
+<?php
+// Aff
+if (isset($_SESSION["account_id"]) && in_array($_SESSION["account_type"], $menu['perms']))
+{
+
+include "template/inc/menu.tpl.php";
+
+$classname = "template";
+include "include/actions.inc.php";
+include "template/form/db_object.tpl.php";
+
+}
+else
+{
+
+include "template/page/login.tpl.php";
+
+}
+
+?>
+</body>
+</html>

+ 0 - 0
admin/template/.gitkeep


+ 2 - 0
admin/template/.htaccess

@@ -0,0 +1,2 @@
+order deny,allow
+deny from all

+ 0 - 0
admin/template/form/.gitkeep


+ 281 - 0
admin/template/form/db_object.tpl.php

@@ -0,0 +1,281 @@
+<script type="text/javascript">
+var date;
+function select_object(object, params)
+{
+	//alert(params);
+	if (params == undefined || !params)
+		var s_params = {};
+	else
+		var s_params = params;
+	for(i in s_params)
+		alert(i+" : "+s_params[i]);
+	s_params.classname = object.alt;
+	s_params.fieldname = object.id.substr(1, object.id.length-6);
+	s_params.q = object.value;
+	//alert(params.q);
+	var thisdate = new Date().getTime();
+	date = thisdate;
+	setTimeout(function(){q_object(s_params, thisdate);}, '500');
+}
+function q_object(params, thisdate)
+{
+	if (date == thisdate)
+	{
+		$.post("db_object_ajax.php", params, function(data){
+			//alert(data);
+			$("#_"+params.fieldname+"_select").html(data);
+		});
+	}
+}
+$(document).ready(function(){
+	$("input.select_object").keypress(function(){select_object(this);});
+});
+</script>
+<style type="text/css">
+p{
+	margin: 0;
+}
+p, td, th, li, input, select, textarea {
+	font-size: inherit;
+}
+form.db_object{
+	width: auto;
+	font-size: 0.85em;
+}
+form.db_object table{
+	width: 100%;
+}
+form.db_object th{
+	text-align: left;
+}
+form.db_object th.label{
+	width: 250px;
+}
+form.db_object td.field input{
+	width: 100%;
+}
+form.db_object td.field input.number{
+	width: 14em;
+}
+form.db_object td.field  textarea{
+	width: 100%;
+	height: 10em;
+}
+form.db_object td.field  textarea.richtext{
+	height: 20em;
+}
+.list td, .list th{
+	vertical-align: top;
+}
+.list th{
+	text-align: left;
+}
+</style>
+</head>
+<body>
+<h1><?php echo $classname()->_label; ?></h1>
+<p>
+	<a href="?list">Liste</a>
+	| <a href="?add">Ajouter</a>
+</p>
+<?php
+
+/* SELECT TEMPLATE */
+
+// Modification
+if (isset($_GET["id"]) && ($object=$classname()->get($_GET["id"])))
+{
+
+$template = "form";
+
+}
+
+// Ajout
+elseif (isset($_GET["add"]))
+{
+
+$template = "form";
+$object = new $classname();
+
+}
+
+// Liste
+else
+{
+
+$template = "list";
+
+}
+
+/* DISPLAY TEMPLATE */
+
+if ($template == "form")
+{
+?>
+<form class="db_object" method="post" action="?id=<?php echo $object->id; ?>" enctype="multipart/form-data">
+<table>
+<?php if ($object->id) { ?>
+<tr>
+	<th>ID</th>
+	<td><?php echo $object->id; ?><input name="id" type="hidden" value="<?php echo $object->id; ?>" /></td>
+</tr>
+<?php } ?>
+<?php foreach($classname()->_fields as $name=>$field) if (in_array($field['type'], $classname()->field_simple) && (empty($field["calculate"])) && ($object->id || empty($field["notinsert"])) && (!$object->id || empty($field["notupdate"]))) { ?>
+<tr>
+	<th class="label"><?php echo $field["label"]; ?> :</th>
+	<td class="field"><?php
+	if (!empty($field["readonly"]))
+		echo "<script type=\"text/javascript\">$(document).ready(function(){ $('.db_object [name=".$name."]').attr('disabled','true'); });</script>\n";
+	if ($field["type"] == "text")
+	{
+		echo "<textarea name=\"".$name."\">".$object->$name."</textarea>";
+	}
+	elseif ($field["type"] == "richtext")
+	{
+		echo "<textarea class=\"ckeditor\" id=\"".$name."\" name=\"".$name."\">".$object->$name."</textarea>";
+	}
+	elseif ($field["type"] == "string")
+	{
+		echo "<input name=\"".$name."\" value=\"".htmlentities($object->$name, ENT_COMPAT, "UTF-8")."\" />";
+	}
+	elseif ($field["type"] == "password")
+	{
+		echo "<input type=\"password\" name=\"".$name."\" value=\"".$object->$name."\" />";
+	}
+	elseif ($field["type"] == "object")
+	{
+		$object_class = $field["object_type"];
+		if ($object_class()->count() < 20)
+		{
+		?>
+		<select name="<?php echo $name; ?>"><option value="">--</option><?php
+		foreach ($object_class()->select() as $o)
+			echo "<option value=\"".$o->id."\"".($object->$name==$o->id?" selected":"").">".$o."</option>";
+		?></select>
+		<?php
+		}
+		else
+		{
+		?>
+		<input type="hidden" name="<?php echo $name; ?>" value="<?php echo $object->$name; ?>" />
+		<input class="select_object" alt="<?php echo $object_class; ?>" id="<?php echo "_".$name."_name"; ?>" value="<?php echo (($object->$name)?$object_class()->get($object->$name):""); ?>" />
+		<div id="<?php echo "_".$name."_select"; ?>"></div>
+		<?php
+		}
+	}
+	elseif (in_array($field["type"], array("int", "numeric", "float")))
+	{
+		echo "<input class=\"number\" name=\"".$name."\" value=\"".$object->$name."\" />";
+	}
+	elseif (in_array($field["type"], array("bool", "boolean")))
+	{
+		echo "<input type=\"radio\" name=\"".$name."\" value=\"0\"".(is_numeric($object->$name) && !$object->$name ?" checked" : "")." style=\"width:20px;\" /> NON <input type=\"radio\" name=\"".$name."\" value=\"1\"".(is_numeric($object->$name) && $object->$name ?" checked" : "")." style=\"width:20px;\" /> OUI";
+	}
+	elseif($field["type"] == "img")
+	{
+		if (isset($field["filename"]))
+			 echo "<div style=\"float:right;\"><img src=\"/".$field["folder"]."/".$object->field_map_replace($field["filename"])."\" /></div>";
+		elseif ($object->$name)
+			echo "<div style=\"float:right;\"><img src=\"/".$object->file($name)."\" /></div>";
+		if (isset($field["filename"]))
+			echo "<input type=\"hidden\" name=\"".$name."\" value=\"".$object->$name."\" /> ";
+		else
+			echo "<input name=\"".$name."\" value=\"".$object->$name."\" /> ";
+		echo " <input type=\"file\" name=\"".$name."\" />";
+	}
+	elseif($field["type"] == "file")
+	{
+		if ($object->$name)
+			echo "<div style=\"float:right;\"><a href=\"/".$object->file($name)."\">Télécharger</a></div>";
+		echo "<input name=\"".$name."\" value=\"".$object->$name."\" /> <input type=\"file\" name=\"".$name."\" />";
+	}
+	elseif(in_array($field["type"], array("timestamp", "datetime")))
+	{
+		echo date_mysql($object->$name);
+	}
+	elseif($field["type"] = "date")	
+	{
+		echo "<input name=\"".$name."\" value=\"".$object->$name."\" class=\"date\" />";
+	}
+	elseif($field["type"] == "select")
+	{
+		echo "<select name=\"".$name."\"><option value=\"\">-- Choisir --</option>";
+		foreach($field["list"] as $i=>$j)
+			echo "<option value=\"".$i."\"".($i==$object->$name ?" selected" : "").">".$j."</option>";
+		echo "</select>";
+	}
+	elseif($field["type"] == "select_multiple")
+	{
+		echo "<input name=\"".$name."\" value=\"\" type=\"hidden\" /><select name=\"".$name."[]\" multiple>";
+		foreach($field["list"] as $i=>$j)
+			echo "<option value=\"".$i."\"".(is_array($object->$name)&&in_array($i, $object->$name) ?" selected" : "").">".$j."</option>";
+		echo "</select>";
+	}
+	elseif($field["type"] == "object_list")
+	{
+		//echo "<input type=\"hidden\" name=\"".$name."\" />";
+		$classname = $field["object_type"];
+		if (is_array($object->$name))
+		{
+			foreach($object->$name as $i)
+				echo "<p><a href=\"javascript:;\" style=\"color: red;\">X</a> ".($classname()->get($i))."</p>\n";
+		}
+	}
+	?></td>
+</tr>
+<?php } ?>
+<tr>
+	<td>&nbsp;</td>
+	<td><?php if ($object->id) { ?>
+		<input type="submit" name="_update" value="Mettre à jour" />
+		<input type="submit" name="_delete" value="Supprimer" style="color:red;" onclick="return (confirm('Supprimer ?'))" />
+		<?php } else { ?>
+		<input type="submit" name="_insert" value="Ajouter" />
+		<?php } ?></td>
+</tr>
+</table>
+</form>
+<?php if (file_exists($filename=PATH_ROOT."/admin/template/form/$classname.tpl.php")) { include $filename; } ?>
+<?php
+}
+// Liste
+else //if ($template == "list")
+{
+?>
+<h3>Liste</h3>
+<table class="list">
+<tr>
+	<td colspan="2">&nbsp;</td>
+<?php foreach ($classname()->_field_disp_list as $name) { ?>
+	<th><?php echo $classname()->_fields[$name]["label"]; ?></th>
+<?php } ?>
+</tr>
+<?php foreach($classname()->select() as $object) { ?>
+<tr>
+<td><a href="?delete_id=<?php echo $object->id; ?>" onclick="return confirm('Êtes-vous certain de vouloir supprimer cet enregistrement ?')"><img src="images/delete.gif" alt="Supprimer" title="Supprimer" /></a></td>
+<td><a href="?id=<?php echo $object->id; ?>"><img src="images/edit.png" alt="Mettre à jour" title="Modifier" /></a></td>
+<?php foreach ($classname()->_field_disp_list as $name) { ?>
+	<td><?php
+		$field = $classname()->_fields[$name];
+		$type = $field["type"];
+		if (in_array($type, array('bool', 'boolean'))) {
+			echo $object->$name ?'OUI' :'NON';
+		}
+		elseif ($type=="object" && is_numeric($object->$name)) {
+			$object_type = $field["object_type"];
+			echo $object_type()->get($object->$name);
+		}
+		elseif (is_string($object->$name))
+			echo $object->$name;
+		elseif (is_array($object->$name))
+			echo implode(", ", $object->$name);
+		else
+			echo "&nbsp;";
+	 ?></td>
+<?php } ?>
+</tr>
+<?php } ?>
+</table>
+<?php
+}
+?>

+ 279 - 0
admin/template/form/db_object.tpl.php.orig

@@ -0,0 +1,279 @@
+<script type="text/javascript">
+var date;
+function select_object(object, params)
+{
+	//alert(params);
+	if (params == undefined || !params)
+		var s_params = {};
+	else
+		var s_params = params;
+	for(i in s_params)
+		alert(i+" : "+s_params[i]);
+	s_params.classname = object.alt;
+	s_params.fieldname = object.id.substr(1, object.id.length-6);
+	s_params.q = object.value;
+	//alert(params.q);
+	var thisdate = new Date().getTime();
+	date = thisdate;
+	setTimeout(function(){q_object(s_params, thisdate);}, '500');
+}
+function q_object(params, thisdate)
+{
+	if (date == thisdate)
+	{
+		$.post("db_object_ajax.php", params, function(data){
+			//alert(data);
+			$("#_"+params.fieldname+"_select").html(data);
+		});
+	}
+}
+$(document).ready(function(){
+	$("input.select_object").keypress(function(){select_object(this);});
+});
+</script>
+<style type="text/css">
+p{
+	margin: 0;
+}
+p, td, th, li, input, select, textarea {
+	font-size: inherit;
+}
+form.db_object{
+	width: auto;
+	font-size: 0.85em;
+}
+form.db_object table{
+	width: 100%;
+}
+form.db_object th{
+	text-align: left;
+}
+form.db_object th.label{
+	width: 250px;
+}
+form.db_object td.field input{
+	width: 100%;
+}
+form.db_object td.field input.number{
+	width: 14em;
+}
+form.db_object td.field  textarea{
+	width: 100%;
+	height: 10em;
+}
+form.db_object td.field  textarea.richtext{
+	height: 20em;
+}
+.list td, .list th{
+	vertical-align: top;
+}
+.list th{
+	text-align: left;
+}
+</style>
+</head>
+<body>
+<h1><?php echo $classname()->_label; ?></h1>
+<p>
+	<a href="?list">Liste</a>
+	| <a href="?add">Ajouter</a>
+</p>
+<?php
+
+/* SELECT TEMPLATE */
+
+// Modification
+if (isset($_GET["id"]) && ($object=$classname()->get($_GET["id"])))
+{
+
+$template = "form";
+
+}
+
+// Ajout
+elseif (isset($_GET["add"]))
+{
+
+$template = "form";
+$object = new $classname();
+
+}
+
+// Liste
+else
+{
+
+$template = "list";
+
+}
+
+/* DISPLAY TEMPLATE */
+
+if ($template == "form")
+{
+?>
+<form class="db_object" method="post" action="?id=<?php echo $object->id; ?>" enctype="multipart/form-data">
+<table>
+<?php if ($object->id) { ?>
+<tr>
+	<th>ID</th>
+	<td><?php echo $object->id; ?><input name="id" type="hidden" value="<?php echo $object->id; ?>" /></td>
+</tr>
+<?php } ?>
+<?php foreach($classname()->_fields as $name=>$field) if (in_array($field['type'], $classname()->field_simple)) { ?>
+<tr>
+	<th class="label"><?php echo $field["label"]; ?> :</th>
+	<td class="field"><?php
+	if (!empty($field["readonly"]) && $object->id)
+		echo "<script type=\"text/javascript\">$(document).ready(function(){ $('.db_object [name=".$name."]').attr('disabled','true'); });</script>\n";
+	if ($field["type"] == "text")
+	{
+		echo "<textarea name=\"".$name."\">".$object->$name."</textarea>";
+	}
+	elseif ($field["type"] == "richtext")
+	{
+		echo "<textarea class=\"ckeditor\" id=\"".$name."\" name=\"".$name."\">".$object->$name."</textarea>";
+	}
+	elseif ($field["type"] == "string")
+	{
+		echo "<input name=\"".$name."\" value=\"".htmlentities($object->$name, ENT_COMPAT, "UTF-8")."\" />";
+	}
+	elseif ($field["type"] == "password")
+	{
+		echo "<input type=\"password\" name=\"".$name."\" value=\"".$object->$name."\" />";
+	}
+	elseif ($field["type"] == "object")
+	{
+		$object_class = $field["object_type"];
+		if ($object_class()->count() < 20)
+		{
+		?>
+		<select name="<?php echo $name; ?>"><option value="">--</option><?php
+		foreach ($object_class()->select() as $o)
+			echo "<option value=\"".$o->id."\"".($object->$name==$o->id?" selected":"").">".$o."</option>";
+		?></select>
+		<?php
+		}
+		else
+		{
+		?>
+		<input type="hidden" name="<?php echo $name; ?>" value="<?php echo $object->$name; ?>" />
+		<input class="select_object" alt="<?php echo $object_class; ?>" id="<?php echo "_".$name."_name"; ?>" value="<?php echo (($object->$name)?$object_class()->get($object->$name):""); ?>" />
+		<div id="<?php echo "_".$name."_select"; ?>"></div>
+		<?php
+		}
+	}
+	elseif (in_array($field["type"], array("int", "numeric", "float")))
+	{
+		echo "<input class=\"number\" name=\"".$name."\" value=\"".$object->$name."\" />";
+	}
+	elseif (in_array($field["type"], array("bool", "boolean")))
+	{
+		echo "<input type=\"radio\" name=\"".$name."\" value=\"0\"".(is_numeric($object->$name) && !$object->$name ?" checked" : "")." style=\"width:20px;\" /> NON <input type=\"radio\" name=\"".$name."\" value=\"1\"".(is_numeric($object->$name) && $object->$name ?" checked" : "")." style=\"width:20px;\" /> OUI";
+	}
+	elseif($field["type"] == "img")
+	{
+		if (isset($field["filename"]))
+			 echo "<div style=\"float:right;\"><img src=\"/".$field["folder"]."/".$object->field_map_replace($field["filename"])."\" /></div>";
+		elseif ($object->$name)
+			echo "<div style=\"float:right;\"><img src=\"/".$object->file($name)."\" /></div>";
+		if (isset($field["filename"]))
+			echo "<input type=\"hidden\" name=\"".$name."\" value=\"".$object->$name."\" /> ";
+		else
+			echo "<input name=\"".$name."\" value=\"".$object->$name."\" /> ";
+		echo " <input type=\"file\" name=\"".$name."\" />";
+	}
+	elseif($field["type"] == "file")
+	{
+		if ($object->$name)
+			echo "<div style=\"float:right;\"><a href=\"/".$object->file($name)."\">Télécharger</a></div>";
+		echo "<input name=\"".$name."\" value=\"".$object->$name."\" /> <input type=\"file\" name=\"".$name."\" />";
+	}
+	elseif(in_array($field["type"], array("timestamp", "datetime")))
+	{
+		echo date_mysql($object->$name);
+	}
+	elseif($field["type"] = "date")	
+	{
+		echo "<input name=\"".$name."\" value=\"".$object->$name."\" class=\"date\" />";
+	}
+	elseif($field["type"] == "select")
+	{
+		echo "<select name=\"".$name."\"><option value=\"\">-- Choisir --</option>";
+		foreach($field["list"] as $i=>$j)
+			echo "<option value=\"".$i."\"".($i==$object->$name ?" selected" : "").">".$j."</option>";
+		echo "</select>";
+	}
+	elseif($field["type"] == "select_multiple")
+	{
+		echo "<input name=\"".$name."\" value=\"\" type=\"hidden\" /><select name=\"".$name."[]\" multiple>";
+		foreach($field["list"] as $i=>$j)
+			echo "<option value=\"".$i."\"".(is_array($object->$name)&&in_array($i, $object->$name) ?" selected" : "").">".$j."</option>";
+		echo "</select>";
+	}
+	elseif($field["type"] == "object_list")
+	{
+		//echo "<input type=\"hidden\" name=\"".$name."\" />";
+		$classname = $field["object_type"];
+		if (is_array($object->$name))
+		{
+			foreach($object->$name as $i)
+				echo "<p><a href=\"javascript:;\" style=\"color: red;\">X</a> ".($classname()->get($i))."</p>\n";
+		}
+	}
+	?></td>
+</tr>
+<?php } ?>
+<tr>
+	<td>&nbsp;</td>
+	<td><?php if ($object->id) { ?>
+		<input type="submit" name="_update" value="Mettre à jour" />
+		<input type="submit" name="_delete" value="Supprimer" style="color:red;" onclick="return (confirm('Supprimer ?'))" />
+		<?php } else { ?>
+		<input type="submit" name="_insert" value="Ajouter" />
+		<?php } ?></td>
+</tr>
+</table>
+</form>
+<?php if (file_exists($filename=PATH_ROOT."/admin/template/form/$classname.tpl.php")) { include $filename; } ?>
+<?php
+}
+// Liste
+else //if ($template == "list")
+{
+?>
+<h3>Liste</h3>
+<table class="list">
+<tr>
+	<td colspan="2">&nbsp;</td>
+<?php foreach ($classname()->_field_disp_list as $name) { ?>
+	<th><?php echo $classname()->_fields[$name]["label"]; ?></th>
+<?php } ?>
+</tr>
+<?php foreach($classname()->select() as $object) { ?>
+<tr>
+<td><a href="?delete_id=<?php echo $object->id; ?>" onclick="return confirm('Êtes-vous certain de vouloir supprimer cet enregistrement ?')"><img src="images/delete.gif" alt="Supprimer" title="Supprimer" /></a></td>
+<td><a href="?id=<?php echo $object->id; ?>"><img src="images/edit.png" alt="Mettre à jour" title="Modifier" /></a></td>
+<?php foreach ($classname()->_field_disp_list as $name) { ?>
+	<td><?php
+		$field = $classname()->_fields[$name];
+		$type = $field["type"];
+		if ($type=="object" && is_numeric($object->$name))
+		{
+			$object_type = $field["object_type"];
+			echo $object_type()->get($object->$name);
+		}
+		elseif (is_string($object->$name))
+			echo $object->$name;
+		elseif (is_array($object->$name))
+			echo implode(", ", $object->$name);
+		else
+			echo "&nbsp;";
+	 ?></td>
+<?php } ?>
+</tr>
+<?php } ?>
+</table>
+<?php
+}
+?>

+ 298 - 0
admin/template/form/db_object.tpl.php.sav

@@ -0,0 +1,298 @@
+<script type="text/javascript">
+var date;
+function select_object(object, params)
+{
+	//alert(params);
+	if (params == undefined || !params)
+		var s_params = {};
+	else
+		var s_params = params;
+	for(i in s_params)
+		alert(i+" : "+s_params[i]);
+	s_params.classname = object.alt;
+	s_params.fieldname = object.id.substr(1, object.id.length-6);
+	s_params.q = object.value;
+	//alert(params.q);
+	var thisdate = new Date().getTime();
+	date = thisdate;
+	setTimeout(function(){q_object(s_params, thisdate);}, '500');
+}
+function q_object(params, thisdate)
+{
+	if (date == thisdate)
+	{
+		$.post("db_object_ajax.php", params, function(data){
+			//alert(data);
+			$("#_"+params.fieldname+"_select").html(data);
+		});
+	}
+}
+$(document).ready(function(){
+	$("input.select_object").keypress(function(){select_object(this);});
+});
+</script>
+<style type="text/css">
+p{
+	margin: 0;
+}
+p, td, th, li, input, select, textarea {
+	font-size: inherit;
+}
+form.db_object{
+	width: auto;
+	font-size: 0.85em;
+}
+form.db_object table{
+	width: 100%;
+}
+form.db_object th{
+	text-align: left;
+}
+form.db_object th.label{
+	width: 250px;
+}
+form.db_object td.field input{
+	width: 100%;
+}
+form.db_object td.field input.number{
+	width: 14em;
+}
+form.db_object td.field  textarea{
+	width: 100%;
+	height: 10em;
+}
+form.db_object td.field  textarea.richtext{
+	height: 20em;
+}
+.list td, .list th{
+	vertical-align: top;
+}
+.list th{
+	text-align: left;
+}
+</style>
+</head>
+<body>
+<h1><?php echo $page_title; ?></h1>
+<p>
+	<a href="?list">Liste</a>
+	| <a href="?add">Ajouter</a>
+</p>
+<?php
+
+/* SELECT TEMPLATE */
+
+// Modification
+if (isset($_GET["id"]) && ($object=$classname($_GET["id"])))
+{
+
+$template = "form";
+
+}
+
+// Ajout
+elseif (isset($_GET["add"]))
+{
+
+$template = "form";
+$object = new $classname();
+
+}
+
+// Liste
+else
+{
+
+$template = "list";
+
+}
+
+/* DISPLAY TEMPLATE */
+
+if ($template == "form")
+{
+?>
+<form class="db_object" method="post" action="?id=<?php echo $object->id; ?>" enctype="multipart/form-data">
+<table>
+<?php if ($object->id) { ?>
+<tr>
+	<th>ID</th>
+	<td><?php echo $object->id; ?><input name="id" type="hidden" value="<?php echo $object->id; ?>" /></td>
+</tr>
+<?php } ?>
+<?php foreach($classname()->_fields as $name=>$field) { ?>
+<tr>
+	<th class="label"><?php echo $field["label"]; ?> :</th>
+	<td class="field"><?php
+	if ($field["type"] == "text")
+	{
+		echo "<textarea name=\"".$name."\">".$object->$name."</textarea>";
+	}
+	elseif ($field["type"] == "richtext")
+	{
+		if (isset($field["textmode"]) && $field["textmode"] == "rich") { ?>
+		<script type="text/javascript">
+		tinyMCE.init({
+		mode : "exact",
+		elements : "<?php echo $name; ?>",
+		theme : "advanced",
+		force_br_newlines : "true",
+		plugins : "table,zoom,paste,searchreplace,insertdatetime,directionality,print,paste,ibrowser",
+		button_tile_map : true,
+		//theme_advanced_buttons1_add : "fontsizeselect",//fontselect,,separator
+		theme_advanced_buttons2_add : "separator,forecolor,backcolor",//print,separator,insertdate,inserttime,
+		theme_advanced_buttons2: "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,separator,charmap,pastetext,code,ibrowser",//,separator,hr,removeformat
+		theme_advanced_buttons3: "separator",
+		theme_advanced_buttons3_add_before: "tablecontrols,separator,pastetext,selectall,search,replace",//pasteword,,ltr,rtl
+		paste_create_paragraphs : false,
+		paste_create_linebreaks : false,
+		paste_use_dialog : true,
+		paste_auto_cleanup_on_paste : true,
+		paste_convert_middot_lists : false,
+		paste_unindented_list_class : "unindentedList",
+		paste_convert_headers_to_strong : true,
+		theme_advanced_blockformats : "p,h1,h2,h3",
+		theme_advanced_toolbar_location : "top",  
+		content_css : "../css/wyziwyg.css",
+		external_image_list_url : "script/image_list.js",
+		language : "fr",
+		preformatted : false,
+		invalid_elements : "div,span"
+		});
+		</script>
+		<?php } else {//if ($field["textmode"] == "light") ?>
+		<script type="text/javascript">
+		tinyMCE.init({
+		mode : "exact",
+		elements : "<?php echo $name; ?>",
+		theme : "advanced",
+		plugins : "paste,ibrowser",
+		force_br_newlines : true,
+		theme_advanced_buttons1: "bold,italic,underline,strikethrough,link,unlink,undo,redo,cleanup,bullist,numlist,pastetext,code,ibrowser",
+		theme_advanced_buttons2: "",
+		theme_advanced_buttons3: "",
+		convert_newlines_to_brs: true,
+		button_tile_map : true,
+		language : "fr",
+		preformatted : false,
+		invalid_elements : "div,span"
+		});
+		</script>
+		<?php }
+		echo "<textarea class=\"richtext\" id=\"".$name."\" name=\"".$name."\">".$object->$name."</textarea>";
+	}
+	elseif ($field["type"] == "string")
+	{
+		echo "<input name=\"".$name."\" value=\"".$object->$name."\" />";
+	}
+	elseif ($field["type"] == "object")
+	{
+		$object_class = $field["object_type"];
+		?>
+		<input type="hidden" name="<?php echo $name; ?>" value="<?php echo $object->$name; ?>" />
+		<input class="select_object" alt="<?php echo $object_class; ?>" id="<?php echo "_".$name."_name"; ?>" value="<?php echo (($object->$name)?$object_class()->get($object->$name):""); ?>" />
+		<div id="<?php echo "_".$name."_select"; ?>"></div>
+		<?php
+	}
+	elseif (in_array($field["type"], array("int", "numeric", "float")))
+	{
+		echo "<input class=\"number\" name=\"".$name."\" value=\"".$object->$name."\" />";
+	}
+	elseif ($field["type"] == "bool")
+	{
+		echo "<input type=\"radio\" name=\"".$name."\" value=\"0\"".(is_numeric($object->$name) && !$object->$name ?" checked" : "")." /> NON <input type=\"radio\" name=\"".$name."\" value=\"1\"".(is_numeric($object->$name) && $object->$name ?" checked" : "")." /> OUI";
+	}
+	elseif($field["type"] == "img")
+	{
+		if ($object->$name)
+			echo "<div style=\"float:right;\"><img src=\"/".$object->file($name)."\" /></div>";
+		echo "<input name=\"".$name."\" value=\"".$object->$name."\" /> <input type=\"file\" name=\"".$name."\" />";
+	}
+	elseif($field["type"] == "file")
+	{
+		if ($object->$name)
+			echo "<div style=\"float:right;\"><a href=\"/".$object->file($name)."\">Télécharger</a></div>";
+		echo "<input name=\"".$name."\" value=\"".$object->$name."\" /> <input type=\"file\" name=\"".$name."\" />";
+	}
+	elseif($field["type"] == "timestamp")
+	{
+		echo date_mysql($object->$name);
+	}
+	elseif($field["type"] == "select")
+	{
+		echo "<select name=\"".$name."\"><option value=\"\">-- Choisir --</option>";
+		foreach($field["list"] as $i=>$j)
+			echo "<option value=\"".$i."\"".($i==$object->$name ?" selected" : "").">".$j."</option>";
+		echo "</select>";
+	}
+	elseif($field["type"] == "select_multiple")
+	{
+		echo "<input name=\"".$name."\" value=\"\" type=\"hidden\" /><select name=\"".$name."[]\" multiple>";
+		foreach($field["list"] as $i=>$j)
+			echo "<option value=\"".$i."\"".(is_array($object->$name)&&in_array($i, $object->$name) ?" selected" : "").">".$j."</option>";
+		echo "</select>";
+	}
+	elseif($field["type"] == "object_list")
+	{
+		//echo "<input type=\"hidden\" name=\"".$name."\" />";
+		$classname = $field["object_type"];
+		if (is_array($object->$name))
+		{
+			foreach($object->$name as $i)
+				echo "<p><a href=\"javascript:;\" style=\"color: red;\">X</a> ".($classname()->get($i))."</p>\n";
+		}
+	}
+	?></td>
+</tr>
+<?php } ?>
+<tr>
+	<td>&nbsp;</td>
+	<td><?php if ($object->id) { ?>
+		<input type="submit" name="_update" value="Mettre à jour" />
+		<input type="button" name="_delete" value="Supprimer" style="color:red;" onclick="if (confirm('Supprimer ?')) this.form.submit();" />
+		<?php } else { ?>
+		<input type="submit" name="_insert" value="Ajouter" />
+		<?php } ?></td>
+</tr>
+</table>
+</form>
+<?php
+}
+// Liste
+else //if ($template == "list")
+{
+?>
+<h3>Liste</h3>
+<table class="list">
+<tr>
+	<td>&nbsp;</td>
+<?php foreach ($classname()->_field_disp_list as $name) { ?>
+	<th><?php echo $classname()->_fields[$name]["label"]; ?></th>
+<?php } ?>
+</tr>
+<?php foreach($classname()->select() as $object) { ?>
+<tr>
+<td><a href="?id=<?php echo $object->id; ?>"><img src="images/edit.png" alt="Mettre à jour" /></a></td>
+<?php foreach ($classname()->_field_disp_list as $name) { ?>
+	<td><?php
+		$field = $classname()->_fields[$name];
+		$type = $field["type"];
+		if ($type=="object" && is_numeric($object->$name))
+		{
+			$object_type = $field["object_type"];
+			echo $object_type()->get($object->$name);
+		}
+		elseif (is_string($object->$name))
+			echo $object->$name;
+		elseif (is_array($object->$name))
+			echo implode(", ", $object->$name);
+		else
+			echo "&nbsp;";
+	 ?></td>
+<?php } ?>
+</tr>
+<?php } ?>
+</table>
+<?php
+}
+?>

+ 27 - 0
admin/template/form/menu.tpl.php

@@ -0,0 +1,27 @@
+<?php if ($object->id) { ?>
+<form class="db_object" method="post">
+<h3>Paramètre supplémentaire</h3>
+<?php
+$menu = $object;
+$page = $menu->page();
+$controller = $page->controller();
+//var_dump($controller);
+$fields = $controller->fields;
+$params = $menu->params;
+//var_dump($params);
+?>
+<input name="id" type="hidden" value="<?php echo $menu->id; ?>" />
+<table>
+<?php foreach ($fields as $name=>$field) if ($field['url_get']) { ?>
+<tr>
+	<th class="label"><?php echo $field["description"]; ?> :</th>
+	<td class="field"><?php echo field_form("params[$name]", $field, isset($params[$name]) ?$params[$name] :null); ?></td>
+</tr>
+<?php } ?>
+</table>
+<tr>
+	<th>&nbsp;</th>
+	<td><input type="submit" name="_update" value="Mettre à jour" /></td>
+</tr>
+</form>
+<?php } ?>

+ 26 - 0
admin/template/form/page.tpl.php

@@ -0,0 +1,26 @@
+<?php if ($object->id) { ?>
+<form class="db_object" method="post" enctype="multipart/form-data">
+<h3>Paramètres supplémentaires</h3>
+<?php
+$page = $object;
+$controller = $page->controller();
+//var_dump($controller);
+$fields = $controller->fields;
+$params = $page->params;
+//var_dump($params);
+?>
+<table>
+<input name="id" type="hidden" value="<?php echo $page->id; ?>" />
+<?php foreach ($fields as $name=>$field) { ?>
+<tr>
+	<th class="label"><?php echo $field["description"]; ?> :<br /><span style="font-size:10px;font-weight: normal; text-transform: italic;"><?php echo $field["commentaire"]; ?></span></th>
+	<td class="field"><?php echo field_form("params[$name]", $field, isset($params[$name]) ?$params[$name] :null); ?></td>
+</tr>
+<?php } ?>
+</table>
+<tr>
+	<th>&nbsp;</th>
+	<td><input type="submit" name="_update" value="Mettre à jour" /></td>
+</tr>
+</form>
+<?php } ?>

+ 155 - 0
admin/template/form/page.tpl.php.old

@@ -0,0 +1,155 @@
+<script type="text/javascript">
+</script>
+
+<style type="text/css">
+form th{
+	text-align: left;
+}
+form.form_page input{
+	width: 100%;
+}
+form.form_page textarea{
+	width: 100%;
+	height: 10em;
+}
+form.form_content_page textarea{
+	width: 100%;
+	height: 20em;
+}
+</style>
+
+<h2>Page <?php echo $form_data["titre"]; ?></h2>
+
+<form class="form_page" method="post">
+<input type="hidden" name="page_id" value="<?php echo $form_data["id"]; ?>" />
+<table align="center">
+<tr>
+	<td width="250"></td>
+	<td width="400"></td>
+</tr>
+<?php
+foreach($field_list as $name=>$field) if (in_array($name, array("controller_id", "parent_id", "sspage_default", "pos", "visible", "titre", "header_title", "header_description")))
+{
+?>
+<tr>
+	<th><label><?php echo $field["label"]; ?> :</label></th>
+<?php if ($field["type"] == "select") { ?>
+	<td><select name="<?php echo $name; ?>"><option value="">--</option><?php
+		foreach($field["list"] as $i=>$j)
+			echo "<option value='".$i."'".((is_numeric($form_data[$name]) && $form_data[$name]==$i)?" selected":"").">".$j."</option>";
+	?></select></td>
+<?php } elseif ($field["type"] == "bool") { ?>
+	<td>
+		<input type="radio" name="<?php echo $name; ?>" value="0"<?php if (!$form_data[$name]) echo " checked=\"checked\""; ?> style="width:30px;" /> NON
+		<input type="radio" name="<?php echo $name; ?>" value="1"<?php if ($form_data[$name]) echo " checked=\"checked\""; ?> style="width:30px;" /> OUI
+	</td>
+<?php } elseif ($field["type"] == "textarea") { ?>
+	<td><textarea name="<?php echo $name; ?>"><?php echo $form_data[$name]; ?></textarea></td>
+<?php } elseif ($field["type"] == "page") { ?>
+	<td><select name="<?php echo $name; ?>"><option value="">-- Choisir si besoin --</option><?php
+	if ($form_data["id"])
+		$q = "SELECT id, titre FROM page WHERE ".str_replace("{page_id}", $form_data["id"], $field["q"])." ORDER BY parent_id, `pos`";
+	else
+		$q = "SELECT id, titre FROM page WHERE 1 ORDER BY parent_id, `pos`";
+	$query = mysql_query($q);
+	while($row=mysql_fetch_assoc($query))
+	{
+		echo "<option value='".$row["id"]."'".((is_numeric($form_data[$name]) && $form_data[$name]==$row["id"])?" selected":"").">".$row["titre"]."</option>";
+	}
+	?></select></td>
+<?php } elseif ($field["type"] == "controller") { ?>
+	<td><select name="<?php echo $name; ?>"><option value="">-- Choisir si besoin --</option><?php
+	$q = "SELECT id, titre FROM controller WHERE 1";
+	$query = mysql_query($q);
+	while($row=mysql_fetch_assoc($query))
+	{
+		echo "<option value='".$row["id"]."'".((is_numeric($form_data[$name]) && $form_data[$name]==$row["id"])?" selected":"").">".$row["titre"]."</option>";
+	}
+	?></select></td>
+<?php } else { ?>
+	<td><input name="<?php echo $name; ?>" value="<?php echo $form_data[$name]; ?>"<?php if (isset($field["readonly"])) echo " readonly"; ?> /></td>
+<?php } ?>
+</tr>
+<?php
+}
+?>
+<tr>
+	<td>&nbsp;</td>
+	<td><input type="submit" name="_page_update" value="Mettre à jour" style="width: auto;" /></td>
+</tr>
+</table>
+</form>
+
+<?php if (count($form_content_data)) { ?>
+<hr />
+<h3>Contenu de la page</h3>
+<form method="get">
+<input type="hidden" name="menu" value="page" />
+<input type="hidden" name="page_id" value="<?php echo $form_data["id"]; ?>" />
+<p align="center"><select name="content" onchange="this.form.submit()"><option value="">-- Choisir le contenu à editer --</option><?php foreach($form_content_data as $name=>$field) { ?>
+<option value="<?php echo $name; ?>"<?php if (isset($_GET["content"]) && $_GET["content"]==$name) echo " selected"; ?>><?php echo $field["description"]; ?></option>
+<?php } ?></select></p>
+</form>
+<?php } ?>
+
+<?php if (count($form_content_data) && isset($_GET["content"])) { ?>
+<form class="form_content_page" method="post" enctype="multipart/form-data">
+<input type="hidden" name="page_id" value="<?php echo $form_data["id"]; ?>" />
+<table align="center">
+<tr>
+	<td width="250"></td>
+	<td width="700"></td>
+</tr>
+<?php
+foreach($form_content_data as $name=>$field) if ($_GET["content"] == $name)
+{
+	$options = json_decode($field["options"], true);
+	//var_dump($options);
+	if ($field["type"]=="richtext") {
+?>
+<tr>
+	<th><label><?php echo $field["description"]; ?> :</label></th>
+	<td><textarea class="ckeditor" name="content[<?php echo $name; ?>]"><?php echo $field["texte"]; ?></textarea></td>
+</tr>
+<?php
+	} elseif ($field["type"]=="textarea") {
+?>
+<tr>
+	<th><label><?php echo $field["description"]; ?> :</label></th>
+	<td><textarea name="content[<?php echo $name; ?>]"><?php echo $field["texte"]; ?></textarea></td>
+</tr>
+<?php
+	} elseif ($field["type"]=="img") {
+?>
+<tr>
+	<th><label><?php echo $field["description"]; ?> :</label></th>
+	<td><input type="file" name="<?php echo $name; ?>" />
+	<?php if (file_exists($filename="../".str_replace("{ref}", $form_data["ref"], $options["filename"]))) { ?><br /><img src="/<?php echo $filename; ?>" /></td><?php } ?>
+</tr>
+<?php
+	} elseif ($field["type"]=="object") {
+?>
+	<th><label><?php echo $field["description"]; ?> :</label></th>
+	<td><select name="<?php echo $name; ?>"><option value="">--</option><?php
+	$object_type = (is_array($options) && isset($options["object_type"])) ?$options["object_type"] :"";
+	if (function_exists($object_type)) foreach ($object_type()->select() as $o)
+		echo "<option value=\"".$o->id."\"".($field["texte"]==$o->id?" selected":"").">".$o."</option>";
+	?></select>
+<?php
+	} else {
+
+?>
+<tr>
+	<th><label><?php echo $field["description"]; ?> :</label></th>
+	<td><input name="content[<?php echo $name; ?>]" value="<?php echo $field["texte"]; ?>" /></td>
+</tr>
+<?php }
+}
+?>
+<tr>
+	<td>&nbsp;</td>
+	<td><input type="submit" name="_page_content_update" value="Mettre à jour" style="width: auto;" /></td>
+</tr>
+</table>
+</form>
+<?php } ?>

+ 0 - 0
admin/template/inc/.gitkeep


+ 8 - 0
admin/template/inc/header.tpl.php

@@ -0,0 +1,8 @@
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Administration <?php echo DOMAIN; ?></title>
+<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
+<script type="text/javascript" src="/js/md5.js"></script>
+<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
+<script type="text/javascript" src="/js/ckfinder/ckfinder.js"></script>
+<script type="text/javascript" src="/js/admin.js"></script>
+<link href="css/common.css" rel="stylesheet" type="text/css" />

+ 14 - 0
admin/template/inc/menu.tpl.php

@@ -0,0 +1,14 @@
+<form class="logout" method="post"><input type="submit" name="_logout" value="Déconnexion" /></form>
+<h1>Administration <?php echo SITE_NAME; ?></h1>
+<p class="menu"><?php
+
+foreach($admin_menu_list as $i=>$j) if (in_array($_SESSION["account_type"], $j['perms']))
+{
+	if ($menu_ref==$i)
+		echo "<a href=\"$i.php\" class=\"selected\">".$j['label']."</a> ";
+	else
+		echo "<a href=\"$i.php\">".$j['label']."</a> ";
+}
+
+?></p>
+<hr style="clear: both;" />

+ 0 - 0
admin/template/page/.gitkeep


+ 1 - 0
admin/template/page/accueil.tpl.php

@@ -0,0 +1 @@
+<h3>Bienvenue</h3>

+ 23 - 0
admin/template/page/login.tpl.php

@@ -0,0 +1,23 @@
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+<h1>Interface d'administration du site <?php echo SITE_NAME; ?></h1>
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+
+<form class="login" method="post">
+<input name="password" type="hidden" />
+<table style="border: 1px gray solid;" align="center">
+<tr>
+	<th>Email :</th>
+	<td><input name="username" class="field" /></td>
+</tr>
+<tr>
+	<th>Mot de passe :</th>
+	<td><input name="password_bis" type="password" class="field" /></td>
+</tr>
+<tr>
+	<th>&nbsp;</th>
+	<td><input type="submit" name="_login" value="Connexion" /></td>
+</tr>
+</table>
+</form>

+ 49 - 0
admin/template/page/page.tpl.php

@@ -0,0 +1,49 @@
+<?php
+
+// TEMPLATE
+
+if (isset($_GET["add"]))
+{
+	
+$form_data = array("id"=>null);
+foreach($field_list as $i=>$j)
+	$form_data[$i] = "";
+
+$form_content_data = array();
+	
+include "template/form/page.tpl.php";
+
+}
+
+elseif (isset($_GET["page_id"]) && is_numeric($_GET["page_id"]))
+{
+
+$q = "SELECT * FROM page WHERE id='".$_GET["page_id"]."'";
+$query = mysql_query($q);
+$form_data = mysql_fetch_assoc($query);
+//var_dump($form_data);
+
+$q = "SELECT name, type, description, options, commentaire, texte FROM page_content WHERE page_id='".$_GET["page_id"]."'";
+$query = mysql_query($q);
+$form_content_data = array();
+while($row = mysql_fetch_assoc($query))
+	$form_content_data[$row["name"]] = $row;
+
+//var_dump($form_content_data);
+
+include "template/form/page.tpl.php";
+
+}
+
+else
+{
+
+?>
+<div class="liste">
+<?php page_list(); ?>
+</div>
+<?php
+
+}
+
+?>

+ 3 - 0
cache/.gitignore

@@ -0,0 +1,3 @@
+img/*
+template/*
+

+ 0 - 0
cache/.gitkeep


+ 2 - 0
cache/.htaccess

@@ -0,0 +1,2 @@
+order deny,allow
+deny from all

+ 0 - 0
cache/img/.gitkeep


+ 0 - 0
cache/template/.gitkeep


+ 26 - 0
captcha.php

@@ -0,0 +1,26 @@
+<?php
+
+session_start();
+include ("include/class/captcha.class.inc.php");
+
+$nb_lettre = 6;
+$font_size = 12;
+
+$Captcha = new captcha('PNG');
+$Captcha->setStringLenght($nb_lettre);
+$Captcha->setFont('include/font/Bleeding_Cowboys.ttf' , $font_size);
+$Captcha->setBorderColor(0,0,0);
+$Captcha->setBorderWidth(0);
+$Captcha->setBackgroundColor(255,255,255);
+//$Captcha -> setImageWidth(150);
+$Captcha -> setImageHeight(24);
+$Captcha -> setTextColor(0, 0, 0);
+$Captcha -> setTextAngle(0);
+$Captcha -> setMarginFromBorder(6);
+$Captcha -> setShadow(-5,-5);
+$Captcha -> setShadowColor(230, 230, 230);
+
+$_SESSION['captcha'] = $Captcha->getRandString();
+
+$Captcha->getImage();
+

+ 1 - 0
config/.gitignore

@@ -0,0 +1 @@
+*

+ 0 - 0
config/.gitkeep


+ 14 - 0
config/config.inc.php.dist

@@ -0,0 +1,14 @@
+<?php
+
+define("DB_HOST", "localhost");
+define("DB_USER", "");
+define("DB_PASS", "");
+define("DB_BASE", "");
+
+define("PATH_ROOT", realpath(dirname(__FILE__)."/.."));
+
+define("PATH_INCLUDE", PATH_ROOT."/include");
+define("PATH_TEMPLATE", PATH_ROOT."/include/template");
+
+#error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
+

+ 2 - 0
css/.gitignore

@@ -0,0 +1,2 @@
+*
+**

+ 0 - 0
css/.gitkeep


+ 1 - 0
docs/.gitignore

@@ -0,0 +1 @@
+*

+ 0 - 0
docs/.gitkeep


+ 208 - 0
img.php

@@ -0,0 +1,208 @@
+<?php
+
+if (!defined('PATH_ROOT')){
+        define("PATH_ROOT", realpath(dirname(__FILE__)));
+        define("PATH_IMG", PATH_ROOT.'/img');
+	define("PATH_CACHE", PATH_ROOT.'/cache/img');
+}
+
+define('IMG_CACHE_EXPIRES', 30*24*60*60); // 30 jours
+
+$quality = 75;
+
+$source = (isset($_GET["src"]) && is_string($_GET["src"])) ?$_GET["src"] :"";
+$width = (isset($_GET["width"]) && is_string($_GET["width"])) ?$_GET["width"] :"";
+$height = (isset($_GET["height"]) && is_string($_GET["height"])) ?$_GET["height"] :"";
+$p = (isset($_GET["p"]) && is_string($_GET["p"])) ?$_GET["p"] :"";
+
+// Vérif existance image à traiter
+if (! $source || ! file_exists(PATH_IMG.'/'.$source))
+	die();
+$source_path = realpath(PATH_IMG.'/'.$source);
+//var_dump($source_path); die();
+
+//$source = realpath(PATH_IMG.'/'.$source);
+
+// Chemin
+$basename = basename($source);
+list($nom, $ext) = explode(".", $basename);
+
+// header standard pour la mise en cache
+header("Cache-Control: max-age=2592000"); // 30 jours
+header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', ($time=time()) + IMG_CACHE_EXPIRES));
+
+// Vérif date fichier
+$last_modified_time = filemtime($source_path);
+header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
+// header image
+switch(strtolower($ext)) {
+	case 'jpg':
+		header('Content-Type: image/jpeg');
+		break;
+	case 'png':
+		header('Content-Type: image/png');
+		break;
+	case 'gif':
+		header('Content-Type: image/gif');
+		break;
+	default:
+		break;
+}
+
+$cache_filename = PATH_CACHE.'/'.$width."x".$height."/".$source;
+//echo $cache_filename; die();
+
+// Flush headers
+flush();
+
+if (! $width && ! $height) {
+	readfile($source_path);
+	die();
+}
+
+
+// Vérif cache
+$cache_test = PATH_CACHE.'/'.$width."x".$height;
+if (!file_exists($cache_test))
+	mkdir($cache_test);
+
+$source_e = explode('/', dirname($source));
+foreach($source_e as $i) {
+	$cache_test .= "/".$i;
+	if (!file_exists($cache_test))
+		mkdir($cache_test);
+	//echo $cache_test.'<br />';
+}
+if (file_exists($cache_filename) && filemtime($cache_filename)>=$last_modified_time) {
+	//echo "yeah";
+	readfile($cache_filename);
+	die();
+}
+
+// Régénération image
+
+switch(strtolower($ext)){
+	case 'jpg':
+		$src_img=imagecreatefromjpeg($source_path);
+		break;
+	case 'png':
+		$src_img=imagecreatefrompng($source_path);
+		break;
+	case 'gif':
+		$src_img=imagecreatefromgif($source_path);
+		break;
+	default:
+		die();
+		break;
+}
+
+//Taille de l'image originale
+$w = imagesx($src_img);
+$h = imagesy($src_img);
+$r = $w/$h;
+
+if ($width > $w)
+	$width = $w;
+if ($height > $h)
+	$height = $h;
+
+//Récupère les proportions
+if ($width!="" && $height!="") {
+	$ratio = $width/$height;
+	
+	$p = $width/$w;
+	// width/height = w/h <=> height < width/r
+	if ($ratio < $r){
+		//
+	}
+	
+	$imageInfo = array($width,$height);
+	$default_size = 55;
+	// On calcul la proportion pour afficher l'image
+	if($imageInfo[0] > $imageInfo[1])
+	{
+		if($imageInfo[0] < $default_size)
+		{
+			$width = $default_size;
+		}
+		else
+		{
+			$width = $imageInfo[0];
+		}
+		$ratio = $width/$imageInfo[0];
+		$height = $imageInfo[1] * $ratio;				
+	}
+	elseif($imageInfo[0] == $imageInfo[1])
+	{
+		if($imageInfo[0] < $default_size)
+		{
+			$width = $default_size;
+			$height = $default_size;
+		} 
+		else 
+		{
+			$width = $imageInfo[0];
+			$height = $imageInfo[1];
+		}				
+	}
+	else
+	{
+		if($imageInfo[1] < $default_size)
+		{
+			$height = $default_size;	
+		}
+		else
+		{
+			$height = $imageInfo[1];	
+		}			
+		$ratio = $height/$imageInfo[1];
+		$width = $imageInfo[0] * $ratio;
+									
+	}
+}
+elseif ($p!="") {
+	$height = $p * $width;
+}
+elseif ($width) {
+	$p = $h / $w;
+	$height = $p * $width;
+}
+elseif ($height) {
+	$p = $h / $w;
+	$width = $height / $p;
+}
+else {
+	$p = $h / $w;
+	$width = $w;
+	$height = $h;
+}
+
+if(strtolower($ext)!='gif'){
+	$dst_img = imagecreatetruecolor($width, $height);
+}
+else{
+	$color_transparent = imagecolortransparent($src_img);  
+	if ($color_transparent > 0)
+		$dst_img = imagecreate($width, $height);	
+	else
+		$dst_img = imagecreatetruecolor($width, $height);		
+	imagepalettecopy($dst_img,$src_img);				
+	if ($color_transparent > 0){
+		imagefill($dst_img,0,0,$color_transparent);
+	    imagecolortransparent($dst_img, $color_transparent);			
+	}
+}	
+
+imagecopyresampled($dst_img,$src_img,0,0,0,0,$width,$height,$w,$h);
+if(strtolower($ext)=='jpg')
+	imagejpeg($dst_img, $cache_filename, $quality);
+else if(strtolower($ext)=='png')	
+	imagepng($dst_img, $cache_filename);
+else if(strtolower($ext)=='gif')	
+	imagegif($dst_img, $cache_filename);
+
+readfile($cache_filename);
+
+if($src_img)
+	imagedestroy ($src_img);		
+imagedestroy ($dst_img);

+ 2 - 0
img/.gitignore

@@ -0,0 +1,2 @@
+*
+**

+ 0 - 0
img/.gitkeep


+ 0 - 0
include/.gitkeep


+ 118 - 0
include/autoload.inc.php

@@ -0,0 +1,118 @@
+<?php
+
+$object_list = array(
+	// Native
+	//"db_object"=>array(),
+	"menu"=>array(),
+	"template"=>array(),
+	"controller"=>array(),
+	"page"=>array(),
+	"commonval"=>array(),
+	// Project
+	"account"=>array(),
+	"activite"=>array(),
+	"realisation"=>array(),
+	"actualite"=>array(),
+	"evenement"=>array(),
+	"cat"=>array(),
+	"partenaire"=>array(),
+	"miniature"=>array(),
+);
+
+// MANUAL ACCESSOR DEFINITION
+
+
+// AUTOMATIC ACCESSOR DEFINITION
+
+/**
+ * Retrieve an objet defined
+ *
+ * @param string $t
+ * @param int $params
+ * @return db_object_manager|db_object|bool
+ */
+function object($t, $params=null)
+{
+
+	static $list;
+	if (!$list)
+		$list = $GLOBALS["object_list"];
+	if (!is_string($t) || !isset($list[$t]))
+		return;
+
+	$p = &$list[$t];
+	$n = "${t}_manager";
+	$l = &$list[$n];
+
+	// Object de gestion
+	if (!isset($l))
+	{
+		if (!empty($p["cache"]) && ($object=apc_fetch($n)))
+		{
+			$l = $object;
+		}
+		else
+		{
+			$l = new $n();
+			if (!empty($p["cache"]))
+				apc_store($n, $l);
+		}
+	}
+
+	// Renvoi de l'objet de gestion
+	if ($params === null)
+	{
+		return $l;
+	}
+	// Renvoi si objet existant
+	else
+	{
+		if ($object=$l->get($params))
+			return $object;
+		else
+			return false;
+	}
+
+}
+
+// Default definition of accessors
+foreach($object_list as $name=>$i)
+{
+	if (!function_exists($name))
+	{
+		eval("function $name(\$params=null) { return object(\"$name\", \$params); }");
+	}
+}
+
+/**
+ * Autoload class function
+ * @param string $class_name
+ */
+function __autoload($class_name)
+{
+
+if (!is_string($class_name))
+	return;
+
+if (substr($class_name, -11, 11) == "_controller"){
+	if (file_exists($filename=PATH_ROOT."/include/controller/".substr($class_name, 0, -11).'.inc.php'))
+		include $filename;
+	else
+		eval('class '.$class_name.' extends controller {}');
+}
+elseif ((substr($class_name, -8, 8) != "_manager" || ($class_name=substr($class_name, 0, -8))) && isset($GLOBALS["object_list"][$class_name])){
+	if (file_exists($filename=PATH_ROOT."/include/class/$class_name.class.inc.php"))
+		include $filename;
+	elseif (file_exists($filename=PATH_ROOT."/include/model/$class_name.class.inc.php"))
+		include $filename;
+	else
+		die('Model '.$class_name.' not found, file not found '.$filename);
+}
+elseif (file_exists($filename=PATH_ROOT."/include/class/$class_name.class.inc.php")){
+	include $filename;
+}
+else{
+	die('Class '.$class_name.' not found, file not found '.$filename);
+}
+
+}

+ 0 - 0
include/class/.gitkeep


+ 44 - 0
include/class/account.class.inc.php

@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * Gestion comptes
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class account_manager extends db_object_manager
+{
+
+public $DB_DEBUG = false;
+public $FILE_DEBUG = false;
+
+public $_fields = array(
+	"type" => array("label"=>"Type", "type"=>"select", "list"=>array("admin"=>"Administrateur", "user"=>"Utilisateur", "client"=>"Client")),
+	"nom" => array("label"=>"Nom", "type"=>"string"),
+	"email" => array("label"=>"Email", "type"=>"string"),
+	"password" => array("label"=>"Mot de passe", "type"=>"password"),
+	"actif" => array("label"=>"Actif", "type"=>"bool"),
+);
+public $_field_disp_list = array("type", "nom", "email", 'actif');
+
+}
+
+/**
+ * Activité
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class account extends db_object
+{
+
+public function __tostring()
+{
+
+return (string)$this->nom;
+
+}
+
+}
+
+?>

+ 421 - 0
include/class/captcha.class.inc.php

@@ -0,0 +1,421 @@
+<?php 
+
+class captcha {
+
+	private $randString = '';
+	private $stringLength = 10;
+	private $imageWidth = false;
+	private $imageHeight = false;
+	private $background = true;
+	private $backgroundColor = array('R'=>255, 'V'=>255, 'B'=>255);
+	private $borderColor = array('R'=>226, 'V'=>113, 'B'=>59);
+	private $borderWidth = 0;
+	private $textColor = array('R'=>0, 'V'=>0, 'B'=>0);
+	private $forbiddenChars= array(1,0,'l','0');
+	private $font = '';
+	private $fontSize = 15;
+	private $fromBorder = 10;
+	private $type = '';
+	private $shadow = false;
+	private $shadowColor = array('R'=>128, 'V'=>128, 'B'=>128);
+	private $shadowX = 2;
+	private $shadowY = 2;
+	private $backgroundImage = false;
+	private $textAngle = 0;
+	private $roundedCorners = false;
+	private $roundedCornersRadius = 5;
+
+	/**
+	 * Constructeur - fixe le type d'image : PNG,GIF,JPEG
+	 *
+	 * @param string $type type de l'image
+	 */
+	public function __construct($type='PNG') {
+		$this->setImageType($type);
+	}
+
+	/**
+	 * Fixe la longueur de la chaîne aléatoire générée
+	 *
+	 * @param int $lenght longueur de la chaîne
+	 */
+	public function setStringLenght($lenght) {
+		$this->stringLength = $lenght;
+	}
+
+	/**
+	 * Fixe la couleur de fond de l'image
+	 *
+	 * @param int $R rouge
+	 * @param int $V vert
+	 * @param int $B bleu
+	 */
+	public function setBackgroundColor($R,$V,$B) {
+		$this->backgroundColor['R'] = $R;
+		$this->backgroundColor['V'] = $V;
+		$this->backgroundColor['B'] = $B;
+	}
+
+	/**
+	 * Fixe la couleur de la bordure
+	 *
+	 * @param int $R rouge
+	 * @param int $V vert
+	 * @param int $B bleu
+	 */
+	public function setBorderColor($R,$V,$B) {
+		$this->borderColor['R'] = $R;
+		$this->borderColor['V'] = $V;
+		$this->borderColor['B'] = $B;
+	}
+
+	/**
+	 * Fixe la taille de la bordure
+	 *
+	 * @param int $width taille en pixel de la bordure
+	 */
+	public function setBorderWidth($width) {
+		$this->borderWidth = (int)$width;
+	}
+
+	/**
+	 * Fixe la couleur du texte
+	 *
+	 * @param int $R rouge
+	 * @param int $V vert
+	 * @param int $B bleu
+	 */
+	public function setTextColor($R,$V,$B) {
+		$this->textColor['R'] = $R;
+		$this->textColor['V'] = $V;
+		$this->textColor['B'] = $B;
+	}
+
+	/**
+	 * Fixe la largeur de l'image
+	 *
+	 * @param int $width largeur en pixel de l'image
+	 */
+	public function setImageWidth($width) {
+		$this->imageWidth = $width;
+	}
+
+	/**
+	 * Fixe la hauteur de l'image
+	 *
+	 * @param int $height hauteur en pixel de l'image
+	 */
+	public function setImageHeight($height) {
+		$this->imageHeight = $height;
+	}
+
+	/**
+	 * Fixe la police True Type et sa taille
+	 *
+	 * @param string $font chemin vers la police
+	 * @param int $size taille de la police
+	 */
+	public function setFont($font, $size) {
+		if(!is_readable($font)) {
+			throw new Exception('La police est introuvable');
+		}
+		$this->font = $font;
+		$this->fontSize = $size;
+	}
+
+	/**
+	 * Fixe si une ombre doit être appliquée au texte
+	 *
+	 * @param int $x décalage de l'ombre en absisse
+	 * @param int $y décalage de l'ombre en ordonné
+	 */
+	public function setShadow($x=false,$y=false) {
+		$this->shadow = true;
+		if($x) {
+			$this->shadowX = (int)$x;
+		}
+		if($y) {
+			$this->shadowY = (int)$y;
+		}
+	}
+
+	/**
+	 * Fixe la couleur de l'ombre
+	 *
+	 * @param int $R rouge
+	 * @param int $V vert
+	 * @param int $B bleu
+	 */
+	public function setShadowColor($R,$V,$B) {
+		$this->shadow = true;
+		$this->shadowColor['R'] = $R;
+		$this->shadowColor['V'] = $V;
+		$this->shadowColor['B'] = $B;
+	}
+
+
+	/**
+	 * Définie si une image de fond doit être appliquée
+	 *
+	 * @param string $image chemin vers l'image
+	 */
+	public function setBackgroundImage($image) {
+		if(!is_readable($image)) {
+			throw new Exception('Image de fond introuvable');
+		}
+		$this->backgroundImage = $image;
+	}
+
+	/**
+	 * Fixe l'angle du texte
+	 *
+	 * @param int $angle angle en degrés
+	 */
+	public function setTextAngle($angle) {
+		$this->textAngle = (int)$angle;
+	}
+
+	/**
+	 * Fixe la taille de la marge par rapport à la bordure
+	 *
+	 * @param int $margin taille en pixel de la marge
+	 */
+	public function setMarginFromBorder($margin) {
+		$this->fromBorder = (int)$margin;
+	}
+	
+	public function setRoundedCorners($radius=false) {
+		$this->roundedCorners = true;
+		if($radius) {
+			$this->roundedCornersRadius = (int)$radius;
+		}
+	}
+
+
+	/**
+	 * Construit l'image
+	 *
+	 */
+	public function getImage() {
+		if(!$this->font) {
+			throw new Exception('Il faut charger une police');
+		}
+
+		$text = $this->getRandString();
+		$text = trim(preg_replace('`(\w)`', '$1  ', $text));
+		$box = imagettfbbox($this->fontSize,$this->textAngle,$this->font,$text);
+
+		if(!$this->imageHeight) {
+			$boxHeight = max($box[1],$box[3]) - min($box[7],$box[5]);
+			$this->imageHeight = $boxHeight + $this->borderWidth*2 + $this->fromBorder*2;
+		}
+		if(!$this->imageWidth) {
+			$boxWidth = max($box[4],$box[2]) - min($box[6],$box[0]);
+			$this->imageWidth =  $boxWidth + $this->borderWidth*2 + $this->fromBorder*2;
+		}
+
+		if(function_exists('imagecreatetruecolor')) {
+			$im = imagecreatetruecolor($this->imageWidth, $this->imageHeight);
+		} else {
+			$im = imagecreate($this->imageWidth, $this->imageHeight);
+		}
+		// border
+		if($this->borderWidth > 0) {
+			$border = imagecolorallocate(
+			$im,
+			$this->borderColor['R'],
+			$this->borderColor['V'],
+			$this->borderColor['B']
+			);
+			if(!$this->roundedCorners) {
+				imagefilledrectangle(
+				$im,
+				0,
+				0,
+				$this->imageWidth,
+				$this->imageHeight,
+				$border
+				);
+			} else {
+				$this->ImageRectangleWithRoundedCorners(
+				$im,
+				0,
+				0,
+				$this->imageWidth,
+				$this->imageHeight,
+				$border,
+				$this->roundedCornersRadius
+				);
+			}
+		}
+
+		// background
+		$background = imagecolorallocate(
+		$im,
+		$this->backgroundColor['R'],
+		$this->backgroundColor['V'],
+		$this->backgroundColor['B']
+		);
+		imagefilledrectangle(
+		$im,
+		$this->borderWidth,
+		$this->borderWidth,
+		$this->imageWidth-$this->borderWidth,
+		$this->imageHeight-$this->borderWidth,
+		$background
+		);
+
+		if($this->backgroundImage) {
+			// Calcul des nouvelles dimensions
+			list($width, $height,$type) = getimagesize($this->backgroundImage);
+
+			$new_width = $this->imageWidth-$this->borderWidth*2;
+			$new_height = $this->imageHeight-$this->borderWidth*2;
+
+			if($type === 1) {
+				$type_ = 'gif';
+			} elseif($type === 2) {
+				$type_ = 'jpeg';
+			} elseif($type === 3) {
+				$type_ = 'png';
+			} else {
+				throw new Exception('Mauvais type pour l\'image de fond');
+			}
+			$fct = 'imagecreatefrom' . $type_;
+			$imb = $fct($this->backgroundImage);
+
+
+			imagecopyresampled(
+			$im,
+			$imb,
+			$this->borderWidth,
+			$this->borderWidth,
+			0,
+			0,
+			$new_width,
+			$new_height,
+			$width,
+			$height
+			);
+
+			imagedestroy($imb);
+		}
+
+		// couleur du texte
+		$textColor = imagecolorallocate (
+		$im,
+		$this->textColor['R'],
+		$this->textColor['V'],
+		$this->textColor['B']
+		);
+
+		// centrage horizontal
+		$x = ($this->imageWidth - $boxWidth)/2;
+		// centrage vertical
+		$y = $this->imageHeight   - $this->borderWidth - $this->fromBorder;
+
+		// ombre
+		if($this->shadow) {
+			$shadow = imagecolorallocate(
+			$im,
+			$this->shadowColor['R'],
+			$this->shadowColor['V'],
+			$this->shadowColor['B']
+			);
+			imagettftext(
+			$im,
+			$this->fontSize,
+			$this->textAngle,
+			$x+$this->shadowX,
+			$y+$this->shadowY,
+			$shadow,
+			$this->font,
+			$text
+			);
+		}
+
+		// le texte
+		imagettftext(
+		$im,
+		$this->fontSize,
+		$this->textAngle,
+		$x,
+		$y,
+		$textColor,
+		$this->font,
+		$text
+		);
+
+		$this->makeHeaders();
+		$image_function = 'image' . $this->type;
+		$image_function($im);
+		imagedestroy($im);
+	}
+
+
+	/**
+	 * Récupère la chaîne aléatoire générée
+	 *
+	 * @return string chaîne aléatoire générée
+	 */
+	public function getRandString() {
+		if(!$this->randString) {
+			$T = array_merge(range('a','z') , range('A', 'Z') , range(1,9));
+			shuffle($T);
+			//$TT = array_filter($T, array($this, 'forbiddenCharsFilter'));
+			$TT = array_chunk($T, $this->stringLength);
+
+			$this->randString = implode('', $TT[0]);
+		}
+		return $this->randString;
+	}
+	
+	private function ImageRectangleWithRoundedCorners(&$im, $x1, $y1, $x2, $y2, $color, $radius) {
+		// transparence
+		$trans = imageColorAllocate ($im, 255, 255, 255);
+		$color_ = imagecolortransparent($im, $trans);
+		// rectangle sans coins
+		imagefilledrectangle($im, $x1, $y1, $x2, $y2, $color_);
+		imagefilledrectangle($im, $x1+$radius, $y1, $x2-$radius, $y2, $color);
+		imagefilledrectangle($im, $x1, $y1+$radius, $x2, $y2-$radius, $color);
+		// coins arrondis
+		imagefilledellipse($im, $x1+$radius, $y1+$radius, $radius*2, $radius*2, $color);
+		imagefilledellipse($im, $x2-$radius, $y1+$radius, $radius*2, $radius*2, $color);
+		imagefilledellipse($im, $x1+$radius, $y2-$radius, $radius*2, $radius*2, $color);
+		imagefilledellipse($im, $x2-$radius, $y2-$radius, $radius*2, $radius*2, $color);
+		
+	}
+
+	private function forbiddenCharsFilter($in) {
+		return in_array($in, $this->forbiddenChars);
+	}
+
+	private function setImageType($type) {
+		switch(strtolower($type)) {
+			case 'gif' :
+			case 'png' :
+			case 'jpeg' :
+			$this->type = $type;
+			break;
+			case 'jpg' :
+			$this->type = 'jpeg';
+			break;
+			default :
+			$this->type = 'png';
+		}
+		if(!function_exists('image'.$this->type)) {
+			throw new Exception('La fonction n\'est pas disponible');
+		}
+	}
+
+	private function makeHeaders() {
+		header('Expires: Mon, 01 Jan 2000 00:00:00 GMT');
+		header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
+		header('Cache-Control: no-store, no-cache, must-revalidate');
+		header('Cache-Control: post-check=0, pre-check=0', false);
+		header('Pragma: no-cache');
+		header('Content-Type: image/' . $this->type);
+	}
+}
+
+?>

+ 158 - 0
include/class/controller.class.inc.php

@@ -0,0 +1,158 @@
+<?php
+
+/**
+ * Gestion controller
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class controller_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),
+	"titre" => array("label"=>"Titre", "type"=>"string"),
+	"description" => array("label"=>"Description", "type"=>"text"),
+	"template_layout" => array("label"=>"Layout", "type"=>"string"),
+	//"template_left_id" => array("label"=>"Template gauche", "type"=>"object", 'object_type'=>'template'),
+	//"template_right_id" => array("label"=>"Template droit", "type"=>"object", 'object_type'=>'template'),
+	"template_id" => array("label"=>"Template central", "type"=>"object", 'object_type'=>'template'),
+	"fields" => array("label"=>"Champs supplémentaires", "type"=>""),
+);
+public $_field_disp_list = array("ref", "titre");
+
+/**
+ * Select en base de donnée
+ * @param [] $params
+ * @param int $limit
+ * @param string $order
+ * @return []
+ */
+public function select($params=null, $limit=null, $order=null)
+{
+
+$list = array();
+foreach ($this->db_retrieve($params, $limit, $order) as $row)
+{
+	if (!isset($this->list[$row["id"]])){
+		$classname = $row['ref'].'_controller';
+		$this->list[$row["id"]] = $object = new $classname(null, $row);
+	}
+	else
+		$object = $this->list[$row["id"]];
+	$list[] = $object;
+}
+
+return $list;
+
+}
+
+protected function db_retrieve_more($list_id=null)
+{
+
+if (!is_array($list_id))
+	return array();
+
+$list = array();
+$sql = "SELECT * FROM `controller_params` WHERE `controller_id` IN (".implode(',', $list_id).")";
+$q = mysql_query($sql);
+while($row = mysql_fetch_assoc($q))
+	$list[$row['controller_id']]['fields'][$row['name']] = $row;
+
+//var_dump($list);
+return $list;
+
+}
+
+}
+
+class controller extends db_object{
+
+public $_name = 'controller';
+
+public $fields = array();
+
+//public $values = array();
+public $page = null;
+public $params = array();
+public $header = array();
+
+function __tostring(){
+	return $this->titre;
+}
+
+function template(){
+
+return $this->object('template_id');
+
+}
+
+function param_url($id){
+
+return "paramurl-$id";
+
+}
+
+function param_title($id){
+
+return "paramtitle-$id";
+
+}
+
+/**
+ * Mise en place des éléments communs au template
+ */
+function view_before(){
+
+// Header
+$this->header = array(
+	"title"=>$this->page->header_title,
+	"description"=>$this->page->header_description,
+	"url"=>$this->page->url(),
+);
+
+}
+
+/**
+ * Mise en place des éléments du template
+ * A surcharger
+ */
+function view(){
+}
+
+/**
+ * Mise en place des éléments communs au template
+ */
+function view_after(){
+
+}
+
+/**
+ * Affichage de la page
+ */ 
+function display(){
+
+$this->params = $this->page->params;
+
+$this->view_before();
+$this->view();
+$this->view_after();
+
+//var_dump($this->template_id);
+$template = $this->template();
+$template->controller = $this;
+$template->page = $this->page;
+
+$template->params = array_merge($template->params, $this->params);
+$template->layout = $this->template_layout;
+$template->header = array_merge($template->header, $this->header);
+
+//var_dump($template);
+$template->display();
+
+}
+
+}
+

+ 1000 - 0
include/class/db_object.class.inc.php

@@ -0,0 +1,1000 @@
+<?php
+
+/**
+ * Classe de gestion ORM
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class db_object_manager
+{
+
+/**
+ * Liste des types de champ "simples" (dans la table principale en base de donnée)
+ * @var []
+ */
+public $field_simple = array("int", "float", "string", "password", "text", "richtext", "object", "timestamp", "bool", 'date', "select", "select_multiple", "file", "img");
+
+/**
+ * Debug database operations
+ * @var bool
+ */
+public $DB_DEBUG = false;
+/**
+ * Debug file operations
+ * @var bool
+ */
+public $FILE_DEBUG = false;
+/**
+ * Class name
+ * @var string
+ */
+public $_name = "";
+
+public $_label = "";
+/**
+ * Database name
+ * @var string
+ */
+public $_db_table = "";
+/**
+ * ID field name in database
+ * @var string
+ */
+public $_db_id = "id";
+/**
+ * Fields specifications
+ * @var []
+ */
+public $_fields = array();
+/**
+ * More fields specifications
+ * @var []
+ */
+public $_fields_more = array();
+public $_db_fields_more_table = '';
+
+/**
+ * Fields to display in lists
+ * @var []
+ */
+public $_field_disp_list = array();
+/**
+ * Object list cache
+ * @var []
+ */
+private $list = array();
+/**
+ * Object list cache
+ * @var []
+ */
+private $list_ref = array();
+
+/**
+ * Constructeur
+ */
+public function __construct()
+{
+
+if (!$this->_name)
+	$this->_name = substr(get_class($this), 0, -8);
+if (!$this->_db_table)
+	$this->_db_table = $this->_name;
+
+}
+
+/**
+ * Returns if an object exists
+ * @param int|string $param
+ * @return bool
+ */
+public function exists($param)
+{
+
+if (is_numeric($param) || is_string($param)) {
+	if (is_numeric($param) && isset($this->list[$param])) {
+		return true;
+	}
+	elseif (is_string($param) && isset($this->list_ref[$param])) {
+		return true;
+	}
+	elseif ($this->get($param)) {
+		return true;
+	}
+	else {
+		return false;
+	}
+}
+else {
+	return false;
+}
+
+}
+
+/**
+ * Renvoie un object de la base
+ * @param int|string $param
+ * @return db_object
+ */
+public function get($param)
+{
+
+if (is_numeric($param)) {
+	if (isset($this->list[$param])) {
+		return $this->list[$param];
+	}
+	elseif(count($objects=$this->select('id='.$param))==1) {
+		$object = array_pop($objects);
+		if ($object->ref) {
+			$this->list_ref[$object->ref] = $object->id;
+		}
+		return $object;
+	}
+	else {
+		return false;
+	}
+}
+elseif (isset($this->_fields['ref']) && is_string($param)) {
+	if (isset($this->list_ref[$param])) {
+		return $this->list[$this->list_ref[$param]];
+	}
+	elseif (count($objects=$this->select("ref='".mysql_real_escape_string($param)."'"))==1) {
+		$object = array_pop($objects);
+		if ($object->ref) {
+			$this->list_ref[$object->ref] = $object->id;
+		}
+		return $object;
+	}
+	else {
+		return false;
+	}
+}
+else {
+	return false;
+}
+
+}
+
+/**
+ * Select en base de donnée
+ * @param [] $params
+ * @param int $limit
+ * @param string $order
+ * @return []
+ */
+public function select($params=null, $limit=null, $order=null)
+{
+
+$classname = $this->_name;
+
+$list = array();
+foreach ($this->db_retrieve($params, $limit, $order) as $row)
+{
+	if (!isset($this->list[$row["id"]])){
+		$this->list[$row["id"]] = $object = new $classname(null, $row);
+		if (isset($row['ref']))
+			$this->list_ref[$row["ref"]] = $row["id"];
+	}
+	else
+		$object = $this->list[$row["id"]];
+	$list[] = $object;
+}
+
+return $list;
+
+}
+
+/**
+ * Select en base de donnée
+ * @param [] $params
+ * @param int $limit
+ * @param string $order
+ * @return []
+ */
+public function db_retrieve($params=null, $limit=null, $order=null)
+{
+
+if ($params)
+	$q_where = "WHERE ".$params;
+else
+	$q_where = "";
+
+if ($limit)
+	$q_limit = "LIMIT ".$limit;
+else
+	$q_limit = "";
+
+if ($order){
+	$q_o = array();
+	foreach(explode(', ', $order) as $o)
+		if (count($o2=explode(' ', trim($o)))>1)
+			$q_o[] = "`".$o2[0]."` ".$o2[1];
+		else
+			$q_o[] = "`".$o2[0]."`";
+	$q_order = "ORDER BY ".implode(', ', $q_o);
+}
+else
+	$q_order = "";
+
+$select_more = array();
+$type_select_multiple = array();
+$q_select = array("`".$this->_db_id."` as `id`");
+foreach($this->_fields as $name=>$field)
+{
+	if (in_array($field["type"], $this->field_simple))
+	{
+		if ($field["type"] == "select_multiple")
+			$type_select_multiple[] = $name;
+		if (isset($field["db_fieldname"]))
+			$q_select[] = "`".$field["db_fieldname"]."` as `".$name."`";
+		else
+			$q_select[] = "`".$name."`";
+	}
+	elseif ($field["type"] == "object_list")
+	{
+		$select_more[] = $name;
+	}
+}
+
+$q_s = "SELECT ".implode(", ", $q_select)." FROM `".$this->_db_table."` ".$q_where." ".$q_order." ".$q_limit;
+$q_r = mysql_query($q_s);
+if ($this->DB_DEBUG == true || ($error=mysql_error()))
+{
+	echo "$q_s : ".$error;
+}
+$list = array();
+$list_id = array();
+while ($row=mysql_fetch_assoc($q_r))
+{
+	// @todo : tout pourris...
+	foreach($row as $i=>$j)
+		$row[$i] = stripslashes($j);
+	foreach($type_select_multiple as $name)
+	{
+		if ($row[$name] !== null)
+			$row[$name] = explode(",", $row[$name]);
+		else
+			$row[$name] = array();
+	}
+	$list[$row["id"]] = $row;
+	$list_id[] = $row["id"];
+}
+
+// Fields of type : object_list
+foreach($select_more as $name)
+{
+	$field = $this->_fields[$name];
+	$classname = $field["object_type"];
+	$q_s = "SELECT `".$field["db_field_id"]."` as id, `".$field["db_field_ref_id"]."` as ref_id FROM `".$field["db_table"]."` WHERE `".$field["db_field_ref_id"]."` IN (".implode(", ", $list_id).")";
+	$q_r = mysql_query($q_s);
+	while ($row=mysql_fetch_assoc($q_r))
+	{
+		$list[$row["ref_id"]][$name][] = $row["id"];
+	}
+}
+
+// More fields
+foreach($this->db_retrieve_more($list_id) as $id=>$row)
+	$list[$id] = array_merge($list[$id], $row);
+
+return $list;
+
+}
+
+/**
+ * retrieve more info
+ * @param []int $list_id
+ */
+protected function db_retrieve_more($list_id=null)
+{
+
+return array();
+
+}
+
+/**
+ * Count en base de donnée
+ * @param [] $params
+ * @return int
+ */
+public function count($params=null)
+{
+
+$classname = $this->_name;
+
+if ($params)
+	$q_where = "WHERE ".$params;
+else
+	$q_where = "";
+
+$q_s = "SELECT COUNT(*) FROM `".$this->_db_table."` ".$q_where;
+$q_r = mysql_query($q_s);
+if ($this->DB_DEBUG == true) {
+	echo "$q_s : ".mysql_error();
+}
+$row = mysql_fetch_row($q_r);
+return array_pop($row);
+
+}
+
+public function insert($info=array())
+{
+
+$classname = $this->_name;
+
+$object = new $classname();
+$object->insert($info);
+if ($object->id) {
+	$this->list[$object->id] = $object;
+	if ($object->ref) {
+		$this->list_ref[$object->ref] = $object->id;
+	}
+	return $object;
+}
+
+}
+
+}
+
+/**
+ * Classe objet ORM
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class db_object
+{
+
+/**
+ * Class name
+ * @var string
+ */
+public $_name = "";
+/**
+ * Manager object
+ * @access public
+ * @var db_object_manager
+ */
+public $_manager = null;
+/**
+ * Object ID
+ * @var int
+ */
+public $id = null;
+
+/* CONSTRUCT */
+
+/**
+ * Constructeur
+ * @param int $id
+ * @param [] $info
+ */
+public function __construct($id=null, $info=null)
+{
+
+if (!$this->_name)
+	$this->_name = get_class($this);
+$classname = $this->_name;
+$this->_manager = $classname();
+
+foreach ($this->_manager->_fields as $name=>$value)
+	$this->$name = null;
+
+if (is_numeric($id))
+{
+	if ($info=$this->db_retrieve($id))
+		$this->field_update($info);
+}
+elseif (is_array($info))
+{
+	$this->field_update($info);
+}
+
+}
+
+/* DISPLAY */
+
+/**
+ * Default display
+ * @return string
+ */
+public function __tostring()
+{
+
+if ($this->id)
+	return $this->_manager->_name." #".$this->id;
+else
+	return $this->_manager->_name." # en cours...";
+
+}
+
+/**
+ * Return image url
+ * @param string $name
+ * @return string
+ */
+public function file($name)
+{
+
+if (isset($this->_manager->_fields[$name]) && in_array($this->_manager->_fields[$name]["type"], array("img", "file")) && $this->$name)
+{
+	return $this->_manager->_fields[$name]["folder"]."/".$this->$name;
+}
+
+}
+
+/**
+ * Return image url
+ * @param string $name
+ * @return string
+ */
+public function img($name, $width=null)
+{
+
+if (isset($this->_manager->_fields[$name]) && in_array($this->_manager->_fields[$name]["type"], array("img", "file")) && $this->$name)
+{
+	if (is_numeric($width))
+		return str_replace('img/', 'img2/'.$width.'/', $this->_manager->_fields[$name]["folder"])."/".$this->$name;
+	else
+		return $this->_manager->_fields[$name]["folder"]."/".$this->$name;
+}
+
+}
+
+/**
+ * Return object associated to a field
+ * @param string $fieldname
+ * @return db_object
+ */
+function object($fieldname)
+{
+
+if (!is_string($fieldname) || !isset($this->_manager->_fields[$fieldname]))
+	return;
+
+$field = $this->_manager->_fields[$fieldname];
+if (!isset($field["type"]) || $field["type"] != "object" || !isset($field["object_type"]))
+	return;
+
+if (!is_string($classname=$field["object_type"]) || !class_exists($classname))
+	return;
+if (!is_numeric($this->$fieldname))
+	return;
+
+return $classname()->get($this->$fieldname);
+
+}
+
+/* INSERT UPDATE VERIF */
+
+public function field_calculated(&$info)
+{
+
+foreach($this->_manager->_fields as $name=>&$field) if (isset($field['calculate'])){
+	list($type, $var) = explode(':', $field['calculate']);
+	if ($type=='url'){
+		if (!isset($info[$var]))
+			continue;
+		$url = strtolower(stripAccents($info[$var]));
+		$patterns = $replacements = array();
+		$patterns[0] = '/(&amp;|&)/i';
+		$replacements[0] = '-and-';
+		$patterns[1] = '/[^a-zA-Z01-9]/i';
+		$replacements[1] = '-';
+		$patterns[2] = '/(-+)/i';
+		$replacements[2] = '-';
+		$patterns[3] = '/(-$|^-)/i';
+		$replacements[3] = '';
+		$url = preg_replace($patterns, $replacements, $url);
+		if (strlen($url)>100){
+			$urle = explode('-', $url);
+			while (strlen($url)>100){
+				array_pop($urle);
+				$url = implode('-', $urle);
+			}
+		}
+		$info[$name] = $url;
+	}
+	if ($type=='ref'){
+		if (!isset($info[$var]))
+			continue;
+		$url = strtolower(stripAccents($info[$var]));
+		$patterns = $replacements = array();
+		$patterns[0] = '/(&amp;|&)/i';
+		$replacements[0] = '';
+		$patterns[1] = '/[^a-zA-Z01-9]/i';
+		$replacements[1] = '_';
+		$patterns[2] = '/(_+)/i';
+		$replacements[2] = '_';
+		$patterns[3] = '/(_$|^_)/i';
+		$replacements[3] = '';
+		$url = preg_replace($patterns, $replacements, $url);
+		$urle = explode('_', $url);
+		$s = 0;
+		while (strlen($url)>20) {
+			$s++;
+			foreach($urle as $i=>&$j) {
+				if (strlen($j)<=$s) {
+					unset($urle[$i]);
+					$url = implode('_', $urle);
+					if (strlen($url)<=20)
+						 break;
+				}
+			}
+		}
+		while (strlen($url)>50){
+			array_pop($urle);
+			$url = implode('_', $urle);
+		}
+		$info[$name] = $url;
+	}
+}
+
+//var_dump($info); die();
+
+}
+
+/**
+ * Contrôle des champs
+ * @param [] $info
+ */
+public function field_verif(&$info)
+{
+
+if (!is_array($info))
+	$info = array();
+
+foreach($info as $name=>&$value)
+{
+	if (!isset($this->_manager->_fields[$name]))
+	{
+		unset($info[$name]);
+	}
+	else
+	{
+		$field = $this->_manager->_fields[$name];
+		if (isset($field["type"]))
+		{
+			$type = $field["type"];
+			if (in_array($type, array("object", "int", "float", "numeric", "decimal")) && !is_numeric($value))
+			{
+				$value = NULL;
+			}
+			elseif ($type == "boolean")
+			{
+				$value = ($value) ?1 :0;
+			}
+			elseif ($type == "object" && $value)
+			{
+				$object_classname = $field["object_type"];
+				if (!$object_classname()->exists($value))
+					$value = NULL;
+			}
+			elseif (in_array($type, array("string", "text", "richtext")) && !is_string($value))
+			{
+				$value = NULL;
+			}
+					elseif ($type == "select" && ((!is_string($value) && !is_numeric($value)) || !isset($field["list"][$value])))
+			{
+				$value = NULL;
+			}
+			elseif ($type == "select_multiple")
+			{
+				if (!is_array($value))
+				{
+					$value = NULL;
+				}
+				else
+				{
+					foreach($value as $i=>$v)
+						if (!isset($field["list"][$v]))
+							unset($value[$i]);
+				}
+			}
+			elseif ($type == "date" && (!is_string($value)))
+			{
+				$value = NULL;
+			}
+			elseif (in_array($type, array("datetime", "timestamp")) && (!is_string($value)))
+			{
+				$value = NULL;
+			}
+			elseif ($type == "img" || $type == "file")
+			{
+				//var_dump($_FILES);
+				// Sans upload ou upload foireux
+				if (isset($_FILES[$name]) && (!$_FILES[$name]["tmp_name"] || $_FILES[$name]["error"] != UPLOAD_ERR_OK)) {
+					unset($_FILES[$name]);
+				}
+				// Fichier sans nom ou nom foireux
+				if (isset($_FILES[$name]))
+				{
+					if (isset($field["filename"]))
+					{
+						$_FILES[$name]["name"] = $this->field_map_replace($field["filename"]);
+					}
+					else
+					{
+						$nb = 0;
+						$name = $field["filename"];
+						while (file_exists(PATH_ROOT."/".$field["folder"]."/".$_FILES[$name]["name"]))
+						{
+							$nb++;
+							$_FILES[$name]["name"] = $nb."-".$name;
+						}
+					}
+					$value = $_FILES[$name]["name"];
+				}
+				// Renommage sans fichier
+				elseif ($value && (isset($field["filename"]) || !$this->$name || !file_exists(PATH_ROOT."/".$field["folder"]."/".$this->$name)))
+				{
+					//echo PATH_ROOT."/".$field["folder"]."/".$this->$name;
+					unset($info[$name]);
+				}
+			}
+		}
+	}
+}
+//var_dump($_FILES); var_dump($info);
+
+}
+
+function field_map_replace($string)
+{
+
+$replace_from = $replace_to = array();
+foreach($this->_manager->_fields as $name=>$field)
+{
+	$replace_from[] = "{".$name."}";
+	$replace_to[] = $this->$name;
+}
+return str_replace($replace_from, $replace_to, $string);
+
+}
+
+/**
+ * Contrôle supplémentaire à l'insertion
+ * @param [] $info
+ */
+public function field_verif_insert(&$info)
+{
+
+}
+
+/**
+ * Contrôle supplémentaire à la mise à jour
+ * @param [] $info
+ */
+public function field_verif_update(&$info)
+{
+
+}
+
+/**
+ * Update object with data
+ * @param [] $info
+ */
+private function field_update(&$info)
+{
+
+if (!is_array($info))
+	return;
+
+foreach($info as $name=>$value)
+	if ($name=="id" || isset($this->_manager->_fields[$name]))
+		$this->$name = $value;
+
+}
+
+public function duplicate()
+{
+
+
+
+}
+
+/* OPERATIONS */
+
+/**
+ * Insertion objet
+ * @param [] $info
+ * @return bool
+ */
+public function insert($info)
+{
+
+if (is_numeric($this->id))
+	return;
+
+$this->field_verif($info);
+$this->field_calculated($info);
+$this->field_verif_insert($info);
+
+if (is_numeric($id=$this->db_insert($info)))
+{
+	$this->id = $id;
+	$this->field_update($info);
+	return true;
+}
+else
+	return false;
+
+}
+
+/**
+ * Mise à jour objet
+ * @param [] $info
+ * @return bool
+ */
+public function update($info)
+{
+
+if (!is_numeric($this->id))
+	return;
+
+$this->field_verif($info);
+foreach($info as $name=>$value)
+	if ($this->$name === $value && (!in_array($this->_manager->_fields[$name]["type"], array("img", "file")) || !isset($_FILES[$name])))
+		unset($info[$name]);
+$this->field_verif_update($info);
+
+if ($this->db_update($info))
+{
+	$this->field_update($info);
+	return true;
+}
+else
+	return false;
+
+}
+
+/**
+ * Supression objet
+ * @return bool
+ */
+public function delete()
+{
+
+if (!is_numeric($this->id))
+	return;
+
+return $this->db_delete($this->id);
+
+}
+
+/* DATABASE */
+/*
+ * Comprend autant les opérations en base de donnée que sur le système de fichiers,
+ * bref sur tout support de stockage de donnée (ce qui se tient logiquement)
+ */
+
+/**
+ * Retrieve object info from database
+ * @param int $id
+ * @return []|bool
+ */
+protected function db_retrieve($id)
+{
+
+if (!is_numeric($id) || !count($list=$this->_manager->db_retrieve("`".$this->_manager->_db_id."`='".$id."'")))
+	return false;
+
+return array_pop($list);
+
+}
+
+/**
+ * Update object in database
+ * @param [] $info
+ * @return int
+ */
+protected function db_update($info)
+{
+
+if (!is_numeric($this->id))
+	return false;
+
+$q_list = array();
+$file_move_list = $file_rename_list = $file_delete_list = array();
+//var_dump($_FILES); var_dump($info);
+foreach($info as $name=>$value)
+{
+	$field = $this->_manager->_fields[$name];
+	if (isset($field["type"]))
+	{
+		$type = $field["type"];
+		if (in_array($field["type"], $this->_manager->field_simple))
+		{
+			if ($field["type"] == "select_multiple")
+			{
+				if (is_array($value))
+					foreach($value as $i=>$v)
+						$value[$i] = mysql_real_escape_string($v);
+				$q_list[] = "`".(isset($field["db_fieldname"]) ?$field["db_fieldname"] :$name)."` = ".(is_array($value)&&count($value) ?"'".implode(",",$value)."'" :"NULL");
+			}
+			else
+				$q_list[] = "`".(isset($field["db_fieldname"]) ?$field["db_fieldname"] :$name)."` = ".($value===NULL?"NULL":"'".mysql_real_escape_string($value)."'");
+			if ($type == "img")
+			{
+				if (isset($_FILES[$name]) && $this->$name) {
+					$file_update = true;
+					$file_delete_list[] = PATH_ROOT."/".$field["folder"]."/".$this->$name;
+				}
+				if (!isset($_FILES[$name]) && $this->$name) {
+					$file_update = true;
+					$file_rename_list[PATH_ROOT."/".$field["folder"]."/".$this->$name] = PATH_ROOT."/".$field["folder"]."/".$value;
+				}
+				if (isset($_FILES[$name])) {
+					$file_update = true;
+					$file_move_list[$_FILES[$name]["tmp_name"]] = PATH_ROOT."/".$field["folder"]."/".$value;
+				}
+			}
+		}
+	}
+}
+
+if (count($q_list)){
+	$q_s = "UPDATE `".$this->_manager->_db_table."` SET ".implode(", ", $q_list)." WHERE `".$this->_manager->_db_id."`='".$this->id."'";
+	$q_r = mysql_query($q_s);
+}
+
+if ($this->_manager->DB_DEBUG == true || (isset($q_s) && ($error=mysql_error())))
+{
+	echo "$q_s : ".$error;
+}
+$return = (isset($q_s) && mysql_affected_rows()>0 ?true :false);
+
+foreach($file_delete_list as $name)
+{
+	if ($this->_manager->FILE_DEBUG)
+		echo "<p>Delete $name</p>\n";
+	$return = (unlink($name) || $return);
+}
+foreach($file_rename_list as $from=>$to)
+{
+	if ($this->_manager->FILE_DEBUG)
+		echo "<p>Rename $from $to</p>\n";
+	$return = (rename($from, $to) || $return);
+}
+foreach($file_move_list as $from=>$to)
+{
+	if ($this->_manager->FILE_DEBUG)
+		echo "<p>Move uplodaed $from $to</p>\n";
+	//var_dump(move_uploaded_file($from, $to));
+	$return = (move_uploaded_file($from, $to) || $return);
+}
+
+// More fields
+$return = ($this->db_update_more($info) || $return);
+
+return $return;
+
+}
+
+/**
+ * Modification supplémentaire
+ * @param [] $info
+ */
+protected function db_update_more($info)
+{
+
+return false;
+
+}
+
+/**
+ * Insert in database
+ * @param [] $info
+ * @return bool
+ */
+protected function db_insert($info)
+{
+
+if (is_numeric($this->id))
+	return false;
+
+$q_list_1 = $q_list_2 = array();
+$file_move_list = array();
+foreach($info as $name=>$value)
+{
+	$field = $this->_manager->_fields[$name];
+	if (isset($field["type"]))
+	{
+		if (in_array($field["type"], $this->_manager->field_simple))
+		{
+			$type = $field["type"];
+			$q_list_1[] = "`".(isset($field["db_fieldname"]) ?$field["db_fieldname"] : $name)."`";
+			if ($field["type"] == "select_multiple")
+			{
+				if (is_array($value))
+					foreach($value as $i=>$v)
+						$value[$i] = "'".mysql_real_escape_string($v)."'";
+				$q_list_2[] = (is_array($value)&&count($value) ?"(".implode(",",$value).")" :"NULL");
+			}
+			else
+				$q_list_2[] = ($value===NULL?"NULL":"'".mysql_real_escape_string($value)."'");
+			if ($type == "img")
+			{
+				$file_move_list[$_FILES[$name]["tmp_name"]] = PATH_ROOT."/".$field["folder"]."/".$value;
+			}
+		}
+	}
+}
+
+$q_s = "INSERT INTO `".$this->_manager->_db_table."` (".implode(", ", $q_list_1).") VALUES (".implode(", ", $q_list_2).")";
+$q_r = mysql_query($q_s);
+if ($this->_manager->DB_DEBUG == true)
+{
+	echo "$q_s : ".mysql_error();
+}
+
+$return = mysql_insert_id();
+
+if ($return)
+{
+	foreach($file_move_list as $from=>$to)
+	{
+		if ($this->_manager->FILE_DEBUG)
+			echo "<p>Move uploaded $from $to</p>\n";
+		move_uploaded_file($from, $to);
+	}
+}
+
+if ($return)
+	$this->db_insert_more($return, $info);
+
+return $return;
+
+}
+
+/**
+ * Insertions supplémentaires
+ * @param int $id
+ * @param [] $info
+ * @return bool
+ */
+protected function db_insert_more($id, $info)
+{
+
+return false;
+
+}
+
+/**
+ * Delete object in database
+ * @return bool
+ */
+protected function db_delete()
+{
+
+if (!is_numeric($this->id))
+	return false;
+
+$q_s = "DELETE FROM `".$this->_manager->_db_table."` WHERE `".$this->_manager->_db_id."`='".$this->id."'";
+$q_r = mysql_query($q_s);
+if ($this->_manager->DB_DEBUG == true)
+{
+	echo "$q_s : ".mysql_error();
+}
+$return = (mysql_affected_rows()>0 ?true :false);
+
+if ($return)
+	$this->db_delete_more();
+
+return $return;
+
+}
+
+/**
+ * Suppressions supplémentaires
+ * @return bool
+ */
+protected function db_delete_more()
+{
+
+return false;
+
+}
+
+}
+

+ 1005 - 0
include/class/db_object.class.inc.php.orig

@@ -0,0 +1,1005 @@
+<?php
+
+/**
+ * Classe de gestion ORM
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class db_object_manager
+{
+
+/**
+ * Liste des types de champ "simples" (dans la table principale en base de donnée)
+ * @var []
+ */
+public $field_simple = array("int", "float", "string", "password", "text", "richtext", "object", "timestamp", "bool", 'date', "select", "select_multiple", "file", "img");
+
+/**
+ * Debug database operations
+ * @var bool
+ */
+public $DB_DEBUG = false;
+/**
+ * Debug file operations
+ * @var bool
+ */
+public $FILE_DEBUG = false;
+/**
+ * Class name
+ * @var string
+ */
+public $_name = "";
+
+public $_label = "";
+/**
+ * Database name
+ * @var string
+ */
+public $_db_table = "";
+/**
+ * ID field name in database
+ * @var string
+ */
+public $_db_id = "id";
+/**
+ * Fields specifications
+ * @var []
+ */
+public $_fields = array();
+/**
+ * More fields specifications
+ * @var []
+ */
+public $_fields_more = array();
+public $_db_fields_more_table = '';
+
+/**
+ * Fields to display in lists
+ * @var []
+ */
+public $_field_disp_list = array();
+/**
+ * Object list cache
+ * @var []
+ */
+private $list = array();
+/**
+ * Object list cache
+ * @var []
+ */
+private $list_ref = array();
+
+/**
+ * Constructeur
+ */
+public function __construct()
+{
+
+if (!$this->_name)
+	$this->_name = substr(get_class($this), 0, -8);
+if (!$this->_db_table)
+	$this->_db_table = $this->_name;
+
+}
+
+/**
+ * Returns if an object exists
+ * @param int $id
+ * @return bool
+ */
+public function exists($id)
+{
+
+if (!is_numeric($id))
+{
+	return false;
+}
+elseif (isset($this->list[$id]))
+{
+	return true;
+}
+elseif ($object=$this->get($id))
+{
+	return true;
+}
+else
+{
+	return false;
+}
+
+}
+
+/**
+ * Returns if an object exists
+ * @param name $string
+ * @return bool
+ */
+public function exists_ref($ref)
+{
+
+if (!isset($this->_fields['ref']))
+{
+	return false;
+}
+elseif (!is_string($ref))
+{
+	return false;
+}
+elseif (isset($this->list_ref[$ref]))
+{
+	return true;
+}
+elseif ($object=$this->get_ref($ref))
+{
+	return true;
+}
+else
+{
+	return false;
+}
+
+}
+
+/**
+ * Renvoie un object de la base
+ * @param string $ref
+ * @return db_object
+ */
+public function get_ref($ref)
+{
+
+if (!isset($this->_fields['ref']))
+{
+	return false;
+}
+elseif (!is_string($ref))
+{
+	return false;
+}
+elseif (isset($this->list_ref[$ref]))
+{
+	return $this->list[$this->list_ref[$ref]];
+}
+elseif (count($objects=$this->select("ref='".mysql_real_escape_string($ref)."'"))==1)
+{
+	return array_pop($objects);
+}
+else
+{
+	return false;
+}
+
+}
+
+/**
+ * Renvoie un object de la base
+ * @param int $id
+ * @return db_object
+ */
+public function get($id)
+{
+
+if (!is_numeric($id))
+{
+	return false;
+}
+elseif (isset($this->list[$id]))
+{
+	return $this->list[$id];
+}
+elseif(count($objects=$this->select('id='.$id))==1)
+{
+	return array_pop($objects);
+}
+else{
+	return false;
+}
+
+}
+
+/**
+ * Select en base de donnée
+ * @param [] $params
+ * @param int $limit
+ * @param string $order
+ * @return []
+ */
+public function select($params=null, $limit=null, $order=null)
+{
+
+$classname = $this->_name;
+
+$list = array();
+foreach ($this->db_retrieve($params, $limit, $order) as $row)
+{
+	if (!isset($this->list[$row["id"]])){
+		$this->list[$row["id"]] = $object = new $classname(null, $row);
+		if (isset($row['ref']))
+			$this->list_ref[$row["ref"]] = $row["id"];
+	}
+	else
+		$object = $this->list[$row["id"]];
+	$list[] = $object;
+}
+
+return $list;
+
+}
+/**
+ * Select en base de donnée
+ * @param [] $params
+ * @param int $limit
+ * @param string $order
+ * @return []
+ */
+public function db_retrieve($params=null, $limit=null, $order=null)
+{
+
+if ($params)
+	$q_where = "WHERE ".$params;
+else
+	$q_where = "";
+
+if ($limit)
+	$q_limit = "LIMIT ".$limit;
+else
+	$q_limit = "";
+
+if ($order){
+	$q_o = array();
+	foreach(explode(', ', $order) as $o)
+		if (count($o2=explode(' ', trim($o)))>1)
+			$q_o[] = "`".$o2[0]."` ".$o2[1];
+		else
+			$q_o[] = "`".$o2[0]."`";
+	$q_order = "ORDER BY ".implode(', ', $q_o);
+}
+else
+	$q_order = "";
+
+$select_more = array();
+$type_select_multiple = array();
+$q_select = array("`".$this->_db_id."` as `id`");
+foreach($this->_fields as $name=>$field)
+{
+	if (in_array($field["type"], $this->field_simple))
+	{
+		if ($field["type"] == "select_multiple")
+			$type_select_multiple[] = $name;
+		if (isset($field["db_fieldname"]))
+			$q_select[] = "`".$field["db_fieldname"]."` as `".$name."`";
+		else
+			$q_select[] = "`".$name."`";
+	}
+	elseif ($field["type"] == "object_list")
+	{
+		$select_more[] = $name;
+	}
+}
+
+$q_s = "SELECT ".implode(", ", $q_select)." FROM `".$this->_db_table."` ".$q_where." ".$q_order." ".$q_limit;
+$q_r = mysql_query($q_s);
+if ($this->DB_DEBUG == true || ($error=mysql_error()))
+{
+	echo "$q_s : ".$error;
+}
+$list = array();
+$list_id = array();
+while ($row=mysql_fetch_assoc($q_r))
+{
+	// @todo : tout pourris...
+	foreach($row as $i=>$j)
+		$row[$i] = stripslashes($j);
+	foreach($type_select_multiple as $name)
+	{
+		if ($row[$name] !== null)
+			$row[$name] = explode(",", $row[$name]);
+		else
+			$row[$name] = array();
+	}
+	$list[$row["id"]] = $row;
+	$list_id[] = $row["id"];
+}
+
+// Fields of type : object_list
+foreach($select_more as $name)
+{
+	$field = $this->_fields[$name];
+	$classname = $field["object_type"];
+	$q_s = "SELECT `".$field["db_field_id"]."` as id, `".$field["db_field_ref_id"]."` as ref_id FROM `".$field["db_table"]."` WHERE `".$field["db_field_ref_id"]."` IN (".implode(", ", $list_id).")";
+	$q_r = mysql_query($q_s);
+	while ($row=mysql_fetch_assoc($q_r))
+	{
+		$list[$row["ref_id"]][$name][] = $row["id"];
+	}
+}
+
+// More fields
+foreach($this->db_retrieve_more($list_id) as $id=>$row)
+	$list[$id] = array_merge($list[$id], $row);
+
+return $list;
+
+}
+
+/**
+ * retrieve more info
+ * @param []int $list_id
+ */
+protected function db_retrieve_more($list_id=null)
+{
+
+return array();
+
+}
+
+/**
+ * Count en base de donnée
+ * @param [] $params
+ * @return int
+ */
+public function count($params=null)
+{
+
+$classname = $this->_name;
+
+if ($params)
+	$q_where = "WHERE ".$params;
+else
+	$q_where = "";
+
+$q_s = "SELECT COUNT(*) FROM `".$this->_db_table."` ".$q_where;
+$q_r = mysql_query($q_s);
+if ($this->DB_DEBUG == true)
+{
+	echo "$q_s : ".mysql_error();
+}
+$row = mysql_fetch_row($q_r);
+return array_pop($row);
+
+}
+
+}
+
+/**
+ * Classe objet ORM
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class db_object
+{
+
+/**
+ * Class name
+ * @var string
+ */
+public $_name = "";
+/**
+ * Manager object
+ * @access public
+ * @var db_object_manager
+ */
+public $_manager = null;
+/**
+ * Object ID
+ * @var int
+ */
+public $id = null;
+
+/* CONSTRUCT */
+
+/**
+ * Constructeur
+ * @param int $id
+ * @param [] $info
+ */
+public function __construct($id=null, $info=null)
+{
+
+if (!$this->_name)
+	$this->_name = get_class($this);
+$classname = $this->_name;
+$this->_manager = $classname();
+
+foreach ($this->_manager->_fields as $name=>$value)
+	$this->$name = null;
+
+if (is_numeric($id))
+{
+	if ($info=$this->db_retrieve($id))
+		$this->field_update($info);
+}
+elseif (is_array($info))
+{
+	$this->field_update($info);
+}
+
+}
+
+/* DISPLAY */
+
+/**
+ * Default display
+ * @return string
+ */
+public function __tostring()
+{
+
+if ($this->id)
+	return $this->_manager->_name." #".$this->id;
+else
+	return $this->_manager->_name." # en cours...";
+
+}
+
+/**
+ * Return image url
+ * @param string $name
+ * @return string
+ */
+public function file($name)
+{
+
+if (isset($this->_manager->_fields[$name]) && in_array($this->_manager->_fields[$name]["type"], array("img", "file")) && $this->$name)
+{
+	return $this->_manager->_fields[$name]["folder"]."/".$this->$name;
+}
+
+}
+
+/**
+ * Return object associated to a field
+ * @param string $fieldname
+ * @return db_object
+ */
+function object($fieldname)
+{
+
+if (!is_string($fieldname) || !isset($this->_manager->_fields[$fieldname]))
+	return;
+
+$field = $this->_manager->_fields[$fieldname];
+if (!isset($field["type"]) || $field["type"] != "object" || !isset($field["object_type"]))
+	return;
+
+if (!is_string($classname=$field["object_type"]) || !class_exists($classname))
+	return;
+if (!is_numeric($this->$fieldname))
+	return;
+
+return $classname()->get($this->$fieldname);
+
+}
+
+/* INSERT UPDATE VERIF */
+
+public function field_calculated(&$info)
+{
+
+foreach($this->_manager->_fields as $name=>&$field) if (isset($field['calculate'])){
+	list($type, $var) = explode(':', $field['calculate']);
+	if ($type=='url'){
+		if (!isset($info[$var]))
+			continue;
+		$url = strtolower(stripAccents($info[$var]));
+		$patterns = $replacements = array();
+		$patterns[0] = '/(&amp;|&)/i';
+		$replacements[0] = '-and-';
+		$patterns[1] = '/[^a-zA-Z01-9]/i';
+		$replacements[1] = '-';
+		$patterns[2] = '/(-+)/i';
+		$replacements[2] = '-';
+		$patterns[3] = '/(-$|^-)/i';
+		$replacements[3] = '';
+		$url = preg_replace($patterns, $replacements, $url);
+		if (strlen($url)>100){
+			$urle = explode('-', $url);
+			while (strlen($url)>100){
+				array_pop($urle);
+				$url = implode('-', $urle);
+			}
+		}
+		$info[$name] = $url;
+	}
+	if ($type=='ref'){
+		if (!isset($info[$var]))
+			continue;
+		$url = strtolower(stripAccents($info[$var]));
+		$patterns = $replacements = array();
+		$patterns[0] = '/(&amp;|&)/i';
+		$replacements[0] = '';
+		$patterns[1] = '/[^a-zA-Z01-9]/i';
+		$replacements[1] = '_';
+		$patterns[2] = '/(_+)/i';
+		$replacements[2] = '_';
+		$patterns[3] = '/(_$|^_)/i';
+		$replacements[3] = '';
+		$url = preg_replace($patterns, $replacements, $url);
+		$urle = explode('_', $url);
+		$s = 0;
+		while (strlen($url)>20) {
+			$s++;
+			foreach($urle as $i=>&$j) {
+				if (strlen($j)<=$s) {
+					unset($urle[$i]);
+					$url = implode('_', $urle);
+					if (strlen($url)<=20)
+						 break;
+				}
+			}
+		}
+		while (strlen($url)>50){
+			array_pop($urle);
+			$url = implode('_', $urle);
+		}
+		$info[$name] = $url;
+	}
+}
+
+//var_dump($info); die();
+
+}
+
+/**
+ * Contrôle des champs
+ * @param [] $info
+ */
+public function field_verif(&$info)
+{
+
+if (!is_array($info))
+	$info = array();
+
+foreach($info as $name=>&$value)
+{
+	if (!isset($this->_manager->_fields[$name]))
+	{
+		unset($info[$name]);
+	}
+	else
+	{
+		$field = $this->_manager->_fields[$name];
+		if (isset($field["type"]))
+		{
+			$type = $field["type"];
+			if (in_array($type, array("object", "int", "float", "numeric", "decimal")) && !is_numeric($value))
+			{
+				$value = NULL;
+			}
+			elseif ($type == "boolean")
+			{
+				$value = ($value) ?1 :0;
+			}
+			elseif ($type == "object" && $value)
+			{
+				$object_classname = $field["object_type"];
+				if (!$object_classname()->exists($value))
+					$value = NULL;
+			}
+			elseif (in_array($type, array("string", "text", "richtext")) && !is_string($value))
+			{
+				$value = NULL;
+			}
+					elseif ($type == "select" && ((!is_string($value) && !is_numeric($value)) || !isset($field["list"][$value])))
+			{
+				$value = NULL;
+			}
+			elseif ($type == "select_multiple")
+			{
+				if (!is_array($value))
+				{
+					$value = NULL;
+				}
+				else
+				{
+					foreach($value as $i=>$v)
+						if (!isset($field["list"][$v]))
+							unset($value[$i]);
+				}
+			}
+			elseif ($type == "date" && (!is_string($value)))
+			{
+				$value = NULL;
+			}
+			elseif (in_array($type, array("datetime", "timestamp")) && (!is_string($value)))
+			{
+				$value = NULL;
+			}
+			elseif ($type == "img" || $type == "file")
+			{
+				//var_dump($_FILES);
+				// Sans upload ou upload foireux
+				if (isset($_FILES[$name]) && (!$_FILES[$name]["tmp_name"] || $_FILES[$name]["error"] != UPLOAD_ERR_OK))
+				{
+					unset($_FILES[$name]);
+				}
+				// Fichier sans nom ou nom foireux
+				if (isset($_FILES[$name]))
+				{
+					if (isset($field["filename"]))
+					{
+						$_FILES[$name]["name"] = $this->field_map_replace($field["filename"]);
+					}
+					else
+					{
+						$nb = 0;
+						$name = $field["filename"];
+						while (file_exists(PATH_ROOT."/".$field["folder"]."/".$_FILES[$name]["name"]))
+						{
+							$nb++;
+							$_FILES[$name]["name"] = $nb."-".$name;
+						}
+					}
+					$value = $_FILES[$name]["name"];
+				}
+				// Renommage sans fichier
+				elseif ($value && (isset($field["filename"]) || !$this->$name || !file_exists(PATH_ROOT."/".$field["folder"]."/".$this->$name)))
+				{
+					//echo PATH_ROOT."/".$field["folder"]."/".$this->$name;
+					unset($info[$name]);
+				}
+			}
+		}
+	}
+}
+//var_dump($_FILES); var_dump($info);
+
+}
+
+function field_map_replace($string)
+{
+
+$replace_from = $replace_to = array();
+foreach($this->_manager->_fields as $name=>$field)
+{
+	$replace_from[] = "{".$name."}";
+	$replace_to[] = $this->$name;
+}
+return str_replace($replace_from, $replace_to, $string);
+
+}
+
+/**
+ * Contrôle supplémentaire à l'insertion
+ * @param [] $info
+ */
+public function field_verif_insert(&$info)
+{
+
+}
+
+/**
+ * Contrôle supplémentaire à la mise à jour
+ * @param [] $info
+ */
+public function field_verif_update(&$info)
+{
+
+}
+
+/**
+ * Update object with data
+ * @param [] $info
+ */
+private function field_update(&$info)
+{
+
+if (!is_array($info))
+	return;
+
+foreach($info as $name=>$value)
+	if ($name=="id" || isset($this->_manager->_fields[$name]))
+		$this->$name = $value;
+
+}
+
+public function duplicate()
+{
+
+
+
+}
+
+/* OPERATIONS */
+
+/**
+ * Insertion objet
+ * @param [] $info
+ * @return bool
+ */
+public function insert($info)
+{
+
+if (is_numeric($this->id))
+	return;
+
+$this->field_verif($info);
+$this->field_calculated($info);
+$this->field_verif_insert($info);
+
+if (is_numeric($id=$this->db_insert($info)))
+{
+	$this->id = $id;
+	$this->field_update($info);
+	return true;
+}
+else
+	return false;
+
+}
+
+/**
+ * Mise à jour objet
+ * @param [] $info
+ * @return bool
+ */
+public function update($info)
+{
+
+if (!is_numeric($this->id))
+	return;
+
+$this->field_verif($info);
+foreach($info as $name=>$value)
+	if ($this->$name === $value && (!in_array($this->_manager->_fields[$name]["type"], array("img", "file")) || !isset($_FILES[$name])))
+		unset($info[$name]);
+$this->field_verif_update($info);
+
+if ($this->db_update($info))
+{
+	$this->field_update($info);
+	return true;
+}
+else
+	return false;
+
+}
+
+/**
+ * Supression objet
+ * @return bool
+ */
+public function delete()
+{
+
+if (!is_numeric($this->id))
+	return;
+
+return $this->db_delete($this->id);
+
+}
+
+/* DATABASE */
+/*
+ * Comprend autant les opérations en base de donnée que sur le système de fichiers,
+ * bref sur tout support de stockage de donnée (ce qui se tient logiquement)
+ */
+
+/**
+ * Retrieve object info from database
+ * @param int $id
+ * @return []|bool
+ */
+protected function db_retrieve($id)
+{
+
+if (!is_numeric($id) || !count($list=$this->_manager->db_retrieve("`".$this->_manager->_db_id."`='".$id."'")))
+	return false;
+
+return array_pop($list);
+
+}
+
+/**
+ * Update object in database
+ * @param [] $info
+ * @return int
+ */
+protected function db_update($info)
+{
+
+if (!is_numeric($this->id))
+	return false;
+
+$q_list = array();
+$file_move_list = $file_rename_list = $file_delete_list = array();
+//var_dump($_FILES); var_dump($info);
+foreach($info as $name=>$value)
+{
+	$field = $this->_manager->_fields[$name];
+	if (isset($field["type"]))
+	{
+		$type = $field["type"];
+		if (in_array($field["type"], $this->_manager->field_simple))
+		{
+			if ($field["type"] == "select_multiple")
+			{
+				if (is_array($value))
+					foreach($value as $i=>$v)
+						$value[$i] = mysql_real_escape_string($v);
+				$q_list[] = "`".(isset($field["db_fieldname"]) ?$field["db_fieldname"] :$name)."` = ".(is_array($value)&&count($value) ?"'".implode(",",$value)."'" :"NULL");
+			}
+			else
+				$q_list[] = "`".(isset($field["db_fieldname"]) ?$field["db_fieldname"] :$name)."` = ".($value===NULL?"NULL":"'".mysql_real_escape_string($value)."'");
+			if ($type == "img")
+			{
+				if (isset($_FILES[$name]) && $this->$name)
+					$file_delete_list[] = PATH_ROOT."/".$field["folder"]."/".$this->$name;
+				if (!isset($_FILES[$name]) && $this->$name)
+					$file_rename_list[PATH_ROOT."/".$field["folder"]."/".$this->$name] = PATH_ROOT."/".$field["folder"]."/".$value;
+				if (isset($_FILES[$name]))
+					$file_move_list[$_FILES[$name]["tmp_name"]] = PATH_ROOT."/".$field["folder"]."/".$value;
+			}
+		}
+	}
+}
+
+if (count($q_list)){
+	$q_s = "UPDATE `".$this->_manager->_db_table."` SET ".implode(", ", $q_list)." WHERE `".$this->_manager->_db_id."`='".$this->id."'";
+	$q_r = mysql_query($q_s);
+}
+
+if ($this->_manager->DB_DEBUG == true || (isset($q_s) && ($error=mysql_error())))
+{
+	echo "$q_s : ".$error;
+}
+$return = (isset($q_s) && mysql_affected_rows()>0 ?true :false);
+if ($return)
+{
+	foreach($file_delete_list as $name)
+	{
+		if ($this->_manager->FILE_DEBUG)
+			echo "<p>Delete $name</p>\n";
+		unlink($name);
+	}
+	foreach($file_rename_list as $from=>$to)
+	{
+		if ($this->_manager->FILE_DEBUG)
+			echo "<p>Rename $from $to</p>\n";
+		rename($from, $to);
+	}
+	foreach($file_move_list as $from=>$to)
+	{
+		if ($this->_manager->FILE_DEBUG)
+			echo "<p>Move uplodaed $from $to</p>\n";
+		move_uploaded_file($from, $to);
+	}
+}
+
+// More fields
+$return = ($this->db_update_more($info) || $return);
+
+return $return;
+
+}
+
+/**
+ * Modification supplémentaire
+ * @param [] $info
+ */
+protected function db_update_more($info)
+{
+
+return false;
+
+}
+
+/**
+ * Insert in database
+ * @param [] $info
+ * @return bool
+ */
+protected function db_insert($info)
+{
+
+if (is_numeric($this->id))
+	return false;
+
+$q_list_1 = $q_list_2 = array();
+$file_move_list = array();
+foreach($info as $name=>$value)
+{
+	$field = $this->_manager->_fields[$name];
+	if (isset($field["type"]))
+	{
+		if (in_array($field["type"], $this->_manager->field_simple))
+		{
+			$type = $field["type"];
+			$q_list_1[] = "`".(isset($field["db_fieldname"]) ?$field["db_fieldname"] : $name)."`";
+			if ($field["type"] == "select_multiple")
+			{
+				if (is_array($value))
+					foreach($value as $i=>$v)
+						$value[$i] = "'".mysql_real_escape_string($v)."'";
+				$q_list_2[] = (is_array($value)&&count($value) ?"(".implode(",",$value).")" :"NULL");
+			}
+			else
+				$q_list_2[] = ($value===NULL?"NULL":"'".mysql_real_escape_string($value)."'");
+			if ($type == "img")
+			{
+				$file_move_list[$_FILES[$name]["tmp_name"]] = PATH_ROOT."/".$field["folder"]."/".$value;
+			}
+		}
+	}
+}
+
+$q_s = "INSERT INTO `".$this->_manager->_db_table."` (".implode(", ", $q_list_1).") VALUES (".implode(", ", $q_list_2).")";
+$q_r = mysql_query($q_s);
+if ($this->_manager->DB_DEBUG == true)
+{
+	echo "$q_s : ".mysql_error();
+}
+
+$return = mysql_insert_id();
+
+if ($return)
+{
+	foreach($file_move_list as $from=>$to)
+	{
+		if ($this->_manager->FILE_DEBUG)
+			echo "<p>Move uploaded $from $to</p>\n";
+		move_uploaded_file($from, $to);
+	}
+}
+
+if ($return)
+	$this->db_insert_more($return, $info);
+
+return $return;
+
+}
+
+/**
+ * Insertions supplémentaires
+ * @param int $id
+ * @param [] $info
+ * @return bool
+ */
+protected function db_insert_more($id, $info)
+{
+
+return false;
+
+}
+
+/**
+ * Delete object in database
+ * @return bool
+ */
+protected function db_delete()
+{
+
+if (!is_numeric($this->id))
+	return false;
+
+$q_s = "DELETE FROM `".$this->_manager->_db_table."` WHERE `".$this->_manager->_db_id."`='".$this->id."'";
+$q_r = mysql_query($q_s);
+if ($this->_manager->DB_DEBUG == true)
+{
+	echo "$q_s : ".mysql_error();
+}
+$return = (mysql_affected_rows()>0 ?true :false);
+
+if ($return)
+	$this->db_delete_more();
+
+return $return;
+
+}
+
+/**
+ * Suppressions supplémentaires
+ * @return bool
+ */
+protected function db_delete_more()
+{
+
+return false;
+
+}
+
+}
+
+?>

+ 97 - 0
include/class/menu.class.inc.php

@@ -0,0 +1,97 @@
+<?php
+
+/**
+ * Gestion menu
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class menu_manager extends db_object_manager{
+
+public $DB_DEBUG = false;
+public $FILE_DEBUG = false;
+
+public $_fields = array(
+	"parent_id" => array("label"=>"Parent", "type"=>"object", "object_type"=>"menu"),
+	"page_id" => array("label"=>"Page", "type"=>"object", "object_type"=>"page"),
+	"pos" => array("label"=>"Position", "type"=>"int"),
+	"visible" => array("label"=>"Visible", "type"=>"bool"),
+	"params" => array("label"=>"Paramètres supplémentaires", "type"=>""),
+);
+public $_field_disp_list = array("page_id", "parent_id", "pos", "visible");
+
+protected function db_retrieve_more($list_id=null)
+{
+
+if (!is_array($list_id))
+	return array();
+
+$list = array();
+$sql = "SELECT * FROM `menu_params` WHERE `menu_id` IN (".implode(',', $list_id).") AND `value` IS NOT NULL";
+$q = mysql_query($sql);
+if ($this->DB_DEBUG == true || ($error=mysql_error())){
+	echo "$sql : ".$error;
+}
+while($row = mysql_fetch_assoc($q))
+	$list[$row['menu_id']]['params'][$row['name']] = $row['value'];
+return $list;
+
+}
+
+}
+
+class menu extends db_object{
+
+public $params = array();
+
+public function __tostring(){
+
+$page = $this->page();
+if (count($this->params))
+	return $page->title(current($this->params));
+else
+	return $page->title();
+
+}
+
+public function page(){
+
+return $this->object('page_id');
+
+}
+
+function controller(){
+
+return $this->page()->controller();
+
+}
+
+public function parent(){
+
+return $this->object('parent_id');
+
+}
+
+protected function db_update_more($info)
+{
+
+if (!is_array($info))
+	return false;
+
+if (!isset($info['params']) || !count($info['params']))
+	return false;
+
+foreach ($info['params'] as $name=>$value){
+	$sql = "REPLACE INTO `menu_params`
+		(`menu_id`, `name`, `value`)
+		VALUES ('$this->id', '$name', '".mysql_real_escape_string($value)."')";
+	$q = mysql_query($sql);
+	return mysql_affected_rows()>0;
+}
+
+return false;
+
+}
+
+}
+

+ 215 - 0
include/class/page.class.inc.php

@@ -0,0 +1,215 @@
+<?php
+
+/**
+ * Gestion pages
+ * @author mathieu
+ * @package db_object
+ *
+ */
+class page_manager extends db_object_manager{
+
+public $DB_DEBUG = false;
+public $FILE_DEBUG = false;
+
+public $_fields = array(
+	"controller_id" => array("label"=>"Controller", "type"=>"object", "object_type"=>"controller"),
+	"ref" => array("label"=>"Référence courte", "type"=>"string", "readonly"=>true),
+	"url" => array("label"=>"URL", "type"=>"string"),
+	"titre" => array("label"=>"Titre", "type"=>"string"),
+	"header_title" => array("label"=>"Titre HTML", "type"=>"string"),
+	"header_description" => array("label"=>"Description HTML", "type"=>"text"),
+	"params" => array("label"=>"Paramètres supplémentaires", "type"=>""),
+);
+public $_field_disp_list = array('controller_id', "ref", "titre");
+
+protected function db_retrieve_more($list_id=null)
+{
+
+if (!is_array($list_id))
+	return array();
+
+$list = array();
+$sql = "SELECT p.id, pp.name, pp.value
+	FROM `controller_params` cp
+	JOIN `page` p ON p.controller_id=cp.controller_id
+	LEFT JOIN `page_params` pp ON pp.page_id=p.id AND pp.name=cp.name
+	WHERE p.`id` IN (".implode(',', $list_id).")";
+$q = mysql_query($sql);
+while($row = mysql_fetch_assoc($q)){
+	$list[$row['id']]['params'][$row['name']] = $row['value'];
+	$list[$row['id']][$row['name']] = $row['value'];
+}
+//var_dump($list);
+return $list;
+
+}
+
+}
+
+class page extends db_object{
+
+public $param_id;
+public $params = array();
+
+function __construct($id=null, $info=null){
+
+if (!isset($info['params']) || !is_array($info['params']))
+	$info['params'] = array();
+
+parent::__construct($id, $info);
+
+}
+
+protected function db_update_more($info)
+{
+
+//var_dump($info);
+//var_dump($this->params);
+
+$fields = $this->controller()->fields;
+if (! empty($_FILES['params'])) foreach($_FILES['params']['tmp_name'] as $name=>$value) {
+	//echo $name;
+	if ($value && isset($fields[$name]) && $fields[$name]['type']=='img')
+		$info['params'][$name] = $value;
+}
+//var_dump($info);
+
+
+if (!is_array($info))
+	return false;
+
+if (!isset($info['params']) || !count($info['params']))
+	return false;
+
+$fields = $this->controller()->fields;
+
+$r = 0;
+foreach ($info['params'] as $name=>$value){
+	if (! isset($fields[$name]))
+		continue;
+	$field = $fields[$name];
+	$options = json_decode($field['options'], true);
+	if ($field['type']=='img') {
+		//var_dump($options);
+		$value = $options['filename'];
+		//var_dump($_FILES);
+		//echo 'From : '.$_FILES['params']['tmp_name'][$name]. ' to '.$value;
+		move_uploaded_file($_FILES['params']['tmp_name'][$name], '../'.$value);
+		//echo $value;
+		//continue;
+	}
+	$sql = "REPLACE INTO `page_params`
+		(`page_id`, `name`, `value`)
+		VALUES ('$this->id', '$name', '".mysql_real_escape_string($value)."')";
+	$q = mysql_query($sql);
+	//echo "<p>$sql</p>";
+	if ($error=mysql_error($q))
+		echo "<p>$error : $sql</p>";
+	$r += (mysql_affected_rows()>0 ?1 :0);
+}
+
+return $r>0 ?true :false;
+
+}
+
+function __tostring(){
+
+return $this->title();
+
+}
+
+function controller(){
+
+return $this->object('controller_id');
+
+}
+
+function params_set($params){
+
+$controller = $this->controller();
+$controller_fields = $controller->fields;
+
+if (is_array($params)){
+	foreach($params as $name=>$value) if (is_string($name) && isset($controller_fields[$name])){
+		$this->params[$name] = $value;
+	}
+}
+
+}
+
+function param_set($param_id){
+
+$this->param_id = $param_id;
+
+$controller = $this->controller();
+$controller_fields = $controller->fields;
+foreach($controller_fields as $field) if ($field['url_get']){
+	//var_dump($field);
+	$this->params[$field['name']] = $param_id;
+	break;
+}
+
+}
+
+/**
+ * Retrieve GET params
+ */
+function params_get(){
+
+$this->params_set($_GET);
+
+}
+
+/**
+ * Retrieve POST params
+ */
+function params_post(){
+
+$this->params_set($_POST);
+
+}
+
+function title($param_id=null){
+
+$param_id = is_array($param_id) ?current($param_id) :($param_id ?$param_id :$this->param_id);
+
+if (!$param_id)
+	return $this->titre;
+else
+	return $this->controller()->param_title($param_id);
+
+}
+
+function url($param_id=null){
+
+$param_id = is_array($param_id) ?current($param_id) :($param_id ?$param_id :$this->param_id);
+
+if (!$this->url)
+	return '/';
+elseif (!$param_id)
+	return '/'.$this->url.'-'.$this->id.'.html';
+else
+	return '/'.$this->url.'-'.$this->id.'/'.$this->controller()->param_url($param_id).'.html';
+
+}
+
+function link($param_id=null){
+
+$param_id = is_array($param_id) ?current($param_id) :($param_id ?$param_id :$this->param_id);
+//var_dump($param_id);
+
+return '<a href="'.$this->url($param_id).'">'.$this->title($param_id).'</a>';
+
+}
+
+function display(){
+
+$controller = $this->controller();
+$controller->page = $this;
+//var_dump($controller);
+$controller->display();
+
+}
+
+}
+

+ 130 - 0
include/class/template.class.inc.php

@@ -0,0 +1,130 @@
+<?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');
+
+}
+
+}
+

+ 75 - 0
include/common.inc.php

@@ -0,0 +1,75 @@
+<?php
+
+if (!mysql_connect(DB_HOST, DB_USER, DB_PASS))
+	die("Erreur Connection MySQL");
+elseif (!mysql_select_db(DB_BASE))
+	die("Erreur Base de donnée : ".DB_BASE);
+mysql_query("SET NAMES UTF8");
+
+include "autoload.inc.php";
+include "field.inc.php";
+
+function date_mysql($date){
+	$d = explode(' ', $date);
+	$d[0] = implode('/', array_reverse(explode('-', $d[0])));
+	return implode(' ', $d);
+}
+
+function header_desc_format($string){
+	return str_replace('"', "'", $string);
+}
+
+function stripAccents($string){
+	return str_replace(
+		array('à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'),
+		array('a','a','a','a','a','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','u','y','y','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','U','Y'),
+		$string
+	);
+	return strtr(
+		$string,
+		'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ',
+		'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY'
+	);
+}
+
+session_start();
+
+// Valeurs communes
+commonval()->define();
+
+if (isset($_POST["_login"]))
+{
+	//var_dump($_POST);
+	if (isset($_POST["username"]) && is_string($_POST["username"]) && isset($_POST["password"]) && is_string($_POST["password"]))
+	{
+		$sql = "SELECT `id`, `email`, `type`, `nom` FROM `account` WHERE `email`='".mysql_real_escape_string($_POST["username"])."' AND MD5(`password`)='".mysql_real_escape_string($_POST["password"])."' AND actif=1";
+		$q = mysql_query($sql);
+		if (mysql_num_rows($q) == 1)
+		{
+			list($_SESSION["account_id"], $_SESSION["account_email"], $_SESSION["account_type"], $_SESSION["account_name"]) = mysql_fetch_row($q);
+			//echo 'Connecté';
+		}
+		//echo $_SESSION["account_type"];
+		//echo $sql;
+	}
+}
+elseif (isset($_POST["_logout"]) && isset($_SESSION["account_id"]))
+{
+	unset($_SESSION["account_id"]);
+	unset($_SESSION["account_email"]);
+	unset($_SESSION["account_type"]);
+	unset($_SESSION["account_name"]);
+}
+
+// Controlleurs
+//controlleur()->select();
+
+// Pages
+page()->select();
+
+// Activités
+activite()->select();
+
+// Réalisations
+//realisation()->select();
+

+ 0 - 0
include/controller/.gitkeep


+ 2 - 0
include/controller/.htaccess

@@ -0,0 +1,2 @@
+order deny,allow
+deny from all

+ 19 - 0
include/controller/accueil.inc.php

@@ -0,0 +1,19 @@
+<?php
+
+class accueil_controller extends controller{
+
+function view(){
+
+$activite_list = activite()->select(null, null, "pos");
+//var_dump($activite_list);
+
+$img_list = array(
+	'amenagement', 'batiment', 'conseil', 'management'
+);
+
+global $activite_list, $img_list;
+
+}
+
+}
+

+ 41 - 0
include/controller/activite.inc.php

@@ -0,0 +1,41 @@
+<?php
+
+class activite_controller extends controller{
+
+function param_url($id){
+
+$activite = activite()->get($id);
+return $activite ?$activite->url.'-'.$id :'';
+
+}
+
+function param_title($id){
+
+$activite = activite()->get($id);
+return $activite ?$activite->titre :'';
+
+}
+
+public function view()
+{
+
+$activite = activite()->get($this->params['activite_id']);
+
+$page = page('activite');
+$url = "http://www.ardeche-miniatures.com".$page->url($activite->id);
+
+$this->header['title'] = $activite->titre.' : Activité';
+$this->header['description'] = header_desc_format($activite->titre.' : Activité au parc Ardèche Miniatures');
+$this->header['meta'] = array(
+	"og:title"=>str_replace('"', "'", $activite->titre),
+	"og:url"=>$url,
+	"og:site_name"=>"Ardèche Miniatures",
+	"og:type"=>"article",
+	"og:image"=>"http://www.ardeche-miniatures.com/img2/300/activites/$activite->img",
+	"og:description"=>str_replace('"', "'", $activite->resume),
+);
+
+}
+
+}
+

+ 18 - 0
include/controller/activite_index.inc.php

@@ -0,0 +1,18 @@
+<?php
+
+class activite_index_controller extends controller{
+
+function view(){
+
+/*
+$activites = activite()->select('home_visible=1 AND pos=1');
+$activite = array_pop($activites);
+
+header('Location: '.page()->get(15)->url($activite->id));
+die('Redirection...');
+*/
+
+}
+
+}
+

+ 35 - 0
include/controller/actualite.inc.php

@@ -0,0 +1,35 @@
+<?php
+
+class actualite_controller extends controller {
+
+public function param_title($id){
+	return actualite()->get($id)->titre;
+}
+
+public function param_url($id){
+	return actualite()->get($id)->url.'-'.$id;
+}
+
+public function view()
+{
+
+$actualite = actualite()->get($this->params['actualite_id']);
+
+$page = page('actualite');
+$url = "http://www.ardeche-miniatures.com".$page->url($actualite->id);
+
+$this->header['title'] = $actualite->titre.' : Actualité';
+$this->header['description'] = header_desc_format($actualite->titre.' : Actualité au parc Ardèche Miniatures');
+$this->header['meta'] = array(
+	"og:title"=>str_replace('"', "'", $actualite->titre),
+	"og:url"=>$url,
+	"og:site_name"=>"Ardèche Miniatures",
+	"og:type"=>"article",
+	"og:image"=>"http://www.ardeche-miniatures.com/img2/300/actualites/$actualite->img",
+	"og:description"=>str_replace('"', "'", $actualite->resume),
+);
+
+}
+
+}
+

+ 6 - 0
include/controller/actualite_index.inc.php

@@ -0,0 +1,6 @@
+<?php
+
+class actualite_index_controller extends controller {
+
+}
+

+ 24 - 0
include/controller/cat.inc.php

@@ -0,0 +1,24 @@
+<?php
+
+class cat_controller extends controller {
+
+public function param_title($id){
+	return cat()->get($id)->titre;
+}
+
+public function param_url($id){
+	return cat()->get($id)->url.'-'.$id;
+}
+
+public function view()
+{
+
+$cat = cat()->get($this->params['cat_id']);
+
+$this->header['title'] = $cat->titre;
+$this->header['description'] = header_desc_format($cat->resume);
+
+}
+
+}
+

+ 7 - 0
include/controller/construction.inc.php

@@ -0,0 +1,7 @@
+<?php
+
+
+class construction_controller extends controller{
+
+}
+

+ 66 - 0
include/controller/contact.inc.php

@@ -0,0 +1,66 @@
+<?php
+
+class contact_controller extends controller{
+
+function view(){
+
+$form = array("nom"=>"", "prenom"=>"", "adresse"=>"", "cp"=>"", "ville"=>"", "tel"=>"", "email"=>"", "objet"=>"", "message"=>"");
+$form_required = array("nom", "prenom", "ville", "tel", "email", "objet", "message");
+$form_email = array("nom"=>"Nom", "prenom"=>"Prénom", "adresse"=>"ADresse", "cp"=>"Code postal", "ville"=>"Ville", "tel"=>"Téléphone", "email"=>"eMail", "objet"=>"Objet", "message"=>"Message");
+
+// Assignation POST
+foreach($_POST as $i=>$j)
+	if (isset($form[$i]) && is_string($j))
+		$form[$i] = $j;
+
+// Submit
+if (isset($_POST["_contact"]))
+{
+	$form["_submitted"] = true;
+
+	// Captcha
+	if (isset($form["_submitted"]) && (!isset($_POST["_captcha"]) || $_POST["_captcha"] != $_SESSION["captcha"]))
+		$form["_message"] = "Le code de sécurité que vous avez saisi est invalide (".$_POST["_captcha"]." au lieu de ".$_SESSION["captcha"].")";
+	
+	// Vérif email
+	if (!preg_match("/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/", $form["email"]))
+	{
+		$form["_message"] = "L'adresse email que vous avez saisie n'est pas valide";
+	}
+	
+	// Champs remplis
+	foreach($form_required as $i)
+	{
+		if (!$form[$i])
+		{
+			$form["_message"] = "Veuillez compléter l'ensemble des champs requis";
+		}
+	}
+	
+	// Envoi
+	if (!isset($form["_message"]))
+	{
+		$message_header = "Content-Type: text/plain; charset=utf-8\r\nFrom: ".$form["prenom"]." ".$form["nom"]." <".$form["email"].">\r\n";
+		$message = "";
+		foreach($form_email as $i=>$j)
+			$message .= "$j : ".$form[$i]."\r\n";
+		if (mail($page["form_email"], "Message en provenance du site Internet", $message, $message_header))
+		{
+			$form["_message"] = "Votre message nous a bien été transmis.";
+			// Sppression des informations
+			foreach($form_email as $i=>$j)
+				$form[$i] = "";
+			unset($form["_submitted"]);
+		}
+		else
+		{
+			$form["_message"] = "Une erreur est survenue lors de l'envoi de votre message. Veuillez réessayer ultérieurement";
+		}
+	}	
+}
+
+$this->params['form'] = $form;
+
+}
+
+}

+ 6 - 0
include/controller/contenu.inc.php

@@ -0,0 +1,6 @@
+<?php
+
+class contenu_controller extends controller{
+
+}
+

+ 35 - 0
include/controller/evenement.inc.php

@@ -0,0 +1,35 @@
+<?php
+
+class evenement_controller extends controller {
+
+public function param_title($id){
+	return evenement()->get($id)->titre;
+}
+
+public function param_url($id){
+	return evenement()->get($id)->url.'-'.$id;
+}
+
+public function view()
+{
+
+$evenement = evenement()->get($this->params['evenement_id']);
+
+$page = page('evenement');
+$url = "http://www.ardeche-miniatures.com".$page->url($evenement->id);
+
+$this->header['title'] = $evenement->titre;
+$this->header['description'] = header_desc_format($evenement->resume.' : Evénement au parc Ardèche Miniatures');
+$this->header['meta'] = array(
+	"og:title"=>str_replace('"', "'", $evenement->titre),
+	"og:url"=>$url,
+	"og:site_name"=>"Ardèche Miniatures",
+	"og:type"=>"article",
+	"og:image"=>"http://www.ardeche-miniatures.com/img2/300/evenement/$evenement->img",
+	"og:description"=>str_replace('"', "'", $evenement->resume),
+);
+
+}
+
+}
+

+ 24 - 0
include/controller/evenement.inc.php.orig

@@ -0,0 +1,24 @@
+<?php
+
+class evenement_controller extends controller {
+
+public function param_title($id){
+	return evenement()->get($id)->titre;
+}
+
+public function param_url($id){
+	return evenement()->get($id)->url.'-'.$id;
+}
+
+public function view()
+{
+
+$evenement = evenement()->get($this->params['evenement_id']);
+
+$this->header['title'] = $evenement->titre;
+$this->header['description'] = header_desc_format($evenement->description.' : Evénement au parc Ardèche Miniatures');
+
+}
+
+}
+

+ 15 - 0
include/controller/intranet.inc.php

@@ -0,0 +1,15 @@
+<?php
+
+class intranet_controller extends controller{
+
+function view(){
+
+if (!isset($_SESSION["account_id"]) || !in_array($_SESSION["account_type"], array("admin","user")))
+	$subtemplate = "unauth";
+
+global $subtemplate;
+
+}
+
+}
+

+ 12 - 0
include/controller/introuvable.inc.php

@@ -0,0 +1,12 @@
+<?php
+
+class introuvable_controller extends controller{
+
+function view(){
+
+header("HTTP/1.0 404 Not Found");
+
+}
+
+}
+

+ 6 - 0
include/controller/mentions.inc.php

@@ -0,0 +1,6 @@
+<?php
+
+class mentions_controller extends controller{
+
+}
+

+ 41 - 0
include/controller/miniature.inc.php

@@ -0,0 +1,41 @@
+<?php
+
+class miniature_controller extends controller{
+
+function param_url($id){
+
+$miniature = miniature()->get($id);
+return $miniature ?$miniature->url.'-'.$id :'';
+
+}
+
+function param_title($id){
+
+$miniature = miniature()->get($id);
+return $miniature ?$miniature->titre :'';
+
+}
+
+public function view()
+{
+
+$miniature = miniature()->get($this->params['miniature_id']);
+
+$page = page('miniature');
+$url = "http://www.ardeche-miniatures.com".$page->url($miniature->id);
+
+$this->header['title'] = $miniature->titre.' : Miniature';
+$this->header['description'] = header_desc_format($miniature->resume.' : Miniature du parc Ardèche Miniatures');
+$this->header['meta'] = array(
+	"og:title"=>"$miniature->titre",
+	"og:url"=>$url,
+	"og:site_name"=>"Ardèche Miniatures",
+	"og:type"=>"article",
+	"og:image"=>"http://www.ardeche-miniatures.com/img2/300/miniature/$miniature->img",
+	"og:description"=>$miniature->resume,
+);
+
+}
+
+}
+

+ 24 - 0
include/controller/partenaire.inc.php

@@ -0,0 +1,24 @@
+<?php
+
+class partenaire_controller extends controller {
+
+public function param_title($id){
+	return partenaire()->get($id)->nom;
+}
+
+public function param_url($id){
+	return partenaire()->get($id)->url.'-'.$id;
+}
+
+public function view()
+{
+
+$partenaire = partenaire()->get($this->params['partenaire_id']);
+
+$this->header['title'] = $partenaire->titre.' : Partenaire';
+$this->header['description'] = header_desc_format($partenaire->titre.' : Partenaire du parc Ardèche Miniatures');
+
+}
+
+}
+

+ 24 - 0
include/controller/partenaire_cat.inc.php

@@ -0,0 +1,24 @@
+<?php
+
+class partenaire_cat_controller extends controller {
+
+public function param_title($id){
+	return cat()->get($id)->titre;
+}
+
+public function param_url($id){
+	return cat()->get($id)->url.'-'.$id;
+}
+
+public function view()
+{
+
+$cat = cat()->get($this->params['cat_id']);
+
+$this->header['title'] = $cat->titre.' : Partenaires';
+$this->header['description'] = header_desc_format($cat->titre.' : Partenaires du parc Ardèche Miniatures');
+
+}
+
+}
+

+ 24 - 0
include/controller/partenaire_cat.inc.php.orig

@@ -0,0 +1,24 @@
+<?php
+
+class partenaire_cat_controller extends controller {
+
+public function param_title($id){
+	return cat()->get($id)->nom;
+}
+
+public function param_url($id){
+	return cat()->get($id)->url.'-'.$id;
+}
+
+public function view()
+{
+
+$cat = cat()->get($this->params['cat_id']);
+
+$this->header['title'] = $cat->titre.' : Partenaires';
+$this->header['description'] = header_desc_format($cat->titre.' : Partenaires du parc Ardèche Miniatures');
+
+}
+
+}
+

+ 6 - 0
include/controller/partenaire_index.inc.php

@@ -0,0 +1,6 @@
+<?php
+
+class partenaire_index_controller extends controller {
+
+}
+

+ 46 - 0
include/controller/password.inc.php

@@ -0,0 +1,46 @@
+<?php
+
+class password_controller extends controller{
+
+function view(){
+
+$form = array("email"=>"", "message"=>"", "form_aff"=>true);
+
+if (isset($_POST["_password"]))
+{
+	if (!isset($_POST["email"]) || !is_string($_POST["email"]) || !$_POST["email"])
+	{
+		$form["message"] = "Adresse email invalide";
+	}
+	elseif (!isset($_POST["_captcha"]) || !isset($_SESSION["captcha"]) || $_POST["_captcha"] != $_SESSION["captcha"])
+	{
+		$form["message"] = "Code de sécurité Captcha invalide";
+		$form["email"] = $_POST["email"];
+	}
+	else
+	{
+		$q_s = "SELECT `password` FROM account WHERE email='".mysql_real_escape_string($_POST["email"])."'";
+		$q_r = mysql_query($q_s);
+		unset($_SESSION["captcha"]);
+		if (list($password)=mysql_fetch_row($q_r))
+		{
+			mail($_POST["email"], "Votre mot de passe sur le site D2P", "Votre mot de passe sur le site D2P est :\r\n  * $password\r\n", "From: ".$this->params["email_from"]);
+			$form["message"] = "Votre mot de passe vient de vous être renvoyé par email";
+			$form["form_aff"] = false;
+		}
+		else
+		{
+			$form["message"] = "Adresse email invalide";
+	                $form["email"] = $_POST["email"];
+		}
+	}
+}
+
+//var_dump($form);
+
+$this->params['form'] = $form;
+
+}
+
+}
+

+ 20 - 0
include/controller/realisation.inc.php

@@ -0,0 +1,20 @@
+<?php
+
+class realisation_controller extends controller{
+
+function param_url($id){
+
+$activite = activite()->get($id);
+return $activite->url.'-'.$id;
+
+}
+
+function param_title($id){
+
+$activite = activite()->get($id);
+return $activite->titre;
+
+}
+
+}
+

+ 16 - 0
include/controller/realisation_index.inc.php

@@ -0,0 +1,16 @@
+<?php
+
+class realisation_index_controller extends controller{
+
+function view(){
+
+$activites = activite()->select('home_visible=1 AND pos=1');
+$activite = array_pop($activites);
+
+header('Location: '.page()->get(23)->url($activite->id));
+die('Redirection...');
+
+}
+
+}
+

+ 20 - 0
include/controller/realisation_projet.inc.php

@@ -0,0 +1,20 @@
+<?php
+
+class realisation_projet_controller extends controller{
+
+function param_url($id){
+
+$realisation = realisation()->get($id);
+return $realisation->url.'-'.$id;
+
+}
+
+function param_title($id){
+
+$realisation = realisation()->get($id);
+return $realisation->titre;
+
+}
+
+}
+

+ 14 - 0
include/controller/societe.inc.php

@@ -0,0 +1,14 @@
+<?php
+
+class societe_controller extends controller{
+
+public function view()
+{
+
+$this->params['ref'] = $this->page->ref;
+$this->params['titre'] = $this->page->titre;
+
+}
+
+}
+

Some files were not shown because too many files changed in this diff