Skip to content

Commit

Permalink
Fixes for User Rights page popovers
Browse files Browse the repository at this point in the history
Fixes for User Rights page popovers
  • Loading branch information
lsgs committed Mar 5, 2019
1 parent 5e7acbd commit 6a84a5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions DAGSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ public function getUserDAGs() {
$userDags = json_decode($row['data_values'], true);
}
}

// return only valid group_id values (remove any DAGs that have been deleted)
$sql = "select group_id from redcap_data_access_groups where project_id = ".db_escape($this->project_id)." ";
$r = db_query($sql);
if ($r->num_rows > 0) {
$currentDagIds = array();
while ($row = $r->fetch_assoc()) {
$currentDagIds[] = $row['group_id'];
}
}

foreach ($userDags as $user => $dags) {
foreach ($dags as $dagKey => $dagId) {
if ($dagId!=0 && !in_array($dagId, $currentDagIds)) {
unset($userDags[$user][$dagKey]);
}
}
}

return $userDags;
}

Expand Down Expand Up @@ -509,23 +528,22 @@ public function switchToDAG($newDag) {

/**
* Print DAG Switcher JavaScript code to User Rights page.
* Users' current DAG display is augmentied to indicate where user may
* Users' current DAG display is augmented to indicate where user may
* switch to other DAGs.
*/
protected function includeUserRightsPageJs() {
$jsPath = $this->getUrl('user_rights.js');
$userDags = $this->getUserDAGs();
$dagNames = array(0=>$this->lang['data_access_groups_ajax_23']) + (array)REDCap::getGroupNames(false);
$dagNames = array_map('htmlentities', $dagNames); // encode quotes etc. in dag names

?>
<script type="text/javascript" src="<?php echo $jsPath;?>"></script>
<script type="text/javascript">
$(document).ready(function() {
var userDags = JSON.parse('<?php echo json_encode($userDags);?>');
var dagNames = JSON.parse('<?php echo json_encode($dagNames, JSON_HEX_APOS);?>');
MCRI_DAG_Switcher_User_Rights.makePopovers(userDags, dagNames);
});

$(window).on('load', function() {
MCRI_DAG_Switcher_User_Rights.activatePopovers();
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion dag_user_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var MCRI_DAG_Switcher_Config = (function(window, document, $, undefined) {
}
})
.fail(function(data) {
console.log(data.result);
console.log(data);
enabled = !enabled; // changing the selection failed so change it back to what it waa
})
.always(function(data) {
Expand Down

0 comments on commit 6a84a5e

Please sign in to comment.