diff --git a/config.php.example b/config.php.example index 02408e6..a0633ee 100644 --- a/config.php.example +++ b/config.php.example @@ -20,6 +20,9 @@ $language = 'en'; # Site name $name = 'My product tracker'; +# Default loan length +$default_loan_length = '1 day'; + # Email subject prefix # Will be prepended without change, so should probably end with a space $email_subject_prefix = "System name: "; diff --git a/include/CheckoutPage.php b/include/CheckoutPage.php index 797b047..17cdd2a 100644 --- a/include/CheckoutPage.php +++ b/include/CheckoutPage.php @@ -85,7 +85,7 @@ class CheckoutPage extends Page { $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(time())); + $enddate = format_date(default_loan_end()); $disabled = ''; $loans = $this->user->get_loans('active'); $loan_table = i18n('No active loans.'); diff --git a/include/ProductPage.php b/include/ProductPage.php index 3d0f72f..c22c72e 100644 --- a/include/ProductPage.php +++ b/include/ProductPage.php @@ -84,7 +84,7 @@ class ProductPage extends Page { 'service' => i18n('Start service'), 'history' => $history, 'attachments' => $attachments, - 'end' => format_date(default_loan_end(time()))); + 'end' => format_date(default_loan_end())); if(class_exists('QRcode')) { $fields['label'] = replace($fields, $this->fragments['product_label']); @@ -123,7 +123,7 @@ class ProductPage extends Page { $this->fragments['item_link']); if(!$end) { $end = $event->get_endtime(); - $extend = format_date(default_loan_end(time())); + $extend = format_date(default_loan_end()); $note = replace(array('id' => $product->get_id(), 'end_new' => $extend), $this->fragments['loan_extend_form']); diff --git a/include/functions.php b/include/functions.php index 49f2ce1..be4eae9 100644 --- a/include/functions.php +++ b/include/functions.php @@ -287,8 +287,12 @@ function format_date($date) { return $date; } -function default_loan_end($start) { - return $start + 604800; # 1 week later +function default_loan_end() { + global $default_loan_length; + $now = new DateTimeImmutable(); + $duration = DateInterval::createFromDateString($default_loan_length); + $end = $now->add($duration); + return $end->getTimestamp(); }