-<?php // $Id$
-
- require_once('../../config.php');
- require_once('lib.php');
- require_once('comment_form.php');
-
- //param needed to go back to view.php
- $rid = required_param('rid', PARAM_INT); // Record ID
- $page = optional_param('page', 0, PARAM_INT); // Page ID
-
- //param needed for comment operations
- $mode = optional_param('mode','add',PARAM_ALPHA);
- $commentid = optional_param('commentid','',PARAM_INT);
- $confirm = optional_param('confirm','',PARAM_INT);
-
-
- if (! $record = $DB->get_record('data_records', array('id'=>$rid))) {
- print_error('invalidrecord', 'data');
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+require_once('../../config.php');
+require_once('lib.php');
+require_once('comment_form.php');
+
+//param needed to go back to view.php
+$rid = required_param('rid', PARAM_INT); // Record ID
+$page = optional_param('page', 0, PARAM_INT); // Page ID
+
+//param needed for comment operations
+$mode = optional_param('mode','add',PARAM_ALPHA);
+$commentid = optional_param('commentid','',PARAM_INT);
+$confirm = optional_param('confirm','',PARAM_INT);
+
+$url = new moodle_url($CFG->wwwroot.'/mod/data/comment.php', array('rid'=>$rid));
+if ($page !== 0) {
+ $url->param('page', $page);
+}
+if ($mode !== 'add') {
+ $url->param('mode', $mode);
+}
+if ($commentid !== '') {
+ $url->param('commentid', $commentid);
+}
+if ($confirm !== '') {
+ $url->param('confirm', $confirm);
+}
+$PAGE->set_url($url);
+
+if (! $record = $DB->get_record('data_records', array('id'=>$rid))) {
+ print_error('invalidrecord', 'data');
+}
+if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) {
+ print_error('invalidid', 'data');
+}
+if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
+ print_error('coursemisconf');
+}
+if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
+ print_error('invalidcoursemodule');
+}
+
+require_login($course->id, false, $cm);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_capability('mod/data:comment', $context);
+
+if ($commentid) {
+ if (! $comment = $DB->get_record('data_comments', array('id'=>$commentid))) {
+ print_error('commentmisconf');
}
- if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) {
- print_error('invalidid', 'data');
+ if ($comment->recordid != $record->id) {
+ print_error('commentmisconf');
}
- if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
- print_error('coursemisconf');
+ if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) {
+ print_error('cannoteditcomment');
}
- if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
- print_error('invalidcoursemodule');
+} else {
+ $comment = false;
+}
+
+
+$mform = new mod_data_comment_form();
+$mform->set_data(array('mode'=>$mode, 'page'=>$page, 'rid'=>$record->id, 'commentid'=>$commentid));
+if ($comment) {
+ $format = $comment->format;
+ $content = $comment->content;
+ if (can_use_html_editor()) {
+ $options = new object();
+ $options->smiley = false;
+ $options->filter = false;
+ $content = format_text($content, $format, $options);
+ $format = FORMAT_HTML;
}
+ $mform->set_data(array('content'=>$content, 'format'=>$format));
+}
- require_login($course->id, false, $cm);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- require_capability('mod/data:comment', $context);
- if ($commentid) {
- if (! $comment = $DB->get_record('data_comments', array('id'=>$commentid))) {
- print_error('commentmisconf');
- }
- if ($comment->recordid != $record->id) {
- print_error('commentmisconf');
+if ($mform->is_cancelled()) {
+ redirect('view.php?rid='.$record->id.'&page='.$page);
+}
+
+switch ($mode) {
+ case 'add':
+ if (!$formadata = $mform->get_data()) {
+ break; // something is wrong here, try again
}
- if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) {
- print_error('cannoteditcomment');
+
+ $newcomment = new object();
+ $newcomment->userid = $USER->id;
+ $newcomment->created = time();
+ $newcomment->modified = time();
+ $newcomment->content = $formadata->content;
+ $newcomment->recordid = $formadata->rid;
+ if ($DB->insert_record('data_comments',$newcomment)) {
+ redirect('view.php?rid='.$record->id.'&page='.$page);
+ } else {
+ print_error('cannotsavecomment');
}
- } else {
- $comment = false;
- }
+ break;
- $mform = new mod_data_comment_form();
- $mform->set_data(array('mode'=>$mode, 'page'=>$page, 'rid'=>$record->id, 'commentid'=>$commentid));
- if ($comment) {
- $format = $comment->format;
- $content = $comment->content;
- if (can_use_html_editor()) {
- $options = new object();
- $options->smiley = false;
- $options->filter = false;
- $content = format_text($content, $format, $options);
- $format = FORMAT_HTML;
+ case 'edit': //print edit form
+ if (!$formadata = $mform->get_data()) {
+ break; // something is wrong here, try again
}
- $mform->set_data(array('content'=>$content, 'format'=>$format));
- }
+ $updatedcomment = new object();
+ $updatedcomment->id = $formadata->commentid;
+ $updatedcomment->content = $formadata->content;
+ $updatedcomment->format = $formadata->format;
+ $updatedcomment->modified = time();
- if ($mform->is_cancelled()) {
- redirect('view.php?rid='.$record->id.'&page='.$page);
- }
+ if ($DB->update_record('data_comments', $updatedcomment)) {
+ redirect('view.php?rid='.$record->id.'&page='.$page);
+ } else {
+ print_error('cannotsavecomment');
+ }
+ break;
- switch ($mode) {
- case 'add':
- if (!$formadata = $mform->get_data()) {
- break; // something is wrong here, try again
- }
-
- $newcomment = new object();
- $newcomment->userid = $USER->id;
- $newcomment->created = time();
- $newcomment->modified = time();
- $newcomment->content = $formadata->content;
- $newcomment->recordid = $formadata->rid;
- if ($DB->insert_record('data_comments',$newcomment)) {
- redirect('view.php?rid='.$record->id.'&page='.$page);
- } else {
- print_error('cannotsavecomment');
- }
-
- break;
-
- case 'edit': //print edit form
- if (!$formadata = $mform->get_data()) {
- break; // something is wrong here, try again
- }
-
- $updatedcomment = new object();
- $updatedcomment->id = $formadata->commentid;
- $updatedcomment->content = $formadata->content;
- $updatedcomment->format = $formadata->format;
- $updatedcomment->modified = time();
-
- if ($DB->update_record('data_comments', $updatedcomment)) {
- redirect('view.php?rid='.$record->id.'&page='.$page);
- } else {
- print_error('cannotsavecomment');
- }
- break;
-
- case 'delete': //deletes single comment from db
- if ($confirm and confirm_sesskey() and $comment) {
- $DB->delete_records('data_comments', array('id'=>$comment->id));
- redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentdeleted', 'data'));
-
- } else { //print confirm delete form
- echo $OUTPUT->header();
- data_print_comment($data, $comment, $page);
-
- echo $OUTPUT->confirm(get_string('deletecomment','data'),
- 'comment.php?rid='.$record->id.'&commentid='.$comment->id.'&page='.$page.'&mode=delete&confirm=1',
- 'view.php?rid='.$record->id.'&page='.$page);
- echo $OUTPUT->footer();
- }
- die;
- break;
+ case 'delete': //deletes single comment from db
+ if ($confirm and confirm_sesskey() and $comment) {
+ $DB->delete_records('data_comments', array('id'=>$comment->id));
+ redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentdeleted', 'data'));
- }
+ } else { //print confirm delete form
+ echo $OUTPUT->header();
+ data_print_comment($data, $comment, $page);
+
+ echo $OUTPUT->confirm(get_string('deletecomment','data'),
+ 'comment.php?rid='.$record->id.'&commentid='.$comment->id.'&page='.$page.'&mode=delete&confirm=1',
+ 'view.php?rid='.$record->id.'&page='.$page);
+ echo $OUTPUT->footer();
+ }
+ die;
+ break;
- echo $OUTPUT->header();
- data_print_comments($data, $record, $page, $mform);
- echo $OUTPUT->footer();
+}
+echo $OUTPUT->header();
+data_print_comments($data, $record, $page, $mform);
+echo $OUTPUT->footer();
-?>
+?>
\ No newline at end of file
-<?php // $Id$
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
- define('NO_MOODLE_COOKIES', true); // session not used here
-
- require_once('../../config.php');
-
- $d = optional_param('d', 0, PARAM_INT); // database id
- $lifetime = 600; // Seconds to cache this stylesheet
-
- if ($data = $DB->get_record('data', array('id'=>$d))) {
- header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
- header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
- header('Cache-control: max_age = '. $lifetime);
- header('Pragma: ');
- header('Content-type: text/css'); // Correct MIME type
-
- echo $data->csstemplate;
- }
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+define('NO_MOODLE_COOKIES', true); // session not used here
+
+require_once('../../config.php');
+
+$d = optional_param('d', 0, PARAM_INT); // database id
+$lifetime = 600; // Seconds to cache this stylesheet
+
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/data/css.php', array('d'=>$d)));
+
+if ($data = $DB->get_record('data', array('id'=>$d))) {
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
+ header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
+ header('Cache-control: max_age = '. $lifetime);
+ header('Pragma: ');
+ header('Content-type: text/css'); // Correct MIME type
+
+ echo $data->csstemplate;
+}
\ No newline at end of file
-<?php // $Id$
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
- require_once('../../config.php');
- require_once('lib.php');
- require_once("$CFG->libdir/rsslib.php");
-
- $id = optional_param('id', 0, PARAM_INT); // course module id
- $d = optional_param('d', 0, PARAM_INT); // database id
- $rid = optional_param('rid', 0, PARAM_INT); //record id
- $import = optional_param('import', 0, PARAM_INT); // show import form
- $cancel = optional_param('cancel', '', PARAM_RAW); // cancel an add
- $mode ='addtemplate'; //define the mode for this page, only 1 mode available
-
- if ($id) {
- if (! $cm = get_coursemodule_from_id('data', $id)) {
- print_error('invalidcoursemodule');
- }
- if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
- print_error('coursemisconf');
- }
- if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
- print_error('invalidcoursemodule');
- }
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+require_once('../../config.php');
+require_once('lib.php');
+require_once("$CFG->libdir/rsslib.php");
+
+$id = optional_param('id', 0, PARAM_INT); // course module id
+$d = optional_param('d', 0, PARAM_INT); // database id
+$rid = optional_param('rid', 0, PARAM_INT); //record id
+$import = optional_param('import', 0, PARAM_INT); // show import form
+$cancel = optional_param('cancel', '', PARAM_RAW); // cancel an add
+$mode ='addtemplate'; //define the mode for this page, only 1 mode available
+
+$url = new moodle_url($CFG->wwwroot.'/mod/data/edit.php');
+if ($rid !== 0) {
+ $url->param('rid', $rid);
+}
+if ($import !== 0) {
+ $url->param('import', $import);
+}
+if ($cancel !== '') {
+ $url->param('cancel', $cancel);
+}
+
+if ($id) {
+ $url->param('id', $id);
+ $PAGE->set_url($url);
+ if (! $cm = get_coursemodule_from_id('data', $id)) {
+ print_error('invalidcoursemodule');
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
+ print_error('coursemisconf');
+ }
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
+ print_error('invalidcoursemodule');
+ }
- } else {
- if (! $data = $DB->get_record('data', array('id'=>$d))) {
- print_error('invalidid', 'data');
- }
- if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
- print_error('coursemisconf');
- }
- if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
- print_error('invalidcoursemodule');
- }
+} else {
+ $url->param('d', $d);
+ $PAGE->set_url($url);
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
+ print_error('invalidid', 'data');
}
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
+ print_error('coursemisconf');
+ }
+ if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
+ print_error('invalidcoursemodule');
+ }
+}
- require_login($course->id, false, $cm);
+require_login($course->id, false, $cm);
- if (!isloggedin() or isguest()) {
- redirect('view.php?d='.$data->id);
- }
+if (!isloggedin() or has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
+ redirect('view.php?d='.$data->id);
+}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// If it's hidden then it doesn't show anything. :)
- if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
- $strdatabases = get_string("modulenameplural", "data");
+if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
+ $strdatabases = get_string("modulenameplural", "data");
- $PAGE->set_title(format_string($data->name));
- echo $OUTPUT->header();
- notice(get_string("activityiscurrentlyhidden"));
- }
+ $PAGE->set_title(format_string($data->name));
+ echo $OUTPUT->header();
+ notice(get_string("activityiscurrentlyhidden"));
+}
/// Can't use this if there are no fields
- if (has_capability('mod/data:managetemplates', $context)) {
- if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database!
- redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
- }
+if (has_capability('mod/data:managetemplates', $context)) {
+ if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database!
+ redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
}
+}
- if ($rid) { // So do you have access?
- if (!(has_capability('mod/data:manageentries', $context) or data_isowner($rid)) or !confirm_sesskey() ) {
- print_error('noaccess','data');
- }
+if ($rid) { // So do you have access?
+ if (!(has_capability('mod/data:manageentries', $context) or data_isowner($rid)) or !confirm_sesskey() ) {
+ print_error('noaccess','data');
}
+}
- if ($cancel) {
- redirect('view.php?d='.$data->id);
- }
+if ($cancel) {
+ redirect('view.php?d='.$data->id);
+}
/// RSS and CSS and JS meta
- if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
- $rsspath = rss_get_url($course->id, $USER->id, 'data', $data->id);
- $PAGE->add_alternate_version(format_string($course->shortname) . ': %fullname%',
- $rsspath, 'application/rss+xml');
- }
- if ($data->csstemplate) {
- $PAGE->requires->css('mod/data/css.php?d='.$data->id);
- }
- if ($data->jstemplate) {
- $PAGE->requires->js('mod/data/js.php?d='.$data->id)->in_head();
- }
+if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
+ $rsspath = rss_get_url($course->id, $USER->id, 'data', $data->id);
+ $PAGE->add_alternate_version(format_string($course->shortname) . ': %fullname%',
+ $rsspath, 'application/rss+xml');
+}
+if ($data->csstemplate) {
+ $PAGE->requires->css('mod/data/css.php?d='.$data->id);
+}
+if ($data->jstemplate) {
+ $PAGE->requires->js('mod/data/js.php?d='.$data->id)->in_head();
+}
/// Print the page header
- $strdata = get_string('modulenameplural','data');
+$strdata = get_string('modulenameplural','data');
- if ($rid) {
- $PAGE->navbar->add(get_string('editentry', 'data'));
- } else {
- $PAGE->navbar->add(get_string('add', 'data'));
- }
+if ($rid) {
+ $PAGE->navbar->add(get_string('editentry', 'data'));
+} else {
+ $PAGE->navbar->add(get_string('add', 'data'));
+}
- $PAGE->set_title($data->name);
- $PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'data')));
- echo $OUTPUT->header();
+$PAGE->set_title($data->name);
+$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'data'));
+echo $OUTPUT->header();
/// Check to see if groups are being used here
- groups_print_activity_menu($cm, 'edit.php?d='.$data->id);
- $currentgroup = groups_get_activity_group($cm);
- $groupmode = groups_get_activity_groupmode($cm);
+groups_print_activity_menu($cm, 'edit.php?d='.$data->id);
+$currentgroup = groups_get_activity_group($cm);
+$groupmode = groups_get_activity_groupmode($cm);
- echo $OUTPUT->heading(format_string($data->name));
+echo $OUTPUT->heading(format_string($data->name));
- if ($currentgroup) {
- $groupselect = " AND groupid = '$currentgroup'";
- $groupparam = "&groupid=$currentgroup";
- } else {
- $groupselect = "";
- $groupparam = "";
- $currentgroup = 0;
- }
+if ($currentgroup) {
+ $groupselect = " AND groupid = '$currentgroup'";
+ $groupparam = "&groupid=$currentgroup";
+} else {
+ $groupselect = "";
+ $groupparam = "";
+ $currentgroup = 0;
+}
/// Print the tabs
- $currenttab = 'add';
- if ($rid) {
- $editentry = true; //used in tabs
- }
- include('tabs.php');
+$currenttab = 'add';
+if ($rid) {
+ $editentry = true; //used in tabs
+}
+include('tabs.php');
/// Process incoming data for adding/updating records
- if ($datarecord = data_submitted() and confirm_sesskey()) {
-
- $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel'); // strings to be ignored in input data
+if ($datarecord = data_submitted() and confirm_sesskey()) {
- if ($rid) { /// Update some records
+ $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel'); // strings to be ignored in input data
- /// All student edits are marked unapproved by default
- $record = $DB->get_record('data_records', array('id'=>$rid));
+ if ($rid) { /// Update some records
- /// reset approved flag after student edit
- if (!has_capability('mod/data:approve', $context)) {
- $record->approved = 0;
- }
+ /// All student edits are marked unapproved by default
+ $record = $DB->get_record('data_records', array('id'=>$rid));
- $record->groupid = $currentgroup;
- $record->timemodified = time();
- $DB->update_record('data_records', $record);
+ /// reset approved flag after student edit
+ if (!has_capability('mod/data:approve', $context)) {
+ $record->approved = 0;
+ }
- /// Update all content
- $field = NULL;
- 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);
- }
- if ($field) {
- $field->update_content($rid, $value, $name);
- }
+ $record->groupid = $currentgroup;
+ $record->timemodified = time();
+ $DB->update_record('data_records', $record);
+
+ /// Update all content
+ $field = NULL;
+ 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);
+ }
+ 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);
+ 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);
+ redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$rid);
- } else { /// Add some new records
+ } else { /// Add some new records
- if (!data_user_can_add_entry($data, $currentgroup, $groupmode)) {
- print_error('cannotadd', 'data');
- }
+ if (!data_user_can_add_entry($data, $currentgroup, $groupmode)) {
+ 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! =)
+ /// 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->notification(get_string('atmaxentry','data'));
+ echo $OUTPUT->footer();
+ exit;
+ }
- if (data_atmaxentries($data) and !has_capability('mod/data:manageentries',$context)){
- 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);
+ }
+ if ($field->notemptyfield($value, $name)) {
+ $emptyform = false;
+ break; // if anything has content, this form is not empty, so stop now!
+ }
}
+ }
- ///Empty form checking - you can't submit an empty form!
+ if ($emptyform){ //nothing gets written to database
+ echo $OUTPUT->notification(get_string('emptyaddform','data'));
+ }
- $emptyform = true; // assume the worst
+ if (!$emptyform && $recordid = data_add_record($data, $currentgroup)) { //add instance to data_record
- foreach ($datarecord as $name => $value) {
+ /// Insert a whole lot of empty records to make sure we have them
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id));
+ foreach ($fields as $field) {
+ $content->recordid = $recordid;
+ $content->fieldid = $field->id;
+ $DB->insert_record('data_content',$content);
+ }
+
+ //for each field in the add form, add it to the data_content.
+ 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);
}
- if ($field->notemptyfield($value, $name)) {
- $emptyform = false;
- break; // if anything has content, this form is not empty, so stop now!
+ if ($field) {
+ $field->update_content($recordid, $value, $name);
}
}
}
- if ($emptyform){ //nothing gets written to database
- echo $OUTPUT->notification(get_string('emptyaddform','data'));
- }
-
- if (!$emptyform && $recordid = data_add_record($data, $currentgroup)) { //add instance to data_record
-
- /// Insert a whole lot of empty records to make sure we have them
- $fields = $DB->get_records('data_fields', array('dataid'=>$data->id));
- foreach ($fields as $field) {
- $content->recordid = $recordid;
- $content->fieldid = $field->id;
- $DB->insert_record('data_content',$content);
- }
-
- //for each field in the add form, add it to the data_content.
- 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);
- }
- if ($field) {
- $field->update_content($recordid, $value, $name);
- }
- }
- }
+ add_to_log($course->id, 'data', 'add', "view.php?d=$data->id&rid=$recordid", $data->id, $cm->id);
- add_to_log($course->id, 'data', 'add', "view.php?d=$data->id&rid=$recordid", $data->id, $cm->id);
+ echo $OUTPUT->notification(get_string('entrysaved','data'));
- echo $OUTPUT->notification(get_string('entrysaved','data'));
-
- if (!empty($datarecord->saveandview)) {
- redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$recordid);
- }
+ if (!empty($datarecord->saveandview)) {
+ redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$recordid);
}
}
- } // End of form processing
+ }
+} // End of form processing
- /// Print the browsing interface
+/// Print the browsing interface
- $patterns = array(); //tags to replace
- $replacement = array(); //html to replace those yucky tags
+$patterns = array(); //tags to replace
+$replacement = array(); //html to replace those yucky tags
- //form goes here first in case add template is empty
- echo '<form enctype="multipart/form-data" action="edit.php" method="post">';
- echo '<div>';
- echo '<input name="d" value="'.$data->id.'" type="hidden" />';
- echo '<input name="rid" value="'.$rid.'" type="hidden" />';
- echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
- echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
+//form goes here first in case add template is empty
+echo '<form enctype="multipart/form-data" action="edit.php" method="post">';
+echo '<div>';
+echo '<input name="d" value="'.$data->id.'" type="hidden" />';
+echo '<input name="rid" value="'.$rid.'" type="hidden" />';
+echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
+echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
- if (!$rid){
- echo $OUTPUT->heading(get_string('newentry','data'), 2);
- }
+if (!$rid){
+ echo $OUTPUT->heading(get_string('newentry','data'), 2);
+}
- /******************************************
- * Regular expression replacement section *
- ******************************************/
- if ($data->addtemplate){
- $possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
-
- ///then we generate strings to replace
- foreach ($possiblefields as $eachfield){
- $field = data_get_field($eachfield, $data);
- $patterns[]="[[".$field->field->name."]]";
- $replacements[] = $field->display_add_field($rid);
- $patterns[]="[[".$field->field->name."#id]]";
- $replacements[] = 'field_'.$field->field->id;
- }
- $newtext = str_ireplace($patterns, $replacements, $data->{$mode});
+/******************************************
+ * Regular expression replacement section *
+ ******************************************/
+if ($data->addtemplate){
+ $possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
- } else { //if the add template is not yet defined, print the default form!
- echo data_generate_default_template($data, 'addtemplate', $rid, true, false);
- $newtext = '';
+ ///then we generate strings to replace
+ foreach ($possiblefields as $eachfield){
+ $field = data_get_field($eachfield, $data);
+ $patterns[]="[[".$field->field->name."]]";
+ $replacements[] = $field->display_add_field($rid);
+ $patterns[]="[[".$field->field->name."#id]]";
+ $replacements[] = 'field_'.$field->field->id;
}
+ $newtext = str_ireplace($patterns, $replacements, $data->{$mode});
- echo $newtext;
- echo '<div style="text-align:center"><input type="submit" name="saveandview" value="'.get_string('saveandview','data').'" />';
- if ($rid) {
- echo ' <input type="submit" name="cancel" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)" />';
- } else {
- echo '<input type="submit" value="'.get_string('saveandadd','data').'" />';
- }
- echo '</div>';
- echo $OUTPUT->box_end();
- echo '</div></form>';
+} else { //if the add template is not yet defined, print the default form!
+ echo data_generate_default_template($data, 'addtemplate', $rid, true, false);
+ $newtext = '';
+}
+
+echo $newtext;
+echo '<div style="text-align:center"><input type="submit" name="saveandview" value="'.get_string('saveandview','data').'" />';
+if ($rid) {
+ echo ' <input type="submit" name="cancel" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)" />';
+} else {
+ echo '<input type="submit" value="'.get_string('saveandadd','data').'" />';
+}
+echo '</div>';
+echo $OUTPUT->box_end();
+echo '</div></form>';
/// Upload records section. Only for teachers and the admin.
- if (has_capability('mod/data:manageentries',$context)) {
- if ($import) {
- echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
- echo $OUTPUT->heading(get_string('uploadrecords', 'data'), 3);
-
- $maxuploadsize = get_max_upload_file_size();
- echo '<div style="text-align:center">';
- echo '<form enctype="multipart/form-data" action="import.php" method="post">';
- echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'" />';
- echo '<input name="d" value="'.$data->id.'" type="hidden" />';
- echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
- echo '<table align="center" cellspacing="0" cellpadding="2" border="0">';
- echo '<tr>';
- echo '<td align="right">'.get_string('csvfile', 'data').':</td>';
- echo '<td><input type="file" name="recordsfile" size="30" />';
- echo $OUTPUT->help_icon(moodle_help_icon::make('importcsv', get_string('csvimport', 'data'), 'data'));
- echo '</td><tr>';
- echo '<td align="right">'.get_string('fielddelimiter', 'data').':</td>';
- echo '<td><input type="text" name="fielddelimiter" size="6" />';
- echo get_string('defaultfielddelimiter', 'data').'</td>';
- echo '</tr>';
- echo '<td align="right">'.get_string('fieldenclosure', 'data').':</td>';
- echo '<td><input type="text" name="fieldenclosure" size="6" />';
- echo get_string('defaultfieldenclosure', 'data').'</td>';
- echo '</tr>';
- echo '</table>';
- echo '<input type="submit" value="'.get_string('uploadfile', 'data').'" />';
- echo '</form>';
- echo '</div>';
- echo $OUTPUT->box_end();
- } else {
- echo '<div style="text-align:center">';
- echo '<a href="edit.php?d='.$data->id.'&import=1">'.get_string('uploadrecords', 'data').'</a>';
- echo '</div>';
- }
+if (has_capability('mod/data:manageentries',$context)) {
+ if ($import) {
+ echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
+ echo $OUTPUT->heading(get_string('uploadrecords', 'data'), 3);
+
+ $maxuploadsize = get_max_upload_file_size();
+ echo '<div style="text-align:center">';
+ echo '<form enctype="multipart/form-data" action="import.php" method="post">';
+ echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'" />';
+ echo '<input name="d" value="'.$data->id.'" type="hidden" />';
+ echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
+ echo '<table align="center" cellspacing="0" cellpadding="2" border="0">';
+ echo '<tr>';
+ echo '<td align="right">'.get_string('csvfile', 'data').':</td>';
+ echo '<td><input type="file" name="recordsfile" size="30" />';
+ echo $OUTPUT->help_icon(moodle_help_icon::make('importcsv', get_string('csvimport', 'data'), 'data'));
+ echo '</td><tr>';
+ echo '<td align="right">'.get_string('fielddelimiter', 'data').':</td>';
+ echo '<td><input type="text" name="fielddelimiter" size="6" />';
+ echo get_string('defaultfielddelimiter', 'data').'</td>';
+ echo '</tr>';
+ echo '<td align="right">'.get_string('fieldenclosure', 'data').':</td>';
+ echo '<td><input type="text" name="fieldenclosure" size="6" />';
+ echo get_string('defaultfieldenclosure', 'data').'</td>';
+ echo '</tr>';
+ echo '</table>';
+ echo '<input type="submit" value="'.get_string('uploadfile', 'data').'" />';
+ echo '</form>';
+ echo '</div>';
+ echo $OUTPUT->box_end();
+ } else {
+ echo '<div style="text-align:center">';
+ echo '<a href="edit.php?d='.$data->id.'&import=1">'.get_string('uploadrecords', 'data').'</a>';
+ echo '</div>';
}
+}
/// Finish the page
- // Print the stuff that need to come after the form fields.
- if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
- print_error('nofieldindatabase', 'data');
- }
- foreach ($fields as $eachfield) {
- $field = data_get_field($eachfield, $data);
- $field->print_after_form();
- }
-
- echo $OUTPUT->footer();
-?>
+// Print the stuff that need to come after the form fields.
+if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
+ print_error('nofieldindatabase', 'data');
+}
+foreach ($fields as $eachfield) {
+ $field = data_get_field($eachfield, $data);
+ $field->print_after_form();
+}
+
+echo $OUTPUT->footer();
+?>
\ No newline at end of file
-<?php // $Id$
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
require_once('../../config.php');
require_once('lib.php');
require_once('export_form.php');
-$d = required_param('d', PARAM_INT);
// database ID
+$d = required_param('d', PARAM_INT);
+
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/data/export.php', array('d'=>$d)));
if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('wrongdataid', 'data');
} elseif (!$formdata = (array) $mform->get_data()) {
// build header to match the rest of the UI
$PAGE->set_title($data->name);
- $PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'data')));
+ $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'data'));
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($data->name));
}
die();
-?>
+?>
\ No newline at end of file
-<?php // $Id$
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
- require_once('../../config.php');
- require_once('lib.php');
-
-
- $id = optional_param('id', 0, PARAM_INT); // course module id
- $d = optional_param('d', 0, PARAM_INT); // database id
- $fid = optional_param('fid', 0 , PARAM_INT); // update field id
- $newtype = optional_param('newtype','',PARAM_ALPHA); // type of the new field
- $mode = optional_param('mode','',PARAM_ALPHA);
- $defaultsort = optional_param('defaultsort', 0, PARAM_INT);
- $defaultsortdir = optional_param('defaultsortdir', 0, PARAM_INT);
- $cancel = optional_param('cancel', 0, PARAM_BOOL);
-
- if ($cancel) {
- $mode = 'list';
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+require_once('../../config.php');
+require_once('lib.php');
+
+$id = optional_param('id', 0, PARAM_INT); // course module id
+$d = optional_param('d', 0, PARAM_INT); // database id
+$fid = optional_param('fid', 0 , PARAM_INT); // update field id
+$newtype = optional_param('newtype','',PARAM_ALPHA); // type of the new field
+$mode = optional_param('mode','',PARAM_ALPHA);
+$defaultsort = optional_param('defaultsort', 0, PARAM_INT);
+$defaultsortdir = optional_param('defaultsortdir', 0, PARAM_INT);
+$cancel = optional_param('cancel', 0, PARAM_BOOL);
+
+if ($cancel) {
+ $mode = 'list';
+}
+
+$url = new moodle_url($CFG->wwwroot.'/mod/data/field.php');
+if ($fid !== 0) {
+ $url->param('fid', $fid);
+}
+if ($newtype !== '') {
+ $url->param('newtype', $newtype);
+}
+if ($mode !== '') {
+ $url->param('mode', $mode);
+}
+if ($defaultsort !== 0) {
+ $url->param('defaultsort', $defaultsort);
+}
+if ($defaultsortdir !== 0) {
+ $url->param('defaultsortdir', $defaultsortdir);
+}
+if ($cancel !== 0) {
+ $url->param('cancel', $cancel);
+}
+
+if ($id) {
+ $url->param('id', $id);
+ $PAGE->set_url($url);
+ if (! $cm = get_coursemodule_from_id('data', $id)) {
+ print_error('invalidcoursemodule');
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
+ print_error('coursemisconf');
+ }
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
+ print_error('invalidcoursemodule');
}
-
- if ($id) {
- if (! $cm = get_coursemodule_from_id('data', $id)) {
- print_error('invalidcoursemodule');
- }
- if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
- print_error('coursemisconf');
- }
- if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
- print_error('invalidcoursemodule');
- }
-
- } else {
- if (! $data = $DB->get_record('data', array('id'=>$d))) {
- print_error('invalidid', 'data');
- }
- if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
- print_error('invalidcoursemodule');
- }
- if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
- print_error('invalidcoursemodule');
- }
+} else {
+ $url->param('d', $d);
+ $PAGE->set_url($url);
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
+ print_error('invalidid', 'data');
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
+ print_error('invalidcoursemodule');
}
+ if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
+ print_error('invalidcoursemodule');
+ }
+}
- require_login($course->id, true, $cm);
+require_login($course->id, true, $cm);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- require_capability('mod/data:managetemplates', $context);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_capability('mod/data:managetemplates', $context);
- /************************************
- * Data Processing *
- ***********************************/
- switch ($mode) {
+/************************************
+ * Data Processing *
+ ***********************************/
+switch ($mode) {
- case 'add': ///add a new field
- if (confirm_sesskey() and $fieldinput = data_submitted()){
+ case 'add': ///add a new field
+ if (confirm_sesskey() and $fieldinput = data_submitted()){
- //$fieldinput->name = data_clean_field_name($fieldinput->name);
+ //$fieldinput->name = data_clean_field_name($fieldinput->name);
- /// Only store this new field if it doesn't already exist.
- if (($fieldinput->name == '') or data_fieldname_exists($fieldinput->name, $data->id)) {
+ /// Only store this new field if it doesn't already exist.
+ if (($fieldinput->name == '') or data_fieldname_exists($fieldinput->name, $data->id)) {
- $displaynoticebad = get_string('invalidfieldname','data');
+ $displaynoticebad = get_string('invalidfieldname','data');
- } else {
+ } else {
- /// Check for arrays and convert to a comma-delimited string
- data_convert_arrays_to_strings($fieldinput);
+ /// Check for arrays and convert to a comma-delimited string
+ data_convert_arrays_to_strings($fieldinput);
- /// Create a field object to collect and store the data safely
- $type = required_param('type', PARAM_FILE);
- $field = data_get_field_new($type, $data);
+ /// Create a field object to collect and store the data safely
+ $type = required_param('type', PARAM_FILE);
+ $field = data_get_field_new($type, $data);
- $field->define_field($fieldinput);
- $field->insert_field();
+ $field->define_field($fieldinput);
+ $field->insert_field();
- /// Update some templates
- data_append_new_field_to_templates($data, $fieldinput->name);
+ /// Update some templates
+ data_append_new_field_to_templates($data, $fieldinput->name);
- add_to_log($course->id, 'data', 'fields add',
- "field.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id);
+ add_to_log($course->id, 'data', 'fields add',
+ "field.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id);
- $displaynoticegood = get_string('fieldadded','data');
- }
+ $displaynoticegood = get_string('fieldadded','data');
}
- break;
+ }
+ break;
- case 'update': ///update a field
- if (confirm_sesskey() and $fieldinput = data_submitted()){
+ case 'update': ///update a field
+ if (confirm_sesskey() and $fieldinput = data_submitted()){
- //$fieldinput->name = data_clean_field_name($fieldinput->name);
+ //$fieldinput->name = data_clean_field_name($fieldinput->name);
- if (($fieldinput->name == '') or data_fieldname_exists($fieldinput->name, $data->id, $fieldinput->fid)) {
+ if (($fieldinput->name == '') or data_fieldname_exists($fieldinput->name, $data->id, $fieldinput->fid)) {
- $displaynoticebad = get_string('invalidfieldname','data');
+ $displaynoticebad = get_string('invalidfieldname','data');
- } else {
- /// Check for arrays and convert to a comma-delimited string
- data_convert_arrays_to_strings($fieldinput);
+ } else {
+ /// Check for arrays and convert to a comma-delimited string
+ data_convert_arrays_to_strings($fieldinput);
- /// Create a field object to collect and store the data safely
- $field = data_get_field_from_id($fid, $data);
- $oldfieldname = $field->field->name;
+ /// Create a field object to collect and store the data safely
+ $field = data_get_field_from_id($fid, $data);
+ $oldfieldname = $field->field->name;
- $field->field->name = $fieldinput->name;
- $field->field->description = $fieldinput->description;
+ $field->field->name = $fieldinput->name;
+ $field->field->description = $fieldinput->description;
- for ($i=1; $i<=10; $i++) {
- if (isset($fieldinput->{'param'.$i})) {
- $field->field->{'param'.$i} = $fieldinput->{'param'.$i};
- } else {
- $field->field->{'param'.$i} = '';
- }
+ for ($i=1; $i<=10; $i++) {
+ if (isset($fieldinput->{'param'.$i})) {
+ $field->field->{'param'.$i} = $fieldinput->{'param'.$i};
+ } else {
+ $field->field->{'param'.$i} = '';
}
+ }
- $field->update_field();
+ $field->update_field();
- /// Update the templates.
- data_replace_field_in_templates($data, $oldfieldname, $field->field->name);
+ /// Update the templates.
+ data_replace_field_in_templates($data, $oldfieldname, $field->field->name);
- add_to_log($course->id, 'data', 'fields update',
- "field.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id);
+ add_to_log($course->id, 'data', 'fields update',
+ "field.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id);
- $displaynoticegood = get_string('fieldupdated','data');
- }
+ $displaynoticegood = get_string('fieldupdated','data');
}
- break;
+ }
+ break;
- case 'delete': // Delete a field
- if (confirm_sesskey()){
+ case 'delete': // Delete a field
+ if (confirm_sesskey()){
- if ($confirm = optional_param('confirm', 0, PARAM_INT)) {
+ if ($confirm = optional_param('confirm', 0, PARAM_INT)) {
- // Delete the field completely
- if ($field = data_get_field_from_id($fid, $data)) {
- $field->delete_field();
+ // Delete the field completely
+ if ($field = data_get_field_from_id($fid, $data)) {
+ $field->delete_field();
- // Update the templates.
- data_replace_field_in_templates($data, $field->field->name, '');
+ // Update the templates.
+ data_replace_field_in_templates($data, $field->field->name, '');
- // Update the default sort field
- if ($fid == $data->defaultsort) {
- unset($rec);
- $rec->id = $data->id;
- $rec->defaultsort = 0;
- $rec->defaultsortdir = 0;
- $DB->update_record('data', $rec);
- }
+ // Update the default sort field
+ if ($fid == $data->defaultsort) {
+ unset($rec);
+ $rec->id = $data->id;
+ $rec->defaultsort = 0;
+ $rec->defaultsortdir = 0;
+ $DB->update_record('data', $rec);
+ }
- add_to_log($course->id, 'data', 'fields delete',
- "field.php?d=$data->id", $field->field->name, $cm->id);
+ add_to_log($course->id, 'data', 'fields delete',
+ "field.php?d=$data->id", $field->field->name, $cm->id);
- $displaynoticegood = get_string('fielddeleted', 'data');
- }
+ $displaynoticegood = get_string('fielddeleted', 'data');
+ }
- } else {
+ } else {
- data_print_header($course,$cm,$data, false);
+ data_print_header($course,$cm,$data, false);
- // Print confirmation message.
- $field = data_get_field_from_id($fid, $data);
+ // Print confirmation message.
+ $field = data_get_field_from_id($fid, $data);
- echo $OUTPUT->confirm('<strong>'.$field->name().': '.$field->field->name.'</strong><br /><br />'. get_string('confirmdeletefield','data'),
- 'field.php?d='.$data->id.'&mode=delete&fid='.$fid.'&confirm=1',
- 'field.php?d='.$data->id);
+ echo $OUTPUT->confirm('<strong>'.$field->name().': '.$field->field->name.'</strong><br /><br />'. get_string('confirmdeletefield','data'),
+ 'field.php?d='.$data->id.'&mode=delete&fid='.$fid.'&confirm=1',
+ 'field.php?d='.$data->id);
- echo $OUTPUT->footer();
- exit;
- }
+ echo $OUTPUT->footer();
+ exit;
}
- break;
+ }
+ break;
- case 'sort': // Set the default sort parameters
- if (confirm_sesskey()) {
- $rec->id = $data->id;
- $rec->defaultsort = $defaultsort;
- $rec->defaultsortdir = $defaultsortdir;
+ case 'sort': // Set the default sort parameters
+ if (confirm_sesskey()) {
+ $rec->id = $data->id;
+ $rec->defaultsort = $defaultsort;
+ $rec->defaultsortdir = $defaultsortdir;
- $DB->update_record('data', $rec);
- redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('changessaved'), 2);
- exit;
- }
- break;
+ $DB->update_record('data', $rec);
+ redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('changessaved'), 2);
+ exit;
+ }
+ break;
- default:
- break;
- }
+ default:
+ break;
+}
/// Print the browsing interface
- ///get the list of possible fields (plugins)
- $directories = get_list_of_plugins('mod/data/field/');
- $menufield = array();
+///get the list of possible fields (plugins)
+$directories = get_list_of_plugins('mod/data/field/');
+$menufield = array();
- foreach ($directories as $directory){
- $menufield[$directory] = get_string($directory,'data'); //get from language files
- }
- asort($menufield); //sort in alphabetical order
+foreach ($directories as $directory){
+ $menufield[$directory] = get_string($directory,'data'); //get from language files
+}
+asort($menufield); //sort in alphabetical order
- $PAGE->set_pagetype('mod-data-field-' . $newtype);
- $PAGE->navbar->add(get_string('fields', 'data'));
- if (($mode == 'new') && (!empty($newtype)) && confirm_sesskey()) { /// Adding a new field
- data_print_header($course, $cm, $data,'fields');
+$PAGE->set_pagetype('mod-data-field-' . $newtype);
+$PAGE->navbar->add(get_string('fields', 'data'));
+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();
+ $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');
+} 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();
+ $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');
+} 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
+ 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
+ } 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);
+ $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) {
+ if ($fff = $DB->get_records('data_fields', array('dataid'=>$data->id),'id')){
+ foreach ($fff as $ff) {
- $field = data_get_field($ff, $data);
+ $field = data_get_field($ff, $data);
- $table->data[] = array(
+ $table->data[] = array(
- '<a href="field.php?mode=display&d='.$data->id.
- '&fid='.$field->field->id.'&sesskey='.sesskey().'">'.$field->field->name.'</a>',
+ '<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'),
+ $field->image().' '.get_string($field->type, 'data'),
- shorten_text($field->field->description, 30),
+ shorten_text($field->field->description, 30),
- '<a href="field.php?d='.$data->id.'&mode=display&fid='.$field->field->id.'&sesskey='.sesskey().'">'.
- '<img src="'.$OUTPUT->old_icon_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->old_icon_url('t/delete') . '" class="iconsmall" alt="'.get_string('delete').'" title="'.get_string('delete').'" /></a>'
+ '<a href="field.php?d='.$data->id.'&mode=display&fid='.$field->field->id.'&sesskey='.sesskey().'">'.
+ '<img src="'.$OUTPUT->old_icon_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->old_icon_url('t/delete') . '" class="iconsmall" alt="'.get_string('delete').'" title="'.get_string('delete').'" /></a>'
- );
- }
+ );
}
- echo $OUTPUT->table($table);
}
+ echo $OUTPUT->table($table);
+ }
- echo '<div class="fieldadd">';
- echo '<label for="fieldform_jump">'.get_string('newfield','data').'</label>';
- $popupurl = $CFG->wwwroot.'/mod/data/field.php?d='.$data->id.'&mode=new&sesskey='. sesskey();
- echo $OUTPUT->select(html_select::make_popup_form($popupurl, 'newtype', $menufield, "fieldform"));
- echo $OUTPUT->help_icon(moodle_help_icon::make('fields', get_string('addafield','data'), 'data'));
- echo '</div>';
-
- echo '<div class="sortdefault">';
- echo '<form id="sortdefault" action="'.$CFG->wwwroot.'/mod/data/field.php" method="get">';
- echo '<div>';
- echo '<input type="hidden" name="d" value="'.$data->id.'" />';
- echo '<input type="hidden" name="mode" value="sort" />';
- echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
- echo '<label for="defaultsort">'.get_string('defaultsortfield','data').'</label>';
- echo '<select id="defaultsort" name="defaultsort">';
- if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
- echo '<optgroup label="'.get_string('fields', 'data').'">';
- foreach ($fields as $field) {
- if ($data->defaultsort == $field->id) {
- echo '<option value="'.$field->id.'" selected="selected">'.$field->name.'</option>';
- } else {
- echo '<option value="'.$field->id.'">'.$field->name.'</option>';
- }
+ echo '<div class="fieldadd">';
+ echo '<label for="fieldform_jump">'.get_string('newfield','data').'</label>';
+ $popupurl = $CFG->wwwroot.'/mod/data/field.php?d='.$data->id.'&mode=new&sesskey='. sesskey();
+ echo $OUTPUT->select(html_select::make_popup_form($popupurl, 'newtype', $menufield, "fieldform"));
+ echo $OUTPUT->help_icon(moodle_help_icon::make('fields', get_string('addafield','data'), 'data'));
+ echo '</div>';
+
+ echo '<div class="sortdefault">';
+ echo '<form id="sortdefault" action="'.$CFG->wwwroot.'/mod/data/field.php" method="get">';
+ echo '<div>';
+ echo '<input type="hidden" name="d" value="'.$data->id.'" />';
+ echo '<input type="hidden" name="mode" value="sort" />';
+ echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+ echo '<label for="defaultsort">'.get_string('defaultsortfield','data').'</label>';
+ echo '<select id="defaultsort" name="defaultsort">';
+ if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
+ echo '<optgroup label="'.get_string('fields', 'data').'">';
+ foreach ($fields as $field) {
+ if ($data->defaultsort == $field->id) {
+ echo '<option value="'.$field->id.'" selected="selected">'.$field->name.'</option>';
+ } else {
+ echo '<option value="'.$field->id.'">'.$field->name.'</option>';
}
- echo '</optgroup>';
}
- $options = array();
- $options[DATA_TIMEADDED] = get_string('timeadded', 'data');
+ echo '</optgroup>';
+ }
+ $options = array();
+ $options[DATA_TIMEADDED] = get_string('timeadded', 'data');
// TODO: we will need to change defaultsort db to unsinged to make these work in 2.0
/* $options[DATA_TIMEMODIFIED] = get_string('timemodified', 'data');
- $options[DATA_FIRSTNAME] = get_string('authorfirstname', 'data');
- $options[DATA_LASTNAME] = get_string('authorlastname', 'data');
- if ($data->approval and has_capability('mod/data:approve', $context)) {
- $options[DATA_APPROVED] = get_string('approved', 'data');
- }*/
- echo '<optgroup label="'.get_string('other', 'data').'">';
- foreach ($options as $key => $name) {
- if ($data->defaultsort == $key) {
- echo '<option value="'.$key.'" selected="selected">'.$name.'</option>';
- } else {
- echo '<option value="'.$key.'">'.$name.'</option>';
- }
+ $options[DATA_FIRSTNAME] = get_string('authorfirstname', 'data');
+ $options[DATA_LASTNAME] = get_string('authorlastname', 'data');
+ if ($data->approval and has_capability('mod/data:approve', $context)) {
+ $options[DATA_APPROVED] = get_string('approved', 'data');
+ }*/
+ echo '<optgroup label="'.get_string('other', 'data').'">';
+ foreach ($options as $key => $name) {
+ if ($data->defaultsort == $key) {
+ echo '<option value="'.$key.'" selected="selected">'.$name.'</option>';
+ } else {
+ echo '<option value="'.$key.'">'.$name.'</option>';
}
- echo '</optgroup>';
- echo '</select>';
+ }
+ echo '</optgroup>';
+ echo '</select>';
- $options = array(0 => get_string('ascending', 'data'),
- 1 => get_string('descending', 'data'));
- echo $OUTPUT->select(html_select::make($options, 'defaultsortdir', $data->defaultsortdir, false));
- echo '<input type="submit" value="'.get_string('save', 'data').'" />';
- echo '</div>';
- echo '</form>';
- echo '</div>';
+ $options = array(0 => get_string('ascending', 'data'),
+ 1 => get_string('descending', 'data'));
+ echo $OUTPUT->select(html_select::make($options, 'defaultsortdir', $data->defaultsortdir, false));
+ echo '<input type="submit" value="'.get_string('save', 'data').'" />';
+ echo '</div>';
+ echo '</form>';
+ echo '</div>';
- }
+}
/// Finish the page
- echo $OUTPUT->footer();
-
+echo $OUTPUT->footer();
-?>
+?>
\ No newline at end of file
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
// A lot of this initial stuff is copied from mod/data/view.php
require_once('../../../../config.php');
$fieldid = required_param('fieldid', PARAM_INT); // field id
$rid = optional_param('rid', 0, PARAM_INT); //record id
+$url = new moodle_url($CFG->wwwroot.'/mod/data/field/latlong/kml.php', array('d'=>$d, 'fieldid'=>$fieldid));
+if ($rid !== 0) {
+ $url->param('rid', $rid);
+}
+$PAGE->set_url($url);
if ($rid) {
if (! $record = $DB->get_record('data_records', array('id'=>$rid))) {
-<?php // $Id$
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
- require_once('../../config.php');
- require_once('lib.php');
- require_once($CFG->libdir.'/uploadlib.php');
-
- require_login();
-
- $id = optional_param('id', 0, PARAM_INT); // course module id
- $d = optional_param('d', 0, PARAM_INT); // database id
- $rid = optional_param('rid', 0, PARAM_INT); // record id
- $fielddelimiter = optional_param('fielddelimiter', ',', PARAM_CLEANHTML); // characters used as field delimiters for csv file import
- $fieldenclosure = optional_param('fieldenclosure', '', PARAM_CLEANHTML); // characters used as record delimiters for csv file import
-
- if ($id) {
- if (! $cm = get_coursemodule_from_id('data', $id)) {
- print_error('invalidcoursemodule');
- }
- if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
- print_error('coursemisconf');
- }
- if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
- print_error('invalidcoursemodule');
- }
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+require_once('../../config.php');
+require_once('lib.php');
+require_once($CFG->libdir.'/uploadlib.php');
+
+require_login();
+
+$id = optional_param('id', 0, PARAM_INT); // course module id
+$d = optional_param('d', 0, PARAM_INT); // database id
+$rid = optional_param('rid', 0, PARAM_INT); // record id
+$fielddelimiter = optional_param('fielddelimiter', ',', PARAM_CLEANHTML); // characters used as field delimiters for csv file import
+$fieldenclosure = optional_param('fieldenclosure', '', PARAM_CLEANHTML); // characters used as record delimiters for csv file import
+
+$url = new moodle_url($CFG->wwwroot.'/mod/data/import.php');
+if ($rid !== 0) {
+ $url->param('rid', $rid);
+}
+if ($fielddelimiter !== '') {
+ $url->param('fielddelimiter', $fielddelimiter);
+}
+if ($fieldenclosure !== '') {
+ $url->param('fieldenclosure', $fieldenclosure);
+}
- } else {
- if (! $data = $DB->get_record('data', array('id'=>$d))) {
- print_error('invalidid', 'data');
- }
- if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
- print_error('coursemisconf');
- }
- if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
- print_error('coursemisconf');
- }
+if ($id) {
+ $url->param('id', $id);
+ $PAGE->set_url($url);
+ if (! $cm = get_coursemodule_from_id('data', $id)) {
+ print_error('invalidcoursemodule');
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
+ print_error('coursemisconf');
+ }
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
+ print_error('invalidcoursemodule');
+ }
+
+} else {
+ $url->param('d', $d);
+ $PAGE->set_url($url);
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
+ print_error('invalidid', 'data');
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
+ print_error('coursemisconf');
}
+ if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
+ print_error('coursemisconf');
+ }
+}
- require_login($course, false, $cm);
+require_login($course, false, $cm);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- require_capability('mod/data:manageentries', $context);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_capability('mod/data:manageentries', $context);
/// Print the page header
- $strdata = get_string('modulenameplural','data');
-
- $PAGE->set_title($data->name);
- echo $OUTPUT->header();
- echo $OUTPUT->heading(format_string($data->name));
+$strdata = get_string('modulenameplural','data');
+
+$PAGE->set_title($data->name);
+echo $OUTPUT->header();
+echo $OUTPUT->heading(format_string($data->name));
/// Groups needed for Add entry tab
- $currentgroup = groups_get_activity_group($cm);
- $groupmode = groups_get_activity_groupmode($cm);
+$currentgroup = groups_get_activity_group($cm);
+$groupmode = groups_get_activity_groupmode($cm);
/// Print the tabs
- $currenttab = 'add';
- include('tabs.php');
-
+$currenttab = 'add';
+include('tabs.php');
- $um = new upload_manager('recordsfile', false, false, null, false, 0);
- if ($um->preprocess_files() && confirm_sesskey()) {
- $filename = $um->files['recordsfile']['tmp_name'];
+$um = new upload_manager('recordsfile', false, false, null, false, 0);
- // Large files are likely to take their time and memory. Let PHP know
- // that we'll take longer, and that the process should be recycled soon
- // to free up memory.
- @set_time_limit(0);
- @raise_memory_limit("96M");
- if (function_exists('apache_child_terminate')) {
- @apache_child_terminate();
- }
+if ($um->preprocess_files() && confirm_sesskey()) {
+ $filename = $um->files['recordsfile']['tmp_name'];
- //Fix mac/dos newlines
- $text = my_file_get_contents($filename);
- $text = preg_replace('!\r\n?!',"\n",$text);
- $fp = fopen($filename, "w");
- fwrite($fp, $text);
- fclose($fp);
+ // Large files are likely to take their time and memory. Let PHP know
+ // that we'll take longer, and that the process should be recycled soon
+ // to free up memory.
+ @set_time_limit(0);
+ @raise_memory_limit("96M");
+ if (function_exists('apache_child_terminate')) {
+ @apache_child_terminate();
+ }
- $recordsadded = 0;
+ //Fix mac/dos newlines
+ $text = my_file_get_contents($filename);
+ $text = preg_replace('!\r\n?!',"\n",$text);
+ $fp = fopen($filename, "w");
+ fwrite($fp, $text);
+ fclose($fp);
- if (!$records = data_get_records_csv($filename, $fielddelimiter, $fieldenclosure)) {
- print_error('csvfailed','data',"{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}");
- } else {
- $fieldnames = array_shift($records);
+ $recordsadded = 0;
- // check the fieldnames are valid
- $fields = $DB->get_records('data_fields', array('dataid'=>$data->id), '', 'name, id, type');
- $errorfield = '';
- foreach ($fieldnames as $name) {
- if (!isset($fields[$name])) {
- $errorfield .= "'$name' ";
- }
+ if (!$records = data_get_records_csv($filename, $fielddelimiter, $fieldenclosure)) {
+ print_error('csvfailed','data',"{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}");
+ } else {
+ $fieldnames = array_shift($records);
+
+ // check the fieldnames are valid
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id), '', 'name, id, type');
+ $errorfield = '';
+ foreach ($fieldnames as $name) {
+ if (!isset($fields[$name])) {
+ $errorfield .= "'$name' ";
}
+ }
- if (!empty($errorfield)) {
- print_error('fieldnotmatched','data',"{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}",$errorfield);
- }
+ if (!empty($errorfield)) {
+ print_error('fieldnotmatched','data',"{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}",$errorfield);
+ }
- foreach ($records as $record) {
- if ($recordid = data_add_record($data, 0)) { // add instance to data_record
- $fields = $DB->get_records('data_fields', array('dataid'=>$data->id), '', 'name, id, type');
+ foreach ($records as $record) {
+ if ($recordid = data_add_record($data, 0)) { // add instance to data_record
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id), '', 'name, id, type');
- // Insert new data_content fields with NULL contents:
- foreach ($fields as $field) {
- $content = new object();
- $content->recordid = $recordid;
- $content->fieldid = $field->id;
- $DB->insert_record('data_content', $content);
+ // Insert new data_content fields with NULL contents:
+ foreach ($fields as $field) {
+ $content = new object();
+ $content->recordid = $recordid;
+ $content->fieldid = $field->id;
+ $DB->insert_record('data_content', $content);
+ }
+ // Fill data_content with the values imported from the CSV file:
+ foreach ($record as $key => $value) {
+ $name = $fieldnames[$key];
+ $field = $fields[$name];
+ $content = new object();
+ $content->fieldid = $field->id;
+ $content->recordid = $recordid;
+ if ($field->type == 'textarea') {
+ // the only field type where HTML is possible
+ $value = clean_param($value, PARAM_CLEANHTML);
+ } else {
+ // remove potential HTML:
+ $patterns[] = '/</';
+ $replacements[] = '<';
+ $patterns[] = '/>/';
+ $replacements[] = '>';
+ $value = preg_replace($patterns, $replacements, $value);
}
- // Fill data_content with the values imported from the CSV file:
- foreach ($record as $key => $value) {
- $name = $fieldnames[$key];
- $field = $fields[$name];
- $content = new object();
- $content->fieldid = $field->id;
- $content->recordid = $recordid;
- if ($field->type == 'textarea') {
- // the only field type where HTML is possible
- $value = clean_param($value, PARAM_CLEANHTML);
- } else {
- // remove potential HTML:
- $patterns[] = '/</';
- $replacements[] = '<';
- $patterns[] = '/>/';
- $replacements[] = '>';
- $value = preg_replace($patterns, $replacements, $value);
- }
- // for now, only for "latlong" and "url" fields, but that should better be looked up from
- // $CFG->dirroot . '/mod/data/field/' . $field->type . '/field.class.php'
- // once there is stored how many contents the field can have.
- if (preg_match("/^(latlong|url)$/", $field->type)) {
- $values = explode(" ", $value, 2);
- $content->content = $values[0];
- $content->content1 = $values[1];
- } else {
- $content->content = $value;
- }
- $oldcontent = $DB->get_record('data_content', array('fieldid'=>$field->id, 'recordid'=>$recordid));
- $content->id = $oldcontent->id;
- $DB->update_record('data_content', $content);
+ // for now, only for "latlong" and "url" fields, but that should better be looked up from
+ // $CFG->dirroot . '/mod/data/field/' . $field->type . '/field.class.php'
+ // once there is stored how many contents the field can have.
+ if (preg_match("/^(latlong|url)$/", $field->type)) {
+ $values = explode(" ", $value, 2);
+ $content->content = $values[0];
+ $content->content1 = $values[1];
+ } else {
+ $content->content = $value;
}
- $recordsadded++;
- print get_string('added', 'moodle', $recordsadded) . ". " . get_string('entry', 'data') . " (ID $recordid)<br />\n";
+ $oldcontent = $DB->get_record('data_content', array('fieldid'=>$field->id, 'recordid'=>$recordid));
+ $content->id = $oldcontent->id;
+ $DB->update_record('data_content', $content);
}
+ $recordsadded++;
+ print get_string('added', 'moodle', $recordsadded) . ". " . get_string('entry', 'data') . " (ID $recordid)<br />\n";
}
}
}
+}
- if ($recordsadded > 0) {
- echo $OUTPUT->notification($recordsadded. ' '. get_string('recordssaved', 'data'));
- } else {
- echo $OUTPUT->notification(get_string('recordsnotsaved', 'data'));
- }
- echo '<p />';
+if ($recordsadded > 0) {
+ echo $OUTPUT->notification($recordsadded. ' '. get_string('recordssaved', 'data'));
+} else {
+ echo $OUTPUT->notification(get_string('recordsnotsaved', 'data'));
+}
+echo '<p />';
/// Finish the page
- echo $OUTPUT->footer();
+echo $OUTPUT->footer();
-<?php // $Id$
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 1990-onwards Moodle Pty Ltd http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
- require_once("../../config.php");
- require_once("lib.php");
-
- $id = required_param('id', PARAM_INT); // course
-
- if (!$course = $DB->get_record('course', array('id'=>$id))) {
- print_error('invalidcourseid');
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 1990 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+require_once("../../config.php");
+require_once("lib.php");
+
+$id = required_param('id', PARAM_INT); // course
+
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/data/index.php', array('id'=>$id)));
+
+if (!$course = $DB->get_record('course', array('id'=>$id))) {
+ print_error('invalidcourseid');
+}
+
+require_course_login($course);
+
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+add_to_log($course->id, "data", "view all", "index.php?id=$course->id", "");
+
+$strweek = get_string('week');
+$strtopic = get_string('topic');
+$strname = get_string('name');
+$strdata = get_string('modulename','data');
+$strdataplural = get_string('modulenameplural','data');
+
+$PAGE->navbar->add($strdata, new moodle_url($CFG->wwwroot.'/mod/data/index.php', array('id'=>$course->id)));
+$PAGE->set_title($strdata);
+echo $OUTPUT->header();
+
+if (! $datas = get_all_instances_in_course("data", $course)) {
+ notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id");
+}
+
+$timenow = time();
+$strname = get_string('name');
+$strweek = get_string('week');
+$strtopic = get_string('topic');
+$strdescription = get_string("description");
+$strentries = get_string('entries', 'data');
+$strnumnotapproved = get_string('numnotapproved', 'data');
+
+$table = new html_table();
+
+if ($course->format == 'weeks') {
+ $table->head = array ($strweek, $strname, $strdescription, $strentries, $strnumnotapproved);
+ $table->align = array ('center', 'center', 'center', 'center', 'center');
+} else if ($course->format == 'topics') {
+ $table->head = array ($strtopic, $strname, $strdescription, $strentries, $strnumnotapproved);
+ $table->align = array ('center', 'center', 'center', 'center', 'center');
+} else {
+ $table->head = array ($strname, $strdescription, $strentries, $strnumnotapproved);
+ $table->align = array ('center', 'center', 'center', 'center');
+}
+
+$rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
+
+if ($rss) {
+ require_once($CFG->libdir."/rsslib.php");
+ array_push($table->head, 'RSS');
+ array_push($table->align, 'center');
+}
+
+$options = new object();
+$options->noclean = true;
+
+$currentsection = "";
+
+foreach ($datas as $data) {
+
+ $printsection = "";
+
+ //Calculate the href
+ if (!$data->visible) {
+ //Show dimmed if the mod is hidden
+ $link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
+ } else {
+ //Show normal if the mod is visible
+ $link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
}
- require_course_login($course);
-
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
-
- add_to_log($course->id, "data", "view all", "index.php?id=$course->id", "");
-
- $strweek = get_string('week');
- $strtopic = get_string('topic');
- $strname = get_string('name');
- $strdata = get_string('modulename','data');
- $strdataplural = get_string('modulenameplural','data');
+ // TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
- $PAGE->navbar->add($strdata, new moodle_url($CFG->wwwroot.'/mod/data/index.php', array('id'=>$course->id)));
- $PAGE->set_title($strdata);
- echo $OUTPUT->header();
+ $numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
- if (! $datas = get_all_instances_in_course("data", $course)) {
- notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id");
- }
-
- $timenow = time();
- $strname = get_string('name');
- $strweek = get_string('week');
- $strtopic = get_string('topic');
- $strdescription = get_string("description");
- $strentries = get_string('entries', 'data');
- $strnumnotapproved = get_string('numnotapproved', 'data');
-
- $table = new html_table();
-
- if ($course->format == 'weeks') {
- $table->head = array ($strweek, $strname, $strdescription, $strentries, $strnumnotapproved);
- $table->align = array ('center', 'center', 'center', 'center', 'center');
- } else if ($course->format == 'topics') {
- $table->head = array ($strtopic, $strname, $strdescription, $strentries, $strnumnotapproved);
- $table->align = array ('center', 'center', 'center', 'center', 'center');
+ if ($data->approval == 1) {
+ $numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
} else {
- $table->head = array ($strname, $strdescription, $strentries, $strnumnotapproved);
- $table->align = array ('center', 'center', 'center', 'center');
+ $numunapprovedrecords = '-';
}
- $rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
-
- if ($rss) {
- require_once($CFG->libdir."/rsslib.php");
- array_push($table->head, 'RSS');
- array_push($table->align, 'center');
+ $rsslink = '';
+ if ($rss && $data->rssarticles > 0) {
+ $rsslink = rss_get_link($course->id, $USER->id, 'data', $data->id, 'RSS');
}
- $options = new object();
- $options->noclean = true;
-
- $currentsection = "";
-
- foreach ($datas as $data) {
-
- $printsection = "";
-
- //Calculate the href
- if (!$data->visible) {
- //Show dimmed if the mod is hidden
- $link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
- } else {
- //Show normal if the mod is visible
- $link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
- }
-
- // TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
-
- $numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
-
- if ($data->approval == 1) {
- $numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
- } else {
- $numunapprovedrecords = '-';
- }
-
- $rsslink = '';
- if ($rss && $data->rssarticles > 0) {
- $rsslink = rss_get_link($course->id, $USER->id, 'data', $data->id, 'RSS');
- }
-
- if ($course->format == 'weeks' or $course->format == 'topics') {
- if ($data->section !== $currentsection) {
- if ($data->section) {
- $printsection = $data->section;
- }
- if ($currentsection !== '') {
- $table->data[] = 'hr';
- }
- $currentsection = $data->section;
+ if ($course->format == 'weeks' or $course->format == 'topics') {
+ if ($data->section !== $currentsection) {
+ if ($data->section) {
+ $printsection = $data->section;
}
- $row = array ($printsection, $link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
-
- } else {
- $row = array ($link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
+ if ($currentsection !== '') {
+ $table->data[] = 'hr';
+ }
+ $currentsection = $data->section;
}
+ $row = array ($printsection, $link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
- if ($rss) {
- array_push($row, $rsslink);
- }
+ } else {
+ $row = array ($link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
+ }
- $table->data[] = $row;
+ if ($rss) {
+ array_push($row, $rsslink);
}
- echo "<br />";
- echo $OUTPUT->table($table);
- echo $OUTPUT->footer();
+ $table->data[] = $row;
+}
+
+echo "<br />";
+echo $OUTPUT->table($table);
+echo $OUTPUT->footer();
-?>
+?>
\ No newline at end of file
<?php
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
- define('NO_MOODLE_COOKIES', true); // session not used here
-
- require_once('../../config.php');
-
- $d = optional_param('d', 0, PARAM_INT); // database id
- $lifetime = 600; // Seconds to cache this stylesheet
-
- if ($data = $DB->get_record('data', array('id'=>$d))) {
- header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
- header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
- header('Cache-control: max_age = '. $lifetime);
- header('Pragma: ');
- header('Content-type: text/css'); // Correct MIME type
-
- echo $data->jstemplate;
- }
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+define('NO_MOODLE_COOKIES', true); // session not used here
+
+require_once('../../config.php');
+
+$d = optional_param('d', 0, PARAM_INT); // database id
+
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/data/js.php', array('d'=>$d)));
+
+$lifetime = 600; // Seconds to cache this stylesheet
+
+if ($data = $DB->get_record('data', array('id'=>$d))) {
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
+ header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
+ header('Cache-control: max_age = '. $lifetime);
+ header('Pragma: ');
+ header('Content-type: text/css'); // Correct MIME type
+
+ echo $data->jstemplate;
+}
\ No newline at end of file
echo '<br />';
}
- if (!isloggedin() or isguest() or !$cancomment) {
+ if (!isloggedin() or has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false) or !$cancomment) {
return;
}
global $CFG, $displaynoticegood, $displaynoticebad, $OUTPUT, $PAGE;
$PAGE->set_title($data->name);
- $PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'data')));
+ $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'data'));
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($data->name));
-<?php // $Id$
-/* Preset Menu
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Preset Menu
*
* This is the page that is the menu item in the config database
* pages.
+ *
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
*/
require_once('../../config.php');
$fullname = optional_param('fullname', '', PARAM_PATH); // directory the preset is in
$file = optional_param('file', '', PARAM_PATH); // uploaded file
+$url = new moodle_url($CFG->wwwroot.'/mod/data/preset.php');
+if ($action !== 'base') {
+ $url->param('action', $action);
+}
+if ($fullname !== '') {
+ $url->param('fullname', $fullname);
+}
+if ($file !== '') {
+ $url->param('file', $file);
+}
+
// find out preset owner userid and shortname
$parts = explode('/', $fullname);
$userid = empty($parts[0]) ? 0 : (int)$parts[0];
unset($fullname);
if ($id) {
+ $url->param('id', $id);
+ $PAGE->set_url($url);
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('invalidcoursemodule');
}
print_error('invalidid', 'data');
}
} else if ($d) {
+ $url->param('d', $d);
+ $PAGE->set_url($url);
if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('invalidid', 'data');
}
-<?php // $Id$
- require_once('../../config.php');
- require_once('lib.php');
+<?php
- $dataid = required_param('dataid', PARAM_INT); // The forum the rated posts are from
+require_once('../../config.php');
+require_once('lib.php');
- if (!$data = $DB->get_record('data', array('id'=>$dataid))) {
- print_error('invalidid', 'data');
- }
+$dataid = required_param('dataid', PARAM_INT); // The forum the rated posts are from
- if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
- print_error('invalidcourseid');
- }
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/data/rate.php', array('dataid'=>$dataid)));
- if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
- print_error('invalidcoursemodule');
- }
+if (!$data = $DB->get_record('data', array('id'=>$dataid))) {
+ print_error('invalidid', 'data');
+}
- require_login($course, false, $cm);
+if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
+ print_error('invalidcourseid');
+}
- if (isguestuser()) {
- print_error('guestrate', 'data');
- }
+if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
+ print_error('invalidcoursemodule');
+}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- require_capability('mod/data:rate', $context);
+require_login($course, false, $cm);
- if (!$data->assessed) {
- print_error('cannotrate', 'data');
- }
+if (isguestuser()) {
+ print_error('guestrate', 'data');
+}
- if (!$frmdata = data_submitted() or !confirm_sesskey()) {
- print_error('invalidaccess', 'data');
- }
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_capability('mod/data:rate', $context);
-/// Calculate scale values
- $scale_values = make_grades_menu($data->scale);
+if (!$data->assessed) {
+ print_error('cannotrate', 'data');
+}
- $count = 0;
+if (!$frmdata = data_submitted() or !confirm_sesskey()) {
+ print_error('invalidaccess', 'data');
+}
- foreach ((array)$frmdata as $recordid => $rating) {
- if (!is_numeric($recordid)) {
- continue;
- }
+/// Calculate scale values
+$scale_values = make_grades_menu($data->scale);
- if (!$record = $DB->get_record('data_records', array('id'=>$recordid))) {
- print_error('invalidid', 'data');
- }
+$count = 0;
- if ($data->id != $record->dataid) {
- print_error('invalidrecord', 'data');
- }
+foreach ((array)$frmdata as $recordid => $rating) {
+ if (!is_numeric($recordid)) {
+ continue;
+ }
- if ($record->userid == $USER->id) {
- continue;
- }
+ if (!$record = $DB->get_record('data_records', array('id'=>$recordid))) {
+ print_error('invalidid', 'data');
+ }
- /// Check rate is valid for that database scale values
- if (!array_key_exists($rating, $scale_values) && $rating != -999) {
- print_error('invalidrate', 'data', '', $rating);
- }
+ if ($data->id != $record->dataid) {
+ print_error('invalidrecord', 'data');
+ }
- // input validation ok
+ if ($record->userid == $USER->id) {
+ continue;
+ }
- $count++;
+/// Check rate is valid for that database scale values
+ if (!array_key_exists($rating, $scale_values) && $rating != -999) {
+ print_error('invalidrate', 'data', '', $rating);
+ }
- if ($oldrating = $DB->get_record('data_ratings', array('userid'=>$USER->id, 'recordid'=>$record->id))) {
- if ($rating == -999) {
- $DB->delete_records('data_ratings', array('userid'=>$oldrating->userid, 'recordid'=>$oldrating->recordid));
- data_update_grades($data, $record->userid);
+ // input validation ok
- } else if ($rating != $oldrating->rating) {
- $oldrating->rating = $rating;
- $DB->update_record('data_ratings', $oldrating);
- data_update_grades($data, $record->userid);
+ $count++;
- }
+ if ($oldrating = $DB->get_record('data_ratings', array('userid'=>$USER->id, 'recordid'=>$record->id))) {
+ if ($rating == -999) {
+ $DB->delete_records('data_ratings', array('userid'=>$oldrating->userid, 'recordid'=>$oldrating->recordid));
+ data_update_grades($data, $record->userid);
- } else if ($rating) {
- $newrating = new object();
- $newrating->userid = $USER->id;
- $newrating->recordid = $record->id;
- $newrating->rating = $rating;
- $DB->insert_record('data_ratings', $newrating);
+ } else if ($rating != $oldrating->rating) {
+ $oldrating->rating = $rating;
+ $DB->update_record('data_ratings', $oldrating);
data_update_grades($data, $record->userid);
+
}
- }
- if ($count == 0) {
- print_error('invalidratedata', 'data');
+ } else if ($rating) {
+ $newrating = new object();
+ $newrating->userid = $USER->id;
+ $newrating->recordid = $record->id;
+ $newrating->rating = $rating;
+ $DB->insert_record('data_ratings', $newrating);
+ data_update_grades($data, $record->userid);
}
-
- if (!empty($_SERVER['HTTP_REFERER'])) {
- redirect($_SERVER['HTTP_REFERER'], get_string('ratingssaved', 'data'));
+}
+
+if ($count == 0) {
+ print_error('invalidratedata', 'data');
+}
+
+if (!empty($_SERVER['HTTP_REFERER'])) {
+ redirect($_SERVER['HTTP_REFERER'], get_string('ratingssaved', 'data'));
+} else {
+ // try to guess where to return
+ if ($count == 1) {
+ redirect('view.php?mode=single&rid='.$record->id, get_string('ratingssaved', 'data'));
} else {
- // try to guess where to return
- if ($count == 1) {
- redirect('view.php?mode=single&rid='.$record->id, get_string('ratingssaved', 'data'));
- } else {
- redirect('view.php?d='.$data->id, get_string('ratingssaved', 'data'));
- }
+ redirect('view.php?d='.$data->id, get_string('ratingssaved', 'data'));
}
+}
-?>
+?>
\ No newline at end of file
-<?php // $Id$
+<?php
// For a given post, shows a report of all the ratings it has
- require_once("../../config.php");
- require_once("lib.php");
-
- $id = required_param('id', PARAM_INT);
- $sort = optional_param('sort', '', PARAM_ALPHA);
-
- if (!$record = $DB->get_record('data_records', array('id'=>$id))) {
- print_error('invalidrecord', 'data');
- }
-
- if (!$data = $DB->get_record('data', array('id'=>$record->dataid))) {
- print_error('invalidid', 'data');
- }
-
- if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
- print_error('coursemisconf');
- }
-
- if (!$cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
- print_error('invalidcoursemodule');
- }
-
- require_login($course->id, false, $cm);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- if (!$data->assessed) {
- print_error('norating', 'data');
- }
-
- if (!data_isowner($record->id) and !has_capability('mod/data:viewrating', $context) and !has_capability('mod/data:rate', $context)) {
- print_error('cannotviewrate', 'data');
- }
-
- switch ($sort) {
- case 'firstname': $sqlsort = "u.firstname ASC"; break;
- case 'rating': $sqlsort = "r.rating ASC"; break;
- default: $sqlsort = "r.id ASC";
- }
-
- $scalemenu = make_grades_menu($data->scale);
-
- $strratings = get_string('ratings', 'data');
- $strrating = get_string('rating', 'data');
- $strname = get_string('name');
-
- $PAGE->set_title($strratings);
- echo $OUTPUT->header();
-
- if (!$ratings = data_get_ratings($record->id, $sqlsort)) {
- print_error('noratingforrecord', 'data');
-
- } else {
- echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
- echo "<tr>";
- echo "<th class=\"header\" scope=\"col\"> </th>";
- echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$record->id&sort=firstname\">$strname</a></th>";
- echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$id&sort=rating\">$strrating</a></th>";
- echo "</tr>";
- foreach ($ratings as $rating) {
- if (has_capability('mod/data:manageentries', $context)) {
- echo '<tr class="forumpostheadertopic">';
- } else {
- echo '<tr class="forumpostheader">';
- }
- echo '<td class="picture">';
- $userpic = moodle_user_picture::make($rating, $data->course);
- $userpic->link = true;
- echo $OUTPUT->user_picture($userpic);
- echo '</td>';
- echo '<td class="author">' . $OUTPUT->link($CFG->wwwroot.'/user/view.php?id='.$rating->id.'&course='.$data->course, fullname($rating)) . '</td>';
- echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating].'</td>';
- echo "</tr>\n";
+require_once("../../config.php");
+require_once("lib.php");
+
+$id = required_param('id', PARAM_INT);
+$sort = optional_param('sort', '', PARAM_ALPHA);
+
+$url = new moodle_url($CFG->wwwroot.'/mod/data/report.php', array('id'=>$id));
+if ($sort !== 0) {
+ $url->param('sort', $sort);
+}
+$PAGE->set_url($url);
+
+if (!$record = $DB->get_record('data_records', array('id'=>$id))) {
+ print_error('invalidrecord', 'data');
+}
+
+if (!$data = $DB->get_record('data', array('id'=>$record->dataid))) {
+ print_error('invalidid', 'data');
+}
+
+if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
+ print_error('coursemisconf');
+}
+
+if (!$cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
+ print_error('invalidcoursemodule');
+}
+
+require_login($course->id, false, $cm);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+if (!$data->assessed) {
+ print_error('norating', 'data');
+}
+
+if (!data_isowner($record->id) and !has_capability('mod/data:viewrating', $context) and !has_capability('mod/data:rate', $context)) {
+ print_error('cannotviewrate', 'data');
+}
+
+switch ($sort) {
+ case 'firstname': $sqlsort = "u.firstname ASC"; break;
+ case 'rating': $sqlsort = "r.rating ASC"; break;
+ default: $sqlsort = "r.id ASC";
+}
+
+$scalemenu = make_grades_menu($data->scale);
+
+$strratings = get_string('ratings', 'data');
+$strrating = get_string('rating', 'data');
+$strname = get_string('name');
+
+$PAGE->set_title($strratings);
+echo $OUTPUT->header();
+
+if (!$ratings = data_get_ratings($record->id, $sqlsort)) {
+ print_error('noratingforrecord', 'data');
+
+} else {
+ echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
+ echo "<tr>";
+ echo "<th class=\"header\" scope=\"col\"> </th>";
+ echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$record->id&sort=firstname\">$strname</a></th>";
+ echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$id&sort=rating\">$strrating</a></th>";
+ echo "</tr>";
+ foreach ($ratings as $rating) {
+ if (has_capability('mod/data:manageentries', $context)) {
+ echo '<tr class="forumpostheadertopic">';
+ } else {
+ echo '<tr class="forumpostheader">';
}
- echo "</table>";
- echo "<br />";
+ echo '<td class="picture">';
+ $userpic = moodle_user_picture::make($rating, $data->course);
+ $userpic->link = true;
+ echo $OUTPUT->user_picture($userpic);
+ echo '</td>';
+ echo '<td class="author">' . $OUTPUT->link($CFG->wwwroot.'/user/view.php?id='.$rating->id.'&course='.$data->course, fullname($rating)) . '</td>';
+ echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating].'</td>';
+ echo "</tr>\n";
}
+ echo "</table>";
+ echo "<br />";
+}
- echo $OUTPUT->close_window_button();
- echo $OUTPUT->footer();
-?>
+echo $OUTPUT->close_window_button();
+echo $OUTPUT->footer();
+?>
\ No newline at end of file
-<?php // $Id$
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
- require_once('../../config.php');
- require_once('lib.php');
-
- $id = optional_param('id', 0, PARAM_INT); // course module id
- $d = optional_param('d', 0, PARAM_INT); // database id
- $mode = optional_param('mode', 'singletemplate', PARAM_ALPHA);
-
- if ($id) {
- if (! $cm = get_coursemodule_from_id('data', $id)) {
- print_error('invalidcoursemodule');
- }
- if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
- print_error('coursemisconf');
- }
- if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
- print_error('invalidcoursemodule');
- }
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is part of the Database module for Moodle
+ *
+ * @copyright 2005 Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod-data
+ */
+
+require_once('../../config.php');
+require_once('lib.php');
+
+$id = optional_param('id', 0, PARAM_INT); // course module id
+$d = optional_param('d', 0, PARAM_INT); // database id
+$mode = optional_param('mode', 'singletemplate', PARAM_ALPHA);
+
+$url = new moodle_url($CFG->wwwroot.'/mod/data/templates.php');
+if ($mode !== 'singletemplate') {
+ $url->param('mode', $mode);
+}
+
+if ($id) {
+ $url->param('id', $id);
+ $PAGE->set_url($url);
+ if (! $cm = get_coursemodule_from_id('data', $id)) {
+ print_error('invalidcoursemodule');
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
+ print_error('coursemisconf');
+ }
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
+ print_error('invalidcoursemodule');
+ }
- } else {
- if (! $data = $DB->get_record('data', array('id'=>$d))) {
- print_error('invalidid', 'data');
- }
- if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
- print_error('coursemisconf');
- }
- if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
- print_error('invalidcoursemodule');
- }
+} else {
+ $url->param('d', $d);
+ $PAGE->set_url($url);
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
+ print_error('invalidid', 'data');
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
+ print_error('coursemisconf');
+ }
+ if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
+ print_error('invalidcoursemodule');
}
+}
- require_login($course->id, false, $cm);
+require_login($course->id, false, $cm);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- require_capability('mod/data:managetemplates', $context);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_capability('mod/data:managetemplates', $context);
- if (!$DB->count_records('data_fields', array('dataid'=>$data->id))) { // Brand new database!
- redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
- }
+if (!$DB->count_records('data_fields', array('dataid'=>$data->id))) { // Brand new database!
+ redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
+}
- add_to_log($course->id, 'data', 'templates view', "templates.php?id=$cm->id&d=$data->id", $data->id, $cm->id);
+add_to_log($course->id, 'data', 'templates view', "templates.php?id=$cm->id&d=$data->id", $data->id, $cm->id);
/// Print the page header
- $strdata = get_string('modulenameplural','data');
+$strdata = get_string('modulenameplural','data');
- // For the javascript for inserting template tags: initialise the default textarea to
- // 'edit_template' - it is always present in all different possible views.
+// For the javascript for inserting template tags: initialise the default textarea to
+// 'edit_template' - it is always present in all different possible views.
- $editorobj = 'editor_'.md5('template');
+$editorobj = 'editor_'.md5('template');
- $bodytag = 'onload="';
- $bodytag .= 'if (typeof('.$editorobj.') != \'undefined\') { currEditor = '.$editorobj.'; } ';
- $bodytag .= 'currTextarea = document.getElementById(\'tempform\').template;';
- $bodytag .= '" ';
+$bodytag = 'onload="';
+$bodytag .= 'if (typeof('.$editorobj.') != \'undefined\') { currEditor = '.$editorobj.'; } ';
+$bodytag .= 'currTextarea = document.getElementById(\'tempform\').template;';
+$bodytag .= '" ';
- $PAGE->navbar->add(get_string($mode,'data'));
- $PAGE->requires->js('mod/data/data.js');
- $PAGE->set_title($data->name);
- $PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'data')));
- echo $OUTPUT->header();
- echo $OUTPUT->heading(format_string($data->name));
+$PAGE->navbar->add(get_string($mode,'data'));
+$PAGE->requires->js('mod/data/data.js');
+$PAGE->set_title($data->name);
+$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'data'));
+echo $OUTPUT->header();
+echo $OUTPUT->heading(format_string($data->name));
/// Groups needed for Add entry tab
- $currentgroup = groups_get_activity_group($cm);
- $groupmode = groups_get_activity_groupmode($cm);
+$currentgroup = groups_get_activity_group($cm);
+$groupmode = groups_get_activity_groupmode($cm);
/// Print the tabs.
- $currenttab = 'templates';
- include('tabs.php');
+$currenttab = 'templates';
+include('tabs.php');
/// Processing submitted data, i.e updating form.
- $resettemplate = false;
-
- if (($mytemplate = data_submitted()) && confirm_sesskey()) {
- $newtemplate->id = $data->id;
- $newtemplate->{$mode} = $mytemplate->template;
-
- if (!empty($mytemplate->defaultform)) {
- // Reset the template to default, but don't save yet.
- $resettemplate = true;
- $data->{$mode} = data_generate_default_template($data, $mode, 0, false, false);
- if ($mode == 'listtemplate') {
- $data->listtemplateheader = '';
- $data->listtemplatefooter = '';
- }
- } else {
- if (isset($mytemplate->listtemplateheader)){
- $newtemplate->listtemplateheader = $mytemplate->listtemplateheader;
- }
- if (isset($mytemplate->listtemplatefooter)){
- $newtemplate->listtemplatefooter = $mytemplate->listtemplatefooter;
- }
- if (isset($mytemplate->rsstitletemplate)){
- $newtemplate->rsstitletemplate = $mytemplate->rsstitletemplate;
- }
+$resettemplate = false;
+
+if (($mytemplate = data_submitted()) && confirm_sesskey()) {
+ $newtemplate->id = $data->id;
+ $newtemplate->{$mode} = $mytemplate->template;
+
+ if (!empty($mytemplate->defaultform)) {
+ // Reset the template to default, but don't save yet.
+ $resettemplate = true;
+ $data->{$mode} = data_generate_default_template($data, $mode, 0, false, false);
+ if ($mode == 'listtemplate') {
+ $data->listtemplateheader = '';
+ $data->listtemplatefooter = '';
+ }
+ } else {
+ if (isset($mytemplate->listtemplateheader)){
+ $newtemplate->listtemplateheader = $mytemplate->listtemplateheader;
+ }
+ if (isset($mytemplate->listtemplatefooter)){
+ $newtemplate->listtemplatefooter = $mytemplate->listtemplatefooter;
+ }
+ if (isset($mytemplate->rsstitletemplate)){
+ $newtemplate->rsstitletemplate = $mytemplate->rsstitletemplate;
+ }
- // Check for multiple tags, only need to check for add template.
- if ($mode != 'addtemplate' or data_tags_check($data->id, $newtemplate->{$mode})) {
- if ($DB->update_record('data', $newtemplate)) {
- echo $OUTPUT->notification(get_string('templatesaved', 'data'), 'notifysuccess');
- }
+ // Check for multiple tags, only need to check for add template.
+ if ($mode != 'addtemplate' or data_tags_check($data->id, $newtemplate->{$mode})) {
+ if ($DB->update_record('data', $newtemplate)) {
+ echo $OUTPUT->notification(get_string('templatesaved', 'data'), 'notifysuccess');
}
- add_to_log($course->id, 'data', 'templates saved', "templates.php?id=$cm->id&d=$data->id", $data->id, $cm->id);
}
- } else {
- echo '<div class="littleintro" style="text-align:center">'.get_string('header'.$mode,'data').'</div>';
+ add_to_log($course->id, 'data', 'templates saved', "templates.php?id=$cm->id&d=$data->id", $data->id, $cm->id);
}
+} else {
+ echo '<div class="littleintro" style="text-align:center">'.get_string('header'.$mode,'data').'</div>';
+}
/// If everything is empty then generate some defaults
- if (empty($data->addtemplate) and empty($data->singletemplate) and
- empty($data->listtemplate) and empty($data->rsstemplate)) {
- data_generate_default_template($data, 'singletemplate');
- data_generate_default_template($data, 'listtemplate');
- data_generate_default_template($data, 'addtemplate');
- data_generate_default_template($data, 'asearchtemplate'); //Template for advanced searches.
- data_generate_default_template($data, 'rsstemplate');
- }
-
-
- echo '<form id="tempform" action="templates.php?d='.$data->id.'&mode='.$mode.'" method="post">';
- echo '<div>';
- echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
- // Print button to autogen all forms, if all templates are empty
-
- if (!$resettemplate) {
- // Only reload if we are not resetting the template to default.
- $data = $DB->get_record('data', array('id'=>$d));
- }
- echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
- echo '<table cellpadding="4" cellspacing="0" border="0">';
+if (empty($data->addtemplate) and empty($data->singletemplate) and
+ empty($data->listtemplate) and empty($data->rsstemplate)) {
+ data_generate_default_template($data, 'singletemplate');
+ data_generate_default_template($data, 'listtemplate');
+ data_generate_default_template($data, 'addtemplate');
+ data_generate_default_template($data, 'asearchtemplate'); //Template for advanced searches.
+ data_generate_default_template($data, 'rsstemplate');
+}
+
+
+echo '<form id="tempform" action="templates.php?d='.$data->id.'&mode='.$mode.'" method="post">';
+echo '<div>';
+echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
+// Print button to autogen all forms, if all templates are empty
+
+if (!$resettemplate) {
+ // Only reload if we are not resetting the template to default.
+ $data = $DB->get_record('data', array('id'=>$d));
+}
+echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
+echo '<table cellpadding="4" cellspacing="0" border="0">';
/// Add the HTML editor(s).
- $usehtmleditor = can_use_html_editor() && ($mode != 'csstemplate') && ($mode != 'jstemplate');
- if ($mode == 'listtemplate'){
- // Print the list template header.
- echo '<tr>';
- echo '<td> </td>';
- echo '<td>';
- echo '<div style="text-align:center"><label for="edit-listtemplateheader">'.get_string('header','data').'</label></div>';
- print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplateheader', $data->listtemplateheader);
- echo '</td>';
- echo '</tr>';
- }
+$usehtmleditor = can_use_html_editor() && ($mode != 'csstemplate') && ($mode != 'jstemplate');
+if ($mode == 'listtemplate'){
+ // Print the list template header.
+ echo '<tr>';
+ echo '<td> </td>';
+ echo '<td>';
+ echo '<div style="text-align:center"><label for="edit-listtemplateheader">'.get_string('header','data').'</label></div>';
+ print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplateheader', $data->listtemplateheader);
+ echo '</td>';
+ echo '</tr>';
+}
+
+// Print the main template.
- // Print the main template.
+echo '<tr><td valign="top">';
+if ($mode != 'csstemplate' and $mode != 'jstemplate') {
+ // Add all the available fields for this data.
+ echo '<label for="availabletags">'.get_string('availabletags','data').'</label>';
+ echo $OUTPUT->help_icon(moodle_help_icon::make('tags', get_string('tags'), 'data'));
+ echo '<br />';
- echo '<tr><td valign="top">';
- if ($mode != 'csstemplate' and $mode != 'jstemplate') {
- // Add all the available fields for this data.
- echo '<label for="availabletags">'.get_string('availabletags','data').'</label>';
- echo $OUTPUT->help_icon(moodle_help_icon::make('tags', get_string('tags'), 'data'));
- echo '<br />';
+ echo '<select name="fields1[]" id="availabletags" size="12" onclick="insert_field_tags(this)">';
- echo '<select name="fields1[]" id="availabletags" size="12" onclick="insert_field_tags(this)">';
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id));
+ echo '<optgroup label="'.get_string('fields', 'data').'">';
+ foreach ($fields as $field) {
+ echo '<option value="[['.$field->name.']]" title="'.$field->description.'">'.$field->name.' - [['.$field->name.']]</option>';
+ }
+ echo '</optgroup>';
- $fields = $DB->get_records('data_fields', array('dataid'=>$data->id));
- echo '<optgroup label="'.get_string('fields', 'data').'">';
+ if ($mode == 'addtemplate') {
+ echo '<optgroup label="'.get_string('fieldids', 'data').'">';
foreach ($fields as $field) {
- echo '<option value="[['.$field->name.']]" title="'.$field->description.'">'.$field->name.' - [['.$field->name.']]</option>';
+ if (in_array($field->type, array('picture', 'checkbox', 'date', 'latlong', 'radiobutton'))) {
+ continue; //ids are not usable for these composed items
+ }
+ echo '<option value="[['.$field->name.'#id]]" title="'.$field->description.' id">'.$field->name.' id - [['.$field->name.'#id]]</option>';
}
echo '</optgroup>';
+ }
- if ($mode == 'addtemplate') {
- echo '<optgroup label="'.get_string('fieldids', 'data').'">';
- foreach ($fields as $field) {
- if (in_array($field->type, array('picture', 'checkbox', 'date', 'latlong', 'radiobutton'))) {
- continue; //ids are not usable for these composed items
- }
- echo '<option value="[['.$field->name.'#id]]" title="'.$field->description.' id">'.$field->name.' id - [['.$field->name.'#id]]</option>';
- }
- echo '</optgroup>';
+ // Print special tags. fix for MDL-7031
+ if ($mode != 'addtemplate' && $mode != 'asearchtemplate') { //Don't print special tags when viewing the advanced search template and add template.
+ echo '<optgroup label="'.get_string('buttons', 'data').'">';
+ echo '<option value="##edit##">' .get_string('edit', 'data'). ' - ##edit##</option>';
+ echo '<option value="##delete##">' .get_string('delete', 'data'). ' - ##delete##</option>';
+ echo '<option value="##approve##">' .get_string('approve', 'data'). ' - ##approve##</option>';
+ if ($mode != 'rsstemplate') {
+ echo '<option value="##export##">' .get_string('export', 'data'). ' - ##export##</option>';
}
-
- // Print special tags. fix for MDL-7031
- if ($mode != 'addtemplate' && $mode != 'asearchtemplate') { //Don't print special tags when viewing the advanced search template and add template.
- echo '<optgroup label="'.get_string('buttons', 'data').'">';
- echo '<option value="##edit##">' .get_string('edit', 'data'). ' - ##edit##</option>';
- echo '<option value="##delete##">' .get_string('delete', 'data'). ' - ##delete##</option>';
- echo '<option value="##approve##">' .get_string('approve', 'data'). ' - ##approve##</option>';
- if ($mode != 'rsstemplate') {
- echo '<option value="##export##">' .get_string('export', 'data'). ' - ##export##</option>';
- }
- if ($mode != 'singletemplate') {
- // more points to single template - not useable there
- echo '<option value="##more##">' .get_string('more', 'data'). ' - ##more##</option>';
- echo '<option value="##moreurl##">' .get_string('moreurl', 'data'). ' - ##moreurl##</option>';
- }
- echo '</optgroup>';
- echo '<optgroup label="'.get_string('other', 'data').'">';
- echo '<option value="##timeadded##">'.get_string('timeadded', 'data'). ' - ##timeadded##</option>';
- echo '<option value="##timemodified##">'.get_string('timemodified', 'data'). ' - ##timemodified##</option>';
- echo '<option value="##user##">' .get_string('user'). ' - ##user##</option>';
- if ($mode != 'singletemplate') {
- // more points to single template - not useable there
- echo '<option value="##comments##">' .get_string('comments', 'data'). ' - ##comments##</option>';
- }
- echo '</optgroup>';
+ if ($mode != 'singletemplate') {
+ // more points to single template - not useable there
+ echo '<option value="##more##">' .get_string('more', 'data'). ' - ##more##</option>';
+ echo '<option value="##moreurl##">' .get_string('moreurl', 'data'). ' - ##moreurl##</option>';
}
-
- if ($mode == 'asearchtemplate') {
- echo '<optgroup label="'.get_string('other', 'data').'">';
- echo '<option value="##firstname##">' .get_string('authorfirstname', 'data'). ' - ##firstname##</option>';
- echo '<option value="##lastname##">' .get_string('authorlastname', 'data'). ' - ##lastname##</option>';
- echo '</optgroup>';
+ echo '</optgroup>';
+ echo '<optgroup label="'.get_string('other', 'data').'">';
+ echo '<option value="##timeadded##">'.get_string('timeadded', 'data'). ' - ##timeadded##</option>';
+ echo '<option value="##timemodified##">'.get_string('timemodified', 'data'). ' - ##timemodified##</option>';
+ echo '<option value="##user##">' .get_string('user'). ' - ##user##</option>';
+ if ($mode != 'singletemplate') {
+ // more points to single template - not useable there
+ echo '<option value="##comments##">' .get_string('comments', 'data'). ' - ##comments##</option>';
}
+ echo '</optgroup>';
+ }
- echo '</select>';
- echo '<br /><br /><br /><br /><input type="submit" name="defaultform" value="'.get_string('resettemplate','data').'" />';
- if (can_use_html_editor()) {
- echo '<br /><br />';
- if ($usehtmleditor) {
- $switcheditor = get_string('editordisable', 'data');
- } else {
- $switcheditor = get_string('editorenable', 'data');
- }
- echo '<input type="submit" name="switcheditor" value="'.s($switcheditor).'" />';
+ if ($mode == 'asearchtemplate') {
+ echo '<optgroup label="'.get_string('other', 'data').'">';
+ echo '<option value="##firstname##">' .get_string('authorfirstname', 'data'). ' - ##firstname##</option>';
+ echo '<option value="##lastname##">' .get_string('authorlastname', 'data'). ' - ##lastname##</option>';
+ echo '</optgroup>';
+ }
+
+ echo '</select>';
+ echo '<br /><br /><br /><br /><input type="submit" name="defaultform" value="'.get_string('resettemplate','data').'" />';
+ if (can_use_html_editor()) {
+ echo '<br /><br />';
+ if ($usehtmleditor) {
+ $switcheditor = get_string('editordisable', 'data');
+ } else {
+ $switcheditor = get_string('editorenable', 'data');
}
- } else {
- echo '<br /><br /><br /><br /><input type="submit" name="defaultform" value="'.get_string('resettemplate','data').'" />';
+ echo '<input type="submit" name="switcheditor" value="'.s($switcheditor).'" />';
}
+} else {
+ echo '<br /><br /><br /><br /><input type="submit" name="defaultform" value="'.get_string('resettemplate','data').'" />';
+}
+echo '</td>';
+
+echo '<td>';
+if ($mode == 'listtemplate'){
+ echo '<div style="text-align:center"><label for="edit-template">'.get_string('multientry','data').'</label></div>';
+} else {
+ echo '<div style="text-align:center"><label for="edit-template">'.get_string($mode,'data').'</label></div>';
+}
+
+print_textarea($usehtmleditor, 20, 72, 0, 0, 'template', $data->{$mode});
+echo '</td>';
+echo '</tr>';
+
+if ($mode == 'listtemplate'){
+ echo '<tr>';
+ echo '<td> </td>';
+ echo '<td>';
+ echo '<div style="text-align:center"><label for="edit-listtemplatefooter">'.get_string('footer','data').'</label></div>';
+ print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplatefooter', $data->listtemplatefooter);
echo '</td>';
-
+ echo '</tr>';
+} else if ($mode == 'rsstemplate') {
+ echo '<tr>';
+ echo '<td> </td>';
echo '<td>';
- if ($mode == 'listtemplate'){
- echo '<div style="text-align:center"><label for="edit-template">'.get_string('multientry','data').'</label></div>';
- } else {
- echo '<div style="text-align:center"><label for="edit-template">'.get_string($mode,'data').'</label></div>';
- }
-
- print_textarea($usehtmleditor, 20, 72, 0, 0, 'template', $data->{$mode});
+ echo '<div style="text-align:center"><label for="edit-rsstitletemplate">'.get_string('rsstitletemplate','data').'</label></div>';
+ print_textarea($usehtmleditor, 10, 72, 0, 0, 'rsstitletemplate', $data->rsstitletemplate);
echo '</td>';
echo '</tr>';
+}
- if ($mode == 'listtemplate'){
- echo '<tr>';
- echo '<td> </td>';
- echo '<td>';
- echo '<div style="text-align:center"><label for="edit-listtemplatefooter">'.get_string('footer','data').'</label></div>';
- print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplatefooter', $data->listtemplatefooter);
- echo '</td>';
- echo '</tr>';
- } else if ($mode == 'rsstemplate') {
- echo '<tr>';
- echo '<td> </td>';
- echo '<td>';
- echo '<div style="text-align:center"><label for="edit-rsstitletemplate">'.get_string('rsstitletemplate','data').'</label></div>';
- print_textarea($usehtmleditor, 10, 72, 0, 0, 'rsstitletemplate', $data->rsstitletemplate);
- echo '</td>';
- echo '</tr>';
- }
-
- echo '<tr><td style="text-align:center" colspan="2">';
- echo '<input type="submit" value="'.get_string('savetemplate','data').'" /> ';
+echo '<tr><td style="text-align:center" colspan="2">';
+echo '<input type="submit" value="'.get_string('savetemplate','data').'" /> ';
- echo '</td></tr></table>';
+echo '</td></tr></table>';
- echo $OUTPUT->box_end();
- echo '</div>';
- echo '</form>';
+echo $OUTPUT->box_end();
+echo '</div>';
+echo '</form>';
/// Finish the page
- echo $OUTPUT->footer();
-?>
+echo $OUTPUT->footer();
+?>
\ No newline at end of file