Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.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   * Prints the contact form to the site's Data Protection Officer
  19   *
  20   * @copyright 2018 onwards Jun Pataleta
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  22   * @package tool_dataprivacy
  23   */
  24  
  25  require_once("../../../config.php");
  26  require_once ('lib.php');
  27  
  28  require_login(null, false);
  29  
  30  $perpage = optional_param('perpage', 0, PARAM_INT);
  31  
  32  $url = new moodle_url('/admin/tool/dataprivacy/datarequests.php');
  33  
  34  $title = get_string('datarequests', 'tool_dataprivacy');
  35  
  36  \tool_dataprivacy\page_helper::setup($url, $title, '', 'tool/dataprivacy:managedatarequests');
  37  
  38  echo $OUTPUT->header();
  39  echo $OUTPUT->heading($title);
  40  
  41  if (!\tool_dataprivacy\data_registry::defaults_set()) {
  42      \core\notification::error(get_string('systemconfignotsetwarning', 'tool_dataprivacy'));
  43  }
  44  
  45  if (\tool_dataprivacy\api::is_site_dpo($USER->id)) {
  46      $filtersapplied = optional_param_array('request-filters', [-1], PARAM_NOTAGS);
  47      $filterscleared = optional_param('filters-cleared', 0, PARAM_INT);
  48      if ($filtersapplied === [-1]) {
  49          // If there are no filters submitted, check if there is a saved filters from the user preferences.
  50          $filterprefs = get_user_preferences(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, null);
  51          if ($filterprefs && empty($filterscleared)) {
  52              $filtersapplied = json_decode($filterprefs);
  53          } else {
  54              $filtersapplied = [];
  55          }
  56      }
  57      // Save the current applied filters to the user preferences.
  58      set_user_preference(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, json_encode($filtersapplied));
  59  
  60      $types = [];
  61      $statuses = [];
  62      $creationmethods = [];
  63      foreach ($filtersapplied as $filter) {
  64          list($category, $value) = explode(':', $filter);
  65          switch($category) {
  66              case \tool_dataprivacy\local\helper::FILTER_TYPE:
  67                  $types[] = $value;
  68                  break;
  69              case \tool_dataprivacy\local\helper::FILTER_STATUS:
  70                  $statuses[] = $value;
  71                  break;
  72              case \tool_dataprivacy\local\helper::FILTER_CREATION:
  73                  $creationmethods[] = $value;
  74                  break;
  75          }
  76      }
  77  
  78      $table = new \tool_dataprivacy\output\data_requests_table(0, $statuses, $types, $creationmethods, true);
  79      if (!empty($perpage)) {
  80          set_user_preference(\tool_dataprivacy\local\helper::PREF_REQUEST_PERPAGE, $perpage);
  81      } else {
  82          $prefperpage = get_user_preferences(\tool_dataprivacy\local\helper::PREF_REQUEST_PERPAGE);
  83          $perpage = ($prefperpage) ? $prefperpage : $table->get_requests_per_page_options()[0];
  84      }
  85      $table->set_requests_per_page($perpage);
  86      $table->baseurl = $url;
  87  
  88      $requestlist = new tool_dataprivacy\output\data_requests_page($table, $filtersapplied);
  89      $requestlistoutput = $PAGE->get_renderer('tool_dataprivacy');
  90      echo $requestlistoutput->render($requestlist);
  91  } else {
  92      $dponamestring = implode (', ', tool_dataprivacy\api::get_dpo_role_names());
  93      $message = get_string('privacyofficeronly', 'tool_dataprivacy', $dponamestring);
  94      echo $OUTPUT->notification($message, 'error');
  95  }
  96  
  97  echo $OUTPUT->footer();