source: extensions/UserAdvManager/branches/2.7/maintain.inc.php @ 32099

Last change on this file since 32099 was 30777, checked in by Eric, 10 years ago

merge r30776 from trunk to branch 2.7 (branch 2.6 will no longer be updated):
New feature - Allow admins to receive a copy of all emails sent by the plugin

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