Exemplo n.º 1
0
 public function indexAction()
 {
     $newsletterMapper = new NewsletterMapper();
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('settings'), array('action' => 'index'));
     if ($this->getRequest()->isPost()) {
         $newsletterModel = new NewsletterModel();
         foreach ($this->getRequest()->getPost('check_users') as $userEmail) {
             if ($userEmail != '') {
                 $newsletterModel->setEmail($userEmail);
                 $newsletterMapper->saveEmail($newsletterModel);
                 //$newsletterMapper->activeEmail($newsletterModel);
             }
         }
         $this->addMessage('saveSuccess');
     }
     $emails = $newsletterMapper->getMail();
     $this->getView()->set('emails', $emails);
     $userList = $newsletterMapper->getSendMailUser();
     $this->getView()->set('userList', $userList);
 }
Exemplo n.º 2
0
 public function treatAction()
 {
     $newsletterMapper = new NewsletterMapper();
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuNewsletter'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat'));
     if ($this->getRequest()->isPost()) {
         $newsletterModel = new NewsletterModel();
         $subject = trim($this->getRequest()->getPost('subject'));
         $text = trim($this->getRequest()->getPost('text'));
         if (empty($subject)) {
             $this->addMessage('missingSubject', 'danger');
         } elseif (empty($text)) {
             $this->addMessage('missingText', 'danger');
         } else {
             $date = new \Ilch\Date();
             $newsletterModel->setDateCreated($date);
             $newsletterModel->setUserId($this->getUser()->getId());
             $newsletterModel->setSubject($this->getRequest()->getPost('subject'));
             $newsletterModel->setText($this->getRequest()->getPost('text'));
             $newsletterMapper->save($newsletterModel);
             if ($_SESSION['layout'] == $this->getConfig()->get('default_layout') && file_exists(APPLICATION_PATH . '/layouts/' . $this->getConfig()->get('default_layout') . '/views/modules/newsletter/layouts/mail/newsletter.php')) {
                 $messageTemplate = file_get_contents(APPLICATION_PATH . '/layouts/' . $this->getConfig()->get('default_layout') . '/views/modules/newsletter/layouts/mail/newsletter.php');
             } else {
                 $messageTemplate = file_get_contents(APPLICATION_PATH . '/modules/newsletter/layouts/mail/newsletter.php');
             }
             $emails = $newsletterMapper->getMail();
             foreach ($emails as $email) {
                 $messageReplace = array('{subject}' => $this->getRequest()->getPost('subject'), '{content}' => $this->getRequest()->getPost('text'), '{sitetitle}' => $this->getConfig()->get('page_title'), '{date}' => $date->format("l, d. F Y", true), '{footer}' => $this->getTranslator()->trans('noReplyMailFooter'), '{unreadable}' => $this->getTranslator()->trans('mailUnreadable', $newsletterMapper->getLastId(), $email->getEmail()), '{unsubscribe}' => $this->getTranslator()->trans('mailUnsubscribe', $email->getEmail()));
                 $message = str_replace(array_keys($messageReplace), array_values($messageReplace), $messageTemplate);
                 $mail = new \Ilch\Mail();
                 $mail->setTo($email->getEmail(), '')->setSubject($this->getRequest()->getPost('subject'))->setFrom($this->getConfig()->get('standardMail'), $this->getConfig()->get('page_title'))->setMessage($message)->addGeneralHeader('Content-type', 'text/html; charset="utf-8"');
                 $mail->send();
             }
             $this->addMessage('sendSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
     $emails = $newsletterMapper->getMail();
     $this->getView()->set('emails', $emails);
 }
Exemplo n.º 3
0
 /**
  * Remove the specified newsletter from storage.
  *
  * @param  int $id
  * @return View
  */
 public function destroy($id = null)
 {
     // If multiple ids are specified
     if ($id == 'multiple') {
         $selected_ids = trim(Input::get('selected_ids'));
         if ($selected_ids == '') {
             return Redirect::back()->with('error_message', "Nothing was selected to delete");
         }
         $selected_ids = explode(' ', $selected_ids);
     } else {
         $selected_ids = array($id);
     }
     foreach ($selected_ids as $id) {
         $newsletter = Newsletter::findOrFail($id);
         $newsletter->delete();
     }
     $wasOrWere = count($selected_ids) > 1 ? 's were' : ' was';
     $message = 'The newsletter' . $wasOrWere . ' deleted.';
     return Redirect::to("{$this->link_type}/modules/newsletters")->with('success_message', $message);
 }
Exemplo n.º 4
0
 /**
  * Insert Mail to Newsletter
  */
 public function saveUserEmail(NewsletterModel $newsletter)
 {
     $userRow = $this->db()->select('email')->from('users')->where(array('id' => $newsletter->getId()))->execute()->fetchRows();
     $userMail = $userRow[0]['email'];
     $newsletterMail = $this->countEmails($userMail);
     if ($newsletterMail == '0') {
         $this->db()->insert('newsletter_mails')->values(array('email' => $userMail))->execute();
     } else {
         $this->db()->delete('newsletter_mails')->where(array('email' => $userMail))->execute();
     }
 }
Exemplo n.º 5
0
 /**
  * Inserts newsletter mail model.
  *
  * @param NewsletterModel $newsletter
  */
 public function saveEmail(NewsletterModel $newsletter)
 {
     $this->db()->insert('newsletter_mails')->values(array('email' => $newsletter->getEmail()))->execute();
 }