2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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'];
44 foreach ($accounts as $account) {
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 bg-warning text-dark');
57 if ($account->get('archived')) {
58 $name .= ' ' . html_writer
::span(get_string('accountarchived', 'payment'), 'badge bg-secondary text-dark');
61 $menu = new action_menu();
62 $menu->set_menu_trigger(get_string('edit'));
63 $menu->set_boundary('window');
65 $menu->add(new action_menu_link_secondary($account->get_edit_url(), null, get_string('edit')));
66 if (!$account->get('archived')) {
67 $deleteurl = $account->get_edit_url(['delete' => 1, 'sesskey' => sesskey()]);
68 $menu->add(new action_menu_link_secondary($deleteurl, null, get_string('deleteorarchive', 'payment'), [
69 'data-modal' => 'confirmation',
70 'data-modal-type' => 'delete',
71 'data-modal-content-str' => json_encode(['accountdeleteconfirm', 'payment']),
74 $restoreurl = $account->get_edit_url(['restore' => 1, 'sesskey' => sesskey()]);
75 $menu->add(new action_menu_link_secondary($restoreurl, null, get_string('restoreaccount', 'payment')));
79 $table->data
[] = [$name, join(', ', $gateways), $OUTPUT->render($menu)];
82 echo html_writer
::div(get_string('paymentaccountsexplained', 'payment'), 'pb-2');
84 if (has_capability('moodle/site:config', context_system
::instance())) {
85 // For administrators add a link to "Manage payment gateways" page.
86 $link = html_writer
::link(new moodle_url('/admin/settings.php', ['section' => 'managepaymentgateways']),
87 get_string('type_paygwmanage', 'plugin'));
88 $text = get_string('gotomanageplugins', 'payment', $link);
89 echo html_writer
::div($text, 'pb-2');
92 echo html_writer
::div(html_writer
::table($table), 'position-relative');
94 echo html_writer
::div(html_writer
::link(new moodle_url($PAGE->url
, ['showarchived' => !$showarchived]),
95 $showarchived ?
get_string('hidearchived', 'payment') : get_string('showarchived', 'payment')), 'mdl-right');
97 echo $OUTPUT->single_button(new moodle_url('/payment/manage_account.php'), get_string('createaccount', 'payment'), 'get');
99 echo $OUTPUT->footer();