From 5dfe5e84a7007ddd9737707ce15f0155e6415066 Mon Sep 17 00:00:00 2001 From: dj3c1t Date: Sun, 26 May 2013 01:06:03 +0200 Subject: [PATCH] module config et role webmaster --- mw/app/config.xml | 17 ++- mw/app/data/modules/share/mw_data_out_config.php | 2 +- mw/app/data/modules/share/mw_data_valid_config.php | 35 +++++ mw/app/data/modules/sql/mw_data_users.php | 28 ++-- mw/app/init/0700_links.php | 8 +- mw/app/mods/admin/config.php | 60 --------- mw/app/mods/admin/index.php | 2 +- mw/app/mods/admin/users.php | 146 +------------------- mw/app/mods/config/index.php | 33 +++++ mw/app/mods/{admin => config}/plugins.php | 12 +- mw/app/mods/config/roles.php | 150 +++++++++++++++++++++ mw/app/mods/config/templates.php | 63 +++++++++ mw/app/mods/users/identification.php | 53 ++++++-- mw/app/out/default/config.php | 36 +++++ .../{admin_plugins.css => config_plugins.css} | 0 .../out/default/js/actions/{admin.js => config.js} | 0 mw/app/out/default/layouts/admin.xml | 9 +- mw/app/out/default/layouts/config.xml | 20 +++ mw/app/out/default/views/admin/users/add.php | 4 +- mw/app/out/default/views/admin/users/edit.php | 4 +- .../views/admin/users/{list.php => index.php} | 4 +- mw/app/out/default/views/config/colonne.php | 5 + .../views/{admin/config.php => config/index.php} | 37 +---- .../plugins/list.php => config/plugins/index.php} | 10 +- .../users/add_role.php => config/roles/add.php} | 4 +- .../users/edit_role.php => config/roles/edit.php} | 6 +- .../users/roles.php => config/roles/index.php} | 15 +-- .../out/default/views/config/templates/index.php | 49 +++++++ .../out/default/views/config/templates/options.php | 32 +++++ mw/app/out/default/views/footer.php | 3 + mw/app/out/default/views/forms/contact/index.php | 2 + mw/env/modules/mw_env_urls.php | 6 +- 32 files changed, 545 insertions(+), 310 deletions(-) create mode 100644 mw/app/data/modules/share/mw_data_valid_config.php delete mode 100644 mw/app/mods/admin/config.php create mode 100644 mw/app/mods/config/index.php rename mw/app/mods/{admin => config}/plugins.php (95%) create mode 100644 mw/app/mods/config/roles.php create mode 100644 mw/app/mods/config/templates.php create mode 100644 mw/app/out/default/config.php rename mw/app/out/default/css/actions/{admin_plugins.css => config_plugins.css} (100%) rename mw/app/out/default/js/actions/{admin.js => config.js} (100%) create mode 100644 mw/app/out/default/layouts/config.xml rename mw/app/out/default/views/admin/users/{list.php => index.php} (95%) create mode 100644 mw/app/out/default/views/config/colonne.php rename mw/app/out/default/views/{admin/config.php => config/index.php} (55%) rename mw/app/out/default/views/{admin/plugins/list.php => config/plugins/index.php} (73%) rename mw/app/out/default/views/{admin/users/add_role.php => config/roles/add.php} (76%) rename mw/app/out/default/views/{admin/users/edit_role.php => config/roles/edit.php} (68%) rename mw/app/out/default/views/{admin/users/roles.php => config/roles/index.php} (75%) create mode 100644 mw/app/out/default/views/config/templates/index.php create mode 100644 mw/app/out/default/views/config/templates/options.php diff --git a/mw/app/config.xml b/mw/app/config.xml index 7d3d91c..e16483f 100644 --- a/mw/app/config.xml +++ b/mw/app/config.xml @@ -46,17 +46,13 @@ + - - - - - @@ -67,6 +63,14 @@ + + + + + + + + @@ -77,6 +81,8 @@ + + @@ -89,6 +95,7 @@ + diff --git a/mw/app/data/modules/share/mw_data_out_config.php b/mw/app/data/modules/share/mw_data_out_config.php index 173efbe..d5471cf 100644 --- a/mw/app/data/modules/share/mw_data_out_config.php +++ b/mw/app/data/modules/share/mw_data_out_config.php @@ -10,7 +10,7 @@ if(!isset($this->sxml)) $this->sxml = new sxml(); $this->sxml->parse($this->buffer); $this->buffer = $this->sxml->data["config"][0]; - if($this->buffer["subs"]) foreach($this->buffer["subs"] as $key => $value){ + if(isset($this->buffer["subs"]) && $this->buffer["subs"]) foreach($this->buffer["subs"] as $key => $value){ $config[$key] = array( "type" => $value[0]["attrs"]["type"], "default" => $value[0]["attrs"]["default"], diff --git a/mw/app/data/modules/share/mw_data_valid_config.php b/mw/app/data/modules/share/mw_data_valid_config.php new file mode 100644 index 0000000..aace0d7 --- /dev/null +++ b/mw/app/data/modules/share/mw_data_valid_config.php @@ -0,0 +1,35 @@ + $config, + "messages" => array(), + "erreurs" => array() + ); + if(isset($input["site_name"])) $res["config"]["site_name"] = $input["site_name"]; + if(isset($input["description"])) $res["config"]["description"] = $input["description"]; + if(isset($input["max_list"]) && $input["max_list"]){ + $res["config"]["max_list"] = $input["max_list"]; + if(!preg_match("/^[0-9]+$/", $res["config"]["max_list"])){ + $res["messages"][] = "la taille maximum des listes doit être un nombre"; + } + } + else $res["config"]["max_list"] = ""; + if(isset($input["contact_form"]) && $input["contact_form"]){ + $res["config"]["contact_form"] = "1"; + if(!isset($input["email"]) || !trim($input["email"])){ + $res["messages"][] = "merci de préciser un email pour le formulaire de contact"; + } + } + else $res["config"]["contact_form"] = "0"; + if(isset($input["email"])) $res["config"]["email"] = trim($input["email"]); + if(isset($input["captcha"]) && $input["captcha"]) $res["config"]["captcha"] = "1"; + else $res["config"]["captcha"] = "0"; + return $res; + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/modules/sql/mw_data_users.php b/mw/app/data/modules/sql/mw_data_users.php index a1d76bd..32bc0c5 100644 --- a/mw/app/data/modules/sql/mw_data_users.php +++ b/mw/app/data/modules/sql/mw_data_users.php @@ -450,19 +450,23 @@ function load_session(){ @session_start(); if(!isset($_SESSION["id"])) $this->clear_session(); - if( - $user = ( - isset($_COOKIE["user"]) || isset($_SESSION["user"]) ? - $this->user(isset($_COOKIE["user"]) ? $_COOKIE["user"] : $_SESSION["user"]) - : array() - ) - ){ - if(isset($_COOKIE["user"])) $this->set_session($user); + $user = array(); + if(isset($_SESSION["user"])){ + $user = $this->user($_SESSION["user"]); + } + elseif(isset($_COOKIE["user"]) && isset($_COOKIE["pass"])){ + if($user = $this->user($_COOKIE["user"])){ + $user["password"] = $_COOKIE["pass"]; + $this->set_session($user); + } + } + if($user){ if(!$this->user_ok($user)){ $this->clear_session(); $user = array(); } } + else $user = array(); $this->user = $user; return $user; } @@ -471,7 +475,9 @@ $_SESSION["user"] = $user["login"]; $_SESSION["pass"] = md5($user["password"].$_SESSION["id"]); $env = $this->env(); - return setcookie("user", $user["login"], time() + (60 * 60 * 24 * 7), $env->path("web")); + return + setcookie("user", $user["login"], time() + (60 * 60 * 24 * 7), $env->path("web")) + && setcookie("pass", $user["password"], time() + (60 * 60 * 24 * 7), $env->path("web")); } function clear_session(){ @@ -480,7 +486,9 @@ $_SESSION["ip"] = $_SERVER["REMOTE_ADDR"]; $_SESSION["id"] = md5(rand()); $env = $this->env(); - return setcookie("user", "", 0, $env->path("web")); + return + setcookie("user", "", 0, $env->path("web")) + && setcookie("pass", "", 0, $env->path("web")); } function get_session_user(){ diff --git a/mw/app/init/0700_links.php b/mw/app/init/0700_links.php index 2057a4a..f995635 100644 --- a/mw/app/init/0700_links.php +++ b/mw/app/init/0700_links.php @@ -1,11 +1,11 @@ init_links()){ - $this->set_link("admin/config", $this->url("admin/config"), "Configuration", 10); $this->set_link("admin/users", $this->url("admin/users"), "Utilisateurs", 20); - $this->set_link("admin/users/list", $this->url("admin/users/index"), "Liste des utilisateurs", 10); - $this->set_link("admin/users/roles", $this->url("admin/users/roles"), "Rôles", 20); - $this->set_link("admin/plugins", $this->url("admin/plugins"), "Plugins", 30); + $this->set_link("config/config", $this->url("config"), "Configuration générale", 10); + $this->set_link("config/template", $this->url("config/templates"), "Template", 20); + $this->set_link("config/roles", $this->url("config/roles"), "Rôles", 30); + $this->set_link("config/plugins", $this->url("config/plugins"), "Plugins", 40); } else $this->erreur("impossible de charger les liens", true); diff --git a/mw/app/mods/admin/config.php b/mw/app/mods/admin/config.php deleted file mode 100644 index 7fc320a..0000000 --- a/mw/app/mods/admin/config.php +++ /dev/null @@ -1,60 +0,0 @@ -data(); - if(($CONFIG = $env->get_CONFIG()) !== false){ - if(!$CONFIG["out"]) $CONFIG["out"] = "dist"; - $env->set_out("config", $CONFIG); - if(($out_config = $env->get_out_config()) !== false){ - $env->set_out("out_config", $out_config); - if($env->set_out("out_pathes", $env->out_pathes()) !== false){ - if($_POST){ - $env->set_out("config", $_POST); - if(preg_match("/^[0-9]+$/", $_POST["max_list"])){ - if(!isset($_POST["contact_form"]) || trim($_POST["email"])){ - $CONTINUE = true; - if($CONTINUE && $data->set_config("site_name", $_POST["site_name"])); - else $CONTINUE = false; - if($CONTINUE && $data->set_config("description", $_POST["description"])); - else $CONTINUE = false; - if($CONTINUE && $data->set_config("max_list", $_POST["max_list"])); - else $CONTINUE = false; - if($CONTINUE && $data->set_config("contact_form", isset($_POST["contact_form"]) ? "1" : "0")); - else $CONTINUE = false; - if($CONTINUE && $data->set_config("email", $_POST["email"])); - else $CONTINUE = false; - if($CONTINUE && $data->set_config("captcha", isset($_POST["captcha"]) ? "1" : "0")); - else $CONTINUE = false; - if($CONTINUE && $data->set_config("out", $_POST["out"])); - else $CONTINUE = false; - if($CONTINUE){ - foreach($out_config as $key => $values){ - if($data->set_config("out_".$key, isset($_POST["out_".$key]) ? $_POST["out_".$key] : "") === false){ - $CONTINUE = false; - break; - } - } - } - if($CONTINUE) $env->redirect( - $env->url("admin/config"), - "la configuration a été enregistrée" - ); - else $env->erreur("Impossible d'enregistrer la configuration"); - } - else $env->message("merci de préciser un email pour le formulaire de contact"); - } - else $env->message("la taille maximum des listes doit être un nombre"); - } - } - else $env->erreur("Impossible de lire la liste des templates"); - } - else $env->erreur("Impossible de lire l configuration du templates"); - } - else $env->erreur("Impossible de lire la configuration"); - } - - } - -?> \ No newline at end of file diff --git a/mw/app/mods/admin/index.php b/mw/app/mods/admin/index.php index ae79169..cd94b9d 100644 --- a/mw/app/mods/admin/index.php +++ b/mw/app/mods/admin/index.php @@ -3,7 +3,7 @@ class mw_admin_index extends mw_mod{ function index(&$env){ - $env->run("admin/config"); + $env->run("admin/users"); } } diff --git a/mw/app/mods/admin/users.php b/mw/app/mods/admin/users.php index 302096b..586d8d2 100644 --- a/mw/app/mods/admin/users.php +++ b/mw/app/mods/admin/users.php @@ -6,14 +6,10 @@ function validate(&$env){ $data = $env->data(); - if(($this->roles = $data->roles()) === false) return "impossible de lire la liste des statuts"; + if(($this->roles = $data->roles()) === false) return "impossible de lire la liste des roles"; return true; } - // ------------------------------------------------------------------------------------ - // utilisateurs - // - function index(&$env){ $data = $env->data(); if($this->roles) $env->set_out("roles", $this->roles); @@ -178,146 +174,6 @@ else $env->erreur("Impossible de lire les informations de cet utilisateur"); } - // ------------------------------------------------------------------------------------ - // roles - // - - function set_default_allow(&$env){ - $default_allow = $_GET[$env->param("id")]; - if(!isset($default_allow) || ($default_allow !== "0" && $default_allow !== "1")){ - $env->erreur("parametre default_allow invalide"); - return; - } - $data = $env->data(); - if(!$data->set_config("default_allow", $default_allow)){ - $env->erreur("impossible de mettre a jour la configuration default_allow"); - return; - } - $env->redirect( - $env->url("admin/users/roles"), - "la configuration default_allow a été enregistrée" - ); - } - - function roles(&$env){ - $data = $env->data(); - $roles = $data->roles(); - $id_role = isset($_GET[$env->param("id")]) && $_GET[$env->param("id")] ? $_GET[$env->param("id")] : 0; - $env->set_out("id_role", $id_role); - if(!isset($roles) || $roles === false){ - $env->erreur("impossible de lire la liste des roles"); - return; - } - $env->set_out("roles", $roles); - if(($actions = $data->get_actions($id_role)) === false){ - $env->erreur("impossible de lire la liste des droits d'acces"); - return; - } - $env->set_out("actions", $actions); - - } - - function add_role(&$env){ - $data = $env->data(); - $role = array( - "nom" => "", - "intitule" => "" - ); - if($_POST){ - if(!($role["nom"] = $_POST["nom"])) $env->message("merci de preciser un nom"); - if(!($role["intitule"] = $_POST["intitule"])) $env->message("merci de preciser un intitule"); - if(!$env->messages()){ - if(($id_role = $data->add_role($role["nom"], $role["intitule"])) !== false){ - $env->redirect( - $env->url("admin/users/roles", array("id" => $id_role)), - "le rôle a été enregistré" - ); - } - else $env->erreur("impossible d'enregistrer les informations du role"); - } - } - $env->set_out("role", $role); - } - - function edit_role(&$env){ - $data = $env->data(); - if(!isset($_GET[$env->param("id")]) || !($role = $data->get_role($_GET[$env->param("id")]))){ - $env->erreur("impossible de lire les informations du role"); - return; - } - if($_POST){ - if(!($role["nom"] = $_POST["nom"])) $env->message("merci de preciser un nom"); - if(!($role["intitule"] = $_POST["intitule"])) $env->message("merci de preciser un intitule"); - if(!$env->messages()){ - if($data->set_role($role["id"], $role["nom"], $role["intitule"])){ - $env->redirect( - $env->url("admin/users/roles", array("id" => $role["id"])), - "le rôle a été enregistré" - ); - } - else $env->erreur("impossible d'enregistrer les informations du role"); - } - } - $env->set_out("role", $role); - } - - function save_role(&$env){ - $data = $env->data(); - if(!($role = $data->get_role($_POST["id_role"]))){ - $env->erreur("impossible de lire les informations du role"); - return; - } - if(!$data->clear_role_actions($role["id"])){ - $env->erreur("impossible de supprimer les actions du role"); - return; - } - $action_roles = array(); - $als = array(); - foreach($_POST as $key => $value){ - if(substr($key, 0, 7) == "module_" && ($action = substr($key, 7))) $action_roles[$action] = $role["id"]; - elseif(substr($key, 0, 11) == "controleur_" && ($action = substr($key, 11))) $action_roles[$action] = $role["id"]; - elseif(substr($key, 0, 3) == "al_" && ($al_index = substr($key, 3))) $als[] = $al_index; - } - foreach($als as $al_index){ - $al_prefix = "action_".$al_index."_"; - $al_prefix_length = strlen($al_prefix); - foreach($_POST as $key => $value){ - if(substr($key, 0, $al_prefix_length) == $al_prefix) $action_roles[$value] = $role["id"]; - } - } - foreach($action_roles as $action => $id_role){ - if(!$data->add_role_action($id_role, $action)){ - $env->erreur("impossible d'enregistrer les actions du role"); - return; - } - } - $env->redirect( - $env->url("admin/users/roles", array("id" => $role["id"])), - "les actions du rôle ont été enregistrées" - ); - } - - function del_role(&$env){ - $data = $env->data(); - if(!isset($_GET[$env->param("id")]) || !($role = $data->get_role($_GET[$env->param("id")]))){ - $env->erreur("impossible de lire les informations du role"); - return; - } - if($data->clear_role_actions($role["id"])){ - if($data->clear_role_users($role["id"])){ - if($data->del_role($role["id"])){ - $env->redirect( - $env->url("admin/users/roles"), - "le rôle a été effacé" - ); - } - else $env->erreur("impossible de supprimer le role"); - } - else $env->erreur("impossible de supprimer le role aux utilisateurs"); - } - else $env->erreur("impossible de supprimer les actions du role"); - } - } ?> \ No newline at end of file diff --git a/mw/app/mods/config/index.php b/mw/app/mods/config/index.php new file mode 100644 index 0000000..1e84189 --- /dev/null +++ b/mw/app/mods/config/index.php @@ -0,0 +1,33 @@ +data(); + if(($config = $env->get_CONFIG()) === false){ + $env->erreur("Impossible de lire la configuration"); + return; + } + if($_POST){ + $res = $data->valid_config($_POST); + $config = $res["config"]; + if($res["messages"]) foreach($res["messages"] as $message) $env->message($message); + if(!$env->messages()){ + foreach($config as $key => $value){ + if($data->set_config($key, $value) === false){ + $env->erreur("erreur lors de l'enregistrement de la configuration"); + return; + } + } + $env->redirect( + $env->url("config"), + "la configuration a été enregistrée" + ); + } + } + $env->set_out("config", $config); + } + + } + +?> \ No newline at end of file diff --git a/mw/app/mods/admin/plugins.php b/mw/app/mods/config/plugins.php similarity index 95% rename from mw/app/mods/admin/plugins.php rename to mw/app/mods/config/plugins.php index 0830f2f..d0621d0 100644 --- a/mw/app/mods/admin/plugins.php +++ b/mw/app/mods/config/plugins.php @@ -1,6 +1,6 @@ redirect( - $env->url("admin/plugins/index"), + $env->url("config/plugins/index"), "les priorités des plugins ont été enregistrées" ); } @@ -63,7 +63,7 @@ ); if($env->set_plugin_data($plugin_name, $plugin_data)){ $env->redirect( - $env->url("admin/plugins/index"), + $env->url("config/plugins/index"), "le plugin a été installé" ); } @@ -87,7 +87,7 @@ ); if($env->set_plugin_data($plugin_name, $plugin_data)){ $env->redirect( - $env->url("admin/plugins/index"), + $env->url("config/plugins/index"), "le plugin a été désinstallé" ); } @@ -113,7 +113,7 @@ ); if($env->set_plugin_data($plugin_name, $plugin_data)){ $env->redirect( - $env->url("admin/plugins/index"), + $env->url("config/plugins/index"), "le plugin a été activé" ); } @@ -143,7 +143,7 @@ ); if($env->set_plugin_data($plugin_name, $plugin_data)){ $env->redirect( - $env->url("admin/plugins/index"), + $env->url("config/plugins/index"), "le plugin a été désactivé" ); } diff --git a/mw/app/mods/config/roles.php b/mw/app/mods/config/roles.php new file mode 100644 index 0000000..16774cb --- /dev/null +++ b/mw/app/mods/config/roles.php @@ -0,0 +1,150 @@ +data(); + if(($this->roles = $data->roles()) === false) return "impossible de lire la liste des roles"; + return true; + } + + function index(&$env){ + $data = $env->data(); + $roles = $this->roles; + $id_role = isset($_GET[$env->param("id")]) && $_GET[$env->param("id")] ? $_GET[$env->param("id")] : 0; + if(!isset($roles) || $roles === false){ + $env->erreur("impossible de lire la liste des roles"); + return; + } + if(($actions = $data->get_actions($id_role)) === false){ + $env->erreur("impossible de lire la liste des droits d'acces"); + return; + } + $env->set_out("roles", $roles); + $env->set_out("id_role", $id_role); + $env->set_out("actions", $actions); + } + + function set_default_allow(&$env){ + $default_allow = $_GET[$env->param("id")]; + if(!isset($default_allow) || ($default_allow !== "0" && $default_allow !== "1")){ + $env->erreur("parametre default_allow invalide"); + return; + } + $data = $env->data(); + if(!$data->set_config("default_allow", $default_allow)){ + $env->erreur("impossible de mettre a jour la configuration default_allow"); + return; + } + $env->redirect( + $env->url("config/roles"), + "la configuration default_allow a été enregistrée" + ); + } + + function add_role(&$env){ + $data = $env->data(); + $role = array( + "nom" => "", + "intitule" => "" + ); + if($_POST){ + if(!($role["nom"] = $_POST["nom"])) $env->message("merci de preciser un nom"); + if(!($role["intitule"] = $_POST["intitule"])) $env->message("merci de preciser un intitule"); + if(!$env->messages()){ + if(($id_role = $data->add_role($role["nom"], $role["intitule"])) !== false){ + $env->redirect( + $env->url("config/roles", array("id" => $id_role)), + "le rôle a été enregistré" + ); + } + else $env->erreur("impossible d'enregistrer les informations du role"); + } + } + $env->set_out("role", $role); + } + + function edit_role(&$env){ + $data = $env->data(); + if(!isset($_GET[$env->param("id")]) || !($role = $data->get_role($_GET[$env->param("id")]))){ + $env->erreur("impossible de lire les informations du role"); + return; + } + if($_POST){ + if(!($role["nom"] = $_POST["nom"])) $env->message("merci de preciser un nom"); + if(!($role["intitule"] = $_POST["intitule"])) $env->message("merci de preciser un intitule"); + if(!$env->messages()){ + if($data->set_role($role["id"], $role["nom"], $role["intitule"])){ + $env->redirect( + $env->url("config/roles", array("id" => $role["id"])), + "le rôle a été enregistré" + ); + } + else $env->erreur("impossible d'enregistrer les informations du role"); + } + } + $env->set_out("role", $role); + } + + function save_role(&$env){ + $data = $env->data(); + if(!($role = $data->get_role($_POST["id_role"]))){ + $env->erreur("impossible de lire les informations du role"); + return; + } + if(!$data->clear_role_actions($role["id"])){ + $env->erreur("impossible de supprimer les actions du role"); + return; + } + $action_roles = array(); + $als = array(); + foreach($_POST as $key => $value){ + if(substr($key, 0, 7) == "module_" && ($action = substr($key, 7))) $action_roles[$action] = $role["id"]; + elseif(substr($key, 0, 11) == "controleur_" && ($action = substr($key, 11))) $action_roles[$action] = $role["id"]; + elseif(substr($key, 0, 3) == "al_" && ($al_index = substr($key, 3))) $als[] = $al_index; + } + foreach($als as $al_index){ + $al_prefix = "action_".$al_index."_"; + $al_prefix_length = strlen($al_prefix); + foreach($_POST as $key => $value){ + if(substr($key, 0, $al_prefix_length) == $al_prefix) $action_roles[$value] = $role["id"]; + } + } + foreach($action_roles as $action => $id_role){ + if(!$data->add_role_action($id_role, $action)){ + $env->erreur("impossible d'enregistrer les actions du role"); + return; + } + } + $env->redirect( + $env->url("config/roles", array("id" => $role["id"])), + "les actions du rôle ont été enregistrées" + ); + } + + function del_role(&$env){ + $data = $env->data(); + if(!isset($_GET[$env->param("id")]) || !($role = $data->get_role($_GET[$env->param("id")]))){ + $env->erreur("impossible de lire les informations du role"); + return; + } + if($data->clear_role_actions($role["id"])){ + if($data->clear_role_users($role["id"])){ + if($data->del_role($role["id"])){ + $env->redirect( + $env->url("config/roles"), + "le rôle a été effacé" + ); + } + else $env->erreur("impossible de supprimer le role"); + } + else $env->erreur("impossible de supprimer le role aux utilisateurs"); + } + else $env->erreur("impossible de supprimer les actions du role"); + } + + } + +?> \ No newline at end of file diff --git a/mw/app/mods/config/templates.php b/mw/app/mods/config/templates.php new file mode 100644 index 0000000..47d1d2f --- /dev/null +++ b/mw/app/mods/config/templates.php @@ -0,0 +1,63 @@ +data(); + if(($out_pathes = $env->out_pathes()) === false){ + $env->erreur("Impossible de lire la liste des templates"); + return; + } + if(($out_config = $env->get_out_config()) === false){ + $env->erreur("Impossible de lire la configuration du template"); + return; + } + if($_POST){ + $template = isset($_POST["out"]) ? $_POST["out"] : ""; + if(!$template) $template = $env->config("default_out"); + if(!$env->app_file_exists("out/".$template)){ + $env->erreur("impossible de trouver le template"); + return; + } + if($data->set_config("out", $template) === false){ + $env->erreur("erreur lors de l'enregistrement du template"); + return; + } + $env->redirect( + $env->url("config/templates/index"), + "la configuration a été enregistrée" + ); + } + $env->set_out("out_pathes", $out_pathes); + $env->set_out("out_config", $out_config); + } + + function options(&$env){ + $data = $env->data(); + if(($config = $env->get_CONFIG()) === false){ + $env->erreur("Impossible de lire la configuration"); + return; + } + if(($out_config = $env->get_out_config()) === false){ + $env->erreur("Impossible de lire la configuration du template"); + return; + } + if($_POST){ + foreach($out_config as $key => $values){ + if($data->set_config("out_".$key, isset($_POST["out_".$key]) ? $_POST["out_".$key] : "") === false){ + $env->erreur("erreur lors de l'enregistrement de la configuration du template"); + return; + } + } + $env->redirect( + $env->url("config/templates/options"), + "la configuration a été enregistrée" + ); + } + $env->set_out("config", $config); + $env->set_out("out_config", $out_config); + } + + } + +?> \ No newline at end of file diff --git a/mw/app/mods/users/identification.php b/mw/app/mods/users/identification.php index c7bd19a..db3b68c 100644 --- a/mw/app/mods/users/identification.php +++ b/mw/app/mods/users/identification.php @@ -6,27 +6,62 @@ } function login(&$env){ - $data = $env->data(); - if($data->login(trim($_POST['login']), trim($_POST['pass']))){ - $env->redirect( - isset($_POST["from"]) ? urldecode($_POST["from"]) : $env->url(), - "Vous êtes maintenant identifié en tant que ".$_POST['login'] - ); + if($_POST){ + $data = $env->data(); + if($data->login(trim($_POST['login']), trim($_POST['pass']))){ + $redirect_action = "index"; + $redirect_params = array(); + if(isset($_SESSION["action_after_login"])){ + $redirect_action = $_SESSION["action_after_login"]; + unset($_SESSION["action_after_login"]); + } + if(isset($_SESSION["params_after_login"])){ + if(!($redirect_params = @unserialize($_SESSION["params_after_login"]))) $redirect_params = array(); + unset($_SESSION["params_after_login"]); + } + $env->redirect( + $env->url($redirect_action, $redirect_params), + "Vous êtes maintenant identifié en tant que ".$_POST['login'] + ); + } + else $env->message("Idantifiants incorrects"); } - else $env->message("Identifiants incorrects"); } function logout(&$env){ $data = $env->data(); if($data->logout()){ $env->redirect( - $env->url(), - "Vous n'êtes plus identifié sur le site" + $env->url("users/identification/check_logout"), + "Deconnexion en cours...", + 0 ); } else $env->message("Erreur lors de la deconnection. il se peut que vous soyez encore identifié"); } + function check_logout(&$env){ + if($env->user()){ + $env->erreur("deconnexion impossible. vous êtes toujours identifié sur le site."); + } + else{ + $redirect_action = "index"; + $redirect_params = array(); + if(isset($_SESSION["action_after_logout"])){ + $redirect_action = $_SESSION["action_after_logout"]; + unset($_SESSION["action_after_logout"]); + } + if(isset($_SESSION["params_after_logout"])){ + if(!($redirect_params = @unserialize($_SESSION["params_after_logout"]))) $redirect_params = array(); + unset($_SESSION["params_after_logout"]); + } + $env->redirect( + $env->url($redirect_action, $redirect_params), + "Vous n'êtes plus identifié sur le site" + ); + } + } + } ?> \ No newline at end of file diff --git a/mw/app/out/default/config.php b/mw/app/out/default/config.php new file mode 100644 index 0000000..bc9516b --- /dev/null +++ b/mw/app/out/default/config.php @@ -0,0 +1,36 @@ + + + +out_file("views/head.php"); ?> + + + +
+
+out_file("views/header.php"); ?> +
+
+ +
+
+ +
+out_file("views/config/colonne.php"); ?> +
+ +
+out_file("views/messages.php"); ?> +out_file_exists($layout["content"])) require $this->out_file($layout["content"]); ?> +
+ +
+
+ + + + + diff --git a/mw/app/out/default/css/actions/admin_plugins.css b/mw/app/out/default/css/actions/config_plugins.css similarity index 100% rename from mw/app/out/default/css/actions/admin_plugins.css rename to mw/app/out/default/css/actions/config_plugins.css diff --git a/mw/app/out/default/js/actions/admin.js b/mw/app/out/default/js/actions/config.js similarity index 100% rename from mw/app/out/default/js/actions/admin.js rename to mw/app/out/default/js/actions/config.js diff --git a/mw/app/out/default/layouts/admin.xml b/mw/app/out/default/layouts/admin.xml index a7a9ee9..4b3d43f 100644 --- a/mw/app/out/default/layouts/admin.xml +++ b/mw/app/out/default/layouts/admin.xml @@ -4,17 +4,10 @@ - + - - - - - - - \ No newline at end of file diff --git a/mw/app/out/default/layouts/config.xml b/mw/app/out/default/layouts/config.xml new file mode 100644 index 0000000..f225232 --- /dev/null +++ b/mw/app/out/default/layouts/config.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mw/app/out/default/views/admin/users/add.php b/mw/app/out/default/views/admin/users/add.php index f2fdce2..e832bd7 100644 --- a/mw/app/out/default/views/admin/users/add.php +++ b/mw/app/out/default/views/admin/users/add.php @@ -17,14 +17,14 @@
diff --git a/mw/app/out/default/views/admin/users/edit.php b/mw/app/out/default/views/admin/users/edit.php index abac7f2..6d438b2 100644 --- a/mw/app/out/default/views/admin/users/edit.php +++ b/mw/app/out/default/views/admin/users/edit.php @@ -21,14 +21,14 @@
diff --git a/mw/app/out/default/views/admin/users/list.php b/mw/app/out/default/views/admin/users/index.php similarity index 95% rename from mw/app/out/default/views/admin/users/list.php rename to mw/app/out/default/views/admin/users/index.php index 884cec2..d7ceb35 100644 --- a/mw/app/out/default/views/admin/users/list.php +++ b/mw/app/out/default/views/admin/users/index.php @@ -31,9 +31,9 @@
  • diff --git a/mw/app/out/default/views/config/colonne.php b/mw/app/out/default/views/config/colonne.php new file mode 100644 index 0000000..c82469e --- /dev/null +++ b/mw/app/out/default/views/config/colonne.php @@ -0,0 +1,5 @@ +data(); if(($config_menu = $data->get_link("config")) && $config_menu["subs"]) : ?> + + + + \ No newline at end of file diff --git a/mw/app/out/default/views/admin/config.php b/mw/app/out/default/views/config/index.php similarity index 55% rename from mw/app/out/default/views/admin/config.php rename to mw/app/out/default/views/config/index.php index 7018400..568cb00 100644 --- a/mw/app/out/default/views/admin/config.php +++ b/mw/app/out/default/views/config/index.php @@ -1,6 +1,6 @@

    Configuration

    -
    " method="post"> +" method="post">
    Configuration générale @@ -37,40 +37,6 @@ " /> - -
    - - out["out_pathes"]) : ?> -
    - Affichage du site -
      -
    • - - config("out"); - $FOUND = false; - foreach($this->out["out_pathes"] as $out_path) { if($template == $out_path) { $FOUND = true; break; } } - if(!$FOUND) $template = $this->config("default_out"); - - ?> -
      - -
      -
    • - out["out_config"] as $key => $config) : if($config["type"] == "checkbox") : ?> -
    • - -
      - " id=""out["config"]["out_".$key]) ? $this->out["config"]["out_".$key] : $config["default"]) ? " checked=\"checked\"" : ""; ?> /> - -
      -
    • -
    • @@ -78,6 +44,5 @@
    -
    diff --git a/mw/app/out/default/views/admin/plugins/list.php b/mw/app/out/default/views/config/plugins/index.php similarity index 73% rename from mw/app/out/default/views/admin/plugins/list.php rename to mw/app/out/default/views/config/plugins/index.php index 06fbbc5..b2aedf4 100644 --- a/mw/app/out/default/views/admin/plugins/list.php +++ b/mw/app/out/default/views/config/plugins/index.php @@ -2,7 +2,7 @@ out["plugins"]) : ?> -
    " method="post"> +" method="post">
      data(); foreach($this->out["plugins"] as $plugin_name => $plugin) : ?> @@ -14,18 +14,18 @@ diff --git a/mw/app/out/default/views/admin/users/add_role.php b/mw/app/out/default/views/config/roles/add.php similarity index 76% rename from mw/app/out/default/views/admin/users/add_role.php rename to mw/app/out/default/views/config/roles/add.php index 2122b9e..1290fb3 100644 --- a/mw/app/out/default/views/admin/users/add_role.php +++ b/mw/app/out/default/views/config/roles/add.php @@ -1,10 +1,10 @@

      Ajouter un rôle

      -" method="post"> +" method="post">
      • diff --git a/mw/app/out/default/views/admin/users/edit_role.php b/mw/app/out/default/views/config/roles/edit.php similarity index 68% rename from mw/app/out/default/views/admin/users/edit_role.php rename to mw/app/out/default/views/config/roles/edit.php index 055ef1e..2fa6edc 100644 --- a/mw/app/out/default/views/admin/users/edit_role.php +++ b/mw/app/out/default/views/config/roles/edit.php @@ -1,14 +1,14 @@

        Editer un rôle

        - $this->out["role"]["id"])); ?>" method="post"> + $this->out["role"]["id"])); ?>" method="post">
        • diff --git a/mw/app/out/default/views/admin/users/roles.php b/mw/app/out/default/views/config/roles/index.php similarity index 75% rename from mw/app/out/default/views/admin/users/roles.php rename to mw/app/out/default/views/config/roles/index.php index a65184c..02ac1a1 100644 --- a/mw/app/out/default/views/admin/users/roles.php +++ b/mw/app/out/default/views/config/roles/index.php @@ -4,8 +4,8 @@


          @@ -13,28 +13,27 @@

          Autorisations d'accès pour out["id_role"]) : ?> - $this->out["id_role"])); ?>" + $this->out["id_role"])); ?>" class="admin_link" title="modifier ce role">" /> - $this->out["id_role"])); ?>" + $this->out["id_role"])); ?>" class="admin_link" title="supprimer ce role">" onclick="return confirm('Supprimer ce role ?')"/> - " + " class="admin_link" title="ajouter un role">" />

          out["actions"]) : ?> -" method="post"> +" method="post"> " />
            out["actions"] as $module_name => $module) : ?> diff --git a/mw/app/out/default/views/config/templates/index.php b/mw/app/out/default/views/config/templates/index.php new file mode 100644 index 0000000..b81e5ad --- /dev/null +++ b/mw/app/out/default/views/config/templates/index.php @@ -0,0 +1,49 @@ +

            Template

            + +out["out_pathes"]) : ?> + +" method="post"> + +
            +
              +
            • + + config("out"); + $FOUND = false; + foreach($this->out["out_pathes"] as $out_path) { if($template == $out_path) { $FOUND = true; break; } } + if(!$FOUND) $template = $this->config("default_out"); + + ?> +
              + +
              +
            • + out["out_config"]) : ?> +
            • + +
              + Ce template a des ">options +
              +
            • + +
            • +
              + +
              +
            • +
            +
            + + + + + +

            Aucun template

            + + diff --git a/mw/app/out/default/views/config/templates/options.php b/mw/app/out/default/views/config/templates/options.php new file mode 100644 index 0000000..3c7f19a --- /dev/null +++ b/mw/app/out/default/views/config/templates/options.php @@ -0,0 +1,32 @@ +

            Options du template

            + +out["out_config"]) : ?> + +
            " method="post"> + +
            +
              + out["out_config"] as $key => $config) : if($config["type"] == "checkbox") : ?> +
            • + +
              + " id=""out["config"]["out_".$key]) ? $this->out["config"]["out_".$key] : $config["default"]) ? " checked=\"checked\"" : ""; ?> /> + +
              +
            • + +
            • +
              + +
              +
            • +
            +
            + +
            + + + +

            Aucune option pour ce template

            + + diff --git a/mw/app/out/default/views/footer.php b/mw/app/out/default/views/footer.php index 54725cf..a5f368d 100644 --- a/mw/app/out/default/views/footer.php +++ b/mw/app/out/default/views/footer.php @@ -12,6 +12,9 @@ action_allowed("admin")) : ?>
          • ">admin
          • +action_allowed("config")) : ?> +
          • ">config
          • +
          • ">deconnexion
          • mtweb
          • diff --git a/mw/app/out/default/views/forms/contact/index.php b/mw/app/out/default/views/forms/contact/index.php index 147c044..659a7fb 100644 --- a/mw/app/out/default/views/forms/contact/index.php +++ b/mw/app/out/default/views/forms/contact/index.php @@ -1,7 +1,9 @@
            " method="post">
            Contact + config("captcha")) : ?> +
            • diff --git a/mw/env/modules/mw_env_urls.php b/mw/env/modules/mw_env_urls.php index d7194f8..7bf6153 100644 --- a/mw/env/modules/mw_env_urls.php +++ b/mw/env/modules/mw_env_urls.php @@ -22,7 +22,8 @@ return false; } - function url($action = "", $_params = array(), $script_name = "index.php"){ + function url($action = "", $_params = array(), $script_name = null){ + $script_name = isset($script_name) ? $script_name : ($this->config("script_name") ? $this->config("script_name") : "index.php"); if($action) $_params["e"] = $action; $get_params = ""; if(isset($this->additional_get_params)) foreach($this->additional_get_params as $key => $value) $get_params .= ($get_params ? "&" : "?").$key."=".$value; @@ -40,6 +41,9 @@ "wait" => $wait ) ); + if(!$wait && !headers_sent()){ + header("Location: ".str_replace("&", "&", $url)); + } } } -- 2.1.4