Commit 5c0452fc authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show inviting/requested institutions & allow membership confirmation on user search

parent b523f6e7
<?php
/**
* This program is part of Mahara
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('INSTITUTIONALADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require('institution.php');
global $USER, $SESSION;
$id = param_integer('id');
$institution = new Institution(param_alpha('institution'));
if (!$USER->get('admin')) {
if (!$USER->is_institutional_admin($institution->name)) {
$SESSION->add_error_msg(get_string('notadminforinstitution', 'admin'));
redirect(get_config('wwwroot').'admin/users/search.php');
}
else if (!get_field('usr_institution_request', 'confirmedusr', 'usr', $id, 'institution', $institution->name)) {
$institution->inviteUser($id);
$SESSION->add_ok_msg(get_string('invitationsent', 'admin'));
redirect(get_config('wwwroot').'admin/users/search.php');
}
}
$institution->addUserAsMember($id);
$SESSION->add_ok_msg(get_string('useradded', 'admin'));
redirect(get_config('wwwroot').'admin/users/edit.php?id='.$id);
?>
......@@ -346,6 +346,10 @@ $string['Admins'] = 'Admins';
// Admin User Search
$string['Query'] = 'Query';
$string['Institution'] = 'Institution';
$string['confirm'] = 'confirm';
$string['invited'] = 'invited';
$string['useradded'] = 'User added';
$string['invitationsent'] = 'Invitation sent';
// general stuff
$string['notificationssaved'] = 'Notification settings saved';
......
......@@ -247,7 +247,7 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
$institutions = get_records_assoc('institution', '', '', '', 'name,displayname');
if (count($institutions) > 1) {
$cols['institution'] = array('name' => get_string('institution'),
'template' => '{if empty($r.institutions)}{$institutions.mahara->displayname}{else}{foreach from=$r.institutions item=i}<div>{$institutions[$i]->displayname}</div>{/foreach}{/if}');
'template' => '{if empty($r.institutions)}{$institutions.mahara->displayname}{else}{foreach from=$r.institutions item=i}<div>{$institutions[$i]->displayname}</div>{/foreach}{/if}{if !empty($r.requested)}{foreach from=$r.requested item=i}<div>{$institutions[$i]->displayname} ({if $USER->is_institutional_admin("$i")}<a href="{$WWWROOT}admin/users/addtoinstitution.php?id={$r.id}&institution={$i}">{str tag=confirm section=admin}</a>{else}{str tag=requested}{/if})</div>{/foreach}{/if}{if !empty($r.invitedby)}{foreach from=$r.invitedby item=i}<div>{$institutions[$i]->displayname} ({str tag=invited section=admin})</div>{/foreach}{/if}');
}
$smarty = smarty_core();
......
......@@ -278,6 +278,7 @@ class PluginSearchInternal extends PluginSearch {
// @todo: Institution stuff is messy and will probably need to
// be rewritten when we get multiple institutions per user
$requested = false;
$institutionsearch = '';
if (!empty($constraints)) {
foreach ($constraints as $f) {
......@@ -293,6 +294,7 @@ class PluginSearchInternal extends PluginSearch {
PluginSearchInternal::match_expression($f['type'], $f['string'], $values, $ilike) .
' OR ir.institution ' .
PluginSearchInternal::match_expression($f['type'], $f['string'], $values, $ilike) . ')';
$requested = true;
} else {
if ($f['string'] == 'mahara') {
$where .= ' AND i.institution IS NULL';
......@@ -337,6 +339,21 @@ class PluginSearchInternal extends PluginSearch {
$data[$i->usr]->institutions[] = $i->institution;
}
}
if ($requested) {
$inst = get_records_select_array('usr_institution_request',
'usr IN (' . join(',', array_keys($data)) . ')',
null, '', 'usr,institution,confirmedusr,confirmedinstitution');
if ($inst) {
foreach ($inst as $i) {
if ($i->confirmedusr) {
$data[$i->usr]->requested[] = $i->institution;
}
if ($i->confirmedinstitution) {
$data[$i->usr]->invitedby[] = $i->institution;
}
}
}
}
foreach ($data as &$item) {
$item = (array)$item;
}
......
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