Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Statistics / Behavioural Statistics] Fix permission issue where users were allowed to see statistics from sites they don't have access to. #5252

Merged
merged 10 commits into from
Jan 14, 2020
21 changes: 13 additions & 8 deletions modules/statistics/php/stats_behavioural.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,23 @@ class Stats_Behavioural extends \NDB_Form
{
parent::setup();

$DB =& \Database::singleton();
$DB =& \Database::singleton();
racostas marked this conversation as resolved.
Show resolved Hide resolved
$user = \User::singleton();
racostas marked this conversation as resolved.
Show resolved Hide resolved

$centers = $DB->pselect(
"SELECT CONCAT('C', CenterID) as ID,
$query = "SELECT CONCAT('C', CenterID) as ID,
CenterID as NumericID,
IFNULL(PSCArea,Name) as LongName,
Name as ShortName
FROM psc
WHERE CenterID <> '1'
AND Study_site = 'Y'",
array()
);
FROM psc
WHERE CenterID <> '1'
AND Study_site = 'Y'";

if (!$user->hasPermission('access_all_profiles')) {
$site_arr = implode(",", $user->getCenterIDs());
racostas marked this conversation as resolved.
Show resolved Hide resolved
$query .= " AND CenterID IN (" . $site_arr . ")";
racostas marked this conversation as resolved.
Show resolved Hide resolved
}

$centers = $DB->pselect($query, array());

$this->tpl_data['Centers'] = $centers;

Expand Down