libdir.'/blocklib.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)) { error('Course Module ID was incorrect'); } if (! $course = get_record('course', 'id', $cm->course)) { error('Course is misconfigured'); } if (! $data = get_record('data', 'id', $cm->instance)) { error('Course module is incorrect'); } } else { if (! $data = get_record('data', 'id', $d)) { error('Data ID is incorrect'); } if (! $course = get_record('course', 'id', $data->course)) { error('Course is misconfigured'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { error('Course Module ID was incorrect'); } } require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/data:managetemplates', $context); if (!count_records('data_fields','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. $editorobj = 'editor_'.md5('template'); $bodytag = 'onload="'; $bodytag .= 'if (typeof('.$editorobj.') != \'undefined\') { currEditor = '.$editorobj.'; } '; $bodytag .= 'currTextarea = document.getElementById(\'tempform\').template;'; $bodytag .= '" '; // Javascript to insert the field tags into the textarea. $meta = ''."\n"; $navigation = build_navigation('', $cm); print_header_simple($data->name, '', $navigation, '', $meta, true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')), navmenu($course, $cm), '', $bodytag); print_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; /// html editor is by default disabled $editor = isset($SESSION->data_use_editor) ? $SESSION->data_use_editor : (can_use_html_editor() ? 1 : 0); if (($mytemplate = data_submitted($CFG->wwwroot.'/mod/data/templates.php')) && confirm_sesskey()) { $newtemplate->id = $data->id; $newtemplate->{$mode} = $mytemplate->template; if (!empty($mytemplate->switcheditor)) { $editor = $editor ? 0 : 1; $SESSION->data_use_editor = $editor; } else 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 (update_record('data', $newtemplate)) { notify(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'); } 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 = get_record('data', 'id', $d); } print_simple_box_start('center','80%'); echo ''; /// Add the HTML editor(s). $usehtmleditor = $editor && can_use_html_editor() && ($mode != 'csstemplate') && ($mode != 'jstemplate'); 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 '
'; print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplateheader', $data->listtemplateheader); echo '
'; if ($mode != 'csstemplate' and $mode != 'jstemplate') { // Add all the available fields for this data. echo ''; helpbutton('tags', get_string('tags'), 'data'); echo '
'; echo ''; echo '



'; if (can_use_html_editor()) { echo '

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



'; } echo '
'; if ($mode == 'listtemplate'){ echo '
'; } else { echo '
'; } print_textarea($usehtmleditor, 20, 72, 0, 0, 'template', $data->{$mode}); echo '
 '; echo '
'; print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplatefooter', $data->listtemplatefooter); echo '
 '; echo '
'; print_textarea($usehtmleditor, 10, 72, 0, 0, 'rsstitletemplate', $data->rsstitletemplate); echo '
'; echo ' '; echo '
'; print_simple_box_end(); echo '
'; echo '
'; if ($usehtmleditor) { use_html_editor('template'); if ($mode == 'listtemplate'){ use_html_editor('listtemplateheader'); use_html_editor('listtemplatefooter'); } else if ($mode == 'rsstemplate'){ use_html_editor('rsstitletemplate'); } } /// Finish the page print_footer($course); ?>