| 1 | <?php |
|---|
| 2 | include_once (UAM_PATH.'include/constants.php'); |
|---|
| 3 | load_language('plugin.lang', UAM_PATH); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Triggered on get_admin_plugin_menu_links |
|---|
| 7 | * |
|---|
| 8 | * Plugin's administration menu |
|---|
| 9 | */ |
|---|
| 10 | function UAM_admin_menu($menu) |
|---|
| 11 | { |
|---|
| 12 | // +-----------------------------------------------------------------------+ |
|---|
| 13 | // | Getting plugin name | |
|---|
| 14 | // +-----------------------------------------------------------------------+ |
|---|
| 15 | $plugin = PluginInfos(UAM_PATH); |
|---|
| 16 | $name = $plugin['name']; |
|---|
| 17 | |
|---|
| 18 | array_push($menu, |
|---|
| 19 | array( |
|---|
| 20 | 'NAME' => $name, |
|---|
| 21 | 'URL' => get_admin_plugin_menu_link(UAM_PATH.'/admin/UAM_admin.php') |
|---|
| 22 | ) |
|---|
| 23 | ); |
|---|
| 24 | |
|---|
| 25 | return $menu; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | * Triggered on loc_begin_index |
|---|
| 30 | * |
|---|
| 31 | * Initiating GhostTracker |
|---|
| 32 | */ |
|---|
| 33 | function UAM_GhostTracker() |
|---|
| 34 | { |
|---|
| 35 | global $conf, $user; |
|---|
| 36 | |
|---|
| 37 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 38 | |
|---|
| 39 | // Admins, Guests and Adult_Content users are not tracked for Ghost Tracker or Users Tracker |
|---|
| 40 | if (!is_admin() and !is_a_guest() and $user['username'] != "16" and $user['username'] != "18") |
|---|
| 41 | { |
|---|
| 42 | if ((isset($conf_UAM[16]) and $conf_UAM[16] == 'true') or (isset($conf_UAM[19]) and $conf_UAM[19] == 'true')) |
|---|
| 43 | { |
|---|
| 44 | |
|---|
| 45 | $userid = get_userid($user['username']); |
|---|
| 46 | |
|---|
| 47 | // Looking for existing entry in last visit table |
|---|
| 48 | $query = ' |
|---|
| 49 | SELECT * |
|---|
| 50 | FROM '.USER_LASTVISIT_TABLE.' |
|---|
| 51 | WHERE user_id = '.$userid.' |
|---|
| 52 | ;'; |
|---|
| 53 | |
|---|
| 54 | $count = pwg_db_num_rows(pwg_query($query)); |
|---|
| 55 | |
|---|
| 56 | if ($count == 0) |
|---|
| 57 | { |
|---|
| 58 | // If not, data are inserted in table |
|---|
| 59 | $query = ' |
|---|
| 60 | INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder) |
|---|
| 61 | VALUES ('.$userid.', now(), "false") |
|---|
| 62 | ;'; |
|---|
| 63 | pwg_query($query); |
|---|
| 64 | } |
|---|
| 65 | else if ($count > 0) |
|---|
| 66 | { |
|---|
| 67 | // If yes, data are updated in table |
|---|
| 68 | $query = ' |
|---|
| 69 | UPDATE '.USER_LASTVISIT_TABLE.' |
|---|
| 70 | SET lastvisit = now(), reminder = "false" |
|---|
| 71 | WHERE user_id = '.$userid.' |
|---|
| 72 | LIMIT 1 |
|---|
| 73 | ;'; |
|---|
| 74 | pwg_query($query); |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * Triggered on register_user |
|---|
| 82 | * |
|---|
| 83 | * Additional controls on user registration |
|---|
| 84 | */ |
|---|
| 85 | function UAM_Adduser($register_user) |
|---|
| 86 | { |
|---|
| 87 | global $conf; |
|---|
| 88 | |
|---|
| 89 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 90 | |
|---|
| 91 | // Exclusion of Adult_Content users |
|---|
| 92 | if ($register_user['username'] != "16" and $register_user['username'] != "18") |
|---|
| 93 | { |
|---|
| 94 | if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
|---|
| 95 | { |
|---|
| 96 | // This is to send an information email and set user to "waiting" group or status until admin validation |
|---|
| 97 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
|---|
| 98 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
|---|
| 99 | setgroup($register_user['id']);// Set to "waiting" group or status until admin validation |
|---|
| 100 | } |
|---|
| 101 | elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
|---|
| 102 | { |
|---|
| 103 | // This is to set user to "waiting" group or status until admin validation |
|---|
| 104 | setgroup($register_user['id']);// Set to "waiting" group or status until admin validation |
|---|
| 105 | } |
|---|
| 106 | elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'false')) |
|---|
| 107 | { |
|---|
| 108 | // This is to send an information email without validation key |
|---|
| 109 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
|---|
| 110 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
|---|
| 111 | } |
|---|
| 112 | // Sending registration confirmation by email |
|---|
| 113 | elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true' or $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true')) |
|---|
| 114 | { |
|---|
| 115 | if (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'true') |
|---|
| 116 | { |
|---|
| 117 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
|---|
| 118 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
|---|
| 119 | } |
|---|
| 120 | elseif (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'false') |
|---|
| 121 | { |
|---|
| 122 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
|---|
| 123 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
|---|
| 124 | } |
|---|
| 125 | elseif (!is_admin()) |
|---|
| 126 | { |
|---|
| 127 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
|---|
| 128 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * Triggered on delete_user |
|---|
| 136 | * |
|---|
| 137 | * Database cleanup on user deletion |
|---|
| 138 | */ |
|---|
| 139 | function UAM_Deluser($user_id) |
|---|
| 140 | { |
|---|
| 141 | // Cleanup for ConfirmMail table |
|---|
| 142 | DeleteConfirmMail($user_id); |
|---|
| 143 | // Cleanup for LastVisit table |
|---|
| 144 | DeleteLastVisit($user_id); |
|---|
| 145 | // Cleanup Redirection settings |
|---|
| 146 | DeleteRedir($user_id); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | /** |
|---|
| 150 | * Triggered on register_user_check |
|---|
| 151 | * |
|---|
| 152 | * Additional controls on user registration check |
|---|
| 153 | */ |
|---|
| 154 | function UAM_RegistrationCheck($errors, $user) |
|---|
| 155 | { |
|---|
| 156 | global $conf; |
|---|
| 157 | |
|---|
| 158 | // Exclusion of Adult_Content users |
|---|
| 159 | if ($user['username'] != "16" and $user['username'] != "18") |
|---|
| 160 | { |
|---|
| 161 | load_language('plugin.lang', UAM_PATH); |
|---|
| 162 | |
|---|
| 163 | $PasswordCheck = 0; |
|---|
| 164 | |
|---|
| 165 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 166 | |
|---|
| 167 | // Password enforcement control |
|---|
| 168 | if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14])) |
|---|
| 169 | { |
|---|
| 170 | if (!empty($user['password']) and !is_admin()) |
|---|
| 171 | { |
|---|
| 172 | $PasswordCheck = testpassword($user['password']); |
|---|
| 173 | |
|---|
| 174 | if ($PasswordCheck < $conf_UAM[14]) |
|---|
| 175 | { |
|---|
| 176 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
|---|
| 177 | $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]; |
|---|
| 178 | array_push($errors, $lang['reg_err_pass']); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | else if (!empty($user['password']) and is_admin() and isset($conf_UAM[15]) and $conf_UAM[15] == 'true') |
|---|
| 182 | { |
|---|
| 183 | $PasswordCheck = testpassword($user['password']); |
|---|
| 184 | |
|---|
| 185 | if ($PasswordCheck < $conf_UAM[14]) |
|---|
| 186 | { |
|---|
| 187 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
|---|
| 188 | $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]; |
|---|
| 189 | array_push($errors, $lang['reg_err_pass']); |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | // Username without forbidden keys |
|---|
| 195 | if (isset($conf_UAM[6]) and $conf_UAM[6] == 'true' and !empty($user['username']) and ValidateUsername($user['username']) and !is_admin()) |
|---|
| 196 | { |
|---|
| 197 | $lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_UAM[7]."'"; |
|---|
| 198 | array_push($errors, $lang['reg_err_login1']); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | // Email without forbidden domains |
|---|
| 202 | if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($user['email']) and ValidateEmailProvider($user['email']) and !is_admin()) |
|---|
| 203 | { |
|---|
| 204 | $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_UAM[12]."'"; |
|---|
| 205 | array_push($errors, $lang['reg_err_login1']); |
|---|
| 206 | } |
|---|
| 207 | return $errors; |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | /** |
|---|
| 212 | * Triggered on loc_begin_profile |
|---|
| 213 | */ |
|---|
| 214 | function UAM_Profile_Init() |
|---|
| 215 | { |
|---|
| 216 | global $conf, $user, $template; |
|---|
| 217 | |
|---|
| 218 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 219 | |
|---|
| 220 | if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true')) |
|---|
| 221 | { |
|---|
| 222 | $user_idsOK = array(); |
|---|
| 223 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
|---|
| 224 | { |
|---|
| 225 | $user_idsOK[] = $user['id']; |
|---|
| 226 | |
|---|
| 227 | $query = " |
|---|
| 228 | UPDATE ".CONFIG_TABLE." |
|---|
| 229 | SET value = \"".implode(',', $user_idsOK)."\" |
|---|
| 230 | WHERE param = 'UserAdvManager_Redir';"; |
|---|
| 231 | |
|---|
| 232 | pwg_query($query); |
|---|
| 233 | } |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | if (isset($_POST['validate']) and !is_admin()) |
|---|
| 237 | { |
|---|
| 238 | // Email without forbidden domains |
|---|
| 239 | if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['mail_address'])) |
|---|
| 240 | { |
|---|
| 241 | if (ValidateEmailProvider($_POST['mail_address'])) |
|---|
| 242 | { |
|---|
| 243 | $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'"); |
|---|
| 244 | unset($_POST['validate']); |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | $typemail = 3; |
|---|
| 249 | |
|---|
| 250 | if (!empty($_POST['use_new_pwd'])) |
|---|
| 251 | { |
|---|
| 252 | $typemail = 2; |
|---|
| 253 | |
|---|
| 254 | // Password enforcement control |
|---|
| 255 | if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14])) |
|---|
| 256 | { |
|---|
| 257 | $PasswordCheck = testpassword($_POST['use_new_pwd']); |
|---|
| 258 | |
|---|
| 259 | if ($PasswordCheck < $conf_UAM[14]) |
|---|
| 260 | { |
|---|
| 261 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
|---|
| 262 | $template->append('errors', l10n_args($message).$conf_UAM[14]); |
|---|
| 263 | unset($_POST['use_new_pwd']); |
|---|
| 264 | unset($_POST['validate']); |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | // Sending registration confirmation by email |
|---|
| 270 | if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
|---|
| 271 | { |
|---|
| 272 | $confirm_mail_need = false; |
|---|
| 273 | |
|---|
| 274 | if (!empty($_POST['mail_address'])) |
|---|
| 275 | { |
|---|
| 276 | $query = ' |
|---|
| 277 | SELECT '.$conf['user_fields']['email'].' AS email |
|---|
| 278 | FROM '.USERS_TABLE.' |
|---|
| 279 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
|---|
| 280 | ;'; |
|---|
| 281 | |
|---|
| 282 | list($current_email) = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 283 | |
|---|
| 284 | // This is to send a new validation key |
|---|
| 285 | if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true')) |
|---|
| 286 | |
|---|
| 287 | $confirm_mail_need = true; |
|---|
| 288 | |
|---|
| 289 | // This is to set the user to "waiting" group or status until admin validation |
|---|
| 290 | if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
|---|
| 291 | |
|---|
| 292 | setgroup($register_user['id']);// Set to "waiting" group or status until admin validation |
|---|
| 293 | $confirm_mail_need = false; |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | if ((!empty($_POST['use_new_pwd']) and (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or $confirm_mail_need)) |
|---|
| 297 | { |
|---|
| 298 | $query = ' |
|---|
| 299 | SELECT '.$conf['user_fields']['username'].' |
|---|
| 300 | FROM '.USERS_TABLE.' |
|---|
| 301 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
|---|
| 302 | ;'; |
|---|
| 303 | |
|---|
| 304 | list($username) = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 305 | SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need); |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | /** |
|---|
| 312 | * Triggered on login_success |
|---|
| 313 | * |
|---|
| 314 | * Triggers scheduled tasks at login |
|---|
| 315 | * Redirects a visitor (except for admins, webmasters and generic statuses) to his profile.php page (Thx to LucMorizur) |
|---|
| 316 | * |
|---|
| 317 | */ |
|---|
| 318 | function UAM_LoginTasks() |
|---|
| 319 | { |
|---|
| 320 | global $conf, $user; |
|---|
| 321 | |
|---|
| 322 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 323 | |
|---|
| 324 | // Performing scheduled tasks |
|---|
| 325 | if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true')) |
|---|
| 326 | { |
|---|
| 327 | UAM_ScheduledTasks(); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true')) |
|---|
| 331 | { |
|---|
| 332 | // Performing redirection |
|---|
| 333 | $query =' |
|---|
| 334 | SELECT user_id, status |
|---|
| 335 | FROM '.USER_INFOS_TABLE.' |
|---|
| 336 | WHERE user_id = '.$user['id'].' |
|---|
| 337 | ;'; |
|---|
| 338 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 339 | |
|---|
| 340 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster" and $data['status'] <> "generic") |
|---|
| 341 | { |
|---|
| 342 | $user_idsOK = array(); |
|---|
| 343 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
|---|
| 344 | redirect(PHPWG_ROOT_PATH.'profile.php'); |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | /** |
|---|
| 350 | * Triggered on UAM_LoginTasks() |
|---|
| 351 | * |
|---|
| 352 | * Executes optional post-login tasks |
|---|
| 353 | * |
|---|
| 354 | */ |
|---|
| 355 | function UAM_ScheduledTasks() |
|---|
| 356 | { |
|---|
| 357 | global $conf, $user, $page; |
|---|
| 358 | |
|---|
| 359 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 360 | |
|---|
| 361 | $collection = array(); |
|---|
| 362 | $reminder = false; |
|---|
| 363 | |
|---|
| 364 | $page['filtered_users'] = get_ghosts_autotasks(); |
|---|
| 365 | |
|---|
| 366 | foreach($page['filtered_users'] as $listed_user) |
|---|
| 367 | { |
|---|
| 368 | array_push($collection, $listed_user['id']); |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | // Ghost accounts auto group or status downgrade with or without information email sending and autodeletion if user already reminded |
|---|
| 372 | if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true') and ((isset($conf_UAM[26]) and $conf_UAM[26] <> -1) or (isset($conf_UAM[27]) and $conf_UAM[27] <> -1))) |
|---|
| 373 | { |
|---|
| 374 | if (count($collection) > 0) |
|---|
| 375 | { |
|---|
| 376 | // Process if a non-admin nor webmaster user is logged |
|---|
| 377 | if (in_array($user['id'], $collection)) |
|---|
| 378 | { |
|---|
| 379 | foreach ($collection as $user_id) |
|---|
| 380 | { |
|---|
| 381 | // Check lastvisit reminder state |
|---|
| 382 | $query = ' |
|---|
| 383 | SELECT reminder |
|---|
| 384 | FROM '.USER_LASTVISIT_TABLE.' |
|---|
| 385 | WHERE user_id = '.$user_id.';'; |
|---|
| 386 | |
|---|
| 387 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 388 | |
|---|
| 389 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
|---|
| 390 | { |
|---|
| 391 | $reminder = true; |
|---|
| 392 | } |
|---|
| 393 | else |
|---|
| 394 | { |
|---|
| 395 | $reminder = false; |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | // If never reminded before, set reminder True |
|---|
| 399 | if (!$reminder) |
|---|
| 400 | { |
|---|
| 401 | // Reset of lastvisit date |
|---|
| 402 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 403 | |
|---|
| 404 | $query = " |
|---|
| 405 | UPDATE ".USER_LASTVISIT_TABLE." |
|---|
| 406 | SET lastvisit='".$dbnow."' |
|---|
| 407 | WHERE user_id = '".$user_id."' |
|---|
| 408 | ;"; |
|---|
| 409 | pwg_query($query); |
|---|
| 410 | |
|---|
| 411 | // Auto change group and / or status |
|---|
| 412 | // Delete user from all groups |
|---|
| 413 | $query = " |
|---|
| 414 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 415 | WHERE user_id = '".$user_id."' |
|---|
| 416 | AND ( |
|---|
| 417 | group_id = '".$conf_UAM[2]."' |
|---|
| 418 | OR |
|---|
| 419 | group_id = '".$conf_UAM[3]."' |
|---|
| 420 | ) |
|---|
| 421 | ;"; |
|---|
| 422 | |
|---|
| 423 | pwg_query($query); |
|---|
| 424 | |
|---|
| 425 | // Change user status |
|---|
| 426 | if ($conf_UAM[27] <> -1) |
|---|
| 427 | { |
|---|
| 428 | $query = " |
|---|
| 429 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 430 | SET status = '".$conf_UAM[27]."' |
|---|
| 431 | WHERE user_id = '".$user_id."' |
|---|
| 432 | ;"; |
|---|
| 433 | pwg_query($query); |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | // Change user group |
|---|
| 437 | if ($conf_UAM[26] <> -1) |
|---|
| 438 | { |
|---|
| 439 | $query = " |
|---|
| 440 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 441 | (user_id, group_id) |
|---|
| 442 | VALUES |
|---|
| 443 | ('".$user_id."', '".$conf_UAM[26]."') |
|---|
| 444 | ;"; |
|---|
| 445 | pwg_query($query); |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | // Auto send email notification on group / status downgrade only if never reminded before |
|---|
| 449 | if (isset($conf_UAM[23]) and $conf_UAM[23] == 'true') |
|---|
| 450 | { |
|---|
| 451 | // Set reminder true |
|---|
| 452 | $query = " |
|---|
| 453 | UPDATE ".USER_LASTVISIT_TABLE." |
|---|
| 454 | SET reminder = 'true' |
|---|
| 455 | WHERE user_id = '".$user_id."' |
|---|
| 456 | ;"; |
|---|
| 457 | pwg_query($query); |
|---|
| 458 | |
|---|
| 459 | // Reset confirmed user date_check |
|---|
| 460 | $query = ' |
|---|
| 461 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
|---|
| 462 | SET date_check = NULL |
|---|
| 463 | WHERE user_id = "'.$user_id.'" |
|---|
| 464 | ;'; |
|---|
| 465 | pwg_query($query); |
|---|
| 466 | |
|---|
| 467 | // Get users information for email notification |
|---|
| 468 | $query = ' |
|---|
| 469 | SELECT username, mail_address |
|---|
| 470 | FROM '.USERS_TABLE.' |
|---|
| 471 | WHERE id = '.$user_id.' |
|---|
| 472 | ;'; |
|---|
| 473 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 474 | |
|---|
| 475 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
|---|
| 476 | } |
|---|
| 477 | } |
|---|
| 478 | elseif ($reminder) // If user already reminded for ghost account |
|---|
| 479 | { |
|---|
| 480 | // delete account |
|---|
| 481 | delete_user($user_id); |
|---|
| 482 | } |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | if (!$reminder) // If user never reminded for ghost account |
|---|
| 486 | { |
|---|
| 487 | // Logged-in user cleanup |
|---|
| 488 | invalidate_user_cache(); |
|---|
| 489 | log_user($user['id'], false); |
|---|
| 490 | redirect(make_index_url()); |
|---|
| 491 | } |
|---|
| 492 | elseif ($reminder) // If user already reminded for ghost account |
|---|
| 493 | { |
|---|
| 494 | // Logged-in user cleanup |
|---|
| 495 | invalidate_user_cache(); |
|---|
| 496 | log_user($user['id'], false); |
|---|
| 497 | redirect(UAM_PATH.'del_account.php'); |
|---|
| 498 | } |
|---|
| 499 | } |
|---|
| 500 | else // Process if an admin or webmaster user is logged |
|---|
| 501 | { |
|---|
| 502 | foreach ($collection as $user_id) |
|---|
| 503 | { |
|---|
| 504 | // Check lastvisit reminder state |
|---|
| 505 | $query = ' |
|---|
| 506 | SELECT reminder |
|---|
| 507 | FROM '.USER_LASTVISIT_TABLE.' |
|---|
| 508 | WHERE user_id = '.$user_id.';'; |
|---|
| 509 | |
|---|
| 510 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 511 | |
|---|
| 512 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
|---|
| 513 | { |
|---|
| 514 | $reminder = true; |
|---|
| 515 | } |
|---|
| 516 | else |
|---|
| 517 | { |
|---|
| 518 | $reminder = false; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | // If never reminded before |
|---|
| 522 | if (!$reminder) |
|---|
| 523 | { |
|---|
| 524 | // Reset of lastvisit date |
|---|
| 525 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 526 | |
|---|
| 527 | $query = " |
|---|
| 528 | UPDATE ".USER_LASTVISIT_TABLE." |
|---|
| 529 | SET lastvisit='".$dbnow."' |
|---|
| 530 | WHERE user_id = '".$user_id."' |
|---|
| 531 | ;"; |
|---|
| 532 | pwg_query($query); |
|---|
| 533 | |
|---|
| 534 | // Auto change group and / or status |
|---|
| 535 | // Delete user from all groups |
|---|
| 536 | $query = " |
|---|
| 537 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 538 | WHERE user_id = '".$user_id."' |
|---|
| 539 | AND ( |
|---|
| 540 | group_id = '".$conf_UAM[2]."' |
|---|
| 541 | OR |
|---|
| 542 | group_id = '".$conf_UAM[3]."' |
|---|
| 543 | ) |
|---|
| 544 | ;"; |
|---|
| 545 | pwg_query($query); |
|---|
| 546 | |
|---|
| 547 | // Change user status |
|---|
| 548 | if ($conf_UAM[27] <> -1) |
|---|
| 549 | { |
|---|
| 550 | $query = " |
|---|
| 551 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 552 | SET status = '".$conf_UAM[27]."' |
|---|
| 553 | WHERE user_id = '".$user_id."' |
|---|
| 554 | ;"; |
|---|
| 555 | pwg_query($query); |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | // Change user group |
|---|
| 559 | if ($conf_UAM[26] <> -1) |
|---|
| 560 | { |
|---|
| 561 | $query = " |
|---|
| 562 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 563 | (user_id, group_id) |
|---|
| 564 | VALUES |
|---|
| 565 | ('".$user_id."', '".$conf_UAM[26]."') |
|---|
| 566 | ;"; |
|---|
| 567 | pwg_query($query); |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | // Auto send email notification on group / status downgrade |
|---|
| 571 | if (isset($conf_UAM[23]) and $conf_UAM[23] == 'true') |
|---|
| 572 | { |
|---|
| 573 | // Set reminder true |
|---|
| 574 | $query = " |
|---|
| 575 | UPDATE ".USER_LASTVISIT_TABLE." |
|---|
| 576 | SET reminder = 'true' |
|---|
| 577 | WHERE user_id = '".$user_id."' |
|---|
| 578 | ;"; |
|---|
| 579 | pwg_query($query); |
|---|
| 580 | |
|---|
| 581 | // Reset confirmed user status to unvalidated |
|---|
| 582 | $query = ' |
|---|
| 583 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
|---|
| 584 | SET date_check = NULL |
|---|
| 585 | WHERE user_id = "'.$user_id.'" |
|---|
| 586 | ;'; |
|---|
| 587 | pwg_query($query); |
|---|
| 588 | |
|---|
| 589 | // Get users information for email notification |
|---|
| 590 | $query = ' |
|---|
| 591 | SELECT id, username, mail_address |
|---|
| 592 | FROM '.USERS_TABLE.' |
|---|
| 593 | WHERE id = '.$user_id.' |
|---|
| 594 | ;'; |
|---|
| 595 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 596 | |
|---|
| 597 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
|---|
| 598 | } |
|---|
| 599 | } |
|---|
| 600 | elseif ($reminder) // If user already reminded for ghost account |
|---|
| 601 | { |
|---|
| 602 | // delete account |
|---|
| 603 | delete_user($user_id); |
|---|
| 604 | } |
|---|
| 605 | } |
|---|
| 606 | } |
|---|
| 607 | } |
|---|
| 608 | } |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | /** |
|---|
| 612 | * Triggered on init |
|---|
| 613 | * |
|---|
| 614 | * Check for forbidden email domains in admin's users management panel |
|---|
| 615 | */ |
|---|
| 616 | function UAM_InitPage() |
|---|
| 617 | { |
|---|
| 618 | load_language('plugin.lang', UAM_PATH); |
|---|
| 619 | global $conf, $template, $page, $lang, $errors; |
|---|
| 620 | |
|---|
| 621 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 622 | |
|---|
| 623 | // Admin user management |
|---|
| 624 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
|---|
| 625 | { |
|---|
| 626 | if (isset($_POST['submit_add'])) |
|---|
| 627 | { |
|---|
| 628 | // Email without forbidden domains |
|---|
| 629 | if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email'])) |
|---|
| 630 | { |
|---|
| 631 | $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'"); |
|---|
| 632 | unset($_POST['submit_add']); |
|---|
| 633 | } |
|---|
| 634 | } |
|---|
| 635 | } |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | /** |
|---|
| 640 | * Triggered on render_lost_password_mail_content |
|---|
| 641 | * |
|---|
| 642 | * Adds a customized text in lost password email content |
|---|
| 643 | * Added text is inserted before users login name and new password |
|---|
| 644 | * |
|---|
| 645 | * @param : Standard Piwigo email content |
|---|
| 646 | * |
|---|
| 647 | * @return : Customized content added to standard content |
|---|
| 648 | * |
|---|
| 649 | */ |
|---|
| 650 | function UAM_lost_password_mail_content($infos) |
|---|
| 651 | { |
|---|
| 652 | global $conf; |
|---|
| 653 | |
|---|
| 654 | load_language('plugin.lang', UAM_PATH); |
|---|
| 655 | |
|---|
| 656 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 657 | |
|---|
| 658 | if (isset($conf_UAM[29]) and $conf_UAM[29] == 'true') |
|---|
| 659 | { |
|---|
| 660 | $infos = $conf_UAM[30]."\n"."\n".$infos; |
|---|
| 661 | } |
|---|
| 662 | return $infos; |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | /** |
|---|
| 667 | * Triggered on user_comment_check |
|---|
| 668 | * |
|---|
| 669 | * checks if author is mandatory and set on comments post |
|---|
| 670 | * |
|---|
| 671 | * @param : comment action, comment |
|---|
| 672 | * |
|---|
| 673 | * @return : comment action |
|---|
| 674 | * |
|---|
| 675 | */ |
|---|
| 676 | function UAM_CheckEmptyCommentAuthor($comment_action, $comm) |
|---|
| 677 | { |
|---|
| 678 | load_language('plugin.lang', UAM_PATH); |
|---|
| 679 | global $infos, $conf, $template; |
|---|
| 680 | |
|---|
| 681 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 682 | |
|---|
| 683 | // User creation OR update |
|---|
| 684 | if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest') |
|---|
| 685 | { |
|---|
| 686 | $comment_action = 'reject'; |
|---|
| 687 | |
|---|
| 688 | array_push($infos, l10n('UAM_Empty Author')); |
|---|
| 689 | } |
|---|
| 690 | |
|---|
| 691 | return $comment_action; |
|---|
| 692 | } |
|---|
| 693 | |
|---|
| 694 | /** |
|---|
| 695 | * Function called from main.inc.php to send validation email |
|---|
| 696 | * |
|---|
| 697 | * @param : Type of email, user id, username, email address, confirmation (optional) |
|---|
| 698 | * |
|---|
| 699 | */ |
|---|
| 700 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
|---|
| 701 | { |
|---|
| 702 | global $conf; |
|---|
| 703 | |
|---|
| 704 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 705 | |
|---|
| 706 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
|---|
| 707 | |
|---|
| 708 | $infos1_perso = ""; |
|---|
| 709 | $infos2_perso = ""; |
|---|
| 710 | |
|---|
| 711 | // We have to get the user's language in database |
|---|
| 712 | $query =' |
|---|
| 713 | SELECT user_id, language |
|---|
| 714 | FROM '.USER_INFOS_TABLE.' |
|---|
| 715 | WHERE user_id = '.$id.' |
|---|
| 716 | ;'; |
|---|
| 717 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 718 | |
|---|
| 719 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
|---|
| 720 | if (empty($data)) |
|---|
| 721 | { |
|---|
| 722 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 723 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
|---|
| 724 | switch_lang_to($language); |
|---|
| 725 | } |
|---|
| 726 | else |
|---|
| 727 | { |
|---|
| 728 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 729 | $language = $data['language']; // Usefull for debugging |
|---|
| 730 | switch_lang_to($data['language']); |
|---|
| 731 | load_language('plugin.lang', UAM_PATH); |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | switch($typemail) |
|---|
| 735 | { |
|---|
| 736 | case 1: |
|---|
| 737 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', stripslashes($username))); |
|---|
| 738 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
|---|
| 739 | |
|---|
| 740 | if (isset($conf_UAM[9]) and $conf_UAM[9] <> '') |
|---|
| 741 | { |
|---|
| 742 | if (function_exists('get_user_language_desc')) |
|---|
| 743 | { |
|---|
| 744 | $infos1_perso = get_user_language_desc($conf_UAM[9])."\n\n"; |
|---|
| 745 | } |
|---|
| 746 | else $infos1_perso = l10n($conf_UAM[9])."\n\n"; |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | break; |
|---|
| 750 | |
|---|
| 751 | case 2: |
|---|
| 752 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
|---|
| 753 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
|---|
| 754 | |
|---|
| 755 | break; |
|---|
| 756 | |
|---|
| 757 | case 3: |
|---|
| 758 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username))); |
|---|
| 759 | $password = $password <> '' ? $password : l10n('UAM_no_update_pwd'); |
|---|
| 760 | |
|---|
| 761 | break; |
|---|
| 762 | } |
|---|
| 763 | |
|---|
| 764 | if (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') |
|---|
| 765 | { |
|---|
| 766 | $infos1 = array( |
|---|
| 767 | get_l10n_args('infos_mail %s', stripslashes($username)), |
|---|
| 768 | get_l10n_args('User: %s', stripslashes($username)), |
|---|
| 769 | get_l10n_args('Password: %s', $password), |
|---|
| 770 | get_l10n_args('Email: %s', $email), |
|---|
| 771 | get_l10n_args('', ''), |
|---|
| 772 | ); |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | if ( isset($conf_UAM[1]) and $conf_UAM[1] == 'true' and $confirm) |
|---|
| 777 | { |
|---|
| 778 | $infos2 = array |
|---|
| 779 | ( |
|---|
| 780 | get_l10n_args('Link: %s', AddConfirmMail($id, $email)), |
|---|
| 781 | get_l10n_args('', ''), |
|---|
| 782 | ); |
|---|
| 783 | |
|---|
| 784 | if (isset($conf_UAM[10]) and $conf_UAM[10] <> '') |
|---|
| 785 | { |
|---|
| 786 | if (function_exists('get_user_language_desc')) |
|---|
| 787 | { |
|---|
| 788 | $infos2_perso = get_user_language_desc($conf_UAM[10])."\n\n"; |
|---|
| 789 | } |
|---|
| 790 | else $infos2_perso = l10n($conf_UAM[10])."\n\n"; |
|---|
| 791 | } |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | // ******************************************************** |
|---|
| 795 | // **** Pending code since to find how to make it work **** |
|---|
| 796 | // ******************************************************** |
|---|
| 797 | // Testing if FCK Editor is used. Then decoding htmlchars to avoid problems with pwg_mail() |
|---|
| 798 | /*$areas = array(); |
|---|
| 799 | array_push( $areas,'UAM_MailInfo_Text','UAM_ConfirmMail_Text'); |
|---|
| 800 | |
|---|
| 801 | if (function_exists('set_fckeditor_instance')) |
|---|
| 802 | { |
|---|
| 803 | $fcke_config = unserialize($conf['FCKEditor']); |
|---|
| 804 | foreach($areas as $area) |
|---|
| 805 | { |
|---|
| 806 | if (isset($fcke_config['UAM_MailInfo_Text']) and $fcke_config['UAM_MailInfo_Text'] = true) |
|---|
| 807 | { |
|---|
| 808 | $infos1_perso = html_entity_decode($infos1_perso,ENT_QUOTES,UTF-8); |
|---|
| 809 | } |
|---|
| 810 | |
|---|
| 811 | if (isset($fcke_config['UAM_ConfirmMail_Text']) and $fcke_config['UAM_ConfirmMail_Text'] = true) |
|---|
| 812 | { |
|---|
| 813 | $infos2_perso = html_entity_decode($infos2_perso,ENT_QUOTES,UTF-8); |
|---|
| 814 | } |
|---|
| 815 | } |
|---|
| 816 | }*/ |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | // Sending the email with subject and contents |
|---|
| 820 | pwg_mail($email, array( |
|---|
| 821 | 'subject' => $subject, |
|---|
| 822 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
|---|
| 823 | )); |
|---|
| 824 | |
|---|
| 825 | // ********************** |
|---|
| 826 | // Email sending debugger |
|---|
| 827 | // This is only to trace |
|---|
| 828 | // the send of emails for |
|---|
| 829 | // debugging |
|---|
| 830 | // ********************** |
|---|
| 831 | //$content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
|---|
| 832 | //MailLog($email,$subject,$content,$language); |
|---|
| 833 | // ********************** |
|---|
| 834 | |
|---|
| 835 | // Switching back to default language |
|---|
| 836 | switch_lang_back(); |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | /** |
|---|
| 840 | * Function called from UAM_admin.php to resend validation email with or without new validation key |
|---|
| 841 | * |
|---|
| 842 | * @param : Type of email, user id, username, email address, confirmation (optional) |
|---|
| 843 | * |
|---|
| 844 | */ |
|---|
| 845 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
|---|
| 846 | { |
|---|
| 847 | global $conf; |
|---|
| 848 | |
|---|
| 849 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 850 | |
|---|
| 851 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
|---|
| 852 | |
|---|
| 853 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
|---|
| 854 | |
|---|
| 855 | // We have to get the user's language in database |
|---|
| 856 | $query =' |
|---|
| 857 | SELECT user_id, language |
|---|
| 858 | FROM '.USER_INFOS_TABLE.' |
|---|
| 859 | WHERE user_id = '.$user_id.' |
|---|
| 860 | ;'; |
|---|
| 861 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 862 | $language = $data['language']; |
|---|
| 863 | |
|---|
| 864 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 865 | switch_lang_to($data['language']); |
|---|
| 866 | |
|---|
| 867 | load_language('plugin.lang', UAM_PATH); |
|---|
| 868 | |
|---|
| 869 | switch($typemail) |
|---|
| 870 | { |
|---|
| 871 | case 1: |
|---|
| 872 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_with_key_of_%s', $username)); |
|---|
| 873 | |
|---|
| 874 | 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) |
|---|
| 875 | { |
|---|
| 876 | if (function_exists('get_user_language_desc')) |
|---|
| 877 | { |
|---|
| 878 | $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n"; |
|---|
| 879 | } |
|---|
| 880 | else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n"; |
|---|
| 881 | |
|---|
| 882 | $infos2 = array |
|---|
| 883 | ( |
|---|
| 884 | get_l10n_args('Link: %s', ResetConfirmMail($user_id)), |
|---|
| 885 | get_l10n_args('', ''), |
|---|
| 886 | ); |
|---|
| 887 | } |
|---|
| 888 | |
|---|
| 889 | // Set reminder true |
|---|
| 890 | $query = " |
|---|
| 891 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 892 | SET reminder = 'true' |
|---|
| 893 | WHERE user_id = '".$user_id."' |
|---|
| 894 | ;"; |
|---|
| 895 | pwg_query($query); |
|---|
| 896 | |
|---|
| 897 | break; |
|---|
| 898 | |
|---|
| 899 | case 2: |
|---|
| 900 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Reminder_without_key_of_%s',$username)); |
|---|
| 901 | |
|---|
| 902 | 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) |
|---|
| 903 | { |
|---|
| 904 | if (function_exists('get_user_language_desc')) |
|---|
| 905 | { |
|---|
| 906 | $infos1 = get_user_language_desc($conf_UAM_ConfirmMail[2])."\n\n"; |
|---|
| 907 | } |
|---|
| 908 | else $infos1 = l10n($conf_UAM_ConfirmMail[2])."\n\n"; |
|---|
| 909 | } |
|---|
| 910 | |
|---|
| 911 | // Set reminder true |
|---|
| 912 | $query = " |
|---|
| 913 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 914 | SET reminder = 'true' |
|---|
| 915 | WHERE user_id = '".$user_id."' |
|---|
| 916 | ;"; |
|---|
| 917 | pwg_query($query); |
|---|
| 918 | |
|---|
| 919 | break; |
|---|
| 920 | } |
|---|
| 921 | |
|---|
| 922 | pwg_mail($email, array( |
|---|
| 923 | 'subject' => $subject, |
|---|
| 924 | 'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
|---|
| 925 | )); |
|---|
| 926 | |
|---|
| 927 | // ********************** |
|---|
| 928 | // Email sending debugger |
|---|
| 929 | // This is only to trace |
|---|
| 930 | // the send of emails for |
|---|
| 931 | // debugging |
|---|
| 932 | // ********************** |
|---|
| 933 | //$content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(); |
|---|
| 934 | //MailLog($email,$subject,$content,$language); |
|---|
| 935 | // ********************** |
|---|
| 936 | |
|---|
| 937 | // Switching back to default language |
|---|
| 938 | switch_lang_back(); |
|---|
| 939 | } |
|---|
| 940 | |
|---|
| 941 | /** |
|---|
| 942 | * Function called from UAM_admin.php to send a reminder mail for ghost users |
|---|
| 943 | * |
|---|
| 944 | * @param : User id, username, email address |
|---|
| 945 | * |
|---|
| 946 | */ |
|---|
| 947 | function ghostreminder($user_id, $username, $email) |
|---|
| 948 | { |
|---|
| 949 | global $conf; |
|---|
| 950 | |
|---|
| 951 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 952 | |
|---|
| 953 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
|---|
| 954 | |
|---|
| 955 | $infos1_perso = ""; |
|---|
| 956 | |
|---|
| 957 | // We have to get the user's language in database |
|---|
| 958 | $query =' |
|---|
| 959 | SELECT user_id, language |
|---|
| 960 | FROM '.USER_INFOS_TABLE.' |
|---|
| 961 | WHERE user_id = '.$user_id.' |
|---|
| 962 | ;'; |
|---|
| 963 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 964 | $language = $data['language']; |
|---|
| 965 | |
|---|
| 966 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 967 | switch_lang_to($data['language']); |
|---|
| 968 | |
|---|
| 969 | load_language('plugin.lang', UAM_PATH); |
|---|
| 970 | |
|---|
| 971 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Ghost_reminder_of_%s', $username)); |
|---|
| 972 | |
|---|
| 973 | if (isset($conf_UAM[18]) and $conf_UAM[18] <> '' and isset($conf_UAM[16]) and $conf_UAM[16] == 'true') |
|---|
| 974 | { |
|---|
| 975 | if (function_exists('get_user_language_desc')) |
|---|
| 976 | { |
|---|
| 977 | $infos1 = get_user_language_desc($conf_UAM[18])."\n\n"; |
|---|
| 978 | } |
|---|
| 979 | else |
|---|
| 980 | { |
|---|
| 981 | $infos1 = l10n($conf_UAM[18])."\n\n"; |
|---|
| 982 | } |
|---|
| 983 | |
|---|
| 984 | resetlastvisit($user_id); |
|---|
| 985 | } |
|---|
| 986 | |
|---|
| 987 | pwg_mail($email, array( |
|---|
| 988 | 'subject' => $subject, |
|---|
| 989 | 'content' => $infos1.get_absolute_root_url(), |
|---|
| 990 | )); |
|---|
| 991 | |
|---|
| 992 | // ********************** |
|---|
| 993 | // Email sending debugger |
|---|
| 994 | // This is only to trace |
|---|
| 995 | // the send of emails for |
|---|
| 996 | // debugging |
|---|
| 997 | // ********************** |
|---|
| 998 | //$content = $infos1.get_absolute_root_url(); |
|---|
| 999 | //MailLog($email,$subject,$content,$language); |
|---|
| 1000 | // ********************** |
|---|
| 1001 | |
|---|
| 1002 | // Switching back to default language |
|---|
| 1003 | switch_lang_back(); |
|---|
| 1004 | } |
|---|
| 1005 | |
|---|
| 1006 | /** |
|---|
| 1007 | * Function called from functions.inc.php to send notification email when user have been downgraded |
|---|
| 1008 | * |
|---|
| 1009 | * @param : user id, username, email address |
|---|
| 1010 | * |
|---|
| 1011 | */ |
|---|
| 1012 | function demotion_mail($id, $username, $email) |
|---|
| 1013 | { |
|---|
| 1014 | global $conf; |
|---|
| 1015 | |
|---|
| 1016 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1017 | |
|---|
| 1018 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
|---|
| 1019 | |
|---|
| 1020 | $custom_txt = ""; |
|---|
| 1021 | |
|---|
| 1022 | // We have to get the user's language in database |
|---|
| 1023 | $query =' |
|---|
| 1024 | SELECT user_id, language |
|---|
| 1025 | FROM '.USER_INFOS_TABLE.' |
|---|
| 1026 | WHERE user_id = '.$id.' |
|---|
| 1027 | ;'; |
|---|
| 1028 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 1029 | |
|---|
| 1030 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
|---|
| 1031 | if (empty($data)) |
|---|
| 1032 | { |
|---|
| 1033 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 1034 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
|---|
| 1035 | switch_lang_to($language); |
|---|
| 1036 | } |
|---|
| 1037 | else |
|---|
| 1038 | { |
|---|
| 1039 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 1040 | $language = $data['language']; // Usefull for debugging |
|---|
| 1041 | switch_lang_to($data['language']); |
|---|
| 1042 | load_language('plugin.lang', UAM_PATH); |
|---|
| 1043 | } |
|---|
| 1044 | |
|---|
| 1045 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Demotion of %s', stripslashes($username))); |
|---|
| 1046 | |
|---|
| 1047 | if (isset($conf_UAM[25]) and $conf_UAM[25] <> '') |
|---|
| 1048 | { |
|---|
| 1049 | if (function_exists('get_user_language_desc')) |
|---|
| 1050 | { |
|---|
| 1051 | $custom_txt = get_user_language_desc($conf_UAM[25])."\n\n"; |
|---|
| 1052 | } |
|---|
| 1053 | else $custom_txt = l10n($conf_UAM[25])."\n\n"; |
|---|
| 1054 | } |
|---|
| 1055 | |
|---|
| 1056 | $infos1 = array( |
|---|
| 1057 | get_l10n_args('User: %s', stripslashes($username)), |
|---|
| 1058 | get_l10n_args('Email: %s', $email), |
|---|
| 1059 | get_l10n_args('', ''), |
|---|
| 1060 | ); |
|---|
| 1061 | |
|---|
| 1062 | $infos2 = array |
|---|
| 1063 | ( |
|---|
| 1064 | get_l10n_args('Link: %s', ResetConfirmMail($id)), |
|---|
| 1065 | get_l10n_args('', ''), |
|---|
| 1066 | ); |
|---|
| 1067 | |
|---|
| 1068 | |
|---|
| 1069 | // Sending the email with subject and contents |
|---|
| 1070 | pwg_mail($email, array( |
|---|
| 1071 | 'subject' => $subject, |
|---|
| 1072 | 'content' => ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(), |
|---|
| 1073 | )); |
|---|
| 1074 | |
|---|
| 1075 | // ********************** |
|---|
| 1076 | // Email sending debugger |
|---|
| 1077 | // This is only to trace |
|---|
| 1078 | // the send of emails for |
|---|
| 1079 | // debugging |
|---|
| 1080 | // ********************** |
|---|
| 1081 | //$content = ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(); |
|---|
| 1082 | //MailLog($email,$subject,$content,$language); |
|---|
| 1083 | // ********************** |
|---|
| 1084 | |
|---|
| 1085 | // Switching back to default language |
|---|
| 1086 | switch_lang_back(); |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|
| 1089 | /** |
|---|
| 1090 | * Function called from UAM_admin.php to send notification email when user registration have been manually validated by admin |
|---|
| 1091 | * |
|---|
| 1092 | * @param : user id |
|---|
| 1093 | * |
|---|
| 1094 | */ |
|---|
| 1095 | function validation_mail($id) |
|---|
| 1096 | { |
|---|
| 1097 | global $conf; |
|---|
| 1098 | |
|---|
| 1099 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1100 | |
|---|
| 1101 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
|---|
| 1102 | |
|---|
| 1103 | $custom_txt = ""; |
|---|
| 1104 | |
|---|
| 1105 | // We have to get the user's language in database |
|---|
| 1106 | $query =' |
|---|
| 1107 | SELECT user_id, language |
|---|
| 1108 | FROM '.USER_INFOS_TABLE.' |
|---|
| 1109 | WHERE user_id = '.$id.' |
|---|
| 1110 | ;'; |
|---|
| 1111 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 1112 | |
|---|
| 1113 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
|---|
| 1114 | if (empty($data)) |
|---|
| 1115 | { |
|---|
| 1116 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 1117 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
|---|
| 1118 | switch_lang_to($language); |
|---|
| 1119 | } |
|---|
| 1120 | else |
|---|
| 1121 | { |
|---|
| 1122 | // And switch gallery to this language before using personalized and multilangual contents |
|---|
| 1123 | $language = $data['language']; // Usefull for debugging |
|---|
| 1124 | switch_lang_to($data['language']); |
|---|
| 1125 | load_language('plugin.lang', UAM_PATH); |
|---|
| 1126 | } |
|---|
| 1127 | |
|---|
| 1128 | // Retreive users email and user name from id |
|---|
| 1129 | $query =' |
|---|
| 1130 | SELECT id, username, mail_address |
|---|
| 1131 | FROM '.USERS_TABLE.' |
|---|
| 1132 | WHERE id = '.$id.' |
|---|
| 1133 | ;'; |
|---|
| 1134 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 1135 | |
|---|
| 1136 | $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Validation of %s', stripslashes($result['username']))); |
|---|
| 1137 | |
|---|
| 1138 | if (isset($conf_UAM[28]) and $conf_UAM[28] <> '') |
|---|
| 1139 | { |
|---|
| 1140 | if (function_exists('get_user_language_desc')) |
|---|
| 1141 | { |
|---|
| 1142 | $custom_txt = get_user_language_desc($conf_UAM[28])."\n\n"; |
|---|
| 1143 | } |
|---|
| 1144 | else $custom_txt = l10n($conf_UAM[28])."\n\n"; |
|---|
| 1145 | } |
|---|
| 1146 | |
|---|
| 1147 | $infos = array( |
|---|
| 1148 | get_l10n_args('User: %s', stripslashes($result['username'])), |
|---|
| 1149 | get_l10n_args('Email: %s', $result['mail_address']), |
|---|
| 1150 | get_l10n_args('', ''), |
|---|
| 1151 | ); |
|---|
| 1152 | |
|---|
| 1153 | // Sending the email with subject and contents |
|---|
| 1154 | pwg_mail($result['mail_address'], array( |
|---|
| 1155 | 'subject' => $subject, |
|---|
| 1156 | 'content' => (l10n_args($infos)."\n\n".$custom_txt), |
|---|
| 1157 | )); |
|---|
| 1158 | |
|---|
| 1159 | // ********************** |
|---|
| 1160 | // Email sending debugger |
|---|
| 1161 | // This is only to trace |
|---|
| 1162 | // the send of emails for |
|---|
| 1163 | // debugging |
|---|
| 1164 | // ********************** |
|---|
| 1165 | //$email = $result['mail_address']; |
|---|
| 1166 | //$content = (l10n_args($infos)."\n\n".$custom_txt); |
|---|
| 1167 | //MailLog($email,$subject,$content,$language); |
|---|
| 1168 | // ********************** |
|---|
| 1169 | |
|---|
| 1170 | // Switching back to default language |
|---|
| 1171 | switch_lang_back(); |
|---|
| 1172 | } |
|---|
| 1173 | |
|---|
| 1174 | /** |
|---|
| 1175 | * Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation |
|---|
| 1176 | * |
|---|
| 1177 | * @return : validation key |
|---|
| 1178 | * |
|---|
| 1179 | */ |
|---|
| 1180 | function FindAvailableConfirmMailID() |
|---|
| 1181 | { |
|---|
| 1182 | while (true) |
|---|
| 1183 | { |
|---|
| 1184 | $id = generate_key(16); |
|---|
| 1185 | $query = " |
|---|
| 1186 | SELECT COUNT(*) |
|---|
| 1187 | FROM ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 1188 | WHERE id = '".$id."' |
|---|
| 1189 | ;"; |
|---|
| 1190 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 1191 | |
|---|
| 1192 | if ($count == 0) |
|---|
| 1193 | return $id; |
|---|
| 1194 | } |
|---|
| 1195 | } |
|---|
| 1196 | |
|---|
| 1197 | /** |
|---|
| 1198 | * Function called from functions SendMail2User to process unvalidated users and generate validation key link |
|---|
| 1199 | * |
|---|
| 1200 | * @param : User id, email address |
|---|
| 1201 | * |
|---|
| 1202 | * @return : Build validation key in URL |
|---|
| 1203 | * |
|---|
| 1204 | */ |
|---|
| 1205 | function AddConfirmMail($user_id, $email) |
|---|
| 1206 | { |
|---|
| 1207 | global $conf; |
|---|
| 1208 | |
|---|
| 1209 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1210 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
|---|
| 1211 | |
|---|
| 1212 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 1213 | |
|---|
| 1214 | if (isset($Confirm_Mail_ID)) |
|---|
| 1215 | { |
|---|
| 1216 | $query = " |
|---|
| 1217 | SELECT status |
|---|
| 1218 | FROM ".USER_INFOS_TABLE." |
|---|
| 1219 | WHERE user_id = '".$user_id."' |
|---|
| 1220 | ;"; |
|---|
| 1221 | list($status) = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 1222 | |
|---|
| 1223 | $query = " |
|---|
| 1224 | INSERT INTO ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 1225 | (id, user_id, mail_address, status, date_check) |
|---|
| 1226 | VALUES |
|---|
| 1227 | ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null) |
|---|
| 1228 | ;"; |
|---|
| 1229 | pwg_query($query); |
|---|
| 1230 | |
|---|
| 1231 | // Delete user from all groups |
|---|
| 1232 | $query = " |
|---|
| 1233 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1234 | WHERE user_id = '".$user_id."' |
|---|
| 1235 | AND ( |
|---|
| 1236 | group_id = '".$conf_UAM[2]."' |
|---|
| 1237 | OR |
|---|
| 1238 | group_id = '".$conf_UAM[3]."' |
|---|
| 1239 | ) |
|---|
| 1240 | ;"; |
|---|
| 1241 | pwg_query($query); |
|---|
| 1242 | |
|---|
| 1243 | // Set user unvalidated status |
|---|
| 1244 | if (!is_admin() and $conf_UAM[8] <> -1) |
|---|
| 1245 | { |
|---|
| 1246 | $query = " |
|---|
| 1247 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 1248 | SET status = '".$conf_UAM[8]."' |
|---|
| 1249 | WHERE user_id = '".$user_id."' |
|---|
| 1250 | ;"; |
|---|
| 1251 | pwg_query($query); |
|---|
| 1252 | } |
|---|
| 1253 | |
|---|
| 1254 | // Set user unvalidated group |
|---|
| 1255 | if (!is_admin() and $conf_UAM[2] <> -1) |
|---|
| 1256 | { |
|---|
| 1257 | $query = " |
|---|
| 1258 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 1259 | (user_id, group_id) |
|---|
| 1260 | VALUES |
|---|
| 1261 | ('".$user_id."', '".$conf_UAM[2]."') |
|---|
| 1262 | ;"; |
|---|
| 1263 | pwg_query($query); |
|---|
| 1264 | } |
|---|
| 1265 | |
|---|
| 1266 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id; |
|---|
| 1267 | } |
|---|
| 1268 | } |
|---|
| 1269 | |
|---|
| 1270 | /** |
|---|
| 1271 | * Function called from main.inc.php to set group to new users if manual validation is set |
|---|
| 1272 | * |
|---|
| 1273 | * @param : User id |
|---|
| 1274 | * |
|---|
| 1275 | * |
|---|
| 1276 | */ |
|---|
| 1277 | function setgroup($user_id) |
|---|
| 1278 | { |
|---|
| 1279 | global $conf; |
|---|
| 1280 | |
|---|
| 1281 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1282 | |
|---|
| 1283 | $query = " |
|---|
| 1284 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1285 | WHERE user_id = '".$user_id."' |
|---|
| 1286 | AND ( |
|---|
| 1287 | group_id = '".$conf_UAM[2]."' |
|---|
| 1288 | OR |
|---|
| 1289 | group_id = '".$conf_UAM[3]."' |
|---|
| 1290 | ) |
|---|
| 1291 | ;"; |
|---|
| 1292 | pwg_query($query); |
|---|
| 1293 | |
|---|
| 1294 | if (!is_admin() and $conf_UAM[8] <> -1) |
|---|
| 1295 | { |
|---|
| 1296 | $query = " |
|---|
| 1297 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 1298 | SET status = '".$conf_UAM[8]."' |
|---|
| 1299 | WHERE user_id = '".$user_id."' |
|---|
| 1300 | ;"; |
|---|
| 1301 | pwg_query($query); |
|---|
| 1302 | } |
|---|
| 1303 | |
|---|
| 1304 | if (!is_admin() and $conf_UAM[2] <> -1) |
|---|
| 1305 | { |
|---|
| 1306 | $query = " |
|---|
| 1307 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 1308 | (user_id, group_id) |
|---|
| 1309 | VALUES |
|---|
| 1310 | ('".$user_id."', '".$conf_UAM[2]."') |
|---|
| 1311 | ;"; |
|---|
| 1312 | pwg_query($query); |
|---|
| 1313 | } |
|---|
| 1314 | } |
|---|
| 1315 | |
|---|
| 1316 | /** |
|---|
| 1317 | * Function called from UAM_admin.php to reset validation key |
|---|
| 1318 | * |
|---|
| 1319 | * @param : User id |
|---|
| 1320 | * |
|---|
| 1321 | * @return : Build validation key in URL |
|---|
| 1322 | * |
|---|
| 1323 | */ |
|---|
| 1324 | function ResetConfirmMail($user_id) |
|---|
| 1325 | { |
|---|
| 1326 | global $conf; |
|---|
| 1327 | |
|---|
| 1328 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
|---|
| 1329 | |
|---|
| 1330 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 1331 | |
|---|
| 1332 | if (isset($Confirm_Mail_ID)) |
|---|
| 1333 | { |
|---|
| 1334 | $query = " |
|---|
| 1335 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 1336 | SET id = '".$Confirm_Mail_ID."' |
|---|
| 1337 | WHERE user_id = '".$user_id."' |
|---|
| 1338 | ;"; |
|---|
| 1339 | pwg_query($query); |
|---|
| 1340 | |
|---|
| 1341 | $query = " |
|---|
| 1342 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 1343 | SET registration_date = '".$dbnow."' |
|---|
| 1344 | WHERE user_id = '".$user_id."' |
|---|
| 1345 | ;"; |
|---|
| 1346 | pwg_query($query); |
|---|
| 1347 | |
|---|
| 1348 | return get_absolute_root_url().UAM_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID.'&userid='.$user_id; |
|---|
| 1349 | } |
|---|
| 1350 | } |
|---|
| 1351 | |
|---|
| 1352 | /** |
|---|
| 1353 | * Function called from functions.inc.php to reset last visit date after sending a reminder |
|---|
| 1354 | * |
|---|
| 1355 | * @param : User id |
|---|
| 1356 | * |
|---|
| 1357 | */ |
|---|
| 1358 | function resetlastvisit($user_id) |
|---|
| 1359 | { |
|---|
| 1360 | global $conf; |
|---|
| 1361 | |
|---|
| 1362 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 1363 | |
|---|
| 1364 | $query = " |
|---|
| 1365 | UPDATE ".USER_LASTVISIT_TABLE." |
|---|
| 1366 | SET lastvisit = '".$dbnow."', reminder = 'true' |
|---|
| 1367 | WHERE user_id = '".$user_id."' |
|---|
| 1368 | ;"; |
|---|
| 1369 | pwg_query($query); |
|---|
| 1370 | } |
|---|
| 1371 | |
|---|
| 1372 | |
|---|
| 1373 | /** |
|---|
| 1374 | * Function called from main.inc.php - Triggered on user deletion |
|---|
| 1375 | * |
|---|
| 1376 | */ |
|---|
| 1377 | function DeleteConfirmMail($user_id) |
|---|
| 1378 | { |
|---|
| 1379 | $query = " |
|---|
| 1380 | DELETE FROM ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 1381 | WHERE user_id = '".$user_id."' |
|---|
| 1382 | ;"; |
|---|
| 1383 | pwg_query($query); |
|---|
| 1384 | } |
|---|
| 1385 | |
|---|
| 1386 | /** |
|---|
| 1387 | * Function called from main.inc.php - Triggered on user deletion |
|---|
| 1388 | * |
|---|
| 1389 | */ |
|---|
| 1390 | function DeleteLastVisit($user_id) |
|---|
| 1391 | { |
|---|
| 1392 | $query = " |
|---|
| 1393 | DELETE FROM ".USER_LASTVISIT_TABLE." |
|---|
| 1394 | WHERE user_id = '".$user_id."' |
|---|
| 1395 | ;"; |
|---|
| 1396 | pwg_query($query); |
|---|
| 1397 | } |
|---|
| 1398 | |
|---|
| 1399 | /** |
|---|
| 1400 | * Function called from main.inc.php - Triggered on user deletion |
|---|
| 1401 | * |
|---|
| 1402 | * @param : User id |
|---|
| 1403 | * |
|---|
| 1404 | */ |
|---|
| 1405 | function DeleteRedir($user_id) |
|---|
| 1406 | { |
|---|
| 1407 | $tab = array(); |
|---|
| 1408 | |
|---|
| 1409 | $query = ' |
|---|
| 1410 | SELECT value |
|---|
| 1411 | FROM '.CONFIG_TABLE.' |
|---|
| 1412 | WHERE param = "UserAdvManager_Redir" |
|---|
| 1413 | ;'; |
|---|
| 1414 | |
|---|
| 1415 | $tab = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 1416 | |
|---|
| 1417 | $values = explode(',', $tab[0]); |
|---|
| 1418 | |
|---|
| 1419 | unset($values[array_search($user_id, $values)]); |
|---|
| 1420 | |
|---|
| 1421 | $query = " |
|---|
| 1422 | UPDATE ".CONFIG_TABLE." |
|---|
| 1423 | SET value = \"".implode(',', $values)."\" |
|---|
| 1424 | WHERE param = 'UserAdvManager_Redir';"; |
|---|
| 1425 | |
|---|
| 1426 | pwg_query($query); |
|---|
| 1427 | } |
|---|
| 1428 | |
|---|
| 1429 | /** |
|---|
| 1430 | * Function called from ConfirmMail.php to verify validation key used by user according time limit |
|---|
| 1431 | * Return true is key validation is OK else return false |
|---|
| 1432 | * |
|---|
| 1433 | * @param : User id |
|---|
| 1434 | * |
|---|
| 1435 | * @return : Bool |
|---|
| 1436 | * |
|---|
| 1437 | */ |
|---|
| 1438 | function VerifyConfirmMail($id) |
|---|
| 1439 | { |
|---|
| 1440 | global $conf; |
|---|
| 1441 | |
|---|
| 1442 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
|---|
| 1443 | |
|---|
| 1444 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1445 | |
|---|
| 1446 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
|---|
| 1447 | |
|---|
| 1448 | $query = " |
|---|
| 1449 | SELECT COUNT(*) |
|---|
| 1450 | FROM ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 1451 | WHERE id = '".$id."' |
|---|
| 1452 | ;"; |
|---|
| 1453 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 1454 | |
|---|
| 1455 | if ($count == 1) |
|---|
| 1456 | { |
|---|
| 1457 | $query = " |
|---|
| 1458 | SELECT user_id, status, date_check |
|---|
| 1459 | FROM ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 1460 | WHERE id = '".$id."' |
|---|
| 1461 | ;"; |
|---|
| 1462 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
|---|
| 1463 | |
|---|
| 1464 | //if (!empty($data) and isset($data['user_id']) and !isset($data['date_check'])) |
|---|
| 1465 | if (!empty($data) and isset($data['user_id'])) |
|---|
| 1466 | { |
|---|
| 1467 | $query = " |
|---|
| 1468 | SELECT registration_date |
|---|
| 1469 | FROM ".USER_INFOS_TABLE." |
|---|
| 1470 | WHERE user_id = '".$data['user_id']."' |
|---|
| 1471 | ;"; |
|---|
| 1472 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 1473 | |
|---|
| 1474 | // Time limit process |
|---|
| 1475 | // ******************************************** |
|---|
| 1476 | if (!empty($registration_date)) |
|---|
| 1477 | { |
|---|
| 1478 | // Verify Confirmmail with time limit ON |
|---|
| 1479 | if (isset ($conf_UAM_ConfirmMail[1])) |
|---|
| 1480 | { |
|---|
| 1481 | // dates formating and compare |
|---|
| 1482 | $today = date("d-m-Y"); // Get today's date |
|---|
| 1483 | list($day, $month, $year) = explode('-', $today); // explode date of today |
|---|
| 1484 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
|---|
| 1485 | |
|---|
| 1486 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
|---|
| 1487 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
|---|
| 1488 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
|---|
| 1489 | |
|---|
| 1490 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
|---|
| 1491 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
|---|
| 1492 | |
|---|
| 1493 | // Condition with the value set for time limit |
|---|
| 1494 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
|---|
| 1495 | { |
|---|
| 1496 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 1497 | |
|---|
| 1498 | $query = ' |
|---|
| 1499 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
|---|
| 1500 | SET date_check="'.$dbnow.'" |
|---|
| 1501 | WHERE id = "'.$id.'" |
|---|
| 1502 | ;'; |
|---|
| 1503 | pwg_query($query); |
|---|
| 1504 | |
|---|
| 1505 | if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group |
|---|
| 1506 | { |
|---|
| 1507 | $query = " |
|---|
| 1508 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1509 | WHERE user_id = '".$data['user_id']."' |
|---|
| 1510 | AND group_id = '".$conf_UAM[2]."' |
|---|
| 1511 | ;"; |
|---|
| 1512 | pwg_query($query); |
|---|
| 1513 | } |
|---|
| 1514 | |
|---|
| 1515 | if ($conf_UAM[3] <> -1) // Add user to validated users group |
|---|
| 1516 | { |
|---|
| 1517 | $query = " |
|---|
| 1518 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 1519 | (user_id, group_id) |
|---|
| 1520 | VALUES |
|---|
| 1521 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
|---|
| 1522 | ;"; |
|---|
| 1523 | pwg_query($query); |
|---|
| 1524 | } |
|---|
| 1525 | |
|---|
| 1526 | if (($conf_UAM[4] <> -1 or isset($data['status']))) // Change user's status |
|---|
| 1527 | { |
|---|
| 1528 | $query = " |
|---|
| 1529 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 1530 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
|---|
| 1531 | WHERE user_id = '".$data['user_id']."' |
|---|
| 1532 | ;"; |
|---|
| 1533 | pwg_query($query); |
|---|
| 1534 | } |
|---|
| 1535 | // Refresh user's category cache |
|---|
| 1536 | invalidate_user_cache(); |
|---|
| 1537 | |
|---|
| 1538 | return true; |
|---|
| 1539 | } |
|---|
| 1540 | elseif ($deltadays > $conf_UAM_ConfirmMail[1]) // If timelimit exeeds |
|---|
| 1541 | { |
|---|
| 1542 | return false; |
|---|
| 1543 | } |
|---|
| 1544 | } |
|---|
| 1545 | // Verify Confirmmail with time limit OFF |
|---|
| 1546 | else |
|---|
| 1547 | { |
|---|
| 1548 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 1549 | |
|---|
| 1550 | $query = ' |
|---|
| 1551 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
|---|
| 1552 | SET date_check="'.$dbnow.'" |
|---|
| 1553 | WHERE id = "'.$id.'" |
|---|
| 1554 | ;'; |
|---|
| 1555 | pwg_query($query); |
|---|
| 1556 | |
|---|
| 1557 | if ($conf_UAM[2] <> -1) |
|---|
| 1558 | { |
|---|
| 1559 | $query = " |
|---|
| 1560 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1561 | WHERE user_id = '".$data['user_id']."' |
|---|
| 1562 | AND group_id = '".$conf_UAM[2]."' |
|---|
| 1563 | ;"; |
|---|
| 1564 | pwg_query($query); |
|---|
| 1565 | } |
|---|
| 1566 | |
|---|
| 1567 | if ($conf_UAM[3] <> -1) |
|---|
| 1568 | { |
|---|
| 1569 | $query = " |
|---|
| 1570 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1571 | WHERE user_id = '".$data['user_id']."' |
|---|
| 1572 | AND group_id = '".$conf_UAM[3]."' |
|---|
| 1573 | ;"; |
|---|
| 1574 | pwg_query($query); |
|---|
| 1575 | |
|---|
| 1576 | $query = " |
|---|
| 1577 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 1578 | (user_id, group_id) |
|---|
| 1579 | VALUES |
|---|
| 1580 | ('".$data['user_id']."', '".$conf_UAM[3]."') |
|---|
| 1581 | ;"; |
|---|
| 1582 | pwg_query($query); |
|---|
| 1583 | } |
|---|
| 1584 | |
|---|
| 1585 | if (($conf_UAM[4] <> -1 or isset($data['status']))) |
|---|
| 1586 | { |
|---|
| 1587 | $query = " |
|---|
| 1588 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 1589 | SET status = '".(isset($data['status']) ? $data['status'] : $conf_UAM[4])."' |
|---|
| 1590 | WHERE user_id = '".$data['user_id']."' |
|---|
| 1591 | ;"; |
|---|
| 1592 | pwg_query($query); |
|---|
| 1593 | } |
|---|
| 1594 | // Refresh user's category cache |
|---|
| 1595 | invalidate_user_cache(); |
|---|
| 1596 | |
|---|
| 1597 | return true; |
|---|
| 1598 | } |
|---|
| 1599 | } |
|---|
| 1600 | } |
|---|
| 1601 | } |
|---|
| 1602 | else |
|---|
| 1603 | return false; |
|---|
| 1604 | } |
|---|
| 1605 | |
|---|
| 1606 | /** |
|---|
| 1607 | * Function called from UAM_admin.php to force users validation by admin |
|---|
| 1608 | * |
|---|
| 1609 | * @param : User id |
|---|
| 1610 | * |
|---|
| 1611 | */ |
|---|
| 1612 | function ForceValidation($id) |
|---|
| 1613 | { |
|---|
| 1614 | global $conf; |
|---|
| 1615 | |
|---|
| 1616 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1617 | |
|---|
| 1618 | if (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') |
|---|
| 1619 | { |
|---|
| 1620 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 1621 | |
|---|
| 1622 | $query = " |
|---|
| 1623 | UPDATE ".USER_CONFIRM_MAIL_TABLE." |
|---|
| 1624 | SET date_check='".$dbnow."' |
|---|
| 1625 | WHERE user_id = '".$id."' |
|---|
| 1626 | ;"; |
|---|
| 1627 | pwg_query($query); |
|---|
| 1628 | |
|---|
| 1629 | if ($conf_UAM[2] <> -1) |
|---|
| 1630 | { |
|---|
| 1631 | $query = " |
|---|
| 1632 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1633 | WHERE user_id = '".$id."' |
|---|
| 1634 | AND group_id = '".$conf_UAM[2]."' |
|---|
| 1635 | ;"; |
|---|
| 1636 | pwg_query($query); |
|---|
| 1637 | } |
|---|
| 1638 | |
|---|
| 1639 | if ($conf_UAM[3] <> -1) |
|---|
| 1640 | { |
|---|
| 1641 | $query = " |
|---|
| 1642 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1643 | WHERE user_id = '".$id."' |
|---|
| 1644 | AND group_id = '".$conf_UAM[3]."' |
|---|
| 1645 | ;"; |
|---|
| 1646 | pwg_query($query); |
|---|
| 1647 | |
|---|
| 1648 | $query = " |
|---|
| 1649 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 1650 | (user_id, group_id) |
|---|
| 1651 | VALUES |
|---|
| 1652 | ('".$id."', '".$conf_UAM[3]."') |
|---|
| 1653 | ;"; |
|---|
| 1654 | pwg_query($query); |
|---|
| 1655 | } |
|---|
| 1656 | |
|---|
| 1657 | if ($conf_UAM[4] <> -1) |
|---|
| 1658 | { |
|---|
| 1659 | $query = " |
|---|
| 1660 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 1661 | SET status = '".$conf_UAM[4]."' |
|---|
| 1662 | WHERE user_id = '".$id."' |
|---|
| 1663 | ;"; |
|---|
| 1664 | pwg_query($query); |
|---|
| 1665 | } |
|---|
| 1666 | } |
|---|
| 1667 | elseif (isset($conf_UAM[1]) and $conf_UAM[1] == 'local') |
|---|
| 1668 | { |
|---|
| 1669 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
|---|
| 1670 | |
|---|
| 1671 | if ($conf_UAM[2] <> -1) |
|---|
| 1672 | { |
|---|
| 1673 | $query = " |
|---|
| 1674 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1675 | WHERE user_id = '".$id."' |
|---|
| 1676 | AND group_id = '".$conf_UAM[2]."' |
|---|
| 1677 | ;"; |
|---|
| 1678 | pwg_query($query); |
|---|
| 1679 | } |
|---|
| 1680 | |
|---|
| 1681 | if ($conf_UAM[3] <> -1) |
|---|
| 1682 | { |
|---|
| 1683 | $query = " |
|---|
| 1684 | DELETE FROM ".USER_GROUP_TABLE." |
|---|
| 1685 | WHERE user_id = '".$id."' |
|---|
| 1686 | AND group_id = '".$conf_UAM[3]."' |
|---|
| 1687 | ;"; |
|---|
| 1688 | pwg_query($query); |
|---|
| 1689 | |
|---|
| 1690 | $query = " |
|---|
| 1691 | INSERT INTO ".USER_GROUP_TABLE." |
|---|
| 1692 | (user_id, group_id) |
|---|
| 1693 | VALUES |
|---|
| 1694 | ('".$id."', '".$conf_UAM[3]."') |
|---|
| 1695 | ;"; |
|---|
| 1696 | pwg_query($query); |
|---|
| 1697 | } |
|---|
| 1698 | |
|---|
| 1699 | if ($conf_UAM[4] <> -1) |
|---|
| 1700 | { |
|---|
| 1701 | $query = " |
|---|
| 1702 | UPDATE ".USER_INFOS_TABLE." |
|---|
| 1703 | SET status = '".$conf_UAM[4]."' |
|---|
| 1704 | WHERE user_id = '".$id."' |
|---|
| 1705 | ;"; |
|---|
| 1706 | pwg_query($query); |
|---|
| 1707 | } |
|---|
| 1708 | } |
|---|
| 1709 | } |
|---|
| 1710 | |
|---|
| 1711 | /** |
|---|
| 1712 | * Function called from main.inc.php - Check if username matches forbidden caracters |
|---|
| 1713 | * |
|---|
| 1714 | * @param : User login |
|---|
| 1715 | * |
|---|
| 1716 | * @return : Bool |
|---|
| 1717 | * |
|---|
| 1718 | */ |
|---|
| 1719 | function ValidateUsername($login) |
|---|
| 1720 | { |
|---|
| 1721 | global $conf; |
|---|
| 1722 | |
|---|
| 1723 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1724 | |
|---|
| 1725 | if (isset($login) and isset($conf_UAM[7]) and $conf_UAM[7] <> '') |
|---|
| 1726 | { |
|---|
| 1727 | $conf_CharExclusion = preg_split("/,/",$conf_UAM[7]); |
|---|
| 1728 | for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++) |
|---|
| 1729 | { |
|---|
| 1730 | $pattern = '/'.$conf_CharExclusion[$i].'/i'; |
|---|
| 1731 | if (preg_match($pattern, $login)) |
|---|
| 1732 | { |
|---|
| 1733 | return true; |
|---|
| 1734 | } |
|---|
| 1735 | } |
|---|
| 1736 | } |
|---|
| 1737 | else |
|---|
| 1738 | { |
|---|
| 1739 | return false; |
|---|
| 1740 | } |
|---|
| 1741 | } |
|---|
| 1742 | |
|---|
| 1743 | /** |
|---|
| 1744 | * Function called from main.inc.php - Check if user's email is in excluded email providers list |
|---|
| 1745 | * Doesn't work on call - Must be copied in main.inc.php to work |
|---|
| 1746 | * |
|---|
| 1747 | * @param : Email address |
|---|
| 1748 | * |
|---|
| 1749 | * @return : Bool |
|---|
| 1750 | * |
|---|
| 1751 | */ |
|---|
| 1752 | function ValidateEmailProvider($email) |
|---|
| 1753 | { |
|---|
| 1754 | global $conf; |
|---|
| 1755 | |
|---|
| 1756 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1757 | |
|---|
| 1758 | if (isset($email) and isset($conf_UAM[12]) and $conf_UAM[12] <> '') |
|---|
| 1759 | { |
|---|
| 1760 | $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]); |
|---|
| 1761 | for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++) |
|---|
| 1762 | { |
|---|
| 1763 | $pattern = '/'.$conf_MailExclusion[$i].'/i'; |
|---|
| 1764 | if (preg_match($pattern, $email)) |
|---|
| 1765 | { |
|---|
| 1766 | return true; |
|---|
| 1767 | } |
|---|
| 1768 | } |
|---|
| 1769 | } |
|---|
| 1770 | else |
|---|
| 1771 | { |
|---|
| 1772 | return false; |
|---|
| 1773 | } |
|---|
| 1774 | } |
|---|
| 1775 | |
|---|
| 1776 | /** |
|---|
| 1777 | * Function called from UAM_admin.php - Get unvalidated users according time limit |
|---|
| 1778 | * |
|---|
| 1779 | * @return : List of users |
|---|
| 1780 | * |
|---|
| 1781 | */ |
|---|
| 1782 | function get_unvalid_user_list() |
|---|
| 1783 | { |
|---|
| 1784 | global $conf, $page; |
|---|
| 1785 | |
|---|
| 1786 | // Get ConfirmMail configuration |
|---|
| 1787 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
|---|
| 1788 | // Get UAM configuration |
|---|
| 1789 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1790 | |
|---|
| 1791 | $users = array(); |
|---|
| 1792 | |
|---|
| 1793 | // search users depending expiration date |
|---|
| 1794 | $query = ' |
|---|
| 1795 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
|---|
| 1796 | u.'.$conf['user_fields']['username'].' AS username, |
|---|
| 1797 | u.'.$conf['user_fields']['email'].' AS email, |
|---|
| 1798 | ui.status, |
|---|
| 1799 | ui.enabled_high, |
|---|
| 1800 | ui.level, |
|---|
| 1801 | ui.registration_date |
|---|
| 1802 | FROM '.USERS_TABLE.' AS u |
|---|
| 1803 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
|---|
| 1804 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
|---|
| 1805 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
|---|
| 1806 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
|---|
| 1807 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
|---|
| 1808 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'" |
|---|
| 1809 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail[1].'")'; |
|---|
| 1810 | |
|---|
| 1811 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] == '-1') |
|---|
| 1812 | { |
|---|
| 1813 | $query.= ' |
|---|
| 1814 | AND ug.group_id = '.$conf_UAM[2]; |
|---|
| 1815 | } |
|---|
| 1816 | if ($conf_UAM[2] == '-1' and $conf_UAM[8] <> '-1') |
|---|
| 1817 | { |
|---|
| 1818 | $query.= ' |
|---|
| 1819 | AND ui.status = \''.$conf_UAM[8]."'"; |
|---|
| 1820 | } |
|---|
| 1821 | if ($conf_UAM[2] <> '-1' and $conf_UAM[8] <> '-1') |
|---|
| 1822 | { |
|---|
| 1823 | $query.= ' |
|---|
| 1824 | AND ug.group_id = \''.$conf_UAM[2]."'"; |
|---|
| 1825 | } |
|---|
| 1826 | $query.= ' |
|---|
| 1827 | ORDER BY ui.registration_date ASC |
|---|
| 1828 | ;'; |
|---|
| 1829 | |
|---|
| 1830 | $result = pwg_query($query); |
|---|
| 1831 | |
|---|
| 1832 | while ($row = pwg_db_fetch_assoc($result)) |
|---|
| 1833 | { |
|---|
| 1834 | $user = $row; |
|---|
| 1835 | $user['groups'] = array(); |
|---|
| 1836 | |
|---|
| 1837 | array_push($users, $user); |
|---|
| 1838 | } |
|---|
| 1839 | |
|---|
| 1840 | // add group lists |
|---|
| 1841 | $user_ids = array(); |
|---|
| 1842 | foreach ($users as $i => $user) |
|---|
| 1843 | { |
|---|
| 1844 | $user_ids[$i] = $user['id']; |
|---|
| 1845 | } |
|---|
| 1846 | |
|---|
| 1847 | $user_nums = array_flip($user_ids); |
|---|
| 1848 | |
|---|
| 1849 | if (count($user_ids) > 0) |
|---|
| 1850 | { |
|---|
| 1851 | $query = ' |
|---|
| 1852 | SELECT user_id, group_id |
|---|
| 1853 | FROM '.USER_GROUP_TABLE.' |
|---|
| 1854 | WHERE user_id IN ('.implode(',', $user_ids).') |
|---|
| 1855 | ;'; |
|---|
| 1856 | |
|---|
| 1857 | $result = pwg_query($query); |
|---|
| 1858 | |
|---|
| 1859 | while ($row = pwg_db_fetch_assoc($result)) |
|---|
| 1860 | { |
|---|
| 1861 | array_push( |
|---|
| 1862 | $users[$user_nums[$row['user_id']]]['groups'], |
|---|
| 1863 | $row['group_id'] |
|---|
| 1864 | ); |
|---|
| 1865 | } |
|---|
| 1866 | } |
|---|
| 1867 | |
|---|
| 1868 | return $users; |
|---|
| 1869 | } |
|---|
| 1870 | |
|---|
| 1871 | /** |
|---|
| 1872 | * Function called from UAM_admin.php - Get ghost users |
|---|
| 1873 | * |
|---|
| 1874 | * @return : List of users |
|---|
| 1875 | * |
|---|
| 1876 | */ |
|---|
| 1877 | function get_ghost_user_list() |
|---|
| 1878 | { |
|---|
| 1879 | global $conf, $page; |
|---|
| 1880 | |
|---|
| 1881 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1882 | |
|---|
| 1883 | $users = array(); |
|---|
| 1884 | |
|---|
| 1885 | // search users depending expiration date |
|---|
| 1886 | $query = ' |
|---|
| 1887 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
|---|
| 1888 | u.'.$conf['user_fields']['username'].' AS username, |
|---|
| 1889 | u.'.$conf['user_fields']['email'].' AS email, |
|---|
| 1890 | lv.lastvisit, |
|---|
| 1891 | lv.reminder |
|---|
| 1892 | FROM '.USERS_TABLE.' AS u |
|---|
| 1893 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
|---|
| 1894 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
|---|
| 1895 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'") |
|---|
| 1896 | ORDER BY lv.lastvisit ASC;'; |
|---|
| 1897 | |
|---|
| 1898 | $result = pwg_query($query); |
|---|
| 1899 | |
|---|
| 1900 | while ($row = pwg_db_fetch_assoc($result)) |
|---|
| 1901 | { |
|---|
| 1902 | $user = $row; |
|---|
| 1903 | $user['groups'] = array(); |
|---|
| 1904 | |
|---|
| 1905 | array_push($users, $user); |
|---|
| 1906 | } |
|---|
| 1907 | |
|---|
| 1908 | // add group lists |
|---|
| 1909 | $user_ids = array(); |
|---|
| 1910 | foreach ($users as $i => $user) |
|---|
| 1911 | { |
|---|
| 1912 | $user_ids[$i] = $user['id']; |
|---|
| 1913 | } |
|---|
| 1914 | |
|---|
| 1915 | return $users; |
|---|
| 1916 | } |
|---|
| 1917 | |
|---|
| 1918 | |
|---|
| 1919 | /** |
|---|
| 1920 | * Function called from functions.inc.php - Get all ghost users to delete or downgrade automatically on any user login |
|---|
| 1921 | * |
|---|
| 1922 | * @return : List of users to delete or downgrade automatically |
|---|
| 1923 | * |
|---|
| 1924 | */ |
|---|
| 1925 | function get_ghosts_autotasks() |
|---|
| 1926 | { |
|---|
| 1927 | global $conf, $page; |
|---|
| 1928 | |
|---|
| 1929 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 1930 | |
|---|
| 1931 | $users = array(); |
|---|
| 1932 | |
|---|
| 1933 | // search users depending expiration date and reminder sent |
|---|
| 1934 | $query = ' |
|---|
| 1935 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
|---|
| 1936 | lv.lastvisit |
|---|
| 1937 | FROM '.USERS_TABLE.' AS u |
|---|
| 1938 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
|---|
| 1939 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
|---|
| 1940 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'") |
|---|
| 1941 | ORDER BY lv.lastvisit ASC;'; |
|---|
| 1942 | |
|---|
| 1943 | $result = pwg_query($query); |
|---|
| 1944 | |
|---|
| 1945 | while ($row = pwg_db_fetch_assoc($result)) |
|---|
| 1946 | { |
|---|
| 1947 | $user = $row; |
|---|
| 1948 | $user['groups'] = array(); |
|---|
| 1949 | |
|---|
| 1950 | array_push($users, $user); |
|---|
| 1951 | } |
|---|
| 1952 | |
|---|
| 1953 | // add group lists |
|---|
| 1954 | $user_ids = array(); |
|---|
| 1955 | foreach ($users as $i => $user) |
|---|
| 1956 | { |
|---|
| 1957 | $user_ids[$i] = $user['id']; |
|---|
| 1958 | } |
|---|
| 1959 | |
|---|
| 1960 | return $users; |
|---|
| 1961 | } |
|---|
| 1962 | |
|---|
| 1963 | |
|---|
| 1964 | /** |
|---|
| 1965 | * Function called from UAM_admin.php - Get all users to display the number of days since their last visit |
|---|
| 1966 | * |
|---|
| 1967 | * @return : List of users |
|---|
| 1968 | * |
|---|
| 1969 | */ |
|---|
| 1970 | function get_user_list() |
|---|
| 1971 | { |
|---|
| 1972 | global $conf, $page; |
|---|
| 1973 | |
|---|
| 1974 | $users = array(); |
|---|
| 1975 | |
|---|
| 1976 | // search users depending expiration date |
|---|
| 1977 | $query = ' |
|---|
| 1978 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
|---|
| 1979 | u.'.$conf['user_fields']['username'].' AS username, |
|---|
| 1980 | u.'.$conf['user_fields']['email'].' AS email, |
|---|
| 1981 | ug.lastvisit |
|---|
| 1982 | FROM '.USERS_TABLE.' AS u |
|---|
| 1983 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug |
|---|
| 1984 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
|---|
| 1985 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
|---|
| 1986 | ORDER BY ug.lastvisit DESC |
|---|
| 1987 | ;'; |
|---|
| 1988 | |
|---|
| 1989 | $result = pwg_query($query); |
|---|
| 1990 | |
|---|
| 1991 | while ($row = pwg_db_fetch_assoc($result)) |
|---|
| 1992 | { |
|---|
| 1993 | $user = $row; |
|---|
| 1994 | $user['groups'] = array(); |
|---|
| 1995 | |
|---|
| 1996 | array_push($users, $user); |
|---|
| 1997 | } |
|---|
| 1998 | |
|---|
| 1999 | // add group lists |
|---|
| 2000 | $user_ids = array(); |
|---|
| 2001 | foreach ($users as $i => $user) |
|---|
| 2002 | { |
|---|
| 2003 | $user_ids[$i] = $user['id']; |
|---|
| 2004 | } |
|---|
| 2005 | |
|---|
| 2006 | return $users; |
|---|
| 2007 | } |
|---|
| 2008 | |
|---|
| 2009 | /** |
|---|
| 2010 | * Function called from UAM_admin.php - to determine who is expired or not and giving a different display color |
|---|
| 2011 | * |
|---|
| 2012 | * @param : user id |
|---|
| 2013 | * |
|---|
| 2014 | * @return : Bool |
|---|
| 2015 | * |
|---|
| 2016 | */ |
|---|
| 2017 | function expiration($id) |
|---|
| 2018 | { |
|---|
| 2019 | global $conf, $page; |
|---|
| 2020 | |
|---|
| 2021 | // Get ConfirmMail configuration |
|---|
| 2022 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
|---|
| 2023 | |
|---|
| 2024 | // Get UAM configuration |
|---|
| 2025 | $conf_UAM = unserialize($conf['UserAdvManager']); |
|---|
| 2026 | |
|---|
| 2027 | $query = " |
|---|
| 2028 | SELECT registration_date |
|---|
| 2029 | FROM ".USER_INFOS_TABLE." |
|---|
| 2030 | WHERE user_id = '".$id."' |
|---|
| 2031 | ;"; |
|---|
| 2032 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
|---|
| 2033 | |
|---|
| 2034 | // Time limit process |
|---|
| 2035 | // ******************************************** |
|---|
| 2036 | if (!empty($registration_date)) |
|---|
| 2037 | { |
|---|
| 2038 | // dates formating and compare |
|---|
| 2039 | $today = date("d-m-Y"); // Get today's date |
|---|
| 2040 | list($day, $month, $year) = explode('-', $today); // explode date of today |
|---|
| 2041 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
|---|
| 2042 | |
|---|
| 2043 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
|---|
| 2044 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
|---|
| 2045 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
|---|
| 2046 | |
|---|
| 2047 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
|---|
| 2048 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
|---|
| 2049 | |
|---|
| 2050 | // Condition with the value set for time limit |
|---|
| 2051 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
|---|
| 2052 | { |
|---|
| 2053 | return false; |
|---|
| 2054 | } |
|---|
| 2055 | else |
|---|
| 2056 | { |
|---|
| 2057 | return true; |
|---|
| 2058 | } |
|---|
| 2059 | } |
|---|
| 2060 | } |
|---|
| 2061 | |
|---|
| 2062 | |
|---|
| 2063 | /** |
|---|
| 2064 | * Returns a password's score for password complexity check |
|---|
| 2065 | * |
|---|
| 2066 | * @param : password filled by user |
|---|
| 2067 | * |
|---|
| 2068 | * @return : Score calculation |
|---|
| 2069 | * |
|---|
| 2070 | * Thanx to MathieuGut from http://m-gut.developpez.com |
|---|
| 2071 | */ |
|---|
| 2072 | function testpassword($password) // Le mot de passe passé en paramètre - $password given by user |
|---|
| 2073 | { |
|---|
| 2074 | |
|---|
| 2075 | // Initialisation des variables - Variables initiation |
|---|
| 2076 | $points = 0; |
|---|
| 2077 | $point_lowercase = 0; |
|---|
| 2078 | $point_uppercase = 0; |
|---|
| 2079 | $point_numbers = 0; |
|---|
| 2080 | $point_characters = 0; |
|---|
| 2081 | |
|---|
| 2082 | // On récupère la longueur du mot de passe - Getting password lengh |
|---|
| 2083 | $length = strlen($password); |
|---|
| 2084 | |
|---|
| 2085 | // On fait une boucle pour lire chaque lettre - Loop to read password characters |
|---|
| 2086 | for($i = 0; $i < $length; $i++) |
|---|
| 2087 | { |
|---|
| 2088 | // On sélectionne une à une chaque lettre - Select each letters |
|---|
| 2089 | // $i étant à 0 lors du premier passage de la boucle - $i is 0 at first turn |
|---|
| 2090 | $letters = $password[$i]; |
|---|
| 2091 | |
|---|
| 2092 | if ($letters>='a' && $letters<='z') |
|---|
| 2093 | { |
|---|
| 2094 | // On ajoute 1 point pour une minuscule - Adding 1 point to score for a lowercase |
|---|
| 2095 | $points = $points + 1; |
|---|
| 2096 | |
|---|
| 2097 | // On rajoute le bonus pour une minuscule - Adding bonus points for lowercase |
|---|
| 2098 | $point_lowercase = 1; |
|---|
| 2099 | } |
|---|
| 2100 | else if ($letters>='A' && $letters <='Z') |
|---|
| 2101 | { |
|---|
| 2102 | // On ajoute 2 points pour une majuscule - Adding 2 points to score for uppercase |
|---|
| 2103 | $points = $points + 2; |
|---|
| 2104 | |
|---|
| 2105 | // On rajoute le bonus pour une majuscule - Adding bonus points for uppercase |
|---|
| 2106 | $point_uppercase = 2; |
|---|
| 2107 | } |
|---|
| 2108 | else if ($letters>='0' && $letters<='9') |
|---|
| 2109 | { |
|---|
| 2110 | // On ajoute 3 points pour un chiffre - Adding 3 points to score for numbers |
|---|
| 2111 | $points = $points + 3; |
|---|
| 2112 | |
|---|
| 2113 | // On rajoute le bonus pour un chiffre - Adding bonus points for numbers |
|---|
| 2114 | $point_numbers = 3; |
|---|
| 2115 | } |
|---|
| 2116 | else |
|---|
| 2117 | { |
|---|
| 2118 | // On ajoute 5 points pour un caractère autre - Adding 5 points to score for special characters |
|---|
| 2119 | $points = $points + 5; |
|---|
| 2120 | |
|---|
| 2121 | // On rajoute le bonus pour un caractère autre - Adding bonus points for special characters |
|---|
| 2122 | $point_characters = 5; |
|---|
| 2123 | } |
|---|
| 2124 | } |
|---|
| 2125 | |
|---|
| 2126 | // Calcul du coefficient points/longueur - calculating the coefficient points/length |
|---|
| 2127 | $step1 = $points / $length; |
|---|
| 2128 | |
|---|
| 2129 | // Calcul du coefficient de la diversité des types de caractères... - Calculation of the diversity of character types... |
|---|
| 2130 | $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters; |
|---|
| 2131 | |
|---|
| 2132 | // Multiplication du coefficient de diversité avec celui de la longueur - Multiplying the coefficient of diversity with that of the length |
|---|
| 2133 | $score = $step1 * $step2; |
|---|
| 2134 | |
|---|
| 2135 | // Multiplication du résultat par la longueur de la chaîne - Multiplying the result by the length of the chain |
|---|
| 2136 | $finalscore = $score * $length; |
|---|
| 2137 | |
|---|
| 2138 | return $finalscore; |
|---|
| 2139 | } |
|---|
| 2140 | |
|---|
| 2141 | /** |
|---|
| 2142 | * Function called from maintain.inc.php - to check if database upgrade is needed |
|---|
| 2143 | * |
|---|
| 2144 | * @param : table name |
|---|
| 2145 | * |
|---|
| 2146 | * @return : boolean |
|---|
| 2147 | * |
|---|
| 2148 | */ |
|---|
| 2149 | function table_exist($table) |
|---|
| 2150 | { |
|---|
| 2151 | $query = 'DESC '.$table.';'; |
|---|
| 2152 | return (bool)($res=pwg_query($query)); |
|---|
| 2153 | } |
|---|
| 2154 | |
|---|
| 2155 | // Email sending debugger function |
|---|
| 2156 | function MailLog($to, $subject, $content, $language) |
|---|
| 2157 | { |
|---|
| 2158 | $fo=fopen (UAM_PATH.'admin/maillog.txt','a') ; |
|---|
| 2159 | fwrite($fo,"======================\n") ; |
|---|
| 2160 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
|---|
| 2161 | fwrite($fo,$to . "\n" . $subject . "\r\n") ; |
|---|
| 2162 | fwrite($fo, "\n" . $content . "\r\n") ; |
|---|
| 2163 | fwrite($fo, 'Langue : '."\n" . $language . "\r\n") ; |
|---|
| 2164 | fclose($fo) ; |
|---|
| 2165 | //return mail ($to,$subject) ; |
|---|
| 2166 | } |
|---|
| 2167 | |
|---|
| 2168 | /** |
|---|
| 2169 | * Function called from UAM_admin.php and main.inc.php to get the plugin version and name |
|---|
| 2170 | * |
|---|
| 2171 | * @param : plugin directory |
|---|
| 2172 | * |
|---|
| 2173 | * @return : plugin's version and name |
|---|
| 2174 | * |
|---|
| 2175 | */ |
|---|
| 2176 | function PluginInfos($dir) |
|---|
| 2177 | { |
|---|
| 2178 | $path = $dir; |
|---|
| 2179 | |
|---|
| 2180 | $plg_data = implode( '', file($path.'main.inc.php') ); |
|---|
| 2181 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
|---|
| 2182 | { |
|---|
| 2183 | $plugin['name'] = trim( $val[1] ); |
|---|
| 2184 | } |
|---|
| 2185 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
|---|
| 2186 | { |
|---|
| 2187 | $plugin['version'] = trim($val[1]); |
|---|
| 2188 | } |
|---|
| 2189 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
|---|
| 2190 | { |
|---|
| 2191 | $plugin['uri'] = trim($val[1]); |
|---|
| 2192 | } |
|---|
| 2193 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
|---|
| 2194 | { |
|---|
| 2195 | $plugin['description'] = trim($desc); |
|---|
| 2196 | } |
|---|
| 2197 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
|---|
| 2198 | { |
|---|
| 2199 | $plugin['description'] = trim($val[1]); |
|---|
| 2200 | } |
|---|
| 2201 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
|---|
| 2202 | { |
|---|
| 2203 | $plugin['author'] = trim($val[1]); |
|---|
| 2204 | } |
|---|
| 2205 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
|---|
| 2206 | { |
|---|
| 2207 | $plugin['author uri'] = trim($val[1]); |
|---|
| 2208 | } |
|---|
| 2209 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
|---|
| 2210 | { |
|---|
| 2211 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
|---|
| 2212 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
|---|
| 2213 | } |
|---|
| 2214 | // IMPORTANT SECURITY ! |
|---|
| 2215 | $plugin = array_map('htmlspecialchars', $plugin); |
|---|
| 2216 | |
|---|
| 2217 | return $plugin ; |
|---|
| 2218 | } |
|---|
| 2219 | |
|---|
| 2220 | |
|---|
| 2221 | function clean_obsolete_files() |
|---|
| 2222 | { |
|---|
| 2223 | if (file_exists(UAM_PATH.'obsolete.list') |
|---|
| 2224 | and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
|---|
| 2225 | and !empty($old_files)) |
|---|
| 2226 | { |
|---|
| 2227 | array_push($old_files, 'obsolete.list'); |
|---|
| 2228 | foreach($old_files as $old_file) |
|---|
| 2229 | { |
|---|
| 2230 | $path = UAM_PATH.$old_file; |
|---|
| 2231 | if (is_file($path)) |
|---|
| 2232 | { |
|---|
| 2233 | @unlink($path); |
|---|
| 2234 | } |
|---|
| 2235 | } |
|---|
| 2236 | } |
|---|
| 2237 | } |
|---|
| 2238 | |
|---|
| 2239 | /** |
|---|
| 2240 | * UAM_check_profile - Thx to LucMorizur |
|---|
| 2241 | * checks if a user id is registered as having already |
|---|
| 2242 | * visited his profile.php page. |
|---|
| 2243 | * |
|---|
| 2244 | * @uid : the user id |
|---|
| 2245 | * |
|---|
| 2246 | * @user_idsOK : (returned) array of all users ids having already visited |
|---|
| 2247 | * their profile.php pages |
|---|
| 2248 | * |
|---|
| 2249 | * @returns : true or false whether the users has already visited his |
|---|
| 2250 | * profile.php page or not |
|---|
| 2251 | * |
|---|
| 2252 | */ |
|---|
| 2253 | function UAM_check_profile($uid, &$user_idsOK) |
|---|
| 2254 | { |
|---|
| 2255 | $t = array(); |
|---|
| 2256 | $v = false; |
|---|
| 2257 | |
|---|
| 2258 | $query = " |
|---|
| 2259 | SELECT value |
|---|
| 2260 | FROM ".CONFIG_TABLE." |
|---|
| 2261 | WHERE param = 'UserAdvManager_Redir' |
|---|
| 2262 | ;"; |
|---|
| 2263 | |
|---|
| 2264 | if ($v = (($t = pwg_db_fetch_row(pwg_query($query))) !== false)) |
|---|
| 2265 | { |
|---|
| 2266 | $user_idsOK = explode(',', $t[0]); |
|---|
| 2267 | $v = (in_array($uid, $user_idsOK)); |
|---|
| 2268 | } |
|---|
| 2269 | return $v; |
|---|
| 2270 | } |
|---|
| 2271 | ?> |
|---|