Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Members search #671

Merged
merged 3 commits into from Jul 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 27 additions & 23 deletions sources/controllers/Memberlist.controller.php
Expand Up @@ -69,7 +69,7 @@ public function action_index()

// Set up the standard columns...
$context['columns'] = array(
'is_online' => array(
'online' => array(
'label' => $txt['status'],
'width' => 60,
'class' => 'first_th centertext',
Expand Down Expand Up @@ -109,7 +109,7 @@ public function action_index()
'up' => 'IFNULL(mg.group_name, 1=1) ASC, mg.group_name ASC'
),
),
'registered' => array(
'date_registered' => array(
'label' => $txt['date_registered'],
'sort' => array(
'down' => 'mem.date_registered DESC',
Expand Down Expand Up @@ -155,17 +155,39 @@ public function action_index()
);

$context['can_send_pm'] = allowedTo('pm_send');
$context['can_send_email'] = allowedTo('send_email_to_members');

// Build the memberlist button array.
$context['memberlist_buttons'] = array(
'view_all_members' => array('text' => 'view_all_members', 'image' => 'mlist.png', 'lang' => true, 'url' => $scripturl . '?action=memberlist' . ';sa=all', 'active'=> true),
'mlist_search' => array('text' => 'mlist_search', 'image' => 'mlist.png', 'lang' => true, 'url' => $scripturl . '?action=memberlist' . ';sa=search'),
);

// Are there custom fields they can search?
ml_findSearchableCustomFields();

// These are all the possible fields.
$context['search_fields'] = array(
'name' => $txt['mlist_search_name'],
'email' => $txt['mlist_search_email'],
'website' => $txt['mlist_search_website'],
'group' => $txt['mlist_search_group'],
);

foreach ($context['custom_search_fields'] as $field)
$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);

// What do we search for by default?
$context['search_defaults'] = array('name', 'email');

// Allow mods to add additional buttons here
call_integration_hook('integrate_memberlist_buttons');

if (!allowedTo('send_email_to_members'))
unset($context['columns']['email_address']);
if (isset($context['disabled_fields']['website']))
unset($context['columns']['website']);
if (isset($context['disabled_fields']['posts']))
unset($context['columns']['posts']);

// Jump to the sub action.
if (isset($subActions[$context['listing_by']]))
$this->{$subActions[$context['listing_by']][1]}();
Expand Down Expand Up @@ -429,24 +451,7 @@ public function action_mlsearch()
$context['page_index'] = constructPageIndex($scripturl . '?action=memberlist;sa=search;search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']), $_REQUEST['start'], $numResults, $modSettings['defaultMaxMembers']);
}
else
{
// These are all the possible fields.
$context['search_fields'] = array(
'name' => $txt['mlist_search_name'],
'email' => $txt['mlist_search_email'],
'website' => $txt['mlist_search_website'],
'group' => $txt['mlist_search_group'],
);

foreach ($context['custom_search_fields'] as $field)
$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);

// What do we search for by default?
$context['search_defaults'] = array('name', 'email');

$context['sub_template'] = 'search';
$context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? htmlspecialchars($_POST['search']) : '');
}
redirectexit('action=memberlist');

$context['linktree'][] = array(
'url' => $scripturl . '?action=memberlist;sa=search',
Expand All @@ -455,6 +460,5 @@ public function action_mlsearch()

// Highlight the correct button, too!
unset($context['memberlist_buttons']['view_all_members']['active']);
$context['memberlist_buttons']['mlist_search']['active'] = true;
}
}
5 changes: 5 additions & 0 deletions sources/subs/Memberlist.subs.php
Expand Up @@ -340,6 +340,11 @@ function printMemberListRows($request)
$context['members'][$member] = $memberContext[$member];
$context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts);
$context['members'][$member]['registered_date'] = strftime('%Y-%m-%d', $context['members'][$member]['registered_timestamp']);
$context['members'][$member]['real_name'] = $context['members'][$member]['link'];
$context['members'][$member]['email_address'] = $context['members'][$member]['email'];
$context['members'][$member]['website_url'] = $context['members'][$member]['website']['url'] != '' ? '<a href="' . $context['members'][$member]['website']['url'] . '" target="_blank" class="new_win"><img src="' . $settings['images_url'] . '/profile/www.png" alt="' . $context['members'][$member]['website']['title'] . '" title="' . $context['members'][$member]['website']['title'] . '" /></a>' : '';
$context['members'][$member]['id_group'] = empty($context['members'][$member]['group']) ? $context['members'][$member]['post_group'] : $context['members'][$member]['group'];
$context['members'][$member]['date_registered'] = $context['members'][$member]['registered'];

