コード例 #1
0
 /**
  * Sends out email via Mandrill
  *
  * @param CakeEmail $email
  * @return array
  */
 public function send(CakeEmail $email)
 {
     // CakeEmail
     $this->_cakeEmail = $email;
     $from = $this->_cakeEmail->from();
     list($fromEmail) = array_keys($from);
     $fromName = $from[$fromEmail];
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders();
     $message = array('html' => $this->_cakeEmail->message('html'), 'text' => $this->_cakeEmail->message('text'), 'subject' => mb_decode_mimeheader($this->_cakeEmail->subject()), 'from_email' => $fromEmail, 'from_name' => $fromName, 'to' => array(), 'headers' => array('Reply-To' => $fromEmail), 'important' => false, 'track_opens' => null, 'track_clicks' => null, 'auto_text' => null, 'auto_html' => null, 'inline_css' => null, 'url_strip_qs' => null, 'preserve_recipients' => null, 'view_content_link' => null, 'tracking_domain' => null, 'signing_domain' => null, 'return_path_domain' => null, 'merge' => true, 'tags' => null, 'subaccount' => null);
     $message = array_merge($message, $this->_headers);
     foreach ($this->_cakeEmail->to() as $email => $name) {
         $message['to'][] = array('email' => $email, 'name' => $name, 'type' => 'to');
     }
     foreach ($this->_cakeEmail->cc() as $email => $name) {
         $message['to'][] = array('email' => $email, 'name' => $name, 'type' => 'cc');
     }
     foreach ($this->_cakeEmail->bcc() as $email => $name) {
         $message['to'][] = array('email' => $email, 'name' => $name, 'type' => 'bcc');
     }
     $attachments = $this->_cakeEmail->attachments();
     if (!empty($attachments)) {
         $message['attachments'] = array();
         foreach ($attachments as $file => $data) {
             $message['attachments'][] = array('type' => $data['mimetype'], 'name' => $file, 'content' => base64_encode(file_get_contents($data['file'])));
         }
     }
     $params = array('message' => $message, "async" => false, "ip_pool" => null, "send_at" => null);
     return $this->_exec($params);
 }
コード例 #2
0
 /**
  * Prepares the data array.
  * Adds headers and content
  *
  * @return void 
  */
 protected function _prepareData()
 {
     $this->_data = array();
     if (count($this->_cakeEmail->cc()) > 0) {
         throw new CakeException('Postageapp transport does not support cc');
     }
     if (count($this->_cakeEmail->bcc()) > 0) {
         throw new CakeException('Postageapp transport does not support bcc');
     }
     if (count($this->_cakeEmail->sender()) > 0) {
         throw new CakeException('Postageapp transport does not support sender');
     }
     $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'returnPath', 'to', 'subject'));
     $this->_data['recipients'] = $headers['To'];
     $map = array('From', 'Subject', 'Reply-To', 'X-Mailer', 'MIME-Version', 'Content-Transfer-Encoding');
     foreach ($map as $header) {
         if (!empty($headers[$header])) {
             $this->_addHeader($header, $headers[$header]);
         }
     }
     $emailFormat = $this->_cakeEmail->emailFormat();
     if ($emailFormat == 'both' || $emailFormat == 'text') {
         $this->_data['content']['text/plain'] = $this->_cakeEmail->message('text');
     }
     if ($emailFormat == 'both' || $emailFormat == 'html') {
         $this->_data['content']['text/html'] = $this->_cakeEmail->message('html');
     }
 }
コード例 #3
0
 /**
  * Sends out email via SparkPost
  *
  * @param CakeEmail $email
  * @return array
  */
 public function send(CakeEmail $email)
 {
     // CakeEmail
     $this->_cakeEmail = $email;
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders();
     // Not allowed by SparkPost
     unset($this->_headers['Content-Type']);
     unset($this->_headers['Content-Transfer-Encoding']);
     unset($this->_headers['MIME-Version']);
     unset($this->_headers['X-Mailer']);
     $from = $this->_cakeEmail->from();
     list($fromEmail) = array_keys($from);
     $fromName = $from[$fromEmail];
     $message = ['html' => $this->_cakeEmail->message('html'), 'text' => $this->_cakeEmail->message('text'), 'from' => ['name' => $fromName, 'email' => $fromEmail], 'subject' => mb_decode_mimeheader($this->_cakeEmail->subject()), 'recipients' => [], 'transactional' => true];
     foreach ($this->_cakeEmail->to() as $email => $name) {
         $message['recipients'][] = ['address' => ['email' => $email, 'name' => $name], 'tags' => $this->_headers['tags']];
     }
     foreach ($this->_cakeEmail->cc() as $email => $name) {
         $message['recipients'][] = ['address' => ['email' => $email, 'name' => $name], 'tags' => $this->_headers['tags']];
     }
     foreach ($this->_cakeEmail->bcc() as $email => $name) {
         $message['recipients'][] = ['address' => ['email' => $email, 'name' => $name], 'tags' => $this->_headers['tags']];
     }
     unset($this->_headers['tags']);
     $attachments = $this->_cakeEmail->attachments();
     if (!empty($attachments)) {
         $message['attachments'] = array();
         foreach ($attachments as $file => $data) {
             if (!empty($data['contentId'])) {
                 $message['inlineImages'][] = array('type' => $data['mimetype'], 'name' => $data['contentId'], 'data' => base64_encode(file_get_contents($data['file'])));
             } else {
                 $message['attachments'][] = array('type' => $data['mimetype'], 'name' => $file, 'data' => base64_encode(file_get_contents($data['file'])));
             }
         }
     }
     $message = array_merge($message, $this->_headers);
     // Load SparkPost configuration settings
     $config = ['key' => $this->_config['sparkpost']['api_key']];
     if (isset($this->_config['sparkpost']['timeout'])) {
         $config['timeout'] = $this->_config['sparkpost']['timeout'];
     }
     // Set up HTTP request adapter
     $httpAdapter = new Ivory\HttpAdapter\Guzzle6HttpAdapter($this->__getClient());
     // Create SparkPost API accessor
     $sparkpost = new SparkPost\SparkPost($httpAdapter, $config);
     // Send message
     try {
         return $sparkpost->transmission->send($message);
     } catch (SparkPost\APIResponseException $e) {
         // TODO: Determine if BRE is the best exception type
         throw new BadRequestException(sprintf('SparkPost API error %d (%d): %s (%s)', $e->getAPICode(), $e->getCode(), ucfirst($e->getAPIMessage()), $e->getAPIDescription()));
     }
 }
