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