Compare commits
72 Commits
40-behatfi
...
MOODLE_34_
Author | SHA1 | Date |
---|---|---|
Morgan Harris | dbe59d1bb7 | 6 years ago |
Dan Marsden | 13bbd26bda | 6 years ago |
Dan Marsden | 6eb87c01f7 | 6 years ago |
Dan Marsden | 9238d3d5d0 | 6 years ago |
Dan Marsden | e69110fa14 | 6 years ago |
Dan Marsden | 2cb6ca75fb | 6 years ago |
Dan Marsden | aa028de126 | 6 years ago |
Dan Marsden | 1ffcc8a6ec | 6 years ago |
Dan Marsden | 9169ac515a | 6 years ago |
Tõnis Tartes | 2183c68d3b | 6 years ago |
Dan Marsden | 56aaba5e99 | 6 years ago |
Dan Marsden | 204d9d7319 | 6 years ago |
Dan Marsden | 907fbd676a | 6 years ago |
Dan Marsden | 2382b1c9fd | 7 years ago |
Dan Marsden | c270e0f9b4 | 7 years ago |
Dan Marsden | f8830ab322 | 7 years ago |
Dan Marsden | ca8d80302e | 7 years ago |
Neill Magill | c1f2008c17 | 7 years ago |
Dan Marsden | 74af6ba2cc | 7 years ago |
Dan Marsden | 90b0d53afb | 7 years ago |
Dan Marsden | 45e7a28fc2 | 7 years ago |
Dan Marsden | 07ff5091df | 7 years ago |
Dan Marsden | 29efe3ed57 | 7 years ago |
Dan Marsden | a41e6b5d04 | 7 years ago |
Dan Marsden | abf205abfa | 7 years ago |
Dan Marsden | 72db494ea8 | 7 years ago |
Dan Marsden | dcbfd04c4d | 7 years ago |
Dan Marsden | c38993ea46 | 7 years ago |
Dan Marsden | edee40553c | 7 years ago |
Dan Marsden | e25513b1b2 | 7 years ago |
Dan Marsden | 643a20778c | 7 years ago |
Nick Phillips | 1f71e7f740 | 7 years ago |
Nick Phillips | 9529211734 | 7 years ago |
Dan Marsden | f8df4ad29d | 7 years ago |
Nick Phillips | 9e4916aad7 | 7 years ago |
Dan Marsden | ae42f9f5c7 | 7 years ago |
Dan Marsden | 7f81249d9a | 7 years ago |
Dan Marsden | cd03de4b72 | 7 years ago |
Dan Marsden | 2cc321cd2c | 7 years ago |
Dan Marsden | 78270c41ae | 7 years ago |
Dan Marsden | 05d701e832 | 7 years ago |
Dan Marsden | 3c58ce2bb7 | 7 years ago |
Dan Marsden | e6fd12779a | 7 years ago |
Dan Marsden | 3c6068aa8f | 7 years ago |
Dan Marsden | 430e51bb20 | 7 years ago |
Dan Marsden | 8e52d83c20 | 7 years ago |
Dan Marsden | 322cd6bb68 | 7 years ago |
Dan Marsden | d856edd627 | 7 years ago |
Dan Marsden | e9a1639d1d | 7 years ago |
Dan Marsden | db93178214 | 7 years ago |
Dan Marsden | f7f4ee7e52 | 7 years ago |
Dan Marsden | 4b68c74140 | 7 years ago |
Dan Marsden | 0cc5332c5b | 7 years ago |
Dan Marsden | 2a9f3a1ea7 | 7 years ago |
Dan Marsden | 1fab8e9691 | 7 years ago |
Dan Marsden | d78f96b8c8 | 7 years ago |
Alicecj | b220a27ff1 | 7 years ago |
Dan Marsden | 2ddfd29843 | 7 years ago |
Dan Marsden | 10f85fffbd | 7 years ago |
Dan Marsden | 8d88758039 | 7 years ago |
Dan Marsden | 06904c98d0 | 7 years ago |
Dan Marsden | 394cc3ded7 | 7 years ago |
Dan Marsden | 82e60a7719 | 7 years ago |
James Voong | 515f27d08c | 7 years ago |
Dan Marsden | 9567221f9c | 7 years ago |
Dan Marsden | 38a6542a4f | 7 years ago |
Dan Marsden | 6aee345330 | 7 years ago |
Dan Marsden | 7614a9690a | 7 years ago |
Dan Marsden | 3039f82e80 | 7 years ago |
Dan Marsden | 8de82ae5ab | 7 years ago |
Chris Wharton | 1ed5a2d245 | 7 years ago |
Dan Marsden | fbf4eea35b | 7 years ago |
44 changed files with 1921 additions and 135 deletions
@ -0,0 +1,93 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* This file contains an event for when self-marking is blocked because |
||||
|
* another student used the same IP address to self-mark. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Dan Marsden <dan@danmarsden.com> |
||||
|
* @copyright 2018 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
namespace mod_attendance\event; |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
|
||||
|
/** |
||||
|
* Event for when self-marking is blocked |
||||
|
* |
||||
|
* @property-read array $other { |
||||
|
* Extra information about event properties. |
||||
|
* |
||||
|
* string mode Mode of the report viewed. |
||||
|
* } |
||||
|
* @package mod_attendance |
||||
|
* @author Dan Marsden <dan@danmarsden.com> |
||||
|
* @copyright 2018 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
class session_ip_shared extends \core\event\base { |
||||
|
|
||||
|
/** |
||||
|
* Init method. |
||||
|
*/ |
||||
|
protected function init() { |
||||
|
$this->data['crud'] = 'r'; |
||||
|
$this->data['edulevel'] = self::LEVEL_PARTICIPATING; |
||||
|
$this->data['objecttable'] = 'attendance_log'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns non-localised description of what happened. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function get_description() { |
||||
|
return 'User with id ' . $this->userid . ' was blocked from taking attendance for sessionid: ' . $this->other['sessionid'] . |
||||
|
' because user with id '.$this->other['otheruser'] . ' previously marked attendance with the same IP address.'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns localised general event name. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function get_name() { |
||||
|
return get_string('eventsessionipshared', 'mod_attendance'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get URL related to the action |
||||
|
* |
||||
|
* @return \moodle_url |
||||
|
*/ |
||||
|
public function get_url() { |
||||
|
return new \moodle_url('/mod/attendance/attendance.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get objectid mapping |
||||
|
* |
||||
|
* @return array of parameters for object mapping. |
||||
|
*/ |
||||
|
public static function get_objectid_mapping() { |
||||
|
return array( |
||||
|
'db' => 'attendance', |
||||
|
'restore' => 'attendance' |
||||
|
); |
||||
|
} |
||||
|
} |
@ -0,0 +1,92 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* This file contains an event for when an attendance sessions is imported. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
namespace mod_attendance\event; |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
|
||||
|
/** |
||||
|
* Event for when an attendance sessions is imported |
||||
|
* |
||||
|
* @property-read array $other { |
||||
|
* Extra information about event properties. |
||||
|
* |
||||
|
* string mode Mode of the report viewed. |
||||
|
* } |
||||
|
* @package mod_attendance |
||||
|
* @since Moodle 2.7 |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
class sessions_imported extends \core\event\base { |
||||
|
|
||||
|
/** |
||||
|
* Init method. |
||||
|
*/ |
||||
|
protected function init() { |
||||
|
$this->data['crud'] = 'c'; |
||||
|
$this->data['edulevel'] = self::LEVEL_OTHER; |
||||
|
$this->data['objecttable'] = 'attendance_sessions'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns non-localised description of what happened. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function get_description() { |
||||
|
return 'User with id ' . $this->userid . ' imported ' . $this->other['count'] . ' sessions'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns localised general event name. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function get_name() { |
||||
|
return get_string('eventsessionsimported', 'mod_attendance'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get URL related to the action |
||||
|
* |
||||
|
* @return \moodle_url |
||||
|
*/ |
||||
|
public function get_url() { |
||||
|
return new \moodle_url('/mod/attendance/import/sessions.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get objectid mapping |
||||
|
* |
||||
|
* @return array of parameters for object mapping. |
||||
|
*/ |
||||
|
public static function get_objectid_mapping() { |
||||
|
return array( |
||||
|
'db' => 'attendance', |
||||
|
'restore' => 'attendance' |
||||
|
); |
||||
|
} |
||||
|
} |
@ -0,0 +1,86 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* This file contains the form for importing sessions from a file. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
namespace mod_attendance\form\import; |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); |
||||
|
|
||||
|
use core_text; |
||||
|
use csv_import_reader; |
||||
|
use moodleform; |
||||
|
require_once($CFG->libdir . '/formslib.php'); |
||||
|
require_once($CFG->libdir . '/csvlib.class.php'); |
||||
|
|
||||
|
/** |
||||
|
* Import attendance sessions. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
class sessions extends moodleform { |
||||
|
|
||||
|
/** |
||||
|
* Define the form - called by parent constructor |
||||
|
*/ |
||||
|
public function definition() { |
||||
|
global $CFG; |
||||
|
|
||||
|
$mform = $this->_form; |
||||
|
$element = $mform->createElement('filepicker', 'importfile', get_string('importfile', 'mod_attendance')); |
||||
|
$mform->addElement($element); |
||||
|
$mform->addHelpButton('importfile', 'importfile', 'mod_attendance'); |
||||
|
$mform->addRule('importfile', null, 'required'); |
||||
|
$mform->addElement('hidden', 'confirm', 0); |
||||
|
$mform->setType('confirm', PARAM_BOOL); |
||||
|
|
||||
|
$choices = csv_import_reader::get_delimiter_list(); |
||||
|
$mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'mod_attendance'), $choices); |
||||
|
if (array_key_exists('cfg', $choices)) { |
||||
|
$mform->setDefault('delimiter_name', 'cfg'); |
||||
|
} else if (get_string('listsep', 'langconfig') == ';') { |
||||
|
$mform->setDefault('delimiter_name', 'semicolon'); |
||||
|
} else { |
||||
|
$mform->setDefault('delimiter_name', 'comma'); |
||||
|
} |
||||
|
|
||||
|
$choices = core_text::get_encodings(); |
||||
|
$mform->addElement('select', 'encoding', get_string('encoding', 'mod_attendance'), $choices); |
||||
|
$mform->setDefault('encoding', 'UTF-8'); |
||||
|
|
||||
|
$this->add_action_buttons(false, get_string('import', 'mod_attendance')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Display an error on the import form. |
||||
|
* |
||||
|
* @param string $msg |
||||
|
*/ |
||||
|
public function set_import_error($msg) { |
||||
|
$mform = $this->_form; |
||||
|
|
||||
|
$mform->setElementError('importfile', $msg); |
||||
|
} |
||||
|
} |
@ -0,0 +1,73 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* Import attendance sessions. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
namespace mod_attendance\form\import; |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); |
||||
|
|
||||
|
use moodleform; |
||||
|
require_once($CFG->libdir . '/formslib.php'); |
||||
|
|
||||
|
/** |
||||
|
* Import attendance sessions. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
class sessions_confirm extends moodleform { |
||||
|
|
||||
|
/** |
||||
|
* Define the form - called by parent constructor |
||||
|
*/ |
||||
|
public function definition() { |
||||
|
$importer = $this->_customdata; |
||||
|
|
||||
|
$mform = $this->_form; |
||||
|
$mform->addElement('hidden', 'confirm', 1); |
||||
|
$mform->setType('confirm', PARAM_BOOL); |
||||
|
$mform->addElement('hidden', 'importid', $importer->get_importid()); |
||||
|
$mform->setType('importid', PARAM_INT); |
||||
|
|
||||
|
$requiredheaders = $importer->list_required_headers(); |
||||
|
$foundheaders = $importer->list_found_headers(); |
||||
|
|
||||
|
if (empty($foundheaders)) { |
||||
|
$foundheaders = range(0, count($requiredheaders)); |
||||
|
} |
||||
|
$foundheaders[- 1] = get_string('none'); |
||||
|
|
||||
|
foreach ($requiredheaders as $index => $requiredheader) { |
||||
|
$mform->addElement('select', 'header' . $index, $requiredheader, $foundheaders); |
||||
|
if (isset($foundheaders[$index])) { |
||||
|
$mform->setDefault('header' . $index, $index); |
||||
|
} else { |
||||
|
$mform->setDefault('header' . $index, - 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$this->add_action_buttons(true, get_string('confirm', 'mod_attendance')); |
||||
|
} |
||||
|
} |
@ -0,0 +1,493 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* Import attendance sessions class. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
|
||||
|
namespace mod_attendance\import; |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
|
||||
|
use csv_import_reader; |
||||
|
use mod_attendance_notifyqueue; |
||||
|
use mod_attendance_structure; |
||||
|
use stdClass; |
||||
|
|
||||
|
/** |
||||
|
* Import attendance sessions. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
class sessions { |
||||
|
|
||||
|
/** @var string $error The errors message from reading the xml */ |
||||
|
protected $error = ''; |
||||
|
|
||||
|
/** @var array $sessions The sessions info */ |
||||
|
protected $sessions = array(); |
||||
|
|
||||
|
/** @var array $mappings The mappings info */ |
||||
|
protected $mappings = array(); |
||||
|
|
||||
|
/** @var int The id of the csv import */ |
||||
|
protected $importid = 0; |
||||
|
|
||||
|
/** @var csv_import_reader|null $importer */ |
||||
|
protected $importer = null; |
||||
|
|
||||
|
/** @var array $foundheaders */ |
||||
|
protected $foundheaders = array(); |
||||
|
|
||||
|
/** @var bool $useprogressbar Control whether importing should use progress bars or not. */ |
||||
|
protected $useprogressbar = false; |
||||
|
|
||||
|
/** @var \core\progress\display_if_slow|null $progress The progress bar instance. */ |
||||
|
protected $progress = null; |
||||
|
|
||||
|
/** |
||||
|
* Store an error message for display later |
||||
|
* |
||||
|
* @param string $msg |
||||
|
*/ |
||||
|
public function fail($msg) { |
||||
|
$this->error = $msg; |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the CSV import id |
||||
|
* |
||||
|
* @return string The import id. |
||||
|
*/ |
||||
|
public function get_importid() { |
||||
|
return $this->importid; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the list of headers required for import. |
||||
|
* |
||||
|
* @return array The headers (lang strings) |
||||
|
*/ |
||||
|
public static function list_required_headers() { |
||||
|
return array( |
||||
|
get_string('course', 'attendance'), |
||||
|
get_string('groups', 'attendance'), |
||||
|
get_string('sessiondate', 'attendance'), |
||||
|
get_string('from', 'attendance'), |
||||
|
get_string('to', 'attendance'), |
||||
|
get_string('description', 'attendance'), |
||||
|
get_string('repeaton', 'attendance'), |
||||
|
get_string('repeatevery', 'attendance'), |
||||
|
get_string('repeatuntil', 'attendance'), |
||||
|
get_string('studentscanmark', 'attendance'), |
||||
|
get_string('passwordgrp', 'attendance'), |
||||
|
get_string('randompassword', 'attendance'), |
||||
|
get_string('subnet', 'attendance'), |
||||
|
get_string('automark', 'attendance'), |
||||
|
get_string('autoassignstatus', 'attendance'), |
||||
|
get_string('absenteereport', 'attendance'), |
||||
|
get_string('preventsharedip', 'attendance'), |
||||
|
get_string('preventsharediptime', 'attendance') |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the list of headers found in the import. |
||||
|
* |
||||
|
* @return array The found headers (names from import) |
||||
|
*/ |
||||
|
public function list_found_headers() { |
||||
|
return $this->foundheaders; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read the data from the mapping form. |
||||
|
* |
||||
|
* @param array $data The mapping data. |
||||
|
*/ |
||||
|
protected function read_mapping_data($data) { |
||||
|
if ($data) { |
||||
|
return array( |
||||
|
'course' => $data->header0, |
||||
|
'groups' => $data->header1, |
||||
|
'sessiondate' => $data->header2, |
||||
|
'from' => $data->header3, |
||||
|
'to' => $data->header4, |
||||
|
'description' => $data->header5, |
||||
|
'repeaton' => $data->header6, |
||||
|
'repeatevery' => $data->header7, |
||||
|
'repeatuntil' => $data->header8, |
||||
|
'studentscanmark' => $data->header9, |
||||
|
'passwordgrp' => $data->header10, |
||||
|
'randompassword' => $data->header11, |
||||
|
'subnet' => $data->header12, |
||||
|
'automark' => $data->header13, |
||||
|
'autoassignstatus' => $data->header14, |
||||
|
'absenteereport' => $data->header15, |
||||
|
'preventsharedip' => $data->header16, |
||||
|
'preventsharediptime' => $data->header17, |
||||
|
); |
||||
|
} else { |
||||
|
return array( |
||||
|
'course' => 0, |
||||
|
'groups' => 1, |
||||
|
'sessiondate' => 2, |
||||
|
'from' => 3, |
||||
|
'to' => 4, |
||||
|
'description' => 5, |
||||
|
'repeaton' => 6, |
||||
|
'repeatevery' => 7, |
||||
|
'repeatuntil' => 8, |
||||
|
'studentscanmark' => 9, |
||||
|
'passwordgrp' => 10, |
||||
|
'randompassword' => 11, |
||||
|
'subnet' => 12, |
||||
|
'automark' => 13, |
||||
|
'autoassignstatus' => 14, |
||||
|
'absenteereport' => 15, |
||||
|
'preventsharedip' => 16, |
||||
|
'preventsharediptime' => 17 |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the a column from the imported data. |
||||
|
* |
||||
|
* @param array $row The imported raw row |
||||
|
* @param int $index The column index we want |
||||
|
* @return string The column data. |
||||
|
*/ |
||||
|
protected function get_column_data($row, $index) { |
||||
|
if ($index < 0) { |
||||
|
return ''; |
||||
|
} |
||||
|
return isset($row[$index]) ? $row[$index] : ''; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Constructor - parses the raw text for sanity. |
||||
|
* |
||||
|
* @param string $text The raw csv text. |
||||
|
* @param string $encoding The encoding of the csv file. |
||||
|
* @param string $delimiter The specified delimiter for the file. |
||||
|
* @param string $importid The id of the csv import. |
||||
|
* @param array $mappingdata The mapping data from the import form. |
||||
|
* @param bool $useprogressbar Whether progress bar should be displayed, to avoid html output on CLI. |
||||
|
*/ |
||||
|
public function __construct($text = null, $encoding = null, $delimiter = null, $importid = 0, |
||||
|
$mappingdata = null, $useprogressbar = false) { |
||||
|
global $CFG; |
||||
|
|
||||
|
require_once($CFG->libdir . '/csvlib.class.php'); |
||||
|
|
||||
|
$pluginconfig = get_config('attendance'); |
||||
|
|
||||
|
$type = 'sessions'; |
||||
|
|
||||
|
if (! $importid) { |
||||
|
if ($text === null) { |
||||
|
return; |
||||
|
} |
||||
|
$this->importid = csv_import_reader::get_new_iid($type); |
||||
|
|
||||
|
$this->importer = new csv_import_reader($this->importid, $type); |
||||
|
|
||||
|
if (! $this->importer->load_csv_content($text, $encoding, $delimiter)) { |
||||
|
$this->fail(get_string('invalidimportfile', 'attendance')); |
||||
|
$this->importer->cleanup(); |
||||
|
return; |
||||
|
} |
||||
|
} else { |
||||
|
$this->importid = $importid; |
||||
|
|
||||
|
$this->importer = new csv_import_reader($this->importid, $type); |
||||
|
} |
||||
|
|
||||
|
if (! $this->importer->init()) { |
||||
|
$this->fail(get_string('invalidimportfile', 'attendance')); |
||||
|
$this->importer->cleanup(); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
$this->foundheaders = $this->importer->get_columns(); |
||||
|
$this->useprogressbar = $useprogressbar; |
||||
|
$domainid = 1; |
||||
|
|
||||
|
$sessions = array(); |
||||
|
|
||||
|
while ($row = $this->importer->next()) { |
||||
|
// This structure mimics what the UI form returns. |
||||
|
$mapping = $this->read_mapping_data($mappingdata); |
||||
|
|
||||
|
$session = new stdClass(); |
||||
|
$session->course = $this->get_column_data($row, $mapping['course']); |
||||
|
if (empty($session->course)) { |
||||
|
\mod_attendance_notifyqueue::notify_problem(get_string('error:sessioncourseinvalid', 'attendance')); |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// Handle multiple group assignments per session. Expect semicolon separated group names. |
||||
|
$groups = $this->get_column_data($row, $mapping['groups']); |
||||
|
if (! empty($groups)) { |
||||
|
$session->groups = explode(';', $groups); |
||||
|
$session->sessiontype = \mod_attendance_structure::SESSION_GROUP; |
||||
|
} else { |
||||
|
$session->sessiontype = \mod_attendance_structure::SESSION_COMMON; |
||||
|
} |
||||
|
|
||||
|
// Expect standardised date format, eg YYYY-MM-DD. |
||||
|
$sessiondate = strtotime($this->get_column_data($row, $mapping['sessiondate'])); |
||||
|
if ($sessiondate === false) { |
||||
|
\mod_attendance_notifyqueue::notify_problem(get_string('error:sessiondateinvalid', 'attendance')); |
||||
|
continue; |
||||
|
} |
||||
|
$session->sessiondate = $sessiondate; |
||||
|
|
||||
|
// Expect standardised time format, eg HH:MM. |
||||
|
$from = $this->get_column_data($row, $mapping['from']); |
||||
|
if (empty($from)) { |
||||
|
\mod_attendance_notifyqueue::notify_problem(get_string('error:sessionstartinvalid', 'attendance')); |
||||
|
continue; |
||||
|
} |
||||
|
$from = explode(':', $from); |
||||
|
$session->sestime['starthour'] = $from[0]; |
||||
|
$session->sestime['startminute'] = $from[1]; |
||||
|
|
||||
|
$to = $this->get_column_data($row, $mapping['to']); |
||||
|
if (empty($to)) { |
||||
|
\mod_attendance_notifyqueue::notify_problem(get_string('error:sessionendinvalid', 'attendance')); |
||||
|
continue; |
||||
|
} |
||||
|
$to = explode(':', $to); |
||||
|
$session->sestime['endhour'] = $to[0]; |
||||
|
$session->sestime['endminute'] = $to[1]; |
||||
|
|
||||
|
// Wrap the plain text description in html tags. |
||||
|
$session->sdescription['text'] = '<p>' . $this->get_column_data($row, $mapping['description']) . '</p>'; |
||||
|
$session->sdescription['format'] = FORMAT_HTML; |
||||
|
$session->sdescription['itemid'] = 0; |
||||
|
$session->passwordgrp = $this->get_column_data($row, $mapping['passwordgrp']); |
||||
|
$session->subnet = $this->get_column_data($row, $mapping['subnet']); |
||||
|
// Set session subnet restriction. Use the default activity level subnet if there isn't one set for this session. |
||||
|
if (empty($session->subnet)) { |
||||
|
$session->usedefaultsubnet = '1'; |
||||
|
} else { |
||||
|
$session->usedefaultsubnet = ''; |
||||
|
} |
||||
|
|
||||
|
if ($mapping['studentscanmark'] == -1) { |
||||
|
$session->studentscanmark = $pluginconfig->studentscanmark_default; |
||||
|
} else { |
||||
|
$session->studentscanmark = $this->get_column_data($row, $mapping['studentscanmark']); |
||||
|
} |
||||
|
if ($mapping['randompassword'] == -1) { |
||||
|
$session->randompassword = $pluginconfig->randompassword_default; |
||||
|
} else { |
||||
|
$session->randompassword = $this->get_column_data($row, $mapping['randompassword']); |
||||
|
} |
||||
|
if ($mapping['automark'] == -1) { |
||||
|
$session->automark = $pluginconfig->automark_default; |
||||
|
} else { |
||||
|
$session->automark = $this->get_column_data($row, $mapping['automark']); |
||||
|
} |
||||
|
if ($mapping['autoassignstatus'] == -1) { |
||||
|
$session->autoassignstatus = $pluginconfig->autoassignstatus; |
||||
|
} else { |
||||
|
$session->autoassignstatus = $this->get_column_data($row, $mapping['autoassignstatus']); |
||||
|
} |
||||
|
if ($mapping['absenteereport'] == -1) { |
||||
|
$session->absenteereport = $pluginconfig->absenteereport_default; |
||||
|
} else { |
||||
|
$session->absenteereport = $this->get_column_data($row, $mapping['absenteereport']); |
||||
|
} |
||||
|
if ($mapping['preventsharedip'] == -1) { |
||||
|
$session->preventsharedip = $pluginconfig->preventsharedip; |
||||
|
} else { |
||||
|
$session->preventsharedip = $this->get_column_data($row, $mapping['preventsharedip']); |
||||
|
} |
||||
|
if ($mapping['preventsharediptime'] == -1) { |
||||
|
$session->preventsharediptime = $pluginconfig->preventsharediptime; |
||||
|
} else { |
||||
|
$session->preventsharediptime = $this->get_column_data($row, $mapping['preventsharediptime']); |
||||
|
} |
||||
|
|
||||
|
$session->statusset = 0; |
||||
|
|
||||
|
$sessions[] = $session; |
||||
|
} |
||||
|
$this->sessions = $sessions; |
||||
|
|
||||
|
$this->importer->close(); |
||||
|
if ($this->sessions == null) { |
||||
|
$this->fail(get_string('invalidimportfile', 'attendance')); |
||||
|
return; |
||||
|
} else { |
||||
|
// We are calling from browser, display progress bar. |
||||
|
if ($this->useprogressbar === true) { |
||||
|
$this->progress = new \core\progress\display_if_slow(get_string('processingfile', 'attendance')); |
||||
|
$this->progress->start_html(); |
||||
|
} else { |
||||
|
// Avoid html output on CLI scripts. |
||||
|
$this->progress = new \core\progress\none(); |
||||
|
} |
||||
|
$this->progress->start_progress('', count($this->sessions)); |
||||
|
raise_memory_limit(MEMORY_EXTRA); |
||||
|
$this->progress->end_progress(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get parse errors. |
||||
|
* |
||||
|
* @return array of errors from parsing the xml. |
||||
|
*/ |
||||
|
public function get_error() { |
||||
|
return $this->error; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Create sessions using the CSV data. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function import() { |
||||
|
global $DB; |
||||
|
|
||||
|
// Count of sessions added. |
||||
|
$okcount = 0; |
||||
|
|
||||
|
foreach ($this->sessions as $session) { |
||||
|
$groupids = array(); |
||||
|
// Check course shortname matches. |
||||
|
if ($DB->record_exists('course', array( |
||||
|
'shortname' => $session->course |
||||
|
))) { |
||||
|
// Get course. |
||||
|
$course = $DB->get_record('course', array( |
||||
|
'shortname' => $session->course |
||||
|
), '*', MUST_EXIST); |
||||
|
|
||||
|
// Check course has activities. |
||||
|
if ($DB->record_exists('attendance', array( |
||||
|
'course' => $course->id |
||||
|
))) { |
||||
|
// Translate group names to group IDs. They are unique per course. |
||||
|
if ($session->sessiontype === \mod_attendance_structure::SESSION_GROUP) { |
||||
|
foreach ($session->groups as $groupname) { |
||||
|
$gid = groups_get_group_by_name($course->id, $groupname); |
||||
|
if ($gid === false) { |
||||
|
\mod_attendance_notifyqueue::notify_problem(get_string('sessionunknowngroup', |
||||
|
'attendance', $groupname)); |
||||
|
} else { |
||||
|
$groupids[] = $gid; |
||||
|
} |
||||
|
} |
||||
|
$session->groups = $groupids; |
||||
|
} |
||||
|
|
||||
|
// Get activities in course. |
||||
|
$activities = $DB->get_recordset('attendance', array( |
||||
|
'course' => $course->id |
||||
|
), 'id', 'id'); |
||||
|
|
||||
|
foreach ($activities as $activity) { |
||||
|
// Build the session data. |
||||
|
$cm = get_coursemodule_from_instance('attendance', $activity->id, $course->id); |
||||
|
if (!empty($cm->deletioninprogress)) { |
||||
|
// Don't do anything if this attendance is in recycle bin. |
||||
|
continue; |
||||
|
} |
||||
|
$att = new mod_attendance_structure($activity, $cm, $course); |
||||
|
$sessions = attendance_construct_sessions_data_for_add($session, $att); |
||||
|
|
||||
|
foreach ($sessions as $index => $sess) { |
||||
|
// Check for duplicate sessions. |
||||
|
if ($this->session_exists($sess)) { |
||||
|
mod_attendance_notifyqueue::notify_message(get_string('sessionduplicate', 'attendance', (array( |
||||
|
'course' => $session->course, |
||||
|
'activity' => $cm->name |
||||
|
)))); |
||||
|
unset($sessions[$index]); |
||||
|
} else { |
||||
|
$okcount ++; |
||||
|
} |
||||
|
} |
||||
|
if (! empty($sessions)) { |
||||
|
$att->add_sessions($sessions); |
||||
|
} |
||||
|
} |
||||
|
$activities->close(); |
||||
|
} else { |
||||
|
mod_attendance_notifyqueue::notify_problem(get_string('error:coursehasnoattendance', |
||||
|
'attendance', $session->course)); |
||||
|
} |
||||
|
} else { |
||||
|
mod_attendance_notifyqueue::notify_problem(get_string('error:coursenotfound', 'attendance', $session->course)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$message = get_string('sessionsgenerated', 'attendance', $okcount); |
||||
|
if ($okcount < 1) { |
||||
|
mod_attendance_notifyqueue::notify_message($message); |
||||
|
} else { |
||||
|
mod_attendance_notifyqueue::notify_success($message); |
||||
|
} |
||||
|
|
||||
|
// Trigger a sessions imported event. |
||||
|
$event = \mod_attendance\event\sessions_imported::create(array( |
||||
|
'objectid' => 0, |
||||
|
'context' => \context_system::instance(), |
||||
|
'other' => array( |
||||
|
'count' => $okcount |
||||
|
) |
||||
|
)); |
||||
|
|
||||
|
$event->trigger(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Check if an identical session exists. |
||||
|
* |
||||
|
* @param stdClass $session |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
private function session_exists(stdClass $session) { |
||||
|
global $DB; |
||||
|
|
||||
|
$check = clone $session; |
||||
|
|
||||
|
// Remove the properties that aren't useful to check. |
||||
|
unset($check->description); |
||||
|
unset($check->descriptionitemid); |
||||
|
unset($check->timemodified); |
||||
|
$check = (array) $check; |
||||
|
|
||||
|
if ($DB->record_exists('attendance_sessions', $check)) { |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
} |
@ -0,0 +1,94 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* Import attendance sessions. |
||||
|
* |
||||
|
* @package mod_attendance |
||||
|
* @author Chris Wharton <chriswharton@catalyst.net.nz> |
||||
|
* @copyright 2017 Catalyst IT |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
|
||||
|
define('NO_OUTPUT_BUFFERING', true); |
||||
|
|
||||
|
require_once(__DIR__ . '/../../../config.php'); |
||||
|
require_once($CFG->libdir . '/adminlib.php'); |
||||
|
require_once($CFG->dirroot . '/mod/attendance/lib.php'); |
||||
|
require_once($CFG->dirroot . '/mod/attendance/locallib.php'); |
||||
|
|
||||
|
admin_externalpage_setup('managemodules'); |
||||
|
$pagetitle = get_string('importsessions', 'attendance'); |
||||
|
|
||||
|
$context = context_system::instance(); |
||||
|
|
||||
|
$url = new moodle_url('/mod/attendance/import/sessions.php'); |
||||
|
|
||||
|
$PAGE->set_context($context); |
||||
|
$PAGE->set_url($url); |
||||
|
$PAGE->set_title($pagetitle); |
||||
|
$PAGE->set_pagelayout('admin'); |
||||
|
$PAGE->set_heading($pagetitle); |
||||
|
|
||||
|
echo $OUTPUT->header(); |
||||
|
echo $OUTPUT->heading(get_string('importsessions', 'attendance')); |
||||
|
$tabmenu = attendance_print_settings_tabs('importsessions'); |
||||
|
echo $tabmenu; |
||||
|
|
||||
|
$form = null; |
||||
|
if (optional_param('needsconfirm', 0, PARAM_BOOL)) { |
||||
|
$form = new \mod_attendance\form\import\sessions($url->out(false)); |
||||
|
} else if (optional_param('confirm', 0, PARAM_BOOL)) { |
||||
|
$importer = new \mod_attendance\import\sessions(); |
||||
|
$form = new \mod_attendance\form\import\sessions_confirm(null, $importer); |
||||
|
} else { |
||||
|
$form = new \mod_attendance\form\import\sessions($url->out(false)); |
||||
|
} |
||||
|
|
||||
|
if ($form->is_cancelled()) { |
||||
|
$form = new \mod_attendance\form\import\sessions($url->out(false)); |
||||
|
} else if ($data = $form->get_data()) { |
||||
|
require_sesskey(); |
||||
|
if ($data->confirm) { |
||||
|
$importid = $data->importid; |
||||
|
$importer = new \mod_attendance\import\sessions(null, null, null, $importid, $data, true); |
||||
|
|
||||
|
$error = $importer->get_error(); |
||||
|
if ($error) { |
||||
|
$form = new \mod_attendance\form\import\sessions($url->out(false)); |
||||
|
$form->set_import_error($error); |
||||
|
} else { |
||||
|
$sessions = $importer->import(); |
||||
|
mod_attendance_notifyqueue::show(); |
||||
|
echo $OUTPUT->continue_button($url); |
||||
|
die(); |
||||
|
} |
||||
|
} else { |
||||
|
$text = $form->get_file_content('importfile'); |
||||
|
$encoding = $data->encoding; |
||||
|
$delimiter = $data->delimiter_name; |
||||
|
$importer = new \mod_attendance\import\sessions($text, $encoding, $delimiter, 0, null, true); |
||||
|
$confirmform = new \mod_attendance\form\import\sessions_confirm(null, $importer); |
||||
|
$form = $confirmform; |
||||
|
$pagetitle = get_string('confirmcolumnmappings', 'attendance'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
echo $OUTPUT->heading($pagetitle); |
||||
|
|
||||
|
$form->display(); |
||||
|
|
||||
|
echo $OUTPUT->footer(); |
@ -0,0 +1,59 @@ |
|||||
|
<form id="theform" method="post" action="messageselect.php"> |
||||
|
<input type="hidden" name="id" value="<?php p($id) ?>" /> |
||||
|
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" /> |
||||
|
<input type="hidden" name="returnto" value="<?php p($returnto) ?>" /> |
||||
|
<input type="hidden" name="deluser" value="" /> |
||||
|
<?php echo $OUTPUT->box_start(); ?> |
||||
|
<table border="0" cellpadding="5"> |
||||
|
<tr valign="top"> |
||||
|
<td align="right"><b> |
||||
|
<?php print_string("messagebody"); ?>: |
||||
|
</b></td> |
||||
|
<td align="left"> |
||||
|
<?php print_textarea(true, 15, 65, 1, 1, "messagebody", $messagebody); ?> |
||||
|
</td> |
||||
|
</tr> |
||||
|
|
||||
|
<tr valign="top"> |
||||
|
<td align="right"><label for="menuformat"><b><?php print_string("formattexttype"); ?>:</b></label></td> |
||||
|
<td> |
||||
|
<?php |
||||
|
print_string('formathtml'); |
||||
|
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />'; |
||||
|
?> |
||||
|
</td> |
||||
|
</tr> |
||||
|
|
||||
|
<tr><td align="center" colspan="2"> |
||||
|
<input type="submit" name="send" value="<?php print_string('sendmessage', 'message'); ?>" /> |
||||
|
<input type="submit" name="preview" value="<?php print_string('preview'); ?>" /> |
||||
|
</td></tr> |
||||
|
</table> |
||||
|
<?php echo $OUTPUT->box_end(); ?> |
||||
|
<table align="center"><tr><th colspan="4" scope="row"><?php print_string('currentlyselectedusers'); ?></th></tr> |
||||
|
<?php |
||||
|
if (count($SESSION->emailto[$id])) { |
||||
|
foreach ($SESSION->emailto[$id] as $user) { |
||||
|
echo '<tr><td>'.fullname($user,true).'</td>'; |
||||
|
// Check to see if we should be showing the email address. |
||||
|
if ($user->maildisplay == 0) { // 0 = don't display my email to anyone. |
||||
|
echo '<td>' . get_string('emaildisplayhidden') . '</td><td>'; |
||||
|
} else { |
||||
|
echo '<td>'.$user->email.'</td><td>'; |
||||
|
} |
||||
|
if (empty($user->email)) { |
||||
|
$error = get_string('emailempty'); |
||||
|
} |
||||
|
if (!empty($error)) { |
||||
|
echo $OUTPUT->pix_icon('t/emailno', $error); |
||||
|
unset($error); |
||||
|
} |
||||
|
echo '</td><td><input type="submit" onClick="this.form.deluser.value='.$user->id.';" value="' . get_string('remove') . '" /></td></tr>'; |
||||
|
} |
||||
|
} |
||||
|
else { |
||||
|
echo '<tr><td colspan="3" align="center">'.get_string('nousersyet').'</td></tr>'; |
||||
|
} |
||||
|
?> |
||||
|
</table> |
||||
|
</form> |
@ -0,0 +1,181 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* Copied from Moodle 3.3 messageselect.php - allows sending messages to multiple users. |
||||
|
* |
||||
|
* @copyright 1999 Martin Dougiamas http://dougiamas.com |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
* @package mod_attendance |
||||
|
*/ |
||||
|
require_once('../../config.php'); |
||||
|
require_once($CFG->dirroot.'/message/lib.php'); |
||||
|
$id = required_param('id', PARAM_INT); |
||||
|
$messagebody = optional_param('messagebody', '', PARAM_CLEANHTML); |
||||
|
$send = optional_param('send', '', PARAM_BOOL); |
||||
|
$preview = optional_param('preview', '', PARAM_BOOL); |
||||
|
$edit = optional_param('edit', '', PARAM_BOOL); |
||||
|
$returnto = optional_param('returnto', '', PARAM_LOCALURL); |
||||
|
$format = optional_param('format', FORMAT_MOODLE, PARAM_INT); |
||||
|
$deluser = optional_param('deluser', 0, PARAM_INT); |
||||
|
$url = new moodle_url('/user/messageselect.php', array('id' => $id)); |
||||
|
if ($messagebody !== '') { |
||||
|
$url->param('messagebody', $messagebody); |
||||
|
} |
||||
|
if ($send !== '') { |
||||
|
$url->param('send', $send); |
||||
|
} |
||||
|
if ($preview !== '') { |
||||
|
$url->param('preview', $preview); |
||||
|
} |
||||
|
if ($edit !== '') { |
||||
|
$url->param('edit', $edit); |
||||
|
} |
||||
|
if ($returnto !== '') { |
||||
|
$url->param('returnto', $returnto); |
||||
|
} |
||||
|
if ($format !== FORMAT_MOODLE) { |
||||
|
$url->param('format', $format); |
||||
|
} |
||||
|
if ($deluser !== 0) { |
||||
|
$url->param('deluser', $deluser); |
||||
|
} |
||||
|
$PAGE->set_url($url); |
||||
|
if (!$course = $DB->get_record('course', array('id' => $id))) { |
||||
|
print_error('invalidcourseid'); |
||||
|
} |
||||
|
require_login($course); |
||||
|
$coursecontext = context_course::instance($id); // Course context. |
||||
|
$systemcontext = context_system::instance(); // SYSTEM context. |
||||
|
require_capability('moodle/course:bulkmessaging', $coursecontext); |
||||
|
if (empty($SESSION->emailto)) { |
||||
|
$SESSION->emailto = array(); |
||||
|
} |
||||
|
if (!array_key_exists($id, $SESSION->emailto)) { |
||||
|
$SESSION->emailto[$id] = array(); |
||||
|
} |
||||
|
if ($deluser) { |
||||
|
if (array_key_exists($id, $SESSION->emailto) && array_key_exists($deluser, $SESSION->emailto[$id])) { |
||||
|
unset($SESSION->emailto[$id][$deluser]); |
||||
|
} |
||||
|
} |
||||
|
if (empty($SESSION->emailselect[$id]) || $messagebody) { |
||||
|
$SESSION->emailselect[$id] = array('messagebody' => $messagebody); |
||||
|
} |
||||
|
$messagebody = $SESSION->emailselect[$id]['messagebody']; |
||||
|
$count = 0; |
||||
|
if ($data = data_submitted()) { |
||||
|
require_sesskey(); |
||||
|
$namefields = get_all_user_name_fields(true); |
||||
|
foreach ($data as $k => $v) { |
||||
|
if (preg_match('/^(user|teacher)(\d+)$/', $k, $m)) { |
||||
|
if (!array_key_exists($m[2], $SESSION->emailto[$id])) { |
||||
|
if ($user = $DB->get_record_select('user', "id = ?", array($m[2]), 'id, '. |
||||
|
$namefields . ', idnumber, email, mailformat, lastaccess, lang, '. |
||||
|
'maildisplay, auth, suspended, deleted, emailstop, username')) { |
||||
|
$SESSION->emailto[$id][$m[2]] = $user; |
||||
|
$count++; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if ($course->id == SITEID) { |
||||
|
$strtitle = get_string('sitemessage'); |
||||
|
$PAGE->set_pagelayout('admin'); |
||||
|
} else { |
||||
|
$strtitle = get_string('coursemessage'); |
||||
|
$PAGE->set_pagelayout('incourse'); |
||||
|
} |
||||
|
$link = null; |
||||
|
if (has_capability('moodle/course:viewparticipants', $coursecontext) || |
||||
|
has_capability('moodle/site:viewparticipants', $systemcontext)) { |
||||
|
$link = new moodle_url("/user/index.php", array('id' => $course->id)); |
||||
|
} |
||||
|
$PAGE->navbar->add(get_string('participants'), $link); |
||||
|
$PAGE->navbar->add($strtitle); |
||||
|
$PAGE->set_title($strtitle); |
||||
|
$PAGE->set_heading($strtitle); |
||||
|
echo $OUTPUT->header(); |
||||
|
|
||||
|
if ($count) { |
||||
|
if ($count == 1) { |
||||
|
$heading = get_string('addedrecip', 'moodle', $count); |
||||
|
} else { |
||||
|
$heading = get_string('addedrecips', 'moodle', $count); |
||||
|
} |
||||
|
echo $OUTPUT->heading($heading); |
||||
|
} |
||||
|
if (!empty($messagebody) && !$edit && !$deluser && ($preview || $send)) { |
||||
|
require_sesskey(); |
||||
|
if (count($SESSION->emailto[$id])) { |
||||
|
if (!empty($preview)) { |
||||
|
echo '<form method="post" action="messageselect.php" style="margin: 0 20px;"> |
||||
|
<input type="hidden" name="returnto" value="'.s($returnto).'" /> |
||||
|
<input type="hidden" name="id" value="'.$id.'" /> |
||||
|
<input type="hidden" name="format" value="'.$format.'" /> |
||||
|
<input type="hidden" name="sesskey" value="' . sesskey() . '" /> |
||||
|
'; |
||||
|
echo "<h3>".get_string('previewhtml')."</h3>"; |
||||
|
echo "<div class=\"messagepreview\">\n".format_text($messagebody, $format)."\n</div>\n"; |
||||
|
echo '<p align="center"><input type="submit" name="send" value="'.get_string('sendmessage', 'message').'" />'."\n"; |
||||
|
echo '<input type="submit" name="edit" value="'.get_string('update').'" /></p>'; |
||||
|
echo "\n</form>"; |
||||
|
} else if (!empty($send)) { |
||||
|
$fails = array(); |
||||
|
foreach ($SESSION->emailto[$id] as $user) { |
||||
|
if (!message_post_message($USER, $user, $messagebody, $format)) { |
||||
|
$user->fullname = fullname($user); |
||||
|
$fails[] = get_string('messagedselecteduserfailed', 'moodle', $user); |
||||
|
}; |
||||
|
} |
||||
|
if (empty($fails)) { |
||||
|
echo $OUTPUT->heading(get_string('messagedselectedusers')); |
||||
|
unset($SESSION->emailto[$id]); |
||||
|
unset($SESSION->emailselect[$id]); |
||||
|
} else { |
||||
|
echo $OUTPUT->heading(get_string('messagedselectedcountusersfailed', 'moodle', count($fails))); |
||||
|
echo '<ul>'; |
||||
|
foreach ($fails as $f) { |
||||
|
echo '<li>', $f, '</li>'; |
||||
|
} |
||||
|
echo '</ul>'; |
||||
|
} |
||||
|
echo '<p align="center"><a href="index.php?id='.$id.'">'.get_string('backtoparticipants').'</a></p>'; |
||||
|
} |
||||
|
echo $OUTPUT->footer(); |
||||
|
exit; |
||||
|
} else { |
||||
|
echo $OUTPUT->notification(get_string('nousersyet')); |
||||
|
} |
||||
|
} |
||||
|
echo '<p align="center"><a href="'.$returnto.'">'.get_string("keepsearching").'</a>'. |
||||
|
((count($SESSION->emailto[$id])) ? ', '.get_string('usemessageform') : '').'</p>'; |
||||
|
if ((!empty($send) || !empty($preview) || !empty($edit)) && (empty($messagebody))) { |
||||
|
echo $OUTPUT->notification(get_string('allfieldsrequired')); |
||||
|
} |
||||
|
if (count($SESSION->emailto[$id])) { |
||||
|
require_sesskey(); |
||||
|
require("message.html"); |
||||
|
} |
||||
|
$PAGE->requires->yui_module('moodle-core-formchangechecker', |
||||
|
'M.core_formchangechecker.init', |
||||
|
array(array( |
||||
|
'formid' => 'theform' |
||||
|
)) |
||||
|
); |
||||
|
$PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle'); |
||||
|
echo $OUTPUT->footer(); |
Loading…
Reference in new issue