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 401] [Versions 39 and 402] [Versions 39 and 403]

   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  $id         = required_param('id',PARAM_INT);                           // The forum to subscribe or unsubscribe to
  30  $returnpage = optional_param('returnpage', 'index.php', PARAM_FILE);    // Page to return to.
  31  
  32  require_sesskey();
  33  
  34  if (! $forum = $DB->get_record("forum", array("id" => $id))) {
  35      print_error('invalidforumid', 'forum');
  36  }
  37  
  38  if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
  39      print_error('invalidcoursemodule');
  40  }
  41  
  42  if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
  43      print_error('invalidcoursemodule');
  44  }
  45  require_login($course, false, $cm);
  46  $returnpageurl = new moodle_url('/mod/forum/' . $returnpage, array('id' => $course->id, 'f' => $forum->id));
  47  $returnto = forum_go_back_to($returnpageurl);
  48  
  49  if (!forum_tp_can_track_forums($forum)) {
  50      redirect($returnto);
  51  }
  52  
  53  $info = new stdClass();
  54  $info->name  = fullname($USER);
  55  $info->forum = format_string($forum->name);
  56  
  57  $eventparams = array(
  58      'context' => context_module::instance($cm->id),
  59      'relateduserid' => $USER->id,
  60      'other' => array('forumid' => $forum->id),
  61  );
  62  
  63  if (forum_tp_is_tracked($forum) ) {
  64      if (forum_tp_stop_tracking($forum->id)) {
  65          $event = \mod_forum\event\readtracking_disabled::create($eventparams);
  66          $event->trigger();
  67          redirect($returnto, get_string("nownottracking", "forum", $info), 1);
  68      } else {
  69          print_error('cannottrack', '', get_local_referer(false));
  70      }
  71  
  72  } else { // subscribe
  73      if (forum_tp_start_tracking($forum->id)) {
  74          $event = \mod_forum\event\readtracking_enabled::create($eventparams);
  75          $event->trigger();
  76          redirect($returnto, get_string("nowtracking", "forum", $info), 1);
  77      } else {
  78          print_error('cannottrack', '', get_local_referer(false));
  79      }
  80  }