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