Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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      print_error('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  
  72  // Check if the feedback is open (timeopen, timeclose).
  73  if (!$feedbackcompletion->is_open()) {
  74      echo $OUTPUT->header();
  75      echo $OUTPUT->heading(format_string($feedback->name));
  76      echo $OUTPUT->box_start('generalbox boxaligncenter');
  77      echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
  78      echo $OUTPUT->continue_button(course_get_url($courseid ?: $feedback->course));
  79      echo $OUTPUT->box_end();
  80      echo $OUTPUT->footer();
  81      exit;
  82  }
  83  
  84  // Mark activity viewed for completion-tracking.
  85  if (isloggedin() && !isguestuser()) {
  86      $feedbackcompletion->set_module_viewed();
  87  }
  88  
  89  // Check if user is prevented from re-submission.
  90  $cansubmit = $feedbackcompletion->can_submit();
  91  
  92  // Initialise the form processing feedback completion.
  93  if (!$feedbackcompletion->is_empty() && $cansubmit) {
  94      // Process the page via the form.
  95      $urltogo = $feedbackcompletion->process_page($gopage, $gopreviouspage);
  96  
  97      if ($urltogo !== null) {
  98          redirect($urltogo);
  99      }
 100  }
 101  
 102  // Print the page header.
 103  $strfeedbacks = get_string("modulenameplural", "feedback");
 104  $strfeedback  = get_string("modulename", "feedback");
 105  
 106  echo $OUTPUT->header();
 107  echo $OUTPUT->heading(format_string($feedback->name));
 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 ($feedbackcompletion->can_view_analysis()) {
 119              echo '<p align="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();