. /** * 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); $disableeditor = optional_param('switcheditor', false, PARAM_RAW); $enableeditor = optional_param('useeditor', false, PARAM_RAW); $url = new moodle_url('/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 { $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); $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 } 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'); // For the javascript for inserting template tags: initialise the default textarea to // 'edit_template' - it is always present in all different possible views. if ($mode == 'singletemplate') { $PAGE->navbar->add(get_string($mode,'data')); } $PAGE->requires->js('/mod/data/data.js'); $PAGE->set_title($data->name); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('report'); 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); /// Print the tabs. $currenttab = 'templates'; include('tabs.php'); /// Processing submitted data, i.e updating form. $resettemplate = false; if (($mytemplate = data_submitted()) && confirm_sesskey()) { $newtemplate = new stdClass(); $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 disableeditor or enableeditor buttons click, don't save instance if (empty($disableeditor) && empty($enableeditor)) { $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 '
'.get_string('header'.$mode,'data').'
'; } /// 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'); } editors_head_setup(); $format = FORMAT_HTML; if ($mode === 'csstemplate' or $mode === 'jstemplate') { $disableeditor = true; } if ($disableeditor) { $format = FORMAT_PLAIN; } $editor = editors_get_preferred_editor($format); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } $options = array(); $options['trusttext'] = false; $options['forcehttps'] = false; $options['subdirs'] = false; $options['maxfiles'] = 0; $options['maxbytes'] = 0; $options['changeformat'] = 0; $options['noclean'] = false; echo '
'; echo '
'; echo ''; // 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 ''; /// Add the HTML editor(s). $usehtmleditor = can_use_html_editor() && ($mode != 'csstemplate') && ($mode != 'jstemplate') && !$disableeditor; if ($mode == 'listtemplate'){ // Print the list template header. echo ''; echo ''; echo ''; echo ''; } // Print the main template. echo ''; echo ''; echo ''; if ($mode == 'listtemplate'){ echo ''; echo ''; echo ''; echo ''; } else if ($mode == 'rsstemplate') { echo ''; echo ''; echo ''; echo ''; } echo '
 '; echo '
'; $field = 'listtemplateheader'; $editor->use_editor($field, $options); echo '
'; echo '
'; if ($mode != 'csstemplate' and $mode != 'jstemplate') { // Add all the available fields for this data. echo ''; echo $OUTPUT->help_icon('availabletags', 'data'); echo '
'; echo ''; echo '



'; if (can_use_html_editor()) { echo '

'; if ($usehtmleditor) { $switcheditor = get_string('editordisable', 'data'); echo ''; } else { $switcheditor = get_string('editorenable', 'data'); echo ''; } } } else { echo '



'; } echo '
'; if ($mode == 'listtemplate'){ echo '
'; } else { echo '
'; } $field = 'template'; $editor->use_editor($field, $options); echo '
'; echo '
 '; echo '
'; $field = 'listtemplatefooter'; $editor->use_editor($field, $options); echo '
'; echo '
 '; echo '
'; $field = 'rsstitletemplate'; $editor->use_editor($field, $options); echo '
'; echo '
'; echo ' '; echo '
'; echo $OUTPUT->box_end(); echo '
'; echo '
'; /// Finish the page echo $OUTPUT->footer();