Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 400 and 401] [Versions 401 and 403]

   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   * Management of payment accounts
  19   *
  20   * @package    core_payment
  21   * @copyright  2020 Marina Glancy
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../config.php');
  26  require_once($CFG->libdir . '/adminlib.php');
  27  
  28  $showarchived = optional_param('showarchived', false, PARAM_BOOL);
  29  
  30  admin_externalpage_setup('paymentaccounts');
  31  $PAGE->set_heading(get_string('paymentaccounts', 'payment'));
  32  
  33  $PAGE->set_primary_active_tab('siteadminnode');
  34  
  35  $enabledplugins = \core\plugininfo\paygw::get_enabled_plugins();
  36  
  37  echo $OUTPUT->header();
  38  
  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());
  52      }
  53      $name = $account->get_formatted_name();
  54      if (!$account->is_available()) {
  55          $name .= ' ' . html_writer::span(get_string('accountnotavailable', 'payment'), 'badge badge-warning');
  56      }
  57      if ($account->get('archived')) {
  58          $name .= ' ' . html_writer::span(get_string('accountarchived', 'payment'), 'badge badge-secondary');
  59      }
  60  
  61      $menu = new action_menu();
  62      $menu->set_menu_trigger(get_string('edit'));
  63      $menu->set_boundary('window');
  64      if ($canmanage) {
  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-action' => 'delete']));
  70          } else {
  71              $restoreurl = $account->get_edit_url(['restore' => 1, 'sesskey' => sesskey()]);
  72              $menu->add(new action_menu_link_secondary($restoreurl, null, get_string('restoreaccount', 'payment')));
  73          }
  74      }
  75  
  76      $table->data[] = [$name, join(', ', $gateways), $OUTPUT->render($menu)];
  77  }
  78  
  79  echo html_writer::div(get_string('paymentaccountsexplained', 'payment'), 'pb-2');
  80  
  81  if (has_capability('moodle/site:config', context_system::instance())) {
  82      // For administrators add a link to "Manage payment gateways" page.
  83      $link = html_writer::link(new moodle_url('/admin/settings.php', ['section' => 'managepaymentgateways']),
  84          get_string('type_paygwmanage', 'plugin'));
  85      $text = get_string('gotomanageplugins', 'payment', $link);
  86      echo html_writer::div($text, 'pb-2');
  87  }
  88  
  89  echo html_writer::div(html_writer::table($table), 'position-relative');
  90  
  91  $PAGE->requires->event_handler('[data-action=delete]', 'click', 'M.util.show_confirm_dialog',
  92      array('message' => get_string('accountdeleteconfirm', 'payment')));
  93  
  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');
  96  
  97  echo $OUTPUT->single_button(new moodle_url('/payment/manage_account.php'), get_string('createaccount', 'payment'), 'get');
  98  
  99  echo $OUTPUT->footer();