fonctionne avec SQLite + ajustements template
[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 enable($env){
38       return true;
39     }
40
41     function disable($env){
42       return true;
43     }
44
45     // ---------------------------------------------------------------------------------
46     //                                                                           install
47     //
48
49     function install($env){
50       if(
51             $env->bdd("sgbd") == "mysql"
52         ||  $env->bdd("sgbd") == "pdo_mysql"
53       ) return $this->install_mysql($env);
54       elseif(
55             $env->bdd("sgbd") == "pdo_sqlite"
56       ) return $this->install_sqlite($env);
57       return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
58     }
59
60     function install_mysql($env){
61       $data = $env->data();
62       $sgbd = $data->sgbd();
63       try{
64         $EXISTS =
65             $sgbd->table_exists("#--sml_authors")
66         ||  $sgbd->table_exists("#--sml_classes")
67         ||  $sgbd->table_exists("#--sml_licences")
68         ||  $sgbd->table_exists("#--sml_sources")
69         ||  $sgbd->table_exists("#--sml_sources_access")
70         ||  $sgbd->table_exists("#--sml_sources_authors")
71         ||  $sgbd->table_exists("#--sml_sources_infos")
72         ||  $sgbd->table_exists("#--sml_source_cache")
73         ||  $sgbd->table_exists("#--sml_source_compositions")
74         ||  $sgbd->table_exists("#--sml_source_derivations")
75         ||  $sgbd->table_exists("#--sml_source_documents")
76         ||  $sgbd->table_exists("#--sml_sources_invitations");
77       }
78       catch(Exception $e){
79         return "impossible de savoir si les tables existent deja";
80       }
81       if($EXISTS){
82         return "des tables existent deja en base. installation annulee";
83       }
84       try{
85         $sql =
86          "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"";
87         $sgbd->query($sql);
88
89         $sql =
90          "CREATE TABLE `#--sml_authors`("
91         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
92         ."  `id_user` int(11) NOT NULL,"
93         ."  `nom` varchar(255) NOT NULL,"
94         ."  `image` varchar(255) DEFAULT NULL,"
95         ."  `description` text,"
96         ."  `email` varchar(255) NOT NULL,"
97         ."  `contact_form` tinyint(4) NOT NULL,"
98         ."  `captcha` tinyint(4) NOT NULL,"
99         ."  PRIMARY KEY (`id`),"
100         ."  KEY `id_user` (`id_user`)"
101         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
102         $sgbd->query($sql);
103
104         $sql =
105          "CREATE TABLE `#--sml_classes`("
106         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
107         ."  `nom` varchar(255) NOT NULL,"
108         ."  PRIMARY KEY (`id`)"
109         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
110         $sgbd->query($sql);
111
112         $sql =
113          "CREATE TABLE `#--sml_licences`("
114         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
115         ."  `nom` varchar(255) NOT NULL,"
116         ."  `url` varchar(255) NOT NULL,"
117         ."  PRIMARY KEY (`id`)"
118         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
119         $sgbd->query($sql);
120
121         $sql =
122          "CREATE TABLE `#--sml_sources`("
123         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
124         ."  `id_class` int(11) NOT NULL,"
125         ."  `reference` varchar(255) DEFAULT NULL,"
126         ."  `titre` varchar(255) DEFAULT NULL,"
127         ."  `licence` int(11) DEFAULT NULL,"
128         ."  `date_creation` date DEFAULT NULL,"
129         ."  `date_inscription` datetime NOT NULL,"
130         ."  PRIMARY KEY (`id`),"
131         ."  KEY `id_class` (`id_class`),"
132         ."  KEY `licence` (`licence`)"
133         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
134         $sgbd->query($sql);
135
136         $sql =
137          "CREATE TABLE `#--sml_sources_access`("
138         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
139         ."  `nom` varchar(255) NOT NULL,"
140         ."  `intitule` varchar(255) NOT NULL,"
141         ."  PRIMARY KEY (`id`)"
142         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
143         $sgbd->query($sql);
144
145         $sql =
146          "CREATE TABLE `#--sml_sources_authors`("
147         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
148         ."  `id_source` int(11) NOT NULL,"
149         ."  `id_author` int(11) NOT NULL,"
150         ."  `id_sources_access` int(11) NOT NULL,"
151         ."  PRIMARY KEY (`id`),"
152         ."  KEY `id_object` (`id_source`),"
153         ."  KEY `id_author` (`id_author`),"
154         ."  KEY `id_sources_access` (`id_sources_access`)"
155         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
156         $sgbd->query($sql);
157
158         $sql =
159          "CREATE TABLE `#--sml_sources_infos`("
160         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
161         ."  `id_source` int(11) NOT NULL,"
162         ."  `key` varchar(255) NOT NULL,"
163         ."  `value` text NOT NULL,"
164         ."  PRIMARY KEY (`id`),"
165         ."  KEY `id_source` (`id_source`)"
166         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
167         $sgbd->query($sql);
168
169         $sql =
170          "CREATE TABLE `#--sml_source_cache`("
171         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
172         ."  `url` varchar(255) NOT NULL,"
173         ."  `id_source` int(11) NOT NULL,"
174         ."  `last_update` datetime NOT NULL,"
175         ."  PRIMARY KEY (`id`)"
176         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
177         $sgbd->query($sql);
178
179         $sql =
180          "CREATE TABLE `#--sml_source_compositions`("
181         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
182         ."  `id_source` int(11) NOT NULL,"
183         ."  `id_composition` int(11) NOT NULL,"
184         ."  PRIMARY KEY (`id`),"
185         ."  KEY `id_source` (`id_source`),"
186         ."  KEY `id_composition` (`id_composition`)"
187         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
188         $sgbd->query($sql);
189
190         $sql =
191          "CREATE TABLE `#--sml_source_derivations`("
192         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
193         ."  `id_source` int(11) NOT NULL,"
194         ."  `derivation` varchar(255) NOT NULL,"
195         ."  PRIMARY KEY (`id`),"
196         ."  KEY `derivation` (`derivation`)"
197         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
198         $sgbd->query($sql);
199
200         $sql =
201          "CREATE TABLE `#--sml_source_documents`("
202         ."  `id` int(11) NOT NULL AUTO_INCREMENT,"
203         ."  `id_source` int(11) NOT NULL,"
204         ."  `nom` varchar(255) NOT NULL,"
205         ."  `url` varchar(255) NOT NULL,"
206         ."  PRIMARY KEY (`id`),"
207         ."  KEY `id_source` (`id_source`)"
208         .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
209         $sgbd->query($sql);
210
211         $sql =
212          "CREATE TABLE `#--sml_sources_invitations`("
213         ."  `id` INT(11) NOT NULL AUTO_INCREMENT,"
214         ."  `id_user` INT(11) NOT NULL,"
215         ."  `id_source` INT(11) NOT NULL,"
216         ."  `id_author` INT(11) NOT NULL,"
217         ."  `id_sources_access` INT(11) NOT NULL,"
218         ."  `date_invitation` datetime NOT NULL,"
219         ."  PRIMARY KEY (`id`)"
220         .")";
221         $sgbd->query($sql);
222
223       }
224       catch(Exception $e){
225         return "imposible de creer les tables en base";
226       }
227       try{
228         $sql =
229          "INSERT INTO `#--sml_licences` (`id`, `nom`, `url`) VALUES"
230         ."(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr'),"
231         ."(2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/'),"
232         ."(3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/'),"
233         ."(4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/'),"
234         ."(5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/'),"
235         ."(6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/'),"
236         ."(7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/'),"
237         ."(8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/'),"
238         ."(9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm'),"
239         ."(10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html'),"
240         ."(11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
241         $sgbd->query($sql);
242
243         $sql =
244          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES"
245         ."(1, 'album'),"
246         ."(2, 'morceau'),"
247         ."(3, 'piste')";
248         $sgbd->query($sql);
249
250         $sql =
251          "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES"\r
252         ."(1, 'admin', 'administrateur'),"\r
253         ."(2, 'editeur', 'éditeur'),"\r
254         ."(3, 'contributeur', 'contributeur')";
255         $sgbd->query($sql);
256
257       }
258       catch(Exception $e){
259         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
260       }
261       return true;
262     }
263
264     function install_sqlite($env){
265       $data = $env->data();
266       $sgbd = $data->sgbd();
267       try{
268         $EXISTS =
269             $sgbd->table_exists("#--sml_authors")
270         ||  $sgbd->table_exists("#--sml_classes")
271         ||  $sgbd->table_exists("#--sml_licences")
272         ||  $sgbd->table_exists("#--sml_sources")
273         ||  $sgbd->table_exists("#--sml_sources_access")
274         ||  $sgbd->table_exists("#--sml_sources_authors")
275         ||  $sgbd->table_exists("#--sml_sources_infos")
276         ||  $sgbd->table_exists("#--sml_source_cache")
277         ||  $sgbd->table_exists("#--sml_source_compositions")
278         ||  $sgbd->table_exists("#--sml_source_derivations")
279         ||  $sgbd->table_exists("#--sml_source_documents")
280         ||  $sgbd->table_exists("#--sml_sources_invitations");
281       }
282       catch(Exception $e){
283         return "impossible de savoir si les tables existent deja";
284       }
285       if($EXISTS){
286         return "des tables existent deja en base. installation annulee";
287       }
288       try{
289
290         $sql =
291          "CREATE TABLE #--sml_authors("
292         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
293         ."  `id_user` INTEGER NOT NULL,"
294         ."  `nom` TEXT NOT NULL,"
295         ."  `image` TEXT DEFAULT NULL,"
296         ."  `description` TEXT,"
297         ."  `email` TEXT NOT NULL,"
298         ."  `contact_form` INTEGER NOT NULL,"
299         ."  `captcha` INTEGER NOT NULL"
300         .")";
301         $sgbd->query($sql);
302
303         $sql =
304          "CREATE TABLE #--sml_classes("
305         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
306         ."  `nom` TEXT NOT NULL"
307         .")";
308         $sgbd->query($sql);
309
310         $sql =
311          "CREATE TABLE #--sml_licences("
312         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
313         ."  `nom` TEXT NOT NULL,"
314         ."  `url` TEXT NOT NULL"
315         .")";
316         $sgbd->query($sql);
317
318         $sql =
319          "CREATE TABLE #--sml_sources("
320         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
321         ."  `id_class` INTEGER NOT NULL,"
322         ."  `reference` TEXT DEFAULT NULL,"
323         ."  `titre` TEXT DEFAULT NULL,"
324         ."  `licence` INTEGER DEFAULT NULL,"
325         ."  `date_creation` TEXT DEFAULT NULL,"
326         ."  `date_inscription` TEXT NOT NULL"
327         .")";
328         $sgbd->query($sql);
329
330         $sql =
331          "CREATE TABLE #--sml_sources_access("
332         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
333         ."  `nom` TEXT NOT NULL,"
334         ."  `intitule` TEXT NOT NULL"
335         .")";
336         $sgbd->query($sql);
337
338         $sql =
339          "CREATE TABLE #--sml_sources_authors("
340         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
341         ."  `id_source` INTEGER NOT NULL,"
342         ."  `id_author` INTEGER NOT NULL,"
343         ."  `id_sources_access` INTEGER NOT NULL"
344         .")";
345         $sgbd->query($sql);
346
347         $sql =
348          "CREATE TABLE #--sml_sources_infos("
349         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
350         ."  `id_source` INTEGER NOT NULL,"
351         ."  `key` TEXT NOT NULL,"
352         ."  `value` TEXT NOT NULL"
353         .")";
354         $sgbd->query($sql);
355
356         $sql =
357          "CREATE TABLE #--sml_source_cache("
358         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
359         ."  `url` TEXT NOT NULL,"
360         ."  `id_source` INTEGER NOT NULL,"
361         ."  `last_update` TEXT NOT NULL"
362         .")";
363         $sgbd->query($sql);
364
365         $sql =
366          "CREATE TABLE #--sml_source_compositions("
367         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
368         ."  `id_source` INTEGER NOT NULL,"
369         ."  `id_composition` INTEGER NOT NULL"
370         .")";
371         $sgbd->query($sql);
372
373         $sql =
374          "CREATE TABLE #--sml_source_derivations("
375         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
376         ."  `id_source` INTEGER NOT NULL,"
377         ."  `derivation` TEXT NOT NULL"
378         .")";
379         $sgbd->query($sql);
380
381         $sql =
382          "CREATE TABLE #--sml_source_documents("
383         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
384         ."  `id_source` INTEGER NOT NULL,"
385         ."  `nom` TEXT NOT NULL,"
386         ."  `url` TEXT NOT NULL"
387         .")";
388         $sgbd->query($sql);
389
390         $sql =
391          "CREATE TABLE #--sml_sources_invitations("
392         ."  `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
393         ."  `id_user` INTEGER NOT NULL,"
394         ."  `id_source` INTEGER NOT NULL,"
395         ."  `id_author` INTEGER NOT NULL,"
396         ."  `id_sources_access` INTEGER NOT NULL,"
397         ."  `date_invitation` TEXT NOT NULL"
398         .")";
399         $sgbd->query($sql);
400
401       }
402       catch(Exception $e){
403         return "imposible de creer les tables en base";
404       }
405       try{
406         $sql =
407          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
408         ." VALUES(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr')";
409         $sgbd->query($sql);
410
411         $sql =
412          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
413         ." VALUES (2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/')";
414         $sgbd->query($sql);
415
416         $sql =
417          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
418         ." VALUES (3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/')";
419         $sgbd->query($sql);
420
421         $sql =
422          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
423         ." VALUES (4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/')";
424         $sgbd->query($sql);
425
426         $sql =
427          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
428         ." VALUES (5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/')";
429         $sgbd->query($sql);
430
431         $sql =
432          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
433         ." VALUES (6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/')";
434         $sgbd->query($sql);
435
436         $sql =
437          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
438         ." VALUES (7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/')";
439         $sgbd->query($sql);
440
441         $sql =
442          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
443         ." VALUES (8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/')";
444         $sgbd->query($sql);
445
446         $sql =
447          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
448         ." VALUES (9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm')";
449         $sgbd->query($sql);
450
451         $sql =
452          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
453         ." VALUES (10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html')";
454         $sgbd->query($sql);
455
456         $sql =
457          "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
458         ." VALUES (11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
459         $sgbd->query($sql);
460
461         $sql =
462          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (1, 'album')";
463         $sgbd->query($sql);
464
465         $sql =
466          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (2, 'morceau')";
467         $sgbd->query($sql);
468
469         $sql =
470          "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (3, 'piste')";
471         $sgbd->query($sql);
472
473         $sql =
474          "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES (1, 'admin', 'administrateur')";\r
475         $sgbd->query($sql);
476
477         $sql =
478          "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES (2, 'editeur', 'éditeur')";
479         $sgbd->query($sql);
480
481         $sql =
482          "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES (3, 'contributeur', 'contributeur')";
483         $sgbd->query($sql);
484
485       }
486       catch(Exception $e){
487         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
488       }
489       return true;
490     }
491
492     // ---------------------------------------------------------------------------------
493     //                                                                         uninstall
494     //
495
496     function uninstall($env){
497       if(
498             $env->bdd("sgbd") == "mysql"
499         ||  $env->bdd("sgbd") == "pdo_mysql"
500         ||  $env->bdd("sgbd") == "pdo_sqlite"
501       ) return $this->uninstall_sql($env);
502       return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
503     }
504
505     function uninstall_sql($env){
506       $data = $env->data();
507       $sgbd = $data->sgbd();
508       if(!$this->disable($env)) return "impossible de desactiver le plugin";
509       try{
510         $sgbd->query("DROP TABLE #--sml_authors");
511       }
512       catch(Exception $e){
513         return "impossible de supprimer la table #--sml_authors";
514       }
515       try{
516         $sgbd->query("DROP TABLE #--sml_classes");
517       }
518       catch(Exception $e){
519         return "impossible de supprimer la table #--sml_classes";
520       }
521       try{
522         $sgbd->query("DROP TABLE #--sml_licences");
523       }
524       catch(Exception $e){
525         return "impossible de supprimer la table #--sml_licences";
526       }
527       try{
528         $sgbd->query("DROP TABLE #--sml_sources");
529       }
530       catch(Exception $e){
531         return "impossible de supprimer la table #--sml_sources";
532       }
533       try{
534         $sgbd->query("DROP TABLE #--sml_sources_access");
535       }
536       catch(Exception $e){
537         return "impossible de supprimer la table #--sml_sources_access";
538       }
539       try{
540         $sgbd->query("DROP TABLE #--sml_sources_authors");
541       }
542       catch(Exception $e){
543         return "impossible de supprimer la table #--sml_sources_authors";
544       }
545       try{
546         $sgbd->query("DROP TABLE #--sml_sources_infos");
547       }
548       catch(Exception $e){
549         return "impossible de supprimer la table #--sml_sources_infos";
550       }
551       try{
552         $sgbd->query("DROP TABLE #--sml_source_cache");
553       }
554       catch(Exception $e){
555         return "impossible de supprimer la table #--sml_source_cache";
556       }
557       try{
558         $sgbd->query("DROP TABLE #--sml_source_compositions");
559       }
560       catch(Exception $e){
561         return "impossible de supprimer la table #--sml_source_compositions";
562       }
563       try{
564         $sgbd->query("DROP TABLE #--sml_source_derivations");
565       }
566       catch(Exception $e){
567         return "impossible de supprimer la table #--sml_source_derivations";
568       }
569       try{
570         $sgbd->query("DROP TABLE #--sml_source_documents");
571       }
572       catch(Exception $e){
573         return "impossible de supprimer la table #--sml_source_documents";
574       }
575       try{
576         $sgbd->query("DROP TABLE #--sml_sources_invitations");
577       }
578       catch(Exception $e){
579         return "impossible de supprimer la table #--sml_sources_invitations";
580       }
581       return true;
582     }
583
584     // ---------------------------------------------------------------------------------
585     //                                                                fonctions internes
586     //
587
588     function nb_invitations($env){
589       if($user = $env->user()){
590         $data = $env->data();
591         if($groupes = $data->groupes($user["id"])){
592           $groupes_in = "";
593           foreach($groupes["list"] as $id_groupe => $groupe) $groupes_in .= ($groupes_in ? "," : "").$id_groupe;
594           if($groupes_in){
595             if(
596               (
597                 $invitations = $data->list_sml_sources_invitations(
598                   array(
599                     "index_name" => "id",
600                     "where"=> "id_author IN(".$groupes_in.") OR id_user=".$user["id"],
601                     "order_by" => "date_invitation",
602                     "order" => "DESC"
603                   )
604                 )
605               ) !== false
606             ){
607               return $invitations["total"];
608             }
609           }
610         }
611       }
612       return 0;
613     }
614
615   }
616
617 ?>