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