1 | <?php |
---|
2 | include_once (NBC_UserAdvManager_PATH.'include/constants.php'); |
---|
3 | include_once (NBC_UserAdvManager_PATH.'include/functions_UserAdvManager.inc.php'); |
---|
4 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
5 | |
---|
6 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
---|
7 | { |
---|
8 | global $conf; |
---|
9 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
10 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
11 | $infos1_perso = ""; |
---|
12 | $infos2_perso = ""; |
---|
13 | |
---|
14 | switch($typemail) |
---|
15 | { |
---|
16 | case 1: |
---|
17 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', $username)); |
---|
18 | $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd'); |
---|
19 | |
---|
20 | if ( function_exists('get_user_language_desc') and isset($conf_nbc_UserAdvManager[10]) and $conf_nbc_UserAdvManager[10] <> '' ) |
---|
21 | $infos1_perso = get_user_language_desc($conf_nbc_UserAdvManager[10])."\n\n"; |
---|
22 | |
---|
23 | break; |
---|
24 | |
---|
25 | case 2: |
---|
26 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', $username)); |
---|
27 | $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd'); |
---|
28 | |
---|
29 | break; |
---|
30 | |
---|
31 | case 3: |
---|
32 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', $username)); |
---|
33 | $password = $password <> '' ? $password : l10n('UserAdvManager_no_update_pwd'); |
---|
34 | |
---|
35 | break; |
---|
36 | } |
---|
37 | |
---|
38 | if ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true' ) |
---|
39 | { |
---|
40 | $infos1 = array( |
---|
41 | get_l10n_args('infos_mail %s', $username), |
---|
42 | get_l10n_args('User: %s', $username), |
---|
43 | get_l10n_args('Password: %s', $password), |
---|
44 | get_l10n_args('Email: %s', $email), |
---|
45 | get_l10n_args('', ''), |
---|
46 | ); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | if ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true' and $confirm) |
---|
51 | { |
---|
52 | $infos2 = array |
---|
53 | ( |
---|
54 | get_l10n_args('Link: %s', AddConfirmMail($id, $email)), |
---|
55 | get_l10n_args('', ''), |
---|
56 | ); |
---|
57 | |
---|
58 | if ( function_exists('get_user_language_desc') and isset($conf_nbc_UserAdvManager[11]) and $conf_nbc_UserAdvManager[11] <> '' ) |
---|
59 | $infos2_perso = get_user_language_desc($conf_nbc_UserAdvManager[11])."\n\n"; |
---|
60 | } |
---|
61 | |
---|
62 | pwg_mail($email, array( |
---|
63 | 'subject' => $subject, |
---|
64 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
65 | )); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | function FindAvailableConfirmMailID() |
---|
71 | { |
---|
72 | while (true) |
---|
73 | { |
---|
74 | $id = generate_key(16); |
---|
75 | $query = " |
---|
76 | SELECT COUNT(*) |
---|
77 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
78 | WHERE id = '".$id."' |
---|
79 | ;"; |
---|
80 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
81 | |
---|
82 | if ($count == 0) |
---|
83 | return $id; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | function AddConfirmMail($user_id, $email) |
---|
90 | { |
---|
91 | global $conf; |
---|
92 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
93 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
94 | |
---|
95 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
96 | |
---|
97 | if ( isset($Confirm_Mail_ID) ) |
---|
98 | { |
---|
99 | $query = " |
---|
100 | SELECT status |
---|
101 | FROM ".USER_INFOS_TABLE." |
---|
102 | WHERE user_id = '".$user_id."' |
---|
103 | ;"; |
---|
104 | list($status) = mysql_fetch_row(pwg_query($query)); |
---|
105 | |
---|
106 | $query = " |
---|
107 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
---|
108 | (id, user_id, mail_address, status, date_check) |
---|
109 | VALUES |
---|
110 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null) |
---|
111 | ;"; |
---|
112 | pwg_query($query); |
---|
113 | |
---|
114 | $query = " |
---|
115 | DELETE FROM ".USER_GROUP_TABLE." |
---|
116 | WHERE user_id = '".$user_id."' |
---|
117 | AND ( |
---|
118 | group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
119 | OR |
---|
120 | group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
121 | ) |
---|
122 | ;"; |
---|
123 | pwg_query($query); |
---|
124 | |
---|
125 | if ( !is_admin() and $conf_nbc_UserAdvManager[9] <> -1 ) |
---|
126 | { |
---|
127 | $query = " |
---|
128 | UPDATE ".USER_INFOS_TABLE." |
---|
129 | SET status = '".$conf_nbc_UserAdvManager[9]."' |
---|
130 | WHERE user_id = '".$user_id."' |
---|
131 | ;"; |
---|
132 | pwg_query($query); |
---|
133 | } |
---|
134 | |
---|
135 | if ( $conf_nbc_UserAdvManager[3] <> -1 ) |
---|
136 | { |
---|
137 | $query = " |
---|
138 | INSERT INTO ".USER_GROUP_TABLE." |
---|
139 | (user_id, group_id) |
---|
140 | VALUES |
---|
141 | ('".$user_id."', '".$conf_nbc_UserAdvManager[3]."') |
---|
142 | ;"; |
---|
143 | pwg_query($query); |
---|
144 | } |
---|
145 | |
---|
146 | return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID; |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | function DeleteConfirmMail($user_id) |
---|
153 | { |
---|
154 | $query = " |
---|
155 | DELETE FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
156 | WHERE user_id = '".$user_id."' |
---|
157 | ;"; |
---|
158 | pwg_query($query); |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | function VerifyConfirmMail($id) |
---|
164 | { |
---|
165 | global $conf; |
---|
166 | |
---|
167 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
168 | |
---|
169 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
170 | |
---|
171 | $query = " |
---|
172 | SELECT COUNT(*) |
---|
173 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
174 | WHERE id = '".$id."' |
---|
175 | ;"; |
---|
176 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
177 | |
---|
178 | if ($count == 1) |
---|
179 | { |
---|
180 | $query = " |
---|
181 | SELECT user_id, status, date_check |
---|
182 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
183 | WHERE id = '".$id."' |
---|
184 | ;"; |
---|
185 | $data = mysql_fetch_array(pwg_query($query)); |
---|
186 | |
---|
187 | |
---|
188 | if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
189 | { |
---|
190 | $query = " |
---|
191 | SELECT registration_date |
---|
192 | FROM ".USER_INFOS_TABLE." |
---|
193 | WHERE user_id = '".$data['user_id']."' |
---|
194 | ;"; |
---|
195 | list($registration_date) = mysql_fetch_row(pwg_query($query)); |
---|
196 | |
---|
197 | if (!empty($registration_date)) |
---|
198 | { |
---|
199 | // Time limit process |
---|
200 | } |
---|
201 | |
---|
202 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
203 | |
---|
204 | $query = ' |
---|
205 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
206 | SET date_check="'.$dbnow.'" |
---|
207 | WHERE id = "'.$id.'" |
---|
208 | ;'; |
---|
209 | pwg_query($query); |
---|
210 | |
---|
211 | if ( $conf_nbc_UserAdvManager[3] <> -1 ) |
---|
212 | { |
---|
213 | $query = " |
---|
214 | DELETE FROM ".USER_GROUP_TABLE." |
---|
215 | WHERE user_id = '".$data['user_id']."' |
---|
216 | AND group_id = '".$conf_nbc_UserAdvManager[3]."' |
---|
217 | ;"; |
---|
218 | pwg_query($query); |
---|
219 | } |
---|
220 | |
---|
221 | if ( $conf_nbc_UserAdvManager[4] <> -1 ) |
---|
222 | { |
---|
223 | $query = " |
---|
224 | DELETE FROM ".USER_GROUP_TABLE." |
---|
225 | WHERE user_id = '".$data['user_id']."' |
---|
226 | AND group_id = '".$conf_nbc_UserAdvManager[4]."' |
---|
227 | ;"; |
---|
228 | pwg_query($query); |
---|
229 | |
---|
230 | $query = " |
---|
231 | INSERT INTO ".USER_GROUP_TABLE." |
---|
232 | (user_id, group_id) |
---|
233 | VALUES |
---|
234 | ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."') |
---|
235 | ;"; |
---|
236 | pwg_query($query); |
---|
237 | } |
---|
238 | |
---|
239 | if ( ( $conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']) ) ) |
---|
240 | { |
---|
241 | $query = " |
---|
242 | UPDATE ".USER_INFOS_TABLE." |
---|
243 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."' |
---|
244 | WHERE user_id = '".$data['user_id']."' |
---|
245 | ;"; |
---|
246 | pwg_query($query); |
---|
247 | } |
---|
248 | // Refresh user's category cache |
---|
249 | invalidate_user_cache(); |
---|
250 | |
---|
251 | return true; |
---|
252 | } |
---|
253 | } |
---|
254 | else |
---|
255 | return false; |
---|
256 | |
---|
257 | } |
---|
258 | |
---|
259 | function NotSensibleSearchUsername($username) |
---|
260 | { |
---|
261 | global $conf; |
---|
262 | |
---|
263 | if ( isset($username) ) |
---|
264 | { |
---|
265 | $query = " |
---|
266 | SELECT ".$conf['user_fields']['username']." |
---|
267 | FROM ".USERS_TABLE." |
---|
268 | WHERE LOWER(".$conf['user_fields']['username'].") = '".strtolower($username)."' |
---|
269 | ;"; |
---|
270 | list($username) = mysql_fetch_row(pwg_query($query)); |
---|
271 | |
---|
272 | return isset($username) ? $username : ''; |
---|
273 | } |
---|
274 | } |
---|
275 | |
---|
276 | function SearchMail($email) |
---|
277 | { |
---|
278 | global $conf, $lang; |
---|
279 | |
---|
280 | if ( isset($email) ) |
---|
281 | { |
---|
282 | $query = " |
---|
283 | SELECT COUNT(*) |
---|
284 | FROM ".USERS_TABLE." |
---|
285 | WHERE ".$conf['user_fields']['email']." = '".$email."' |
---|
286 | ;"; |
---|
287 | list($nbr_mail) = mysql_fetch_row(pwg_query($query)); |
---|
288 | |
---|
289 | return isset($nbr_mail) ? $nbr_mail : 0; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | function ValidateUsername($login) |
---|
294 | { |
---|
295 | global $conf; |
---|
296 | |
---|
297 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
298 | |
---|
299 | if ( isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '' ) |
---|
300 | { |
---|
301 | $pattern = '/'.$conf_nbc_UserAdvManager[8].'/'; |
---|
302 | if ( preg_match($pattern, $login) ) |
---|
303 | return false; |
---|
304 | else |
---|
305 | return true; |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | return true; |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | |
---|
314 | function ValidateEmailProvider($email) |
---|
315 | { |
---|
316 | global $conf; |
---|
317 | |
---|
318 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
319 | if (isset($conf_nbc_UserAdvManager[12])) |
---|
320 | { |
---|
321 | $ncsemail = strtolower($email); |
---|
322 | $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]); |
---|
323 | for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++) |
---|
324 | { |
---|
325 | $pattern = '/'.$conf_nbc_MailExclusion[$i].'/'; |
---|
326 | if (preg_match($pattern, $ncsemail)) |
---|
327 | return false; |
---|
328 | else |
---|
329 | return true; |
---|
330 | } |
---|
331 | } |
---|
332 | } |
---|
333 | ?> |
---|