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