$data->course = $cm->course; $data->cmidnumber = $cm->idnumber; $data->instance = $cm->instance; if (!($context = get_context_instance(CONTEXT_MODULE, $cm->id))) { error('Could not find context'); } require_login($course->id, false, $cm); require_capability('mod/data:managetemplates', $context); if ($userid && $userid != $USER->id && !has_capability('mod/data:viewalluserpresets', $context)) { error('You are not allowed to access presets from other users'); } /* Need sesskey security check here for import instruction */ $sesskey = sesskey(); /********************************************************************/ /* Output */ data_print_header($course, $cm, $data, 'presets'); switch ($action) { /***************** Deleting *****************/ case 'confirmdelete': if (!confirm_sesskey()) { // GET request ok here error("Sesskey Invalid"); } if ($userid > 0 and $userid == $USER->id || has_capability('mod/data:manageuserpresets', $context)) { //ok can delete } else { error("Invalid request"); } $path = data_preset_path($course, $userid, $shortname); $strwarning = get_string('deletewarning', 'data') . '<br />' . data_preset_name($shortname, $path); $options = new object();
$PAGE->set_heading($course->fullname); $PAGE->set_pagetype('mod-data-field-' . $newtype); if ($mode == 'new' && !empty($newtype) && confirm_sesskey()) { /// Adding a new field data_print_header($course, $cm, $data, 'fields'); $field = data_get_field_new($newtype, $data); $field->display_edit_field(); } else { if ($mode == 'display' && confirm_sesskey()) { /// Display/edit existing field data_print_header($course, $cm, $data, 'fields'); $field = data_get_field_from_id($fid, $data); $field->display_edit_field(); } else { /// Display the main listing of all fields data_print_header($course, $cm, $data, 'fields'); if (!$DB->record_exists('data_fields', array('dataid' => $data->id))) { echo $OUTPUT->notification(get_string('nofieldindatabase', 'data')); // nothing in database echo $OUTPUT->notification(get_string('pleaseaddsome', 'data', 'preset.php?id=' . $cm->id)); // link to presets } else { //else print quiz style list of fields $table = new html_table(); $table->head = array(get_string('fieldname', 'data'), get_string('type', 'data'), get_string('fielddescription', 'data'), get_string('action', 'data')); $table->align = array('left', 'left', 'left', 'center'); $table->wrap = array(false, false, false, false); if ($fff = $DB->get_records('data_fields', array('dataid' => $data->id), 'id')) { foreach ($fff as $ff) { $field = data_get_field($ff, $data); $table->data[] = array('<a href="field.php?mode=display&d=' . $data->id . '&fid=' . $field->field->id . '&sesskey=' . sesskey() . '">' . $field->field->name . '</a>', $field->image() . ' ' . get_string($field->type, 'data'), shorten_text($field->field->description, 30), '<a href="field.php?d=' . $data->id . '&mode=display&fid=' . $field->field->id . '&sesskey=' . sesskey() . '">' . '<img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>' . ' ' . '<a href="field.php?d=' . $data->id . '&mode=delete&fid=' . $field->field->id . '&sesskey=' . sesskey() . '">' . '<img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>');