Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * Manage the various templates available
  19   *
  20   * @author Peter Dias
  21   * @copyright 2021 Peter Dias
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  23   * @package mod_feedback
  24   */
  25  
  26  require_once("../../config.php");
  27  require_once ("lib.php");
  28  
  29  $id = required_param('id', PARAM_INT);
  30  $mode = optional_param('mode', '', PARAM_ALPHA);
  31  $templateid = optional_param('deletetemplate', 0, PARAM_INT);
  32  
  33  list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  34  $context = context_module::instance($cm->id);
  35  
  36  require_login($course, true, $cm);
  37  require_capability('mod/feedback:edititems', $context);
  38  
  39  $feedback = $PAGE->activityrecord;
  40  $systemcontext = context_system::instance();
  41  
  42  $params = ['id' => $id];
  43  if ($mode) {
  44      $params += ['mode' => $mode];
  45  }
  46  $url = new moodle_url('/mod/feedback/manage_templates.php', $params);
  47  if ($mode == 'manage') {
  48      navigation_node::override_active_url($url);
  49  } else {
  50      navigation_node::override_active_url(new moodle_url('/mod/feedback/view.php', $params));
  51  }
  52  
  53  $PAGE->set_url($url);
  54  $actionbar = new \mod_feedback\output\edit_action_bar($cm->id, $url);
  55  
  56  $PAGE->set_heading($course->fullname);
  57  $PAGE->set_title($feedback->name);
  58  
  59  // Process template deletion.
  60  if ($templateid) {
  61      require_sesskey();
  62      require_capability('mod/feedback:deletetemplate', $context);
  63      $template = $DB->get_record('feedback_template', ['id' => $templateid], '*', MUST_EXIST);
  64  
  65      if ($template->ispublic) {
  66          require_capability('mod/feedback:createpublictemplate', $systemcontext);
  67          require_capability('mod/feedback:deletetemplate', $systemcontext);
  68      }
  69  
  70      feedback_delete_template($template);
  71      $successurl = new moodle_url('/mod/feedback/manage_templates.php', ['id' => $id]);
  72      redirect($url, get_string('template_deleted', 'feedback'), null, \core\output\notification::NOTIFY_SUCCESS);
  73  }
  74  $PAGE->activityheader->set_attrs([
  75      "hidecompletion" => true,
  76      "description" => ''
  77  ]);
  78  echo $OUTPUT->header();
  79  /** @var \mod_feedback\output\renderer $renderer */
  80  $renderer = $PAGE->get_renderer('mod_feedback');
  81  if (!$mode) {
  82      echo $renderer->main_action_bar($actionbar);
  83  }
  84  echo $OUTPUT->heading(get_string('templates', 'mod_feedback'), 3);
  85  
  86  // First we get the course templates.
  87  $templates = feedback_get_template_list($course, 'own');
  88  echo $OUTPUT->box_start('coursetemplates');
  89  echo $OUTPUT->heading(get_string('course'), 4);
  90  
  91  $baseurl = new moodle_url('/mod/feedback/use_templ.php', $params);
  92  $tablecourse = new mod_feedback_templates_table('feedback_template_course_table', $baseurl, $mode);
  93  $tablecourse->display($templates);
  94  echo $OUTPUT->box_end();
  95  
  96  $templates = feedback_get_template_list($course, 'public');
  97  echo $OUTPUT->box_start('publictemplates');
  98  echo $OUTPUT->heading(get_string('public', 'feedback'), 4);
  99  $tablepublic = new mod_feedback_templates_table('feedback_template_public_table', $baseurl, $mode);
 100  $tablepublic->display($templates);
 101  echo $OUTPUT->box_end();
 102  echo $OUTPUT->footer();