diff --git a/DAGSwitcher.php b/DAGSwitcher.php index 84bd3f6..8724eb1 100644 --- a/DAGSwitcher.php +++ b/DAGSwitcher.php @@ -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; } @@ -509,13 +528,15 @@ 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 + ?> diff --git a/dag_user_config.js b/dag_user_config.js index a2072c6..b6b9b98 100644 --- a/dag_user_config.js +++ b/dag_user_config.js @@ -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) {