]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7716 In visible groups mode, It is possible to put a database entries in other...
authorskodak <skodak>
Sun, 10 Dec 2006 20:16:03 +0000 (20:16 +0000)
committerskodak <skodak>
Sun, 10 Dec 2006 20:16:03 +0000 (20:16 +0000)
mod/data/edit.php
mod/data/import.php
mod/data/lib.php
mod/data/tabs.php
mod/data/templates.php

index 815dea7515c87f1d06463864c70290772a12878e..45debc1cad093ed2375ace29a168e9c1d3ea4722 100755 (executable)
             redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;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! =)
 
index d0216df3ddb7a207b1bb2a8a296fc159626ff979..77c59daa4effdfd82cdf810c30f492dc52956a8e 100755 (executable)
     print_header_simple($data->name, "", "<a href='index.php?id=$course->id'>$strdata</a> -> $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');
index f770e55942477c1e21c9f438c27dd331039b6b29..0a923121ab7321be0cb30721bb8510d74f3ac063 100755 (executable)
@@ -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;
+        }
+    }
+}
+
+
 ?>
index 38b67f2f4b3223a46556c376211dc8ce139c9d16..f592e72d183cd6f4f41d93f3f5b271bce4118383 100755 (executable)
@@ -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);
         }
index b008335f56e40bd6ef34f232eed42b2677e67cde..0a155c23903483dda389e48e27744d88ccaa39da 100755 (executable)
     
     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');