MDL-29190 - XHTML not well formed in show_nonrespondents.php
[moodle.git] / mod / feedback / delete_template.php
CommitLineData
84973212 1<?php
2
c70ad9f7 3/**
4* deletes a template
5*
c70ad9f7 6* @author Andreas Grabs
7* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8* @package feedback
9*/
10
84973212 11require_once("../../config.php");
12require_once("lib.php");
13require_once('delete_template_form.php');
14
15// $SESSION->feedback->current_tab = 'templates';
16$current_tab = 'templates';
17
18$id = required_param('id', PARAM_INT);
19$canceldelete = optional_param('canceldelete', false, PARAM_INT);
20$shoulddelete = optional_param('shoulddelete', false, PARAM_INT);
21$deletetempl = optional_param('deletetempl', false, PARAM_INT);
22// $formdata = data_submitted();
23
a6855934 24$url = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
84973212 25if ($canceldelete !== false) {
26 $url->param('canceldelete', $canceldelete);
27}
28if ($shoulddelete !== false) {
29 $url->param('shoulddelete', $shoulddelete);
30}
31if ($deletetempl !== false) {
32 $url->param('deletetempl', $deletetempl);
33}
34$PAGE->set_url($url);
35
36if(($formdata = data_submitted()) AND !confirm_sesskey()) {
37 print_error('invalidsesskey');
38}
39
40if($canceldelete == 1){
5dee2210
AG
41 $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>'templates'));
42 redirect($editurl->out(false));
84973212 43}
44
b6f26001
AG
45if (! $cm = get_coursemodule_from_id('feedback', $id)) {
46 print_error('invalidcoursemodule');
47}
d4b1d58c 48
b6f26001
AG
49if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
50 print_error('coursemisconf');
51}
d4b1d58c 52
b6f26001
AG
53if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
54 print_error('invalidcoursemodule');
84973212 55}
c987dbad
AG
56
57if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
58 print_error('badcontext');
59}
84973212 60
61require_login($course->id, true, $cm);
62
53ba55ec 63require_capability('mod/feedback:deletetemplate', $context);
84973212 64
65$mform = new mod_feedback_delete_template_form();
66$newformdata = array('id'=>$id,
67 'deletetempl'=>$deletetempl,
68 'confirmdelete'=>'1');
69
70$mform->set_data($newformdata);
71$formdata = $mform->get_data();
72
5dee2210
AG
73$deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
74
84973212 75if ($mform->is_cancelled()) {
5dee2210 76 redirect($deleteurl->out(false));
84973212 77}
78
79if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
80 feedback_delete_template($formdata->deletetempl);
5dee2210 81 redirect($deleteurl->out(false));
84973212 82}
83
84/// Print the page header
85$strfeedbacks = get_string("modulenameplural", "feedback");
86$strfeedback = get_string("modulename", "feedback");
87
9d092aa9 88$PAGE->set_heading(format_string($course->fullname));
84973212 89$PAGE->set_title(format_string($feedback->name));
84973212 90echo $OUTPUT->header();
91
92/// print the tabs
93include('tabs.php');
94
95/// Print the main part of the page
96///////////////////////////////////////////////////////////////////////////
97///////////////////////////////////////////////////////////////////////////
98///////////////////////////////////////////////////////////////////////////
99echo $OUTPUT->heading(get_string('delete_template','feedback'));
100if($shoulddelete == 1) {
101
102 echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
103 echo $OUTPUT->heading(get_string('confirmdeletetemplate', 'feedback'));
104 $mform->display();
105 echo $OUTPUT->box_end();
106}else {
107 $templates = feedback_get_template_list($course, true);
108 echo '<div class="mdl-align">';
109 if(!is_array($templates)) {
110 echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter');
c70ad9f7 111 }else {
84973212 112 echo '<table width="30%">';
113 echo '<tr><th>'.get_string('templates', 'feedback').'</th><th>&nbsp;</th></tr>';
114 foreach($templates as $template) {
115 echo '<tr><td align="center">'.$template->name.'</td>';
116 echo '<td align="center">';
a6855934 117 echo '<form action="delete_template.php" method="post">';
b5d0cafc 118 echo '<input title="'.get_string('delete_template','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/delete') . '" hspace="1" height="11" width="11" border="0" />';
84973212 119 echo '<input type="hidden" name="deletetempl" value="'.$template->id.'" />';
120 echo '<input type="hidden" name="shoulddelete" value="1" />';
121 echo '<input type="hidden" name="id" value="'.$id.'" />';
122 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
123 echo '</form>';
124 echo '</td></tr>';
c70ad9f7 125 }
84973212 126 echo '</table>';
127 }
c70ad9f7 128?>
a6855934 129 <form name="frm" action="delete_template.php" method="post">
973d2660 130 <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
c70ad9f7 131 <input type="hidden" name="id" value="<?php echo $id;?>" />
132 <input type="hidden" name="canceldelete" value="0" />
133 <button type="button" onclick="this.form.canceldelete.value=1;this.form.submit();"><?php print_string('cancel');?></button>
134 </form>
135 </div>
136<?php
84973212 137}
c70ad9f7 138
84973212 139echo $OUTPUT->footer();
c70ad9f7 140