Commit 9d13aea6 authored by Nigel McNie's avatar Nigel McNie
Browse files
parents 518b59aa be42786a
......@@ -108,9 +108,11 @@ function UserSearch() {
self.params.action = 'search';
sendjsonrequest('search.json.php', self.params, 'POST', function(data) {
$('results').innerHTML = data.data;
self.rewritePaging();
self.rewriteSorting();
self.rewriteSuspendLinks();
if ($('searchresults')) {
self.rewritePaging();
self.rewriteSorting();
self.rewriteSuspendLinks();
}
});
}
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
//
// NOTE:
// This script is used by the userlist element to retrieve data on all users,
// for the 'potential staff' and 'potential admins' boxes. The general plan is
// that after 0.9, the script admin/users/search.json.php is used instead of
// this one, as per richardm's institutionaladmin branch. At which point, this
// script will probably be removed.
//
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
if (!$USER->get('admin')) {
throw new AccessDeniedException();
}
require('searchlib.php');
safe_require('search', 'internal');
try {
$query = param_variable('query');
}
catch (ParameterException $e) {
json_reply('missingparameter','Missing parameter \'query\'');
}
$limit = param_integer('limit', 20);
$offset = param_integer('offset', 0);
$allfields = param_boolean('allfields');
if ($query) {
$query = array(
array(
'type' => 'contains',
'field' => 'firstname',
'string' => $query,
),
array(
'type' => 'contains',
'field' => 'lastname',
'string' => $query,
),
array(
'type' => 'contains',
'field' => 'username',
'string' => $query,
),
);
}
$data = call_static_method(generate_class_name('search', 'internal'), 'admin_search_user',
$query, null, $offset, $limit, 'username', 'asc');
if ($data['data']) {
foreach($data['data'] as &$row) {
$row['name'] = display_name($row);
}
}
json_headers();
$data['error'] = false;
$data['message'] = false;
echo json_encode($data);
?>
......@@ -1547,4 +1547,17 @@ function db_ignore_sql_exceptions($status=null) {
$DB_IGNORE_SQL_EXCEPTIONS = (bool)$status;
}
/**
* Returns the SQL keyword required to do LIKE in a case insensitive fashion.
*
* MySQL, as long as you use a case insensitive collation (as is the default),
* uses LIKE for this, while real databases use ILIKE.
*/
function db_ilike() {
if (is_mysql()) {
return 'LIKE';
}
return 'ILIKE';
}
?>
......@@ -163,20 +163,18 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
$searchurl = get_config('wwwroot') . 'admin/users/search.php?' . join('&amp;', $params)
. '&amp;limit=' . $limit;
$templatedir = get_config('docroot') . 'theme/' . get_config('theme') . '/templates/admin/users/';
$cols = array(
'icon' => array('name' => '',
'template' => file_get_contents($templatedir . 'icon.tpl')),
'template' => '<img src="' . get_config('wwwroot') . 'thumb.php?type=profileicon&size=40x40&id={$r.id}" alt="' . get_string('profileimage') . '" />'),
'firstname' => array('name' => get_string('firstname')),
'lastname' => array('name' => get_string('lastname')),
'username' => array('name' => get_string('username'),
'template' => file_get_contents($templatedir . 'username.tpl')),
'template' => '<a href="' . get_config('wwwroot') . 'user/view.php?id={$r.id}">{$r.username|escape}</a>'),
'email' => array('name' => get_string('email')),
'institution' => array('name' => get_string('institution'),
'template' => file_get_contents($templatedir . 'institution.tpl')),
'template' => '{$institutions[$r.institution]->displayname|escape}'),
'suspend' => array('name' => '',
'template' => file_get_contents($templatedir . 'suspendlink.tpl'))
'template' => '{if !$r.suspended || $r.suspended == \'f\'}<a class="suspend-user-link" href="' . get_config('wwwroot') . 'admin/users/suspend.php?id={$r.id}">' . get_string('suspenduser', 'admin') . '</a>{/if}'),
);
$smarty = smarty_core();
......
......@@ -237,30 +237,20 @@ class PluginSearchInternal extends PluginSearch {
}
public static function admin_search_user($queries, $constratints, $offset, $limit,
public static function admin_search_user($queries, $constraints, $offset, $limit,
$sortfield, $sortdir) {
if (is_postgres()) {
return self::admin_search_user_pg($queries, $constratints, $offset, $limit,
$sortfield . ' ' . strtoupper($sortdir));
}
//else if (is_mysql()) {
// return self::admin_search_user_my($query_string, $limit, $offset);
//}
else {
throw new SQLException('admin_search_user() is not implemented for your database engine (' . get_config('dbtype') . ')');
}
}
public static function admin_search_user_pg($queries, $constraints, $offset, $limit, $sort) {
$sort = $sortfield . ' ' . strtoupper($sortdir);
$where = 'WHERE u.id <> 0 AND u.deleted = 0';
$values = array();
// Get the correct keyword for case insensitive LIKE
$ilike = db_ilike();
// Only handle OR/AND expressions at the top level. Eventually we may need subexpressions.
$matchtypes = array('starts' => ' ILIKE ? || \'%\'',
$matchtypes = array('starts' => " $ilike ? || '%'",
'equals' => ' = ? ',
'contains' => ' ILIKE \'%\' || ? || \'%\'');
'contains' => " $ilike '%' || ? || '%'");
if (!empty($queries)) {
$where .= ' AND ( ';
......
<img src="{$WWWROOT}thumb.php?type=profileicon&size=40x40&id={$r.id}" alt="{str tag=profileimage}" />
\ No newline at end of file
{$institutions[$r.institution]->displayname}
\ No newline at end of file
{if !$r.suspended || $r.suspended == 'f'}
<a class="suspend-user-link" href="{$WWWROOT}admin/users/suspend.php?id={$r.id}">{str tag=suspenduser section=admin}</a>
{/if}
\ No newline at end of file
<a href="{$WWWROOT}user/view.php?id={$r.id}">{$r.username}</a>
\ No newline at end of file
......@@ -5,7 +5,12 @@
replaceChildNodes('{{$name}}_messages');
sendjsonrequest('{{$WWWROOT}}json/usersearch.php', {'query':q, 'limit': 100}, 'GET',
// NOTE TO MERGE PEOPLE: I'm aware this template has changed, so
// there's a conflict here. The general plan here is to make this use
// richardm's admin/users/search.json.php script with raw=1, and remove
// json/adminusersearch.php when the merge happens. Talk to him or
// Nigel about this.
sendjsonrequest('{{$WWWROOT}}json/adminusersearch.php', {'query':q, 'limit': 100}, 'GET',
function (users) {
var members = {};
var counter = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment