Erik Thuning e640c24515 FIX: Initiating a loan from a product no longer requires the user to already exist.
Loans created on the checkout page and the product page used different
functions to look up users, causing inconsistent behaviour. Now both use the
"advanced" user lookup that will initialize users that don't currently exist
in the system.
2025-03-13 14:49:34 +01:00

61 lines
2.2 KiB
PHP

<?php
class CheckoutPage extends Page {
private $userstr = '';
private $emailstr = '';
private $user = null;
public function __construct() {
parent::__construct();
if(isset($_GET['user'])) {
$this->userstr = trim(strtolower($_GET['user']));
}
if(isset($_GET['email'])) {
$this->emailstr = trim(strtolower($_GET['email']));
}
try {
$this->user = $this->user_init($this->userstr,
$this->emailstr);
} catch(Exception $e) {
$this->error = $e->getMessage();
}
}
protected function render_body() {
$username = $this->userstr;
$email = $this->emailstr;
$displayname = '';
$notes = '';
$loan_table = '';
$subhead = '';
$enddate = '';
$disabled = 'disabled';
if($this->user !== null) {
$username = $this->user->get_name();
$email = $this->user->get_email($this->ldap);
$displayname = $this->user->get_displayname($this->ldap);
$notes = $this->user->get_notes();
$enddate = format_date(default_loan_end());
$disabled = '';
$loans = $this->user->get_loans('active');
$loan_table = i18n('No active loans.');
if($loans) {
$loan_table = $this->build_user_loan_table($loans);
}
$subhead = replace(array('title' => i18n('Borrowed products')),
$this->fragments['subtitle']);
}
$loan_presets = $this->build_loan_preset_buttons();
print(replace(array('user' => $username,
'email' => $email,
'displayname' => $displayname,
'notes' => $notes,
'end' => $enddate,
'subtitle' => $subhead,
'disabled' => $disabled,
'loan_table' => $loan_table,
'loan_presets' => $loan_presets),
$this->fragments['checkout_page']));
}
}
?>