} if ($field) { $field->update_content($rid, $value, $name); } } } add_to_log($course->id, 'data', 'update', "view.php?d={$data->id}&rid={$rid}", $data->id, $cm->id); 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, $context)) { print_error('cannotadd', 'data'); } /// 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! =) if (data_atmaxentries($data) and !has_capability('mod/data:manageentries', $context)) { echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('atmaxentry', 'data')); echo $OUTPUT->footer(); exit; } ///Empty form checking - you can't submit an empty form! $emptyform = true; // assume the worst foreach ($datarecord as $name => $value) { if (!in_array($name, $ignorenames)) { $namearr = explode('_', $name); // Second one is the field id if (empty($field->field) || $namearr[1] != $field->field->id) { // Try to reuse classes $field = data_get_field_from_id($namearr[1], $data);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $inactive = NULL; $activetwo = NULL; $tabs = array(); $row = array(); $row[] = new tabobject('list', $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id, get_string('list', 'data')); if (isset($record)) { $row[] = new tabobject('single', $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id, get_string('single', 'data')); } else { $row[] = new tabobject('single', $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&mode=single', get_string('single', 'data')); } // Add an advanced search tab. $row[] = new tabobject('asearch', $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&mode=asearch', get_string('search', 'data')); if (isloggedin()) { // just a perf shortcut if (data_user_can_add_entry($data, $currentgroup, $groupmode) && !data_atmaxentries($data)) { // 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); } if (has_capability(DATA_CAP_EXPORT, $context)) { // The capability required to Export database records is centrally defined in 'lib.php' // and should be weaker than those required to edit Templates, Fields and Presets. $row[] = new tabobject('export', $CFG->wwwroot . '/mod/data/export.php?d=' . $data->id, get_string('export', 'data')); } if (has_capability('mod/data:managetemplates', $context)) { if ($currenttab == 'list') { $defaultemplate = 'listtemplate'; } else { if ($currenttab == 'add') { $defaultemplate = 'addtemplate';
/** * Can user add more entries? * * @param object $data * @param mixed $currentgroup * @param int $groupmode * @param stdClass $context * @return bool */ function data_user_can_add_entry($data, $currentgroup, $groupmode, $context = null) { global $USER; if (empty($context)) { $cm = get_coursemodule_from_instance('data', $data->id, 0, false, MUST_EXIST); $context = get_context_instance(CONTEXT_MODULE, $cm->id); } if (has_capability('mod/data:manageentries', $context)) { // no entry limits apply if user can manage } else if (!has_capability('mod/data:writeentry', $context)) { return false; } else if (data_atmaxentries($data)) { return false; } //if in the view only time window $now = time(); if ($now>$data->timeviewfrom && $now<$data->timeviewto) { return false; } if (!$groupmode or has_capability('moodle/site:accessallgroups', $context)) { return true; } if ($currentgroup) { return groups_is_member($currentgroup); } else { //else it might be group 0 in visible mode if ($groupmode == VISIBLEGROUPS){ return true; } else { return false; } } }
/** * Can user add more entries? * * @param object $data * @param mixed $currentgroup * @param int $groupmode * @param stdClass $context * @return bool */ function data_user_can_add_entry($data, $currentgroup, $groupmode, $context = null) { global $USER; if (empty($context)) { $cm = get_coursemodule_from_instance('data', $data->id, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); } if (has_capability('mod/data:manageentries', $context)) { // no entry limits apply if user can manage } else { if (!has_capability('mod/data:writeentry', $context)) { return false; } else { if (data_atmaxentries($data)) { return false; } else { if (data_in_readonly_period($data)) { // Check whether we're in a read-only period return false; } } } } if (!$groupmode or has_capability('moodle/site:accessallgroups', $context)) { return true; } if ($currentgroup) { return groups_is_member($currentgroup); } else { //else it might be group 0 in visible mode if ($groupmode == VISIBLEGROUPS) { return true; } else { return false; } } }