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('form.ActionForm');
 
  32 import('ttSysConfig');
 
  33 import('ttReportHelper');
 
  36 if (!ttAccessCheck(right_view_reports)) {
 
  37   header('Location: access_denied.php');
 
  41 $sc = new ttSysConfig($user->id);
 
  43 if ($request->getMethod() == 'POST') {
 
  44   $cl_receiver = trim($request->getParameter('receiver'));
 
  45   $cl_cc = trim($request->getParameter('cc'));
 
  46   $cl_subject = trim($request->getParameter('subject'));
 
  47   $cl_comment = trim($request->getParameter('comment'));
 
  49   $cl_receiver = $sc->getValue(SYSC_LAST_REPORT_EMAIL);
 
  50   $cl_cc = $sc->getValue(SYSC_LAST_REPORT_CC);
 
  51   $cl_subject = $i18n->getKey('form.mail.report_subject');
 
  54 $form = new Form('mailForm');
 
  55 $form->addInput(array('type'=>'text','name'=>'receiver','style'=>'width: 300px;','value'=>$cl_receiver));
 
  56 $form->addInput(array('type'=>'text','name'=>'cc','style'=>'width: 300px;','value'=>$cl_cc));
 
  57 $form->addInput(array('type'=>'text','name'=>'subject','style'=>'width: 300px;','value'=>$cl_subject));
 
  58 $form->addInput(array('type'=>'textarea','name'=>'comment','maxlength'=>'250','style'=>'width: 300px; height: 60px;'));
 
  59 $form->addInput(array('type'=>'submit','name'=>'btn_send','value'=>$i18n->getKey('button.send')));
 
  61 if ($request->getMethod() == 'POST') {
 
  62   // Validate user input.
 
  63   if (!ttValidEmailList($cl_receiver)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.to'));
 
  64   if (!ttValidEmailList($cl_cc, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.cc'));
 
  65   if (!ttValidString($cl_subject)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.subject'));
 
  66   if (!ttValidString($cl_comment, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.comment'));
 
  68   if ($errors->isEmpty()) {
 
  69     // Save last report emails for future use.
 
  70     $sc->setValue(SYSC_LAST_REPORT_EMAIL, $cl_receiver);
 
  71         $sc->setValue(SYSC_LAST_REPORT_CC, $cl_cc);
 
  73         // Obtain session bean with report attributes.
 
  74         $bean = new ActionForm('reportBean', new Form('reportForm'));
 
  75         // Prepare report body.
 
  76         $body = ttReportHelper::prepareReportBody($bean, $cl_comment);
 
  78     import('mail.Mailer');
 
  79     $mailer = new Mailer();
 
  80     $mailer->setCharSet(CHARSET);
 
  81     $mailer->setContentType('text/html');
 
  82     $mailer->setSender(SENDER);
 
  83     $mailer->setReceiver($cl_receiver);
 
  85       $mailer->setReceiverCC($cl_cc);
 
  86     $mailer->setSendType(MAIL_MODE);
 
  87     if ($mailer->send($cl_subject, $body))
 
  88       $messages->add($i18n->getKey('form.mail.report_sent'));
 
  90       $errors->add($i18n->getKey('error.mail_send'));
 
  94 $smarty->assign('title', $i18n->getKey('title.send_report'));
 
  95 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
 
  96 $smarty->assign('onload', 'onLoad="document.mailForm.'.($cl_receiver?'comment':'receiver').'.focus()"');
 
  97 $smarty->assign('content_page_name', 'mail.tpl');
 
  98 $smarty->display('index.tpl');