2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
31 import('ttInvoiceHelper');
32 import('ttSysConfig');
35 if (!(ttAccessAllowed('manage_invoices') || ttAccessAllowed('view_own_invoices'))) {
36 header('Location: access_denied.php');
39 if (!$user->isPluginEnabled('iv')) {
40 header('Location: feature_disabled.php');
43 $cl_invoice_id = (int)$request->getParameter('id');
44 $invoice = ttInvoiceHelper::getInvoice($cl_invoice_id);
46 header('Location: access_denied.php');
49 // End of access checks.
51 $sc = new ttSysConfig($user->id);
53 if ($request->isPost()) {
54 $cl_receiver = trim($request->getParameter('receiver'));
55 $cl_cc = trim($request->getParameter('cc'));
56 $cl_subject = trim($request->getParameter('subject'));
57 $cl_comment = trim($request->getParameter('comment'));
59 $cl_receiver = $sc->getValue(SYSC_LAST_INVOICE_EMAIL);
60 $cl_cc = $sc->getValue(SYSC_LAST_INVOICE_CC);
61 $cl_subject = $i18n->get('title.invoice').' '.$invoice['name'].', '.$user->group;
64 $form = new Form('mailForm');
65 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_invoice_id));
66 $form->addInput(array('type'=>'text','name'=>'receiver','style'=>'width: 300px;','value'=>$cl_receiver));
67 $form->addInput(array('type'=>'text','name'=>'cc','style'=>'width: 300px;','value'=>$cl_cc));
68 $form->addInput(array('type'=>'text','name'=>'subject','style'=>'width: 300px;','value'=>$cl_subject));
69 $form->addInput(array('type'=>'textarea','name'=>'comment','maxlength'=>'250','style'=>'width: 300px; height: 60px;'));
70 $form->addInput(array('type'=>'submit','name'=>'btn_send','value'=>$i18n->get('button.send')));
72 if ($request->isPost()) {
73 // Validate user input.
74 if (!ttValidEmailList($cl_receiver)) $err->add($i18n->get('error.field'), $i18n->get('form.mail.to'));
75 if (!ttValidEmailList($cl_cc, true)) $err->add($i18n->get('error.field'), $i18n->get('label.cc'));
76 if (!ttValidString($cl_subject)) $err->add($i18n->get('error.field'), $i18n->get('label.subject'));
77 if (!ttValidString($cl_comment, true)) $err->add($i18n->get('error.field'), $i18n->get('label.comment'));
80 // Save last invoice emails for future use.
81 $sc->setValue(SYSC_LAST_INVOICE_EMAIL, $cl_receiver);
82 $sc->setValue(SYSC_LAST_INVOICE_CC, $cl_cc);
84 $body = ttInvoiceHelper::prepareInvoiceBody($cl_invoice_id, $cl_comment);
86 import('mail.Mailer');
87 $mailer = new Mailer();
88 $mailer->setCharSet(CHARSET);
89 $mailer->setContentType('text/html');
90 $mailer->setSender(SENDER);
91 $mailer->setReceiver($cl_receiver);
93 $mailer->setReceiverCC($cl_cc);
94 if (!empty($user->bcc_email))
95 $mailer->setReceiverBCC($user->bcc_email);
96 $mailer->setMailMode(MAIL_MODE);
97 if ($mailer->send($cl_subject, $body))
98 $msg->add($i18n->get('form.mail.invoice_sent'));
100 $err->add($i18n->get('error.mail_send'));
104 $smarty->assign('sender', SENDER);
105 if (function_exists('imap_mime_header_decode')) {
106 // Decode sender in case it is encoded. PHP IMAP extension must be installed for us to get here.
107 $elements = imap_mime_header_decode(SENDER);
108 if (count($elements) > 1) {
110 $smarty->assign('sender', $elements[count($elements) - 2]->text);
114 $smarty->assign('title', $i18n->get('title.send_invoice'));
115 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
116 $smarty->assign('onload', 'onLoad="document.mailForm.'.($cl_receiver?'comment':'receiver').'.focus()"');
117 $smarty->assign('content_page_name', 'mail.tpl');
118 $smarty->display('index.tpl');