source: extensions/NBC_UserAdvManager/trunk/maintain.inc.php @ 5056

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

[NBC_UserAdvManager] Pre-2.13.5

  • Bug 1465 fixed : Plugin data are now serialized
  • Code simplification : Variables improved
  • Files renamed : functions.inc.php and UAM_admin.php
  • Update of obsolete.list (There is a bug on obsolete fils deletion)
  • Property svn:eol-style set to LF
File size: 9.4 KB
Line 
1<?php
2
3if(!defined("NBC_UAM_PATH")) define('NBC_UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
4if (!defined('NBC_UAM_ROOT')) {
5  define('NBC_UAM_ROOT',     dirname(__FILE__).'/');
6}
7
8include_once (NBC_UAM_PATH.'include/constants.php');
9include_once (NBC_UAM_PATH.'include/functions.inc.php');
10
11function plugin_install()
12{
13        global $conf;
14       
15  $default1 = array('false','false','false',-1,-1,-1,'false','false','',-1,'','','false','','false',100,'false','false',10,'Hello.
16       
17This 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.
18
19On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
20
21Best regards,
22
23The admin of the gallery.','false');
24
25  $q = '
26INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
27VALUES ("nbc_UserAdvManager","'.addslashes(serialize($default1)).'","NBC_UAM parameters")
28  ;';
29  pwg_query($q);
30 
31/*  $q = '
32INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
33VALUES ("nbc_UserAdvManager","false;false;false;-1;-1;-1;false;false;;-1;;;false;;false;100;false;false;10;Hello.
34       
35This 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.
36
37On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
38
39Best regards,
40
41The admin of the gallery.;false","Parametres du plugin nbc UserAdvManager")
42  ;';
43  pwg_query($q);*/
44
45  $default2 = array('false',5,'Hello.
46               
47This 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.
48
49Note: After this period, your account will be permanently deleted.','false','Hello.
50
51This 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.
52
53Note: After this period, your account will be permanently deleted.');
54
55  $q = '
56INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
57VALUES ("nbc_UserAdvManager_ConfirmMail","'.addslashes(serialize($default2)).'","NBC_UAM ConfirmMail parameters")
58  ;';
59  pwg_query($q);
60
61
62/*  $q = '
63INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
64VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello.
65               
66This 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.
67
68Note: After this period, your account will be permanently deleted.;false;Hello.
69
70This 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.
71
72Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail")
73  ;';
74  pwg_query($q);*/
75
76        $q = "
77CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
78  id varchar(50) NOT NULL default '',
79  user_id smallint(5) NOT NULL default '0',
80  mail_address varchar(255) default NULL,
81  status enum('webmaster','admin','normal','generic','guest') default NULL,
82  date_check datetime default NULL,
83  reminder ENUM('true','false') NULL,
84PRIMARY KEY  (id)
85  )
86;";
87  pwg_query($q);
88
89        $q = "
90CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
91  user_id SMALLINT(5) NOT NULL DEFAULT '0',
92  lastvisit DATETIME NULL DEFAULT NULL,
93  reminder ENUM('true','false') NULL,
94PRIMARY KEY (`user_id`)
95  )
96;";
97  pwg_query($q);
98}
99
100function plugin_activate()
101{
102          global $conf;
103
104/* Cleaning obsolete files */
105    update_files($plugin_id);
106
107
108/* Check for upgrade from 2.10 to 2.11 */
109          $query = '
110SELECT *
111  FROM '.CONFIG_TABLE.'
112WHERE param = "nbc_UserAdvManager_ConfirmMail"
113;';
114  $count = mysql_num_rows(pwg_query($query)); 
115 
116        if ($count == 0)
117        {
118         /* upgrade from branch 2.10 to 2.11 */
119                upgrade_210();
120        }
121
122
123/* Check for upgrade from 2.11 to 2.12 */
124  if (!table_exist(USER_LASTVISIT_TABLE))
125  {
126    /* upgrade from branch 2.11 to 2.12 */
127                upgrade_211();
128  }
129
130
131/* Check for upgrade from 2.12 to 2.13 */
132  $query = '
133SELECT *
134FROM '.USER_CONFIRM_MAIL_TABLE.'
135;';
136
137  $result = pwg_query($query);
138       
139        $numfields = mysql_num_fields($result);
140
141  if ($numfields < 6)
142  {
143    /* upgrade from branch 2.12 to 2.13 */
144    upgrade_212();
145  }
146
147
148/* Serializing conf parameters - Available since 2.13.5 */
149  if (unserialize($conf['nbc_UserAdvManager']) === false)
150  {
151    $data = explode(';', $conf['nbc_UserAdvManager']);
152
153    $query = '
154UPDATE '.CONFIG_TABLE.'
155  SET value = "'.addslashes(serialize($data)).'"
156  WHERE param = "nbc_UserAdvManager"
157;';
158    pwg_query($query);
159  }
160 
161  if (unserialize($conf['nbc_UserAdvManager_ConfirmMail']) === false)
162  {
163    $data = explode(';', $conf['nbc_UserAdvManager_ConfirmMail']);
164
165    $query = '
166UPDATE '.CONFIG_TABLE.'
167  SET value = "'.addslashes(serialize($data)).'"
168  WHERE param = "nbc_UserAdvManager_ConfirmMail"
169;';
170    pwg_query($query);
171  }
172}
173
174
175function plugin_uninstall()
176{
177  global $conf;
178
179  if (isset($conf['nbc_UserAdvManager']))
180  {
181    $q = '
182DELETE FROM '.CONFIG_TABLE.'
183WHERE param="nbc_UserAdvManager"
184;';
185
186    pwg_query($q);
187  }
188
189  if (isset($conf['nbc_UserAdvManager_ConfirmMail']))
190  {
191    $q = '
192DELETE FROM '.CONFIG_TABLE.'
193WHERE param="nbc_UserAdvManager_ConfirmMail"
194;';
195
196    pwg_query($q);
197  }
198
199  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
200  pwg_query( $q );
201
202  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
203  pwg_query( $q );
204}
205
206
207/* upgrade from branch 2.10 to 2.11 */
208function upgrade_210()
209{
210        global $conf;
211         
212  $q = '
213INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
214VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello.
215               
216This 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.
217
218Note: After this period, your account will be permanently deleted.;false;Hello.
219
220This 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.
221
222Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail")
223  ;';
224  pwg_query($q);
225
226  upgrade_211();
227}
228
229
230/* upgrade from branch 2.11 to 2.12 */
231function upgrade_211()
232{
233        global $conf;
234
235  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
236
237  if ((!isset($conf_UAM[14]) and !isset($conf_UAM[15])) and !isset($conf_UAM[16]) and !isset($conf_UAM[17]))
238  {
239    $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.
240       
241This 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.
242
243On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
244
245Best regards,
246
247The admin of the gallery.';
248               
249                $query = '
250UPDATE '.CONFIG_TABLE.'
251SET value="'.$upgrade_UAM.'"
252WHERE param="nbc_UserAdvManager"
253LIMIT 1
254;';
255                pwg_query($query);
256  }
257 
258        $q = "
259CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
260  user_id SMALLINT(5) NOT NULL DEFAULT '0',
261  lastvisit DATETIME NULL DEFAULT NULL,
262  reminder ENUM('true','false') NULL,
263PRIMARY KEY (`user_id`)
264  )
265;";
266  pwg_query($q);
267
268  upgrade_212();
269}
270
271
272/* upgrade from branch 2.12 to 2.13 */
273function upgrade_212()
274{
275/* Create missing table */
276  $query = "
277ALTER TABLE ".USER_CONFIRM_MAIL_TABLE."
278ADD reminder ENUM('true', 'false') NULL DEFAULT NULL
279;";
280 
281  pwg_query($query);
282
283/* Upgrade plugin configuration */
284        global $conf;
285
286  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
287
288  if ((!isset($conf_UAM[20])))
289  {
290    $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';
291               
292                $query = '
293UPDATE '.CONFIG_TABLE.'
294SET value="'.$upgrade_UAM.'"
295WHERE param="nbc_UserAdvManager"
296LIMIT 1
297;';
298                pwg_query($query);
299  }
300}
301
302function update_files($plugin_id)
303{
304  $clean = clean_obsolete_files(UAM_OBSOLETE);
305}
306?>
Note: See TracBrowser for help on using the repository browser.