Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * deletes a template
  19   *
  20   * @author Andreas Grabs
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  22   * @package mod_feedback
  23   */
  24  
  25  require_once("../../config.php");
  26  require_once ("lib.php");
  27  
  28  $current_tab = 'templates';
  29  
  30  $id = required_param('id', PARAM_INT);
  31  $deletetempl = optional_param('deletetempl', false, PARAM_INT);
  32  
  33  $baseurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id));
  34  $PAGE->set_url($baseurl);
  35  
  36  list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  37  $context = context_module::instance($cm->id);
  38  
  39  require_login($course, true, $cm);
  40  require_capability('mod/feedback:deletetemplate', $context);
  41  
  42  $feedback = $PAGE->activityrecord;
  43  $systemcontext = context_system::instance();
  44  
  45  // Process template deletion.
  46  if ($deletetempl) {
  47      require_sesskey();
  48      $template = $DB->get_record('feedback_template', array('id' => $deletetempl), '*', MUST_EXIST);
  49  
  50      if ($template->ispublic) {
  51          require_capability('mod/feedback:createpublictemplate', $systemcontext);
  52          require_capability('mod/feedback:deletetemplate', $systemcontext);
  53      }
  54  
  55      feedback_delete_template($template);
  56      redirect($baseurl, get_string('template_deleted', 'feedback'));
  57  }
  58  
  59  /// Print the page header
  60  $strfeedbacks = get_string("modulenameplural", "feedback");
  61  $strfeedback  = get_string("modulename", "feedback");
  62  $strdeletefeedback = get_string('delete_template', 'feedback');
  63  
  64  navigation_node::override_active_url(new moodle_url('/mod/feedback/edit.php',
  65          array('id' => $id, 'do_show' => 'templates')));
  66  $PAGE->set_heading($course->fullname);
  67  $PAGE->set_title($feedback->name);
  68  echo $OUTPUT->header();
  69  echo $OUTPUT->heading(format_string($feedback->name));
  70  /// print the tabs
  71  require ('tabs.php');
  72  
  73  // Print the main part of the page.
  74  echo $OUTPUT->heading($strdeletefeedback, 3);
  75  
  76  // First we get the course templates.
  77  $templates = feedback_get_template_list($course, 'own');
  78  echo $OUTPUT->box_start('coursetemplates');
  79  echo $OUTPUT->heading(get_string('course'), 4);
  80  $tablecourse = new mod_feedback_templates_table('feedback_template_course_table', $baseurl);
  81  $tablecourse->display($templates);
  82  echo $OUTPUT->box_end();
  83  // Now we get the public templates if it is permitted.
  84  if (has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
  85      has_capability('mod/feedback:deletetemplate', $systemcontext)) {
  86      $templates = feedback_get_template_list($course, 'public');
  87      echo $OUTPUT->box_start('publictemplates');
  88      echo $OUTPUT->heading(get_string('public', 'feedback'), 4);
  89      $tablepublic = new mod_feedback_templates_table('feedback_template_public_table', $baseurl);
  90      $tablepublic->display($templates);
  91      echo $OUTPUT->box_end();
  92  }
  93  
  94  $url = new moodle_url('/mod/feedback/edit.php', array('id' => $id, 'do_show' => 'templates'));
  95  echo $OUTPUT->single_button($url, get_string('back'), 'post');
  96  
  97  echo $OUTPUT->footer();
  98