MDL-76617 store_mongodb: Update mongo-php-library to v1.15.0
[moodle.git] / payment / accounts.php
bloba612cf84a4264fdf6c8a333e3f0602140ecd2ac0
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 * Management of payment accounts
20 * @package core_payment
21 * @copyright 2020 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__ . '/../config.php');
26 require_once($CFG->libdir . '/adminlib.php');
28 $showarchived = optional_param('showarchived', false, PARAM_BOOL);
30 admin_externalpage_setup('paymentaccounts');
31 $PAGE->set_heading(get_string('paymentaccounts', 'payment'));
33 $PAGE->set_primary_active_tab('siteadminnode');
35 $enabledplugins = \core\plugininfo\paygw::get_enabled_plugins();
37 echo $OUTPUT->header();
39 $accounts = \core_payment\helper::get_payment_accounts_to_manage(context_system::instance(), $showarchived);
40 $table = new html_table();
41 $table->head = [get_string('accountname', 'payment'), get_string('type_paygw_plural', 'plugin'), ''];
42 $table->colclasses = ['', '', 'mdl-right'];
43 $table->data = [];
44 foreach ($accounts as $account) {
45 $gateways = [];
46 $canmanage = has_capability('moodle/payment:manageaccounts', $account->get_context());
47 foreach ($account->get_gateways() as $gateway) {
48 $status = $gateway->get('enabled') ? $OUTPUT->pix_icon('i/valid', get_string('gatewayenabled', 'payment')) :
49 $OUTPUT->pix_icon('i/invalid', get_string('gatewaydisabled', 'payment'));
50 $gateways[] = $status .
51 ($canmanage ? html_writer::link($gateway->get_edit_url(), $gateway->get_display_name()) : $gateway->get_display_name());
53 $name = $account->get_formatted_name();
54 if (!$account->is_available()) {
55 $name .= ' ' . html_writer::span(get_string('accountnotavailable', 'payment'), 'badge badge-warning');
57 if ($account->get('archived')) {
58 $name .= ' ' . html_writer::span(get_string('accountarchived', 'payment'), 'badge badge-secondary');
61 $menu = new action_menu();
62 $menu->set_menu_trigger(get_string('edit'));
63 if ($canmanage) {
64 $menu->add(new action_menu_link_secondary($account->get_edit_url(), null, get_string('edit')));
65 if (!$account->get('archived')) {
66 $deleteurl = $account->get_edit_url(['delete' => 1, 'sesskey' => sesskey()]);
67 $menu->add(new action_menu_link_secondary($deleteurl, null, get_string('deleteorarchive', 'payment'),
68 ['data-action' => 'delete']));
69 } else {
70 $restoreurl = $account->get_edit_url(['restore' => 1, 'sesskey' => sesskey()]);
71 $menu->add(new action_menu_link_secondary($restoreurl, null, get_string('restoreaccount', 'payment')));
75 $table->data[] = [$name, join(', ', $gateways), $OUTPUT->render($menu)];
78 echo html_writer::div(get_string('paymentaccountsexplained', 'payment'), 'pb-2');
80 if (has_capability('moodle/site:config', context_system::instance())) {
81 // For administrators add a link to "Manage payment gateways" page.
82 $link = html_writer::link(new moodle_url('/admin/settings.php', ['section' => 'managepaymentgateways']),
83 get_string('type_paygwmanage', 'plugin'));
84 $text = get_string('gotomanageplugins', 'payment', $link);
85 echo html_writer::div($text, 'pb-2');
88 echo html_writer::table($table);
90 $PAGE->requires->event_handler('[data-action=delete]', 'click', 'M.util.show_confirm_dialog',
91 array('message' => get_string('accountdeleteconfirm', 'payment')));
93 echo html_writer::div(html_writer::link(new moodle_url($PAGE->url, ['showarchived' => !$showarchived]),
94 $showarchived ? get_string('hidearchived', 'payment') : get_string('showarchived', 'payment')), 'mdl-right');
96 echo $OUTPUT->single_button(new moodle_url('/payment/manage_account.php'), get_string('createaccount', 'payment'), 'get');
98 echo $OUTPUT->footer();