MDL-14493 First checkin of Feedback module into HEAD.
[moodle.git] / mod / feedback / delete_template.php
1 <?php // $Id$
2 /**
3 * deletes a template
4 *
5 * @version $Id$
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');
14     
15     $SESSION->feedback->current_tab = 'templates';
17     $id = required_param('id', PARAM_INT);
18     $canceldelete = optional_param('canceldelete', false, PARAM_INT);
19     $shoulddelete = optional_param('shoulddelete', false, PARAM_INT);
20     $deletetempl = optional_param('deletetempl', false, PARAM_INT);
21     // $formdata = data_submitted('nomatch');
22     
23     if(($formdata = data_submitted('nomatch')) AND !confirm_sesskey()) {
24         error('no sesskey defined');
25     }
26     
27     if($canceldelete == 1){
28         redirect(htmlspecialchars('edit.php?id='.$id.'&do_show=templates'));
29     }
31     if ($id) {
32         if (! $cm = get_coursemodule_from_id('feedback', $id)) {
33             error("Course Module ID was incorrect");
34         }
35      
36         if (! $course = get_record("course", "id", $cm->course)) {
37             error("Course is misconfigured");
38         }
39      
40         if (! $feedback = get_record("feedback", "id", $cm->instance)) {
41             error("Course module is incorrect");
42         }
43     }
44     $capabilities = feedback_load_capabilities($cm->id);
46     require_login($course->id);
47     
48     if(!$capabilities->deletetemplate){
49         error(get_string('error'));
50     }
51     
52     $mform = new mod_feedback_delete_template_form();
53     $newformdata = array('id'=>$id,
54                         'deletetempl'=>$deletetempl,
55                         'confirmdelete'=>'1');
56     
57     $mform->set_data($newformdata);
58     $formdata = $mform->get_data();
59     
60     if ($mform->is_cancelled()) {
61         redirect(htmlspecialchars('delete_template.php?id='.$id));
62     }
63     
64     if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
65         feedback_delete_template($formdata->deletetempl);
66         redirect(htmlspecialchars('delete_template.php?id=' . $id));
67     }
69     /// Print the page header
70     $strfeedbacks = get_string("modulenameplural", "feedback");
71     $strfeedback  = get_string("modulename", "feedback");
72     $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
73     
74     $navlinks = array();
75     $navlinks[] = array('name' => $strfeedbacks, 'link' => "index.php?id=$course->id", 'type' => 'activity');
76     $navlinks[] = array('name' => format_string($feedback->name), 'link' => "", 'type' => 'activityinstance');
77     
78     $navigation = build_navigation($navlinks);
79     
80     print_header_simple(format_string($feedback->name), "",
81                  $navigation, "", "", true, $buttontext, navmenu($course, $cm));
83     /// Print the main part of the page
84     ///////////////////////////////////////////////////////////////////////////
85     ///////////////////////////////////////////////////////////////////////////
86     ///////////////////////////////////////////////////////////////////////////
87     print_heading(get_string('delete_template','feedback'));
88     if($shoulddelete == 1) {
89     
90         // print_simple_box_start("center", "60%", "#FFAAAA", 20, "noticebox");
91         print_box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
92         print_heading(get_string('confirmdeletetemplate', 'feedback'));
93         $mform->display();
94         // print_simple_box_end();
95         print_box_end();
96     }else {
97         $templates = feedback_get_template_list($course, true);
98         echo '<div align="center">';
99         if(!is_array($templates)) {
100             // print_simple_box(get_string('no_templates_available_yet', 'feedback'), "center");
101             print_box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter');
102         }else {
103             echo '<table width="30%">';
104             echo '<tr><th>'.get_string('templates', 'feedback').'</th><th>&nbsp;</th></tr>';
105             foreach($templates as $template) {
106                 echo '<tr><td align="center">'.$template->name.'</td>';
107                 echo '<td align="center">';
108                 echo '<form action="'.$ME.'" method="post">';
109                 echo '<input title="'.get_string('delete_template','feedback').'" type="image" src="'.$CFG->pixpath .'/t/delete.gif" hspace="1" height="11" width="11" border="0" />';
110                 echo '<input type="hidden" name="deletetempl" value="'.$template->id.'" />';
111                 echo '<input type="hidden" name="shoulddelete" value="1" />';
112                 echo '<input type="hidden" name="id" value="'.$id.'" />';
113                 echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
114                 echo '</form>';
115                 echo '</td></tr>';
116             }
117             echo '</table>';
118         }
119 ?>
120         <form name="frm" action="<?php echo $ME;?>" method="post">
121             <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey;?>" />
122             <input type="hidden" name="id" value="<?php echo $id;?>" />
123             <input type="hidden" name="canceldelete" value="0" />
124             <button type="button" onclick="this.form.canceldelete.value=1;this.form.submit();"><?php print_string('cancel');?></button>
125         </form>
126         </div>
127 <?php
128     }
130     print_footer($course);
132 ?>