[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 /** 15 * @ignore 16 */ 17 if (!defined('IN_PHPBB')) 18 { 19 exit; 20 } 21 22 /** 23 * Execute message options 24 */ 25 function message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions) 26 { 27 global $phpbb_root_path, $phpEx, $user, $template, $auth, $config, $db; 28 29 $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=options"); 30 31 add_form_key('ucp_pm_options'); 32 // Change "full folder" setting - what to do if folder is full 33 if (isset($_POST['fullfolder'])) 34 { 35 if (!check_form_key('ucp_pm_options')) 36 { 37 trigger_error('FORM_INVALID'); 38 } 39 40 $full_action = request_var('full_action', 0); 41 42 $set_folder_id = 0; 43 switch ($full_action) 44 { 45 case 1: 46 $set_folder_id = FULL_FOLDER_DELETE; 47 break; 48 49 case 2: 50 $set_folder_id = request_var('full_move_to', PRIVMSGS_INBOX); 51 break; 52 53 case 3: 54 $set_folder_id = FULL_FOLDER_HOLD; 55 break; 56 57 default: 58 $full_action = 0; 59 break; 60 } 61 62 if ($full_action) 63 { 64 $sql = 'UPDATE ' . USERS_TABLE . ' 65 SET user_full_folder = ' . $set_folder_id . ' 66 WHERE user_id = ' . $user->data['user_id']; 67 $db->sql_query($sql); 68 69 $user->data['user_full_folder'] = $set_folder_id; 70 71 $message = $user->lang['FULL_FOLDER_OPTION_CHANGED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); 72 meta_refresh(3, $redirect_url); 73 trigger_error($message); 74 } 75 } 76 77 // Add Folder 78 if (isset($_POST['addfolder'])) 79 { 80 if (check_form_key('ucp_pm_options')) 81 { 82 $folder_name = utf8_normalize_nfc(request_var('foldername', '', true)); 83 $msg = ''; 84 85 if ($folder_name) 86 { 87 $sql = 'SELECT folder_name 88 FROM ' . PRIVMSGS_FOLDER_TABLE . " 89 WHERE folder_name = '" . $db->sql_escape($folder_name) . "' 90 AND user_id = " . $user->data['user_id']; 91 $result = $db->sql_query_limit($sql, 1); 92 $row = $db->sql_fetchrow($result); 93 $db->sql_freeresult($result); 94 95 if ($row) 96 { 97 trigger_error(sprintf($user->lang['FOLDER_NAME_EXIST'], $folder_name)); 98 } 99 100 $sql = 'SELECT COUNT(folder_id) as num_folder 101 FROM ' . PRIVMSGS_FOLDER_TABLE . ' 102 WHERE user_id = ' . $user->data['user_id']; 103 $result = $db->sql_query($sql); 104 $num_folder = (int) $db->sql_fetchfield('num_folder'); 105 $db->sql_freeresult($result); 106 107 if ($num_folder >= $config['pm_max_boxes']) 108 { 109 trigger_error('MAX_FOLDER_REACHED'); 110 } 111 112 $sql = 'INSERT INTO ' . PRIVMSGS_FOLDER_TABLE . ' ' . $db->sql_build_array('INSERT', array( 113 'user_id' => (int) $user->data['user_id'], 114 'folder_name' => $folder_name) 115 ); 116 $db->sql_query($sql); 117 $msg = $user->lang['FOLDER_ADDED']; 118 } 119 else 120 { 121 $msg = $user->lang['FOLDER_NAME_EMPTY']; 122 } 123 } 124 else 125 { 126 $msg = $user->lang['FORM_INVALID']; 127 } 128 $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); 129 meta_refresh(3, $redirect_url); 130 trigger_error($message); 131 } 132 133 // Rename folder 134 if (isset($_POST['rename_folder'])) 135 { 136 if (check_form_key('ucp_pm_options')) 137 { 138 $new_folder_name = utf8_normalize_nfc(request_var('new_folder_name', '', true)); 139 $rename_folder_id= request_var('rename_folder_id', 0); 140 141 if (!$new_folder_name) 142 { 143 trigger_error('NO_NEW_FOLDER_NAME'); 144 } 145 146 // Select custom folder 147 $sql = 'SELECT folder_name, pm_count 148 FROM ' . PRIVMSGS_FOLDER_TABLE . " 149 WHERE user_id = {$user->data['user_id']} 150 AND folder_id = $rename_folder_id"; 151 $result = $db->sql_query_limit($sql, 1); 152 $folder_row = $db->sql_fetchrow($result); 153 $db->sql_freeresult($result); 154 155 if (!$folder_row) 156 { 157 trigger_error('CANNOT_RENAME_FOLDER'); 158 } 159 160 $sql = 'UPDATE ' . PRIVMSGS_FOLDER_TABLE . " 161 SET folder_name = '" . $db->sql_escape($new_folder_name) . "' 162 WHERE folder_id = $rename_folder_id 163 AND user_id = {$user->data['user_id']}"; 164 $db->sql_query($sql); 165 $msg = $user->lang['FOLDER_RENAMED']; 166 } 167 else 168 { 169 $msg = $user->lang['FORM_INVALID']; 170 } 171 172 $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); 173 174 meta_refresh(3, $redirect_url); 175 trigger_error($message); 176 } 177 178 // Remove Folder 179 if (isset($_POST['remove_folder'])) 180 { 181 $remove_folder_id = request_var('remove_folder_id', 0); 182 183 // Default to "move all messages to inbox" 184 $remove_action = request_var('remove_action', 1); 185 $move_to = request_var('move_to', PRIVMSGS_INBOX); 186 187 // Move to same folder? 188 if ($remove_action == 1 && $remove_folder_id == $move_to) 189 { 190 trigger_error('CANNOT_MOVE_TO_SAME_FOLDER'); 191 } 192 193 // Select custom folder 194 $sql = 'SELECT folder_name, pm_count 195 FROM ' . PRIVMSGS_FOLDER_TABLE . " 196 WHERE user_id = {$user->data['user_id']} 197 AND folder_id = $remove_folder_id"; 198 $result = $db->sql_query_limit($sql, 1); 199 $folder_row = $db->sql_fetchrow($result); 200 $db->sql_freeresult($result); 201 202 if (!$folder_row) 203 { 204 trigger_error('CANNOT_REMOVE_FOLDER'); 205 } 206 207 $s_hidden_fields = array( 208 'remove_folder_id' => $remove_folder_id, 209 'remove_action' => $remove_action, 210 'move_to' => $move_to, 211 'remove_folder' => 1 212 ); 213 214 // Do we need to confirm? 215 if (confirm_box(true)) 216 { 217 // Gather message ids 218 $sql = 'SELECT msg_id 219 FROM ' . PRIVMSGS_TO_TABLE . ' 220 WHERE user_id = ' . $user->data['user_id'] . " 221 AND folder_id = $remove_folder_id"; 222 $result = $db->sql_query($sql); 223 224 $msg_ids = array(); 225 while ($row = $db->sql_fetchrow($result)) 226 { 227 $msg_ids[] = (int) $row['msg_id']; 228 } 229 $db->sql_freeresult($result); 230 231 // First of all, copy all messages to another folder... or delete all messages 232 switch ($remove_action) 233 { 234 // Move Messages 235 case 1: 236 $num_moved = move_pm($user->data['user_id'], $user->data['message_limit'], $msg_ids, $move_to, $remove_folder_id); 237 238 // Something went wrong, only partially moved? 239 if ($num_moved != $folder_row['pm_count']) 240 { 241 trigger_error($user->lang('MOVE_PM_ERROR', $user->lang('MESSAGES_COUNT', (int) $folder_row['pm_count']), $num_moved)); 242 } 243 break; 244 245 // Remove Messages 246 case 2: 247 delete_pm($user->data['user_id'], $msg_ids, $remove_folder_id); 248 break; 249 } 250 251 // Remove folder 252 $sql = 'DELETE FROM ' . PRIVMSGS_FOLDER_TABLE . " 253 WHERE user_id = {$user->data['user_id']} 254 AND folder_id = $remove_folder_id"; 255 $db->sql_query($sql); 256 257 // Check full folder option. If the removed folder has been specified as destination switch back to inbox 258 if ($user->data['user_full_folder'] == $remove_folder_id) 259 { 260 $sql = 'UPDATE ' . USERS_TABLE . ' 261 SET user_full_folder = ' . PRIVMSGS_INBOX . ' 262 WHERE user_id = ' . $user->data['user_id']; 263 $db->sql_query($sql); 264 265 $user->data['user_full_folder'] = PRIVMSGS_INBOX; 266 } 267 268 // Now make sure the folder is not used for rules 269 // We assign another folder id (the one the messages got moved to) or assign the INBOX (to not have to remove any rule) 270 $sql = 'UPDATE ' . PRIVMSGS_RULES_TABLE . ' SET rule_folder_id = '; 271 $sql .= ($remove_action == 1) ? $move_to : PRIVMSGS_INBOX; 272 $sql .= ' WHERE rule_folder_id = ' . $remove_folder_id; 273 274 $db->sql_query($sql); 275 276 $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=$mode"); 277 $message = $user->lang['FOLDER_REMOVED']; 278 279 meta_refresh(3, $meta_info); 280 $message .= '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $meta_info . '">', '</a>'); 281 trigger_error($message); 282 } 283 else 284 { 285 confirm_box(false, 'REMOVE_FOLDER', build_hidden_fields($s_hidden_fields)); 286 } 287 } 288 289 // Add Rule 290 if (isset($_POST['add_rule'])) 291 { 292 if (check_form_key('ucp_pm_options')) 293 { 294 $check_option = request_var('check_option', 0); 295 $rule_option = request_var('rule_option', 0); 296 $cond_option = request_var('cond_option', ''); 297 $action_option = explode('|', request_var('action_option', '')); 298 $rule_string = ($cond_option != 'none') ? utf8_normalize_nfc(request_var('rule_string', '', true)) : ''; 299 $rule_user_id = ($cond_option != 'none') ? request_var('rule_user_id', 0) : 0; 300 $rule_group_id = ($cond_option != 'none') ? request_var('rule_group_id', 0) : 0; 301 302 $action = (int) $action_option[0]; 303 $folder_id = (int) $action_option[1]; 304 305 if (!$action || !$check_option || !$rule_option || !$cond_option || ($cond_option != 'none' && !$rule_string)) 306 { 307 trigger_error('RULE_NOT_DEFINED'); 308 } 309 310 if (($cond_option == 'user' && !$rule_user_id) || ($cond_option == 'group' && !$rule_group_id)) 311 { 312 trigger_error('RULE_NOT_DEFINED'); 313 } 314 315 $rule_ary = array( 316 'user_id' => $user->data['user_id'], 317 'rule_check' => $check_option, 318 'rule_connection' => $rule_option, 319 'rule_string' => $rule_string, 320 'rule_user_id' => $rule_user_id, 321 'rule_group_id' => $rule_group_id, 322 'rule_action' => $action, 323 'rule_folder_id' => $folder_id 324 ); 325 326 $sql = 'SELECT rule_id 327 FROM ' . PRIVMSGS_RULES_TABLE . ' 328 WHERE ' . $db->sql_build_array('SELECT', $rule_ary); 329 $result = $db->sql_query($sql); 330 $row = $db->sql_fetchrow($result); 331 $db->sql_freeresult($result); 332 333 if ($row) 334 { 335 trigger_error('RULE_ALREADY_DEFINED'); 336 } 337 338 // Prevent users from flooding the rules table 339 $sql = 'SELECT COUNT(rule_id) AS num_rules 340 FROM ' . PRIVMSGS_RULES_TABLE . ' 341 WHERE user_id = ' . (int) $user->data['user_id']; 342 $result = $db->sql_query($sql); 343 $num_rules = (int) $db->sql_fetchfield('num_rules'); 344 $db->sql_freeresult($result); 345 346 if ($num_rules >= 5000) 347 { 348 trigger_error('RULE_LIMIT_REACHED'); 349 } 350 351 $sql = 'INSERT INTO ' . PRIVMSGS_RULES_TABLE . ' ' . $db->sql_build_array('INSERT', $rule_ary); 352 $db->sql_query($sql); 353 354 // Set the user_message_rules bit 355 $sql = 'UPDATE ' . USERS_TABLE . ' 356 SET user_message_rules = 1 357 WHERE user_id = ' . $user->data['user_id']; 358 $db->sql_query($sql); 359 360 $msg = $user->lang['RULE_ADDED']; 361 } 362 else 363 { 364 $msg = $user->lang['FORM_INVALID']; 365 } 366 $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); 367 meta_refresh(3, $redirect_url); 368 trigger_error($message); 369 } 370 371 // Remove Rule 372 if (isset($_POST['delete_rule']) && !isset($_POST['cancel'])) 373 { 374 $delete_id = array_keys(request_var('delete_rule', array(0 => 0))); 375 $delete_id = (!empty($delete_id[0])) ? $delete_id[0] : 0; 376 377 if (!$delete_id) 378 { 379 redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=' . $mode)); 380 } 381 382 // Do we need to confirm? 383 if (confirm_box(true)) 384 { 385 $sql = 'DELETE FROM ' . PRIVMSGS_RULES_TABLE . ' 386 WHERE user_id = ' . $user->data['user_id'] . " 387 AND rule_id = $delete_id"; 388 $db->sql_query($sql); 389 390 $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=' . $mode); 391 $message = $user->lang['RULE_DELETED']; 392 393 // Reset user_message_rules if no more assigned 394 $sql = 'SELECT rule_id 395 FROM ' . PRIVMSGS_RULES_TABLE . ' 396 WHERE user_id = ' . $user->data['user_id']; 397 $result = $db->sql_query_limit($sql, 1); 398 $row = $db->sql_fetchrow($result); 399 $db->sql_freeresult($result); 400 401 // Unset the user_message_rules bit 402 if (!$row) 403 { 404 $sql = 'UPDATE ' . USERS_TABLE . ' 405 SET user_message_rules = 0 406 WHERE user_id = ' . $user->data['user_id']; 407 $db->sql_query($sql); 408 } 409 410 meta_refresh(3, $meta_info); 411 $message .= '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $meta_info . '">', '</a>'); 412 trigger_error($message); 413 } 414 else 415 { 416 confirm_box(false, 'DELETE_RULE', build_hidden_fields(array('delete_rule' => array($delete_id => 1)))); 417 } 418 } 419 420 $folder = array(); 421 422 $sql = 'SELECT COUNT(msg_id) as num_messages 423 FROM ' . PRIVMSGS_TO_TABLE . ' 424 WHERE user_id = ' . $user->data['user_id'] . ' 425 AND folder_id = ' . PRIVMSGS_INBOX; 426 $result = $db->sql_query($sql); 427 $num_messages = (int) $db->sql_fetchfield('num_messages'); 428 $db->sql_freeresult($result); 429 430 $folder[PRIVMSGS_INBOX] = array( 431 'folder_name' => $user->lang['PM_INBOX'], 432 'message_status' => $user->lang('FOLDER_MESSAGE_STATUS', $user->lang('MESSAGES_COUNT', (int) $user->data['message_limit']), $num_messages), 433 ); 434 435 $sql = 'SELECT folder_id, folder_name, pm_count 436 FROM ' . PRIVMSGS_FOLDER_TABLE . ' 437 WHERE user_id = ' . $user->data['user_id']; 438 $result = $db->sql_query($sql); 439 440 $num_user_folder = 0; 441 while ($row = $db->sql_fetchrow($result)) 442 { 443 $num_user_folder++; 444 $folder[$row['folder_id']] = array( 445 'folder_name' => $row['folder_name'], 446 'message_status' => $user->lang('FOLDER_MESSAGE_STATUS', $user->lang('MESSAGES_COUNT', (int) $user->data['message_limit']), (int) $row['pm_count']), 447 ); 448 } 449 $db->sql_freeresult($result); 450 451 $s_full_folder_options = $s_to_folder_options = $s_folder_options = ''; 452 453 if ($user->data['user_full_folder'] == FULL_FOLDER_NONE) 454 { 455 // -3 here to let the correct folder id be selected 456 $to_folder_id = $config['full_folder_action'] - 3; 457 } 458 else 459 { 460 $to_folder_id = $user->data['user_full_folder']; 461 } 462 463 foreach ($folder as $folder_id => $folder_ary) 464 { 465 $s_full_folder_options .= '<option value="' . $folder_id . '"' . (($user->data['user_full_folder'] == $folder_id) ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; 466 $s_to_folder_options .= '<option value="' . $folder_id . '"' . (($to_folder_id == $folder_id) ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; 467 468 if ($folder_id != PRIVMSGS_INBOX) 469 { 470 $s_folder_options .= '<option value="' . $folder_id . '">' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; 471 } 472 } 473 474 $s_delete_checked = ($user->data['user_full_folder'] == FULL_FOLDER_DELETE) ? ' checked="checked"' : ''; 475 $s_hold_checked = ($user->data['user_full_folder'] == FULL_FOLDER_HOLD) ? ' checked="checked"' : ''; 476 $s_move_checked = ($user->data['user_full_folder'] >= 0) ? ' checked="checked"' : ''; 477 478 if ($user->data['user_full_folder'] == FULL_FOLDER_NONE) 479 { 480 switch ($config['full_folder_action']) 481 { 482 case 1: 483 $s_delete_checked = ' checked="checked"'; 484 break; 485 486 case 2: 487 $s_hold_checked = ' checked="checked"'; 488 break; 489 } 490 } 491 492 $template->assign_vars(array( 493 'S_FULL_FOLDER_OPTIONS' => $s_full_folder_options, 494 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options, 495 'S_FOLDER_OPTIONS' => $s_folder_options, 496 'S_DELETE_CHECKED' => $s_delete_checked, 497 'S_HOLD_CHECKED' => $s_hold_checked, 498 'S_MOVE_CHECKED' => $s_move_checked, 499 'S_MAX_FOLDER_REACHED' => ($num_user_folder >= $config['pm_max_boxes']) ? true : false, 500 'S_MAX_FOLDER_ZERO' => ($config['pm_max_boxes'] == 0) ? true : false, 501 502 'DEFAULT_ACTION' => ($config['full_folder_action'] == 1) ? $user->lang['DELETE_OLDEST_MESSAGES'] : $user->lang['HOLD_NEW_MESSAGES'], 503 504 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=ucp&field=rule_string&select_single=true'), 505 )); 506 507 $rule_lang = $action_lang = $check_lang = array(); 508 509 // Build all three language arrays 510 preg_replace('#^((RULE|ACTION|CHECK)_([A-Z0-9_]+))$#e', "\$strtolower('\\2') . '_lang'}[constant('\\1')] = \$user->lang['PM_\\2']['\\3']", array_keys(get_defined_constants())); 511 512 /* 513 Rule Ordering: 514 -> CHECK_* -> RULE_* [IN $global_privmsgs_rules:CHECK_*] -> [IF $rule_conditions[RULE_*] [|text|bool|user|group|own_group]] -> ACTION_* 515 */ 516 517 $check_option = request_var('check_option', 0); 518 $rule_option = request_var('rule_option', 0); 519 $cond_option = request_var('cond_option', ''); 520 $action_option = request_var('action_option', ''); 521 $back = (isset($_REQUEST['back'])) ? request_var('back', array('' => 0)) : array(); 522 523 if (sizeof($back)) 524 { 525 if ($action_option) 526 { 527 $action_option = ''; 528 } 529 else if ($cond_option) 530 { 531 $cond_option = ''; 532 } 533 else if ($rule_option) 534 { 535 $rule_option = 0; 536 } 537 else if ($check_option) 538 { 539 $check_option = 0; 540 } 541 } 542 543 if (isset($back['action']) && $cond_option == 'none') 544 { 545 $back['cond'] = true; 546 } 547 548 // Check 549 if (!isset($global_privmsgs_rules[$check_option])) 550 { 551 $check_option = 0; 552 } 553 554 define_check_option(($check_option && !isset($back['rule'])) ? true : false, $check_option, $check_lang); 555 556 if ($check_option && !isset($back['rule'])) 557 { 558 define_rule_option(($rule_option && !isset($back['cond'])) ? true : false, $rule_option, $rule_lang, $global_privmsgs_rules[$check_option]); 559 } 560 561 if ($rule_option && !isset($back['cond'])) 562 { 563 if (!isset($global_rule_conditions[$rule_option])) 564 { 565 $cond_option = 'none'; 566 $template->assign_var('NONE_CONDITION', true); 567 } 568 else 569 { 570 define_cond_option(($cond_option && !isset($back['action'])) ? true : false, $cond_option, $rule_option, $global_rule_conditions); 571 } 572 } 573 574 if ($cond_option && !isset($back['action'])) 575 { 576 define_action_option(false, $action_option, $action_lang, $folder); 577 } 578 579 show_defined_rules($user->data['user_id'], $check_lang, $rule_lang, $action_lang, $folder); 580 } 581 582 /** 583 * Defining check option for message rules 584 */ 585 function define_check_option($hardcoded, $check_option, $check_lang) 586 { 587 global $template; 588 589 $s_check_options = ''; 590 if (!$hardcoded) 591 { 592 foreach ($check_lang as $value => $lang) 593 { 594 $s_check_options .= '<option value="' . $value . '"' . (($value == $check_option) ? ' selected="selected"' : '') . '>' . $lang . '</option>'; 595 } 596 } 597 598 $template->assign_vars(array( 599 'S_CHECK_DEFINED' => true, 600 'S_CHECK_SELECT' => ($hardcoded) ? false : true, 601 'CHECK_CURRENT' => isset($check_lang[$check_option]) ? $check_lang[$check_option] : '', 602 'S_CHECK_OPTIONS' => $s_check_options, 603 'CHECK_OPTION' => $check_option) 604 ); 605 } 606 607 /** 608 * Defining action option for message rules 609 */ 610 function define_action_option($hardcoded, $action_option, $action_lang, $folder) 611 { 612 global $db, $template, $user; 613 614 $l_action = $s_action_options = ''; 615 if ($hardcoded) 616 { 617 $option = explode('|', $action_option); 618 $action = (int) $option[0]; 619 $folder_id = (int) $option[1]; 620 621 $l_action = $action_lang[$action]; 622 if ($action == ACTION_PLACE_INTO_FOLDER) 623 { 624 $l_action .= ' -> ' . $folder[$folder_id]['folder_name']; 625 } 626 } 627 else 628 { 629 foreach ($action_lang as $action => $lang) 630 { 631 if ($action == ACTION_PLACE_INTO_FOLDER) 632 { 633 foreach ($folder as $folder_id => $folder_ary) 634 { 635 $s_action_options .= '<option value="' . $action . '|' . $folder_id . '"' . (($action_option == $action . '|' . $folder_id) ? ' selected="selected"' : '') . '>' . $lang . ' -> ' . $folder_ary['folder_name'] . '</option>'; 636 } 637 } 638 else 639 { 640 $s_action_options .= '<option value="' . $action . '|0"' . (($action_option == $action . '|0') ? ' selected="selected"' : '') . '>' . $lang . '</option>'; 641 } 642 } 643 } 644 645 $template->assign_vars(array( 646 'S_ACTION_DEFINED' => true, 647 'S_ACTION_SELECT' => ($hardcoded) ? false : true, 648 'ACTION_CURRENT' => $l_action, 649 'S_ACTION_OPTIONS' => $s_action_options, 650 'ACTION_OPTION' => $action_option) 651 ); 652 } 653 654 /** 655 * Defining rule option for message rules 656 */ 657 function define_rule_option($hardcoded, $rule_option, $rule_lang, $check_ary) 658 { 659 global $template; 660 global $module; 661 662 $exclude = array(); 663 664 if (!$module->loaded('zebra', 'friends')) 665 { 666 $exclude[RULE_IS_FRIEND] = true; 667 } 668 669 if (!$module->loaded('zebra', 'foes')) 670 { 671 $exclude[RULE_IS_FOE] = true; 672 } 673 674 $s_rule_options = ''; 675 if (!$hardcoded) 676 { 677 foreach ($check_ary as $value => $_check) 678 { 679 if (isset($exclude[$value])) 680 { 681 continue; 682 } 683 $s_rule_options .= '<option value="' . $value . '"' . (($value == $rule_option) ? ' selected="selected"' : '') . '>' . $rule_lang[$value] . '</option>'; 684 } 685 } 686 687 $template->assign_vars(array( 688 'S_RULE_DEFINED' => true, 689 'S_RULE_SELECT' => !$hardcoded, 690 'RULE_CURRENT' => isset($rule_lang[$rule_option]) ? $rule_lang[$rule_option] : '', 691 'S_RULE_OPTIONS' => $s_rule_options, 692 'RULE_OPTION' => $rule_option) 693 ); 694 } 695 696 /** 697 * Defining condition option for message rules 698 */ 699 function define_cond_option($hardcoded, $cond_option, $rule_option, $global_rule_conditions) 700 { 701 global $db, $template, $auth, $user; 702 703 $template->assign_vars(array( 704 'S_COND_DEFINED' => true, 705 'S_COND_SELECT' => (!$hardcoded && isset($global_rule_conditions[$rule_option])) ? true : false) 706 ); 707 708 // Define COND_OPTION 709 if (!isset($global_rule_conditions[$rule_option])) 710 { 711 $template->assign_vars(array( 712 'COND_OPTION' => 'none', 713 'COND_CURRENT' => false) 714 ); 715 return; 716 } 717 718 // Define Condition 719 $condition = $global_rule_conditions[$rule_option]; 720 $current_value = ''; 721 722 switch ($condition) 723 { 724 case 'text': 725 $rule_string = utf8_normalize_nfc(request_var('rule_string', '', true)); 726 727 $template->assign_vars(array( 728 'S_TEXT_CONDITION' => true, 729 'CURRENT_STRING' => $rule_string, 730 'CURRENT_USER_ID' => 0, 731 'CURRENT_GROUP_ID' => 0) 732 ); 733 734 $current_value = $rule_string; 735 break; 736 737 case 'user': 738 $rule_user_id = request_var('rule_user_id', 0); 739 $rule_string = utf8_normalize_nfc(request_var('rule_string', '', true)); 740 741 if ($rule_string && !$rule_user_id) 742 { 743 $sql = 'SELECT user_id 744 FROM ' . USERS_TABLE . " 745 WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($rule_string)) . "'"; 746 $result = $db->sql_query($sql); 747 $rule_user_id = (int) $db->sql_fetchfield('user_id'); 748 $db->sql_freeresult($result); 749 750 if (!$rule_user_id) 751 { 752 $rule_string = ''; 753 } 754 } 755 else if (!$rule_string && $rule_user_id) 756 { 757 $sql = 'SELECT username 758 FROM ' . USERS_TABLE . " 759 WHERE user_id = $rule_user_id"; 760 $result = $db->sql_query($sql); 761 $rule_string = $db->sql_fetchfield('username'); 762 $db->sql_freeresult($result); 763 764 if (!$rule_string) 765 { 766 $rule_user_id = 0; 767 } 768 } 769 770 $template->assign_vars(array( 771 'S_USER_CONDITION' => true, 772 'CURRENT_STRING' => $rule_string, 773 'CURRENT_USER_ID' => $rule_user_id, 774 'CURRENT_GROUP_ID' => 0) 775 ); 776 777 $current_value = $rule_string; 778 break; 779 780 case 'group': 781 $rule_group_id = request_var('rule_group_id', 0); 782 $rule_string = utf8_normalize_nfc(request_var('rule_string', '', true)); 783 784 $sql = 'SELECT g.group_id, g.group_name, g.group_type 785 FROM ' . GROUPS_TABLE . ' g '; 786 787 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) 788 { 789 $sql .= 'LEFT JOIN ' . USER_GROUP_TABLE . ' ug 790 ON ( 791 g.group_id = ug.group_id 792 AND ug.user_id = ' . $user->data['user_id'] . ' 793 AND ug.user_pending = 0 794 ) 795 WHERE (ug.user_id = ' . $user->data['user_id'] . ' OR g.group_type <> ' . GROUP_HIDDEN . ') 796 AND'; 797 } 798 else 799 { 800 $sql .= 'WHERE'; 801 } 802 803 $sql .= " (g.group_name NOT IN ('GUESTS', 'BOTS') OR g.group_type <> " . GROUP_SPECIAL . ') 804 ORDER BY g.group_type DESC, g.group_name ASC'; 805 806 $result = $db->sql_query($sql); 807 808 $s_group_options = ''; 809 while ($row = $db->sql_fetchrow($result)) 810 { 811 if ($rule_group_id && ($row['group_id'] == $rule_group_id)) 812 { 813 $rule_string = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']); 814 } 815 816 $s_class = ($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : ''; 817 $s_selected = ($row['group_id'] == $rule_group_id) ? ' selected="selected"' : ''; 818 819 $s_group_options .= '<option value="' . $row['group_id'] . '"' . $s_class . $s_selected . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>'; 820 } 821 $db->sql_freeresult($result); 822 823 $template->assign_vars(array( 824 'S_GROUP_CONDITION' => true, 825 'S_GROUP_OPTIONS' => $s_group_options, 826 'CURRENT_STRING' => $rule_string, 827 'CURRENT_USER_ID' => 0, 828 'CURRENT_GROUP_ID' => $rule_group_id) 829 ); 830 831 $current_value = $rule_string; 832 break; 833 834 default: 835 return; 836 } 837 838 $template->assign_vars(array( 839 'COND_OPTION' => $condition, 840 'COND_CURRENT' => $current_value) 841 ); 842 } 843 844 /** 845 * Display defined message rules 846 */ 847 function show_defined_rules($user_id, $check_lang, $rule_lang, $action_lang, $folder) 848 { 849 global $db, $template; 850 851 $sql = 'SELECT * 852 FROM ' . PRIVMSGS_RULES_TABLE . ' 853 WHERE user_id = ' . $user_id . ' 854 ORDER BY rule_id ASC'; 855 $result = $db->sql_query($sql); 856 857 $count = 0; 858 while ($row = $db->sql_fetchrow($result)) 859 { 860 $template->assign_block_vars('rule', array( 861 'COUNT' => ++$count, 862 'RULE_ID' => $row['rule_id'], 863 'CHECK' => $check_lang[$row['rule_check']], 864 'RULE' => $rule_lang[$row['rule_connection']], 865 'STRING' => $row['rule_string'], 866 'ACTION' => $action_lang[$row['rule_action']], 867 'FOLDER' => ($row['rule_action'] == ACTION_PLACE_INTO_FOLDER) ? $folder[$row['rule_folder_id']]['folder_name'] : '') 868 ); 869 } 870 $db->sql_freeresult($result); 871 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |