|
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
|
|
|
* pagseguro enrolment plugin - support for user self unenrolment. |
|
19
|
|
|
* |
|
20
|
|
|
* @package enrol |
|
21
|
|
|
* @subpackage pagseguro |
|
22
|
|
|
* @copyright 2010 Petr Skoda {@link http://skodak.org} |
|
23
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
require('../../config.php'); |
|
27
|
|
|
|
|
28
|
|
|
$enrolid = required_param('enrolid', PARAM_INT); |
|
29
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL); |
|
30
|
|
|
|
|
31
|
|
|
$instance = $DB->get_record('enrol', array('id' => $enrolid, 'enrol' => 'pagseguro'), '*', MUST_EXIST); |
|
32
|
|
|
$course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST); |
|
33
|
|
|
$context = context_course::instance($course->id); |
|
34
|
|
|
|
|
35
|
|
|
require_login(); |
|
36
|
|
|
if (!is_enrolled($context)) { |
|
37
|
|
|
redirect(new moodle_url('/')); |
|
38
|
|
|
} |
|
39
|
|
|
require_login($course); |
|
40
|
|
|
|
|
41
|
|
|
$plugin = enrol_get_plugin('pagseguro'); |
|
42
|
|
|
|
|
43
|
|
|
// security defined inside following function |
|
44
|
|
|
if (!$plugin->get_unenrolself_link($instance)) { |
|
45
|
|
|
redirect(new moodle_url('/course/view.php', array('id' => $course->id))); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$PAGE->set_url('/enrol/pagseguro/unenrolself.php', array('enrolid' => $instance->id)); |
|
49
|
|
|
$PAGE->set_title($plugin->get_instance_name($instance)); |
|
50
|
|
|
|
|
51
|
|
|
if ($confirm and confirm_sesskey()) { |
|
|
|
|
|
|
52
|
|
|
$plugin->unenrol_user($instance, $USER->id); |
|
53
|
|
|
// TODO: trigger event. |
|
54
|
|
|
redirect(new moodle_url('/index.php')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
echo $OUTPUT->header(); |
|
58
|
|
|
$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey())); |
|
59
|
|
|
$nourl = new moodle_url('/course/view.php', array('id' => $course->id)); |
|
60
|
|
|
$message = get_string('unenrolselfconfirm', 'enrol_pagseguro', format_string($course->fullname)); |
|
61
|
|
|
echo $OUTPUT->confirm($message, $yesurl, $nourl); |
|
62
|
|
|
echo $OUTPUT->footer(); |
|
63
|
|
|
|
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.