コード例 #4
0
 public function _sendMails($to, $sub = '', $contents = '', $attachments = null, $cc = null, $bcc = null)
 {
     //prd($contents);
     if (empty($from)) {
         $from = strtolower(Configure::read('Site.email'));
     }
     $Email = new CakeEmail();
     $Email->config('smtp');
     $Email->emailFormat('html');
     $Email->subject($sub);
     $Email->template('default', 'default');
     $Email->to($to);
     $Email->from(array($from => $sub));
     $Email->replyTo('*****@*****.**', "Meocart Team");
     if (!empty($cc)) {
         $Email->cc($cc);
     }
     if (!empty($bcc)) {
         $Email->bcc($bcc);
     }
     if (!empty($attachments) && $attachments != '' && is_array($attachments)) {
         $Email->attachments($attachments);
     }
     $Email->viewVars(array('content' => $contents));
     try {
         if ($Email->send()) {
             return true;
         }
         return false;
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
コード例 #5
0
 /**
  * Wenn es sich um einen POST-Request handelt, wird eine Rundmail mit den übergebenen Daten versendet.
  * 
  * @author aloeser
  * @return void
  */
 public function index()
 {
     if ($this->request->is('POST')) {
         $conditions = array('User.mail !=' => '', 'User.admin != ' => 2);
         if (!$this->request->data['Mail']['sendToAll']) {
             $conditions['User.leave_date'] = null;
         }
         $activeUsersWithEmail = $this->User->find('all', array('conditions' => $conditions));
         $receivers = array();
         foreach ($activeUsersWithEmail as $user) {
             array_push($receivers, $user['User']['mail']);
         }
         $senderMail = '*****@*****.**';
         $senderName = 'Humboldt Cafeteria';
         $EMail = new CakeEmail();
         $EMail->from(array($senderMail => $senderName));
         $EMail->bcc($receivers);
         $EMail->subject($this->request->data['Mail']['subject']);
         $EMail->config('web');
         $EMail->template('default');
         $EMail->emailFormat('html');
         $EMail->viewVars(array('senderName' => $senderName, 'senderMail' => $senderMail, 'content' => $this->request->data['Mail']['content'], 'subject' => $this->request->data['Mail']['subject'], 'allowReply' => $this->request->data['Mail']['allowReply']));
         if ($EMail->send()) {
             $this->Session->setFlash('Die Rundmail wurde erfolgreich abgeschickt.', 'alert-box', array('class' => 'alert-success'));
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash('Beim Senden ist ein Fehler aufgetreten.', 'alert-box', array('class' => 'alert-error'));
         }
     }
     $this->set('actions', array());
 }
コード例 #6
0
 /**
  * Prepares the recipient email addresses.
  *
  * @return array
  */
 protected function _prepareRecipientAddresses()
 {
     $to = $this->_cakeEmail->to();
     $cc = $this->_cakeEmail->cc();
     $bcc = $this->_cakeEmail->bcc();
     return array_merge(array_keys($to), array_keys($cc), array_keys($bcc));
 }
コード例 #7
0
ファイル: Email.php プロジェクト: yogesha3/yogesh-test
 public function sendEmail($to = NULL, $subject = NULL, $data = NULL, $template = NULL, $format = 'text', $cc = NULL, $bcc = NULL)
 {
     $Email = new CakeEmail();
     $Email->from(array(Configure::read('Email_From_Email') => Configure::read('Email_From_Name')));
     //$Email->config(Configure::read('TRANSPORT'));
     $Email->config('default');
     $Email->template($template);
     if ($to != NULL) {
         $Email->to($to);
     }
     if ($cc != NULL) {
         $Email->cc($cc);
     }
     if ($bcc != NULL) {
         $Email->bcc($bcc);
     }
     $Email->subject($subject);
     $Email->viewVars($data);
     $Email->emailFormat($format);
     if ($Email->send()) {
         return true;
     } else {
         return false;
     }
 }
コード例 #8
0
 /**
  * Send email via SNS
  * @param CakeEmail $email
  * @return bool
  */
 public function send(CakeEmail $email)
 {
     $ses = SesClient::factory(array("key" => "AKIAIQHPCMQTEEXD5MGA", "secret" => "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", 'region' => 'us-east-1'));
     $destination = array('ToAddresses' => array());
     foreach ($email->to() as $addr => $name) {
         $destination['ToAddresses'][] = "{$name} <{$addr}>";
     }
     foreach ($email->bcc() as $addr => $name) {
         $destination['BccAddresses'][] = "{$name} <{$addr}>";
     }
     $message = array('Subject' => array('Data' => $email->subject()), 'Body' => array());
     $text = $email->message('text');
     if (!empty($text)) {
         $message['Body']['Text'] = array('Data' => $text);
     }
     $html = $email->message('html');
     if (!empty($html)) {
         $message['Body']['Html'] = array('Data' => $html);
     }
     $from = '';
     foreach ($email->from() as $addr => $name) {
         $from = "{$name} <{$addr}>";
         break;
     }
     $response = $ses->sendEmail(['Source' => $from, 'Destination' => $destination, 'Message' => $message]);
     return !empty($response);
 }
コード例 #9
0
 /**
  * testPostmarkSend method
  *
  * @return void
  */
 public function testPostmarkSend()
 {
     $this->email->config('postmark');
     $this->email->template('default', 'default');
     $this->email->emailFormat('html');
     $this->email->from(array('*****@*****.**' => 'Your Name'));
     $this->email->to(array('*****@*****.**' => 'Recipient'));
     $this->email->cc(array('*****@*****.**' => 'Recipient'));
     $this->email->bcc(array('*****@*****.**' => 'Recipient'));
     $this->email->subject('Test Postmark');
     $this->email->addHeaders(array('Tag' => 'my tag'));
     $this->email->attachments(array('cake.icon.png' => array('file' => WWW_ROOT . 'img' . DS . 'cake.icon.png')));
     $sendReturn = $this->email->send();
     $headers = $this->email->getHeaders(array('to'));
     $this->assertEqual($sendReturn['To'], $headers['To']);
     $this->assertEqual($sendReturn['ErrorCode'], 0);
     $this->assertEqual($sendReturn['Message'], 'OK');
 }
コード例 #10
0
 /**
  * Send emails
  *
  * @return void
  * @throws SocketException
  */
 protected function _sendRcpt()
 {
     $from = $this->_cakeEmail->from();
     $this->_smtpSend('MAIL FROM:<' . key($from) . '>');
     $to = $this->_cakeEmail->to();
     $cc = $this->_cakeEmail->cc();
     $bcc = $this->_cakeEmail->bcc();
     $emails = array_merge(array_keys($to), array_keys($cc), array_keys($bcc));
     foreach ($emails as $email) {
         $this->_smtpSend('RCPT TO:<' . $email . '>');
     }
 }
コード例 #11
0
 public function main()
 {
     $email = new CakeEmail();
     $email->config(array('transport' => 'AmazonSESTransport.AmazonSES', 'log' => true, 'Amazon.SES.Key' => Configure::read('Amazon.SES.Key'), 'Amazon.SES.Secret' => Configure::read('Amazon.SES.Secret')));
     $email->sender('*****@*****.**');
     $email->from('*****@*****.**', 'Example');
     $email->to('*****@*****.**');
     $email->bcc('*****@*****.**');
     $email->subject('SES Test from CakePHP');
     $res = $email->send('test message.');
     var_dump($res);
 }
コード例 #12
0
 /**
  * Prepares the data array.
  *
  * @return void 
  */
 protected function _prepareData()
 {
     $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
     if ($headers['Sender'] == '') {
         $headers['Sender'] = $headers['From'];
     }
     $headers = $this->_headersToString($headers);
     $message = implode("\r\n", $this->_cakeEmail->message());
     $this->_data = array('Data' => base64_encode($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n."));
     $this->_dataOptions = array('Source' => key($this->_cakeEmail->from()), 'Destinations' => array());
     $this->_dataOptions['Destinations'] += array_keys($this->_cakeEmail->to());
     $this->_dataOptions['Destinations'] += array_keys($this->_cakeEmail->cc());
     $this->_dataOptions['Destinations'] += array_keys($this->_cakeEmail->bcc());
     $this->_content = array('headers' => $headers, 'message' => $message);
 }
コード例 #13
0
 /**
  * Send
  * 
  * A bit of a misnomer, because this actually just adds it to a CakeResque
  * queue.  The actual sending of the email will be performed later by a worker.
  *
  * @params CakeEmail $email
  * @return array
  */
 public function send(CakeEmail $email)
 {
     // Take a copy of the existing configuration.
     $config = array('headers' => $email->getHeaders(), 'from' => $email->from(), 'sender' => $email->sender(), 'replyTo' => $email->replyTo(), 'readReceipt' => $email->readReceipt(), 'returnPath' => $email->returnPath(), 'to' => $email->to(), 'cc' => $email->cc(), 'bcc' => $email->bcc(), 'subject' => $email->subject(), 'viewRender' => $email->viewRender(), 'viewVars' => $email->viewVars(), 'emailFormat' => $email->emailFormat(), 'messageId' => $email->messageId(), 'attachments' => $email->attachments());
     //        unset($config['config']['transport']);
     $template = $email->template();
     $config['template'] = $template['template'];
     $config['layout'] = $template['layout'];
     // Clean it up to avoid errors.
     $config = array_filter($config, function ($v) {
         return (bool) $v;
     });
     debug($config);
     // Include a message, if they sent one via plain text.
     $message = $email->message(CakeEmail::MESSAGE_HTML) ? null : $email->message(CakeEmail::MESSAGE_TEXT);
     // Drop it in a queue.
     Resque::enqueue('email', 'ResqueEmail.EmailShell', array('send', $config, $message));
     return array('headers' => $email->getHeaders(), 'message' => $email->message());
 }
コード例 #14
0
 public function broadcast()
 {
     if ($this->request->is('post')) {
         $gmail = new CakeEmail('gmail');
         $emails = Hash::extract($this->EventMembership->find('all', array('conditions' => array('event_id' => $this->request->data['eventid']))), "{n}.User.email");
         $gmail->bcc(array_filter($emails));
         $gmail->subject($this->request->data['subject']);
         $messages = $gmail->send($this->request->data['messages']);
         if ($messages == null) {
             $this->Session->setFlash("メールが送信できませんでした。管理者にお問い合わせください。", "flash_error");
         } else {
             $this->Session->setFlash("メール送信が完了しました。", "flash_success");
         }
         $this->redirect(array('controller' => 'Event', 'action' => 'detail', $this->request->data['eventid']));
     } else {
         $event = $this->Event->findById($this->passedArgs[0]);
         if ($event['Event']['owner'] != $this->Auth->user('id')) {
             throw new NotFoundException();
         }
         $this->set('eventid', $this->passedArgs[0]);
         $this->set('subject', "【seapa】" . $event['Event']['title'] . "からのお知らせ");
     }
 }
コード例 #15
0
 protected function buildRequest(CakeEmail $email)
 {
     $sender = $email->from();
     if (key($sender) != '*****@*****.**') {
         $this->data['fromEmail'] = key($sender);
         $this->data['fromName'] = reset($sender);
     }
     $replyTo = $email->replyTo();
     if (!empty($replyTo)) {
         $this->data['replyToEmail'] = key($replyTo);
         $this->data['replyToName'] = reset($replyTo);
     }
     $headers = $email->getHeaders(array('subject', 'id', 'language'));
     if (empty($headers['id'])) {
         throw new CakeException("ID header is required");
     }
     $this->data['templateId'] = $headers['id'];
     if (!empty($headers['language'])) {
         $this->data['language'] = $headers['language'];
     }
     $variables = $email->viewVars();
     $variables['subject'] = $headers['Subject'];
     $recipients = array_merge($email->to(), $email->cc(), $email->bcc());
     if (count($recipients) > 1) {
         $this->data['batch'] = array();
         foreach ($recipients as $recipientEmail => $recipientName) {
             $this->data['batch'][] = array('variables' => $variables, 'templateId' => $headers['id'], 'recipientName' => $recipientName, 'recipientEmail' => $recipientEmail);
         }
     } else {
         $this->data['recipientName'] = reset($recipients);
         $this->data['recipientEmail'] = key($recipients);
         $this->data['variables'] = $variables;
     }
     $this->addAttachments($email);
     return $this->data;
 }
コード例 #16
0
 /**
  * Utility method to send basic emails based on a paypal IPN transaction.
  * This method is very basic, if you need something more complicated I suggest
  * creating your own method in the afterPaypalNotification function you build
  * in the app_controller.php
  *
  * Example Usage: (InstantPaymentNotification = IPN)
  *   IPN->id = '4aeca923-4f4c-49ec-a3af-73d3405bef47';
  *   IPN->email('Thank you for your transaction!');
  *
  *   IPN->email(array(
  *     'id' => '4aeca923-4f4c-49ec-a3af-73d3405bef47',
  *     'subject' => 'Donation Complete!',
  *     'message' => 'Thank you for your donation!',
  *     'sendAs' => 'text'
  *   ));
  *
  *  Hint: use this in your afterPaypalNotification callback in your app_controller.php
  *   function afterPaypalNotification($txnId){
  *     ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
  *       'id' => $txnId,
  *       'subject' => 'Thanks!',
  *       'message' => 'Thank you for the transaction!'
  *     ));
  *   }
  *
  * Options:
  *   id: id of instant payment notification to base email off of
  *   subject: subject of email (default: Thank you for your paypal transaction)
  *   sendAs: html | text (default: html)
  *   to: email address to send email to (default: ipn payer_email)
  *   from: from email address (default: ipn business)
  *   cc: array of email addresses to carbon copy to (default: array())
  *   bcc: array of email addresses to blind carbon copy to (default: array())
  *   layout: layout of email to send (default: default)
  *   template: template of email to send (default: null)
  *   log: boolean true | false if you'd like to log the email being sent. (default: true)
  *   message: actual body of message to be sent (default: null)
  *
  * @param array $options of the ipn to send
  *
  */
 public function email($options = array())
 {
     if (!is_array($options)) {
         $message = $options;
         $options = array();
         $options['message'] = $message;
     }
     if (isset($options['id'])) {
         $this->id = $options['id'];
     }
     $this->read();
     $defaults = array('subject' => 'Thank you for your paypal transaction', 'sendAs' => 'html', 'to' => $this->data['InstantPaymentNotification']['payer_email'], 'from' => $this->data['InstantPaymentNotification']['business'], 'cc' => array(), 'bcc' => array(), 'layout' => 'default', 'template' => null, 'log' => true, 'message' => null, 'config' => 'default');
     $options = array_merge($defaults, $options);
     //debug($options);
     if ($options['log']) {
         $this->log("Emailing: {$options['to']} through the PayPal IPN Plugin. ", 'email');
     }
     $fullname = sprintf('%s %s', $this->data['InstantPaymentNotification']['first_name'], $this->data['InstantPaymentNotification']['last_name']);
     App::uses('CakeEmail', 'Network/Email');
     $Email = new CakeEmail($options['config']);
     $Email->to($options['to'], $fullname)->from($options['from'])->subject($options['subject'])->emailFormat($options['sendAs'])->template($options['template'], $options['layout']);
     if (!empty($options['bcc'])) {
         $Email->bcc($options['bcc']);
     }
     if (!empty($options['cc'])) {
         $Email->cc($options['cc']);
     }
     //Send the message.
     if ($options['message']) {
         $Email->send($options['message']);
     } else {
         $Email->send();
     }
 }
コード例 #17
0
 public function prepEmail($id = null)
 {
     $Email = new CakeEmail();
     if (!is_null($id)) {
         $this->Registrant->id = $id;
         if (!$this->Registrant->exists($id)) {
             throw new NotFoundException(__('Invalid registrant (3)'));
         }
         $this->data = $this->Registrant->read();
     }
     $Email->viewVars(array('registrant' => $this->data));
     $Email->template('default', 'default')->emailFormat('text');
     $Email->from(array(Configure::read('site.host_email') => Configure::read('site.name')));
     $Email->to($this->data['Registrant']['email']);
     $Email->bcc(Configure::read('site.admin_email'));
     $Email->subject("Registration for " . $this->data['Registrant']['name']);
     if (!is_null($id)) {
         $this->set('registrant', $this->data);
         $this->render('../Emails/text/default', 'Emails/text/default');
         return null;
     }
     return $Email;
 }
コード例 #18
0
 /**
  * approve method
  *
  * @throws NotFoundException
  * @param string $id
  * @return void
  */
 public function approve($id = null, $approvalId = null)
 {
     if (!$this->InternalAuditPlan->exists($id)) {
         throw new NotFoundException(__('Invalid internal audit plan'));
     }
     $this->loadModel('Approval');
     if (!$this->Approval->exists($approvalId)) {
         throw new NotFoundException(__('Invalid approval id'));
     }
     $approval = $this->Approval->read(null, $approvalId);
     $this->set('same', $approval['Approval']['user_id']);
     if ($this->_show_approvals()) {
         $this->set(array('showApprovals' => $this->_show_approvals()));
     }
     if ($this->request->is('post') || $this->request->is('put')) {
         $this->request->data['InternalAuditPlan']['system_table_id'] = $this->_get_system_table_id();
         $this->request->data['InternalAuditPlan']['note'] = htmlentities($this->request->data['InternalAuditPlan']['note']);
         if ($this->InternalAuditPlan->save($this->request->data, false)) {
             //Edit internal audit on timeline
             if ($this->request->data['InternalAuditPlan']['show_on_timeline']) {
                 $this->loadModel('Timeline');
                 $this->Timeline->deleteAll(array('internal_audit_plan_id' => $this->InternalAuditPlan->id), false);
                 $this->Timeline->create();
                 $val = array();
                 $val['title'] = $this->request->data['InternalAuditPlan']['title'];
                 $val['message'] = htmlentities($this->request->data['InternalAuditPlan']['note']);
                 $val['start_date'] = $this->request->data['InternalAuditPlan']['schedule_date_from'];
                 $val['end_date'] = $this->request->data['InternalAuditPlan']['schedule_date_to'];
                 $val['internal_audit_plan_id'] = $this->InternalAuditPlan->id;
                 $val['prepared_by'] = $this->Session->read('User.id');
                 $val['approved_by'] = $this->Session->read('User.id');
                 $val['publish'] = $this->request->data['InternalAuditPlan']['publish'];
                 $val['branchid'] = $this->request->data['InternalAuditPlan']['branchid'];
                 $val['departmentid'] = $this->request->data['InternalAuditPlan']['departmentid'];
                 $val['modified_by'] = $this->Session->read('User.id');
                 $val['system_table_id'] = $this->_get_system_table_id();
                 $this->Timeline->save($val, false);
             } else {
                 $this->loadModel('Timeline');
                 $this->Timeline->deleteAll(array('internal_audit_plan_id' => $this->InternalAuditPlan->id), false);
             }
             $internalAuditPlanDepartments = $this->InternalAuditPlan->InternalAuditPlanDepartment->find('all', array('conditions' => array('internal_audit_plan_id' => $this->InternalAuditPlan->id)));
             $internalAuditPlanBranches = $this->InternalAuditPlan->InternalAuditPlanBranch->find('all', array('conditions' => array('internal_audit_plan_id' => $this->InternalAuditPlan->id)));
             $auditDepartmentUsers = array();
             if (count($internalAuditPlanBranches) && count($internalAuditPlanDepartments)) {
                 foreach ($internalAuditPlanBranches as $branches) {
                     foreach ($internalAuditPlanDepartments as $val) {
                         $auditDepartmentUsers[$val['InternalAuditPlanDepartment']['employee_id']] = $val['InternalAuditPlanDepartment']['employee_id'];
                         $auditDepartmentUsers[$val['ListOfTrainedInternalAuditor']['employee_id']] = $val['ListOfTrainedInternalAuditor']['employee_id'];
                     }
                 }
             }
             if ($this->request->data['InternalAuditPlan']['notify_users']) {
                 //Edit internal audit plan on notification
                 $this->loadModel('Notification');
                 $notifications = $this->Notification->find('first', array('conditions' => array('internal_audit_plan_id' => $this->InternalAuditPlan->id)), false);
                 $notificationsId = $notifications['Notification']['id'];
                 $val = array();
                 $val['id'] = $notificationsId;
                 $val['title'] = $this->request->data['InternalAuditPlan']['title'];
                 $val['message'] = htmlentities($this->request->data['InternalAuditPlan']['note']);
                 $val['start_date'] = $this->request->data['InternalAuditPlan']['schedule_date_from'];
                 $val['end_date'] = $this->request->data['InternalAuditPlan']['schedule_date_to'];
                 $val['internal_audit_plan_id'] = $this->InternalAuditPlan->id;
                 $val['prepared_by'] = $this->Session->read('User.id');
                 $val['approved_by'] = $this->Session->read('User.id');
                 $val['publish'] = $this->request->data['InternalAuditPlan']['publish'];
                 $val['branchid'] = $this->request->data['InternalAuditPlan']['branchid'];
                 $val['departmentid'] = $this->request->data['InternalAuditPlan']['departmentid'];
                 $val['modified_by'] = $this->Session->read('User.id');
                 $val['system_table_id'] = $this->_get_system_table_id();
                 $this->Notification->save($val, false);
                 //Edit internal audit plan on notification User
                 $this->loadModel('NotificationUser');
                 $this->NotificationUser->deleteAll(array('notification_id' => $this->Notification->id), false);
                 $this->loadModel('User');
                 foreach ($auditDepartmentUsers as $employeeId) {
                     $this->NotificationUser->create();
                     $val = array();
                     $val['notification_id'] = $this->Notification->id;
                     $val['employee_id'] = $employeeId;
                     $val['publish'] = $this->request->data['InternalAuditPlan']['publish'];
                     $val['branchid'] = $this->Session->read('User.branch_id');
                     $val['departmentid'] = $this->Session->read('User.department_id');
                     $val['created_by'] = $this->Session->read('User.id');
                     $val['modified_by'] = $this->Session->read('User.id');
                     $val['system_table_id'] = $this->_get_system_table_id();
                     $this->NotificationUser->save($val, false);
                 }
             } else {
                 $this->loadModel('Notification');
                 $this->Notification->deleteAll(array('internal_audit_plan_id' => $this->InternalAuditPlan->id), false);
             }
             if ($this->request->data['InternalAuditPlan']['notify_users_emails']) {
                 try {
                     App::uses('CakeEmail', 'Network/Email');
                     if ($this->Session->read('User.is_smtp') == '1') {
                         $EmailConfig = new CakeEmail("smtp");
                     } else {
                         if ($this->Session->read('User.is_smtp') == '0') {
                             $EmailConfig = new CakeEmail("default");
                         }
                     }
                     $EmailConfig->subject('FlinkISO: Internal Audit Plan');
                     $internalAuditPlan = $this->InternalAuditPlan->find('first', array('conditions' => array('InternalAuditPlan.id' => $id, 'InternalAuditPlan.publish' => 1, 'InternalAuditPlan.soft_delete' => 0)));
                     $this->loadModel('Employee');
                     $this->Employee->recursive = -1;
                     $emails = array();
                     $k = 0;
                     foreach ($auditDepartmentUsers as $employeeId) {
                         $auditorEmail = $this->Employee->find('first', array('conditions' => array('Employee.id' => $employeeId), 'fields' => array('Employee.office_email', 'Employee.name')));
                         if ($k == 0) {
                             $EmailConfig->to($auditorEmail['Employee']['office_email']);
                         } else {
                             $emails[] = $auditorEmail['Employee']['office_email'];
                         }
                         $k++;
                     }
                     $EmailConfig->bcc($emails);
                     $EmailConfig->template('internalAuditPlan');
                     $EmailConfig->viewVars(array('internalAudit' => $internalAuditPlan));
                     $EmailConfig->emailFormat('html');
                     $EmailConfig->send();
                     $this->Session->setFlash('An email has been sent');
                     $this->redirect(array('controller' => 'internalAuditPlans', 'action' => 'index'));
                 } catch (Exception $e) {
                     $this->Session->setFlash(__('Can not notify user using email. Please check SMTP details and email address is correct.'));
                 }
             }
             if ($this->_show_approvals()) {
                 if ($this->request->data['InternalAuditPlan']['publish'] == 0 && $this->request->data['Approval']['user_id'] != -1) {
                     $this->loadModel('Approval');
                     $this->Approval->create();
                     $this->request->data['Approval']['model_name'] = 'InternalAuditPlan';
                     $this->request->data['Approval']['controller_name'] = $this->request->params['controller'];
                     $this->request->data['Approval']['from'] = $this->Session->read('User.id');
                     $this->request->data['Approval']['user_id'] = $this->request->data['Approval']['user_id'];
                     $this->request->data['Approval']['created_by'] = $this->Session->read('User.id');
                     $this->request->data['Approval']['modified_by'] = $this->Session->read('User.id');
                     $this->request->data['Approval']['record'] = $this->InternalAuditPlan->id;
                     $this->Approval->save($this->request->data['Approval']);
                     $this->Session->setFlash(__('The internal audit plan has been saved'));
                 } elseif ($this->request->data['InternalAuditPlan']['publish'] == 1) {
                     $this->Approval->read(null, $approvalId);
                     $data['Approval']['status'] = 'Approved';
                     $data['Approval']['modified_by'] = $this->Session->read('User.id');
                     $this->Approval->save($data);
                     $this->Session->setFlash(__('The internal audit plan has been published'));
                 }
             }
             $this->redirect(array('controller' => 'users', 'action' => 'dashboard'));
         } else {
             $this->Session->setFlash(__('The internal audit plan could not be saved. Please, try again.'));
         }
     } else {
         $options = array('conditions' => array('InternalAuditPlan.' . $this->InternalAuditPlan->primaryKey => $id));
         $this->request->data = $this->InternalAuditPlan->find('first', $options);
     }
     $systemTables = $this->InternalAuditPlan->SystemTable->find('list', array('conditions' => array('SystemTable.publish' => 1, 'SystemTable.soft_delete' => 0)));
     $masterListOfFormats = $this->InternalAuditPlan->MasterListOfFormat->find('list', array('conditions' => array('MasterListOfFormat.publish' => 1, 'MasterListOfFormat.soft_delete' => 0)));
     $count = $this->InternalAuditPlan->find('count');
     $published = $this->InternalAuditPlan->find('count', array('conditions' => array('InternalAuditPlan.publish' => 1)));
     $unpublished = $this->InternalAuditPlan->find('count', array('conditions' => array('InternalAuditPlan.publish' => 0)));
     $this->set(compact('count', 'published', 'unpublished', 'systemTables', 'masterListOfFormats'));
 }
コード例 #19
0
 public function send_email($id = null)
 {
     try {
         App::uses('CakeEmail', 'Network/Email');
         if ($this->Session->read('User.is_smtp') == '1') {
             $EmailConfig = new CakeEmail("smtp");
         } else {
             if ($this->Session->read('User.is_smtp') == '0') {
                 $EmailConfig = new CakeEmail("default");
             }
         }
         $EmailConfig->subject('FlinkISO: Internal Audit');
         $internalAudit = $this->InternalAudit->find('first', array('conditions' => array('InternalAudit.id' => $id, 'InternalAudit.publish' => 1, 'InternalAudit.soft_delete' => 0)));
         $this->loadModel('Employee');
         $this->Employee->recursive = -1;
         $emails = array();
         $auditorEmail = $this->Employee->find('first', array('conditions' => array('Employee.id' => $internalAudit['ListOfTrainedInternalAuditor']['employee_id']), 'fields' => array('Employee.office_email', 'Employee.name')));
         $EmailConfig->to($auditorEmail['Employee']['office_email']);
         $internalAudit['InternalAudit']['auditorName'] = $auditorEmail['Employee']['name'];
         $auditeeEmail = $this->Employee->find('first', array('conditions' => array('Employee.id' => $internalAudit['InternalAudit']['employee_id']), 'fields' => 'office_email'));
         if (!empty($auditeeEmail)) {
             $emails[] = $auditeeEmail['Employee']['office_email'];
         }
         $moderatorEmail = $this->Employee->find('first', array('conditions' => array('Employee.id' => $internalAudit['InternalAudit']['employeeId']), 'fields' => 'office_email'));
         if (!empty($moderatorEmail)) {
             $emails[] = $moderatorEmail['Employee']['office_email'];
         }
         $EmailConfig->bcc($emails);
         $EmailConfig->template('internalAudit');
         $EmailConfig->viewVars(array('internalAudit' => $internalAudit));
         $EmailConfig->emailFormat('html');
         $EmailConfig->send();
         $this->Session->setFlash('An email has been sent');
         $this->redirect(array('controller' => 'internalAuditPlans', 'action' => 'index'));
     } catch (Exception $e) {
         $this->Session->setFlash(__('Can not notify user using email. Please check SMTP details and email address are correct or not: ' . $e->getMessage()));
         $this->redirect(array('controller' => 'internalAuditPlans', 'action' => 'index'));
         exit;
     }
     exit;
 }
コード例 #20
0
 function _sendMail($cliente, $factura, $template = 'first_email', $text = null)
 {
     App::uses('CakeEmail', 'Network/Email');
     $email = new CakeEmail();
     $email->config('smtp');
     if ($template === 'our_email') {
         $email->to(Configure::read('Facturacion.email'));
     } else {
         $email->to($cliente['email']);
     }
     $email->bcc(Configure::read('Facturacion.email'));
     $email->template($template)->emailFormat('html')->subject(Configure::read('Email.Subject.' . $template))->viewVars(compact('cliente', 'factura', 'text'))->send();
 }
コード例 #21
0
 /**
  * Sendet eine Notfallmail an alle aktiven Nutzer außer denjenigen mit der ID $exceptOf,
  * die am $date in der $halfshift $shiftname Zeit hätten, um kurzfristig einzuspringen.
  * 
  * @param date - gibt an, an welchem Tag ein Dienst kurzfristig freigeworden ist
  * @param halfshift - gibt die Halbschicht an, in der der Dienst freigeworden ist
  * @param exceptOf - die Benutzerid, die keine E-Mail erhalten soll, weil sie sich ausgetragen hat
  * @param shiftname - Name des Dienstes
  * @author jgraeger
  */
 private function sendEmergencyMail($date, $halfshift, $exceptOf, $shiftname)
 {
     //auf Deutsch umstellen
     setlocale(LC_TIME, 'de_DE@euro', 'de_DE', 'de', 'ge', 'de_DE.utf8');
     $dow = strtolower(strftime('%a', strtotime($date)));
     $conditionArray = array('User.leave_date' => null, 'User.admin != ' => 2, 'User.id != ' => $exceptOf, 'User.mail != ' => '');
     if ($dow == "sa" || $dow == "so") {
     } else {
         if ($halfshift == 3) {
             $conditionsArray['User.' . $dow] = array('1 ', '2 ', 'H', 'G');
         } else {
             $conditionsArray['User.' . $dow] = array($halfshift . ' ', 'H', 'G');
         }
     }
     $receivingUsers = $this->User->find('all', array('recursive' => -1, 'conditions' => $conditionArray));
     $senderMail = '*****@*****.**';
     $senderName = 'Humboldt Cafeteria';
     $mailContent = "Hallo,<br />\n\t\t\t\tleider ist die " . $shiftname . " für " . strftime('%A', strtotime($date)) . ", den " . date('d.m.Y', strtotime($date)) . ", kurzfristig frei geworden.\n\t\t\t\tFalls Ihr Zeit habt, springt bitte ein.\n\t\t\t\t\n\t\t\t\tMit freundlichen Grüßen\n\t\t\t\tDas Cafeteria-Team\n\t\t\t\t";
     $EMail = new CakeEmail();
     $EMail->from(array($senderMail => $senderName));
     $EMail->subject("Humboldt-Cafeteria - Dienst kurzfristig frei geworden");
     $EMail->config('web');
     $EMail->template('default');
     $EMail->emailFormat('html');
     $EMail->viewVars(array('senderName' => $senderName, 'senderMail' => $senderMail, 'content' => $mailContent, 'subject' => "Humboldt-Cafeteria - nächste Woche unvollständig", 'allowReply' => false));
     $bcc = array();
     foreach ($receivingUsers as $receivingUser) {
         array_push($bcc, $receivingUser['User']['mail']);
     }
     $EMail->bcc($bcc);
     $EMail->send();
 }
コード例 #22
0
 public function prepEmail($id = null)
 {
     $Email = new CakeEmail();
     if (!is_null($id)) {
         $this->Conference->id = $id;
         if (!$this->Conference->exists($id)) {
             throw new NotFoundException(__('Invalid conference (3)'));
         }
         $this->data = $this->Conference->read();
     }
     $Email->viewVars(array('conference' => $this->data));
     $Email->template('default', 'default')->emailFormat('text');
     $Email->from(array(Configure::read('site.host_email') => Configure::read('site.name')));
     $to_array = preg_split("/[\\s,]+/", $this->data['Conference']['contact_email']);
     $Email->to($to_array);
     $Email->bcc(Configure::read('site.admin_email'));
     $Email->subject(Configure::read('site.name') . ": " . $this->data['Conference']['title']);
     if (!is_null($id)) {
         $this->set('conference', $this->data);
         $this->render('../Emails/text/default', 'Emails/text/default');
         return null;
     }
     return $Email;
 }
コード例 #23
0
ファイル: myMailer.php プロジェクト: belamide09/mysite
 public static function forgotTeacherMail($teacher, $hash)
 {
     App::uses('CakeEmail', 'Network/Email');
     $email = new CakeEmail();
     $email->config('default');
     $email->emailFormat('text');
     $email->template('forgot');
     $email->viewVars(array('teacher' => $teacher, 'hash' => $hash));
     $email->to($teacher->email);
     $email->bcc(Configure::read('my.admin_email'));
     $email->subject(__('Forgot Password') . ' - ' . Configure::read('my.site_name'));
     $email->returnPath('*****@*****.**', 'NativeCamp運営事務局');
     $email->send();
 }
コード例 #24
0
ファイル: AppController.php プロジェクト: kn2s/EDC
 public function sitemailsend($mailtype = 0, $from = array(), $to = "", $message = "EDC Email", $data = array())
 {
     //get the admin configre email sections
     $this->loadModel('Service');
     $adminemails = $this->Service->find('first', array('fields' => array('Service.sending_email', 'Service.receiving_email', 'Service.id')));
     $adminname = "Eradicate Cancer";
     $adminsendemail = "Eradicate Cancer";
     $adminrecieveemail = "*****@*****.**";
     $bodymessage = "";
     if (is_array($adminemails) && count($adminemails) > 0) {
         $adminsendemail = isset($adminemails['Service']['sending_email']) && $adminemails['Service']['sending_email'] != '' ? $adminemails['Service']['sending_email'] : $adminsendemail;
         $adminrecieveemail = isset($adminemails['Service']['receiving_email']) ? $adminemails['Service']['receiving_email'] : $adminrecieveemail;
     }
     $Email = new CakeEmail($this->mailTransportType);
     //dynamic smpt configuration section
     if ($this->mailTransportType == 'smtp') {
         $dynamic_smtp = $this->getSmtpConfigdata();
         //pr($dynamic_smtp);
         $Email->config($dynamic_smtp);
     }
     if (!is_array($from) || count($from) == 0) {
         $from = array($adminsendemail => $adminname);
     }
     //
     if ($to == '') {
         //admin will reciev the email
         $to = $adminrecieveemail;
     }
     //if reviever email is valid then
     if (filter_var($to, FILTER_VALIDATE_EMAIL)) {
         //get the boddy text and data from admin
         if ($mailtype != 14 && $mailtype != 16) {
             $emaildata = $this->getemailbodytext($mailtype);
             $bodymessage = isset($emaildata['body_txt']) ? $emaildata['body_txt'] : '';
         }
         //mail type
         $subjects = "We thanksfull to you being with us";
         $templatenameview = "default";
         switch ($mailtype) {
             case 1:
                 //regiatration
                 $subjects = "You are registered successfully";
                 $templatenameview = "registration";
                 $data['signinlink'] = FULL_BASE_URL . $this->base . "/Patients/account";
                 //$bodymessage="";
                 break;
             case 2:
                 //patient appoinment confirm
                 $subjects = "Your appointment schedule confirm for consultant";
                 $templatenameview = "appointment";
                 break;
             case 3:
                 //opinion give
                 $subjects = "Your doctor give the opinion about your case";
                 $templatenameview = "caseopinion";
                 break;
             case 4:
                 //doctor allow to modify
                 $subjects = "Your doctor allow you to edit your questionnair";
                 $templatenameview = "doctalloweditquestionnair";
                 break;
             case 5:
                 //patient give reply to the doctor message
                 //$subjects="Your patient give reply to you";
                 $subjects = "You have received a communication from a patient";
                 //$templatenameview="patientreply";
                 $templatenameview = "doctpatientcommuniction";
                 break;
             case 6:
                 //patient re update the questionnair
                 $subjects = "Your patient update questionnair details";
                 $templatenameview = "patientquestionnairupdate";
                 break;
             case 7:
                 //paypal account not set so noify the admin about that
                 $subjects = "Paypal marchant account dose not set.";
                 $templatenameview = "paypalnotset";
             case 8:
                 $subjects = "Someone try to contact with you";
                 $templatenameview = "contactus";
                 break;
             case 9:
                 //password recovery
                 $subjects = "EDC password recovery";
                 $templatenameview = "forgotpassword";
                 break;
             case 10:
                 //new case assing
                 $subjects = "You have been assigned with a case , with due date";
                 $templatenameview = "caseassign";
                 break;
             case 11:
                 //due alert
                 $subjects = "You are due to submit an opinion within 2 days";
                 $templatenameview = "opiniondue";
                 break;
             case 12:
                 //After opinion submission
                 $subjects = "Thank you for submitting your opinion.";
                 $templatenameview = "thanks";
                 break;
             case 13:
                 //Past Due opinion
                 $subjects = "You missed to gave an opinion";
                 $templatenameview = "opinionmissed";
                 break;
             case 14:
                 //bulk mail from admin section
                 $subjects = $data['email_sub'];
                 $templatenameview = "bulkmail";
                 $bodymessage = $data['email_body'];
             case 15:
                 //doctor send communication
                 $subjects = "You have received a communication from your doctor";
                 $templatenameview = "doctpatientcommuniction";
                 break;
             case 16:
                 // opinion 2 day pre alert for admin
                 $subjects = "Doctor need to submit an opinion within 2 days";
                 $templatenameview = "opiniondue";
                 $bodymessage = isset($data['doct_name']) ? $data['doct_name'] : 'Doctor';
                 $bodymessage .= " need to be post an opinion.";
                 break;
             case 17:
                 // opinion missed alert for admin
                 $subjects = "Doctor missed to gave an opinion";
                 $templatenameview = "opinionmissed";
                 $bodymessage = isset($data['doct_name']) ? $data['doct_name'] : 'Doctor';
                 $bodymessage .= " missed to post an opinion.";
                 break;
             default:
                 break;
         }
         //now set the body message
         $data['bodymessage'] = $bodymessage;
         $Email->from($from);
         $Email->to($to);
         //hear need to keep the admin as bcc
         $Email->bcc($adminrecieveemail);
         $Email->subject($subjects);
         $Email->template($templatenameview, 'emain');
         $Email->emailFormat('html');
         $Email->viewVars($data);
         $Email->send();
     }
 }
コード例 #25
0
ファイル: EmailComponent.php プロジェクト: hungnt88/5stars-1
/**
 * Send an email using the specified content, template and layout
 *
 * @param string|array $content Either an array of text lines, or a string with contents
 *  If you are rendering a template this variable will be sent to the templates as `$content`
 * @param string $template Template to use when sending email
 * @param string $layout Layout to use to enclose email body
 * @return boolean Success
 */
	public function send($content = null, $template = null, $layout = null) {
		$lib = new CakeEmail();
		$lib->charset = $this->charset;
		$lib->headerCharset = $this->charset;

		$lib->from($this->_formatAddresses((array)$this->from));
		if (!empty($this->to)) {
			$lib->to($this->_formatAddresses((array)$this->to));
		}
		if (!empty($this->cc)) {
			$lib->cc($this->_formatAddresses((array)$this->cc));
		}
		if (!empty($this->bcc)) {
			$lib->bcc($this->_formatAddresses((array)$this->bcc));
		}
		if (!empty($this->replyTo)) {
			$lib->replyTo($this->_formatAddresses((array)$this->replyTo));
		}
		if (!empty($this->return)) {
			$lib->returnPath($this->_formatAddresses((array)$this->return));
		}
		if (!empty($this->readReceipt)) {
			$lib->readReceipt($this->_formatAddresses((array)$this->readReceipt));
		}

		$lib->subject($this->subject)->messageID($this->messageId);
		$lib->helpers($this->_controller->helpers);

		$headers = array('X-Mailer' => $this->xMailer);
		foreach ($this->headers as $key => $value) {
			$headers['X-' . $key] = $value;
		}
		if ($this->date) {
			$headers['Date'] = $this->date;
		}
		$lib->setHeaders($headers);

		if ($template) {
			$this->template = $template;
		}
		if ($layout) {
			$this->layout = $layout;
		}
		$lib->template($this->template, $this->layout)->viewVars($this->_controller->viewVars)->emailFormat($this->sendAs);

		if (!empty($this->attachments)) {
			$lib->attachments($this->_formatAttachFiles());
		}

		$lib->transport(ucfirst($this->delivery));
		if ($this->delivery === 'mail') {
			$lib->config(array('eol' => $this->lineFeed, 'additionalParameters' => $this->additionalParams));
		} elseif ($this->delivery === 'smtp') {
			$lib->config($this->smtpOptions);
		} else {
			$lib->config(array());
		}

		$sent = $lib->send($content);

		$this->htmlMessage = $lib->message(CakeEmail::MESSAGE_HTML);
		if (empty($this->htmlMessage)) {
			$this->htmlMessage = null;
		}
		$this->textMessage = $lib->message(CakeEmail::MESSAGE_TEXT);
		if (empty($this->textMessage)) {
			$this->textMessage = null;
		}

		$this->_header = array();
		$this->_message = array();

		return $sent;
	}
コード例 #26
0
    function payslip_update()
    {
        if ($this->request->data) {
            $this->set('employee_id', $this->request->data['SalaryRecord']['employee_id']);
            $res = $this->Employee->SalaryRecord->salarySearch($this->request->data['SalaryRecord']['employee_id'], $this->request->data['SalaryRecord']['salary_date']);
            if ($res['SalaryRecord']['payslip_generated'] != 1) {
                //debug($this->request->data);
                $earnings = $this->request->data['SalaryRecord']['basic'] + $this->request->data['SalaryRecord']['da'] + $this->request->data['SalaryRecord']['bonus'] + $this->request->data['SalaryRecord']['medical_allowance'] + $this->request->data['SalaryRecord']['tiffin'] + $this->request->data['SalaryRecord']['house_rent'] + $this->request->data['SalaryRecord']['education'] + $this->request->data['SalaryRecord']['entertainment'];
                $deductions = $this->request->data['SalaryRecord']['pf'] + $this->request->data['SalaryRecord']['esi'] + $this->request->data['SalaryRecord']['income_tax'];
                $this->request->data['SalaryRecord']['net_salary'] = $earnings - $deductions;
                $se = $this->Session->read("Auth");
                $this->request->data['SalaryRecord']['user_id'] = $se['User']['id'];
                $this->request->data['SalaryRecord']['print_copy'] = 1;
                $this->request->data['SalaryRecord']['payslip_generated'] = 1;
                //debug($this->request->data['SalaryRecord']);exit();
                if ($res['SalaryRecord']['id']) {
                    $this->Employee->SalaryRecord->id = $res['SalaryRecord']['id'];
                } else {
                    $this->Employee->SalaryRecord->create();
                }
                if ($this->Employee->SalaryRecord->save($this->request->data)) {
                    //update the loan amount
                    if ($this->request->data['SalaryRecord']['loan_amount'] > 0) {
                        $this->request->data['Loan']['loan_amount'] = $this->request->data['SalaryRecord']['loan_amount'];
                        $this->request->data['Loan']['employee_id'] = $this->request->data['SalaryRecord']['employee_id'];
                        $loan_save = $this->Employee->Loan->loanEntryUpdate($this->request->data['Loan']);
                    }
                    $this->set('salary_saved', 1);
                    $name = $this->request->data['SalaryRecord']['fname'];
                    if ($this->request->data['SalaryRecord']['mname'] != null) {
                        $name .= ' ' . $this->request->data['SalaryRecord']['mname'];
                    }
                    $name .= ' ' . $this->request->data['SalaryRecord']['lname'];
                    App::import('Vendor', 'xtcpdf');
                    $tcpdf = new XTCPDF();
                    $textfont = 'freesans';
                    // looks better, finer, and more condensed than 'dejavusans'
                    $tcpdf->SetAuthor("Company Name");
                    $tcpdf->SetAutoPageBreak(false);
                    $tcpdf->setPrintHeader(false);
                    $tcpdf->setPrintFooter(false);
                    //$tcpdf->setHeaderFont(array($textfont,'',40));
                    //$tcpdf->xheadercolor = array(0,0,0);
                    //$tcpdf->xheadertext = '';
                    //$tcpdf->xfootertext = '';
                    // add a page (required with recent versions of tcpdf)
                    $tcpdf->AddPage();
                    // Now you position and print your page content
                    // example:
                    $fill = 0;
                    $tcpdf->SetTextColor(0, 0, 0);
                    $tcpdf->SetFont($textfont, 'B', 20);
                    $header_html = '<span>Company Logo</span>';
                    $header_html2 = '<span>Company Address</span>';
                    $payslip_date = '<p style="font-size:20px!important">Playslip for the month of ' . $this->request->data['SalaryRecord']['salary_date'] . '</p>';
                    $emp_name = '<p style="font-size:20px!important">Name : ' . $name . '</p>';
                    $employee_id = '<p style="font-size:20px!important">Employee Id : emp' . $this->request->data['SalaryRecord']['employee_id'] . '</p>';
                    $department = '<p style="font-size:20px!important">Department : ' . $this->request->data['SalaryRecord']['department'] . '</p>';
                    $designation = '<p style="font-size:20px!important">Designation : ' . $this->request->data['SalaryRecord']['designation'] . '</p>';
                    $employee = $this->Employee->employeeSearch($this->request->data['SalaryRecord']['employee_id']);
                    $expected_earnings = $employee['Employee']['net_salary'] + $employee['Employee']['da'] + $employee['Employee']['bonus'] + $employee['Employee']['medical_allowance'] + $employee['Employee']['tiffin'] + $employee['Employee']['house_rent'] + $employee['Employee']['education'] + $employee['Employee']['entertainment'];
                    $expected_deductions = $employee['Employee']['pf'] + $employee['Employee']['esi'] + $employee['Employee']['income_tax'];
                    $earnings_content = '
<style>
	table{width:100%;border:none}
	th{font-size:12px;height:10px;font-size:22px!important;border-bottom:0px solid black}
	td{font-size:20px!important;width:100%;}
	.total{border-top:0px solid black}
</style>
<table>
 <tr>
  <th><b>Earnings</b></th>
 </tr>
 <tr>
 <td width="50%"></td>
  <td width="25%">Full (Rs.)</td>
  <td width="25%">Actual (Rs.)</td>
 </tr>
 <tr>
 <td width="50%">Basic</td>
  <td width="25%">' . $employee['Employee']['net_salary'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['basic'] . '</td>
 </tr>
 <tr>
  <td width="50%">DA</td>
  <td width="25%">' . $employee['Employee']['da'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['da'] . '</td>
 </tr>
 <tr>
  <td width="50%">Bonus</td>
  <td width="25%">' . $employee['Employee']['bonus'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['bonus'] . '</td>
 </tr>
 <tr>
  <td width="50%">Medical Allowance</td>
  <td width="25%">' . $employee['Employee']['medical_allowance'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['medical_allowance'] . '</td>
 </tr>
  <tr>
  <td width="50%">Tiffin Allowance</td>
  <td width="25%">' . $employee['Employee']['tiffin'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['tiffin'] . '</td>
 </tr>
  <tr>
  <td width="50%">House Rent Allowance</td>
  <td width="25%">' . $employee['Employee']['house_rent'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['house_rent'] . '</td>
 </tr>
 <tr>
  <td width="50%">Education Allowance</td>
  <td width="25%">' . $employee['Employee']['education'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['education'] . '</td>
 </tr>
  <tr>
  <td width="50%">Entertainment Allowance</td>
  <td width="25%">' . $employee['Employee']['entertainment'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['entertainment'] . '</td>
 </tr>
 <tr>
  <td width="50%"  class="total"><b>Total Earnings (Rs.) :</b></td>
  <td width="25%"  class="total"><b>' . $expected_earnings . '</b></td>
  <td width="25%"  class="total"><b>' . $earnings . '</b></td>
 </tr>
	 </table>';
                    $deductions_content = '
<style>
	table{width:100%;border:none}
	th{font-size:12px;height:10px;font-size:22px!important;border-bottom:0px solid black}
	td{font-size:20px!important;width:100%;}
	.total{border-top:0px solid black}

</style>
<table>
 <tr>
  <th><b>Deductions</b></th>
 </tr>
 <tr>
 <td width="50%"></td>
  <td width="25%">Full (Rs.)</td>
  <td width="25%">Actual (Rs.)</td>
 </tr>
 <tr>
 <td width="50%">PF</td>
  <td width="25%">' . $employee['Employee']['pf'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['pf'] . '</td>
 </tr>
 <tr>
  <td width="50%">ESI</td>
  <td width="25%">' . $employee['Employee']['esi'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['esi'] . '</td>
 </tr>
 <tr>
  <td width="50%">TDS</td>
  <td width="25%">' . $employee['Employee']['income_tax'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['income_tax'] . '</td>
 </tr>
  <tr>
  <td width="50%">Advance</td>
  <td width="25%">0</td>
  <td width="25%">0</td>
 </tr>
  <tr>
  <td width="50%">Loan</td>
  <td width="25%">0</td>
  <td width="25%">0</td>
 </tr>
 <tr>
  <td width="50%"></td>
  <td width="25%"></td>
  <td width="25%"></td>
 </tr>
 <tr>
  <td width="50%"></td>
  <td width="25%"></td>
  <td width="25%"></td>
 </tr>
 <tr>
  <td width="50%"></td>
  <td width="25%"></td>
  <td width="25%"></td>
 </tr>
 <tr>
  <td width="50%"  class="total"><b>Total Deductions (Rs.) :</b></td>
  <td width="25%"  class="total"><b>' . $expected_deductions . '</b></td>
  <td width="25%"  class="total"><b>' . $deductions . '</b></td>
 </tr>
	 </table>';
                    $net_earnings = $earnings - $deductions;
                    $net_salary = '<p style="font-size:20px!important"><b>Net Salary : Rs. ' . $net_earnings . '</b></p>';
                    $auto_text = '<p style="font-size:22px!important;color:#cccccc">This is a computer-generated salary slip. Does not require a Signature</p>';
                    $tcpdf->SetFillColor(155, 100, 0);
                    $tcpdf->writeHTMLCell(50, 0, '', 10, $header_html, 0, 1, 0, true, 'L', true);
                    $tcpdf->writeHTMLCell(50, 0, 55, 10, $header_html2, 0, 0, 0, true, 'R', true);
                    $tcpdf->writeHTMLCell(0, 0, '', 35, $payslip_date, 0, 1, 0, true, 'L', true);
                    $tcpdf->writeHTMLCell(80, 5, '', 40, $emp_name, 'LRTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, 5, 85, 40, $employee_id, 'RTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, 5, '', 45, $department, 'LRB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, 5, 85, 45, $designation, 'RB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, '', '', 55, $earnings_content, 'LRTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, '', 85, 55, $deductions_content, 'RTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(155, 3, '', '', $net_salary, 'LRTB', 1, 0, true, 'L', true);
                    $tcpdf->writeHTMLCell(155, '', '', 105, $auto_text, '', 1, 0, true, 'L', true);
                    // ...
                    // etc.
                    // see the TCPDF examples
                    $file_name = time() . '.pdf';
                    echo $tcpdf->Output($file_name, 'F');
                    //setting view variables before sending email so that if email is not sent generated salry slip will still be viewed
                    $this->set('salaryrecord', $this->request->data['SalaryRecord']);
                    $this->set('employee', $employee);
                    $this->set('earnings', $earnings);
                    $this->set('deductions', $deductions);
                    $this->set('expected_earnings', $expected_earnings);
                    $this->set('net_earnings', $net_earnings);
                    App::uses('CakeEmail', 'Network/Email');
                    $Email = new CakeEmail();
                    $Email->to($this->request->data['SalaryRecord']['email']);
                    $Email->bcc($se['User']['email']);
                    $Email->subject('Salary Slip of ' . $name . ' [ emp' . $this->request->data['SalaryRecord']['employee_id'] . ' ] for ' . $this->request->data['SalaryRecord']['salary_date']);
                    $Email->replyTo($se['User']['email']);
                    $Email->from($se['User']['email']);
                    $Email->emailFormat('html');
                    $Email->viewVars(array('salary_record' => $this->request->data['SalaryRecord']));
                    $Email->attachments($file_name);
                    $Email->template('salaryslip');
                    //$Email->send();
                    App::uses('File', 'Utility');
                    $file = new File($file_name);
                    $file->delete();
                } else {
                    $this->set('salary_saved', 0);
                }
            }
        }
    }
コード例 #27
0
 public function contact_confirm()
 {
     $this->title_tag = "お問い合わせ確認画面";
     $this->set("naviType", "contact");
     $data = $this->Session->read('contact');
     $this->set("data", $data);
     if ($this->request->is('post') && !empty($data)) {
         //メール送信
         $email = new CakeEmail('smtp');
         $email->to($data["email"]);
         $email->bcc('*****@*****.**');
         $email->subject('お問い合わせ頂きありがとうございます');
         $email->emailFormat('text');
         $email->template('contact');
         $email->viewVars(compact('data'));
         $email->send();
         //sessionから削除
         $this->Session->write('contact', "");
         //リダイレクト
         $this->redirect("/contact_complete");
     }
 }
コード例 #28
0
 /**
  * testRcpt method
  *
  * @return void
  */
 public function testRcpt()
 {
     $email = new CakeEmail();
     $email->from('*****@*****.**', 'CakePHP Test');
     $email->to('*****@*****.**', 'CakePHP');
     $email->bcc('*****@*****.**');
     $email->cc(array('*****@*****.**' => 'Mark Story', '*****@*****.**' => 'Juan Basso'));
     $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(6))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(9))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(12))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(13))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(14))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->SmtpTransport->setCakeEmail($email);
     $this->SmtpTransport->sendRcpt();
 }
