[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/ucp/ -> ucp_pm_options.php (source)

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


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1