MDL-55999 lib: Update ADOdb to version 5.20.7
[moodle.git] / enrol / bulkchange_forms.php
blob46aca0c396d165b602a9dd4e227faba3606d5b7a
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.
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/>.
17 /**
18 * This file contains form for bulk changing user enrolments.
20 * @package core_enrol
21 * @copyright 2011 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once("$CFG->libdir/formslib.php");
29 /**
30 * A base class that can be used to easily construct a form for use with bulk operations
32 * @copyright 2011 Sam Hemelryk
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 abstract class enrol_bulk_enrolment_change_form extends moodleform {
37 /**
38 * Defines the standard structure of the form
40 protected function definition() {
41 $form = $this->_form;
42 $users = $this->_customdata['users'];
44 $statusoptions = $this->get_status_options();
45 $form->addElement('html', $this->get_users_table($users, $statusoptions));
46 $form->addElement('select', 'status', get_string('alterstatus', 'enrol_manual'), $statusoptions, array('optional' => true));
47 $form->addElement('date_time_selector', 'timestart', get_string('altertimestart', 'enrol_manual'), array('optional' => true));
48 $form->addElement('date_time_selector', 'timeend', get_string('altertimeend', 'enrol_manual'), array('optional' => true));
50 $this->add_action_buttons();
53 /**
54 * Returns an array of status options
55 * @return array
57 protected function get_status_options() {
58 return array(-1 => get_string('nochange', 'enrol'),
59 ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
60 ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
63 /**
64 * Generates an HTML table to display the users being affected by the bulk change.
66 * @param array $users
67 * @param array $statusoptions
68 * @return string
70 protected function get_users_table(array $users, array $statusoptions) {
71 $table = new html_table();
72 $table->head = array(
73 get_string('name'),
74 get_string('participationstatus', 'enrol'),
75 get_string('enroltimestart', 'enrol'),
76 get_string('enroltimeend', 'enrol'),
78 $table->data = array();
79 foreach ($users as $user) {
80 foreach ($user->enrolments as $enrolment) {
81 $input = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'bulkuser[]', 'value' => $user->id));
82 $table->data[] = array(
83 fullname($user).$input,
84 $statusoptions[$enrolment->status],
85 (!empty($enrolment->timestart))?userdate($enrolment->timestart):'',
86 (!empty($enrolment->timeend))?userdate($enrolment->timeend):'',
90 return html_writer::table($table);
94 /**
95 * A convenience class to allow the quick generation of a confirmation form for a bulk operation.
96 * @copyright 2011 Sam Hemelryk
97 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
99 abstract class enrol_bulk_enrolment_confirm_form extends enrol_bulk_enrolment_change_form {
102 * Defines the standard structure of the form
104 protected function definition() {
105 $form = $this->_form;
106 $users = $this->_customdata['users'];
107 $title = $this->_customdata['title'];
108 $message = $this->_customdata['message'];
109 $button = $this->_customdata['button'];
111 $form->addElement('html', $this->get_users_table($users, $this->get_status_options()));
112 $form->addElement('header', 'ebecf_header', $title);
113 $form->addElement('html', html_writer::tag('p', $message));
114 $this->add_action_buttons(true, $button);