コード例 #29
0
 /**
  * Wrapper of CakeEmail object creation and submission.
  * @param $emailData
  * @param string $templateName
  * @param string $to
  * @param string $subjectBlockName
  * @param string $tag
  * @param string $locale
  * @param bool $debug
  * @param array $emailOptions
  * @return string
  * @throws Exception
  */
 public static function sendEmail($emailData, $templateName = '', $to = '', $subjectBlockName = '', $tag = '', $locale = 'en-US', $debug = false, $emailOptions = array())
 {
     if (empty($templateName) || empty($to) || empty($subjectBlockName)) {
         CakeLog::error('CRITICAL EXEPTION: In email library.');
         CakeLog::error('Empty argument passed to email sender.');
         throw new BadMethodCallException('Empty argument passed to email sender.', 1);
         return false;
     }
     // Since getting the data from Drupal happens in-line we need to check
     // for errors by seeing if we only get log_info back and nothing else.
     if (!empty($tag)) {
         $drupalData = array();
         DruniqueAPIUtil::getData(['api_url' => 'email_text.json', 'params' => ['tag' => $tag], 'locale' => $locale], $drupalData);
         if (sizeof($drupalData) <= 1) {
             CakeLog::error('CRITICAL EXEPTION: In email library.');
             CakeLog::error('Unable to get view variables from CMS.');
             throw new Exception('Unable to get view variables from CMS.', 1);
             return false;
         }
         $emailData['email_text'] = $drupalData;
     }
     $email = new CakeEmail('default');
     $subject = DruniqueAPIUtil::content($subjectBlockName, $emailData['email_text']);
     $subject = preg_replace('/[\\pZ\\pC]/u', ' ', $subject);
     if ($debug) {
         $email->transport('Debug');
     }
     // Make sure format is set correctly based on existence of templates.
     $format = 'both';
     $htmlTemplateExists = is_readable(APP . "View/Emails/html/{$templateName}.ctp");
     $textTemplateExists = is_readable(APP . "View/Emails/text/{$templateName}.ctp");
     if (!$htmlTemplateExists && !$textTemplateExists) {
         CakeLog::error('CRITICAL ERROR: In email library.');
         CakeLog::error("Unable to find email template named {$templateName}.ctp");
         return false;
     } elseif (!$htmlTemplateExists && $textTemplateExists) {
         $format = 'text';
     } elseif ($htmlTemplateExists && !$textTemplateExists) {
         $format = 'html';
     }
     $email->template($templateName, 'default')->emailFormat($format)->to($to)->subject(html_entity_decode($subject, ENT_QUOTES))->viewVars($emailData);
     if (isset($emailOptions['bcc'])) {
         $email->bcc($emailOptions['bcc']);
     }
     if (isset($emailOptions['cc'])) {
         $email->cc($emailOptions['cc']);
     }
     try {
         $response = $email->send();
         if ($debug) {
             return $response;
         }
         if ($response) {
             $result = 'Email was sent successfully';
         } else {
             $result = 'Email failed to send without exceptions';
             CakeLog::error('CRITICAL ERROR: Email library failed to send an email without exception.');
             Cakelog::error(print_r($email, true));
         }
     } catch (Exception $e) {
         $result = 'Email failed with exception: ' . print_r($e->getMessage(), true);
         CakeLog::error('CRITICAL ERROR: In email library.');
         CakeLog::error($e->getMessage());
     }
     return $result;
 }