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

Last change on this file since 9846 was 9846, checked in by Eric, 13 years ago

Missing config table insertion on installation from scratch
Unnecessary code cleanup

  • Property svn:eol-style set to LF
File size: 7.9 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  $q = '
27INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
28VALUES ("UserAdvManager","'.addslashes(serialize($default1)).'","UAM parameters")
29  ;';
30  pwg_query($q);
31
32
33  $default2 = array('false',5,'Hello [username].
34               
35This 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.
36
37Note: After this period, your account will be permanently deleted.','false','Hello [username].
38
39This 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.
40
41Note: 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.');
42
43  $q = '
44INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
45VALUES ("UserAdvManager_ConfirmMail","'.addslashes(serialize($default2)).'","UAM ConfirmMail parameters")
46  ;';
47  pwg_query($q);
48 
49  $q = '
50INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
51VALUES ("UserAdvManager_Redir","0","UAM Redirections")
52  ;';
53  pwg_query($q);
54
55// Set current plugin version in config table
56  $plugin =  PluginInfos(UAM_PATH);
57  $version = $plugin['version'];
58  $q = '
59INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
60VALUES ("UserAdvManager_Version","'.$version.'","UAM version check")
61  ;';
62 
63  pwg_query($q);
64
65
66        $q = "
67CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
68  id varchar(50) NOT NULL default '',
69  user_id smallint(5) NOT NULL default '0',
70  mail_address varchar(255) default NULL,
71  status enum('webmaster','admin','normal','generic','guest') default NULL,
72  date_check datetime default NULL,
73  reminder ENUM('true','false') NULL,
74PRIMARY KEY  (id)
75  )
76ENGINE=MyISAM;";
77  pwg_query($q);
78
79        $q = "
80CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
81  user_id SMALLINT(5) NOT NULL DEFAULT '0',
82  lastvisit DATETIME NULL DEFAULT NULL,
83  reminder ENUM('true','false') NULL,
84PRIMARY KEY (`user_id`)
85  )
86ENGINE=MyISAM;";
87  pwg_query($q);
88}
89
90
91function plugin_activate()
92{
93  global $conf;
94
95/* Cleaning obsolete files */
96/* *********************** */
97  clean_obsolete_files();
98 
99  include_once (UAM_PATH.'include/upgradedb.inc.php');
100
101/* Check if old version is < 2.15 */
102/* ****************************** */
103        $query = '
104SELECT param
105  FROM '.CONFIG_TABLE.'
106WHERE param = "nbc_UserAdvManager"
107;';
108  $count1 = pwg_db_num_rows(pwg_query($query));
109 
110  $query = '
111SELECT *
112  FROM '.CONFIG_TABLE.'
113WHERE param = "nbc_UserAdvManager_ConfirmMail"
114;';
115  $count2 = pwg_db_num_rows(pwg_query($query)); 
116
117/* If old params exist an upgrade is needed */
118/* **************************************** */
119  if ($count1 == 1)
120  {
121/* Check for upgrade from 2.10 to 2.11 */
122/* *********************************** */
123    if ($count1 == 1 and $count2 == 0)
124    {
125    /* upgrade from branch 2.10 to 2.11 */
126    /* ******************************** */
127      upgrade_210_211();
128    }
129
130
131/* Check for upgrade from 2.11 to 2.12 */
132/* *********************************** */
133    if (!table_exist(USER_LASTVISIT_TABLE))
134    {
135    /* upgrade from branch 2.11 to 2.12 */
136    /* ******************************** */
137                upgrade_211_212();
138    }
139
140
141/* Check for upgrade from 2.12 to 2.13 */
142/* *********************************** */
143    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
144    $nb_fields = mysql_num_fields($fields); 
145
146    if ($nb_fields < 6)
147    {
148    /* upgrade from branch 2.12 to 2.13 */
149    /* ******************************** */
150      upgrade_212_213();
151    }
152
153
154/* Serializing conf parameters - Available since 2.14.0 */
155/* **************************************************** */
156    if (unserialize($conf['nbc_UserAdvManager']) === false)
157    {
158    /* upgrade from branch 2.13 to 2.14 */
159    /* ******************************** */
160      upgrade_213_214();
161    }
162   
163
164/* Check for upgrade from 2.14 to 2.15 */
165/* *********************************** */
166    //if ($count1 == 1 or $count2 == 1)
167    //{
168    /* upgrade from branch 2.14 to 2.15 */
169    /* ******************************** */
170      upgrade_214_215();
171    //}
172  }
173
174/* Old version is > 2.15 */
175/* ********************* */
176        $query = '
177SELECT param
178  FROM '.CONFIG_TABLE.'
179WHERE param = "UserAdvManager_Redir"
180;';
181  $count = pwg_db_num_rows(pwg_query($query));
182 
183  if ($count == 0)
184  {
185    upgrade_2153_2154();
186  }
187
188/* Check for upgrade from 2.15 to 2.16 */
189/* *********************************** */
190        $query = '
191SELECT param
192  FROM '.CONFIG_TABLE.'
193WHERE param = "UserAdvManager_Version"
194;';
195  $count = pwg_db_num_rows(pwg_query($query));
196 
197  if ($count == 0)
198  {
199    /* upgrade from branch 2.15 to 2.16 */
200    /* ******************************** */
201    upgrade_215_2160();
202  }
203
204/* Check for upgrade from 2.16 to 2.20 */
205/* *********************************** */
206        $query = '
207SELECT value
208  FROM '.CONFIG_TABLE.'
209WHERE param = "UserAdvManager_Version"
210;';
211
212  $data = pwg_db_fetch_assoc(pwg_query($query));
213 
214  if ($data['value'] != '2.20.0')
215  {
216    /* upgrade from branch 2.16 to 2.20 */
217    /* ******************************** */
218    upgrade_216_220();
219  }
220
221load_conf_from_db('param like \'UserAdvManager\\_%\'');
222}
223
224
225function plugin_uninstall()
226{
227  global $conf;
228
229  if (isset($conf['UserAdvManager']))
230  {
231    $q = '
232DELETE FROM '.CONFIG_TABLE.'
233WHERE param="UserAdvManager"
234;';
235
236    pwg_query($q);
237  }
238
239  if (isset($conf['UserAdvManager_ConfirmMail']))
240  {
241    $q = '
242DELETE FROM '.CONFIG_TABLE.'
243WHERE param="UserAdvManager_ConfirmMail"
244;';
245
246    pwg_query($q);
247  }
248
249  if (isset($conf['UserAdvManager_Redir']))
250  {
251    $q = '
252DELETE FROM '.CONFIG_TABLE.'
253WHERE param="UserAdvManager_Redir"
254;';
255
256    pwg_query($q);
257  }
258
259  if (isset($conf['UserAdvManager_Version']))
260  {
261    $q = '
262DELETE FROM '.CONFIG_TABLE.'
263WHERE param="UserAdvManager_Version"
264;';
265
266    pwg_query($q);
267  }
268
269  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
270  pwg_query( $q );
271
272  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
273  pwg_query( $q );
274}
275?>
Note: See TracBrowser for help on using the repository browser.