9bebcf969c5e90c855e3d4149ff69d6bf76fdc1c
[mtweb] / mw / app / data / modules / xml / mw_data_xml_install.php
1 <?php
2
3   class mw_data_xml_install extends mw_data{
4
5     function install_xml($params){
6       $env = $this->env();
7       $data = $env->data();
8       $sgbd = $data->sgbd();
9       $host = isset($params["host"]) ? $params["host"] : "";
10       $base = isset($params["base"]) ? $params["base"] : "";
11       $user = isset($params["user"]) ? $params["user"] : "";
12       $password = isset($params["password"]) ? $params["password"] : "";
13       if(!$host || !$base) return "paramètres manquant pour la base XML";
14       $host .= substr($host, -1) == "/" ? "" : "/";
15       if(!is_dir($host)){
16         $parent_dir = dirname($host);
17         if(is_dir($parent_dir)) @mkdir($host);
18         if(!is_dir($host)) return "impossible de créer le répertoire des données XML";
19       }
20       $base_dir = $host.$base;
21       if(!is_dir($base_dir)) @mkdir($base_dir);
22       if(!is_dir($base_dir)) return "impossible de créer le dossier de la base XML";
23       $base .= substr($base, -1) == "/" ? "" : "/";
24       if(
25             !$sgbd->connect(
26               $host,
27               $base,
28               $user,
29               $password
30             )
31         ||  !$sgbd->select_db($base)
32       ){
33         return "impossible de se connecter à la base XML";
34       }
35       $ERROR = false;
36       $EXISTS = false;
37       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("actions_roles");
38       $ERROR = !isset($EXISTS);
39       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("config");
40       $ERROR = !isset($EXISTS);
41       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("roles");
42       $ERROR = !isset($EXISTS);
43       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users");
44       $ERROR = !isset($EXISTS);
45       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users_roles");
46       $ERROR = !isset($EXISTS);
47       if($ERROR){
48         return "impossible de savoir si les tables existent deja";
49       }
50       if($EXISTS){
51         return "des tables a installer existent deja en base. installation annulee";
52       }
53       if(!$ERROR) if(!$sgbd->create_data("actions_roles")) $ERROR = true;
54       if(!$ERROR) if(!$sgbd->create_data("config")) $ERROR = true;
55       if(!$ERROR) if(!$sgbd->create_data("roles")) $ERROR = true;
56       if(!$ERROR) if(!$sgbd->create_data("users")) $ERROR = true;
57       if(!$ERROR) if(!$sgbd->create_data("users_roles")) $ERROR = true;
58       if($ERROR){
59         return "imposible de creer les tables en base";
60       }
61
62       // ------------------------------------ actions_roles
63       if(!$ERROR) if(
64         !$sgbd->add_data(
65           "actions_roles",
66           array(
67             "action" => "admin",
68             "id_role" => 1
69           )
70         )
71       ) $ERROR = true;
72       if(!$ERROR) if(
73         !$sgbd->add_data(
74           "actions_roles",
75           array(
76             "action" => "users",
77             "id_role" => 2
78           )
79         )
80       ) $ERROR = true;
81       if(!$ERROR) if(
82         !$sgbd->add_data(
83           "actions_roles",
84           array(
85             "action" => "users/identification",
86             "id_role" => 0
87           )
88         )
89       ) $ERROR = true;
90       if(!$ERROR) if(
91         !$sgbd->add_data(
92           "actions_roles",
93           array(
94             "action" => "config",
95             "id_role" => 3
96           )
97         )
98       ) $ERROR = true;
99
100       // ------------------------------------ config
101       if(!$ERROR) if(
102         !$sgbd->add_data(
103           "config",
104           array(
105             "key" => "site_name",
106             "value" => "mtweb"
107           )
108         )
109       ) $ERROR = true;
110       if(!$ERROR) if(
111         !$sgbd->add_data(
112           "config",
113           array(
114             "key" => "max_list",
115             "value" => "10"
116           )
117         )
118       ) $ERROR = true;
119       if(!$ERROR) if(
120         !$sgbd->add_data(
121           "config",
122           array(
123             "key" => "description",
124             "value" => ""
125           )
126         )
127       ) $ERROR = true;
128       if(!$ERROR) if(
129         !$sgbd->add_data(
130           "config",
131           array(
132             "key" => "out",
133             "value" => "default"
134           )
135         )
136       ) $ERROR = true;
137       if(!$ERROR) if(
138         !$sgbd->add_data(
139           "config",
140           array(
141             "key" => "start_action",
142             "value" => ""
143           )
144         )
145       ) $ERROR = true;
146       if(!$ERROR) if(
147         !$sgbd->add_data(
148           "config",
149           array(
150             "key" => "contact_form",
151             "value" => "0"
152           )
153         )
154       ) $ERROR = true;
155       if(!$ERROR) if(
156         !$sgbd->add_data(
157           "config",
158           array(
159             "key" => "email",
160             "value" => ""
161           )
162         )
163       ) $ERROR = true;
164       if(!$ERROR) if(
165         !$sgbd->add_data(
166           "config",
167           array(
168             "key" => "captcha",
169             "value" => "0"
170           )
171         )
172       ) $ERROR = true;
173       if(!$ERROR) if(
174         !$sgbd->add_data(
175           "config",
176           array(
177             "key" => "start_action_params",
178             "value" => ""
179           )
180         )
181       ) $ERROR = true;
182       if(!$ERROR) if(
183         !$sgbd->add_data(
184           "config",
185           array(
186             "key" => "out_navig_menu_top",
187             "value" => "on"
188           )
189         )
190       ) $ERROR = true;
191       if(!$ERROR) if(
192         !$sgbd->add_data(
193           "config",
194           array(
195             "key" => "out_colonne",
196             "value" => "on"
197           )
198         )
199       ) $ERROR = true;
200       if(!$ERROR) if(
201         !$sgbd->add_data(
202           "config",
203           array(
204             "key" => "default_allow",
205             "value" => "1"
206           )
207         )
208       ) $ERROR = true;
209
210       // ------------------------------------ roles
211       if(!$ERROR){
212         $res = $sgbd->add_data(
213           "roles",
214           array(
215             "nom" => "guest",
216             "intitule" => "invité"
217           ),
218           0
219         );
220         if(!isset($res)) $ERROR = true;
221       } 
222       if(!$ERROR) if(
223         !$sgbd->add_data(
224           "roles",
225           array(
226             "nom" => "admin",
227             "intitule" => "administrateur"
228           )
229         )
230       ) $ERROR = true;
231       if(!$ERROR) if(
232         !$sgbd->add_data(
233           "roles",
234           array(
235             "nom" => "membre",
236             "intitule" => "membre"
237           )
238         )
239       ) $ERROR = true;
240       if(!$ERROR) if(
241         !$sgbd->add_data(
242           "roles",
243           array(
244             "nom" => "webmaster",
245             "intitule" => "webmaster"
246           )
247         )
248       ) $ERROR = true;
249
250       if($ERROR){
251         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
252       }
253
254       return true;
255     }
256
257   }
258
259 ?>