source: extensions/UserAdvManager/trunk/maintain.inc.php @ 9875

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

Renaming plugin directory from NBC_UserAdvManager to UserAdvManager on plugin upgrade

  • Property svn:eol-style set to LF
File size: 8.6 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
11
12function plugin_install()
13{
14        global $conf;
15       
16  $default1 = array('false','false',-1,-1,-1,'false','false','',-1,'','','false','','false',100,'false','false',10,'Hello [username].
17       
18This is a reminder because a very long time passed since your last visit on our gallery [mygallery]. 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.
19
20On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
21
22Best regards,
23
24The admin of the gallery.','false','false','false','false','false','Sorry [username], your account has been deleted due to a too long time passed since your last visit at [mygallery].','Sorry [username], your account has been deprecated due to a too long time passed since your last visit at [mygallery]. Please, use the following link to revalidate your account.',-1,-1,'Thank you for registering at [mygallery]. Your account has been manually validated by _admin_. You may now log in at _link_to_site_ and make any appropriate changes to your profile. Welcome to _name_of_site_!','false','You have requested a password reset on our gallery. Please, find below your new connection settings.','false','Sorry, your account has been deleted because you have not validated your registration in requested time. Please, try registration with a valid and non blocked email account.','false');
25
26        $query = '
27SELECT param
28  FROM '.CONFIG_TABLE.'
29WHERE param = "UserAdvManager"
30;';
31  $count = pwg_db_num_rows(pwg_query($query));
32 
33  if ($count == 0)
34  {
35    $q = '
36INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
37VALUES ("UserAdvManager","'.addslashes(serialize($default1)).'","UAM parameters")
38  ;';
39    pwg_query($q);
40  }
41
42
43  $default2 = array('false',5,'Hello [username].
44               
45This is a reminder message because you registered on our gallery [mygallery] 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.
46
47Note: After this period, your account will be permanently deleted.','false','Hello [username].
48
49This is a reminder message because you registered on our gallery [mygallery] 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.
50
51Note: After this period, your account will be permanently deleted.','You have confirmed that you are human and may now use [mygallery]! Welcome [username]!','Your activation key is incorrect or expired or you have already validated your account, please contact the webmaster to fix this problem.');
52
53        $query = '
54SELECT param
55  FROM '.CONFIG_TABLE.'
56WHERE param = "UserAdvManager_ConfirmMail"
57;';
58  $count = pwg_db_num_rows(pwg_query($query));
59 
60  if ($count == 0)
61  {
62    $q = '
63INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
64VALUES ("UserAdvManager_ConfirmMail","'.addslashes(serialize($default2)).'","UAM ConfirmMail parameters")
65  ;';
66    pwg_query($q);
67  }
68
69        $query = '
70SELECT param
71  FROM '.CONFIG_TABLE.'
72WHERE param = "UserAdvManager_Redir"
73;';
74  $count = pwg_db_num_rows(pwg_query($query));
75 
76  if ($count == 0)
77  {
78    $q = '
79INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
80VALUES ("UserAdvManager_Redir","0","UAM Redirections")
81  ;';
82    pwg_query($q);
83  }
84
85// Set current plugin version in config table
86  $plugin =  PluginInfos(UAM_PATH);
87  $version = $plugin['version'];
88
89        $query = '
90SELECT param
91  FROM '.CONFIG_TABLE.'
92WHERE param = "UserAdvManager_Redir"
93;';
94  $count = pwg_db_num_rows(pwg_query($query));
95 
96  if ($count == 0)
97  {
98    $q = '
99INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
100VALUES ("UserAdvManager_Version","'.$version.'","UAM version check")
101  ;';
102    pwg_query($q);
103  }
104
105
106        $q = "
107CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
108  id varchar(50) NOT NULL default '',
109  user_id smallint(5) NOT NULL default '0',
110  mail_address varchar(255) default NULL,
111  status enum('webmaster','admin','normal','generic','guest') default NULL,
112  date_check datetime default NULL,
113  reminder ENUM('true','false') NULL,
114PRIMARY KEY  (id)
115  )
116ENGINE=MyISAM;";
117  pwg_query($q);
118
119        $q = "
120CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
121  user_id SMALLINT(5) NOT NULL DEFAULT '0',
122  lastvisit DATETIME NULL DEFAULT NULL,
123  reminder ENUM('true','false') NULL,
124PRIMARY KEY (`user_id`)
125  )
126ENGINE=MyISAM;";
127  pwg_query($q);
128}
129
130
131function plugin_activate()
132{
133  global $conf;
134
135/* Cleaning obsolete files */
136/* *********************** */
137  clean_obsolete_files();
138 
139  include_once (UAM_PATH.'include/upgradedb.inc.php');
140
141/* Check if old version is < 2.15 */
142/* ****************************** */
143        $query = '
144SELECT param
145  FROM '.CONFIG_TABLE.'
146WHERE param = "nbc_UserAdvManager"
147;';
148  $count1 = pwg_db_num_rows(pwg_query($query));
149 
150  $query = '
151SELECT *
152  FROM '.CONFIG_TABLE.'
153WHERE param = "nbc_UserAdvManager_ConfirmMail"
154;';
155  $count2 = pwg_db_num_rows(pwg_query($query)); 
156
157/* If old params exist an upgrade is needed */
158/* **************************************** */
159  if ($count1 == 1)
160  {
161/* Check for upgrade from 2.10 to 2.11 */
162/* *********************************** */
163    if ($count1 == 1 and $count2 == 0)
164    {
165    /* upgrade from branch 2.10 to 2.11 */
166    /* ******************************** */
167      upgrade_210_211();
168    }
169
170
171/* Check for upgrade from 2.11 to 2.12 */
172/* *********************************** */
173    if (!table_exist(USER_LASTVISIT_TABLE))
174    {
175    /* upgrade from branch 2.11 to 2.12 */
176    /* ******************************** */
177                upgrade_211_212();
178    }
179
180
181/* Check for upgrade from 2.12 to 2.13 */
182/* *********************************** */
183    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
184    $nb_fields = mysql_num_fields($fields); 
185
186    if ($nb_fields < 6)
187    {
188    /* upgrade from branch 2.12 to 2.13 */
189    /* ******************************** */
190      upgrade_212_213();
191    }
192
193
194/* Serializing conf parameters - Available since 2.14.0 */
195/* **************************************************** */
196    if (unserialize($conf['nbc_UserAdvManager']) === false)
197    {
198    /* upgrade from branch 2.13 to 2.14 */
199    /* ******************************** */
200      upgrade_213_214();
201    }
202   
203
204/* Check for upgrade from 2.14 to 2.15 */
205/* *********************************** */
206    //if ($count1 == 1 or $count2 == 1)
207    //{
208    /* upgrade from branch 2.14 to 2.15 */
209    /* ******************************** */
210      upgrade_214_215();
211    //}
212  }
213
214/* Old version is > 2.15 */
215/* ********************* */
216        $query = '
217SELECT param
218  FROM '.CONFIG_TABLE.'
219WHERE param = "UserAdvManager_Redir"
220;';
221  $count = pwg_db_num_rows(pwg_query($query));
222 
223  if ($count == 0)
224  {
225    upgrade_2153_2154();
226  }
227
228/* Check for upgrade from 2.15 to 2.16 */
229/* *********************************** */
230        $query = '
231SELECT param
232  FROM '.CONFIG_TABLE.'
233WHERE param = "UserAdvManager_Version"
234;';
235  $count = pwg_db_num_rows(pwg_query($query));
236 
237  if ($count == 0)
238  {
239    /* upgrade from branch 2.15 to 2.16 */
240    /* ******************************** */
241    upgrade_215_2160();
242  }
243
244/* Check for upgrade from 2.16 to 2.20 */
245/* *********************************** */
246        $query = '
247SELECT value
248  FROM '.CONFIG_TABLE.'
249WHERE param = "UserAdvManager_Version"
250;';
251
252  $data = pwg_db_fetch_assoc(pwg_query($query));
253 
254  if ($data['value'] != '2.20.0')
255  {
256    /* upgrade from branch 2.16 to 2.20 */
257    /* ******************************** */
258    upgrade_216_220();
259  }
260
261load_conf_from_db('param like \'UserAdvManager\\_%\'');
262}
263
264
265function plugin_uninstall()
266{
267  global $conf;
268
269  if (isset($conf['UserAdvManager']))
270  {
271    $q = '
272DELETE FROM '.CONFIG_TABLE.'
273WHERE param="UserAdvManager"
274;';
275
276    pwg_query($q);
277  }
278
279  if (isset($conf['UserAdvManager_ConfirmMail']))
280  {
281    $q = '
282DELETE FROM '.CONFIG_TABLE.'
283WHERE param="UserAdvManager_ConfirmMail"
284;';
285
286    pwg_query($q);
287  }
288
289  if (isset($conf['UserAdvManager_Redir']))
290  {
291    $q = '
292DELETE FROM '.CONFIG_TABLE.'
293WHERE param="UserAdvManager_Redir"
294;';
295
296    pwg_query($q);
297  }
298
299  if (isset($conf['UserAdvManager_Version']))
300  {
301    $q = '
302DELETE FROM '.CONFIG_TABLE.'
303WHERE param="UserAdvManager_Version"
304;';
305
306    pwg_query($q);
307  }
308
309  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
310  pwg_query( $q );
311
312  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
313  pwg_query( $q );
314}
315?>
Note: See TracBrowser for help on using the repository browser.