source: extensions/UserAdvManager/branches/2.50/maintain.inc.php @ 24213

Last change on this file since 24213 was 24213, checked in by Eric, 11 years ago

r24212 merged from trunk to branch 2.50Next version is 2.5.14:
Evolution 2951 fixed - Add an option to add the gallery URL at the end of emails sent by UAM
Update ru_RU, thanks to : Konve
Update lv_LV, thanks to : agrisans
Add pt_PT, thanks to : ANO

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