Commit b5b899b1 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Change user searches to autocomplete boxes (Bug #1396845)

Now we pass round the userid rather than the username as well

Change-Id: I633d058e7b0cc6efd9b3fcb626635f380aa55968
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent da2b9fb3
{include file="header.tpl"}
<p>{str tag="usersearchinstructions" section="str.webservice"}</p>
<div id="initials">
<label>{str tag="firstname"}:</label>
<span class="{if !$search->f} selected{/if} all">
<a href="{$WWWROOT}webservice/admin/search.php{if $search->l}?l={$search->l}{/if}">{str tag="All"}</a>
</span>
{foreach from=$alphabet item=a}
<span class="{if $a == $search->f} selected{/if}">
<a href="{$WWWROOT}webservice/admin/search.php?f={$a}{if $search->l}&amp;l={$search->l}{/if}">{$a}</a>
</span>
{/foreach}
<br />
<label>{str tag="lastname"}:</label>
<span class="{if !$search->l} selected{/if} all">
<a href="{$WWWROOT}webservice/admin/search.php{if $search->f}?f={$search->f}{/if}">{str tag="All"}</a>
</span>
{foreach from=$alphabet item=a}
<span class="{if $a == $search->l} selected{/if}">
<a href="{$WWWROOT}webservice/admin/search.php?l={$a}{if $search->f}&amp;f={$search->f}{/if}">{$a}</a>
</span>
{/foreach}
</div>
<form action="{$WWWROOT}webservice/admin/search.php" method="post">
<div class="searchform">
<label>{str tag='Search' section='admin'}:</label>
<input type="text" name="query" id="query"{if $search->query} value="{$search->query}"{/if}>
{if count($institutions) > 1}
<span class="institutions">
<label>{str tag='Institution' section='admin'}:</label>
{if $USER->get('admin')}
<select name="institution" id="institution">
{else}
<select name="institution_requested" id="institution_requested">
{/if}
<option value="all"{if !$.request.institution} selected="selected"{/if}>{str tag=All}</option>
{foreach from=$institutions item=i}
<option value="{$i->name}"{if $i->name == $.request.institution}" selected="selected"{/if}>{$i->displayname}</option>
{/foreach}
</select>
</span>
{/if}
<input type="hidden" name="token" id="token" value="{$token_id}" />
<input type="hidden" name="suid" id="suid" value="{$suid}" />
<input type="hidden" name="ouid" id="ouid" value="{$ouid}" />
<button id="query-button" class="btn-search" type="submit">{str tag="go"}</button>
<input type="submit" class="submitcancel cancel" id="cancel_submit" name="cancel_submit" value="{$cancel}">
</div>
<div id="results" class="section">
<h2 id="resultsheading">{str tag="Results"}</h2>
{if $results}
<table id="searchresults" class="tablerenderer fullwidth listing">
<thead>
<tr>
{foreach from=$columns key=f item=c}
<th class="{if $c.sort}search-results-sort-column{if $f == $sortby} {$sortdir}{/if}{/if}{if $c.class} {$c.class}{/if}">
{if $c.sort}
<a href="{$searchurl}&sortby={$f}&sortdir={if $f == $sortby && $sortdir == 'asc'}desc{else}asc{/if}">
{$c.name}
<span class="accessible-hidden">({str tag=sortby} {if $f == $sortby && $sortdir == 'asc'}{str tag=descending}{else}{str tag=ascending}{/if})</span>
</a>
{else}
{$c.name}
{/if}
{if $c.help}
{$c.helplink|safe}
{/if}
{if $c.headhtml}<div style="font-weight: normal;">{$c.headhtml|safe}</div>{/if}
</th>
{/foreach}
</tr>
</thead>
<tbody>
{$results|safe}
</tbody>
</table>
{$pagination|safe}
{else}
<div>{str tag="noresultsfound"}</div>
{/if}
</div>
</form>
{include file="footer.tpl"}
<a href="{$returnurl}&user={$r.id}"><img src="{profile_icon_url user=$r maxwidth=40 maxheight=40}" alt="{str tag=profileimage}" />
{if $results.data}
<div id="setlimit" class="setlimit fr">
{str tag=resultsperpage}:
{foreach from=$limitoptions item=l}
<a href="?suid={$suid}&token={$token}&limit={$l}"{if $l == $results.limit} class="selected"{/if}>{$l}</a>
{/foreach}
</div>
<h2>{str tag="Results"}</h2>
<table id="searchresults" class="tablerenderer fullwidth listing">
<thead>
<tr>
{foreach from=$columns key=f item=c}
BLAH
<th class="{if $c.sort}search-results-sort-column{if $f == $sortby} {$sortdir}{/if}{/if}{if $c.class} {$c.class}{/if}">
{if $c.sort}
<a href="{$searchurl}&sortby={$f}&sortdir={if $f == $sortby && $sortdir == 'asc'}desc{else}asc{/if}">
{$c.name}
<span class="accessible-hidden">({str tag=sortby} {if $f == $sortby && $sortdir == 'asc'}{str tag=descending}{else}{str tag=ascending}{/if})</span>
</a>
{else}
{$c.name}
{/if}
{if $c.help}
{$c.helplink|safe}
{/if}
{if $c.headhtml}<div style="font-weight: normal;">{$c.headhtml|safe}</div>{/if}
</th>
{/foreach}
</tr>
</thead>
<tbody>
{$results|safe}
</tbody>
</table>
{$pagination|safe}
{else}
<div>{str tag="noresultsfound"}</div>
{/if}
<a href="{$returnurl}&user={$r.id}">{$r.username}</a>
\ No newline at end of file
......@@ -108,8 +108,8 @@ function webservices_token_submit(Pieform $form, $values) {
global $SESSION, $USER;
if ($values['action'] == 'generate') {
if (isset($values['username'])) {
$dbuser = get_record('usr', 'username', $values['username']);
if (isset($values['userid'])) {
$dbuser = get_record('usr', 'id', $values['userid']);
if (!empty($dbuser)) {
$services = get_records_array('external_services', 'restrictedusers', 0);
if (empty($services)) {
......@@ -155,8 +155,8 @@ function webservices_user_submit(Pieform $form, $values) {
global $SESSION, $USER;
if ($values['action'] == 'add') {
if (isset($values['username'])) {
$dbuser = get_record('usr', 'username', $values['username']);
if (isset($values['userid'])) {
$dbuser = get_record('usr', 'id', $values['userid']);
if ($auth_instance = webservice_validate_user($dbuser)) {
// make sure that this account is not already in use
$existing = get_record('external_services_users', 'userid', $dbuser->id);
......@@ -644,20 +644,18 @@ function service_tokens_edit_form() {
'name' => 'webservices_token_generate',
'renderer' => 'oneline',
'successcallback' => 'webservices_token_submit',
'class' => 'oneline inline',
'jsform' => false,
'action' => get_config('wwwroot') . 'webservice/admin/index.php',
'elements' => array(
'username' => array(
'type' => 'text',
'title' => get_string('username'),
'value' => $username,
),
'usersearch' => array(
'type' => 'html',
'value' => '&nbsp;<a href="' . get_config('wwwroot') .'webservice/admin/search.php?token=add"><img src="' . $searchicon . '" id="usersearch"/></a> &nbsp; ',
),
'userid' => array(
'type' => 'autocomplete',
'title' => get_string('username') . ': ',
'ajaxurl' => get_config('wwwroot') . 'webservice/admin/users.json.php',
'multiple' => false,
'allowclear' => true,
'ajaxextraparams' => array(),
'width' => '400px',
),
'action' => array('type' => 'hidden', 'value' => 'generate'),
'submit' => array(
'type' => 'submit',
......@@ -840,20 +838,18 @@ function service_users_edit_form() {
'name' => 'webservices_user_generate',
'renderer' => 'oneline',
'successcallback' => 'webservices_user_submit',
'class' => 'oneline inline',
'jsform' => false,
'action' => get_config('wwwroot') . 'webservice/admin/index.php',
'elements' => array(
'username' => array(
'type' => 'text',
'title' => get_string('username'),
'value' => $username,
),
'usersearch' => array(
'type' => 'html',
'value' => '&nbsp;<a href="' . get_config('wwwroot') . 'webservice/admin/search.php?suid=add"><img src="' . $searchicon . '" id="usersearch"/></a> &nbsp; ',
),
'userid' => array(
'type' => 'autocomplete',
'title' => get_string('username') . ': ',
'ajaxurl' => get_config('wwwroot') . 'webservice/admin/users.json.php',
'multiple' => false,
'allowclear' => true,
'ajaxextraparams' => array(),
'width' => '400px',
),
'action' => array('type' => 'hidden', 'value' => 'add'),
'submit' => array(
'type' => 'submit',
......
<?php
/**
*
* @package mahara
* @subpackage auth-webservice
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configextensions/pluginadminwebservices');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('pluginadmin', 'admin'));
$plugintype = 'auth';
$pluginname = 'webservice';
define('SECTION_PLUGINTYPE', $plugintype);
define('SECTION_PLUGINNAME', $pluginname);
define('SECTION_PAGE', 'pluginconfig');
require_once('webservicessearchlib.php');
// validate the incoming token
$token = param_variable('token', '');
$suid = param_variable('suid', '');
$ouid = param_variable('ouid', '');
// did the user cancel
if (param_alpha('cancel_submit', 'empty') != 'empty') {
if ($ouid) {
redirect('/webservice/admin/oauthv1sregister.php?ouid=' . $ouid);
}
else if ($suid) {
redirect('/webservice/admin/userconfig.php?suid=' . $suid);
}
else {
redirect('/webservice/admin/tokenconfig.php?token=' . $token);
}
}
$sortby = param_alpha('sortby', 'firstname');
$sortdir = param_alpha('sortdir', 'asc');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$search = (object) array(
'query' => trim(param_variable('query', '')),
'f' => param_alpha('f', null),
'l' => param_alpha('l', null),
'sortby' => $sortby,
'sortdir' => $sortdir,
'loggedin' => 'any',
'loggedindate' => strftime(get_string('strftimedatetimeshort')),
'duplicateemail' => false,
'offset' => $offset,
'limit' => $limit,
);
if ($USER->get('admin')) {
$institutions = get_records_array('institution', '', '', 'displayname');
$search->institution = param_alphanum('institution', 'all');
}
else {
$institutions = get_records_select_array('institution', "name IN ('" . join("','", array_keys($USER->get('admininstitutions'))) . "')", null, 'displayname');
$search->institution_requested = param_alphanum('institution_requested', 'all');
}
$smarty = smarty(array(get_config('wwwroot') . 'webservice/admin/js/usersearch.js'));
$smarty->assign('token_id', $token);
$smarty->assign('token', $token);
$smarty->assign('suid', $suid);
$smarty->assign('ouid', $ouid);
$smarty->assign('search', $search);
$smarty->assign('alphabet', explode(',', get_string('alphabet')));
$smarty->assign('cancel', get_string('cancel'));
$smarty->assign('institutions', $institutions);
list($html, $columns, $searchurl, $pagination) = build_webservice_user_search_results($search, $offset, $limit, $sortby, $sortdir);
$smarty->assign('results', $html);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('columns', $columns);
$smarty->assign('searchurl', $searchurl['url']);
$smarty->assign('sortby', $searchurl['sortby']);
$smarty->assign('sortdir', $searchurl['sortdir']);
if ($token) {
$heading = get_string('headingusersearchtoken', 'auth.webservice');
}
else {
$heading = get_string('headingusersearchuser', 'auth.webservice');
}
$smarty->assign('PAGEHEADING', $heading);
$smarty->display('auth:webservice:search.tpl');
<?php
/**
*
* @package mahara
* @subpackage webservices
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('docroot') . '/lib/searchlib.php');
global $USER;
$request = param_variable('q');
$page = param_integer('page');
if ($page < 1) {
$page = 1;
}
$usersperpage = 5;
$more = true;
$tmpuser = array();
while ($more && count($tmpuser) < $usersperpage) {
$users = search_user($request, $usersperpage, $usersperpage * ($page - 1));
$more = $users['count'] > $usersperpage * $page;
if (!$users['data']) {
$users['data'] = array();
}
foreach ($users['data'] as $user) {
if (count($tmpuser) >= $usersperpage) {
$more = true;
continue;
}
$tmpuser[] = (object) array('id' => $user['id'],
'text' => display_name($user['id']));
}
$page++;
}
echo json_encode(array(
'more' => $more,
'results' => $tmpuser,
));
\ No newline at end of file
This diff is collapsed.
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