// Take care of the custom fields if any are being displayed
if (!empty($context['custom_profile_fields']['columns']))
Expand Down
137 changes: 58 additions & 79 deletions themes/default/Memberlist.template.php
Expand Up @@ -21,9 +21,37 @@ function template_main()
{
global $context, $settings, $scripturl, $txt;

template_pagesection('memberlist_buttons', 'right', 'go_down');
$extra = '
<form id="mlsearch" action="' . $scripturl . '?action=memberlist;sa=search" method="post" accept-charset="UTF-8">
<ul class="floatright">
<li>
<input onfocus="toggle_mlsearch_opt();" onblur="toggle_mlsearch_opt();" type="text" name="search" value="" class="input_text" placeholder="' . $txt['search'] . '" />&nbsp;
<input type="submit" name="search2" value="' . $txt['search'] . '" class="button_submit" />
<ul id="mlsearch_options">';

foreach ($context['search_fields'] as $id => $title)
{
$extra .= '
<li class="mlsearch_option">
<label for="fields-' . $id . '"><input type="checkbox" name="fields[]" id="fields-' . $id . '" value="' . $id . '" ' . (in_array($id, $context['search_defaults']) ? 'checked="checked"' : '') . ' class="input_check floatright" />' . $title . '</label>
</li>';
}

$extra .= '
</ul>
</li>
</ul>
</form>';

template_pagesection('memberlist_buttons', 'right', 'go_down', array('extra' => $extra));

echo '
<script><!-- // --><![CDATA[
function toggle_mlsearch_opt()
{
$("#mlsearch_options").slideToggle("fast");
}
// ]]></script>
<div id="memberlist">
<h2 class="category_header">
<span class="floatleft">', $txt['members_list'], '</span>';
Expand All @@ -41,10 +69,6 @@ function template_main()
// Display each of the column headers of the table.
foreach ($context['columns'] as $key => $column)
{
// @TODO maybe find something nicer?
if ($key == 'email_address' && !$context['can_send_email'])
continue;

// This is a selected column, so underline it or some such.
if ($column['selected'])
echo '
Expand All @@ -70,37 +94,36 @@ function template_main()
foreach ($context['members'] as $member)
{
echo '
<tr class="', $alternate ? 'alternate_' : 'standard_', 'row"', empty($member['sort_letter']) ? '' : ' id="letter' . $member['sort_letter'] . '"', '>
<td class="centertext">
', $context['can_send_pm'] ? '<a href="' . $member['online']['href'] . '" title="' . $member['online']['text'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $member['online']['image_href'] . '" alt="' . $member['online']['text'] . '" class="centericon" />' : $member['online']['label'], $context['can_send_pm'] ? '</a>' : '', '
</td>
<td>', $member['link'], '</td>';

if ($context['can_send_email'])
echo '
<td class="centertext">', $member['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $member['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/profile/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $member['name'] . '" /></a>', '</td>';

if (!isset($context['disabled_fields']['website']))
echo '
<td class="centertext">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" class="new_win"><img src="' . $settings['images_url'] . '/profile/www.png" alt="' . $member['website']['title'] . '" title="' . $member['website']['title'] . '" /></a>' : '', '</td>';

// Group and date.
echo '
<td>', empty($member['group']) ? $member['post_group'] : $member['group'], '</td>
<td>', $member['registered_date'], '</td>';

if (!isset($context['disabled_fields']['posts']))
{
echo '
<td class="centertext">', $member['posts'], '</td>';
}

// Any custom fields on display?
if (!empty($context['custom_profile_fields']['columns']))
<tr class="', $alternate ? 'alternate_' : 'standard_', 'row"', empty($member['sort_letter']) ? '' : ' id="letter' . $member['sort_letter'] . '"', '>';
foreach ($context['columns'] as $column => $values)
{
foreach ($context['custom_profile_fields']['columns'] as $key => $column)
echo '
<td>', $member['options'][substr($key, 5)], '</td>';
if (isset($member[$column]))
{
if ($column == 'online')
{
echo '
<td class="centertext">
', $context['can_send_pm'] ? '<a href="' . $member['online']['href'] . '" title="' . $member['online']['text'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $member['online']['image_href'] . '" alt="' . $member['online']['text'] . '" class="centericon" />' : $member['online']['label'], $context['can_send_pm'] ? '</a>' : '', '
</td>';
continue;
}
elseif ($column == 'email_address')
{
echo '
<td class="centertext">', $member['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $member['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/profile/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $member['name'] . '" /></a>', '</td>';
continue;
}
else
echo '
<td>', $member[$column], '</td>';
}
// Any custom fields on display?
elseif (!empty($context['custom_profile_fields']['columns']) && isset($context['custom_profile_fields']['columns'][$column]))
{
foreach ($context['custom_profile_fields']['columns'] as $key => $col)
echo '
<td>', $member['options'][substr($key, 5)], '</td>';
}
}

echo '
Expand Down Expand Up @@ -133,48 +156,4 @@ function template_main()
echo '
</div>';

}

/**
* A page allowing people to search the member list.
*/
function template_search()
{
global $context, $settings, $scripturl, $txt;

template_pagesection('memberlist_buttons', 'right', '', array('top_button' => false));

// Start the submission form for the search!
echo '
<form id="memberlist" class="standard_category" action="', $scripturl, '?action=memberlist;sa=search" method="post" accept-charset="UTF-8">
<h2 class="category_header">
', !empty($settings['use_buttons']) ? '<img src="' . $settings['images_url'] . '/buttons/search_hd.png" alt="" class="icon" />' : '', $txt['mlist_search'], '
</h2>
<div class="content">
<dl id="memberlist_search" class="settings">
<dt>
<label><strong>', $txt['search_for'], ':</strong></label>
</dt>
<dd>
<input type="text" name="search" value="', $context['old_search'], '" size="40" class="input_text" placeholder="', $txt['search'], '" autofocus="autofocus" required="required" />
</dd>
<dt>
<label><strong>', $txt['mlist_search_filter'], ':</strong></label>
</dt>';

foreach ($context['search_fields'] as $id => $title)
{
echo '
<dd>
<label for="fields-', $id, '"><input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '" ', in_array($id, $context['search_defaults']) ? 'checked="checked"' : '', ' class="input_check floatright" />', $title, '</label>
</dd>';
}

echo '
</dl>
<div class="submit_buttons_wrap">
<input type="submit" name="submit" value="' . $txt['search'] . '" class="button_submit" />
</div>
</div>
</form>';
}
18 changes: 17 additions & 1 deletion themes/default/css/index.css
Expand Up @@ -3692,7 +3692,23 @@ dl.merge_topic dd {
width: 100%;
}


#mlsearch {
padding-top: 5px;
}
#mlsearch_options {
position: absolute;
display: none;
background: #FAFAFA;
padding: 0.5em;
border: 1px solid #DDDDDD;
border-radius: 5px;
}
#mlsearch_options .mlsearch_option .input_check {
margin-left: 0.5em;
}
#mlsearch_options .mlsearch_option {
padding: 0.2em 0;
}


/* $LOGIN */
Expand Down