From cca1547e7cb11672df1d3c3c75666d28746dbeec Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 10 Dec 2006 20:16:03 +0000 Subject: [PATCH] MDL-7716 In visible groups mode, It is possible to put a database entries in other group that it his --- mod/data/edit.php | 6 +++++- mod/data/import.php | 7 +++++++ mod/data/lib.php | 32 ++++++++++++++++++++++++++++++++ mod/data/tabs.php | 2 +- mod/data/templates.php | 7 +++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/mod/data/edit.php b/mod/data/edit.php index 815dea7515..45debc1cad 100755 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -180,7 +180,11 @@ redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$rid); } else { /// Add some new records - + + if (!data_user_can_add_entry($data, $currentgroup, $groupmode)) { + error('Can not add entries!'); + } + /// Check if maximum number of entry as specified by this database is reached /// Of course, you can't be stopped if you are an editting teacher! =) diff --git a/mod/data/import.php b/mod/data/import.php index d0216df3dd..77c59daa4e 100755 --- a/mod/data/import.php +++ b/mod/data/import.php @@ -78,6 +78,13 @@ print_header_simple($data->name, "", "$strdata -> $data->name", "", "", true, "", navmenu($course)); print_heading(format_string($data->name)); +/// Groups needed for Add entry tab + if ($groupmode = groupmode($course, $cm)) { // Groups are being used + $currentgroup = get_and_set_current_group($course, $groupmode); + } else { + $currentgroup = 0; + } + /// Print the tabs $currenttab = 'add'; include('tabs.php'); diff --git a/mod/data/lib.php b/mod/data/lib.php index f770e55942..0a923121ab 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -1415,6 +1415,13 @@ function data_print_header($course, $cm, $data, $currenttab='') { print_heading(format_string($data->name)); +/// Groups needed for Add entry tab + if ($groupmode = groupmode($course, $cm)) { // Groups are being used + $currentgroup = get_and_set_current_group($course, $groupmode); + } else { + $currentgroup = 0; + } + /// Print the tabs if ($currenttab) { @@ -1430,4 +1437,29 @@ function data_print_header($course, $cm, $data, $currenttab='') { } } +function data_user_can_add_entry($data, $currentgroup=false, $groupmode='') { + global $USER; + + if (!$cm = get_coursemodule_from_instance('data', $data->id)) { + error('Course Module ID was incorrect'); + } + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + if (!has_capability('mod/data:writeentry', $context) and !has_capability('mod/data:manageentries',$context)) { + return false; + } + + if ($currentgroup) { + return (has_capability('moodle/site:accessallgroups', $context) or ismember($currentgroup)); + } else { + //else it might be group 0 in visible mode + if ($groupmode == VISIBLEGROUPS){ + return (ismember($currentgroup)); + } else { + return true; + } + } +} + + ?> diff --git a/mod/data/tabs.php b/mod/data/tabs.php index 38b67f2f4b..f592e72d18 100755 --- a/mod/data/tabs.php +++ b/mod/data/tabs.php @@ -43,7 +43,7 @@ } if (isloggedin()) { - if (has_capability('mod/data:writeentry', $context)) { // took out participation list here! + if (data_user_can_add_entry($data, $currentgroup, $groupmode)) { // took out participation list here! $addstring = empty($editentry) ? get_string('add', 'data') : get_string('editentry', 'data'); $row[] = new tabobject('add', $CFG->wwwroot.'/mod/data/edit.php?d='.$data->id, $addstring, '', true); } diff --git a/mod/data/templates.php b/mod/data/templates.php index b008335f56..0a155c2390 100755 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -84,6 +84,13 @@ print_heading(format_string($data->name)); +/// Groups needed for Add entry tab + if ($groupmode = groupmode($course, $cm)) { // Groups are being used + $currentgroup = get_and_set_current_group($course, $groupmode); + } else { + $currentgroup = 0; + } + /// Print the tabs. $currenttab = 'templates'; include('tabs.php'); -- 2.39.5