Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Bulk user actions
19
 *
20
 * @package    core
21
 * @copyright  Moodle
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once('../../config.php');
26
require_once($CFG->libdir.'/adminlib.php');
27
require_once($CFG->dirroot.'/'.$CFG->admin.'/user/lib.php');
28
require_once($CFG->dirroot.'/'.$CFG->admin.'/user/user_bulk_forms.php');
29
 
30
admin_externalpage_setup('userbulk');
31
 
32
if (!isset($SESSION->bulk_users)) {
33
    $SESSION->bulk_users = array();
34
}
35
// Create the user filter form.
36
$ufiltering = new user_filtering();
37
 
38
// Create the bulk operations form.
39
$actionform = new user_bulk_action_form();
40
$actionform->set_data(['returnurl' => $PAGE->url->out_as_local_url(false)]);
41
if ($data = $actionform->get_data()) {
42
    if ($data->passuserids) {
43
        // This means we called the form from /admin/user.php or similar and the userids should be taken from the form
44
        // data and not from $SESSION->bulk_users. For backwards compatibility we still set $SESSION->bulk_users.
45
        $users = preg_split('/,/', $data->userids, -1, PREG_SPLIT_NO_EMPTY);
46
        $SESSION->bulk_users = array_combine($users, $users);
47
    }
48
    // Check if an action should be performed and do so.
49
    $bulkactions = $actionform->get_actions();
50
    if (array_key_exists($data->action, $bulkactions)) {
51
        redirect(new moodle_url($bulkactions[$data->action]->url, ['returnurl' => $data->returnurl ?: null]));
52
    }
53
 
54
}
55
 
56
$userbulkform = new user_bulk_form(null, get_selection_data($ufiltering));
57
 
58
if ($data = $userbulkform->get_data()) {
59
    if (!empty($data->addall)) {
60
        add_selection_all($ufiltering);
61
 
62
    } else if (!empty($data->addsel)) {
63
        if (!empty($data->ausers)) {
64
            if (in_array(0, $data->ausers)) {
65
                add_selection_all($ufiltering);
66
            } else {
67
                foreach ($data->ausers as $userid) {
68
                    if ($userid == -1) {
69
                        continue;
70
                    }
71
                    if (!isset($SESSION->bulk_users[$userid])) {
72
                        $SESSION->bulk_users[$userid] = $userid;
73
                    }
74
                }
75
            }
76
        }
77
 
78
    } else if (!empty($data->removeall)) {
79
        $SESSION->bulk_users = array();
80
 
81
    } else if (!empty($data->removesel)) {
82
        if (!empty($data->susers)) {
83
            if (in_array(0, $data->susers)) {
84
                $SESSION->bulk_users = array();
85
            } else {
86
                foreach ($data->susers as $userid) {
87
                    if ($userid == -1) {
88
                        continue;
89
                    }
90
                    unset($SESSION->bulk_users[$userid]);
91
                }
92
            }
93
        }
94
    }
95
 
96
    // Reset the form selections.
97
    unset($_POST);
98
    $userbulkform = new user_bulk_form(null, get_selection_data($ufiltering));
99
}
100
echo $OUTPUT->header();
101
 
102
$ufiltering->display_add();
103
$ufiltering->display_active();
104
 
105
$userbulkform->display();
106
 
107
$actionform->display();
108
 
109
echo $OUTPUT->footer();