forked from iplusacademy/moodle-report_payments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
118 lines (105 loc) · 4.02 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?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/>.
/**
* Global payments.
*
* @package report_payments
* @copyright 2023 Medical Access Uganda Limited
* @author Renaat Debleu <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core\report_helper;
use report_payments\reportbuilder\local\systemreports\{payments_course, payments_global, payments_user};
use core_reportbuilder\system_report_factory;
use core_reportbuilder\external\system_report_exporter;
require_once(dirname(__FILE__) . '/../../config.php');
require_once("{$CFG->libdir}/adminlib.php");
$courseid = optional_param('courseid', 1, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$categoryid = optional_param('categoryid', 0, PARAM_INT);
$download = optional_param('download', false, PARAM_BOOL);
$filter = optional_param('filter', null, PARAM_TEXT);
$recurrent = optional_param('cancel', null, PARAM_INT);
if ($courseid == 1) {
if ($categoryid != 0) {
$context = \context_coursecat::instance($categoryid);
$params = ['categoryid' => $categoryid];
$classname = payments_global::class;
} else if ($userid != 0) {
$context = \context_user::instance($userid);
$params = ['userid' => $userid];
$classname = payments_user::class;
} else {
$context = \context_system::instance();
$params = ['courseid' => $courseid];
$classname = payments_global::class;
}
} else {
$context = \context_course::instance($courseid);
$params = ['courseid' => $courseid];
$classname = payments_course::class;
}
require_login();
// Delete recurrent payment from database.
if ($recurrent > 0) {
require_sesskey();
// Get payment.
if ($payment = $DB->get_record('payments', ['id' => $recurrent])) {
// Check userid.
if ($payment->userid == $USER->id || is_siteadmin()) {
// Get id.
$gateway = 'paygw_' . $payment->gateway;
if ($paytx = $DB->get_record($gateway, ['paymentid' => $recurrent])) {
// Do real update.
$paytx->recurrent = 0;
$paytx->invoiceid = 'deleted by user';
$DB->update_record($gateway, $paytx);
}
}
}
if (!is_siteadmin()) {
$params = ['userid' => $USER->id];
}
redirect(new \moodle_url('/report/payments/index.php', $params));
}
$PAGE->set_url(new \moodle_url('/report/payments/index.php', $params));
$PAGE->set_pagelayout('report');
$PAGE->set_context($context);
$strheading = get_string('payments', 'report_payments');
$PAGE->set_title($strheading);
switch ($context->contextlevel) {
case CONTEXT_COURSECAT:
core_course_category::page_setup();
break;
case CONTEXT_COURSE:
$course = get_course($courseid);
$PAGE->set_heading($course->fullname);
$PAGE->set_course($course);
break;
default:
$PAGE->set_heading($strheading);
}
\report_payments\event\report_viewed::create(['context' => $context])->trigger();
$report = system_report_factory::create($classname, $context);
if (!empty($filter)) {
$report->set_filter_values(['payment:name_values' => $filter]);
}
echo $OUTPUT->header();
// $pluginname = get_string('pluginname', 'report_payments');
// report_helper::print_report_selector($pluginname);
echo get_string('cancel_helper', 'report_payments');
echo $report->output();
echo $OUTPUT->footer();