3 class mw_pages extends mw_plugin
10 function description($env)
11 { return "Pour ajouter des pages, avec un éditeur dans l'administration du site";
15 { $env->set_link("plugins/admin/mw_pages", $env->url("pages/admin"), "éditer les pages");
18 ( ( $pages = $data->pages
22 "order_by" => "position",
28 { foreach($pages["list"] as $id_page => $page)
30 ( "menu_top/mw_page_".$id_page,
31 $env->url("pages/view/page", array("id" => $id_page)),
41 { $plugins_pages_start_id = $env->config("plugins_pages_start_id");
42 if($plugins_pages_start_id)
43 { $data = $env->data();
45 ( $data->set_config("start_action", "pages/view/page")
46 && $data->set_config("start_action_params", @serialize(array("id" => $plugins_pages_start_id)))
55 function disable($env)
56 { $start_action = $env->config("start_action");
57 if($start_action == "pages/view/page")
58 { $data = $env->data();
60 ( $data->set_config("start_action", "")
61 && $data->set_config("start_action_params", "")
70 // ---------------------------------------------------------------------------------
74 function install($env)
75 { if($env->bdd("sgbd") == "xml") return $this->install_xml($env);
76 if($env->bdd("sgbd") == "sqlite") return $this->install_sqlite($env);
77 if($env->bdd("sgbd") == "mysql") return $this->install_mysql($env);
80 function install_xml($env)
81 { $data = $env->data();
82 $sgbd = $data->sgbd();
83 $EXISTS = $sgbd->data_exists("pages");
85 { return "impossible de savoir si la table #--pages existe";
88 { return "la table #--pages existe deja";
90 if(!$sgbd->create_data("pages"))
91 { return "imposible de creer la table #--pages";
93 if(!$sgbd->add_data("action_status", array("action" => "pages/admin", "id_status" => "1")))
94 { $sgbd->remove_data("pages");
95 return "impossible d'ajouter un statut pour l'action pages/admin";
100 function install_sqlite($env)
101 { $data = $env->data();
102 $sgbd = $data->sgbd();
103 $EXISTS = $sgbd->table_exists("#--pages");
105 { return "impossible de savoir si la table #--pages existe";
108 { return "la table #--pages existe deja";
111 "CREATE TABLE #--pages"
112 ."( id INTEGER NOT NULL PRIMARY KEY"
113 .", id_parent INTEGER NULL"
114 .", title VARCHAR NULL"
115 .", content TEXT NULL"
116 .", date_creation TEXT NOT NULL"
117 .", user_creation INTEGER NOT NULL"
118 .", date_last_update TEXT NOT NULL"
119 .", user_last_update INTEGER NOT NULL"
120 .", enabled INTEGER NOT NULL DEFAULT 1"
121 .", position INTEGER NOT NULL DEFAULT 0"
123 if(!$sgbd->query($sql))
124 { return "imposible de creer la table #--pages";
126 if(!$sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)"))
127 { $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
128 return "impossible d'ajouter un statut pour l'action pages/admin";
133 function install_mysql($env)
134 { $data = $env->data();
135 $sgbd = $data->sgbd();
136 $EXISTS = $sgbd->table_exists("#--pages");
138 { return "impossible de savoir si la table #--pages existe";
141 { return "la table #--pages existe deja";
144 "CREATE TABLE #--pages"
145 ."( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
146 .", id_parent INT(11) NULL"
147 .", title VARCHAR(255) NULL"
148 .", content TEXT NULL"
149 .", date_creation DATETIME NOT NULL"
150 .", user_creation INT(11) NOT NULL"
151 .", date_last_update DATETIME NOT NULL"
152 .", user_last_update INT(11) NOT NULL"
153 .", enabled TINYINT NOT NULL DEFAULT '1'"
154 .", position INT(11) NOT NULL DEFAULT '0'"
155 .") DEFAULT CHARSET=utf8";
156 if(!$sgbd->query($sql))
157 { return "imposible de creer la table #--pages";
159 if(!$sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)"))
160 { $sgbd->query("DROP TABLE #--pages");
161 return "impossible d'ajouter un statut pour l'action pages/admin";
166 // ---------------------------------------------------------------------------------
170 function uninstall($env)
171 { if($env->bdd("sgbd") == "xml") return $this->uninstall_xml($env);
172 if($env->bdd("sgbd") == "sqlite") return $this->uninstall_sqlite($env);
173 if($env->bdd("sgbd") == "mysql") return $this->uninstall_mysql($env);
176 function uninstall_xml($env)
177 { $data = $env->data();
178 $sgbd = $data->sgbd();
179 if(!$this->disable($env)) return "impossible de desactiver le plugin";
180 $data->del_config("plugins_pages_start_id");
181 $EXISTS = $sgbd->data_exists("pages");
183 { return "impossible de savoir si la table #--pages existe";
186 { // return "la table #--pages n'existe pas";
188 elseif(!$sgbd->remove_data("pages"))
189 { return "imposible de supprimer la table #--pages";
192 if($rst = $sgbd->open_data("action_status"))
193 { while($v_rst = $sgbd->fetch_data($rst))
195 { if(isset($v_rst["action"]) && isset($v_rst["id"]) && $v_rst["action"] == "pages/admin")
196 { $ids[] = $v_rst["id"];
201 $sgbd->close_data($rst);
204 { foreach($ids as $id)
205 { $sgbd->del_data("action_status", $id);
211 function uninstall_sqlite($env)
212 { $data = $env->data();
213 $sgbd = $data->sgbd();
214 if(!$this->disable($env)) return "impossible de desactiver le plugin";
215 $data->del_config("plugins_pages_start_id");
216 $EXISTS = $sgbd->table_exists("#--pages");
218 { return "impossible de savoir si la table #--pages existe";
221 { // return "la table #--pages n'existe pas";
223 elseif(!$sgbd->query("DROP TABLE \"main\".\"#--pages\""))
224 { return "imposible de supprimer la table #--pages";
226 $sgbd->query("DELETE FROM #--action_status WHERE action='pages/admin'");
230 function uninstall_mysql($env)
231 { $data = $env->data();
232 $sgbd = $data->sgbd();
233 if(!$this->disable($env)) return "impossible de desactiver le plugin";
234 $data->del_config("plugins_pages_start_id");
235 $EXISTS = $sgbd->table_exists("#--pages");
237 { return "impossible de savoir si la table #--pages existe";
240 { // return "la table #--pages n'existe pas";
242 elseif(!$sgbd->query("DROP TABLE #--pages"))
243 { return "imposible de supprimer la table #--pages";
245 $sgbd->query("DELETE FROM #--action_status WHERE action='pages/admin'");