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.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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   * prints the form so the user can fill out the feedback
  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  feedback_init_feedback_session();
  29  
  30  $id = required_param('id', PARAM_INT);
  31  $courseid = optional_param('courseid', null, PARAM_INT);
  32  $gopage = optional_param('gopage', 0, PARAM_INT);
  33  $gopreviouspage = optional_param('gopreviouspage', null, PARAM_RAW);
  34  
  35  list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  36  $feedback = $DB->get_record("feedback", array("id" => $cm->instance), '*', MUST_EXIST);
  37  
  38  $urlparams = array('id' => $cm->id, 'gopage' => $gopage, 'courseid' => $courseid);
  39  $PAGE->set_url('/mod/feedback/complete.php', $urlparams);
  40  
  41  require_course_login($course, true, $cm);
  42  $PAGE->set_activity_record($feedback);
  43  
  44  $context = context_module::instance($cm->id);
  45  $feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
  46  
  47  $courseid = $feedbackcompletion->get_courseid();
  48  
  49  // Check whether the feedback is mapped to the given courseid.
  50  if (!has_capability('mod/feedback:edititems', $context) &&
  51          !$feedbackcompletion->check_course_is_mapped()) {
  52      echo $OUTPUT->header();
  53      echo $OUTPUT->notification(get_string('cannotaccess', 'mod_feedback'));
  54      echo $OUTPUT->footer();
  55      exit;
  56  }
  57  
  58  //check whether the given courseid exists
  59  if ($courseid AND $courseid != SITEID) {
  60      require_course_login(get_course($courseid)); // This overwrites the object $COURSE .
  61  }
  62  
  63  if (!$feedbackcompletion->can_complete()) {
  64      throw new \moodle_exception('error');
  65  }
  66  
  67  $PAGE->navbar->add(get_string('feedback:complete', 'feedback'));
  68  $PAGE->set_heading($course->fullname);
  69  $PAGE->set_title($feedback->name);
  70  $PAGE->set_pagelayout('incourse');
  71  $PAGE->set_secondary_active_tab('modulepage');
  72  $PAGE->add_body_class('limitedwidth');
  73  
  74  // Check if the feedback is open (timeopen, timeclose).
  75  if (!$feedbackcompletion->is_open()) {
  76      echo $OUTPUT->header();
  77      echo $OUTPUT->box_start('generalbox boxaligncenter');
  78      echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
  79      echo $OUTPUT->continue_button(course_get_url($courseid ?: $feedback->course));
  80      echo $OUTPUT->box_end();
  81      echo $OUTPUT->footer();
  82      exit;
  83  }
  84  
  85  // Mark activity viewed for completion-tracking.
  86  if (isloggedin() && !isguestuser()) {
  87      $feedbackcompletion->set_module_viewed();
  88  }
  89  
  90  // Check if user is prevented from re-submission.
  91  $cansubmit = $feedbackcompletion->can_submit();
  92  
  93  // Initialise the form processing feedback completion.
  94  if (!$feedbackcompletion->is_empty() && $cansubmit) {
  95      // Process the page via the form.
  96      $urltogo = $feedbackcompletion->process_page($gopage, $gopreviouspage);
  97  
  98      if ($urltogo !== null) {
  99          redirect($urltogo);
 100      }
 101  }
 102  
 103  // Print the page header.
 104  $strfeedbacks = get_string("modulenameplural", "feedback");
 105  $strfeedback  = get_string("modulename", "feedback");
 106  
 107  echo $OUTPUT->header();
 108  
 109  if ($feedbackcompletion->is_empty()) {
 110      \core\notification::error(get_string('no_items_available_yet', 'feedback'));
 111  } else if ($cansubmit) {
 112      if ($feedbackcompletion->just_completed()) {
 113          // Display information after the submit.
 114          if ($feedback->page_after_submit) {
 115              echo $OUTPUT->box($feedbackcompletion->page_after_submit(),
 116                      'generalbox boxaligncenter');
 117          }
 118          if (!$PAGE->has_secondary_navigation() && $feedbackcompletion->can_view_analysis()) {
 119              echo '<p class="text-center">';
 120              $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id' => $cm->id, 'courseid' => $courseid));
 121              echo html_writer::link($analysisurl, get_string('completed_feedbacks', 'feedback'));
 122              echo '</p>';
 123          }
 124  
 125          if ($feedback->site_after_submit) {
 126              $url = feedback_encode_target_url($feedback->site_after_submit);
 127          } else {
 128              $url = course_get_url($courseid ?: $course->id);
 129          }
 130          echo $OUTPUT->continue_button($url);
 131      } else {
 132          // Display the form with the questions.
 133          echo $feedbackcompletion->render_items();
 134      }
 135  } else {
 136      echo $OUTPUT->box_start('generalbox boxaligncenter');
 137      echo $OUTPUT->notification(get_string('this_feedback_is_already_submitted', 'feedback'));
 138      echo $OUTPUT->continue_button(course_get_url($courseid ?: $course->id));
 139      echo $OUTPUT->box_end();
 140  }
 141  
 142  echo $OUTPUT->footer();