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

Revision 5634, 11.6 KB checked in by Eric, 10 years ago (diff)

[NBC_UserAdvManager]

Merged from trunk to branches/2.15

  • Property svn:eol-style set to LF
Line 
1<?php
2
3if(!defined("UAM_PATH")) define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
4if (!defined('UAM_ROOT'))
5{
6  define('UAM_ROOT', dirname(__FILE__).'/');
7}
8
9include_once (UAM_PATH.'include/constants.php');
10include_once (UAM_PATH.'include/functions.inc.php');
11
12
13function plugin_install()
14{
15        global $conf;
16       
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
25The admin of the gallery.','false','false');
26
27  $q = '
28INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
29VALUES ("UserAdvManager","'.addslashes(serialize($default1)).'","UAM parameters")
30  ;';
31  pwg_query($q);
32
33
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
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.');
43
44  $q = '
45INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
46VALUES ("UserAdvManager_ConfirmMail","'.addslashes(serialize($default2)).'","UAM ConfirmMail parameters")
47  ;';
48  pwg_query($q);
49
50
51        $q = "
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,
58  reminder ENUM('true','false') NULL,
59PRIMARY KEY  (id)
60  )
61;";
62  pwg_query($q);
63
64        $q = "
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;";
72  pwg_query($q);
73}
74
75
76function plugin_activate()
77{
78  global $conf;
79
80/* Cleaning obsolete files */
81/* *********************** */
82  clean_obsolete_files();
83
84/* Check if it's a blank installation */
85/* ********************************** */
86        $query = '
87SELECT param
88  FROM '.CONFIG_TABLE.'
89WHERE param = "nbc_UserAdvManager_ConfirmMail"
90;';
91  $count1 = pwg_db_num_rows(pwg_query($query));
92 
93        $query1 = '
94SELECT param
95  FROM '.CONFIG_TABLE.'
96WHERE param = "nbc_UserAdvManager_ConfirmMail"
97;';
98  $count2 = pwg_db_num_rows(pwg_query($query1));
99
100/* If old params exist an upgrade is needed */
101/* **************************************** */
102  if ($count1 == 1 or $count2 == 1)
103  {
104/* Check for upgrade from 2.10 to 2.11 */
105/* *********************************** */
106    $query = '
107SELECT *
108  FROM '.CONFIG_TABLE.'
109WHERE param = "nbc_UserAdvManager_ConfirmMail"
110;';
111    $count = pwg_db_num_rows(pwg_query($query)); 
112 
113    if ($count == 0)
114    {
115    /* upgrade from branch 2.10 to 2.11 */
116    /* ******************************** */
117      upgrade_210();
118    }
119
120
121/* Check for upgrade from 2.11 to 2.12 */
122/* *********************************** */
123    if (!table_exist(USER_LASTVISIT_TABLE))
124    {
125    /* upgrade from branch 2.11 to 2.12 */
126    /* ******************************** */
127                upgrade_211();
128    }
129
130
131/* Check for upgrade from 2.12 to 2.13 */
132/* *********************************** */
133    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
134    $nb_fields = mysql_num_fields($fields); 
135
136//  $query = '
137//SELECT *
138//FROM '.USER_CONFIRM_MAIL_TABLE.'
139//;';
140
141//  $result = pwg_query($query);
142       
143//      $numfields = mysql_num_fields($result);
144
145    if ($nb_fields < 6)
146    {
147    /* upgrade from branch 2.12 to 2.13 */
148    /* ******************************** */
149      upgrade_212();
150    }
151
152
153/* Serializing conf parameters - Available since 2.14.0 */
154/* **************************************************** */
155    if (unserialize($conf['nbc_UserAdvManager']) === false)
156    {
157    /* upgrade from branch 2.13 to 2.14 */
158    /* ******************************** */
159      upgrade_213();
160    }
161 
162
163/* Check for upgrade from 2.14.1 to 2.14.2 */
164/* *************************************** */
165        $query1 = '
166SELECT param
167  FROM '.CONFIG_TABLE.'
168WHERE param = "nbc_UserAdvManager"
169;';
170    $count1 = mysql_num_rows(pwg_query($query1));
171 
172    $query1 = '
173SELECT param
174  FROM '.CONFIG_TABLE.'
175WHERE param = "nbc_UserAdvManager_ConfirmMail"
176;';
177    $count2 = mysql_num_rows(pwg_query($query1)); 
178 
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  }
186}
187
188
189function plugin_uninstall()
190{
191  global $conf;
192
193  if (isset($conf['UserAdvManager']))
194  {
195    $q = '
196DELETE FROM '.CONFIG_TABLE.'
197WHERE param="UserAdvManager"
198;';
199
200    pwg_query($q);
201  }
202
203  if (isset($conf['UserAdvManager_ConfirmMail']))
204  {
205    $q = '
206DELETE FROM '.CONFIG_TABLE.'
207WHERE param="UserAdvManager_ConfirmMail"
208;';
209
210    pwg_query($q);
211  }
212
213  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
214  pwg_query( $q );
215
216  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
217  pwg_query( $q );
218}
219
220
221// +----------------------------------------------------------+
222// |       Upgrading database from old plugin versions        |
223// +----------------------------------------------------------+
224
225/* upgrade from branch 2.10 to 2.11 */
226/* ******************************** */
227function upgrade_210()
228{
229        global $conf;
230         
231  $q = '
232INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
233VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello.
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.
236
237Note: After this period, your account will be permanently deleted.;false;Hello.
238
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.
240
241Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail")
242  ;';
243  pwg_query($q);
244
245  upgrade_211();
246}
247
248
249/* upgrade from branch 2.11 to 2.12 */
250/* ******************************** */
251function upgrade_211()
252{
253        global $conf;
254
255  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
256
257  if ((!isset($conf_UAM[14]) and !isset($conf_UAM[15])) and !isset($conf_UAM[16]) and !isset($conf_UAM[17]))
258  {
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.
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.';
268               
269                $query = '
270UPDATE '.CONFIG_TABLE.'
271SET value="'.$upgrade_UAM.'"
272WHERE param="nbc_UserAdvManager"
273LIMIT 1
274;';
275                pwg_query($query);
276  }
277 
278        $q = "
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;";
286  pwg_query($q);
287
288  upgrade_212();
289}
290
291
292/* upgrade from branch 2.12 to 2.13 */
293/* ******************************** */
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
307  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
308
309  if ((!isset($conf_UAM[20])))
310  {
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';
312               
313                $query = '
314UPDATE '.CONFIG_TABLE.'
315SET value="'.$upgrade_UAM.'"
316WHERE param="nbc_UserAdvManager"
317LIMIT 1
318;';
319                pwg_query($query);
320   
321    upgrade_213();
322  }
323}
324
325
326/* upgrade from branch 2.13 to 2.14 */
327/* ******************************** */
328function upgrade_213()
329{
330        global $conf;
331 
332  $conf_UAM = explode(';', $conf['nbc_UserAdvManager']);
333
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');
335
336  $query = '
337UPDATE '.CONFIG_TABLE.'
338  SET value = "'.addslashes(serialize($upgrade_UAM)).'"
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);
353   
354    upgrade_214_1();
355  }
356}
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 */
378  $query = '
379SELECT value
380  FROM '.CONFIG_TABLE.'
381WHERE param = "UserAdvManager_ConfirmMail"
382;';
383
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                ;';
400
401                pwg_query($query);
402}
403?>
Note: See TracBrowser for help on using the repository browser.