public function indexAction() { $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuReceiver'), array('action' => 'index')); $receiverMapper = new ReceiverMapper(); $receivers = $receiverMapper->getReceivers(); $this->getView()->set('receivers', $receivers); if ($this->getRequest()->getPost('saveContact')) { $receiver = $receiverMapper->getReceiverById($this->getRequest()->getPost('contact_receiver')); $name = $this->getRequest()->getPost('contact_name'); $contactEmail = $this->getRequest()->getPost('contact_email'); $subject = $this->getTranslator()->trans('contactWebsite') . $this->getConfig()->get('page_title') . ':<' . $name . '>(' . $contactEmail . ')'; $captcha = trim(strtolower($this->getRequest()->getPost('captcha'))); $message = $this->getRequest()->getPost('contact_message'); if (empty($_SESSION['captcha']) || $captcha != $_SESSION['captcha']) { $this->addMessage('invalidCaptcha', 'danger'); } elseif (empty($message)) { $this->addMessage('missingText', 'danger'); } elseif (empty($name)) { $this->addMessage('missingName', 'danger'); } elseif (empty($contactEmail)) { $this->addMessage('missingEmail', 'danger'); } else { /* * @todo create a general sender. */ $mail = new \Ilch\Mail(); $mail->setTo($receiver->getEmail(), $receiver->getName())->setSubject($subject)->setFrom('*****@*****.**', 'automatische eMail')->setMessage($message)->addGeneralHeader('Content-type', 'text/plain; charset="utf-8"'); $mail->send(); $this->addMessage('sendSuccess'); } } }
public function treatAction() { $receiverMapper = new ReceiverMapper(); if ($this->getRequest()->getParam('id')) { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuReceiver'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat', 'id' => $this->getRequest()->getParam('id'))); $this->getView()->set('receiver', $receiverMapper->getReceiverById($this->getRequest()->getParam('id'))); } else { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuReceiver'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat')); } if ($this->getRequest()->isPost()) { $model = new ReceiverModel(); if ($this->getRequest()->getParam('id')) { $model->setId($this->getRequest()->getParam('id')); } $model->setName($this->getRequest()->getPost('name')); $model->setEmail($this->getRequest()->getPost('email')); $receiverMapper->save($model); $this->redirect(array('action' => 'index')); } }