Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/delete_template.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00025 require_once("../../config.php");
00026 require_once("lib.php");
00027 require_once('delete_template_form.php');
00028 require_once($CFG->libdir.'/tablelib.php');
00029 
00030 $current_tab = 'templates';
00031 
00032 $id = required_param('id', PARAM_INT);
00033 $canceldelete = optional_param('canceldelete', false, PARAM_INT);
00034 $shoulddelete = optional_param('shoulddelete', false, PARAM_INT);
00035 $deletetempl = optional_param('deletetempl', false, PARAM_INT);
00036 
00037 $url = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
00038 if ($canceldelete !== false) {
00039     $url->param('canceldelete', $canceldelete);
00040 }
00041 if ($shoulddelete !== false) {
00042     $url->param('shoulddelete', $shoulddelete);
00043 }
00044 if ($deletetempl !== false) {
00045     $url->param('deletetempl', $deletetempl);
00046 }
00047 $PAGE->set_url($url);
00048 
00049 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
00050     print_error('invalidsesskey');
00051 }
00052 
00053 if ($canceldelete == 1) {
00054     $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>'templates'));
00055     redirect($editurl->out(false));
00056 }
00057 
00058 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
00059     print_error('invalidcoursemodule');
00060 }
00061 
00062 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00063     print_error('coursemisconf');
00064 }
00065 
00066 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
00067     print_error('invalidcoursemodule');
00068 }
00069 
00070 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
00071         print_error('badcontext');
00072 }
00073 
00074 require_login($course->id, true, $cm);
00075 
00076 require_capability('mod/feedback:deletetemplate', $context);
00077 
00078 $mform = new mod_feedback_delete_template_form();
00079 $newformdata = array('id'=>$id,
00080                     'deletetempl'=>$deletetempl,
00081                     'confirmdelete'=>'1');
00082 
00083 $mform->set_data($newformdata);
00084 $formdata = $mform->get_data();
00085 
00086 $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
00087 
00088 if ($mform->is_cancelled()) {
00089     redirect($deleteurl->out(false));
00090 }
00091 
00092 if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
00093     if (!$template = $DB->get_record("feedback_template", array("id"=>$deletetempl))) {
00094         print_error('error');
00095     }
00096 
00097     if ($template->ispublic) {
00098         $systemcontext = get_system_context();
00099         require_capability('mod/feedback:createpublictemplate', $systemcontext);
00100         require_capability('mod/feedback:deletetemplate', $systemcontext);
00101     }
00102 
00103     feedback_delete_template($template);
00104     redirect($deleteurl->out(false));
00105 }
00106 
00108 $strfeedbacks = get_string("modulenameplural", "feedback");
00109 $strfeedback  = get_string("modulename", "feedback");
00110 $strdeletefeedback = get_string('delete_template', 'feedback');
00111 
00112 $PAGE->set_heading(format_string($course->fullname));
00113 $PAGE->set_title(format_string($feedback->name));
00114 echo $OUTPUT->header();
00115 
00117 require('tabs.php');
00118 
00123 echo $OUTPUT->heading($strdeletefeedback);
00124 if ($shoulddelete == 1) {
00125 
00126     echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
00127     echo $OUTPUT->heading(get_string('confirmdeletetemplate', 'feedback'));
00128     $mform->display();
00129     echo $OUTPUT->box_end();
00130 } else {
00131     //first we get the own templates
00132     $templates = feedback_get_template_list($course, 'own');
00133     if (!is_array($templates)) {
00134         echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
00135                          'generalbox boxaligncenter');
00136     } else {
00137         echo $OUTPUT->heading(get_string('course'), 3);
00138         echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
00139         $tablecolumns = array('template', 'action');
00140         $tableheaders = array(get_string('template', 'feedback'), '');
00141         $tablecourse = new flexible_table('feedback_template_course_table');
00142 
00143         $tablecourse->define_columns($tablecolumns);
00144         $tablecourse->define_headers($tableheaders);
00145         $tablecourse->define_baseurl($deleteurl);
00146         $tablecourse->column_style('action', 'width', '10%');
00147 
00148         $tablecourse->sortable(false);
00149         $tablecourse->set_attribute('width', '100%');
00150         $tablecourse->set_attribute('class', 'generaltable');
00151         $tablecourse->setup();
00152 
00153         foreach ($templates as $template) {
00154             $data = array();
00155             $data[] = $template->name;
00156             $url = new moodle_url($deleteurl, array(
00157                                             'id'=>$id,
00158                                             'deletetempl'=>$template->id,
00159                                             'shoulddelete'=>1,
00160                                             ));
00161 
00162             $data[] = $OUTPUT->single_button($url, $strdeletefeedback, 'post');
00163             $tablecourse->add_data($data);
00164         }
00165         $tablecourse->finish_output();
00166         echo $OUTPUT->box_end();
00167     }
00168     //now we get the public templates if it is permitted
00169     $systemcontext = get_system_context();
00170     if (has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
00171         has_capability('mod/feedback:deletetemplate', $systemcontext)) {
00172         $templates = feedback_get_template_list($course, 'public');
00173         if (!is_array($templates)) {
00174             echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
00175                               'generalbox boxaligncenter');
00176         } else {
00177             echo $OUTPUT->heading(get_string('public', 'feedback'), 3);
00178             echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
00179             $tablecolumns = array('template', 'action');
00180             $tableheaders = array(get_string('template', 'feedback'), '');
00181             $tablepublic = new flexible_table('feedback_template_public_table');
00182 
00183             $tablepublic->define_columns($tablecolumns);
00184             $tablepublic->define_headers($tableheaders);
00185             $tablepublic->define_baseurl($deleteurl);
00186             $tablepublic->column_style('action', 'width', '10%');
00187 
00188             $tablepublic->sortable(false);
00189             $tablepublic->set_attribute('width', '100%');
00190             $tablepublic->set_attribute('class', 'generaltable');
00191             $tablepublic->setup();
00192 
00193             foreach ($templates as $template) {
00194                 $data = array();
00195                 $data[] = $template->name;
00196                 $url = new moodle_url($deleteurl, array(
00197                                                 'id'=>$id,
00198                                                 'deletetempl'=>$template->id,
00199                                                 'shoulddelete'=>1,
00200                                                 ));
00201 
00202                 $data[] = $OUTPUT->single_button($url, $strdeletefeedback, 'post');
00203                 $tablepublic->add_data($data);
00204             }
00205             $tablepublic->finish_output();
00206             echo $OUTPUT->box_end();
00207         }
00208     }
00209 
00210     echo $OUTPUT->box_start('boxaligncenter boxwidthnormal');
00211     $url = new moodle_url($deleteurl, array(
00212                                     'id'=>$id,
00213                                     'canceldelete'=>1,
00214                                     ));
00215 
00216     echo $OUTPUT->single_button($url, get_string('back'), 'post');
00217     echo $OUTPUT->box_end();
00218 }
00219 
00220 echo $OUTPUT->footer();
00221 
 All Data Structures Namespaces Files Functions Variables Enumerations