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]

   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   * Manage one 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  $id = optional_param('id', 0, PARAM_INT);
  29  $delete = optional_param('delete', false, PARAM_BOOL);
  30  $restore = optional_param('restore', false, PARAM_BOOL);
  31  
  32  $pageurl = new moodle_url('/payment/manage_account.php');
  33  admin_externalpage_setup('paymentaccounts', '', [], $pageurl);
  34  
  35  $enabledplugins = \core\plugininfo\paygw::get_enabled_plugins();
  36  
  37  $account = new \core_payment\account($id);
  38  require_capability('moodle/payment:manageaccounts', $account->get_context());
  39  
  40  if ($delete && !$account->get('archived') && confirm_sesskey()) {
  41      \core_payment\helper::delete_payment_account($account);
  42      redirect(new moodle_url('/payment/accounts.php'));
  43  }
  44  if ($restore && $account->get('archived') && confirm_sesskey()) {
  45      \core_payment\helper::restore_payment_account($account);
  46      redirect(new moodle_url('/payment/accounts.php'));
  47  }
  48  
  49  $PAGE->set_secondary_active_tab('siteadminnode');
  50  $PAGE->set_primary_active_tab('siteadminnode');
  51  if ($id == 0) {
  52      $PAGE->navbar->add(get_string('createaccount', 'payment'), $PAGE->url);
  53  } else {
  54      $PAGE->navbar->add(get_string('editpaymentaccount', 'payment'), $PAGE->url);
  55  }
  56  
  57  $PAGE->set_heading($id ? format_string($account->get('name')) : get_string('createaccount', 'payment'));
  58  
  59  $form = new \core_payment\form\account($pageurl->out(false), ['persistent' => $account]);
  60  
  61  if ($form->is_cancelled()) {
  62      redirect(new moodle_url('/payment/accounts.php'));
  63  } else if ($data = $form->get_data()) {
  64      \core_payment\helper::save_payment_account($data);
  65      redirect(new moodle_url('/payment/accounts.php'));
  66  }
  67  
  68  echo $OUTPUT->header();
  69  $form->display();
  70  echo $OUTPUT->footer();