[5056] | 1 | <?php |
---|
[5181] | 2 | include_once (UAM_PATH.'include/constants.php'); |
---|
| 3 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 4 | |
---|
| 5 | /* Function called from main.inc.php to send validation email */ |
---|
| 6 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
---|
| 7 | { |
---|
| 8 | /* Only available for next Piwigo release (bug in switch_lang function) */ |
---|
[5064] | 9 | global $conf; |
---|
[5056] | 10 | |
---|
[5181] | 11 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 12 | |
---|
| 13 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
| 14 | |
---|
| 15 | $infos1_perso = ""; |
---|
| 16 | $infos2_perso = ""; |
---|
| 17 | |
---|
| 18 | /* We have to get the user's language in database */ |
---|
| 19 | $query =' |
---|
| 20 | SELECT user_id, language |
---|
| 21 | FROM '.USER_INFOS_TABLE.' |
---|
| 22 | WHERE user_id = '.$id.' |
---|
| 23 | ;'; |
---|
[5633] | 24 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 25 | |
---|
| 26 | /* Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language */ |
---|
| 27 | if (empty($data)) |
---|
| 28 | { |
---|
| 29 | /* And switch gallery to this language before using personalized and multilangual contents */ |
---|
| 30 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
| 31 | switch_lang_to($language); |
---|
| 32 | } |
---|
| 33 | else |
---|
| 34 | { |
---|
| 35 | /* And switch gallery to this language before using personalized and multilangual contents */ |
---|
| 36 | $language = $data['language']; /* Usefull for debugging */ |
---|
| 37 | switch_lang_to($data['language']); |
---|
[5181] | 38 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 39 | } |
---|
| 40 | |
---|
| 41 | switch($typemail) |
---|
| 42 | { |
---|
| 43 | case 1: |
---|
| 44 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', stripslashes($username))); |
---|
| 45 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
---|
| 46 | |
---|
[6354] | 47 | if (isset($conf_UAM[9]) and $conf_UAM[9] <> '') |
---|
[5056] | 48 | { |
---|
| 49 | if (function_exists('get_user_language_desc')) |
---|
| 50 | { |
---|
[6354] | 51 | $infos1_perso = get_user_language_desc($conf_UAM[9])."\n\n"; |
---|
[5056] | 52 | } |
---|
[6354] | 53 | else $infos1_perso = l10n($conf_UAM[9])."\n\n"; |
---|
[5056] | 54 | } |
---|
| 55 | |
---|
| 56 | break; |
---|
| 57 | |
---|
| 58 | case 2: |
---|
| 59 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
---|
| 60 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
---|
| 61 | |
---|
| 62 | break; |
---|
| 63 | |
---|
| 64 | case 3: |
---|
| 65 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
---|
| 66 | $password = $password <> '' ? $password : l10n('UAM_no_update_pwd'); |
---|
| 67 | |
---|
| 68 | break; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | if (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') |
---|
| 72 | { |
---|
| 73 | $infos1 = array( |
---|
| 74 | get_l10n_args('infos_mail %s', stripslashes($username)), |
---|
| 75 | get_l10n_args('User: %s', stripslashes($username)), |
---|
| 76 | get_l10n_args('Password: %s', $password), |
---|
| 77 | get_l10n_args('Email: %s', $email), |
---|
| 78 | get_l10n_args('', ''), |
---|
| 79 | ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
[6354] | 83 | if ( isset($conf_UAM[1]) and $conf_UAM[1] == 'true' and $confirm) |
---|
[5056] | 84 | { |
---|
| 85 | $infos2 = array |
---|
| 86 | ( |
---|
| 87 | get_l10n_args('Link: %s', AddConfirmMail($id, $email)), |
---|
| 88 | get_l10n_args('', ''), |
---|
| 89 | ); |
---|
| 90 | |
---|
[6354] | 91 | if (isset($conf_UAM[10]) and $conf_UAM[10] <> '') |
---|
[5056] | 92 | { |
---|
| 93 | if (function_exists('get_user_language_desc')) |
---|
| 94 | { |
---|
[6354] | 95 | $infos2_perso = get_user_language_desc($conf_UAM[10])."\n\n"; |
---|
[5056] | 96 | } |
---|
[6354] | 97 | else $infos2_perso = l10n($conf_UAM[10])."\n\n"; |
---|
[5056] | 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
[5084] | 101 | /* ******************************************************** */ |
---|
| 102 | /* **** Pending code since to find how to make it work **** */ |
---|
| 103 | /* ******************************************************** */ |
---|
| 104 | // Testing if FCK Editor is used. Then decoding htmlchars to avoid problems with pwg_mail() |
---|
| 105 | /*$areas = array(); |
---|
| 106 | array_push( $areas,'UAM_MailInfo_Text','UAM_ConfirmMail_Text'); |
---|
| 107 | |
---|
| 108 | if (function_exists('set_fckeditor_instance')) |
---|
| 109 | { |
---|
| 110 | $fcke_config = unserialize($conf['FCKEditor']); |
---|
| 111 | foreach($areas as $area) |
---|
| 112 | { |
---|
| 113 | if (isset($fcke_config['UAM_MailInfo_Text']) and $fcke_config['UAM_MailInfo_Text'] = true) |
---|
| 114 | { |
---|
| 115 | $infos1_perso = html_entity_decode($infos1_perso,ENT_QUOTES,UTF-8); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | if (isset($fcke_config['UAM_ConfirmMail_Text']) and $fcke_config['UAM_ConfirmMail_Text'] = true) |
---|
| 119 | { |
---|
| 120 | $infos2_perso = html_entity_decode($infos2_perso,ENT_QUOTES,UTF-8); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | }*/ |
---|
| 124 | |
---|
| 125 | |
---|
[5056] | 126 | /* Sending the email with subject and contents */ |
---|
| 127 | pwg_mail($email, array( |
---|
| 128 | 'subject' => $subject, |
---|
| 129 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
| 130 | )); |
---|
| 131 | |
---|
| 132 | /* ********************** */ |
---|
| 133 | /* Email sending debugger */ |
---|
| 134 | /* This is only to trace */ |
---|
| 135 | /* the send of emails for */ |
---|
| 136 | /* debugging */ |
---|
| 137 | /* ********************** */ |
---|
| 138 | //$content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
| 139 | //MailLog($email,$subject,$content,$language); |
---|
| 140 | /* ********************** */ |
---|
| 141 | |
---|
| 142 | /* Switching back to default language */ |
---|
| 143 | switch_lang_back(); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | /* Function called from UAM_admin.php to resend validation email with or without new validation key */ |
---|
| 148 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
---|
| 149 | { |
---|
| 150 | /* Only available for next Piwigo release (bug in switch_lang function) */ |
---|
[5064] | 151 | global $conf; |
---|
[5056] | 152 | |
---|
[5181] | 153 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 154 | |
---|
[5181] | 155 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[5056] | 156 | |
---|
| 157 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
| 158 | |
---|
| 159 | $infos1_perso = ""; |
---|
| 160 | $infos2_perso = ""; |
---|
| 161 | |
---|
| 162 | /* We have to get the user's language in database */ |
---|
| 163 | $query =' |
---|
| 164 | SELECT user_id, language |
---|
| 165 | FROM '.USER_INFOS_TABLE.' |
---|
| 166 | WHERE user_id = '.$user_id.' |
---|
| 167 | ;'; |
---|
[5633] | 168 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 169 | $language = $data['language']; |
---|
| 170 | |
---|
| 171 | /* And switch gallery to this language before using personalized and multilangual contents */ |
---|
| 172 | switch_lang_to($data['language']); |
---|
| 173 | |
---|
[5181] | 174 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 175 | |
---|
| 176 | switch($typemail) |
---|
| 177 | { |
---|
| 178 | case 1: |
---|
| 179 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_with_key_of_%s', $username)); |
---|
| 180 | |
---|
| 181 | if (isset($conf_UAM_ConfirmMail[2]) and $conf_UAM_ConfirmMail[2] <> '' and isset($conf_UAM_ConfirmMail[3]) and $conf_UAM_ConfirmMail[3] == 'true' and $confirm) |
---|
| 182 | { |
---|
| 183 | if (function_exists('get_user_language_desc')) |
---|
| 184 | { |
---|
| 185 | $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
| 186 | } |
---|
| 187 | else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
| 188 | |
---|
| 189 | $infos2 = array |
---|
| 190 | ( |
---|
| 191 | get_l10n_args('Link: %s', ResetConfirmMail($user_id)), |
---|
| 192 | get_l10n_args('', ''), |
---|
| 193 | ); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | /* Set reminder true */ |
---|
| 197 | $query = " |
---|
| 198 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
| 199 | SET reminder = 'true' |
---|
| 200 | WHERE user_id = '".$user_id."' |
---|
| 201 | ;"; |
---|
| 202 | pwg_query($query); |
---|
| 203 | |
---|
| 204 | break; |
---|
| 205 | |
---|
| 206 | case 2: |
---|
| 207 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_without_key_of_%s',$username)); |
---|
| 208 | |
---|
| 209 | if (isset($conf_UAM_ConfirmMail[2]) and $conf_UAM_ConfirmMail[2] <> '' and isset($conf_UAM_ConfirmMail[3]) and $conf_UAM_ConfirmMail[3] == 'true' and !$confirm) |
---|
| 210 | { |
---|
| 211 | if (function_exists('get_user_language_desc')) |
---|
| 212 | { |
---|
| 213 | $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
| 214 | } |
---|
| 215 | else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n"; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | /* Set reminder true */ |
---|
| 219 | $query = " |
---|
| 220 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
| 221 | SET reminder = 'true' |
---|
| 222 | WHERE user_id = '".$user_id."' |
---|
| 223 | ;"; |
---|
| 224 | pwg_query($query); |
---|
| 225 | |
---|
| 226 | break; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | pwg_mail($email, array( |
---|
| 230 | 'subject' => $subject, |
---|
| 231 | 'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
| 232 | )); |
---|
| 233 | |
---|
| 234 | /* ********************** */ |
---|
| 235 | /* Email sending debugger */ |
---|
| 236 | /* This is only to trace */ |
---|
| 237 | /* the send of emails for */ |
---|
| 238 | /* debugging */ |
---|
| 239 | /* ********************** */ |
---|
| 240 | //$content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
---|
| 241 | //MailLog($email,$subject,$content,$language); |
---|
| 242 | /* ********************** */ |
---|
| 243 | |
---|
| 244 | /* Switching back to default language */ |
---|
| 245 | switch_lang_back(); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | /* Function called from UAM_admin.php to send a reminder mail for ghost users */ |
---|
| 250 | function ghostreminder($user_id, $username, $email) |
---|
| 251 | { |
---|
| 252 | /* Only available for next Piwigo release (bug in switch_lang function) */ |
---|
[5064] | 253 | global $conf; |
---|
[5056] | 254 | |
---|
[5181] | 255 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 256 | |
---|
| 257 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
| 258 | |
---|
| 259 | $infos1_perso = ""; |
---|
| 260 | |
---|
| 261 | /* We have to get the user's language in database */ |
---|
| 262 | $query =' |
---|
| 263 | SELECT user_id, language |
---|
| 264 | FROM '.USER_INFOS_TABLE.' |
---|
| 265 | WHERE user_id = '.$user_id.' |
---|
| 266 | ;'; |
---|
[5633] | 267 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 268 | $language = $data['language']; |
---|
| 269 | |
---|
| 270 | /* And switch gallery to this language before using personalized and multilangual contents */ |
---|
| 271 | switch_lang_to($data['language']); |
---|
| 272 | |
---|
[5181] | 273 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 274 | |
---|
| 275 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Ghost_reminder_of_%s', $username)); |
---|
| 276 | |
---|
[6354] | 277 | if (isset($conf_UAM[18]) and $conf_UAM[18] <> '' and isset($conf_UAM[16]) and $conf_UAM[16] == 'true') |
---|
[5056] | 278 | { |
---|
| 279 | if (function_exists('get_user_language_desc')) |
---|
| 280 | { |
---|
[6354] | 281 | $infos1 = get_user_language_desc($conf_UAM[18])."\n\n"; |
---|
[5056] | 282 | } |
---|
| 283 | else |
---|
| 284 | { |
---|
[6354] | 285 | $infos1 = l10n($conf_UAM[18])."\n\n"; |
---|
[5056] | 286 | } |
---|
| 287 | |
---|
| 288 | resetlastvisit($user_id); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | pwg_mail($email, array( |
---|
| 292 | 'subject' => $subject, |
---|
| 293 | 'content' => $infos1.get_absolute_root_url(), |
---|
| 294 | )); |
---|
| 295 | |
---|
| 296 | /* ********************** */ |
---|
| 297 | /* Email sending debugger */ |
---|
| 298 | /* This is only to trace */ |
---|
| 299 | /* the send of emails for */ |
---|
| 300 | /* debugging */ |
---|
| 301 | /* ********************** */ |
---|
| 302 | //$content = get_user_language_desc($conf_UAM[19])."\n\n"; |
---|
| 303 | //MailLog($email,$subject,$content,$language); |
---|
| 304 | /* ********************** */ |
---|
| 305 | |
---|
| 306 | /* Switching back to default language */ |
---|
| 307 | switch_lang_back(); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | /* Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation */ |
---|
| 312 | function FindAvailableConfirmMailID() |
---|
| 313 | { |
---|
| 314 | while (true) |
---|
| 315 | { |
---|
| 316 | $id = generate_key(16); |
---|
| 317 | $query = " |
---|
| 318 | SELECT COUNT(*) |
---|
| 319 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
| 320 | WHERE id = '".$id."' |
---|
| 321 | ;"; |
---|
[5633] | 322 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 323 | |
---|
| 324 | if ($count == 0) |
---|
| 325 | return $id; |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | |
---|
| 330 | /* Function called from functions SendMail2User to process unvalidated users and generate validation key link */ |
---|
| 331 | function AddConfirmMail($user_id, $email) |
---|
| 332 | { |
---|
| 333 | global $conf; |
---|
| 334 | |
---|
[5181] | 335 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 336 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
| 337 | |
---|
[5633] | 338 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 339 | |
---|
| 340 | if (isset($Confirm_Mail_ID)) |
---|
| 341 | { |
---|
| 342 | $query = " |
---|
| 343 | SELECT status |
---|
| 344 | FROM ".USER_INFOS_TABLE." |
---|
| 345 | WHERE user_id = '".$user_id."' |
---|
| 346 | ;"; |
---|
[5633] | 347 | list($status) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 348 | |
---|
| 349 | $query = " |
---|
| 350 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
---|
| 351 | (id, user_id, mail_address, status, date_check) |
---|
| 352 | VALUES |
---|
| 353 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null) |
---|
| 354 | ;"; |
---|
| 355 | pwg_query($query); |
---|
| 356 | |
---|
| 357 | $query = " |
---|
| 358 | DELETE FROM ".USER_GROUP_TABLE." |
---|
| 359 | WHERE user_id = '".$user_id."' |
---|
| 360 | AND ( |
---|
[6354] | 361 | group_id = '".$conf_UAM[2]."' |
---|
| 362 | OR |
---|
[5056] | 363 | group_id = '".$conf_UAM[3]."' |
---|
| 364 | ) |
---|
| 365 | ;"; |
---|
| 366 | pwg_query($query); |
---|
| 367 | |
---|
[6354] | 368 | if (!is_admin() and $conf_UAM[8] <> -1) |
---|
[5056] | 369 | { |
---|
| 370 | $query = " |
---|
| 371 | UPDATE ".USER_INFOS_TABLE." |
---|
[6354] | 372 | SET status = '".$conf_UAM[8]."' |
---|
[5056] | 373 | WHERE user_id = '".$user_id."' |
---|
| 374 | ;"; |
---|
| 375 | pwg_query($query); |
---|
| 376 | } |
---|
| 377 | |
---|
[6354] | 378 | if ( $conf_UAM[2] <> -1 ) |
---|
[5056] | 379 | { |
---|
| 380 | $query = " |
---|
| 381 | INSERT INTO ".USER_GROUP_TABLE." |
---|
| 382 | (user_id, group_id) |
---|
| 383 | VALUES |
---|
[6354] | 384 | ('".$user_id."', '".$conf_UAM[2]."') |
---|
[5056] | 385 | ;"; |
---|
| 386 | pwg_query($query); |
---|
| 387 | } |
---|
| 388 | |
---|
[5181] | 389 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID; |
---|
[5056] | 390 | } |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | |
---|
[6757] | 394 | /* Function called from main.inc.php to set group to new users if manual validation is set */ |
---|
| 395 | function setgroup($user_id) |
---|
| 396 | { |
---|
| 397 | global $conf; |
---|
| 398 | |
---|
| 399 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 400 | |
---|
| 401 | $query = " |
---|
| 402 | DELETE FROM ".USER_GROUP_TABLE." |
---|
| 403 | WHERE user_id = '".$user_id."' |
---|
| 404 | AND ( |
---|
| 405 | group_id = '".$conf_UAM[2]."' |
---|
| 406 | OR |
---|
| 407 | group_id = '".$conf_UAM[3]."' |
---|
| 408 | ) |
---|
| 409 | ;"; |
---|
| 410 | pwg_query($query); |
---|
| 411 | |
---|
| 412 | if (!is_admin() and $conf_UAM[8] <> -1) |
---|
| 413 | { |
---|
| 414 | $query = " |
---|
| 415 | UPDATE ".USER_INFOS_TABLE." |
---|
| 416 | SET status = '".$conf_UAM[8]."' |
---|
| 417 | WHERE user_id = '".$user_id."' |
---|
| 418 | ;"; |
---|
| 419 | pwg_query($query); |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | if ( $conf_UAM[2] <> -1 ) |
---|
| 423 | { |
---|
| 424 | $query = " |
---|
| 425 | INSERT INTO ".USER_GROUP_TABLE." |
---|
| 426 | (user_id, group_id) |
---|
| 427 | VALUES |
---|
| 428 | ('".$user_id."', '".$conf_UAM[2]."') |
---|
| 429 | ;"; |
---|
| 430 | pwg_query($query); |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | |
---|
[5056] | 435 | /* Function called from UAM_admin.php to reset validation key */ |
---|
| 436 | function ResetConfirmMail($user_id) |
---|
| 437 | { |
---|
| 438 | global $conf; |
---|
| 439 | |
---|
| 440 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
| 441 | |
---|
[5633] | 442 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 443 | |
---|
| 444 | if (isset($Confirm_Mail_ID)) |
---|
| 445 | { |
---|
| 446 | $query = " |
---|
| 447 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
| 448 | SET id = '".$Confirm_Mail_ID."' |
---|
| 449 | WHERE user_id = '".$user_id."' |
---|
| 450 | ;"; |
---|
| 451 | pwg_query($query); |
---|
| 452 | |
---|
| 453 | $query = " |
---|
| 454 | UPDATE ".USER_INFOS_TABLE." |
---|
| 455 | SET registration_date = '".$dbnow."' |
---|
| 456 | WHERE user_id = '".$user_id."' |
---|
| 457 | ;"; |
---|
| 458 | pwg_query($query); |
---|
| 459 | |
---|
[5181] | 460 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID; |
---|
[5056] | 461 | } |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | |
---|
| 465 | /* Function called from function_UserAdvManager.inc.php to reset last visit date after sending a reminder */ |
---|
| 466 | function resetlastvisit($user_id) |
---|
| 467 | { |
---|
| 468 | global $conf; |
---|
| 469 | |
---|
[5633] | 470 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 471 | |
---|
| 472 | $query = " |
---|
| 473 | UPDATE ".USER_LASTVISIT_TABLE." |
---|
| 474 | SET lastvisit = '".$dbnow."', reminder = 'true' |
---|
| 475 | WHERE user_id = '".$user_id."' |
---|
| 476 | ;"; |
---|
| 477 | pwg_query($query); |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | |
---|
| 481 | /* Function called from main.inc.php - Triggered on user deletion */ |
---|
| 482 | function DeleteConfirmMail($user_id) |
---|
| 483 | { |
---|
| 484 | $query = " |
---|
| 485 | DELETE FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
| 486 | WHERE user_id = '".$user_id."' |
---|
| 487 | ;"; |
---|
| 488 | pwg_query($query); |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | /* Function called from main.inc.php - Triggered on user deletion */ |
---|
| 492 | function DeleteLastVisit($user_id) |
---|
| 493 | { |
---|
| 494 | $query = " |
---|
| 495 | DELETE FROM ".USER_LASTVISIT_TABLE." |
---|
| 496 | WHERE user_id = '".$user_id."' |
---|
| 497 | ;"; |
---|
| 498 | pwg_query($query); |
---|
| 499 | } |
---|
| 500 | |
---|
[6775] | 501 | |
---|
| 502 | /* Function called from main.inc.php - Triggered on user deletion */ |
---|
| 503 | function DeleteRedir($user_id) |
---|
| 504 | { |
---|
| 505 | $tab = array(); |
---|
| 506 | |
---|
| 507 | $query = " |
---|
| 508 | SELECT value |
---|
| 509 | FROM ".CONFIG_TABLE." |
---|
| 510 | WHERE param = 'UserAdvManager_Redir' |
---|
| 511 | ;"; |
---|
| 512 | |
---|
| 513 | $tab = pwg_db_fetch_row(pwg_query($query)); |
---|
| 514 | |
---|
| 515 | $values = explode(',', $tab[0]); |
---|
| 516 | |
---|
| 517 | unset($values[array_search($user_id, $values)]); |
---|
| 518 | |
---|
| 519 | $query = " |
---|
| 520 | UPDATE ".CONFIG_TABLE." |
---|
| 521 | SET value = \"".implode(',', $values)."\" |
---|
| 522 | WHERE param = 'UserAdvManager_Redir';"; |
---|
| 523 | |
---|
| 524 | pwg_query($query); |
---|
| 525 | } |
---|
| 526 | |
---|
| 527 | |
---|
[5056] | 528 | /* Function called from ConfirmMail.php to verify validation key used by user according time limit */ |
---|
| 529 | function VerifyConfirmMail($id) |
---|
| 530 | { |
---|
| 531 | global $conf; |
---|
| 532 | |
---|
| 533 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 534 | |
---|
[5181] | 535 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 536 | |
---|
[5181] | 537 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[5056] | 538 | |
---|
| 539 | $query = " |
---|
| 540 | SELECT COUNT(*) |
---|
| 541 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
| 542 | WHERE id = '".$id."' |
---|
| 543 | ;"; |
---|
[5633] | 544 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 545 | |
---|
| 546 | if ($count == 1) |
---|
| 547 | { |
---|
| 548 | $query = " |
---|
| 549 | SELECT user_id, status, date_check |
---|
| 550 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
| 551 | WHERE id = '".$id."' |
---|
| 552 | ;"; |
---|
[5633] | 553 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 554 | |
---|
| 555 | if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
| 556 | { |
---|
| 557 | $query = " |
---|
| 558 | SELECT registration_date |
---|
| 559 | FROM ".USER_INFOS_TABLE." |
---|
| 560 | WHERE user_id = '".$data['user_id']."' |
---|
| 561 | ;"; |
---|
[5633] | 562 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 563 | |
---|
| 564 | /* Time limit process */ |
---|
[5064] | 565 | /* ******************************************** */ |
---|
[5056] | 566 | if (!empty($registration_date)) |
---|
| 567 | { |
---|
| 568 | // Verify Confirmmail with time limit ON |
---|
| 569 | if (isset ($conf_UAM_ConfirmMail[1])) |
---|
| 570 | { |
---|
| 571 | // dates formating and compare |
---|
| 572 | $today = date("d-m-Y"); // Get today's date |
---|
| 573 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
| 574 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
| 575 | |
---|
| 576 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
| 577 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
| 578 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
| 579 | |
---|
| 580 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
| 581 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
| 582 | |
---|
| 583 | // Condition with the value set for time limit |
---|
| 584 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
| 585 | { |
---|
[5633] | 586 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 587 | |
---|
| 588 | $query = ' |
---|
| 589 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 590 | SET date_check="'.$dbnow.'" |
---|
| 591 | WHERE id = "'.$id.'" |
---|
| 592 | ;'; |
---|
| 593 | pwg_query($query); |
---|
| 594 | |
---|
[6354] | 595 | if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group |
---|
[5056] | 596 | { |
---|
| 597 | $query = " |
---|
| 598 | DELETE FROM ".USER_GROUP_TABLE." |
---|
| 599 | WHERE user_id = '".$data['user_id']."' |
---|
[6354] | 600 | AND group_id = '".$conf_UAM[2]."' |
---|
[5056] | 601 | ;"; |
---|
| 602 | pwg_query($query); |
---|
| 603 | } |
---|
| 604 | |
---|
[6354] | 605 | if ($conf_UAM[3] <> -1) // Add user to validated users group |
---|
[5056] | 606 | { |
---|
| 607 | $query = " |
---|
| 608 | INSERT INTO ".USER_GROUP_TABLE." |
---|
| 609 | (user_id, group_id) |
---|
| 610 | VALUES |
---|
[6354] | 611 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
---|
[5056] | 612 | ;"; |
---|
| 613 | pwg_query($query); |
---|
| 614 | } |
---|
| 615 | |
---|
[6354] | 616 | if (($conf_UAM[4] <> -1 or isset($data['status']))) // Change user's status |
---|
[5056] | 617 | { |
---|
| 618 | $query = " |
---|
| 619 | UPDATE ".USER_INFOS_TABLE." |
---|
[6354] | 620 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
---|
[5056] | 621 | WHERE user_id = '".$data['user_id']."' |
---|
| 622 | ;"; |
---|
| 623 | pwg_query($query); |
---|
| 624 | } |
---|
| 625 | // Refresh user's category cache |
---|
| 626 | invalidate_user_cache(); |
---|
| 627 | |
---|
| 628 | return true; |
---|
| 629 | } |
---|
| 630 | elseif ($deltadays > $conf_UAM_ConfirmMail[1]) // If timelimit exeeds |
---|
| 631 | { |
---|
| 632 | return false; |
---|
| 633 | } |
---|
| 634 | } |
---|
| 635 | // Verify Confirmmail with time limit OFF |
---|
| 636 | else |
---|
| 637 | { |
---|
[5633] | 638 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 639 | |
---|
| 640 | $query = ' |
---|
| 641 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 642 | SET date_check="'.$dbnow.'" |
---|
| 643 | WHERE id = "'.$id.'" |
---|
| 644 | ;'; |
---|
| 645 | pwg_query($query); |
---|
| 646 | |
---|
[6354] | 647 | if ($conf_UAM[2] <> -1) |
---|
[5056] | 648 | { |
---|
| 649 | $query = " |
---|
| 650 | DELETE FROM ".USER_GROUP_TABLE." |
---|
| 651 | WHERE user_id = '".$data['user_id']."' |
---|
[6354] | 652 | AND group_id = '".$conf_UAM[2]."' |
---|
[5056] | 653 | ;"; |
---|
| 654 | pwg_query($query); |
---|
| 655 | } |
---|
| 656 | |
---|
[6354] | 657 | if ($conf_UAM[3] <> -1) |
---|
[5056] | 658 | { |
---|
| 659 | $query = " |
---|
| 660 | DELETE FROM ".USER_GROUP_TABLE." |
---|
| 661 | WHERE user_id = '".$data['user_id']."' |
---|
[6354] | 662 | AND group_id = '".$conf_UAM[3]."' |
---|
[5056] | 663 | ;"; |
---|
| 664 | pwg_query($query); |
---|
| 665 | |
---|
| 666 | $query = " |
---|
| 667 | INSERT INTO ".USER_GROUP_TABLE." |
---|
| 668 | (user_id, group_id) |
---|
| 669 | VALUES |
---|
[6354] | 670 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
---|
[5056] | 671 | ;"; |
---|
| 672 | pwg_query($query); |
---|
| 673 | } |
---|
| 674 | |
---|
[6354] | 675 | if (($conf_UAM[4] <> -1 or isset($data['status']))) |
---|
[5056] | 676 | { |
---|
| 677 | $query = " |
---|
| 678 | UPDATE ".USER_INFOS_TABLE." |
---|
[6354] | 679 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
---|
[5056] | 680 | WHERE user_id = '".$data['user_id']."' |
---|
| 681 | ;"; |
---|
| 682 | pwg_query($query); |
---|
| 683 | } |
---|
| 684 | // Refresh user's category cache |
---|
| 685 | invalidate_user_cache(); |
---|
| 686 | |
---|
| 687 | return true; |
---|
| 688 | } |
---|
| 689 | } |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | else |
---|
| 693 | return false; |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | /* Function called from UAM_admin.php to force users validation by admin */ |
---|
| 697 | function ForceValidation($id) |
---|
| 698 | { |
---|
| 699 | global $conf; |
---|
| 700 | |
---|
| 701 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 702 | |
---|
[5181] | 703 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 704 | |
---|
| 705 | $query = " |
---|
| 706 | SELECT COUNT(*) |
---|
| 707 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
| 708 | WHERE user_id = '".$id."' |
---|
| 709 | ;"; |
---|
[5633] | 710 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 711 | |
---|
| 712 | if ($count == 1) |
---|
| 713 | { |
---|
| 714 | $query = " |
---|
| 715 | SELECT user_id, status, date_check |
---|
| 716 | FROM ".USER_CONFIRM_MAIL_TABLE." |
---|
| 717 | WHERE user_id = '".$id."' |
---|
| 718 | ;"; |
---|
[5633] | 719 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 720 | |
---|
| 721 | if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
---|
| 722 | { |
---|
[5633] | 723 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 724 | |
---|
| 725 | $query = " |
---|
| 726 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
---|
| 727 | SET date_check='".$dbnow."' |
---|
| 728 | WHERE user_id = '".$data['user_id']."' |
---|
| 729 | ;"; |
---|
| 730 | pwg_query($query); |
---|
| 731 | |
---|
[6354] | 732 | if ($conf_UAM[2] <> -1) |
---|
[5056] | 733 | { |
---|
| 734 | $query = " |
---|
| 735 | DELETE FROM ".USER_GROUP_TABLE." |
---|
| 736 | WHERE user_id = '".$data['user_id']."' |
---|
[6354] | 737 | AND group_id = '".$conf_UAM[2]."' |
---|
[5056] | 738 | ;"; |
---|
| 739 | pwg_query($query); |
---|
| 740 | } |
---|
| 741 | |
---|
[6354] | 742 | if ($conf_UAM[3] <> -1) |
---|
[5056] | 743 | { |
---|
| 744 | $query = " |
---|
| 745 | DELETE FROM ".USER_GROUP_TABLE." |
---|
| 746 | WHERE user_id = '".$data['user_id']."' |
---|
[6354] | 747 | AND group_id = '".$conf_UAM[3]."' |
---|
[5056] | 748 | ;"; |
---|
| 749 | pwg_query($query); |
---|
| 750 | |
---|
| 751 | $query = " |
---|
| 752 | INSERT INTO ".USER_GROUP_TABLE." |
---|
| 753 | (user_id, group_id) |
---|
| 754 | VALUES |
---|
[6354] | 755 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
---|
[5056] | 756 | ;"; |
---|
| 757 | pwg_query($query); |
---|
| 758 | } |
---|
| 759 | |
---|
[6354] | 760 | if (($conf_UAM[4] <> -1 or isset($data['status']))) |
---|
[5056] | 761 | { |
---|
| 762 | $query = " |
---|
| 763 | UPDATE ".USER_INFOS_TABLE." |
---|
[6354] | 764 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
---|
[5056] | 765 | WHERE user_id = '".$data['user_id']."' |
---|
| 766 | ;"; |
---|
| 767 | pwg_query($query); |
---|
| 768 | } |
---|
| 769 | // Refresh user's category cache |
---|
| 770 | invalidate_user_cache(); |
---|
| 771 | return true; |
---|
| 772 | } |
---|
| 773 | } |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | |
---|
| 777 | /* Function called from main.inc.php - Check if username matches forbidden caracters */ |
---|
| 778 | function ValidateUsername($login) |
---|
| 779 | { |
---|
| 780 | global $conf; |
---|
| 781 | |
---|
[5181] | 782 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 783 | |
---|
[6354] | 784 | if (isset($login) and isset($conf_UAM[7]) and $conf_UAM[7] <> '') |
---|
[5056] | 785 | { |
---|
[6354] | 786 | $conf_CharExclusion = preg_split("/,/",$conf_UAM[7]); |
---|
[5181] | 787 | for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++) |
---|
[5056] | 788 | { |
---|
[5181] | 789 | $pattern = '/'.$conf_CharExclusion[$i].'/i'; |
---|
[5056] | 790 | if (preg_match($pattern, $login)) |
---|
| 791 | { |
---|
| 792 | return true; |
---|
| 793 | } |
---|
| 794 | } |
---|
| 795 | } |
---|
| 796 | else |
---|
| 797 | { |
---|
| 798 | return false; |
---|
| 799 | } |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | |
---|
| 803 | /* Function called from main.inc.php - Check if user's email is in excluded email providers list */ |
---|
| 804 | /* Doesn't work on call - Must be copied in main.inc.php to work */ |
---|
| 805 | function ValidateEmailProvider($email) |
---|
| 806 | { |
---|
| 807 | global $conf; |
---|
| 808 | |
---|
[5181] | 809 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 810 | |
---|
[6354] | 811 | if (isset($email) and isset($conf_UAM[12]) and $conf_UAM[12] <> '') |
---|
[5056] | 812 | { |
---|
| 813 | //$ncsemail = strtolower($email); |
---|
[6354] | 814 | $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]); |
---|
[5181] | 815 | for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++) |
---|
[5056] | 816 | { |
---|
[5181] | 817 | $pattern = '/'.$conf_MailExclusion[$i].'/i'; |
---|
[5056] | 818 | if (preg_match($pattern, $email)) |
---|
| 819 | { |
---|
| 820 | return true; |
---|
| 821 | } |
---|
| 822 | } |
---|
| 823 | } |
---|
| 824 | else |
---|
| 825 | { |
---|
| 826 | return false; |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | |
---|
| 830 | |
---|
| 831 | /* Function called from UserAdvManager.php - Get unvalidated users according time limit */ |
---|
| 832 | function get_unvalid_user_list() |
---|
| 833 | { |
---|
| 834 | global $conf, $page; |
---|
| 835 | |
---|
| 836 | /* Get ConfirmMail configuration */ |
---|
[5181] | 837 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[5056] | 838 | /* Get UAM configuration */ |
---|
[5181] | 839 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 840 | |
---|
| 841 | $users = array(); |
---|
| 842 | |
---|
| 843 | /* search users depending expiration date */ |
---|
| 844 | $query = ' |
---|
| 845 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 846 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 847 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 848 | ui.status, |
---|
| 849 | ui.adviser, |
---|
| 850 | ui.enabled_high, |
---|
| 851 | ui.level, |
---|
| 852 | ui.registration_date |
---|
| 853 | FROM '.USERS_TABLE.' AS u |
---|
| 854 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 855 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 856 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 857 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
| 858 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
| 859 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'" |
---|
| 860 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail[1].'")'; |
---|
| 861 | |
---|
[6354] | 862 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] == '-1') |
---|
[5056] | 863 | { |
---|
| 864 | $query.= ' |
---|
[6354] | 865 | AND ug.group_id = '.$conf_UAM[2]; |
---|
[5056] | 866 | } |
---|
[6354] | 867 | if ($conf_UAM[2] == '-1' and $conf_UAM[8] <> '-1') |
---|
[5056] | 868 | { |
---|
| 869 | $query.= ' |
---|
[6354] | 870 | AND ui.status = \''.$conf_UAM[8]."'"; |
---|
[5056] | 871 | } |
---|
[6354] | 872 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] <> '-1') |
---|
[5056] | 873 | { |
---|
| 874 | $query.= ' |
---|
[6354] | 875 | AND ug.group_id = \''.$conf_UAM[2]."'"; |
---|
[5056] | 876 | } |
---|
| 877 | $query.= ' |
---|
[6399] | 878 | ORDER BY ui.registration_date ASC |
---|
[5056] | 879 | ;'; |
---|
| 880 | |
---|
| 881 | $result = pwg_query($query); |
---|
| 882 | |
---|
[5633] | 883 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 884 | { |
---|
| 885 | $user = $row; |
---|
| 886 | $user['groups'] = array(); |
---|
| 887 | |
---|
| 888 | array_push($users, $user); |
---|
| 889 | } |
---|
| 890 | |
---|
| 891 | /* add group lists */ |
---|
| 892 | $user_ids = array(); |
---|
| 893 | foreach ($users as $i => $user) |
---|
| 894 | { |
---|
| 895 | $user_ids[$i] = $user['id']; |
---|
| 896 | } |
---|
| 897 | |
---|
| 898 | $user_nums = array_flip($user_ids); |
---|
| 899 | |
---|
| 900 | if (count($user_ids) > 0) |
---|
| 901 | { |
---|
| 902 | $query = ' |
---|
| 903 | SELECT user_id, group_id |
---|
| 904 | FROM '.USER_GROUP_TABLE.' |
---|
| 905 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
| 906 | ;'; |
---|
| 907 | |
---|
| 908 | $result = pwg_query($query); |
---|
| 909 | |
---|
[5633] | 910 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 911 | { |
---|
| 912 | array_push( |
---|
| 913 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
| 914 | $row['group_id'] |
---|
| 915 | ); |
---|
| 916 | } |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | return $users; |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | |
---|
| 923 | /* Function called from UserAdvManager.php - Get ghost users */ |
---|
| 924 | function get_ghost_user_list() |
---|
| 925 | { |
---|
| 926 | global $conf, $page; |
---|
| 927 | |
---|
[5181] | 928 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 929 | |
---|
| 930 | $users = array(); |
---|
| 931 | |
---|
| 932 | /* search users depending expiration date */ |
---|
| 933 | $query = ' |
---|
| 934 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 935 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 936 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 937 | lv.lastvisit, |
---|
| 938 | lv.reminder |
---|
| 939 | FROM '.USERS_TABLE.' AS u |
---|
| 940 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
| 941 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
[6354] | 942 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'") |
---|
[6399] | 943 | ORDER BY lv.lastvisit ASC;'; |
---|
[5056] | 944 | |
---|
| 945 | $result = pwg_query($query); |
---|
| 946 | |
---|
[5633] | 947 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 948 | { |
---|
| 949 | $user = $row; |
---|
| 950 | $user['groups'] = array(); |
---|
| 951 | |
---|
| 952 | array_push($users, $user); |
---|
| 953 | } |
---|
| 954 | |
---|
| 955 | /* add group lists */ |
---|
| 956 | $user_ids = array(); |
---|
| 957 | foreach ($users as $i => $user) |
---|
| 958 | { |
---|
| 959 | $user_ids[$i] = $user['id']; |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | return $users; |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | |
---|
| 966 | /* Function called from UserAdvManager.php - Get all users to display the number of days since their last visit */ |
---|
| 967 | function get_user_list() |
---|
| 968 | { |
---|
| 969 | global $conf, $page; |
---|
| 970 | |
---|
| 971 | $users = array(); |
---|
| 972 | |
---|
| 973 | /* search users depending expiration date */ |
---|
| 974 | $query = ' |
---|
| 975 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 976 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 977 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 978 | ug.lastvisit |
---|
| 979 | FROM '.USERS_TABLE.' AS u |
---|
| 980 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug |
---|
| 981 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
| 982 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
[6399] | 983 | ORDER BY ug.lastvisit DESC |
---|
[5056] | 984 | ;'; |
---|
| 985 | |
---|
| 986 | $result = pwg_query($query); |
---|
| 987 | |
---|
[5633] | 988 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 989 | { |
---|
| 990 | $user = $row; |
---|
| 991 | $user['groups'] = array(); |
---|
| 992 | |
---|
| 993 | array_push($users, $user); |
---|
| 994 | } |
---|
| 995 | |
---|
| 996 | /* add group lists */ |
---|
| 997 | $user_ids = array(); |
---|
| 998 | foreach ($users as $i => $user) |
---|
| 999 | { |
---|
| 1000 | $user_ids[$i] = $user['id']; |
---|
| 1001 | } |
---|
| 1002 | |
---|
| 1003 | return $users; |
---|
| 1004 | } |
---|
| 1005 | |
---|
| 1006 | |
---|
| 1007 | /* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */ |
---|
| 1008 | function expiration($id) |
---|
| 1009 | { |
---|
| 1010 | global $conf, $page; |
---|
| 1011 | |
---|
| 1012 | /* Get ConfirmMail configuration */ |
---|
[5181] | 1013 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[5056] | 1014 | |
---|
| 1015 | /* Get UAM configuration */ |
---|
[5181] | 1016 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 1017 | |
---|
| 1018 | $query = " |
---|
| 1019 | SELECT registration_date |
---|
| 1020 | FROM ".USER_INFOS_TABLE." |
---|
| 1021 | WHERE user_id = '".$id."' |
---|
| 1022 | ;"; |
---|
[5633] | 1023 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 1024 | |
---|
| 1025 | /* Time limit process */ |
---|
[5064] | 1026 | /* ******************************************** */ |
---|
[5056] | 1027 | if (!empty($registration_date)) |
---|
| 1028 | { |
---|
| 1029 | // dates formating and compare |
---|
| 1030 | $today = date("d-m-Y"); // Get today's date |
---|
| 1031 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
| 1032 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
| 1033 | |
---|
| 1034 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
| 1035 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
| 1036 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
| 1037 | |
---|
| 1038 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
| 1039 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
| 1040 | |
---|
| 1041 | // Condition with the value set for time limit |
---|
| 1042 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
| 1043 | { |
---|
| 1044 | return false; |
---|
| 1045 | } |
---|
| 1046 | else |
---|
| 1047 | { |
---|
[6754] | 1048 | return true; |
---|
[5056] | 1049 | } |
---|
| 1050 | } |
---|
| 1051 | } |
---|
| 1052 | |
---|
| 1053 | |
---|
| 1054 | /** |
---|
| 1055 | * Returns a password's score for password complexity check |
---|
| 1056 | * |
---|
| 1057 | * @param password filled by user |
---|
| 1058 | * |
---|
| 1059 | * Thanx to MathieuGut from http://m-gut.developpez.com |
---|
| 1060 | */ |
---|
| 1061 | function testpassword($password) // Le mot de passe passé en paramètre - $password given by user |
---|
| 1062 | { |
---|
| 1063 | |
---|
| 1064 | // Initialisation des variables - Variables initiation |
---|
| 1065 | $points = 0; |
---|
| 1066 | $point_lowercase = 0; |
---|
| 1067 | $point_uppercase = 0; |
---|
| 1068 | $point_numbers = 0; |
---|
| 1069 | $point_characters = 0; |
---|
| 1070 | |
---|
| 1071 | // On récupère la longueur du mot de passe - Getting password lengh |
---|
| 1072 | $length = strlen($password); |
---|
| 1073 | |
---|
| 1074 | // On fait une boucle pour lire chaque lettre - Loop to read password characters |
---|
| 1075 | for($i = 0; $i < $length; $i++) |
---|
| 1076 | { |
---|
| 1077 | // On sélectionne une à une chaque lettre - Select each letters |
---|
| 1078 | // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn |
---|
| 1079 | $letters = $password[$i]; |
---|
| 1080 | |
---|
| 1081 | if ($letters>='a' && $letters<='z') |
---|
| 1082 | { |
---|
| 1083 | // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase |
---|
| 1084 | $points = $points + 1; |
---|
| 1085 | |
---|
| 1086 | // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase |
---|
| 1087 | $point_lowercase = 1; |
---|
| 1088 | } |
---|
| 1089 | else if ($letters>='A' && $letters <='Z') |
---|
| 1090 | { |
---|
| 1091 | // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase |
---|
| 1092 | $points = $points + 2; |
---|
| 1093 | |
---|
| 1094 | // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase |
---|
| 1095 | $point_uppercase = 2; |
---|
| 1096 | } |
---|
| 1097 | else if ($letters>='0' && $letters<='9') |
---|
| 1098 | { |
---|
| 1099 | // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers |
---|
| 1100 | $points = $points + 3; |
---|
| 1101 | |
---|
| 1102 | // On rajoute le bonus pour un chiffre - Adding bonus points for numbers |
---|
| 1103 | $point_numbers = 3; |
---|
| 1104 | } |
---|
| 1105 | else |
---|
| 1106 | { |
---|
| 1107 | // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters |
---|
| 1108 | $points = $points + 5; |
---|
| 1109 | |
---|
| 1110 | // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters |
---|
| 1111 | $point_characters = 5; |
---|
| 1112 | } |
---|
| 1113 | } |
---|
| 1114 | |
---|
| 1115 | // Calcul du coefficient points/longueur - calculating the coefficient points/length |
---|
| 1116 | $step1 = $points / $length; |
---|
| 1117 | |
---|
| 1118 | // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types... |
---|
| 1119 | $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters; |
---|
| 1120 | |
---|
| 1121 | // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length |
---|
| 1122 | $score = $step1 * $step2; |
---|
| 1123 | |
---|
| 1124 | // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain |
---|
| 1125 | $finalscore = $score * $length; |
---|
| 1126 | |
---|
| 1127 | return $finalscore; |
---|
| 1128 | } |
---|
| 1129 | |
---|
| 1130 | /* Function called from maintain.inc.php - to check if database upgrade is needed */ |
---|
| 1131 | function table_exist($table) |
---|
| 1132 | { |
---|
| 1133 | $query = 'DESC '.$table.';'; |
---|
[5633] | 1134 | return (bool)($res=pwg_query($query)); |
---|
[5056] | 1135 | } |
---|
| 1136 | |
---|
| 1137 | /* Email sending debugger function */ |
---|
[5181] | 1138 | function MailLog($to, $subject, $content, $language) |
---|
[5056] | 1139 | { |
---|
[5181] | 1140 | $fo=fopen (UAM_PATH.'admin/maillog.txt','a') ; |
---|
[5056] | 1141 | fwrite($fo,"======================\n") ; |
---|
| 1142 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
| 1143 | fwrite($fo,$to . "\n" . $subject . "\r\n") ; |
---|
| 1144 | fwrite($fo, "\n" . $content . "\r\n") ; |
---|
| 1145 | fwrite($fo, 'Langue : '."\n" . $language . "\r\n") ; |
---|
| 1146 | fclose($fo) ; |
---|
[5064] | 1147 | //return mail ($to,$subject) ; |
---|
[5056] | 1148 | } |
---|
| 1149 | |
---|
| 1150 | |
---|
[5181] | 1151 | /* Function called from UAM_admin.php and main.inc.php to get the plugin version and name */ |
---|
| 1152 | function PluginInfos($dir) |
---|
[5056] | 1153 | { |
---|
| 1154 | $path = $dir; |
---|
| 1155 | |
---|
| 1156 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
| 1157 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
| 1158 | { |
---|
| 1159 | $plugin['name'] = trim( $val[1] ); |
---|
| 1160 | } |
---|
| 1161 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
| 1162 | { |
---|
| 1163 | $plugin['version'] = trim($val[1]); |
---|
| 1164 | } |
---|
| 1165 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
| 1166 | { |
---|
| 1167 | $plugin['uri'] = trim($val[1]); |
---|
| 1168 | } |
---|
| 1169 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
| 1170 | { |
---|
| 1171 | $plugin['description'] = trim($desc); |
---|
| 1172 | } |
---|
| 1173 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
| 1174 | { |
---|
| 1175 | $plugin['description'] = trim($val[1]); |
---|
| 1176 | } |
---|
| 1177 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
| 1178 | { |
---|
| 1179 | $plugin['author'] = trim($val[1]); |
---|
| 1180 | } |
---|
| 1181 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
| 1182 | { |
---|
| 1183 | $plugin['author uri'] = trim($val[1]); |
---|
| 1184 | } |
---|
| 1185 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
| 1186 | { |
---|
| 1187 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
| 1188 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
| 1189 | } |
---|
| 1190 | // IMPORTANT SECURITY ! |
---|
| 1191 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
| 1192 | |
---|
| 1193 | return $plugin ; |
---|
| 1194 | } |
---|
| 1195 | |
---|
| 1196 | |
---|
[5064] | 1197 | function clean_obsolete_files() |
---|
[5056] | 1198 | { |
---|
[5181] | 1199 | if (file_exists(UAM_PATH.'obsolete.list') |
---|
| 1200 | and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
[5064] | 1201 | and !empty($old_files)) |
---|
[5056] | 1202 | { |
---|
[5064] | 1203 | array_push($old_files, 'obsolete.list'); |
---|
| 1204 | foreach($old_files as $old_file) |
---|
| 1205 | { |
---|
[5181] | 1206 | $path = UAM_PATH.$old_file; |
---|
[5064] | 1207 | if (is_file($path)) |
---|
| 1208 | { |
---|
| 1209 | @unlink($path); |
---|
| 1210 | } |
---|
| 1211 | } |
---|
[5056] | 1212 | } |
---|
| 1213 | } |
---|
[6775] | 1214 | |
---|
| 1215 | |
---|
| 1216 | // check_consult - Thx to LucMorizur |
---|
| 1217 | // checks if a user id is registered as having already |
---|
| 1218 | // visited his profile.php page. |
---|
| 1219 | // @uid : the user id |
---|
| 1220 | // @user_idsOK : (returned) array of all users ids having already visited |
---|
| 1221 | // their profile.php pages |
---|
| 1222 | // |
---|
| 1223 | // @returns : true or false whether the users has already visited his |
---|
| 1224 | // profile.php page or not |
---|
| 1225 | function check_consult($uid, &$user_idsOK) |
---|
| 1226 | { |
---|
| 1227 | $t = array(); |
---|
| 1228 | $v = false; |
---|
| 1229 | |
---|
| 1230 | $query = " |
---|
| 1231 | SELECT value |
---|
| 1232 | FROM ".CONFIG_TABLE." |
---|
| 1233 | WHERE param = 'UserAdvManager_Redir' |
---|
| 1234 | ;"; |
---|
| 1235 | |
---|
| 1236 | if ($v = (($t = pwg_db_fetch_row(pwg_query($query))) !== false)) |
---|
| 1237 | { |
---|
| 1238 | $user_idsOK = explode(',', $t[0]); |
---|
| 1239 | $v = (in_array($uid, $user_idsOK)); |
---|
| 1240 | } |
---|
| 1241 | return $v; |
---|
| 1242 | } |
---|
[5056] | 1243 | ?> |
---|