Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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      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')));
  72          }
  73      }
  74  
  75      $table->data[] = [$name, join(', ', $gateways), $OUTPUT->render($menu)];
  76  }
  77  
  78  echo html_writer::div(get_string('paymentaccountsexplained', 'payment'), 'pb-2');
  79  
  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');
  86  }
  87  
  88  echo html_writer::table($table);
  89  
  90  $PAGE->requires->event_handler('[data-action=delete]', 'click', 'M.util.show_confirm_dialog',
  91      array('message' => get_string('accountdeleteconfirm', 'payment')));
  92  
  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');
  95  
  96  echo $OUTPUT->single_button(new moodle_url('/payment/manage_account.php'), get_string('createaccount', 'payment'), 'get');
  97  
  98  echo $OUTPUT->footer();