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  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Set tracking option for the forum.
  20   *
  21   * @package   mod_forum
  22   * @copyright 2005 mchurch
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once("../../config.php");
  27  require_once ("lib.php");
  28  
  29  $f          = required_param('f',PARAM_INT); // The forum to mark
  30  $mark       = required_param('mark',PARAM_ALPHA); // Read or unread?
  31  $d          = optional_param('d',0,PARAM_INT); // Discussion to mark.
  32  $return     = optional_param('return', null, PARAM_LOCALURL);    // Page to return to.
  33  
  34  $url = new moodle_url('/mod/forum/markposts.php', array('f'=>$f, 'mark'=>$mark));
  35  if ($d !== 0) {
  36      $url->param('d', $d);
  37  }
  38  if (null !== $return) {
  39      $url->param('return', $return);
  40  }
  41  $PAGE->set_url($url);
  42  
  43  if (! $forum = $DB->get_record("forum", array("id" => $f))) {
  44      throw new \moodle_exception('invalidforumid', 'forum');
  45  }
  46  
  47  if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
  48      throw new \moodle_exception('invalidcourseid');
  49  }
  50  
  51  if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
  52      throw new \moodle_exception('invalidcoursemodule');
  53  }
  54  
  55  $user = $USER;
  56  
  57  require_login($course, false, $cm);
  58  require_sesskey();
  59  
  60  if (null === $return) {
  61      $returnto = new moodle_url("/mod/forum/index.php", ['id' => $course->id]);
  62  } else {
  63      $returnto = new moodle_url($return);
  64  }
  65  
  66  if (isguestuser()) {   // Guests can't change forum
  67      $PAGE->set_title($course->shortname);
  68      $PAGE->set_heading($course->fullname);
  69      echo $OUTPUT->header();
  70      echo $OUTPUT->confirm(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'), get_login_url(), $returnto);
  71      echo $OUTPUT->footer();
  72      exit;
  73  }
  74  
  75  $info = new stdClass();
  76  $info->name  = fullname($user);
  77  $info->forum = format_string($forum->name);
  78  
  79  if ($mark == 'read') {
  80      if (!empty($d)) {
  81          if (! $discussion = $DB->get_record('forum_discussions', array('id'=> $d, 'forum'=> $forum->id))) {
  82              throw new \moodle_exception('invaliddiscussionid', 'forum');
  83          }
  84  
  85          forum_tp_mark_discussion_read($user, $d);
  86      } else {
  87          // Mark all messages read in current group
  88          $currentgroup = groups_get_activity_group($cm);
  89          if(!$currentgroup) {
  90              // mark_forum_read requires ===false, while get_activity_group
  91              // may return 0
  92              $currentgroup=false;
  93          }
  94          forum_tp_mark_forum_read($user, $forum->id, $currentgroup);
  95      }
  96  }
  97  
  98  redirect($returnto);
  99