Commit 049c51b0 authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Allow viewing of institution statististics by staff



Site staff can always view, institution staff can view if
staffstats config option is set

Change-Id: Ia7dcd8623ef6d6eaba77a3370a1d9fb637163c29
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 2a1ef135
...@@ -35,7 +35,7 @@ if (!is_logged_in()) { ...@@ -35,7 +35,7 @@ if (!is_logged_in()) {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
$institutionelement = get_institution_selector(); $institutionelement = get_institution_selector(true, false, true, get_config('staffstats'));
if (empty($institutionelement)) { if (empty($institutionelement)) {
$smarty = smarty(); $smarty = smarty();
...@@ -45,7 +45,7 @@ if (empty($institutionelement)) { ...@@ -45,7 +45,7 @@ if (empty($institutionelement)) {
} }
$institution = param_alphanum('institution', null); $institution = param_alphanum('institution', null);
if (!$institution || !$USER->can_edit_institution($institution)) { if (!$institution || !$USER->can_edit_institution($institution, true)) {
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value']; $institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value'];
} }
else if (!empty($institution)) { else if (!empty($institution)) {
......
...@@ -741,7 +741,10 @@ class User { ...@@ -741,7 +741,10 @@ class User {
return isset($a[$institution]); return isset($a[$institution]);
} }
public function can_edit_institution($institution = null) { public function can_edit_institution($institution = null, $staff = false) {
if ($staff) {
return $this->get('admin') || $this->get('staff') || $this->is_institutional_admin($institution) || $this->is_institutional_staff($institution);
}
return $this->get('admin') || $this->is_institutional_admin($institution); return $this->get('admin') || $this->is_institutional_admin($institution);
} }
......
...@@ -662,10 +662,10 @@ class Institution { ...@@ -662,10 +662,10 @@ class Institution {
} }
} }
function get_institution_selector($includedefault = true, $assumesiteadmin=false) { function get_institution_selector($includedefault = true, $assumesiteadmin=false, $includesitestaff=false, $includeinstitutionstaff=false) {
global $USER; global $USER;
if ($assumesiteadmin || $USER->get('admin')) { if (($assumesiteadmin || $USER->get('admin')) || ($includesitestaff && $USER->get('staff'))) {
if ($includedefault) { if ($includedefault) {
$institutions = get_records_array('institution', '', '', 'displayname'); $institutions = get_records_array('institution', '', '', 'displayname');
} }
...@@ -678,6 +678,13 @@ function get_institution_selector($includedefault = true, $assumesiteadmin=false ...@@ -678,6 +678,13 @@ function get_institution_selector($includedefault = true, $assumesiteadmin=false
'name IN (' . join(',', array_map('db_quote',$USER->get('admininstitutions'))) . ')', 'name IN (' . join(',', array_map('db_quote',$USER->get('admininstitutions'))) . ')',
null, 'displayname' null, 'displayname'
); );
}
else if ($includeinstitutionstaff) {
$institutions = get_records_select_array(
'institution',
'name IN (' . join(',', array_map('db_quote',$USER->get('staffinstitutions'))) . ')',
null, 'displayname'
);
} else { } else {
return null; return null;
} }
......
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