3 class mw_env_run extends mw_env
8 { $data = $this->data();
9 return $data->get_session_user();
12 function set_etat($etat, $valid_status = true)
13 { if(($this->etat = $this->valid_etat($etat)) !== false)
14 { if(!$valid_status || $this->status_ok($this->etat, false))
17 else $this->erreur("Vous n'avez pas le statut requis pour effectuer cette action");
19 else $this->erreur("etat invalide");
23 function valid_etat($etat)
26 $_etat["controller"] = "";
27 $_etat["action"] = "";
29 { $_etat["mod"] = isset($etat["mod"]) ? $etat["mod"] : "";
30 $_etat["controller"] = isset($etat["controller"]) ? $etat["controller"] : "";
31 $_etat["action"] = isset($etat["action"]) ? $etat["action"] : "";
34 { $etat = explode("/", $etat);
35 foreach($etat as $etat_item)
37 { if(!$_etat["mod"]) $_etat["mod"] = $etat_item;
39 { if(!$_etat["controller"]) $_etat["controller"] = $etat_item;
41 { if(!$_etat["action"]) $_etat["action"] = $etat_item;
49 { $_etat["mod"] = "index";
50 $_etat["controller"] = "index";
51 $_etat["action"] = "index";
54 { if(!$_etat["controller"])
55 { $_etat["controller"] = "index";
56 $_etat["action"] = "index";
59 { if(!$_etat["action"]) $_etat["action"] = "index";
65 && isset($_etat["mod"]) && preg_match("/^[a-zA-Z0-9_]+$/", $_etat["mod"])
66 && isset($_etat["controller"]) && preg_match("/^[a-zA-Z0-9_]+$/", $_etat["controller"])
67 && isset($_etat["action"]) && preg_match("/^[a-zA-Z0-9_]+$/", $_etat["action"])
72 function etat_is_valid()
73 { return $this->valid_etat($this->etat);
76 function status_ok($etat, $CHECK_FORMAT = true)
77 { $OK = $this->config("default_allow");
78 $data = $this->data();
79 if($CHECK_FORMAT) $etat = $this->valid_etat($etat);
81 { if(($user_status = $data->get_user_status()) !== false)
83 ( ( $action_status = $data->get_action_status
90 { $action = $etat["mod"]."/".$etat["controller"]."/".$etat["action"];
91 if(isset($action_status[$action]))
92 { $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]);
95 { $action = $etat["mod"]."/".$etat["controller"];
96 if(isset($action_status[$action]))
97 { $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]);
100 { $action = $etat["mod"];
101 if(isset($action_status[$action]))
102 { $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]);
107 else $this->erreur("Impossible de lire les status des actions en base");
109 else $this->erreur("Impossible de lire le statut de l'utilisateur courant");
111 else $this->erreur("etat invalide");
115 function run($etat, $valid_status = true, $params = array(), $method = "GET")
116 { if($this->set_etat($etat, $valid_status))
117 { $controller_file = "mods/".$this->etat("mod")."/".$this->etat("controller").".php";
118 if($this->app_file_exists($controller_file = "mods/".$this->etat("mod")."/".$this->etat("controller").".php", "DESC"))
119 { if(!class_exists("mw_mod")) require $this->app_file("mods/mw_mod.php");
120 if(!class_exists($controller_class = "mw_".$this->etat("mod")."_".$this->etat("controller")))
121 { require $this->app_file($controller_file, "DESC");
123 if(class_exists($controller_class))
124 { $controller = new $controller_class();
125 $action_method = $this->etat("action");
126 if(method_exists($controller, $action_method))
127 { foreach($params as $key => $value)
128 { switch(strtolower($method))
129 { case "get": $_GET[$this->param($key)] = $value; break;
130 case "post": $_POST[$key] = $value; break;
134 if(($controller_validate = $controller->validate($this)) === true)
135 { if(($controller_prepare_inputs = $controller->prepare_inputs($this)) === true)
136 { $controller->$action_method($this);
138 else $this->erreur($controller_prepare_inputs);
140 else $this->erreur($controller_validate);
142 else $this->erreur("Impossible de trouver l'action ".$this->etat("action"));
144 else $this->erreur("Impossible d'instancier le controleur ".$this->etat("controller"));
146 else $this->erreur("Impossible de trouver le controleur ".$this->etat("controller")." pour le module ".$this->etat("mod"));
148 else $this->erreur("Impossible d'effectuer cette action");
151 function etat($name) { return $this->etat[$name]; }
153 function check_stop()
154 { return $this->etat("mod") == "reponses";
157 function get_mod($mod_name)
158 { if($etat = $this->valid_etat($mod_name))
159 { if($this->app_file_exists($controller_file = "mods/".$etat["mod"]."/".$etat["controller"].".php"))
160 { if(!class_exists("mw_mod")) require $this->app_file("mods/mw_mod.php");
161 if(!class_exists($controller_class = "mw_".$etat["mod"]."_".$etat["controller"]))
162 { require $this->app_file($controller_file);
164 if(class_exists($controller_class))
165 { return new $controller_class();