source: extensions/UserAdvManager/trunk/maintain.inc.php @ 22112

Last change on this file since 22112 was 21519, checked in by Eric, 12 years ago

Next version is 2.50.2 :
Bug 2866 fixed - Fatal error message (Fatal error: Call to undefined function switch_lang_to()) when using validation link

  • Property svn:eol-style set to LF
File size: 13.7 KB
Line 
1<?php
2
3if(!defined('UAM_PATH'))
4{
5  define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
6}
7
8include_once (UAM_PATH.'include/constants.php');
9include_once (UAM_PATH.'include/functions.inc.php');
10
11load_language('plugin.lang', UAM_PATH);
12
13
14function plugin_install()
15{
16        global $conf;
17
18/* ****************************************************************** */
19/* **************** BEGIN - Data preparation in vars **************** */
20/* ****************************************************************** */
21
22  // Default global parameters for UserAdvManager conf
23  // -------------------------------------------------
24  $defaultUAM = array(
25    'MAIL_INFO'                   => 'false',
26    'CONFIRM_MAIL'                => 'false',
27    'NO_CONFIRM_GROUP'            => '-1',
28    'VALIDATED_GROUP'             => '-1',
29    'VALIDATED_STATUS'            => '-1',
30    'USERNAME_CHAR'               => 'false',
31    'USERNAME_CHAR_LIST'          => '',
32    'NO_CONFIRM_STATUS'           => '-1',
33    'MAILINFO_TEXT'               => l10n('UAM_Default_InfoMail_Txt'),
34    'CONFIRMMAIL_TEXT'            => l10n('UAM_Default_ConfirmMail_Txt'),
35    'MAILEXCLUSION'               => 'false',
36    'MAILEXCLUSION_LIST'          => '',
37    'PASSWORDENF'                 => 'false',
38    'PASSWORD_SCORE'              => '100',
39    'ADMINPASSWENF'               => 'false',
40    'GHOSTRACKER'                 => 'false',
41    'GHOSTRACKER_DAYLIMIT'        => '10',
42    'GHOSTRACKER_REMINDERTEXT'    => l10n('UAM_Default_GhstReminder_Txt'),
43    'ADDLASTVISIT'                => 'false',
44    'ADMINCONFMAIL'               => 'false',
45    'REDIRTOPROFILE'              => 'false',
46    'GTAUTO'                      => 'false',
47    'GTAUTOMAIL'                  => 'false',
48    'GTAUTODEL'                   => l10n('UAM_Default_GhstDeletion_Txt'),
49    'GTAUTOMAILTEXT'              => l10n('UAM_Default_GhstDemotion_Txt'),
50    'DOWNGRADE_GROUP'             => '-1',
51    'DOWNGRADE_STATUS'            => '-1',
52    'ADMINVALIDATIONMAIL'         => l10n('UAM_Default_AdminValidation_Txt'),
53    'CUSTOMPASSWRETR'             => 'false',
54    'CUSTOMPASSWRETR_TEXT'        => l10n('UAM_Default_PwdRequest_Txt'),
55    'USRAUTO'                     => 'false',
56    'USRAUTODEL'                  => l10n('UAM_Default_ValidationTimeout_Txt'),
57    'USRAUTOMAIL'                 => 'false',
58    'STUFFS'                      => 'false',
59    'HIDEPASSW'                   => 'false',
60    'NO_VALID_LEVEL'              => '-1',
61    'VALID_LEVEL'                 => '-1',
62    'DOWNGRADE_LEVEL'             => '-1',
63    'PWDRESET'                    => 'false',
64    'REJECTCONNECT'               => 'false',
65    'REJECTCONNECT_TEXT'          => l10n('UAM_Default_RejectConnexion_Txt'),
66    'CONFIRMMAIL_SUBJECT'         => l10n('UAM_Default_ConfirmMail_Subject'),
67    'CONFIRMMAIL_REMAIL_SUBJECT'  => l10n('UAM_Default_ConfirmMail_Remail_Subject'),
68    'INFOMAIL_SUBJECT'            => l10n('UAM_Default_InfoMail_Subject'),
69    'GTAUTOMAIL_SUBJECT'          => l10n('UAM_Default_GTAutoMail_Subject'),
70    'GTREMINDER_SUBJECT'          => l10n('UAM_Default_GTReminder_Subject'),
71    'ADMINVALIDATIONMAIL_SUBJECT' => l10n('UAM_Default_AdminValidationMail_Subject')
72  );
73 
74  // Default specific parameters for UserAdvManager ConfirmMail conf
75  // ---------------------------------------------------------------
76  $defaultConfirmMail = array(
77    'CONFIRMMAIL_TIMEOUT'     => 'false',
78    'CONFIRMMAIL_DELAY'       => '5',
79    'CONFIRMMAIL_REMAIL_TXT1' => l10n('UAM_Default_CfmMail_Remail_Txt1'),
80    'CONFIRMMAIL_REMAIL'      => 'false',
81    'CONFIRMMAIL_REMAIL_TXT2' => l10n('UAM_Default_CfmMail_Remail_Txt2'),
82    'CONFIRMMAIL_CUSTOM_TXT1' => l10n('UAM_Default_CfmMail_Custom_Txt1'),
83    'CONFIRMMAIL_CUSTOM_TXT2' => l10n('UAM_Default_CfmMail_Custom_Txt2')
84  );
85 
86  // Set current plugin version in config table
87  // ------------------------------------------
88  $plugin =  PluginInfos(UAM_PATH);
89  $version = $plugin['version'];
90
91/* **************************************************************** */
92/* **************** END - Data preparation in vars **************** */
93/* **************************************************************** */
94
95
96/* ***************************************************************************** */
97/* **************** BEGIN - Database actions and initialization **************** */
98/* ***************************************************************************** */
99
100  // Create UserAdvManager conf if not already exists
101  // ------------------------------------------------
102        $query = '
103SELECT param
104  FROM '.CONFIG_TABLE.'
105WHERE param = "UserAdvManager"
106;';
107  $count = pwg_db_num_rows(pwg_query($query));
108 
109  if ($count == 0)
110  {
111    $q = '
112INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
113VALUES ("UserAdvManager","'.pwg_db_real_escape_string(serialize($defaultUAM)).'","UAM parameters")
114  ;';
115    pwg_query($q);
116  }
117
118  // Create UserAdvManager_ConfirmMail conf if not already exists
119  // ------------------------------------------------------------
120        $query = '
121SELECT param
122  FROM '.CONFIG_TABLE.'
123WHERE param = "UserAdvManager_ConfirmMail"
124;';
125  $count = pwg_db_num_rows(pwg_query($query));
126 
127  if ($count == 0)
128  {
129    $q = '
130INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
131VALUES ("UserAdvManager_ConfirmMail","'.pwg_db_real_escape_string(serialize($defaultConfirmMail)).'","UAM ConfirmMail parameters")
132  ;';
133    pwg_query($q);
134  }
135
136  // Create UserAdvManager_Redir conf if not already exists
137  // ------------------------------------------------------
138        $query = '
139SELECT param
140  FROM '.CONFIG_TABLE.'
141WHERE param = "UserAdvManager_Redir"
142;';
143  $count = pwg_db_num_rows(pwg_query($query));
144 
145  if ($count == 0)
146  {
147    $q = '
148INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
149VALUES ("UserAdvManager_Redir","0","UAM Redirections")
150  ;';
151    pwg_query($q);
152  }
153
154  // Create UserAdvManager_Version conf if not already exists
155  // --------------------------------------------------------
156        $query = '
157SELECT param
158  FROM '.CONFIG_TABLE.'
159WHERE param = "UserAdvManager_Version"
160;';
161  $count = pwg_db_num_rows(pwg_query($query));
162 
163  if ($count == 0)
164  {
165    $q = '
166INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
167VALUES ("UserAdvManager_Version","'.$version.'","UAM version check")
168  ;';
169    pwg_query($q);
170  }
171
172  // Create USER_CONFIRM_MAIL_TABLE
173  // ------------------------------
174        $q = '
175CREATE TABLE IF NOT EXISTS '.USER_CONFIRM_MAIL_TABLE.' (
176  id varchar(50) NOT NULL default "",
177  user_id smallint(5) NOT NULL default "0",
178  mail_address varchar(255) default NULL,
179  status enum("webmaster","admin","normal","generic","guest") default NULL,
180  date_check datetime default NULL,
181  reminder ENUM("true","false") NULL,
182PRIMARY KEY  (id)
183  )
184ENGINE=MyISAM;';
185  pwg_query($q);
186
187  // Create USER_LASTVISIT_TABLE
188  // ---------------------------
189        $q = '
190CREATE TABLE IF NOT EXISTS '.USER_LASTVISIT_TABLE.' (
191  user_id SMALLINT(5) NOT NULL DEFAULT "0",
192  lastvisit DATETIME NULL DEFAULT NULL,
193  reminder ENUM("true","false") NULL,
194PRIMARY KEY (`user_id`)
195  )
196ENGINE=MyISAM;';
197  pwg_query($q);
198
199  // Piwigo's native tables modifications for password reset function - Add pwdreset column if not already exists
200  // ------------------------------------------------------------------------------------------------------------
201  $query = '
202SHOW COLUMNS FROM '.USERS_TABLE.'
203LIKE "UAM_pwdreset"
204;';
205 
206  $result = pwg_query($query);
207
208  if(!pwg_db_fetch_row($result))
209  {
210    $q = '
211ALTER TABLE '.USERS_TABLE.'
212ADD UAM_pwdreset enum("true","false")
213;';
214    pwg_query($q);
215  }
216
217  // Piwigo's native tables modifications for validation status
218  // ----------------------------------------------------------
219  $query = '
220SHOW COLUMNS FROM '.USERS_TABLE.'
221LIKE "UAM_validated"
222;';
223 
224  $result = pwg_query($query);
225
226  if(!pwg_db_fetch_row($result))
227  {
228    $q = '
229ALTER TABLE '.USERS_TABLE.'
230ADD UAM_validated enum("true","false")
231;';
232    pwg_query($q);
233  }
234
235/* *************************************************************************** */
236/* **************** END - Database actions and initialization **************** */
237/* *************************************************************************** */
238}
239
240
241function plugin_activate()
242{
243  global $conf;
244
245/* Cleaning obsolete files */
246/* *********************** */
247  clean_obsolete_files();
248 
249  include_once (UAM_PATH.'include/upgradedb.inc.php');
250
251/* Check if old version is < 2.15 */
252/* ****************************** */
253        $query = '
254SELECT param
255  FROM '.CONFIG_TABLE.'
256WHERE param = "nbc_UserAdvManager"
257;';
258  $count1 = pwg_db_num_rows(pwg_query($query));
259 
260  $query = '
261SELECT *
262  FROM '.CONFIG_TABLE.'
263WHERE param = "nbc_UserAdvManager_ConfirmMail"
264;';
265  $count2 = pwg_db_num_rows(pwg_query($query)); 
266
267/* If old params exist an upgrade is needed */
268/* **************************************** */
269  if ($count1 == 1)
270  {
271/* Check for upgrade from 2.10 to 2.11 */
272/* *********************************** */
273    if ($count1 == 1 and $count2 == 0)
274    {
275    /* upgrade from branch 2.10 to 2.11 */
276    /* ******************************** */
277      upgrade_210_211();
278    }
279
280
281/* Check for upgrade from 2.11 to 2.12 */
282/* *********************************** */
283    if (!table_exist(USER_LASTVISIT_TABLE))
284    {
285    /* upgrade from branch 2.11 to 2.12 */
286    /* ******************************** */
287                upgrade_211_212();
288    }
289
290
291/* Check for upgrade from 2.12 to 2.13 */
292/* *********************************** */
293    $fields = pwg_query('SHOW COLUMNS FROM '.USER_CONFIRM_MAIL_TABLE.';');
294    $nb_fields = pwg_db_num_rows($fields);
295
296    if ($nb_fields < 6)
297    {
298    /* upgrade from branch 2.12 to 2.13 */
299    /* ******************************** */
300      upgrade_212_213();
301    }
302
303
304/* Serializing conf parameters - Available since 2.14.0 */
305/* **************************************************** */
306    if (unserialize($conf['nbc_UserAdvManager']) === false)
307    {
308    /* upgrade from branch 2.13 to 2.14 */
309    /* ******************************** */
310      upgrade_213_214();
311    }
312   
313    /* upgrade from branch 2.14 to 2.15 */
314    /* ******************************** */
315      upgrade_214_215();
316  }
317
318/* Old version is > 2.15 */
319/* ********************* */
320        $query = '
321SELECT param
322  FROM '.CONFIG_TABLE.'
323WHERE param = "UserAdvManager_Redir"
324;';
325  $count = pwg_db_num_rows(pwg_query($query));
326 
327  if ($count == 0)
328  {
329    upgrade_2153_2154();
330  }
331
332/* Check for upgrade from 2.15 to 2.16 */
333/* *********************************** */
334        $query = '
335SELECT param
336  FROM '.CONFIG_TABLE.'
337WHERE param = "UserAdvManager_Version"
338;';
339  $count = pwg_db_num_rows(pwg_query($query));
340 
341  if ($count == 0)
342  {
343    /* upgrade from branch 2.15 to 2.16 */
344    /* ******************************** */
345    upgrade_215_2160();
346  }
347
348/* Check database upgrade since version 2.16.0 */
349/* ******************************************* */
350  if (isset($conf['UserAdvManager_Version']))
351  {
352    if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0)
353    {
354    /* upgrade from branch 2.16 to 2.20 */
355    /* ******************************** */
356      upgrade_216_220();
357    }
358   
359    if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0)
360    {
361    /* upgrade from version 2.20.3 to 2.20.4 */
362    /* ************************************* */
363      upgrade_2203_2204();
364    }
365   
366    if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0)
367    {
368    /* upgrade from version 2.20.4 to 2.20.7 */
369    /* ************************************* */
370      upgrade_2204_2207();
371    }
372
373    if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0)
374    {
375    /* upgrade from version 2.20.7 to 2.20.8 */
376    /* ************************************* */
377      upgrade_2207_2208();
378    }
379
380    if (version_compare($conf['UserAdvManager_Version'], '2.30.0') < 0)
381    {
382    /* upgrade from version 2.20.8 to 2.30.0 */
383    /* ************************************* */
384      upgrade_2208_2300();
385    }
386
387    if (version_compare($conf['UserAdvManager_Version'], '2.30.2') < 0)
388    {
389    /* upgrade from version 2.30.x to 2.30.2 */
390    /* ************************************* */
391      upgrade_2300_2302();
392    }
393
394    if (version_compare($conf['UserAdvManager_Version'], '2.40.0') < 0)
395    {
396    /* upgrade from version 2.30.x to 2.40.0 */
397    /* ************************************* */
398      upgrade_2300_2400();
399    }
400
401    if (version_compare($conf['UserAdvManager_Version'], '2.41.0') < 0)
402    {
403    /* upgrade from version 2.40.x to 2.41.0 */
404    /* ************************************* */
405      upgrade_2400_2410();
406    }
407
408    if (version_compare($conf['UserAdvManager_Version'], '2.50.0') < 0)
409    {
410    /* upgrade from version 2.41.x to 2.50.0 */
411    /* ************************************* */
412      upgrade_2410_2500();
413    }
414  }
415
416  // Update plugin version number in #_config table and check consistency of #_plugins table
417  // ---------------------------------------------------------------------------------------
418  UAM_version_update();
419
420  load_conf_from_db('param like \'UserAdvManager\\_%\'');
421}
422
423
424function plugin_uninstall()
425{
426  global $conf;
427
428  if (isset($conf['UserAdvManager']))
429  {
430    $q = '
431DELETE FROM '.CONFIG_TABLE.'
432WHERE param="UserAdvManager"
433;';
434
435    pwg_query($q);
436  }
437
438  if (isset($conf['UserAdvManager_ConfirmMail']))
439  {
440    $q = '
441DELETE FROM '.CONFIG_TABLE.'
442WHERE param="UserAdvManager_ConfirmMail"
443;';
444
445    pwg_query($q);
446  }
447
448  if (isset($conf['UserAdvManager_Redir']))
449  {
450    $q = '
451DELETE FROM '.CONFIG_TABLE.'
452WHERE param="UserAdvManager_Redir"
453;';
454
455    pwg_query($q);
456  }
457
458  if (isset($conf['UserAdvManager_Version']))
459  {
460    $q = '
461DELETE FROM '.CONFIG_TABLE.'
462WHERE param="UserAdvManager_Version"
463;';
464
465    pwg_query($q);
466  }
467
468  $q = '
469DROP TABLE '.USER_CONFIRM_MAIL_TABLE.'
470;';
471  pwg_query( $q );
472
473  $q = '
474DROP TABLE '.USER_LASTVISIT_TABLE.'
475;';
476  pwg_query( $q );
477
478  $q = '
479ALTER TABLE '.USERS_TABLE.'
480DROP UAM_pwdreset
481;';
482  pwg_query($q);
483
484  $q = '
485ALTER TABLE '.USERS_TABLE.'
486DROP UAM_validated
487;';
488  pwg_query($q);
489}
490?>
Note: See TracBrowser for help on using the repository browser.