$string['jstemplate'] = 'Javascript template';
$string['latitude'] = 'Latitude';
$string['latlong'] = 'Latitude/longitude';
+ $string['latlongboth'] = 'Both the Latitude and the Longitude must be filled in.';
$string['latlongdownloadallhint'] = 'Download link for all entries as KML';
$string['latlongkmllabelling'] = 'How to label items in KML files (Google Earth)';
$string['latlonglinkservicesdisplayed'] = 'Link-out services to display';
$string['list'] = 'View list';
$string['listtemplate'] = 'List template';
$string['longitude'] = 'Longitude';
+$string['manageapproved'] = 'Allow editing of approved entries';
+$string['manageapproved_help'] = 'If disabled, approved entries are not editable and deletable by its owner. This setting only takes effect if approval required is set to yes. Default is yes.';
$string['mapexistingfield'] = 'Map to {$a}';
$string['mapnewfield'] = 'Create a new field';
$string['mappingwarning'] = 'All old fields not mapped to a new field will be lost and all data in that field will be removed.';
}
$jumpurl = new moodle_url($jumpurl, array('page' => $page, 'sesskey' => sesskey()));
- // Check whether this activity is read-only at present
- $readonly = data_in_readonly_period($data);
-
foreach ($records as $record) { // Might be just one for the single template
// Replacing tags
// Replacing special tags (##Edit##, ##Delete##, ##More##)
$patterns[]='##edit##';
$patterns[]='##delete##';
- if ($canmanageentries || (!$readonly && data_isowner($record->id))) {
+ if (data_user_can_manage_entry($record, $data, $context)) {
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d='
.$data->id.'&rid='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.get_string('edit').'" title="'.get_string('edit').'" /></a>';
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
}
}
+/**
+ * Check whether the current user is allowed to manage the given record considering manageentries capability,
+ * data_in_readonly_period() result, ownership (determined by data_isowner()) and manageapproved setting.
+ * @param mixed $record record object or id
+ * @param object $data data object
+ * @param object $context context object
+ * @return bool returns true if the user is allowd to edit the entry, false otherwise
+ */
+function data_user_can_manage_entry($record, $data, $context) {
+ global $DB;
+
+ if (has_capability('mod/data:manageentries', $context)) {
+ return true;
+ }
+
+ // Check whether this activity is read-only at present.
+ $readonly = data_in_readonly_period($data);
+
+ if (!$readonly) {
+ // Get record object from db if just id given like in data_isowner.
+ // ...done before calling data_isowner() to avoid querying db twice.
+ if (!is_object($record)) {
+ if (!$record = $DB->get_record('data_records', array('id' => $record))) {
+ return false;
+ }
+ }
+ if (data_isowner($record)) {
+ if ($data->approval && $record->approved) {
+ return $data->manageapproved == 1;
+ } else {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
/**
* Check whether the specified database activity is currently in a read-only period
*
'maxentries',
'rssarticles',
'approval',
+ 'manageapproved',
'defaultsortdir'
);
// Empty form checking - you can't submit an empty form.
$emptyform = true;
$requiredfieldsfilled = true;
+ $fieldsvalidated = true;
// Store the notifications.
$result->generalnotifications = array();
$field = data_get_field($fieldrecord, $mod);
if (isset($submitteddata[$fieldrecord->id])) {
+ // Field validation check.
+ if (method_exists($field, 'field_validation')) {
+ $errormessage = $field->field_validation($submitteddata[$fieldrecord->id]);
+ if ($errormessage) {
+ $result->fieldnotifications[$field->field->name][] = $errormessage;
+ $fieldsvalidated = false;
+ }
+ }
foreach ($submitteddata[$fieldrecord->id] as $fieldname => $value) {
if ($field->notemptyfield($value->value, $value->fieldname)) {
// The field has content and the form is not empty.
$result->generalnotifications[] = get_string('emptyaddform', 'data');
}
- $result->validated = $requiredfieldsfilled && !$emptyform;
+ $result->validated = $requiredfieldsfilled && !$emptyform && $fieldsvalidated;
return $result;
}