This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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. |
||
19 | * |
||
20 | * This plugin allows you to set up paid courses. |
||
21 | * |
||
22 | * @package enrol |
||
23 | * @subpackage pagseguro |
||
24 | * @copyright 2010 Eugene Venter |
||
25 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||
26 | */ |
||
27 | |||
28 | defined('MOODLE_INTERNAL') || die(); |
||
29 | |||
30 | /** |
||
31 | * pagseguro enrolment plugin implementation. |
||
32 | * @author Eugene Venter - based on code by Martin Dougiamas and others |
||
33 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||
34 | */ |
||
35 | class enrol_pagseguro_plugin extends enrol_plugin { |
||
36 | |||
37 | /** |
||
38 | * Returns optional enrolment information icons. |
||
39 | * |
||
40 | * This is used in course list for quick overview of enrolment options. |
||
41 | * |
||
42 | * We are not using single instance parameter because sometimes |
||
43 | * we might want to prevent icon repetition when multiple instances |
||
44 | * of one type exist. One instance may also produce several icons. |
||
45 | * |
||
46 | * @param array $instances all enrol instances of this type in one course |
||
47 | * @return array of pix_icon |
||
48 | */ |
||
49 | public function get_info_icons(array $instances) { |
||
50 | return array(new pix_icon('icon', get_string('pluginname', 'enrol_pagseguro'), 'enrol_pagseguro')); |
||
51 | } |
||
52 | |||
53 | public function roles_protected() { |
||
54 | return false; |
||
55 | } |
||
56 | |||
57 | public function allow_unenrol(stdClass $instance) { |
||
58 | return true; |
||
59 | } |
||
60 | |||
61 | public function allow_manage(stdClass $instance) { |
||
62 | return true; |
||
63 | } |
||
64 | |||
65 | public function show_enrolme_link(stdClass $instance) { |
||
66 | return ($instance->status == ENROL_INSTANCE_ENABLED); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Sets up navigation entries. |
||
71 | * |
||
72 | * @param object $instance |
||
73 | * @return void |
||
74 | */ |
||
75 | public function add_course_navigation($instancesnode, stdClass $instance) { |
||
76 | if ($instance->enrol !== 'pagseguro') { |
||
77 | throw new coding_exception('Invalid enrol instance type!'); |
||
78 | } |
||
79 | |||
80 | $context = context_course::instance($instance->courseid); |
||
81 | if (has_capability('enrol/pagseguro:config', $context)) { |
||
82 | $managelink = new moodle_url('/enrol/pagseguro/edit.php', array('courseid' => $instance->courseid, 'id' => $instance->id)); |
||
83 | $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Returns edit icons for the page with list of instances |
||
89 | * @param stdClass $instance |
||
90 | * @return array |
||
91 | */ |
||
92 | public function get_action_icons(stdClass $instance) { |
||
93 | global $OUTPUT; |
||
94 | |||
95 | if ($instance->enrol !== 'pagseguro') { |
||
96 | throw new coding_exception('invalid enrol instance!'); |
||
97 | } |
||
98 | $context = context_course::instance($instance->courseid); |
||
99 | |||
100 | $icons = array(); |
||
101 | |||
102 | if (has_capability('enrol/pagseguro:config', $context)) { |
||
103 | $editlink = new moodle_url("/enrol/pagseguro/edit.php", array('courseid' => $instance->courseid, 'id' => $instance->id)); |
||
104 | $icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'icon'))); |
||
105 | } |
||
106 | |||
107 | return $icons; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Returns link to page which may be used to add new instance of enrolment plugin in course. |
||
112 | * @param int $courseid |
||
113 | * @return moodle_url page url |
||
114 | */ |
||
115 | public function get_newinstance_link($courseid) { |
||
116 | $context = context_course::instance($courseid); |
||
117 | |||
118 | if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/pagseguro:config', $context)) { |
||
119 | return null; |
||
120 | } |
||
121 | |||
122 | return new moodle_url('/enrol/pagseguro/edit.php', array('courseid' => $courseid)); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Creates course enrol form, checks if form submitted |
||
127 | * and enrols user if necessary. It can also redirect. |
||
128 | * |
||
129 | * @param stdClass $instance |
||
130 | * @return string html text, usually a form in a text box |
||
131 | */ |
||
132 | public function enrol_page_hook(stdClass $instance) { |
||
133 | global $CFG, $USER, $OUTPUT, $PAGE, $DB; |
||
134 | |||
135 | ob_start(); |
||
136 | |||
137 | if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) { |
||
138 | return ob_get_clean(); |
||
139 | } |
||
140 | |||
141 | if ($instance->enrolstartdate != 0 && $instance->enrolstartdate > time()) { |
||
142 | return ob_get_clean(); |
||
143 | } |
||
144 | |||
145 | if ($instance->enrolenddate != 0 && $instance->enrolenddate < time()) { |
||
146 | return ob_get_clean(); |
||
147 | } |
||
148 | |||
149 | $course = $DB->get_record('course', array('id' => $instance->courseid)); |
||
150 | $context = context_course::instance($instance->courseid); |
||
151 | |||
152 | $shortname = format_string($course->shortname, true, array('context' => $context)); |
||
153 | $strloginto = get_string("loginto", "", $shortname); |
||
154 | $strcourses = get_string("courses"); |
||
155 | |||
156 | // Pass $view=true to filter hidden caps if the user cannot see them. |
||
157 | View Code Duplication | if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', |
|
0 ignored issues
–
show
|
|||
158 | '', '', '', '', false, true)) { |
||
159 | $users = sort_by_roleassignment_authority($users, $context); |
||
160 | $teacher = array_shift($users); |
||
161 | } else { |
||
162 | $teacher = false; |
||
163 | } |
||
164 | |||
165 | if ( (float) $instance->cost <= 0 ) { |
||
166 | $cost = (float) $this->get_config('cost'); |
||
167 | } else { |
||
168 | $cost = (float) $instance->cost; |
||
169 | } |
||
170 | |||
171 | if (abs($cost) < 0.01) { // No cost, other enrolment methods (instances) should be used. |
||
172 | echo '<p>'.get_string('nocost', 'enrol_pagseguro').'</p>'; |
||
173 | } else { |
||
174 | |||
175 | if (isguestuser()) { // Force login only for guest user, not real users with guest role. |
||
176 | if (empty($CFG->loginhttps)) { |
||
177 | $wwwroot = $CFG->wwwroot; |
||
178 | } else { |
||
179 | // This actually is not so secure ;-), 'cause we're in unencrypted connection... |
||
180 | $wwwroot = str_replace("http://", "https://", $CFG->wwwroot); |
||
181 | } |
||
182 | echo '<div class="mdl-align"><p>'.get_string('paymentrequired').'</p>'; |
||
183 | echo '<p><b>'.get_string('cost').": $instance->currency $cost".'</b></p>'; |
||
184 | echo '<p><a href="'.$wwwroot.'/login/">'.get_string('loginsite').'</a></p>'; |
||
185 | echo '</div>'; |
||
186 | } else { |
||
187 | require_once("$CFG->dirroot/enrol/pagseguro/locallib.php"); |
||
188 | // Sanitise some fields before building the pagseguro form. |
||
189 | $coursefullname = format_string($course->fullname, true, array('context' => $context)); |
||
190 | $courseshortname = $shortname; |
||
191 | $userfullname = fullname($USER); |
||
192 | $userfirstname = $USER->firstname; |
||
193 | $userlastname = $USER->lastname; |
||
194 | $useraddress = $USER->address; |
||
195 | $usercity = $USER->city; |
||
196 | $instancename = $this->get_instance_name($instance); |
||
197 | |||
198 | $form = new enrol_pagseguro_enrol_form($CFG->wwwroot.'/enrol/pagseguro/process.php', $instance); |
||
199 | |||
200 | ob_start(); |
||
201 | $form->display(); |
||
202 | $output = ob_get_clean(); |
||
203 | return $OUTPUT->box($output); |
||
204 | } |
||
205 | |||
206 | } |
||
207 | |||
208 | return $OUTPUT->box(ob_get_clean()); |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Is it possible to delete enrol instance via standard UI? |
||
213 | * |
||
214 | * @param stdClass $instance |
||
215 | * @return bool |
||
216 | */ |
||
217 | public function can_delete_instance($instance) { |
||
218 | $context = context_course::instance($instance->courseid); |
||
219 | return has_capability('enrol/self:config', $context); |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * Is it possible to hide/show enrol instance via standard UI? |
||
224 | * |
||
225 | * @param stdClass $instance |
||
226 | * @return bool |
||
227 | */ |
||
228 | public function can_hide_show_instance($instance) { |
||
229 | $context = context_course::instance($instance->courseid); |
||
230 | return has_capability('enrol/pagseguro:config', $context); |
||
231 | } |
||
232 | |||
233 | } |
||
234 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.