source: extensions/ContestResults/maintain.inc.php @ 9572

Last change on this file since 9572 was 9572, checked in by mistic100, 13 years ago

[extensions] ContestResults 1.3

  • Add error and success messages on admin page
  • Add Spain (es_ES) thanks to jpr928
  • Contest status is automatic and shows remaining days
  • More flexibility for description fields
  • Compatibility with Piwigo 2.2.0
File size: 3.9 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4// Configuration par défaut
5define('default_config', serialize(array(
6        'menubar_mode' => array(
7                'link' => 0,
8                'block' => 1
9        ),
10        'menubar_link' => array(
11                'menu' => 1,
12                'specials' => 0
13        ),
14        'menubar_block' => array(
15                'number' => 5
16        )
17)));
18
19// Installtion
20function plugin_install() {
21        global $prefixeTable;
22
23        pwg_query("CREATE TABLE `" . $prefixeTable . "contests` (
24                `id` INT NOT NULL AUTO_INCREMENT ,
25                `name` VARCHAR( 255 ) NOT NULL ,
26                `date_begin` DATE NOT NULL ,
27                `date_end` DATE NOT NULL ,
28                `visible` TINYINT(1) NOT NULL ,
29                `logo` VARCHAR( 255 ) NULL ,
30                `banner` VARCHAR( 255 ) NULL ,
31                `description` TEXT NULL ,
32                PRIMARY KEY ( `id` )
33        );");
34       
35        pwg_query("CREATE TABLE `" . $prefixeTable . "contests_results` (
36                `image_id` INT NOT NULL ,
37                `contest_id` INT NOT NULL ,
38                `rank` INT NOT NULL ,
39                `author` VARCHAR( 255 ) NOT NULL ,
40                `comment` TEXT NULL,
41                UNIQUE ( `image_id` , `contest_id` )
42        );");
43       
44        pwg_query("INSERT INTO " . CONFIG_TABLE . "(param,value,comment) VALUES('ContestResults', '" . default_config . "', 'Parametres du plugin ContestResults');");
45}
46
47// Activation
48function plugin_activate(){
49        global $conf, $prefixeTable;
50
51        // compatibilité avec les versions < 1.1 (ajout d'une entrée de configuration)
52        if (!isset($conf['ContestResults'])) {
53                pwg_query("INSERT INTO " . CONFIG_TABLE . "(param,value,comment) VALUES('ContestResults', '" . default_config . "', 'Parametres du plugin ContestResults');");
54        }
55       
56        // compatibilité avec les versions < 1.2 (suppression option d'affichage)
57        $field = pwg_query("SHOW COLUMNS FROM `" . $prefixeTable . "contests` LIKE 'presentation_display'");
58        if (pwg_db_num_rows($field)) {
59                pwg_query("ALTER TABLE `" . $prefixeTable . "contests`
60                        DROP `presentation_display`,
61                        DROP `rules_display`,
62                        DROP `prices_display`,
63                        DROP `final_display`;"
64                );
65        }
66       
67        // compatibilité avec les versions < 1.3 (suppression option status, regroupement des champs de description)
68        $field = pwg_query("SHOW COLUMNS FROM `" . $prefixeTable . "contests` LIKE 'status'");
69        if (pwg_db_num_rows($field)) {
70                pwg_query("ALTER TABLE `" . $prefixeTable . "contests` DROP `status`");
71                pwg_query("ALTER TABLE `" . $prefixeTable . "contests` ADD `description` TEXT NULL");
72               
73                $contests = pwg_query("SELECT * FROM `" . $prefixeTable . "contests`");
74                while ($contest = pwg_db_fetch_assoc($contests)) {
75                        $new_description = array();
76                        if (!empty($contest['presentation'])) {
77                                $new_description[] = array(
78                                        'name' => 'Presentation[lang=fr]Présentation[/lang][lang=es]Presentación[/lang][lang=lv]Prezentacija[/lang]',
79                                        'content' => $contest['presentation'],
80                                );
81                        }
82                        if (!empty($contest['rules'])) {
83                                $new_description[] = array(
84                                        'name' => 'Rules[lang=fr]Règles[/lang][lang=es]Restricciones[/lang][lang=lv]Noteikumi[/lang]',
85                                        'content' => $contest['rules'],
86                                );
87                        }
88                        if (!empty($contest['prices'])) {
89                                $new_description[] = array(
90                                        'name' => 'Prices[lang=fr]Prix[/lang][lang=es]Precios[/lang][lang=lv]Cenas[/lang]',
91                                        'content' => $contest['prices'],
92                                );
93                        }
94                        if (!empty($contest['final'])) {
95                                $new_description[] = array(
96                                        'name' => 'Conclusion[lang=fr]Conclusion[/lang][lang=es]Conclusión[/lang][lang=lv]Beigsana[/lang]',
97                                        'content' => $contest['final'],
98                                );
99                        }
100               
101                        $new_description = base64_encode(serialize($new_description));
102                        pwg_query("UPDATE `" . $prefixeTable . "contests`
103                                SET description = '". $new_description ."'
104                                WHERE id = ". $contest['id'] .";"
105                        );
106                }
107               
108                pwg_query("ALTER TABLE `" . $prefixeTable . "contests`
109                        DROP `presentation`,
110                        DROP `rules`,
111                        DROP `prices`,
112                        DROP `final`;"
113                );
114        }
115       
116}
117
118// Désinstallation
119function plugin_uninstall() {
120        global $prefixeTable;
121
122        pwg_query("DROP TABLE `" . $prefixeTable . "contests`;");
123        pwg_query("DROP TABLE `" . $prefixeTable . "contests_results`;");
124        pwg_query("DELETE FROM " . CONFIG_TABLE . " WHERE `param` = 'ContestResults';");
125}
126?>
Note: See TracBrowser for help on using the repository browser.