diff --git a/config.php.example b/config.php.example index 9a6fbb8..32cc899 100644 --- a/config.php.example +++ b/config.php.example @@ -6,6 +6,9 @@ $db_user = 'dbname'; $db_pass = 'dbpassword'; $db_name = 'dbuser'; +# Email subject prefix +$email_subject_prefix = "System name: "; + # Address to use as the sender for reminder emails $sender = 'noreply@example.com'; @@ -15,7 +18,7 @@ $error_address = 'root@example.com'; # Discard notifications # If this is set to an email address, the system will send a notification # there each time a product is discarded. -#$notify_discard = 'inventory-tracking@example.com'; +#$discard_notify = 'inventory-tracking@example.com'; $discard_notify = false; # Directory to save attachments to diff --git a/cron.php b/cron.php index 5e52909..7761e2f 100755 --- a/cron.php +++ b/cron.php @@ -7,7 +7,7 @@ require('./include/functions.php'); 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(); ?> diff --git a/html/fragments.html b/html/fragments.html index 3fade23..dcaca53 100644 --- a/html/fragments.html +++ b/html/fragments.html @@ -306,6 +306,8 @@ <button>Ladda upp</button> </form> </div> + +¤¤ product_meta ¤¤ <div id="product-history"> <h2>Artikelhistorik</h2> ¤history¤ diff --git a/include/Ajax.php b/include/Ajax.php index 99abc22..bc4a4cc 100644 --- a/include/Ajax.php +++ b/include/Ajax.php @@ -164,7 +164,7 @@ class Ajax extends Responder { } $product = null; try { - $product = new Product($_POST['serial'], 'serial'); + $product = new Product(trim($_POST['serial']), 'serial'); } catch(Exception $e) { return new Failure('Ogiltigt serienummer.'); } diff --git a/include/Cron.php b/include/Cron.php index f0f41a0..9fcaed8 100644 --- a/include/Cron.php +++ b/include/Cron.php @@ -5,10 +5,11 @@ class Cron { private $error = ''; private $kvs; private $ldap; - public function __construct($sender, $error) { + public function __construct($sender, $error, $prefix) { $this->now = new DateTimeImmutable(); $this->sender = $sender; $this->error = $error; + $this->subject_prefix = $prefix; $this->warn_time = DateInterval::createFromDateString('3 days'); $this->warn_date = $this->now->add($this->warn_time); $this->run_interval = DateInterval::createFromDateString('1 day'); @@ -108,7 +109,7 @@ class Cron { } private function make_receipt_subject($num_new, $num_extended) { - $subject = "DSV Helpdesk: "; + $subject = $this->subject_prefix; $messages = array(); if($num_new > 1) { $messages[] = $num_new." nya"; @@ -206,7 +207,7 @@ EOF; } private function make_reminder_subject($num_expiring, $num_expired) { - $subject = "DSV Helpdesk: "; + $subject = $this->subject_prefix; $messages = array(); if($num_expiring > 0) { $messages[] = $num_expiring." utgående"; diff --git a/include/Product.php b/include/Product.php index 1f4468c..a13c1b3 100644 --- a/include/Product.php +++ b/include/Product.php @@ -68,6 +68,13 @@ class Product extends Entity { $this->update_fields(); $this->update_info(); $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() { @@ -272,9 +279,42 @@ class Product extends Entity { bind($update, 'ii', $now, $this->id); execute($update); $this->discardtime = $now; + if($this->discard_email_address) { + $this->send_discard_email(); + } 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() { $status = $this->get_status(); $now = time(); diff --git a/include/ProductPage.php b/include/ProductPage.php index b0fefb4..bef9807 100644 --- a/include/ProductPage.php +++ b/include/ProductPage.php @@ -69,6 +69,7 @@ class ProductPage extends Page { 'label' => '', 'label_hidden' => 'hidden', 'checkout_hidden' => 'hidden', + 'hidden' => '', 'service' => 'Starta service', 'history' => $history, 'attachments' => $attachments, @@ -86,7 +87,9 @@ class ProductPage extends Page { $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) { diff --git a/style.css b/style.css index 61c9529..d3eeec8 100644 --- a/style.css +++ b/style.css @@ -1,3 +1,7 @@ +body { + font-size: 90%; +} + textarea { height: 80px; }