libdir.'/blocklib.php'); require_login(); $id = optional_param('id', 0, PARAM_INT); // course module id $d = optional_param('d', 0, PARAM_INT); // database id $mode = optional_param('mode', '', PARAM_ALPHA); if ($id) { if (! $cm = get_record('course_modules', 'id', $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'); } } if (!isteacheredit($course->id)){ error(get_string('noaccess','data')); } if (isteacher($course->id)) { if (!count_records('data_fields','dataid',$data->id)) { // Brand new database! redirect($CFG->wwwroot.'/mod/data/fields.php?d='.$data->id); // Redirect to field entry } } add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id); /// Print the page header $strdata = get_string('modulenameplural','data'); print_header_simple($data->name, "", "$strdata -> $data->name", "", "", true, "", navmenu($course)); print_heading(format_string($data->name)); ///processing submitted data, i.e updating form if (($mytemplate = data_submitted($CFG->wwwroot.'/mod/data/templates.php')) && confirm_sesskey()){ //generate default template if (!empty($mytemplate->defaultform)){ data_generate_default_form($data->id, $mode); } else if (!empty($mytemplate->allforms)){ //generate all default templates data_generate_default_form($data->id, 'singletemplate'); data_generate_default_form($data->id, 'listtemplate'); data_generate_default_form($data->id, 'addtemplate'); data_generate_default_form($data->id, 'rsstemplate'); } else { $newtemplate->id = $data->id; $newtemplate->{$mode} = $mytemplate->template; if (isset($mytemplate->listtemplateheader)){ $newtemplate->listtemplateheader = $mytemplate->listtemplateheader; } if (isset($mytemplate->listtemplatefooter)){ $newtemplate->listtemplatefooter = $mytemplate->listtemplatefooter; } //check for multiple tags, only need to check for add template if ($mode != 'addtemplate' or data_tags_check($data->id, $newtemplate->{$mode})){ update_record('data',$newtemplate); } } } /// Print the tabs $currenttab = 'templates'; include('tabs.php'); /// Print the browsing interface echo '
'.get_string('header'.$mode,'data').'

'; echo '
'; echo ''; //print button to autogen all forms, if all templates are empty $data = get_record('data', 'id', $d); //reload because of possible updates so far! if (empty($data->addtemplate) and empty($data->singletemplate) and empty($data->listtemplate) and empty($data->rsstemplate)){ echo '
'; } print_simple_box_start('center','80%'); echo ''; echo '
'; ///add all the available fields for this data echo get_string('availabletags','data'); helpbutton('tags', get_string('tags','data'), 'data'); echo '
'; echo ''; ///add the HTML editor(s) echo ''; $usehtmleditor = can_use_html_editor(); if ($mode == 'listtemplate'){ echo '
'.get_string('header','data').'
'; print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplateheader', $data->listtemplateheader); } if ($mode == 'listtemplate'){ echo '
'.get_string('multientry','data').'
'; } print_textarea($usehtmleditor, 20, 72, 0, 0, 'template', $data->{$mode}); if ($mode == 'listtemplate'){ echo '
'.get_string('footer','data').'
'; print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplatefooter', $data->listtemplatefooter); } echo '
'; echo ' '; if (!$data->{$mode}){ echo ''; } echo '
'; print_simple_box_end(); echo '
'; if ($usehtmleditor) { use_html_editor('template'); if ($mode == 'listtemplate'){ use_html_editor('listtemplateheader'); use_html_editor('listtemplatefooter'); } } /// Finish the page print_footer($course); ?>