Exemplo n.º 1
0
 public function pre_dispatch()
 {
     global $context, $txt;
     // These are all the possible fields.
     $this->_search_fields = array('name' => $txt['mlist_search_name'], 'email' => $txt['mlist_search_email'], 'website' => $txt['mlist_search_website'], 'group' => $txt['mlist_search_group']);
     // Are there custom fields they can search?
     require_once SUBSDIR . '/Memberlist.subs.php';
     ml_findSearchableCustomFields();
     // These are handy later
     $context['old_search_value'] = '';
     $context['in_search'] = !empty($_REQUEST['search']);
     foreach ($context['custom_search_fields'] as $field) {
         $this->_search_fields['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
     }
 }
Exemplo n.º 2
0
 /**
  * Search for members, or display search results.
  * If variable $_REQUEST['search'] is empty displays search dialog box, using the search sub-template.
  * Calls printMemberListRows to retrieve the results of the query.
  */
 public function action_mlsearch()
 {
     global $txt, $scripturl, $context, $modSettings;
     $context['page_title'] = $txt['mlist_search'];
     $context['can_moderate_forum'] = allowedTo('moderate_forum');
     // Are there custom fields they can search?
     ml_findSearchableCustomFields();
     // They're searching..
     if (isset($_REQUEST['search']) && isset($_REQUEST['fields'])) {
         $search = Util::htmlspecialchars(trim(isset($_GET['search']) ? $_GET['search'] : $_POST['search']), ENT_QUOTES);
         $input_fields = isset($_GET['fields']) ? explode(',', $_GET['fields']) : $_POST['fields'];
         $context['old_search'] = $_REQUEST['search'];
         $context['old_search_value'] = urlencode($_REQUEST['search']);
         // No fields?  Use default...
         if (empty($input_fields)) {
             $input_fields = array('name');
         }
         // Set defaults for how the results are sorted
         if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
             $_REQUEST['sort'] = 'real_name';
         }
         // Build the column link / sort information.
         foreach ($context['columns'] as $col => $column_details) {
             $context['columns'][$col]['href'] = $scripturl . '?action=memberlist;sa=search;start=0;sort=' . $col;
             if (!isset($_REQUEST['desc']) && $col == $_REQUEST['sort'] || $col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])) {
                 $context['columns'][$col]['href'] .= ';desc';
             }
             $context['columns'][$col]['href'] .= ';search=' . $search . ';fields=' . implode(',', $input_fields);
             $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
             $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
         }
         // set up some things for use in the template
         $context['sort_direction'] = !isset($_REQUEST['desc']) ? 'up' : 'down';
         $context['sort_by'] = $_REQUEST['sort'];
         $query_parameters = array('regular_id_group' => 0, 'is_activated' => 1, 'blank_string' => '', 'search' => '%' . strtr($search, array('_' => '\\_', '%' => '\\%', '*' => '%')) . '%', 'sort' => $context['columns'][$_REQUEST['sort']]['sort'][$context['sort_direction']]);
         // Search for a name
         if (in_array('name', $input_fields)) {
             $fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name');
         } else {
             $fields = array();
         }
         // Search for websites.
         if (in_array('website', $input_fields)) {
             $fields += array(7 => 'website_title', 'website_url');
         }
         // Search for groups.
         if (in_array('group', $input_fields)) {
             $fields += array(9 => 'IFNULL(group_name, {string:blank_string})');
         }
         // Search for an email address?
         if (in_array('email', $input_fields)) {
             $fields += array(2 => allowedTo('moderate_forum') ? 'email_address' : '(hide_email = 0 AND email_address');
             $condition = allowedTo('moderate_forum') ? '' : ')';
         } else {
             $condition = '';
         }
         if (defined('DB_CASE_SENSITIVE')) {
             foreach ($fields as $key => $field) {
                 $fields[$key] = 'LOWER(' . $field . ')';
             }
         }
         $customJoin = array();
         $customCount = 10;
         $validFields = array();
         // Any custom fields to search for - these being tricky?
         foreach ($input_fields as $field) {
             $curField = substr($field, 5);
             if (substr($field, 0, 5) === 'cust_' && isset($context['custom_search_fields'][$curField])) {
                 $customJoin[] = 'LEFT JOIN {db_prefix}custom_fields_data AS cfd' . $curField . ' ON (cfd' . $curField . '.variable = {string:cfd' . $curField . '} AND cfd' . $curField . '.id_member = mem.id_member)';
                 $query_parameters['cfd' . $curField] = $curField;
                 $fields += array($customCount++ => 'IFNULL(cfd' . $curField . '.value, {string:blank_string})');
                 $validFields[] = $field;
             }
         }
         if (empty($fields)) {
             redirectexit('action=memberlist');
         }
         $query = $search == '' ? '= {string:blank_string}' : (defined('DB_CASE_SENSITIVE') ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}');
         $where = implode(' ' . $query . ' OR ', $fields) . ' ' . $query . $condition;
         // Find the members from the database.
         $numResults = ml_searchMembers($query_parameters, $customJoin, $where, $_REQUEST['start']);
         $context['page_index'] = constructPageIndex($scripturl . '?action=memberlist;sa=search;search=' . $search . ';fields=' . implode(',', $validFields), $_REQUEST['start'], $numResults, $modSettings['defaultMaxMembers']);
     } else {
         redirectexit('action=memberlist');
     }
     $context['linktree'][] = array('url' => $scripturl . '?action=memberlist;sa=search', 'name' => &$context['page_title']);
     // Highlight the correct button, too!
     unset($context['memberlist_buttons']['view_all_members']['active']);
 }