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.
   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   * Install script for plugin.
  19   *
  20   * @package    quizaccess_seb
  21   * @author     Andrew Madden <andrewmadden@catalyst-au.net>
  22   * @copyright  2019 Catalyst IT
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once($CFG->dirroot  . '/mod/quiz/accessrule/seb/lib.php');
  29  
  30  /**
  31   * Custom code to be run on installing the plugin.
  32   */
  33  function xmldb_quizaccess_seb_install() {
  34      global $DB;
  35  
  36      // Reconfigure all existing quizzes to use a new quizaccess_seb.
  37      $params = ['browsersecurity' => 'safebrowser'];
  38  
  39      $total = $DB->count_records('quiz', $params);
  40      if ($total > 0) {
  41          $rs = $DB->get_recordset('quiz', $params);
  42  
  43          $i = 0;
  44          $pbar = new progress_bar('updatequizrecords', 500, true);
  45  
  46          foreach ($rs as $quiz) {
  47              if (!$DB->record_exists('quizaccess_seb_quizsettings', ['quizid' => $quiz->id])) {
  48                  $cm = get_coursemodule_from_instance('quiz', $quiz->id, $quiz->course);
  49  
  50                  $sebsettings = new stdClass();
  51  
  52                  $sebsettings->quizid = $quiz->id;
  53                  $sebsettings->cmid = $cm->id;
  54                  $sebsettings->templateid = 0;
  55                  $sebsettings->requiresafeexambrowser = \quizaccess_seb\settings_provider::USE_SEB_CLIENT_CONFIG;
  56                  $sebsettings->showsebtaskbar = null;
  57                  $sebsettings->showwificontrol = null;
  58                  $sebsettings->showreloadbutton = null;
  59                  $sebsettings->showtime = null;
  60                  $sebsettings->showkeyboardlayout = null;
  61                  $sebsettings->allowuserquitseb = null;
  62                  $sebsettings->quitpassword = null;
  63                  $sebsettings->linkquitseb = null;
  64                  $sebsettings->userconfirmquit = null;
  65                  $sebsettings->enableaudiocontrol = null;
  66                  $sebsettings->muteonstartup = null;
  67                  $sebsettings->allowspellchecking = null;
  68                  $sebsettings->allowreloadinexam = null;
  69                  $sebsettings->activateurlfiltering = null;
  70                  $sebsettings->filterembeddedcontent = null;
  71                  $sebsettings->expressionsallowed = null;
  72                  $sebsettings->regexallowed = null;
  73                  $sebsettings->expressionsblocked = null;
  74                  $sebsettings->regexblocked = null;
  75                  $sebsettings->allowedbrowserexamkeys = null;
  76                  $sebsettings->showsebdownloadlink = 1;
  77                  $sebsettings->usermodified = get_admin()->id;
  78                  $sebsettings->timecreated = time();
  79                  $sebsettings->timemodified = time();
  80  
  81                  $DB->insert_record('quizaccess_seb_quizsettings', $sebsettings);
  82  
  83                  $quiz->browsersecurity = '-';
  84                  $DB->update_record('quiz', $quiz);
  85              }
  86  
  87              $i++;
  88              $pbar->update($i, $total, "Reconfiguring existing quizzes to use a new SEB plugin - $i/$total.");
  89          }
  90  
  91          $rs->close();
  92      }
  93  
  94      return true;
  95  }