Commit cd78d649 authored by Stacey Walker's avatar Stacey Walker Committed by Francois Marier
Browse files

Institutional admin/staff contact page user profile links



bug #794361

Change-Id: I505acd49a0bdc67364076a631f3e84d1db6e1beb
Signed-off-by: default avatarStacey Walker <stacey@catalyst-eu.net>
parent f6808c12
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2011 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 Stacey Walker
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2011 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', '');
define('SECTION_PLUGINTYPE', 'core');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('institution.php');
if (!is_logged_in()) {
throw new AccessDeniedException();
}
$inst = param_alpha('institution');
$institution = new Institution($inst);
$admins = $institution->admins();
$staff = $institution->staff();
build_stafflist_html($admins, 'institution', 'admin', $inst);
build_stafflist_html($staff, 'institution', 'staff', $inst);
define('TITLE', $institution->displayname);
$smarty = smarty();
$smarty->assign('admins', $admins);
$smarty->assign('staff', $staff);
$smarty->assign('PAGEHEADING', get_string('institutioncontacts', 'mahara', TITLE));
$smarty->display('institution/staffadmin.tpl');
......@@ -81,6 +81,8 @@ $string['lastpage'] = 'Last page';
$string['accept'] = 'Accept';
$string['memberofinstitutions'] = 'Member of %s';
$string['staffofinstitutions'] = 'Staff of %s';
$string['adminofinstitutions'] = 'Admin of %s';
$string['reject'] = 'Reject';
$string['sendrequest'] = 'Send request';
$string['reason'] = 'Reason';
......@@ -305,6 +307,8 @@ $string['confirmpassword'] = 'Confirm password';
$string['javascriptnotenabled'] = 'Your browser does not have javascript enabled for this site. Mahara requires javascript to be enabled before you can log in';
$string['cookiesnotenabled'] = 'Your browser does not have cookies enabled, or is blocking cookies from this site. Mahara requires cookies to be enabled before you can log in';
$string['institution'] = 'Institution';
$string['institutioncontacts'] = '\'%s\' contacts';
$string['institutionlink'] = '<a href="%s">%s</a>';
$string['loggedoutok'] = 'You have been logged out successfully';
$string['login'] = 'Login';
$string['loginfailed'] = 'You have not provided the correct credentials to log in. Please check your username and password are correct.';
......@@ -522,6 +526,8 @@ $string['institutionmemberconfirmsubject'] = 'Institution membership confirmatio
$string['institutionmemberconfirmmessage'] = 'You have been added as a member of %s.';
$string['institutionmemberrejectsubject'] = 'Institution membership request declined';
$string['institutionmemberrejectmessage'] = 'Your request for membership of %s was declined.';
$string['noinstitutionstafffound'] = 'No institution staff were found';
$string['noinstitutionadminfound'] = 'No institution administrators were found';
$string['Memberships'] = 'Memberships';
$string['Requests'] = 'Requests';
$string['Invitations'] = 'Invitations';
......
......@@ -401,6 +401,34 @@ class Institution {
return ($this->maxuseraccounts != '') && ($this->countMembers() >= $this->maxuseraccounts);
}
/**
* Returns the current institution admin member records
*
* @return array A data structure containing admins
*/
public function admins() {
if ($results = get_records_sql_array('
SELECT u.id FROM {usr} u INNER JOIN {usr_institution} i ON u.id = i.usr
WHERE i.institution = ? AND u.deleted = 0 AND i.admin = 1', array($this->name))) {
return array_map(create_function('$a', 'return $a->id;'), $results);
}
return array();
}
/**
* Returns the current institution staff member records
*
* @return array A data structure containing staff
*/
public function staff() {
if ($results = get_records_sql_array('
SELECT u.id FROM {usr} u INNER JOIN {usr_institution} i ON u.id = i.usr
WHERE i.institution = ? AND u.deleted = 0 AND i.staff = 1', array($this->name))) {
return array_map(create_function('$a', 'return $a->id;'), $results);
}
return array();
}
/**
* Returns the list of institutions, implements institution searching
*
......
......@@ -1503,10 +1503,42 @@ function build_onlinelist_html(&$data, $page) {
$data['pagination_js'] = $pagination['javascript'];
}
/**
* Build the html for a list of staff information
*
* @param object $data
* @param string $page
* @param string $listtype
* @param string $institution
*/
function build_stafflist_html(&$data, $page, $listtype, $inst='mahara') {
global $USER;
if ($data) {
$data = get_users_data($data, $page);
}
$smarty = smarty_core();
$smarty->assign('page', $page);
$smarty->assign('listtype', $listtype);
$smarty->assign('inst', $inst);
$smarty->assign('USER', $USER);
if (count($data) > 5) {
$split = ceil(count($data) / 2);
$columns = array_chunk($data, $split);
}
if (isset($columns) && count($columns) == 2) {
$smarty->assign('columnleft', $columns[0]);
$smarty->assign('columnright', $columns[1]);
}
else {
$smarty->assign('data', isset($data) ? $data : null);
}
$data['tablerows'] = $smarty->fetch('institution/stafflist.tpl');
}
function get_institution_strings_for_users($userids) {
$userlist = join(',', $userids);
if (!$records = get_records_sql_array('
SELECT ui.usr, i.displayname
SELECT ui.usr, i.displayname, ui.staff, ui.admin, i.name
FROM {usr_institution} ui JOIN {institution} i ON ui.institution = i.name
WHERE ui.usr IN (' . $userlist . ')', array())) {
return array();
......@@ -1516,10 +1548,31 @@ function get_institution_strings_for_users($userids) {
if (!isset($institutions[$ui->usr])) {
$institutions[$ui->usr] = array();
}
$institutions[$ui->usr][] = $ui->displayname;
$key = ($ui->admin ? 'admin' : ($ui->staff ? 'staff' : 'member'));
$institutions[$ui->usr][$key][$ui->name] = $ui->displayname;
}
foreach ($institutions as &$userinst) {
foreach ($userinst as $key => &$value) {
$links = array();
foreach ($value as $k => $v) {
$url = get_config('wwwroot').'institution/index.php?institution='.$k;
$links[] = get_string('institutionlink', 'mahara', $url, $v);
}
switch ($key) {
case 'admin':
$value = get_string('adminofinstitutions', 'mahara', join(', ', $links));
break;
case 'staff':
$value = get_string('staffofinstitutions', 'mahara', join(', ', $links));
break;
default:
$value = get_string('memberofinstitutions', 'mahara', join(', ', $links));
break;
}
}
}
foreach ($institutions as &$u) {
$u = get_string('memberofinstitutions', 'mahara', join(', ', $u));
foreach ($institutions as &$userinst) {
$userinst = join('. ',$userinst);
}
return $institutions;
}
......
......@@ -216,7 +216,9 @@ td.narrow {
}
/* table with gap between rows */
#friendslist td,
#onlinelist td {
#onlinelist td,
#adminlist td,
#stafflist td {
border-bottom: 2px solid #FFF;
}
table.fixwidth {
......@@ -2147,7 +2149,9 @@ ul.friendinfo li.approvefriend form input:hover {
cursor: pointer;
}
#friendslist ul.actionlist,
#onlinelist ul.actionlist {
#onlinelist ul.actionlist,
#adminlist ul.actionlist,
#stafflist ul.actionlist {
margin: 0 0 0 10px;
float: right;
width: 180px;
......@@ -2178,7 +2182,9 @@ div.groupbox li.last {
margin-top: 5px;
}
#friendslist ul.actionlist li,
#onlinelist ul.actionlist li {
#onlinelist ul.actionlist li,
#adminlist ul.actionlist li,
#stafflist ul.actionlist li {
list-style: none;
margin: 0;
border-top: 1px solid #d1d1d1;
......@@ -2186,7 +2192,9 @@ div.groupbox li.last {
line-height: 1.2em;
}
#friendslist ul.actionlist li:first-child,
#onlinelist ul.actionlist li:first-child {
#onlinelist ul.actionlist li:first-child,
#adminlist ul.actionlist li:first-child,
#stafflist ul.actionlist li:first-child {
border-top: none;
}
#editgroup th label {
......@@ -2213,12 +2221,16 @@ form#search, form#filter, div.searchform, #searchviews {
background: url(../images/divider-dot.gif) no-repeat left;
}
#friendslist .leftdiv,
#onlinelist .leftdiv {
#onlinelist .leftdiv,
#adminlist .leftdiv,
#stafflist .leftdiv {
float: left;
width: 50px;
}
#friendslist .rightdiv,
#onlinelist .rightdiv {
#onlinelist .rightdiv,
#adminlist .rightdiv,
#stafflist .rightdiv {
min-height: 35px;
padding: 5px 0 0 0;
margin-left: 50px;
......@@ -2559,3 +2571,14 @@ form#sendmessage #sendmessage_message,
width: 98% !important;
}
}
/* Institution contacts */
#admin_left,
#staff_left {
float: left;
width: 50% !important;
}
#admin_right,
#staff_right {
float: right;
width: 50% !important;
}
<td class="staffinfo">
{if $USER->get('id') != $user->id}
{if $user->messages && $listtype == 'admin'}
<ul class="actionlist">
<li>
<a href="{$WWWROOT}user/sendmessage.php?id={$user->id}&returnto={$page}&inst={$inst}" id="btn-sendmessage" class="btn-message">
{str tag='sendmessage' section='group'}
</a>
</li>
</ul>
{/if}
{/if}
<div class="leftdiv" id="staffinfo_{$user->id}">
<img src="{profile_icon_url user=$user maxwidth=40 maxheight=40}" alt="">
</div>
<div class="rightdiv">
<h3>
<a href="{$WWWROOT}user/view.php?id={$user->id}">{$user->display_name}</a>
</h3>
</div>
</td>
{include file="header.tpl"}
<div id="staffadminlistcontainer">
<div class="fullwidth">
<h3>{str tag=institutionadmins section=admin}</h3>
{$admins.tablerows|safe}
</div>
<div class="cb"></div>
<div class="fullwidth">
<h3>{str tag=institutionstaff section=admin}</h3>
{$staff.tablerows|safe}
</div>
</div>
{include file="footer.tpl"}
{if $data}
<table id="{$listtype}list" class="fullwidth listing">
<tbody>
{foreach from=$data item=user}
<tr class="{cycle values='r0,r1'}">
{include file="institution/staff.tpl" user=$user page=$page}
</tr>
{/foreach}
</tbody>
</table>
{elseif $columnleft && $columnright}
<div id="{$listtype}_left" class="leftdiv">
<table id="{$listtype}list" class="fullwidth listing">
<tbody>
{foreach from=$columnleft item=leftuser}
<tr class="{cycle values='r0,r1'}">
{include file="institution/staff.tpl" user=$leftuser page=$page}
</tr>
{/foreach}
</tbody>
</table>
</div>
<div id="{$listtype}_right" class="rightdiv">
<table id="{$listtype}list" class="fullwidth listing">
<tbody>
{foreach from=$columnright item=rightuser}
<tr class="{cycle values='r0,r1'}">
{include file="institution/staff.tpl" user=$rightuser page=$page}
</tr>
{/foreach}
</tbody>
</table>
</div>
{else}
<div class="message">
{if $listtype == 'staff'}
{str tag=noinstitutionstafffound section=mahara}
{elseif $listtype == 'admin'}
{str tag=noinstitutionadminfound section=mahara}
{/if}
</div>
{/if}
......@@ -18,7 +18,7 @@
{/if}
<div id="userview">
<div class="user-icon">
{$institutions}
{$institutions|safe}
{if $loginas}
<a href="{$WWWROOT}admin/users/changeuser.php?id={$USERID}" class="btn-login">{$loginas}</a>
{if $USER->get('admin')}<a href="{$WWWROOT}admin/users/edit.php?id={$USERID}" class="btn-edit">{str tag=accountsettings section=admin}</a>{/if}
......
......@@ -48,6 +48,24 @@ if (!is_null($replytoid)) {
}
$returnto = param_alpha('returnto', 'myfriends');
switch ($returnto) {
case 'find':
$goto = 'user/find.php';
break;
case 'view':
$goto = 'user/view.php?id=' . $id;
break;
case 'inbox':
$goto = 'account/activity';
break;
case 'institution':
$goto = ($inst = param_alpha('inst', null))
? 'institution/index.php?institution=' . $inst
: 'account/activity';
break;
default:
$goto = 'user/myfriends.php';
}
$user = get_record('usr', 'id', $id, 'deleted', 0);
......@@ -67,10 +85,14 @@ $form = pieform(array(
'cols' => 80,
'rows' => 10,
),
'goto' => array(
'type' => 'hidden',
'value' => $goto,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array($messages ? get_string('Reply', 'group') : get_string('sendmessage', 'group'), get_string('cancel')),
'goto' => get_config('wwwroot') . ($returnto == 'find' ? 'user/find.php' : ($returnto == 'view' ? 'user/view.php?id=' . $id : 'user/myfriends.php')),
'goto' => get_config('wwwroot') . $goto,
)
)
));
......@@ -87,18 +109,5 @@ function sendmessage_submit(Pieform $form, $values) {
$user = get_record('usr', 'id', $id);
send_user_message($user, $values['message'], param_integer('replyto', null));
$SESSION->add_ok_msg(get_string('messagesent', 'group'));
switch (param_alpha('returnto', 'myfriends')) {
case 'find':
redirect('/user/find.php');
break;
case 'view':
redirect('/user/view.php?id=' . $id);
break;
case 'inbox':
redirect('/account/activity');
break;
default:
redirect('/user/myfriends.php');
break;
}
redirect(get_config('wwwroot').$values['goto']);
}
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