1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Psli-BingMaps |
---|
4 | Author: psli |
---|
5 | */ |
---|
6 | |
---|
7 | $query = ' |
---|
8 | SELECT value |
---|
9 | FROM '.CONFIG_TABLE.' |
---|
10 | WHERE param = "'.PSLI_CONF_VERSION_MAJ.'";'; |
---|
11 | $result = pwg_query($query); |
---|
12 | $row = pwg_db_fetch_assoc($result); |
---|
13 | $version_maj = $row['value']; |
---|
14 | |
---|
15 | $query = ' |
---|
16 | SELECT value |
---|
17 | FROM '.CONFIG_TABLE.' |
---|
18 | WHERE param = "'.PSLI_CONF_VERSION_MIN.'";'; |
---|
19 | $result = pwg_query($query); |
---|
20 | $row = pwg_db_fetch_assoc($result); |
---|
21 | $version_min = $row['value']; |
---|
22 | |
---|
23 | // from version 1.0 |
---|
24 | if (($version_maj == "1") and ($version_min == "0")) |
---|
25 | { |
---|
26 | // No differences between 1.0 and 1.1 except localization |
---|
27 | // Just update version in configuration |
---|
28 | $query = ' |
---|
29 | UPDATE '.CONFIG_TABLE.' |
---|
30 | SET value = "' . PSLI_VERSION_MAJ . '" |
---|
31 | WHERE param = "'.PSLI_CONF_VERSION_MAJ.'" |
---|
32 | LIMIT 1'; |
---|
33 | pwg_query($query); |
---|
34 | $query = ' |
---|
35 | UPDATE '.CONFIG_TABLE.' |
---|
36 | SET value = "' . PSLI_VERSION_MIN . '" |
---|
37 | WHERE param = "'.PSLI_CONF_VERSION_MIN.'" |
---|
38 | LIMIT 1'; |
---|
39 | pwg_query($query); |
---|
40 | $version_maj = "1"; |
---|
41 | $version_min = "1"; |
---|
42 | } |
---|
43 | |
---|
44 | // from version 1.1 |
---|
45 | if (($version_maj == "1") and ($version_min == "1")) |
---|
46 | { |
---|
47 | // No differences between 1.1 and 1.2 except localization |
---|
48 | // Just update version in configuration |
---|
49 | $query = ' |
---|
50 | UPDATE '.CONFIG_TABLE.' |
---|
51 | SET value = "' . PSLI_VERSION_MAJ . '" |
---|
52 | WHERE param = "'.PSLI_CONF_VERSION_MAJ.'" |
---|
53 | LIMIT 1'; |
---|
54 | pwg_query($query); |
---|
55 | $query = ' |
---|
56 | UPDATE '.CONFIG_TABLE.' |
---|
57 | SET value = "' . PSLI_VERSION_MIN . '" |
---|
58 | WHERE param = "'.PSLI_CONF_VERSION_MIN.'" |
---|
59 | LIMIT 1'; |
---|
60 | pwg_query($query); |
---|
61 | $version_maj = "1"; |
---|
62 | $version_min = "2"; |
---|
63 | } |
---|
64 | |
---|
65 | // from version 1.2 |
---|
66 | if (($version_maj == "1") and ($version_min == "2")) |
---|
67 | { |
---|
68 | // New Conf data in v1.3 |
---|
69 | // Update version and create new conf param PSLI_CONF_PATH |
---|
70 | $query = ' |
---|
71 | UPDATE '.CONFIG_TABLE.' |
---|
72 | SET value = "' . PSLI_VERSION_MAJ . '" |
---|
73 | WHERE param = "'.PSLI_CONF_VERSION_MAJ.'" |
---|
74 | LIMIT 1'; |
---|
75 | pwg_query($query); |
---|
76 | $query = ' |
---|
77 | UPDATE '.CONFIG_TABLE.' |
---|
78 | SET value = "' . PSLI_VERSION_MIN . '" |
---|
79 | WHERE param = "'.PSLI_CONF_VERSION_MIN.'" |
---|
80 | LIMIT 1'; |
---|
81 | pwg_query($query); |
---|
82 | $version_maj = "1"; |
---|
83 | $version_min = "3"; |
---|
84 | $sql = 'INSERT INTO '.CONFIG_TABLE." (param, value) VALUES ('".PSLI_CONF_PATH."', 'http://".$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'],0, strrpos($_SERVER['REQUEST_URI'],"/"))."/');"; |
---|
85 | pwg_query($sql); |
---|
86 | } |
---|
87 | |
---|
88 | // from version 1.3 |
---|
89 | if (($version_maj == "1") and ($version_min == "3")) |
---|
90 | { |
---|
91 | // New table MAPS and changes in Entities table |
---|
92 | define('PSLI_CONF_LAT', 'PsliBingMapsLat'); |
---|
93 | define('PSLI_CONF_LON', 'PsliBingMapsLon'); |
---|
94 | define('PSLI_CONF_ZOOM', 'PsliBingMapsZoom'); |
---|
95 | define('PSLI_CONF_CATEGORY', 'PsliBingMapsCategoryInitiale'); |
---|
96 | |
---|
97 | // Create table Maps and default element |
---|
98 | $sql = ' |
---|
99 | CREATE TABLE IF NOT EXISTS `'.PSLI_MAPS_TABLE."` ( |
---|
100 | `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
---|
101 | `id_category` smallint(5) unsigned DEFAULT NULL, |
---|
102 | `title` text, |
---|
103 | `lat` decimal(15,12) DEFAULT '0.000000000000', |
---|
104 | `lon` decimal(15,12) DEFAULT '0.000000000000', |
---|
105 | `zoom` smallint(6) DEFAULT NULL, |
---|
106 | PRIMARY KEY (`id`) |
---|
107 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;"; |
---|
108 | pwg_query($sql); |
---|
109 | |
---|
110 | // Create table Entity-Map and default element |
---|
111 | $sql = ' |
---|
112 | CREATE TABLE IF NOT EXISTS `'.PSLI_ENTITIES_MAPS_TABLE."` ( |
---|
113 | `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
---|
114 | `id_entity` smallint(5) unsigned DEFAULT NULL, |
---|
115 | `id_map` smallint(5) unsigned DEFAULT NULL, |
---|
116 | PRIMARY KEY (`id`), |
---|
117 | UNIQUE `psli_entity_map_1` (`id_entity`, `id_map`), |
---|
118 | INDEX `psli_entity_map_2` (`id_entity`), |
---|
119 | INDEX `psli_entity_map_3` (`id_map`) |
---|
120 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;"; |
---|
121 | pwg_query($sql); |
---|
122 | |
---|
123 | $query = ' |
---|
124 | SELECT value |
---|
125 | FROM '.CONFIG_TABLE.' |
---|
126 | WHERE param = "'.PSLI_CONF_LAT.'";'; |
---|
127 | $result = pwg_query($query); |
---|
128 | $row = pwg_db_fetch_assoc($result); |
---|
129 | $lat = $row['value']; |
---|
130 | |
---|
131 | $query = ' |
---|
132 | SELECT value |
---|
133 | FROM '.CONFIG_TABLE.' |
---|
134 | WHERE param = "'.PSLI_CONF_LON.'";'; |
---|
135 | $result = pwg_query($query); |
---|
136 | $row = pwg_db_fetch_assoc($result); |
---|
137 | $lon = $row['value']; |
---|
138 | |
---|
139 | $query = ' |
---|
140 | SELECT value |
---|
141 | FROM '.CONFIG_TABLE.' |
---|
142 | WHERE param = "'.PSLI_CONF_ZOOM.'";'; |
---|
143 | $result = pwg_query($query); |
---|
144 | $row = pwg_db_fetch_assoc($result); |
---|
145 | $zoom = $row['value']; |
---|
146 | |
---|
147 | $query = ' |
---|
148 | SELECT value |
---|
149 | FROM '.CONFIG_TABLE.' |
---|
150 | WHERE param = "'.PSLI_CONF_CATEGORY.'";'; |
---|
151 | $result = pwg_query($query); |
---|
152 | $row = pwg_db_fetch_assoc($result); |
---|
153 | $category = $row['value']; |
---|
154 | if ($category == 'to define') |
---|
155 | { |
---|
156 | $category = 'null'; |
---|
157 | } |
---|
158 | |
---|
159 | $sql = "INSERT INTO `".PSLI_MAPS_TABLE."` (`id`, `id_category`, `title`, `lat`, `lon`, `zoom`) |
---|
160 | VALUES (1, ".$category.", 'Default', ".$lat.", ".$lon.", ".$zoom.");"; |
---|
161 | pwg_query($sql); |
---|
162 | |
---|
163 | $sql = "INSERT INTO `".PSLI_ENTITIES_MAPS_TABLE."` (`id_entity`, `id_map`) |
---|
164 | SELECT id, 1 FROM `".PSLI_ENTITIES_TABLE."`;"; |
---|
165 | pwg_query($sql); |
---|
166 | |
---|
167 | // Update table Entities |
---|
168 | $sql = 'ALTER TABLE `'.PSLI_ENTITIES_TABLE.'` DROP INDEX `psli_i10`;'; |
---|
169 | pwg_query($sql); |
---|
170 | $sql = 'ALTER TABLE `'.PSLI_ENTITIES_TABLE.'` CHANGE COLUMN `id_category` `id_action` smallint(5) unsigned DEFAULT NULL;'; |
---|
171 | pwg_query($sql); |
---|
172 | $sql = 'ALTER TABLE `'.PSLI_ENTITIES_TABLE.'` ADD COLUMN `type` smallint(1) default 1;'; |
---|
173 | pwg_query($sql); |
---|
174 | $sql = 'UPDATE `'.PSLI_ENTITIES_TABLE.'` SET `id_action`=`action`, `action`=1 WHERE `action` <> 0;'; |
---|
175 | pwg_query($sql); |
---|
176 | $sql = 'UPDATE `'.PSLI_ENTITIES_TABLE.'` SET `action`=2 WHERE `action` = 0;'; |
---|
177 | pwg_query($sql); |
---|
178 | $sql = 'UPDATE '.PSLI_ENTITIES_TABLE.' e SET e.type=2 where exists (select * from '.PSLI_DATAPOINT_TABLE.' d where d.id_entity = e.id);'; |
---|
179 | pwg_query($sql); |
---|
180 | |
---|
181 | // Drop conf param PSLI_CONF_LAT, PSLI_CONF_LON, PSLI_CONF_ZOOM |
---|
182 | $sql = 'DELETE FROM `'.CONFIG_TABLE."` WHERE param = '".PSLI_CONF_LAT."';"; |
---|
183 | pwg_query($sql); |
---|
184 | $sql = 'DELETE FROM `'.CONFIG_TABLE."` WHERE param = '".PSLI_CONF_LON."';"; |
---|
185 | pwg_query($sql); |
---|
186 | $sql = 'DELETE FROM `'.CONFIG_TABLE."` WHERE param = '".PSLI_CONF_ZOOM."';"; |
---|
187 | pwg_query($sql); |
---|
188 | $sql = 'DELETE FROM `'.CONFIG_TABLE."` WHERE param = '".PSLI_CONF_CATEGORY."';"; |
---|
189 | pwg_query($sql); |
---|
190 | |
---|
191 | // Update version |
---|
192 | $query = ' |
---|
193 | UPDATE '.CONFIG_TABLE.' |
---|
194 | SET value = "' . PSLI_VERSION_MAJ . '" |
---|
195 | WHERE param = "'.PSLI_CONF_VERSION_MAJ.'" |
---|
196 | LIMIT 1'; |
---|
197 | pwg_query($query); |
---|
198 | $query = ' |
---|
199 | UPDATE '.CONFIG_TABLE.' |
---|
200 | SET value = "' . PSLI_VERSION_MIN . '" |
---|
201 | WHERE param = "'.PSLI_CONF_VERSION_MIN.'" |
---|
202 | LIMIT 1'; |
---|
203 | pwg_query($query); |
---|
204 | $version_maj = "2"; |
---|
205 | $version_min = "0"; |
---|
206 | } |
---|
207 | |
---|
208 | ?> |
---|