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! =)
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');
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) {
}
}
+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;
+ }
+ }
+}
+
+
?>
}
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);
}
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');