marche avec MySql, SQLite ou XML
[mw_sourceml] / mw_sourceml.php
1 <?php
2
3   class mw_sourceml extends mw_plugin{
4
5     function title(){
6       return "SourceML";
7     }
8
9     function description(){
10       return "Publication de sources musicales";
11     }
12
13     function init($env){
14
15       $env->set_link("admin/sourceml", $env->url("admin/sourceml"), "SourceML", 50);
16       $env->set_link("admin/sourceml/licences", $env->url("admin/licences"), "Licences", 10);
17       $env->set_link("admin/sourceml/cache", $env->url("admin/cache"), "Cache", 20);
18       $env->set_link("admin/sourceml/maintenance", $env->url("admin/maintenance"), "Maintenance", 30);
19
20       $env->set_link("users/authors", $env->url("users/groupes"), "Groupes", 30);
21       $env->set_link("users/albums", $env->url("users/albums"), "Albums", 31);
22       $env->set_link("users/morceaux", $env->url("users/morceaux"), "Morceaux", 32);
23       $env->set_link("users/pistes", $env->url("users/pistes"), "Sources", 33);
24
25       $invitations_title = "Invitations";
26       if($nb_invitations = $this->nb_invitations($env)) $invitations_title .= " (".$nb_invitations.")";
27       $env->set_link("users/sources_invitations", $env->url("users/sources_invitations"), $invitations_title, 34);
28
29       $env->set_link("menu_top/groupes", $env->url("sources/groupe"), "Groupes", 10);
30       $env->set_link("menu_top/albums", $env->url("sources/album"), "Albums", 11);
31       $env->set_link("menu_top/morceaux", $env->url("sources/morceau"), "Morceaux", 12);
32       $env->set_link("menu_top/pistes", $env->url("sources/piste"), "Sources", 13);
33
34       return true;
35     }
36
37     function nb_invitations($env){
38       if($user = $env->user()){
39         $data = $env->data();
40         if($groupes = $data->groupes($user["id"])){
41           if($invitations = $data->sources_invitations($groupes["list"], $user["id"])){
42             return $invitations["total"];
43           }
44         }
45       }
46       return 0;
47     }
48
49     function enable($env){
50       return true;
51     }
52
53     function disable($env){
54       return true;
55     }
56
57     // ---------------------------------------------------------------------------------
58     //                                                                           install
59     //
60
61     function install($env){
62       if(
63             $env->bdd("sgbd") == "mysql"
64         ||  $env->bdd("sgbd") == "pdo_mysql"
65       ) return $this->install_mysql($env);
66       elseif(
67             $env->bdd("sgbd") == "pdo_sqlite"
68       ) return $this->install_sqlite($env);
69       elseif(
70             $env->bdd("sgbd") == "xml"
71       ) return $this->install_xml($env);
72       return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
73     }
74
75     function install_mysql($env){
76       $data = $env->data();
77       $sgbd = $data->sgbd();
78       try{
79         $EXISTS =
80             $sgbd->table_exists("#--sml_authors")
81         ||  $sgbd->table_exists("#--sml_classes")
82         ||  $sgbd->table_exists("#--sml_licences")
83         ||  $sgbd->table_exists("#--sml_sources")
84         ||  $sgbd->table_exists("#--sml_sources_access")
85         ||  $sgbd->table_exists("#--sml_sources_authors")
86         ||  $sgbd->table_exists("#--sml_sources_infos")
87         ||  $sgbd->table_exists("#--sml_source_cache")
88         ||  $sgbd->table_exists("#--sml_source_compositions")
89         ||  $sgbd->table_exists("#--sml_source_derivations")
90         ||  $sgbd->table_exists("#--sml_source_documents")
91         ||  $sgbd->table_exists("#--sml_sources_invitations");
92       }
93       catch(Exception $e){
94         return "impossible de savoir si les tables existent deja";
95       }
96       if($EXISTS){
97         return "des tables existent deja en base. installation annulee";
98       }
99       try{
100         $sql =
101          "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"";
102         $sgbd->query($sql);
103
104         $sql =
105          "CREATE TABLE `#--sml_authors`("
106         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
107         ."  `id_user` int(11) NOT NULL,"
108         ."  `nom` varchar(255) NOT NULL,"
109         ."  `image` varchar(255) DEFAULT NULL,"
110         ."  `description` text,"
111         ."  `email` varchar(255) NOT NULL,"
112         ."  `contact_form` tinyint(4) NOT NULL,"
113         ."  `captcha` tinyint(4) NOT NULL,"
114         ."  PRIMARY KEY (`id`),"
115         ."  KEY `id_user` (`id_user`)"
116         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
117         $sgbd->query($sql);
118
119         $sql =
120          "CREATE TABLE `#--sml_classes`("
121         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
122         ."  `nom` varchar(255) NOT NULL,"
123         ."  PRIMARY KEY (`id`)"
124         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
125         $sgbd->query($sql);
126
127         $sql =
128          "CREATE TABLE `#--sml_licences`("
129         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
130         ."  `nom` varchar(255) NOT NULL,"
131         ."  `url` varchar(255) NOT NULL,"
132         ."  PRIMARY KEY (`id`)"
133         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
134         $sgbd->query($sql);
135
136         $sql =
137          "CREATE TABLE `#--sml_sources`("
138         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
139         ."  `id_class` int(11) NOT NULL,"
140         ."  `reference` varchar(255) DEFAULT NULL,"
141         ."  `titre` varchar(255) DEFAULT NULL,"
142         ."  `licence` int(11) DEFAULT NULL,"
143         ."  `date_creation` date DEFAULT NULL,"
144         ."  `date_inscription` datetime NOT NULL,"
145         ."  PRIMARY KEY (`id`),"
146         ."  KEY `id_class` (`id_class`),"
147         ."  KEY `licence` (`licence`)"
148         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
149         $sgbd->query($sql);
150
151         $sql =
152          "CREATE TABLE `#--sml_sources_access`("
153         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
154         ."  `nom` varchar(255) NOT NULL,"
155         ."  `intitule` varchar(255) NOT NULL,"
156         ."  PRIMARY KEY (`id`)"
157         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
158         $sgbd->query($sql);
159
160         $sql =
161          "CREATE TABLE `#--sml_sources_authors`("
162         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
163         ."  `id_source` int(11) NOT NULL,"
164         ."  `id_author` int(11) NOT NULL,"
165         ."  `id_sources_access` int(11) NOT NULL,"
166         ."  PRIMARY KEY (`id`),"
167         ."  KEY `id_object` (`id_source`),"
168         ."  KEY `id_author` (`id_author`),"
169         ."  KEY `id_sources_access` (`id_sources_access`)"
170         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
171         $sgbd->query($sql);
172
173         $sql =
174          "CREATE TABLE `#--sml_sources_infos`("
175         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
176         ."  `id_source` int(11) NOT NULL,"
177         ."  `key` varchar(255) NOT NULL,"
178         ."  `value` text NOT NULL,"
179         ."  PRIMARY KEY (`id`),"
180         ."  KEY `id_source` (`id_source`)"
181         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
182         $sgbd->query($sql);
183
184         $sql =
185          "CREATE TABLE `#--sml_source_cache`("
186         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
187         ."  `url` varchar(255) NOT NULL,"
188         ."  `id_source` int(11) NOT NULL,"
189         ."  `last_update` datetime NOT NULL,"
190         ."  PRIMARY KEY (`id`)"
191         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
192         $sgbd->query($sql);
193
194         $sql =
195          "CREATE TABLE `#--sml_source_compositions`("
196         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
197         ."  `id_source` int(11) NOT NULL,"
198         ."  `id_composition` int(11) NOT NULL,"
199         ."  PRIMARY KEY (`id`),"
200         ."  KEY `id_source` (`id_source`),"
201         ."  KEY `id_composition` (`id_composition`)"
202         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
203         $sgbd->query($sql);
204
205         $sql =
206          "CREATE TABLE `#--sml_source_derivations`("
207         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
208         ."  `id_source` int(11) NOT NULL,"
209         ."  `derivation` varchar(255) NOT NULL,"
210         ."  PRIMARY KEY (`id`),"
211         ."  KEY `derivation` (`derivation`)"
212         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
213         $sgbd->query($sql);
214
215         $sql =
216          "CREATE TABLE `#--sml_source_documents`("
217         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
218         ."  `id_source` int(11) NOT NULL,"
219         ."  `nom` varchar(255) NOT NULL,"
220         ."  `url` varchar(255) NOT NULL,"
221         ."  PRIMARY KEY (`id`),"
222         ."  KEY `id_source` (`id_source`)"
223         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
224         $sgbd->query($sql);
225
226         $sql =
227          "CREATE TABLE `#--sml_sources_invitations`("
228         ."  `id` INT(11) NOT NULL AUTO_INCREMENT,"
229         ."  `id_user` INT(11) NOT NULL,"
230         ."  `id_source` INT(11) NOT NULL,"
231         ."  `id_author` INT(11) NOT NULL,"
232         ."  `id_sources_access` INT(11) NOT NULL,"
233         ."  `date_invitation` datetime NOT NULL,"
234         ."  PRIMARY KEY (`id`)"
235         .")";
236         $sgbd->query($sql);
237
238       }
239       catch(Exception $e){
240         return "imposible de creer les tables en base";
241       }
242       try{
243         $sql =
244          "INSERT INTO `#--sml_licences` (`id`, `nom`, `url`) VALUES"
245         ."(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr'),"
246         ."(2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/'),"
247         ."(3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/'),"
248         ."(4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/'),"
249         ."(5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/'),"
250         ."(6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/'),"
251         ."(7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/'),"
252         ."(8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/'),"
253         ."(9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm'),"
254         ."(10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html'),"
255         ."(11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
256         $sgbd->query($sql);
257
258         $sql =
259          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES"
260         ."(1, 'album'),"
261         ."(2, 'morceau'),"
262         ."(3, 'piste')";
263         $sgbd->query($sql);
264
265         $sql =
266          "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES"\r
267         ."(1, 'admin', 'administrateur'),"\r
268         ."(2, 'editeur', 'éditeur'),"\r
269         ."(3, 'contributeur', 'contributeur')";
270         $sgbd->query($sql);
271
272       }
273       catch(Exception $e){
274         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
275       }
276       return true;
277     }
278
279     function install_sqlite($env){
280       $data = $env->data();
281       $sgbd = $data->sgbd();
282       try{
283         $EXISTS =
284             $sgbd->table_exists("#--sml_authors")
285         ||  $sgbd->table_exists("#--sml_classes")
286         ||  $sgbd->table_exists("#--sml_licences")
287         ||  $sgbd->table_exists("#--sml_sources")
288         ||  $sgbd->table_exists("#--sml_sources_access")
289         ||  $sgbd->table_exists("#--sml_sources_authors")
290         ||  $sgbd->table_exists("#--sml_sources_infos")
291         ||  $sgbd->table_exists("#--sml_source_cache")
292         ||  $sgbd->table_exists("#--sml_source_compositions")
293         ||  $sgbd->table_exists("#--sml_source_derivations")
294         ||  $sgbd->table_exists("#--sml_source_documents")
295         ||  $sgbd->table_exists("#--sml_sources_invitations");
296       }
297       catch(Exception $e){
298         return "impossible de savoir si les tables existent deja";
299       }
300       if($EXISTS){
301         return "des tables existent deja en base. installation annulee";
302       }
303       try{
304
305         $sql =
306          "CREATE TABLE #--sml_authors("
307         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
308         ."  `id_user` INTEGER NOT NULL,"
309         ."  `nom` TEXT NOT NULL,"
310         ."  `image` TEXT DEFAULT NULL,"
311         ."  `description` TEXT,"
312         ."  `email` TEXT NOT NULL,"
313         ."  `contact_form` INTEGER NOT NULL,"
314         ."  `captcha` INTEGER NOT NULL"
315         .")";
316         $sgbd->query($sql);
317
318         $sql =
319          "CREATE TABLE #--sml_classes("
320         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
321         ."  `nom` TEXT NOT NULL"
322         .")";
323         $sgbd->query($sql);
324
325         $sql =
326          "CREATE TABLE #--sml_licences("
327         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
328         ."  `nom` TEXT NOT NULL,"
329         ."  `url` TEXT NOT NULL"
330         .")";
331         $sgbd->query($sql);
332
333         $sql =
334          "CREATE TABLE #--sml_sources("
335         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
336         ."  `id_class` INTEGER NOT NULL,"
337         ."  `reference` TEXT DEFAULT NULL,"
338         ."  `titre` TEXT DEFAULT NULL,"
339         ."  `licence` INTEGER DEFAULT NULL,"
340         ."  `date_creation` TEXT DEFAULT NULL,"
341         ."  `date_inscription` TEXT NOT NULL"
342         .")";
343         $sgbd->query($sql);
344
345         $sql =
346          "CREATE TABLE #--sml_sources_access("
347         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
348         ."  `nom` TEXT NOT NULL,"
349         ."  `intitule` TEXT NOT NULL"
350         .")";
351         $sgbd->query($sql);
352
353         $sql =
354          "CREATE TABLE #--sml_sources_authors("
355         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
356         ."  `id_source` INTEGER NOT NULL,"
357         ."  `id_author` INTEGER NOT NULL,"
358         ."  `id_sources_access` INTEGER NOT NULL"
359         .")";
360         $sgbd->query($sql);
361
362         $sql =
363          "CREATE TABLE #--sml_sources_infos("
364         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
365         ."  `id_source` INTEGER NOT NULL,"
366         ."  `key` TEXT NOT NULL,"
367         ."  `value` TEXT NOT NULL"
368         .")";
369         $sgbd->query($sql);
370
371         $sql =
372          "CREATE TABLE #--sml_source_cache("
373         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
374         ."  `url` TEXT NOT NULL,"
375         ."  `id_source` INTEGER NOT NULL,"
376         ."  `last_update` TEXT NOT NULL"
377         .")";
378         $sgbd->query($sql);
379
380         $sql =
381          "CREATE TABLE #--sml_source_compositions("
382         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
383         ."  `id_source` INTEGER NOT NULL,"
384         ."  `id_composition` INTEGER NOT NULL"
385         .")";
386         $sgbd->query($sql);
387
388         $sql =
389          "CREATE TABLE #--sml_source_derivations("
390         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
391         ."  `id_source` INTEGER NOT NULL,"
392         ."  `derivation` TEXT NOT NULL"
393         .")";
394         $sgbd->query($sql);
395
396         $sql =
397          "CREATE TABLE #--sml_source_documents("
398         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
399         ."  `id_source` INTEGER NOT NULL,"
400         ."  `nom` TEXT NOT NULL,"
401         ."  `url` TEXT NOT NULL"
402         .")";
403         $sgbd->query($sql);
404
405         $sql =
406          "CREATE TABLE #--sml_sources_invitations("
407         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
408         ."  `id_user` INTEGER NOT NULL,"
409         ."  `id_source` INTEGER NOT NULL,"
410         ."  `id_author` INTEGER NOT NULL,"
411         ."  `id_sources_access` INTEGER NOT NULL,"
412         ."  `date_invitation` TEXT NOT NULL"
413         .")";
414         $sgbd->query($sql);
415
416       }
417       catch(Exception $e){
418         return "imposible de creer les tables en base";
419       }
420       try{
421         $sql =
422          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
423         ." VALUES(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr')";
424         $sgbd->query($sql);
425
426         $sql =
427          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
428         ." VALUES (2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/')";
429         $sgbd->query($sql);
430
431         $sql =
432          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
433         ." VALUES (3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/')";
434         $sgbd->query($sql);
435
436         $sql =
437          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
438         ." VALUES (4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/')";
439         $sgbd->query($sql);
440
441         $sql =
442          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
443         ." VALUES (5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/')";
444         $sgbd->query($sql);
445
446         $sql =
447          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
448         ." VALUES (6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/')";
449         $sgbd->query($sql);
450
451         $sql =
452          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
453         ." VALUES (7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/')";
454         $sgbd->query($sql);
455
456         $sql =
457          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
458         ." VALUES (8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/')";
459         $sgbd->query($sql);
460
461         $sql =
462          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
463         ." VALUES (9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm')";
464         $sgbd->query($sql);
465
466         $sql =
467          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
468         ." VALUES (10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html')";
469         $sgbd->query($sql);
470
471         $sql =
472          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
473         ." VALUES (11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
474         $sgbd->query($sql);
475
476         $sql =
477          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (1, 'album')";
478         $sgbd->query($sql);
479
480         $sql =
481          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (2, 'morceau')";
482         $sgbd->query($sql);
483
484         $sql =
485          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (3, 'piste')";
486         $sgbd->query($sql);
487
488         $sql =
489          "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES (1, 'admin', 'administrateur')";\r
490         $sgbd->query($sql);
491
492         $sql =
493          "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES (2, 'editeur', 'éditeur')";
494         $sgbd->query($sql);
495
496         $sql =
497          "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES (3, 'contributeur', 'contributeur')";
498         $sgbd->query($sql);
499
500       }
501       catch(Exception $e){
502         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
503       }
504       return true;
505     }
506
507     function install_xml($env){
508       $data = $env->data();
509       $sgbd = $data->sgbd();
510
511       $RES = true;
512       $res = $sgbd->data_exists("sml_authors"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
513       $res = $sgbd->data_exists("sml_classes"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
514       $res = $sgbd->data_exists("sml_licences"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
515       $res = $sgbd->data_exists("sml_sources"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
516       $res = $sgbd->data_exists("sml_sources_access"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
517       $res = $sgbd->data_exists("sml_sources_authors"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
518       $res = $sgbd->data_exists("sml_sources_infos"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
519       $res = $sgbd->data_exists("sml_source_cache"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
520       $res = $sgbd->data_exists("sml_source_compositions"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
521       $res = $sgbd->data_exists("sml_source_derivations"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
522       $res = $sgbd->data_exists("sml_source_documents"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
523       $res = $sgbd->data_exists("sml_sources_invitations"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
524
525       if($RES === -1) return "impossible de savoir si les tables existent deja. installation annulee";
526       if($RES === 1) return "des tables existent deja en base. installation annulee";
527
528       if(!$sgbd->create_data("sml_authors")) return "impossible de creer la table sml_authors";
529       if(!$sgbd->create_data("sml_classes")) return "impossible de creer la table sml_classes";
530       if(!$sgbd->create_data("sml_licences")) return "impossible de creer la table sml_licences";
531       if(!$sgbd->create_data("sml_sources")) return "impossible de creer la table sml_sources";
532       if(!$sgbd->create_data("sml_sources_access")) return "impossible de creer la table sml_sources_access";
533       if(!$sgbd->create_data("sml_sources_authors")) return "impossible de creer la table sml_sources_authors";
534       if(!$sgbd->create_data("sml_sources_infos")) return "impossible de creer la table sml_sources_infos";
535       if(!$sgbd->create_data("sml_source_cache")) return "impossible de creer la table sml_source_cache";
536       if(!$sgbd->create_data("sml_source_compositions")) return "impossible de creer la table sml_source_compositions";
537       if(!$sgbd->create_data("sml_source_derivations")) return "impossible de creer la table sml_source_derivations";
538       if(!$sgbd->create_data("sml_source_documents")) return "impossible de creer la table sml_source_documents";
539       if(!$sgbd->create_data("sml_sources_invitations")) return "impossible de creer la table sml_sources_invitations";
540
541       $ERROR = false;
542
543       // ------------------------------------ sml_licences
544
545       if(!$ERROR) if(
546         !$sgbd->add_data(
547           "sml_licences",
548           array(
549             "nom" => "Creative commons by-sa 2.0",
550             "url" => "http://creativecommons.org/licenses/by-sa/2.0/deed.fr"
551           )
552         )
553       ) $ERROR = true;
554       if(!$ERROR) if(
555         !$sgbd->add_data(
556           "sml_licences",
557           array(
558             "nom" => "Creative Commons by-nc-nd 2.5",
559             "url" => "http://creativecommons.org/licenses/by-nc-nd/2.5/"
560           )
561         )
562       ) $ERROR = true;
563       if(!$ERROR) if(
564         !$sgbd->add_data(
565           "sml_licences",
566           array(
567             "nom" => "Creative Commons by-nc-sa 2.5",
568             "url" => "http://creativecommons.org/licenses/by-nc-sa/2.5/"
569           )
570         )
571       ) $ERROR = true;
572       if(!$ERROR) if(
573         !$sgbd->add_data(
574           "sml_licences",
575           array(
576             "nom" => "Creative Commons by-nc 2.5",
577             "url" => "http://creativecommons.org/licenses/by-nc/2.5/"
578           )
579         )
580       ) $ERROR = true;
581       if(!$ERROR) if(
582         !$sgbd->add_data(
583           "sml_licences",
584           array(
585             "nom" => "Creative Commons by-nd 2.5",
586             "url" => "http://creativecommons.org/licenses/by-nd/2.5/"
587           )
588         )
589       ) $ERROR = true;
590       if(!$ERROR) if(
591         !$sgbd->add_data(
592           "sml_licences",
593           array(
594             "nom" => "Creative Commons by-sa 2.5",
595             "url" => "http://creativecommons.org/licenses/by-sa/2.5/"
596           )
597         )
598       ) $ERROR = true;
599       if(!$ERROR) if(
600         !$sgbd->add_data(
601           "sml_licences",
602           array(
603             "nom" => "Creative Commons by 2.5",
604             "url" => "http://creativecommons.org/licenses/by/2.5/"
605           )
606         )
607       ) $ERROR = true;
608       if(!$ERROR) if(
609         !$sgbd->add_data(
610           "sml_licences",
611           array(
612             "nom" => "Licence Art Libre",
613             "url" => "http://artlibre.org/licence/lal/"
614           )
615         )
616       ) $ERROR = true;
617       if(!$ERROR) if(
618         !$sgbd->add_data(
619           "sml_licences",
620           array(
621             "nom" => "Licence C Reaction",
622             "url" => "http://morne.free.fr/Necktar7/creactionfr.htm"
623           )
624         )
625       ) $ERROR = true;
626       if(!$ERROR) if(
627         !$sgbd->add_data(
628           "sml_licences",
629           array(
630             "nom" => "Yellow OpenMusic License",
631             "url" => "http://openmusic.linuxtag.org/yellow.html"
632           )
633         )
634       ) $ERROR = true;
635       if(!$ERROR) if(
636         !$sgbd->add_data(
637           "sml_licences",
638           array(
639             "nom" => "Green OpenMusic License",
640             "url" => "http://openmusic.linuxtag.org/green.html"
641           )
642         )
643       ) $ERROR = true;
644
645       // ------------------------------------ sml_classes
646
647       if(!$ERROR) if(
648         !$sgbd->add_data(
649           "sml_classes",
650           array(
651             "nom" => "album"
652           )
653         )
654       ) $ERROR = true;
655       if(!$ERROR) if(
656         !$sgbd->add_data(
657           "sml_classes",
658           array(
659             "nom" => "morceau"
660           )
661         )
662       ) $ERROR = true;
663       if(!$ERROR) if(
664         !$sgbd->add_data(
665           "sml_classes",
666           array(
667             "nom" => "piste"
668           )
669         )
670       ) $ERROR = true;
671
672       // ------------------------------------ sml_sources_access
673
674       if(!$ERROR) if(
675         !$sgbd->add_data(
676           "sml_sources_access",
677           array(
678             "nom" => "admin",
679             "intitule" => "administrateur"
680           )
681         )
682       ) $ERROR = true;
683       if(!$ERROR) if(
684         !$sgbd->add_data(
685           "sml_sources_access",
686           array(
687             "nom" => "editeur",
688             "intitule" => "éditeur"
689           )
690         )
691       ) $ERROR = true;
692       if(!$ERROR) if(
693         !$sgbd->add_data(
694           "sml_sources_access",
695           array(
696             "nom" => "contributeur",
697             "intitule" => "contributeur"
698           )
699         )
700       ) $ERROR = true;
701
702       if($ERROR){
703         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
704       }
705
706       return true;
707     }
708
709     // ---------------------------------------------------------------------------------
710     //                                                                         uninstall
711     //
712
713     function uninstall($env){
714       if(
715             $env->bdd("sgbd") == "mysql"
716         ||  $env->bdd("sgbd") == "pdo_mysql"
717         ||  $env->bdd("sgbd") == "pdo_sqlite"
718       ) return $this->uninstall_sql($env);
719       if(
720             $env->bdd("sgbd") == "xml"
721       ) return $this->uninstall_xml($env);
722       return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
723     }
724
725     function uninstall_sql($env){
726       $data = $env->data();
727       $sgbd = $data->sgbd();
728       if(!$this->disable($env)) return "impossible de desactiver le plugin";
729       try{
730         $sgbd->query("DROP TABLE #--sml_authors");
731       }
732       catch(Exception $e){
733         return "impossible de supprimer la table #--sml_authors";
734       }
735       try{
736         $sgbd->query("DROP TABLE #--sml_classes");
737       }
738       catch(Exception $e){
739         return "impossible de supprimer la table #--sml_classes";
740       }
741       try{
742         $sgbd->query("DROP TABLE #--sml_licences");
743       }
744       catch(Exception $e){
745         return "impossible de supprimer la table #--sml_licences";
746       }
747       try{
748         $sgbd->query("DROP TABLE #--sml_sources");
749       }
750       catch(Exception $e){
751         return "impossible de supprimer la table #--sml_sources";
752       }
753       try{
754         $sgbd->query("DROP TABLE #--sml_sources_access");
755       }
756       catch(Exception $e){
757         return "impossible de supprimer la table #--sml_sources_access";
758       }
759       try{
760         $sgbd->query("DROP TABLE #--sml_sources_authors");
761       }
762       catch(Exception $e){
763         return "impossible de supprimer la table #--sml_sources_authors";
764       }
765       try{
766         $sgbd->query("DROP TABLE #--sml_sources_infos");
767       }
768       catch(Exception $e){
769         return "impossible de supprimer la table #--sml_sources_infos";
770       }
771       try{
772         $sgbd->query("DROP TABLE #--sml_source_cache");
773       }
774       catch(Exception $e){
775         return "impossible de supprimer la table #--sml_source_cache";
776       }
777       try{
778         $sgbd->query("DROP TABLE #--sml_source_compositions");
779       }
780       catch(Exception $e){
781         return "impossible de supprimer la table #--sml_source_compositions";
782       }
783       try{
784         $sgbd->query("DROP TABLE #--sml_source_derivations");
785       }
786       catch(Exception $e){
787         return "impossible de supprimer la table #--sml_source_derivations";
788       }
789       try{
790         $sgbd->query("DROP TABLE #--sml_source_documents");
791       }
792       catch(Exception $e){
793         return "impossible de supprimer la table #--sml_source_documents";
794       }
795       try{
796         $sgbd->query("DROP TABLE #--sml_sources_invitations");
797       }
798       catch(Exception $e){
799         return "impossible de supprimer la table #--sml_sources_invitations";
800       }
801       return true;
802     }
803
804     function uninstall_xml($env){
805       $data = $env->data();
806       $sgbd = $data->sgbd();
807       if(!$this->disable($env)) return "impossible de desactiver le plugin";
808
809       $ERROR = false;
810
811       if(!$ERROR) if(!$sgbd->remove_data("sml_authors")) $ERROR = true;
812       if(!$ERROR) if(!$sgbd->remove_data("sml_classes")) $ERROR = true;
813       if(!$ERROR) if(!$sgbd->remove_data("sml_licences")) $ERROR = true;
814       if(!$ERROR) if(!$sgbd->remove_data("sml_sources")) $ERROR = true;
815       if(!$ERROR) if(!$sgbd->remove_data("sml_sources_access")) $ERROR = true;
816       if(!$ERROR) if(!$sgbd->remove_data("sml_sources_authors")) $ERROR = true;
817       if(!$ERROR) if(!$sgbd->remove_data("sml_sources_infos")) $ERROR = true;
818       if(!$ERROR) if(!$sgbd->remove_data("sml_source_cache")) $ERROR = true;
819       if(!$ERROR) if(!$sgbd->remove_data("sml_source_compositions")) $ERROR = true;
820       if(!$ERROR) if(!$sgbd->remove_data("sml_source_derivations")) $ERROR = true;
821       if(!$ERROR) if(!$sgbd->remove_data("sml_source_documents")) $ERROR = true;
822       if(!$ERROR) if(!$sgbd->remove_data("sml_sources_invitations")) $ERROR = true;
823
824
825       if($ERROR){
826         return "erreur lors de la suppression des tables";
827       }
828
829       return true;
830     }
831
832   }
833
834 ?>