MDL-29190 - XHTML not well formed in show_nonrespondents.php
[moodle.git] / mod / feedback / delete_template.php
1 <?php
3 /**
4 * deletes a template
5 *
6 * @author Andreas Grabs
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package feedback
9 */
11 require_once("../../config.php");
12 require_once("lib.php");
13 require_once('delete_template_form.php');
15 // $SESSION->feedback->current_tab = 'templates';
16 $current_tab = 'templates';
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();
24 $url = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
25 if ($canceldelete !== false) {
26     $url->param('canceldelete', $canceldelete);
27 }
28 if ($shoulddelete !== false) {
29     $url->param('shoulddelete', $shoulddelete);
30 }
31 if ($deletetempl !== false) {
32     $url->param('deletetempl', $deletetempl);
33 }
34 $PAGE->set_url($url);
36 if(($formdata = data_submitted()) AND !confirm_sesskey()) {
37     print_error('invalidsesskey');
38 }
40 if($canceldelete == 1){
41     $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>'templates'));
42     redirect($editurl->out(false));
43 }
45 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
46     print_error('invalidcoursemodule');
47 }
49 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
50     print_error('coursemisconf');
51 }
53 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
54     print_error('invalidcoursemodule');
55 }
57 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
58         print_error('badcontext');
59 }
61 require_login($course->id, true, $cm);
63 require_capability('mod/feedback:deletetemplate', $context);
65 $mform = new mod_feedback_delete_template_form();
66 $newformdata = array('id'=>$id,
67                     'deletetempl'=>$deletetempl,
68                     'confirmdelete'=>'1');
70 $mform->set_data($newformdata);
71 $formdata = $mform->get_data();
73 $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
75 if ($mform->is_cancelled()) {
76     redirect($deleteurl->out(false));
77 }
79 if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
80     feedback_delete_template($formdata->deletetempl);
81     redirect($deleteurl->out(false));
82 }
84 /// Print the page header
85 $strfeedbacks = get_string("modulenameplural", "feedback");
86 $strfeedback  = get_string("modulename", "feedback");
88 $PAGE->set_heading(format_string($course->fullname));
89 $PAGE->set_title(format_string($feedback->name));
90 echo $OUTPUT->header();
92 /// print the tabs
93 include('tabs.php');
95 /// Print the main part of the page
96 ///////////////////////////////////////////////////////////////////////////
97 ///////////////////////////////////////////////////////////////////////////
98 ///////////////////////////////////////////////////////////////////////////
99 echo $OUTPUT->heading(get_string('delete_template','feedback'));
100 if($shoulddelete == 1) {
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');
111     }else {
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">';
117             echo '<form action="delete_template.php" method="post">';
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" />';
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>';
125         }
126         echo '</table>';
127     }
128 ?>
129         <form name="frm" action="delete_template.php" method="post">
130             <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
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
139 echo $OUTPUT->footer();