/** * * @param type $msg * @param type $log_level EMERG=0, ALERT=1, CRIT=2, ERR=3, WARN=4, NOTICE=5, INFO=6, DEBUG=7 */ public function log($msg, $priority = 5) { if ($this->logEnabled) { if (!is_string($msg)) { $this->logger->log($priority, var_export($msg, true)); } else { $this->logger->log($priority, $msg); } } }
/** * * @param string $msg * @param int $priority EMERG=0, ALERT=1, CRIT=2, ERR=3, WARN=4, NOTICE=5, INFO=6, DEBUG=7 */ public function log($msg, $priority = 5) { $max_len = 512; $msg = rtrim(mb_strimwidth($msg, 0, $max_len)) . "..."; if ($this->log_enabled) { if (!is_string($msg)) { $this->logger->log($priority, var_export($msg, true)); } else { $this->logger->log($priority, $msg); } } }
/** * re-issue password2 * @return ViewModel */ public function remindStoreAction() { $this->layout('layout/index'); // get temporary id $id = (string) $this->params()->fromRoute('id'); if (!$id) { $this->flashMessenger()->addMessage('Not allowed'); // $this->flashMessenger()->addMessage('許可されていません。'); return $this->redirect()->toRoute('app', array('controller' => 'index')); } $tmp = new TemporaryIdTable(); $row = $tmp->getFetchOne($id); if (!$row || !isset($row->create_user) || !$row->create_user) { $this->flashMessenger()->addMessage('Not allowed'); // $this->flashMessenger()->addMessage('許可されていません。'); return $this->redirect()->toRoute('app', array('controller' => 'index')); } $success = false; $request = $this->getRequest(); if ($request->isPost()) { $token_id = $this->container()->get('token_id'); $this->container()->clear('token_id'); if ($token_id != $request->getPost('token_id')) { $this->flashMessenger()->addMessage('Not allowed'); // $this->flashMessenger()->addMessage('許可されていません。'); return $this->redirect()->toRoute('app', array('controller' => 'index')); } $db = new UserEntity(); $chk = true; $i = 0; while ($chk) { $new_pw = make_rand_str(8, 3); $chk = $db->db()->checkLoginPw($row->create_user, $new_pw); ++$i; if (!$chk || 10 < $i) { // avoid infinite loop break; } } if (!$chk) { $success = $db->changePw($row->create_user, $new_pw, 1); } if ($success) { $mail = new Message(); $mail->setEncoding("UTF-8"); $mail->addFrom(AUTO_MAIL_FROM)->addTo($row->email)->setSubject($this->translator()->translate("About initialize password")); // ->setSubject($this->translator()->translate("パスワード初期化について")); $body_tpl = file_get_contents(APP_DIR . '/tpl/remind-store-mail.txt'); $body_tpl = trim(str_replace("\r\n", "\n", $body_tpl)); $body_tpl = $this->translator()->translate($body_tpl); $body_tpl .= "\n\n" . "PW:" . $new_pw; $body_tpl .= "\n\n\n" . "URL:" . BASE_URL; $mail->setBody($body_tpl); $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'plain', 'connection_config' => array('ssl' => 'tls', 'username' => AUTO_MAIL_FROM, 'password' => AUTO_MAIL_FROM_PASSWORD), 'port' => 587)); $transport->setOptions($options); } if ($success) { $success = $transport->send($mail); } else { if (IS_TEST) { $logger = new \Zend\Log\Logger(); $writer = new \Zend\Log\Writer\Stream(APP_DIR . '/log/debug.txt'); $logger->addWriter($writer); $logger->log(\Zend\Log\Logger::DEBUG, print_r($mail, 1)); } } $tmp->finishRecord($id); $message = $success ? 'Please confirm e-mail' : 'Failed'; // $message = $success ? 'メールを確認してください。' : '処理失敗'; $this->flashMessenger()->addMessage($message); return $this->redirect()->toRoute('app', array('controller' => 'index')); } // create token_id $token_id = make_token_id(); $this->container()->set('token_id', $token_id); $values = array('token_id' => $token_id, 'id' => $id); $view = new ViewModel($values); $view->setTemplate('/' . VIEW_DIR . '/index/remind-store.phtml'); return $view; }
public function detailsAction() { $decision_no = (int) $this->params()->fromRoute('id', 0); if (!$decision_no) { return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden')); } $this->init(); $fm = $this->flashMessenger(); $success = 0 < $this->ctrlLv ? true : false; if (!$success) { return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden')); } $fm = $this->flashMessenger(); $decisionTable = new DecisionTable(); $loggedin_user_no = $this->auth()->get('user_no'); try { $decisionDetails = $decisionTable->getApprovalDetails($decision_no, $loggedin_user_no); $approversList = $decisionTable->getApproverList($decisionDetails['decision_no'], $this->auth()->get('user_no')); $approvalAttachments = $decisionTable->getApprovalAttachments($decision_no); } catch (\Exception $e) { $this->flashMessenger()->addMessage("Fatal Error! " . $e->getMessage()); return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden')); } $continue = false; foreach ($approversList as $approver) { if ($approver["user_no"] == $loggedin_user_no || $loggedin_user_no == $decisionDetails['create_user']) { $continue = true; break; } } if (!$continue) { $this->flashMessenger()->addMessage("You must be 1 of its approver in order to view this resource.."); return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden')); } $form = new ApprovalForm(); $form->setApprovalDetailsForm(); $success = false; $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); $filter = new ApprovalFilter(); $filter->setDetailsFilter(); $form->setInputFilter($filter->getInputFilter()); if ($form->isValid()) { $parram = $this->params(); $mail = new Message(); $mail->setEncoding("UTF-8"); if ($parram->fromPost('approve') != null) { $success = $decisionTable->approveRequest($decision_no, $this->auth()->get('user_no'), $this->params()->fromPost('remarks')); $approver = $decisionTable->getCurrentApprover($decision_no); $progress = $decisionTable->isCompleted($decision_no); if ($progress) { $mail->addFrom(AUTO_MAIL_FROM)->addTo($decisionDetails['email'])->setSubject("Request Completed - " . $decisionDetails['decision_title']); $body_tpl = "Your Request has been approved."; $body_tpl .= "\nFor more details, just click the link below"; $body_tpl .= "\n\n\n Reference no.: " . $decisionDetails['ref_no']; $body_tpl .= "\n Request: " . $decisionDetails['decision_title']; $body_tpl .= "\n" . "URL:" . BASE_URL . "/approval/details/" . $decision_no; $body_tpl .= "\n\n *** This is an automatically generated email, please do not reply ***"; $mail->setBody($body_tpl); } else { $mail->addFrom(AUTO_MAIL_FROM)->addTo($approver['email'])->setSubject("Approval Request - " . $decisionDetails['decision_title']); $body_tpl = file_get_contents(APP_DIR . '/tpl/remind-request.txt'); $body_tpl = trim(str_replace("\r\n", "\n", $body_tpl)); $body_tpl = $this->translator()->translate($body_tpl); $body_tpl .= "\n\n\n Reference no.: " . $decisionDetails['ref_no']; $body_tpl .= "\n Request: " . $decisionDetails['decision_title']; $body_tpl .= "\n" . "URL:" . BASE_URL . "/approval/details/" . $decision_no; $body_tpl .= "\n\n *** This is an automatically generated email, please do not reply ***"; $mail->setBody($body_tpl); } } else { if ($parram->fromPost('reject') != null) { $success = $decisionTable->rejectRequest($decision_no, $this->auth()->get('user_no'), $this->params()->fromPost('remarks')); $mail->addFrom(AUTO_MAIL_FROM)->addTo($decisionDetails['email'])->setSubject("Request Rejected - " . $decisionDetails['decision_title']); $cc_approver = $decisionTable->getApprovers($decision_no); foreach ($cc_approver as $each_recipient) { $mail->addCc($each_recipient['email']); } $body_tpl = "Request has been rejected by " . $this->auth()->get('user_name'); $body_tpl .= "\n\n\n Reference no.: " . $decisionDetails['ref_no']; $body_tpl .= "\n Request: " . $decisionDetails['decision_title']; $body_tpl .= "\n\n " . $this->auth()->get('user_name') . ":" . $this->params()->fromPost('remarks') . "\n\n"; $body_tpl .= "\n\n *** This is an automatically generated email, please do not reply ***"; $mail->setBody($body_tpl); } else { if ($parram->fromPost('recall') != null) { $success = $decisionTable->recallRequest($decision_no, $this->auth()->get('user_no'), $this->params()->fromPost('remarks')); $nextApprover = $decisionTable->nextApprover($decision_no); $mail->addFrom(AUTO_MAIL_FROM)->addCc($nextApprover['email'])->addBcc($decisionDetails['email'])->setSubject("Approval Recall - " . $decisionDetails['decision_title']); $recipients = $decisionTable->getApprovers($decision_no); foreach ($recipients as $each_recipient) { $mail->addTo($each_recipient['email']); } $body_tpl = "Request has been recalled by " . $this->auth()->get('user_name') . " san"; $body_tpl .= "\n\n\n Reference no.: " . $decisionDetails['ref_no']; $body_tpl .= "\n Subject: " . $decisionDetails['decision_title']; $body_tpl .= "\n\n " . $this->auth()->get('user_name') . ":" . $this->params()->fromPost('remarks') . "\n\n"; $body_tpl .= "\n\n *** This is an automatically generated email, please do not reply ***"; $mail->setBody($body_tpl); } else { if ($parram->fromPost('recall-by-owner') != null) { $success = $decisionTable->recallByOwner($decision_no, $this->auth()->get('user_no'), $this->params()->fromPost('remarks')); $mail->addFrom(AUTO_MAIL_FROM)->setSubject("Approval Recall by Requestor - " . $decisionDetails['decision_title']); $recipients = $decisionTable->getApprovers($decision_no); foreach ($recipients as $each_recipient) { $mail->addTo($each_recipient['email']); } $body_tpl = "Request has been recalled by applicant - " . $decisionDetails['user_name']; $body_tpl .= "\n\n\n Reference no.: " . $decisionDetails['ref_no']; $body_tpl .= "\n Subject: " . $decisionDetails['decision_title']; $body_tpl .= "\n\n " . $decisionDetails['user_name'] . ":" . $this->params()->fromPost('remarks') . "\n\n"; $body_tpl .= "\n\n *** This is an automatically generated email, please do not reply ***"; $mail->setBody($body_tpl); } } } } if ($success) { $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'plain', 'connection_config' => array('ssl' => 'tls', 'username' => AUTO_MAIL_FROM, 'password' => AUTO_MAIL_FROM_PASSWORD), 'port' => 587)); $transport->setOptions($options); $success = $transport->send($mail); } else { if ($success && IS_TEST) { $logger = new \Zend\Log\Logger(); $writer = new \Zend\Log\Writer\Stream(APP_DIR . '/log/debug.txt'); $logger->addWriter($writer); $logger->log(\Zend\Log\Logger::DEBUG, print_r($mail, 1)); } } return $this->redirect()->toRoute('app', array('controller' => 'approval', 'action' => 'details', 'id' => $decision_no)); } } $values = array('ctrlLv' => $this->ctrlLv, 'admin' => $this->auth()->get('admin'), 'user_log' => $loggedin_user_no, 'approver' => $this->auth()->get('approver'), 'decisionDetails' => $decisionDetails, 'approversList' => $approversList, 'approvalAttachments' => $approvalAttachments, 'form' => $form, 'id' => $decision_no); $view = new ViewModel($values); $view->setTemplate('/' . VIEW_DIR . '/approval/details.phtml'); return $view; }