source: extensions/NBC_UserAdvManager/branches/2.15/maintain.inc.php @ 5634

Last change on this file since 5634 was 5634, checked in by Eric, 14 years ago

[NBC_UserAdvManager]

Merged from trunk to branches/2.15

  • Property svn:eol-style set to LF
File size: 11.6 KB
RevLine 
[3742]1<?php
2
[5181]3if(!defined("UAM_PATH")) define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
[5593]4if (!defined('UAM_ROOT'))
5{
6  define('UAM_ROOT', dirname(__FILE__).'/');
[5056]7}
[3742]8
[5181]9include_once (UAM_PATH.'include/constants.php');
10include_once (UAM_PATH.'include/functions.inc.php');
[3742]11
[5064]12
[3742]13function plugin_install()
14{
[3872]15        global $conf;
16       
[5056]17  $default1 = array('false','false','false',-1,-1,-1,'false','false','',-1,'','','false','','false',100,'false','false',10,'Hello.
18       
19This is a reminder because a very long time passed since your last visit on our gallery. If you do not want anymore to use your access account, please let us know by replying to this email. Your account will be deleted.
20
21On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
22
23Best regards,
24
[5064]25The admin of the gallery.','false','false');
[5056]26
[3742]27  $q = '
[4143]28INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
[5181]29VALUES ("UserAdvManager","'.addslashes(serialize($default1)).'","UAM parameters")
[5056]30  ;';
31  pwg_query($q);
[4143]32
33
[5056]34  $default2 = array('false',5,'Hello.
35               
36This is a reminder message because you registered on our gallery but you do not validate your registration and your validation key has expired. To still allow you to access to our gallery, your validation period has been reset. You have again 5 days to validate your registration.
37
38Note: After this period, your account will be permanently deleted.','false','Hello.
39
40This is a reminder message because you registered on our gallery but you do not validate your registration and your validation key will expire. To allow you access to our gallery, you have 2 days to confirm your registration by clicking on the link in the message you should have received when you registered.
41
[5181]42Note: After this period, your account will be permanently deleted.','Thank you to have confirmed your email address and your registration on the gallery. Have fun !','Your activation key is incorrect or expired or you have already validated your account, please contact the webmaster to fix this problem.');
[5056]43
[3742]44  $q = '
[4143]45INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
[5181]46VALUES ("UserAdvManager_ConfirmMail","'.addslashes(serialize($default2)).'","UAM ConfirmMail parameters")
[5056]47  ;';
48  pwg_query($q);
49
50
[3742]51        $q = "
[4143]52CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
53  id varchar(50) NOT NULL default '',
54  user_id smallint(5) NOT NULL default '0',
55  mail_address varchar(255) default NULL,
56  status enum('webmaster','admin','normal','generic','guest') default NULL,
57  date_check datetime default NULL,
[4380]58  reminder ENUM('true','false') NULL,
[4143]59PRIMARY KEY  (id)
60  )
61;";
[3742]62  pwg_query($q);
[4135]63
64        $q = "
[4143]65CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
66  user_id SMALLINT(5) NOT NULL DEFAULT '0',
67  lastvisit DATETIME NULL DEFAULT NULL,
68  reminder ENUM('true','false') NULL,
69PRIMARY KEY (`user_id`)
70  )
71;";
[4135]72  pwg_query($q);
[3742]73}
74
[5064]75
[3872]76function plugin_activate()
77{
[5064]78  global $conf;
[5056]79
[4952]80/* Cleaning obsolete files */
[5064]81/* *********************** */
82  clean_obsolete_files();
[5056]83
[5593]84/* Check if it's a blank installation */
85/* ********************************** */
86        $query = '
87SELECT param
88  FROM '.CONFIG_TABLE.'
89WHERE param = "nbc_UserAdvManager_ConfirmMail"
90;';
[5634]91  $count1 = pwg_db_num_rows(pwg_query($query));
[5593]92 
93        $query1 = '
94SELECT param
95  FROM '.CONFIG_TABLE.'
96WHERE param = "nbc_UserAdvManager_ConfirmMail"
97;';
[5634]98  $count2 = pwg_db_num_rows(pwg_query($query1));
[5056]99
[5593]100/* If old params exist an upgrade is needed */
101/* **************************************** */
102  if ($count1 == 1 or $count2 == 1)
103  {
[4380]104/* Check for upgrade from 2.10 to 2.11 */
[5064]105/* *********************************** */
[5593]106    $query = '
[4143]107SELECT *
[4159]108  FROM '.CONFIG_TABLE.'
[4143]109WHERE param = "nbc_UserAdvManager_ConfirmMail"
110;';
[5634]111    $count = pwg_db_num_rows(pwg_query($query)); 
[3872]112 
[5593]113    if ($count == 0)
114    {
115    /* upgrade from branch 2.10 to 2.11 */
116    /* ******************************** */
117      upgrade_210();
118    }
[4135]119
[4380]120
121/* Check for upgrade from 2.11 to 2.12 */
[5064]122/* *********************************** */
[5593]123    if (!table_exist(USER_LASTVISIT_TABLE))
124    {
125    /* upgrade from branch 2.11 to 2.12 */
126    /* ******************************** */
127                upgrade_211();
128    }
[4380]129
130
131/* Check for upgrade from 2.12 to 2.13 */
[5064]132/* *********************************** */
[5593]133    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
134    $nb_fields = mysql_num_fields($fields); 
[4380]135
[5593]136//  $query = '
137//SELECT *
138//FROM '.USER_CONFIRM_MAIL_TABLE.'
139//;';
140
141//  $result = pwg_query($query);
[4380]142       
[5593]143//      $numfields = mysql_num_fields($result);
[4380]144
[5593]145    if ($nb_fields < 6)
146    {
147    /* upgrade from branch 2.12 to 2.13 */
148    /* ******************************** */
149      upgrade_212();
150    }
[5056]151
152
[5064]153/* Serializing conf parameters - Available since 2.14.0 */
154/* **************************************************** */
[5593]155    if (unserialize($conf['nbc_UserAdvManager']) === false)
156    {
157    /* upgrade from branch 2.13 to 2.14 */
158    /* ******************************** */
159      upgrade_213();
160    }
161 
[5181]162
163/* Check for upgrade from 2.14.1 to 2.14.2 */
164/* *************************************** */
[5593]165        $query1 = '
[5181]166SELECT param
167  FROM '.CONFIG_TABLE.'
[5593]168WHERE param = "nbc_UserAdvManager"
[5181]169;';
[5593]170    $count1 = mysql_num_rows(pwg_query($query1));
[5181]171 
[5593]172    $query1 = '
[5181]173SELECT param
174  FROM '.CONFIG_TABLE.'
175WHERE param = "nbc_UserAdvManager_ConfirmMail"
176;';
[5593]177    $count2 = mysql_num_rows(pwg_query($query1)); 
[5181]178 
[5593]179    if ($count1 == 1 or $count2 == 1)
180    {
181    /* upgrade from branch 2.14.1 to 2.14.2 */
182    /* ************************************ */
183      upgrade_214_1();
184    }
185  }
[3872]186}
[3742]187
[4135]188
[3742]189function plugin_uninstall()
190{
191  global $conf;
192
[5181]193  if (isset($conf['UserAdvManager']))
[3742]194  {
195    $q = '
[4143]196DELETE FROM '.CONFIG_TABLE.'
[5181]197WHERE param="UserAdvManager"
[4143]198;';
[3742]199
200    pwg_query($q);
201  }
202
[5181]203  if (isset($conf['UserAdvManager_ConfirmMail']))
[3881]204  {
205    $q = '
[4143]206DELETE FROM '.CONFIG_TABLE.'
[5181]207WHERE param="UserAdvManager_ConfirmMail"
[4143]208;';
[3742]209
[3881]210    pwg_query($q);
211  }
212
[3742]213  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
214  pwg_query( $q );
[4135]215
216  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
217  pwg_query( $q );
[3742]218}
[3872]219
[4380]220
[5064]221// +----------------------------------------------------------+
222// |       Upgrading database from old plugin versions        |
223// +----------------------------------------------------------+
224
[4380]225/* upgrade from branch 2.10 to 2.11 */
[5064]226/* ******************************** */
[4061]227function upgrade_210()
[3872]228{
229        global $conf;
230         
231  $q = '
[4143]232INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
233VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello.
[3881]234               
235This is a reminder message because you registered on our gallery but you do not validate your registration and your validation key has expired. To still allow you to access to our gallery, your validation period has been reset. You have again 5 days to validate your registration.
[3872]236
[3881]237Note: After this period, your account will be permanently deleted.;false;Hello.
[3872]238
[3881]239This is a reminder message because you registered on our gallery but you do not validate your registration and your validation key will expire. To allow you access to our gallery, you have 2 days to confirm your registration by clicking on the link in the message you should have received when you registered.
[3872]240
241Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail")
242  ;';
243  pwg_query($q);
[4135]244
[4380]245  upgrade_211();
[3872]246}
[4135]247
[4380]248
249/* upgrade from branch 2.11 to 2.12 */
[5064]250/* ******************************** */
[4135]251function upgrade_211()
252{
253        global $conf;
254
[5056]255  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
[4135]256
[5056]257  if ((!isset($conf_UAM[14]) and !isset($conf_UAM[15])) and !isset($conf_UAM[16]) and !isset($conf_UAM[17]))
[4135]258  {
[5056]259    $upgrade_UAM = $conf_UAM[0].';'.$conf_UAM[1].';'.$conf_UAM[2].';'.$conf_UAM[3].';'.$conf_UAM[4].';'.$conf_UAM[5].';'.$conf_UAM[6].';'.$conf_UAM[7].';'.$conf_UAM[8].';'.$conf_UAM[9].';'.$conf_UAM[10].';'.$conf_UAM[11].';'.$conf_UAM[12].';'.$conf_UAM[13].';false;100;false;false;10;Hello.
[4143]260       
261This is a reminder because a very long time passed since your last visit on our gallery. If you do not want anymore to use your access account, please let us know by replying to this email. Your account will be deleted.
262
263On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
264
265Best regards,
266
267The admin of the gallery.';
[4135]268               
269                $query = '
[4143]270UPDATE '.CONFIG_TABLE.'
[5056]271SET value="'.$upgrade_UAM.'"
[4143]272WHERE param="nbc_UserAdvManager"
273LIMIT 1
274;';
[4135]275                pwg_query($query);
276  }
277 
278        $q = "
[4143]279CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
280  user_id SMALLINT(5) NOT NULL DEFAULT '0',
281  lastvisit DATETIME NULL DEFAULT NULL,
282  reminder ENUM('true','false') NULL,
283PRIMARY KEY (`user_id`)
284  )
285;";
[4135]286  pwg_query($q);
[4380]287
288  upgrade_212();
[4135]289}
[4380]290
291
292/* upgrade from branch 2.12 to 2.13 */
[5064]293/* ******************************** */
[4380]294function upgrade_212()
295{
296/* Create missing table */
297  $query = "
298ALTER TABLE ".USER_CONFIRM_MAIL_TABLE."
299ADD reminder ENUM('true', 'false') NULL DEFAULT NULL
300;";
301 
302  pwg_query($query);
303
304/* Upgrade plugin configuration */
305        global $conf;
306
[5056]307  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
[4380]308
[5056]309  if ((!isset($conf_UAM[20])))
[4380]310  {
[5056]311    $upgrade_UAM = $conf_UAM[0].';'.$conf_UAM[1].';'.$conf_UAM[2].';'.$conf_UAM[3].';'.$conf_UAM[4].';'.$conf_UAM[5].';'.$conf_UAM[6].';'.$conf_UAM[7].';'.$conf_UAM[8].';'.$conf_UAM[9].';'.$conf_UAM[10].';'.$conf_UAM[11].';'.$conf_UAM[12].';'.$conf_UAM[13].';'.$conf_UAM[14].';'.$conf_UAM[15].';'.$conf_UAM[16].';'.$conf_UAM[17].';'.$conf_UAM[18].';'.$conf_UAM[19].';false';
[4380]312               
313                $query = '
314UPDATE '.CONFIG_TABLE.'
[5056]315SET value="'.$upgrade_UAM.'"
[4380]316WHERE param="nbc_UserAdvManager"
317LIMIT 1
318;';
319                pwg_query($query);
[5064]320   
321    upgrade_213();
[4380]322  }
323}
[4952]324
[5064]325
326/* upgrade from branch 2.13 to 2.14 */
327/* ******************************** */
328function upgrade_213()
[4952]329{
[5084]330        global $conf;
331 
332  $conf_UAM = explode(';', $conf['nbc_UserAdvManager']);
[5064]333
[5086]334  $upgrade_UAM = array($conf_UAM[0],$conf_UAM[1],$conf_UAM[2],$conf_UAM[3],$conf_UAM[4],$conf_UAM[5],$conf_UAM[6],$conf_UAM[7],$conf_UAM[8],$conf_UAM[9],$conf_UAM[10],$conf_UAM[11],$conf_UAM[12],$conf_UAM[13],$conf_UAM[14],$conf_UAM[15],$conf_UAM[16],$conf_UAM[17],$conf_UAM[18],$conf_UAM[19],$conf_UAM[20],'false');
[5084]335
[5064]336  $query = '
337UPDATE '.CONFIG_TABLE.'
[5084]338  SET value = "'.addslashes(serialize($upgrade_UAM)).'"
[5064]339  WHERE param = "nbc_UserAdvManager"
340;';
341  pwg_query($query);
342 
343  if (unserialize($conf['nbc_UserAdvManager_ConfirmMail']) === false)
344  {
345    $data = explode(';', $conf['nbc_UserAdvManager_ConfirmMail']);
346
347    $query = '
348UPDATE '.CONFIG_TABLE.'
349  SET value = "'.addslashes(serialize($data)).'"
350  WHERE param = "nbc_UserAdvManager_ConfirmMail"
351;';
352    pwg_query($query);
[5181]353   
354    upgrade_214_1();
[5064]355  }
[4952]356}
[5181]357
358function upgrade_214_1()
359{
360  global $conf;
361
362/* Changing parameter name */
363  $q = '
364UPDATE '.CONFIG_TABLE.'
365SET param = "UserAdvManager"
366WHERE param = "nbc_UserAdvManager"
367;';
368  pwg_query($q);
369 
370  $q = '
371UPDATE '.CONFIG_TABLE.'
372SET param = "UserAdvManager_ConfirmMail"
373WHERE param = "nbc_UserAdvManager_ConfirmMail"
374;';
375  pwg_query($q);
376
377/* Upgrading ConfirmMail options */
[5593]378  $query = '
379SELECT value
380  FROM '.CONFIG_TABLE.'
381WHERE param = "UserAdvManager_ConfirmMail"
382;';
[5181]383
[5593]384  $result = pwg_query($query);
385  $conf_UAM_ConfirmMail = pwg_db_fetch_assoc($result);
386   
387  $conf_ConfirmMail = unserialize($conf_UAM_ConfirmMail['value']);
388 
389  $conf_ConfirmMail[5] ='Thank you to have confirmed your email address and your registration on the gallery. Have fun !';
390  $conf_ConfirmMail[6] ='Your activation key is incorrect or expired or you have already validated your account, please contact the webmaster to fix this problem.';
391 
392  $update_conf = serialize($conf_ConfirmMail);
393   
394  $query = '
395      UPDATE '.CONFIG_TABLE.'
396                        SET value="'.addslashes($update_conf).'"
397                        WHERE param="UserAdvManager_ConfirmMail"
398                        LIMIT 1
399                ;';
[5181]400
[5593]401                pwg_query($query);
[5181]402}
[3742]403?>
Note: See TracBrowser for help on using the repository browser.