Merge branch 'test' into prod

This commit is contained in:
Erik Thuning 2024-02-09 11:43:50 +01:00
commit 6ad29ccd7d
8 changed files with 61 additions and 8 deletions

@ -6,6 +6,9 @@ $db_user = 'dbname';
$db_pass = 'dbpassword'; $db_pass = 'dbpassword';
$db_name = 'dbuser'; $db_name = 'dbuser';
# Email subject prefix
$email_subject_prefix = "System name: ";
# Address to use as the sender for reminder emails # Address to use as the sender for reminder emails
$sender = 'noreply@example.com'; $sender = 'noreply@example.com';
@ -15,7 +18,7 @@ $error_address = 'root@example.com';
# Discard notifications # Discard notifications
# If this is set to an email address, the system will send a notification # If this is set to an email address, the system will send a notification
# there each time a product is discarded. # there each time a product is discarded.
#$notify_discard = 'inventory-tracking@example.com'; #$discard_notify = 'inventory-tracking@example.com';
$discard_notify = false; $discard_notify = false;
# Directory to save attachments to # Directory to save attachments to

@ -7,7 +7,7 @@ require('./include/functions.php');
header('Content-Type: text/html; charset=UTF-8'); header('Content-Type: text/html; charset=UTF-8');
$cron = new Cron($sender, $error_address); $cron = new Cron($sender, $error_address, $email_subject_prefix);
$cron->run(); $cron->run();
?> ?>

@ -306,6 +306,8 @@
<button>Ladda upp</button> <button>Ladda upp</button>
</form> </form>
</div> </div>
¤¤ product_meta ¤¤
<div id="product-history"> <div id="product-history">
<h2>Artikelhistorik</h2> <h2>Artikelhistorik</h2>
¤history¤ ¤history¤

@ -164,7 +164,7 @@ class Ajax extends Responder {
} }
$product = null; $product = null;
try { try {
$product = new Product($_POST['serial'], 'serial'); $product = new Product(trim($_POST['serial']), 'serial');
} catch(Exception $e) { } catch(Exception $e) {
return new Failure('Ogiltigt serienummer.'); return new Failure('Ogiltigt serienummer.');
} }

@ -5,10 +5,11 @@ class Cron {
private $error = ''; private $error = '';
private $kvs; private $kvs;
private $ldap; private $ldap;
public function __construct($sender, $error) { public function __construct($sender, $error, $prefix) {
$this->now = new DateTimeImmutable(); $this->now = new DateTimeImmutable();
$this->sender = $sender; $this->sender = $sender;
$this->error = $error; $this->error = $error;
$this->subject_prefix = $prefix;
$this->warn_time = DateInterval::createFromDateString('3 days'); $this->warn_time = DateInterval::createFromDateString('3 days');
$this->warn_date = $this->now->add($this->warn_time); $this->warn_date = $this->now->add($this->warn_time);
$this->run_interval = DateInterval::createFromDateString('1 day'); $this->run_interval = DateInterval::createFromDateString('1 day');
@ -108,7 +109,7 @@ class Cron {
} }
private function make_receipt_subject($num_new, $num_extended) { private function make_receipt_subject($num_new, $num_extended) {
$subject = "DSV Helpdesk: "; $subject = $this->subject_prefix;
$messages = array(); $messages = array();
if($num_new > 1) { if($num_new > 1) {
$messages[] = $num_new." nya"; $messages[] = $num_new." nya";
@ -206,7 +207,7 @@ EOF;
} }
private function make_reminder_subject($num_expiring, $num_expired) { private function make_reminder_subject($num_expiring, $num_expired) {
$subject = "DSV Helpdesk: "; $subject = $this->subject_prefix;
$messages = array(); $messages = array();
if($num_expiring > 0) { if($num_expiring > 0) {
$messages[] = $num_expiring." utgående"; $messages[] = $num_expiring." utgående";

@ -68,6 +68,13 @@ class Product extends Entity {
$this->update_fields(); $this->update_fields();
$this->update_info(); $this->update_info();
$this->update_tags(); $this->update_tags();
# Global variables are bad, but passing these email properties
# around everywhere would be worse
global $sender, $notify_discard, $email_subject_prefix;
$this->discard_email_address = $notify_discard;
$this->email_sender = $sender;
$this->email_subject_prefix = $email_subject_prefix;
} }
private function update_fields() { private function update_fields() {
@ -272,9 +279,42 @@ class Product extends Entity {
bind($update, 'ii', $now, $this->id); bind($update, 'ii', $now, $this->id);
execute($update); execute($update);
$this->discardtime = $now; $this->discardtime = $now;
if($this->discard_email_address) {
$this->send_discard_email();
}
return true; return true;
} }
private function send_discard_email() {
$brand = $this->brand;
$name = $this->name;
$invoice = $this->invoice;
$serial = $this->serial;
$discardtime = format_date($this->discardtime);
$subject = $this->email_subject_prefix.$brand.' '.$name.' skrotad';
$message = <<<EOF
Hej!
Följande artikel har skrotats i Boka:
$brand $name, serienummer: $serial, fakturanummer: $invoice
EOF;
try {
mb_send_mail($this->discard_email_address,
$subject,
$message,
'From: '.$this->email_sender);
} catch(Exception $e) {
error_log($e->getMessage());
mb_send_mail($this->error,
"Kunde inte skicka mail",
"Mail kunde inte skickas till "
. $this->discard_email_address);
}
}
public function toggle_service() { public function toggle_service() {
$status = $this->get_status(); $status = $this->get_status();
$now = time(); $now = time();

@ -69,6 +69,7 @@ class ProductPage extends Page {
'label' => '', 'label' => '',
'label_hidden' => 'hidden', 'label_hidden' => 'hidden',
'checkout_hidden' => 'hidden', 'checkout_hidden' => 'hidden',
'hidden' => '',
'service' => 'Starta service', 'service' => 'Starta service',
'history' => $history, 'history' => $history,
'attachments' => $attachments, 'attachments' => $attachments,
@ -86,7 +87,9 @@ class ProductPage extends Page {
$fields['checkout_hidden'] = ''; $fields['checkout_hidden'] = '';
} }
} }
return replace($fields, $this->fragments['product_form']); $out = replace($fields, $this->fragments['product_form']);
$out .= replace($fields, $this->fragments['product_meta']);
return $out;
} }
private function build_history_table($history) { private function build_history_table($history) {

@ -1,3 +1,7 @@
body {
font-size: 90%;
}
textarea { textarea {
height: 80px; height: 80px;
} }