1 | <?php |
---|
2 | |
---|
3 | if(!defined('UAM_PATH')) |
---|
4 | { |
---|
5 | define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
6 | } |
---|
7 | |
---|
8 | include_once (UAM_PATH.'include/constants.php'); |
---|
9 | include_once (UAM_PATH.'include/functions.inc.php'); |
---|
10 | |
---|
11 | load_language('plugin.lang', UAM_PATH); |
---|
12 | |
---|
13 | |
---|
14 | function plugin_install() |
---|
15 | { |
---|
16 | global $conf; |
---|
17 | |
---|
18 | /* ****************************************************************** */ |
---|
19 | /* **************** BEGIN - Data preparation in vars **************** */ |
---|
20 | /* ****************************************************************** */ |
---|
21 | |
---|
22 | $defaultUAM = array(); |
---|
23 | $defaultConfirmMail = array(); |
---|
24 | |
---|
25 | // Default global parameters for UserAdvManager conf |
---|
26 | // ------------------------------------------------- |
---|
27 | $defaultUAM[0] = 'false'; // UAM_MAIL_INFO_TRUE/FALSE |
---|
28 | $defaultUAM[1] = 'false'; // UAM_CONFIRM_MAIL_TRUE/FALSE |
---|
29 | $defaultUAM[2] = '-1'; // UAM_No_Confirm_Group |
---|
30 | $defaultUAM[3] = '-1'; // UAM_Validated_Group |
---|
31 | $defaultUAM[4] = '-1'; // UAM_Validated_Status |
---|
32 | $defaultUAM[5] = 'false'; // UAM_USERNAME_CHAR_TRUE |
---|
33 | $defaultUAM[6] = ''; // UAM_USERNAME_CHAR_LIST |
---|
34 | $defaultUAM[7] = '-1'; // UAM_No_Confirm_Status |
---|
35 | $defaultUAM[8] = l10n('UAM_Default_InfoMail_Txt'); // UAM_MAILINFO_TEXT |
---|
36 | $defaultUAM[9] = l10n('UAM_Default_ConfirmMail_Txt'); // UAM_CONFIRMMAIL_TEXT |
---|
37 | $defaultUAM[10] = 'false'; // UAM_MAILEXCLUSION_TRUE/FALSE |
---|
38 | $defaultUAM[11] = ''; // UAM_MAILEXCLUSION_LIST |
---|
39 | $defaultUAM[12] = 'false'; // UAM_PASSWORDENF_TRUE/FALSE |
---|
40 | $defaultUAM[13] = '100'; // UAM_PASSWORD_SCORE |
---|
41 | $defaultUAM[14] = 'false'; // UAM_ADMINPASSWENF_TRUE/FALSE |
---|
42 | $defaultUAM[15] = 'false'; // UAM_GHOSTRACKER_TRUE/FALSE |
---|
43 | $defaultUAM[16] = '10'; // UAM_GHOSTRACKER_DAYLIMIT |
---|
44 | $defaultUAM[17] = l10n('UAM_Default_GhstReminder_Txt'); // UAM_GHOSTRACKER_REMINDERTEXT |
---|
45 | $defaultUAM[18] = 'false'; // UAM_ADDLASTVISIT_TRUE/FALSE |
---|
46 | $defaultUAM[19] = 'false'; // UAM_ADMINCONFMAIL_TRUE/FALSE |
---|
47 | $defaultUAM[20] = 'false'; // UAM_REDIRTOPROFILE_TRUE/FALSE |
---|
48 | $defaultUAM[21] = 'false'; // UAM_GTAUTO_TRUE/FALSE |
---|
49 | $defaultUAM[22] = 'false'; // UAM_GTAUTOMAIL_TRUE/FALSE |
---|
50 | $defaultUAM[23] = l10n('UAM_Default_GhstDeletion_Txt'); // UAM_GTAUTODEL_TEXT |
---|
51 | $defaultUAM[24] = l10n('UAM_Default_GhstDemotion_Txt'); // UAM_GTAUTOMAILTEXT |
---|
52 | $defaultUAM[25] = '-1'; // UAM_Downgrade_Group |
---|
53 | $defaultUAM[26] = '-1'; // UAM_Downgrade_Status |
---|
54 | $defaultUAM[27] = l10n('UAM_Default_AdminValidation_Txt'); // UAM_ADMINVALIDATIONMAIL_TEXT |
---|
55 | $defaultUAM[28] = 'false'; // UAM_CUSTOMPASSWRETR_TRUE/FALSE |
---|
56 | $defaultUAM[29] = l10n('UAM_Default_PwdRequest_Txt'); // UAM_CUSTOMPASSWRETR_TEXT |
---|
57 | $defaultUAM[30] = 'false'; // UAM_USRAUTO_TRUE/FALSE |
---|
58 | $defaultUAM[31] = l10n('UAM_Default_ValidationTimeout_Txt');// UAM_USRAUTODEL_TEXT |
---|
59 | $defaultUAM[32] = 'false'; // UAM_USRAUTOMAIL_TRUE/FALSE |
---|
60 | $defaultUAM[33] = 'false'; // UAM_STUFFS_TRUE/FALSE |
---|
61 | $defaultUAM[34] = 'false'; // UAM_HIDEPASSW_TRUE/FALSE |
---|
62 | $defaultUAM[35] = '-1'; // UAM_NO_VALID_LEVEL |
---|
63 | $defaultUAM[36] = '-1'; // UAM_VALID_LEVEL |
---|
64 | $defaultUAM[37] = '-1'; // UAM_DOWNGRADE_LEVEL |
---|
65 | $defaultUAM[38] = 'false'; // UAM_PWDRESET_TRUE/FALSE |
---|
66 | |
---|
67 | // Default specific parameters for UserAdvManager ConfirmMail conf |
---|
68 | // --------------------------------------------------------------- |
---|
69 | $defaultConfirmMail[0] = 'false'; // UAM_CONFIRMMAIL_TIMEOUT_TRUE/FALSE |
---|
70 | $defaultConfirmMail[1] = '5'; // UAM_CONFIRMMAIL_DELAY |
---|
71 | $defaultConfirmMail[2] = l10n('UAM_Default_CfmMail_Remail_Txt1'); // UAM_CONFIRMMAIL_REMAIL_TXT1 |
---|
72 | $defaultConfirmMail[3] = 'false'; // UAM_CONFIRMMAIL_REMAIL_TRUE/FALSE |
---|
73 | $defaultConfirmMail[4] = l10n('UAM_Default_CfmMail_Remail_Txt2'); // UAM_CONFIRMMAIL_REMAIL_TXT2 |
---|
74 | $defaultConfirmMail[5] = l10n('UAM_Default_CfmMail_Custom_Txt1'); // UAM_CONFIRMMAIL_CUSTOM_TXT1 |
---|
75 | $defaultConfirmMail[6] = l10n('UAM_Default_CfmMail_Custom_Txt2'); // UAM_CONFIRMMAIL_CUSTOM_TXT2 |
---|
76 | |
---|
77 | // Set current plugin version in config table |
---|
78 | // ------------------------------------------ |
---|
79 | $plugin = PluginInfos(UAM_PATH); |
---|
80 | $version = $plugin['version']; |
---|
81 | |
---|
82 | /* **************************************************************** */ |
---|
83 | /* **************** END - Data preparation in vars **************** */ |
---|
84 | /* **************************************************************** */ |
---|
85 | |
---|
86 | |
---|
87 | /* ***************************************************************************** */ |
---|
88 | /* **************** BEGIN - Database actions and initialization **************** */ |
---|
89 | /* ***************************************************************************** */ |
---|
90 | |
---|
91 | // Create UserAdvManager conf if not already exists |
---|
92 | // ------------------------------------------------ |
---|
93 | $query = ' |
---|
94 | SELECT param |
---|
95 | FROM '.CONFIG_TABLE.' |
---|
96 | WHERE param = "UserAdvManager" |
---|
97 | ;'; |
---|
98 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
99 | |
---|
100 | if ($count == 0) |
---|
101 | { |
---|
102 | $q = ' |
---|
103 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
104 | VALUES ("UserAdvManager","'.pwg_db_real_escape_string(serialize($defaultUAM)).'","UAM parameters") |
---|
105 | ;'; |
---|
106 | pwg_query($q); |
---|
107 | } |
---|
108 | |
---|
109 | // Create UserAdvManager_ConfirmMail conf if not already exists |
---|
110 | // ------------------------------------------------------------ |
---|
111 | $query = ' |
---|
112 | SELECT param |
---|
113 | FROM '.CONFIG_TABLE.' |
---|
114 | WHERE param = "UserAdvManager_ConfirmMail" |
---|
115 | ;'; |
---|
116 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
117 | |
---|
118 | if ($count == 0) |
---|
119 | { |
---|
120 | $q = ' |
---|
121 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
122 | VALUES ("UserAdvManager_ConfirmMail","'.pwg_db_real_escape_string(serialize($defaultConfirmMail)).'","UAM ConfirmMail parameters") |
---|
123 | ;'; |
---|
124 | pwg_query($q); |
---|
125 | } |
---|
126 | |
---|
127 | // Create UserAdvManager_Redir conf if not already exists |
---|
128 | // ------------------------------------------------------ |
---|
129 | $query = ' |
---|
130 | SELECT param |
---|
131 | FROM '.CONFIG_TABLE.' |
---|
132 | WHERE param = "UserAdvManager_Redir" |
---|
133 | ;'; |
---|
134 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
135 | |
---|
136 | if ($count == 0) |
---|
137 | { |
---|
138 | $q = ' |
---|
139 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
140 | VALUES ("UserAdvManager_Redir","0","UAM Redirections") |
---|
141 | ;'; |
---|
142 | pwg_query($q); |
---|
143 | } |
---|
144 | |
---|
145 | // Create UserAdvManager_Version conf if not already exists |
---|
146 | // -------------------------------------------------------- |
---|
147 | $query = ' |
---|
148 | SELECT param |
---|
149 | FROM '.CONFIG_TABLE.' |
---|
150 | WHERE param = "UserAdvManager_Version" |
---|
151 | ;'; |
---|
152 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
153 | |
---|
154 | if ($count == 0) |
---|
155 | { |
---|
156 | $q = ' |
---|
157 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
158 | VALUES ("UserAdvManager_Version","'.$version.'","UAM version check") |
---|
159 | ;'; |
---|
160 | pwg_query($q); |
---|
161 | } |
---|
162 | |
---|
163 | // Create USER_CONFIRM_MAIL_TABLE |
---|
164 | // ------------------------------ |
---|
165 | $q = " |
---|
166 | CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." ( |
---|
167 | id varchar(50) NOT NULL default '', |
---|
168 | user_id smallint(5) NOT NULL default '0', |
---|
169 | mail_address varchar(255) default NULL, |
---|
170 | status enum('webmaster','admin','normal','generic','guest') default NULL, |
---|
171 | date_check datetime default NULL, |
---|
172 | reminder ENUM('true','false') NULL, |
---|
173 | PRIMARY KEY (id) |
---|
174 | ) |
---|
175 | ENGINE=MyISAM;"; |
---|
176 | pwg_query($q); |
---|
177 | |
---|
178 | // Create USER_LASTVISIT_TABLE |
---|
179 | // --------------------------- |
---|
180 | $q = " |
---|
181 | CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." ( |
---|
182 | user_id SMALLINT(5) NOT NULL DEFAULT '0', |
---|
183 | lastvisit DATETIME NULL DEFAULT NULL, |
---|
184 | reminder ENUM('true','false') NULL, |
---|
185 | PRIMARY KEY (`user_id`) |
---|
186 | ) |
---|
187 | ENGINE=MyISAM;"; |
---|
188 | pwg_query($q); |
---|
189 | |
---|
190 | // Piwigo's native tables modifications for password reset function - Add pwdreset column if not already exists |
---|
191 | // ------------------------------------------------------------------------------------------------------------ |
---|
192 | $query = ' |
---|
193 | SHOW COLUMNS FROM '.USERS_TABLE.' |
---|
194 | LIKE "UAM_pwdreset" |
---|
195 | ;'; |
---|
196 | |
---|
197 | $result = pwg_query($query); |
---|
198 | |
---|
199 | if(!pwg_db_fetch_row($result)) |
---|
200 | { |
---|
201 | $q = ' |
---|
202 | ALTER TABLE '.USERS_TABLE.' |
---|
203 | ADD UAM_pwdreset enum("true","false") |
---|
204 | ;'; |
---|
205 | pwg_query($q); |
---|
206 | } |
---|
207 | |
---|
208 | /* *************************************************************************** */ |
---|
209 | /* **************** END - Database actions and initialization **************** */ |
---|
210 | /* *************************************************************************** */ |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | function plugin_activate() |
---|
215 | { |
---|
216 | global $conf; |
---|
217 | |
---|
218 | /* Cleaning obsolete files */ |
---|
219 | /* *********************** */ |
---|
220 | clean_obsolete_files(); |
---|
221 | |
---|
222 | include_once (UAM_PATH.'include/upgradedb.inc.php'); |
---|
223 | |
---|
224 | /* Check if old version is < 2.15 */ |
---|
225 | /* ****************************** */ |
---|
226 | $query = ' |
---|
227 | SELECT param |
---|
228 | FROM '.CONFIG_TABLE.' |
---|
229 | WHERE param = "nbc_UserAdvManager" |
---|
230 | ;'; |
---|
231 | $count1 = pwg_db_num_rows(pwg_query($query)); |
---|
232 | |
---|
233 | $query = ' |
---|
234 | SELECT * |
---|
235 | FROM '.CONFIG_TABLE.' |
---|
236 | WHERE param = "nbc_UserAdvManager_ConfirmMail" |
---|
237 | ;'; |
---|
238 | $count2 = pwg_db_num_rows(pwg_query($query)); |
---|
239 | |
---|
240 | /* If old params exist an upgrade is needed */ |
---|
241 | /* **************************************** */ |
---|
242 | if ($count1 == 1) |
---|
243 | { |
---|
244 | /* Check for upgrade from 2.10 to 2.11 */ |
---|
245 | /* *********************************** */ |
---|
246 | if ($count1 == 1 and $count2 == 0) |
---|
247 | { |
---|
248 | /* upgrade from branch 2.10 to 2.11 */ |
---|
249 | /* ******************************** */ |
---|
250 | upgrade_210_211(); |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | /* Check for upgrade from 2.11 to 2.12 */ |
---|
255 | /* *********************************** */ |
---|
256 | if (!table_exist(USER_LASTVISIT_TABLE)) |
---|
257 | { |
---|
258 | /* upgrade from branch 2.11 to 2.12 */ |
---|
259 | /* ******************************** */ |
---|
260 | upgrade_211_212(); |
---|
261 | } |
---|
262 | |
---|
263 | |
---|
264 | /* Check for upgrade from 2.12 to 2.13 */ |
---|
265 | /* *********************************** */ |
---|
266 | $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE); |
---|
267 | $nb_fields = mysql_num_fields($fields); |
---|
268 | |
---|
269 | if ($nb_fields < 6) |
---|
270 | { |
---|
271 | /* upgrade from branch 2.12 to 2.13 */ |
---|
272 | /* ******************************** */ |
---|
273 | upgrade_212_213(); |
---|
274 | } |
---|
275 | |
---|
276 | |
---|
277 | /* Serializing conf parameters - Available since 2.14.0 */ |
---|
278 | /* **************************************************** */ |
---|
279 | if (unserialize($conf['nbc_UserAdvManager']) === false) |
---|
280 | { |
---|
281 | /* upgrade from branch 2.13 to 2.14 */ |
---|
282 | /* ******************************** */ |
---|
283 | upgrade_213_214(); |
---|
284 | } |
---|
285 | |
---|
286 | /* upgrade from branch 2.14 to 2.15 */ |
---|
287 | /* ******************************** */ |
---|
288 | upgrade_214_215(); |
---|
289 | } |
---|
290 | |
---|
291 | /* Old version is > 2.15 */ |
---|
292 | /* ********************* */ |
---|
293 | $query = ' |
---|
294 | SELECT param |
---|
295 | FROM '.CONFIG_TABLE.' |
---|
296 | WHERE param = "UserAdvManager_Redir" |
---|
297 | ;'; |
---|
298 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
299 | |
---|
300 | if ($count == 0) |
---|
301 | { |
---|
302 | upgrade_2153_2154(); |
---|
303 | } |
---|
304 | |
---|
305 | /* Check for upgrade from 2.15 to 2.16 */ |
---|
306 | /* *********************************** */ |
---|
307 | $query = ' |
---|
308 | SELECT param |
---|
309 | FROM '.CONFIG_TABLE.' |
---|
310 | WHERE param = "UserAdvManager_Version" |
---|
311 | ;'; |
---|
312 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
313 | |
---|
314 | if ($count == 0) |
---|
315 | { |
---|
316 | /* upgrade from branch 2.15 to 2.16 */ |
---|
317 | /* ******************************** */ |
---|
318 | upgrade_215_2160(); |
---|
319 | } |
---|
320 | |
---|
321 | /* Check database upgrade since version 2.16.0 */ |
---|
322 | /* ******************************************* */ |
---|
323 | if (isset($conf['UserAdvManager_Version'])) |
---|
324 | { |
---|
325 | if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0) |
---|
326 | { |
---|
327 | /* upgrade from branch 2.16 to 2.20 */ |
---|
328 | /* ******************************** */ |
---|
329 | upgrade_216_220(); |
---|
330 | } |
---|
331 | |
---|
332 | if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0) |
---|
333 | { |
---|
334 | /* upgrade from version 2.20.3 to 2.20.4 */ |
---|
335 | /* ************************************* */ |
---|
336 | upgrade_2203_2204(); |
---|
337 | } |
---|
338 | |
---|
339 | if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0) |
---|
340 | { |
---|
341 | /* upgrade from version 2.20.4 to 2.20.7 */ |
---|
342 | /* ************************************* */ |
---|
343 | upgrade_2204_2207(); |
---|
344 | } |
---|
345 | |
---|
346 | if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0) |
---|
347 | { |
---|
348 | /* upgrade from version 2.20.7 to 2.20.8 */ |
---|
349 | /* ************************************* */ |
---|
350 | upgrade_2207_2208(); |
---|
351 | } |
---|
352 | |
---|
353 | if (version_compare($conf['UserAdvManager_Version'], '2.30.0') < 0) |
---|
354 | { |
---|
355 | /* upgrade from version 2.20.8 to 2.30.0 */ |
---|
356 | /* ************************************* */ |
---|
357 | upgrade_2208_2300(); |
---|
358 | } |
---|
359 | } |
---|
360 | |
---|
361 | // Update plugin version number in #_config table and check consistency of #_plugins table |
---|
362 | // --------------------------------------------------------------------------------------- |
---|
363 | UAM_version_update(); |
---|
364 | |
---|
365 | load_conf_from_db('param like \'UserAdvManager\\_%\''); |
---|
366 | } |
---|
367 | |
---|
368 | |
---|
369 | function plugin_uninstall() |
---|
370 | { |
---|
371 | global $conf; |
---|
372 | |
---|
373 | if (isset($conf['UserAdvManager'])) |
---|
374 | { |
---|
375 | $q = ' |
---|
376 | DELETE FROM '.CONFIG_TABLE.' |
---|
377 | WHERE param="UserAdvManager" |
---|
378 | ;'; |
---|
379 | |
---|
380 | pwg_query($q); |
---|
381 | } |
---|
382 | |
---|
383 | if (isset($conf['UserAdvManager_ConfirmMail'])) |
---|
384 | { |
---|
385 | $q = ' |
---|
386 | DELETE FROM '.CONFIG_TABLE.' |
---|
387 | WHERE param="UserAdvManager_ConfirmMail" |
---|
388 | ;'; |
---|
389 | |
---|
390 | pwg_query($q); |
---|
391 | } |
---|
392 | |
---|
393 | if (isset($conf['UserAdvManager_Redir'])) |
---|
394 | { |
---|
395 | $q = ' |
---|
396 | DELETE FROM '.CONFIG_TABLE.' |
---|
397 | WHERE param="UserAdvManager_Redir" |
---|
398 | ;'; |
---|
399 | |
---|
400 | pwg_query($q); |
---|
401 | } |
---|
402 | |
---|
403 | if (isset($conf['UserAdvManager_Version'])) |
---|
404 | { |
---|
405 | $q = ' |
---|
406 | DELETE FROM '.CONFIG_TABLE.' |
---|
407 | WHERE param="UserAdvManager_Version" |
---|
408 | ;'; |
---|
409 | |
---|
410 | pwg_query($q); |
---|
411 | } |
---|
412 | |
---|
413 | $q = ' |
---|
414 | DROP TABLE '.USER_CONFIRM_MAIL_TABLE.' |
---|
415 | ;'; |
---|
416 | pwg_query( $q ); |
---|
417 | |
---|
418 | $q = ' |
---|
419 | DROP TABLE '.USER_LASTVISIT_TABLE.' |
---|
420 | ;'; |
---|
421 | pwg_query( $q ); |
---|
422 | |
---|
423 | $q = ' |
---|
424 | ALTER TABLE '.USERS_TABLE.' |
---|
425 | DROP UAM_pwdreset |
---|
426 | ;'; |
---|
427 | pwg_query($q); |
---|
428 | } |
---|
429 | ?> |
---|