Commit c541934b authored by Doris Tam's avatar Doris Tam Committed by Robert Lyon

Bug 920246: Adding category filter to admin/groups/groups.php

- Like the group/index.php page with the filter, this page also
  has a problem with the button when the width of screen is too small
- Added a parameter to an existing helper function for groupcategory
  (build_group_list_html
- Helper function group_get_extended_data(..) to htdocs/lib/group.php
- Fix previous bug failure due to button class change for submit
- Styling for table changed to to "break-word" to stop truncating words
- overflow of buttons controlled + responsive results heading+footer
- button moved to first level of form to stop button cutting button on
  small screen
behatnotneeded

Change-Id: I646135f6963f944b6d253d800882a77cac995e1a
parent 8f7021f0
......@@ -25,6 +25,8 @@ $offset = param_integer('offset', 0);
$limit = param_integer('limit', 0);
$limit = user_preferred_limit($limit, 'itemsperpage');
$institution = param_alphanum('institution', null);
$groupcategory = param_signed_integer('groupcategory', 0);
// Build the institution select field that sits behind the search field
$inst_select = array();
......@@ -36,42 +38,88 @@ if (is_array($institutions)) {
$inst_select[$inst->name] = $inst->displayname;
}
}
$inst_options = array();
$inst_options['all'] = get_string('Allinstitutions');
foreach ($institutions as $inst) {
$inst_options[$inst->name] = $inst->displayname;
}
$count = 0;
$data = build_grouplist_html($query, $limit, $offset, $count, $institution);
$data = build_grouplist_html($query, $limit, $offset, $count, $institution, $groupcategory);
$elements = array();
//dropdown with search
$queryfield = array(
'title' => get_string('search') . ': ',
'hiddenlabel' => false,
'type' => 'text',
'defaultvalue' => $query,
'class' => 'with-dropdown js-with-dropdown',
);
$filterfield = array(
'title' => get_string('Institution', 'admin'),
'hiddenlabel' => false,
'type' => 'select',
'class' => 'dropdown-connect js-dropdown-connect',
'options' => $inst_options,
'defaultvalue' => $institution
);
$elements['searchwithin'] = array(
'type' => 'fieldset',
'class' => 'dropdown-group js-dropdown-group',
'elements' => array(
'query' => $queryfield,
'filter' => $filterfield
)
);
$options = array();
$options[0] = get_string('allcategories', 'group');
$options[-1] = get_string('notcategorised', 'group');
if ($groupcategories = get_records_menu('group_category','','','displayorder', 'id,title')) {
$options += $groupcategories;
}
$groupcategoryfield = array(
'title' => get_string('groupcategory', 'group'). ': ',
'hiddenlabel' => false,
'type' => 'select',
'options' => $options,
'defaultvalue' => $groupcategory,
'class' => 'input-small'
);
$searchfield = array(
'type' => 'submit',
'usebuttontag' => true,
'class' => 'btn-primary input-group-append no-label button',
'value' => get_string('search'),
);
$elements['formgroupcategory'] = array(
'type' => 'fieldset',
'class' => 'form input-group',
'elements' => array(
'groupcategory' => $groupcategoryfield
)
);
$elements['search'] = $searchfield;
$searchform = pieform(array(
'name' => 'search',
'renderer' => 'div',
'method' => 'post',
'class' => 'form-inline with-heading dropdown admin-user-search',
'autofocus' => false,
'elements' => array(
'inputgroup' => array(
'type' => 'fieldset',
'class' => 'dropdown-group js-dropdown-group',
'elements' => array(
'query' => array(
'type' => 'text',
'defaultvalue' => $query,
'class' => 'with-dropdown js-with-dropdown',
'title' => get_string('search') . ': ',
),
'institution' => array(
'type' => 'select',
'title' => get_string('Institution', 'admin'),
'defaultvalue' => $institution,
'options' => $inst_select,
'class' => 'dropdown-connect js-dropdown-connect',
),
),
),
'submit' => array(
'type' => 'button',
'usebuttontag' => true,
'class' => 'btn-search btn btn-primary admin-groups',
'value' => get_string('search'),
)
),
));
'elements' => $elements
)
);
$js = <<< EOF
jQuery(function() {
......@@ -95,8 +143,9 @@ $smarty->assign('results', $data);
$smarty->display('admin/groups/groups.tpl');
function search_submit(Pieform $form, $values) {
$search = (isset($values['query']) && $values['query'] != '') ? 'query=' . urlencode($values['query']) : null;
$institution = (isset($values['institution']) && $values['institution'] != '') ? urlencode($values['institution']) : null;
$query = '?search=1&query=' . $search . '&institution=' . $institution;
$search = (isset($values['query']) && $values['query'] != '') ? urlencode($values['query']) : null;
$institution = (isset($values['filter']) && $values['filter'] != '') ? urlencode($values['filter']) : null;
$groupcategory = (!empty($values['groupcategory']) ? '&groupcategory=' . intval($values['groupcategory']) : '' );
$query = '?search=1&query=' . $search . '&institution=' . $institution . '&groupcategory' . $groupcategory;
redirect(get_config('wwwroot') . 'admin/groups/groups.php' . $query);
}
......@@ -54,47 +54,7 @@ else {
// including type if the user is associated with the group in some way
if ($searchmode == 'find') {
if ($groups['data']) {
$groupids = array();
foreach ($groups['data'] as $group) {
$groupids[] = $group->id;
}
$groups['data'] = get_records_sql_array("
SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests,
g1.editwindowstart, g1.editwindowend
FROM (
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, COUNT(gm.member) AS membercount,
g.editwindowstart, g.editwindowend
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN (
SELECT g.id, 'admin' AS membershiptype, gm.role AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS membershiptype, gm.role AS role
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')
UNION
SELECT g.id, 'invite' AS membershiptype, gmi.role
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION
SELECT g.id, 'request' AS membershiptype, NULL as role
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
WHERE g.id IN (" . implode($groupids, ',') . ')
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, g.editwindowstart, g.editwindowend
) g1
LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id)
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, g1.editwindowstart, g1.editwindowend
ORDER BY g1.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
$groups['data'] = group_get_extended_data($groups['data']);
}
}
......
......@@ -160,47 +160,7 @@ else {
// including type if the user is associated with the group in some way
if ($searchmode == 'find') {
if ($groups['data']) {
$groupids = array();
foreach ($groups['data'] as $group) {
$groupids[] = $group->id;
}
$groups['data'] = get_records_sql_array("
SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests,
g1.editwindowstart, g1.editwindowend
FROM (
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, COUNT(gm.member) AS membercount,
g.editwindowstart, g.editwindowend
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN (
SELECT g.id, 'admin' AS membershiptype, gm.role AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS membershiptype, gm.role AS role
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')
UNION
SELECT g.id, 'invite' AS membershiptype, gmi.role
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION
SELECT g.id, 'request' AS membershiptype, NULL as role
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
WHERE g.id IN (" . implode($groupids, ',') . ')
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, g.editwindowstart, g.editwindowend
) g1
LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id)
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, g1.editwindowstart, g1.editwindowend
ORDER BY g1.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
$groups['data'] = group_get_extended_data($groups['data']);
}
}
......
......@@ -956,8 +956,6 @@ function group_delete($groupid, $shortname=null, $institution=null, $notifymembe
}
delete_records('lti_assessment', 'group', $group->id);
}
// Delete any submission history
delete_records('module_assessmentreport_history', 'groupid', $group->id);
if ($notifymembers) {
require_once('activity.php');
......@@ -1737,11 +1735,8 @@ function group_prepare_usergroups_for_display($groups) {
else if ($group->membershiptype == 'invite') {
$group->invite = group_get_accept_form('invite' . $i++, $group->id);
}
// Only admin can create public groups when isolatedinstitutions is set.
// It's up to the admin to correctly set the jointype. Public should not affect the open status.
// So for isolatedinstitutions and open groups, people can join that group if it's in their
// institution.
else if ($group->jointype == 'open') {
// When 'isolatedinstitutions' is set, people cannot join public groups by themselves
else if ($group->jointype == 'open' && !(is_isolated() && $group->public == 1)) {
$group->groupjoin = group_get_join_form('joingroup' . $i++, $group->id);
}
......@@ -1788,10 +1783,10 @@ function group_format_editwindow($group) {
/*
* Used by admin/groups/groups.php and admin/groups/groups.json.php for listing groups.
*/
function build_grouplist_html($query, $limit, $offset, &$count=null, $institution) {
function build_grouplist_html($query, $limit, $offset, &$count=null, $institution, $groupcategory='') {
global $USER;
$groups = search_group($query, $limit, $offset, 'all', '', $institution);
$groups = search_group($query, $limit, $offset, 'all', $groupcategory, $institution);
$count = $groups['count'];
if ($ids = array_map(function($a) { return intval($a->id); }, $groups['data'])) {
......
......@@ -127,6 +127,7 @@ iframe {
.view-container {
margin-top: 15px;
clear: both;
overflow-x: auto;
}
.view-description {
......
......@@ -292,7 +292,7 @@ table.table tr {
.table>thead>tr>th.groupname,
.table>thead>tr>th.groupshortname,
.table>thead>tr>th.groupmanagebuttons {
width: 15%;
width: 8em;
}
.table.profile-info {
......
{include file="header.tpl"}
{$searchform|safe}
<div class="card view-container">
<h2 class="card-header">{str tag="Results"}</h2>
<div class="table-responsive">
<table id="admgroupslist" class="fullwidth table table-striped">
<thead>
<tr>
<th class="groupname">{str tag="groupname" section="admin"}</th>
<th class="groupshortname">{str tag="groupshortname" section="admin"}</th>
<th class="center">{str tag="groupmembers" section="admin"}</th>
<th class="center">{str tag="groupadmins" section="admin"}</th>
<th>{str tag="grouptype" section="admin"}</th>
{if get_config('allowgroupcategories')}
<th>{str tag="groupcategory" section="group"}</th>
{/if}
<th>{str tag="groupvisible" section="admin"}</th>
<th>{str tag="institution"}</th>
<th class="groupmanagebuttons"><span class="accessible-hidden sr-only">{str tag=edit}</span></th>
</tr>
</thead>
<tbody>
{$results.tablerows|safe}
</tbody>
</table>
</div>
<table id="admgroupslist" class="fullwidth table table-striped table-group-list">
<thead>
<tr>
<th class="groupname">{str tag="groupname" section="admin"}</th>
<th class="groupshortname">{str tag="groupshortname" section="admin"}</th>
<th class="center">{str tag="groupmembers" section="admin"}</th>
<th class="center">{str tag="groupadmins" section="admin"}</th>
<th>{str tag="grouptype" section="admin"}</th>
{if get_config('allowgroupcategories')}
<th>{str tag="groupcategory" section="group"}</th>
{/if}
<th>{str tag="groupvisible" section="admin"}</th>
<th>{str tag="institution"}</th>
<th class="groupmanagebuttons"><span class="accessible-hidden sr-only">{str tag=edit}</span></th>
</tr>
</thead>
<tbody>
{$results.tablerows|safe}
</tbody>
</table>
{if $results.csv}
<a href="{$WWWROOT}download.php" class="card-footer"><span class="icon icon-table" role="presentation" aria-hidden="true"></span> {str tag=exportgroupscsv section=admin}</a>
{/if}
......
......@@ -23,7 +23,7 @@ Scenario:Injecting sql in groups search field
And I choose "Administer groups" in "Groups" from administration menu
When I set the following fields to these values:
| search_query | <script>alert(1);</script> |
And I press "search_submit"
And I press "search_search"
And I follow "About"
And I should see "About us"
Then I go to "homepage"
......
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