Example #1
0
 /**
  * Show preview and send the Newsletter.
  *
  * @return string
  */
 public function send()
 {
     $id = $this->Input->get('id');
     $newsletter = AvisotaNewsletter::load($id);
     if (!$newsletter) {
         $this->redirect('contao/main.php?do=avisota_newsletter');
     }
     $category = AvisotaNewsletterCategory::load($newsletter->pid);
     if (!$category) {
         $this->redirect('contao/main.php?do=avisota_newsletter');
     }
     if (!$this->User->isAdmin) {
         if (!is_array($this->User->avisota_newsletter_categories) || count($this->User->avisota_newsletter_categories) < 1) {
             $root = array(0);
         } else {
             $root = $this->User->avisota_newsletter_categories;
         }
         if (!in_array($category->id, $root)) {
             $this->log('Not enough permissions to send newsletter from category ID ' . $category->id, 'Avisota::send()', TL_ERROR);
             $this->redirect('contao/main.php?act=error');
         }
     }
     AvisotaStatic::pushCategory($category);
     AvisotaStatic::pushNewsletter($newsletter);
     $template = new BackendTemplate('be_avisota_send');
     $template->import('BackendUser', 'User');
     // allow backend sending
     $template->beSend = $this->Base->allowBackendSending();
     // Store the current referer
     $session = $this->Session->get('referer');
     if ($session['current'] != $this->Environment->requestUri) {
         $session['orm_avisota_message'] = $this->Environment->requestUri;
         $session['last'] = $session['current'];
         $session['current'] = $this->Environment->requestUri;
         $this->Session->set('referer', $session);
     }
     $template->users = $this->getAllowedUsers();
     return $template->parse();
 }
 public function addHeader($add, $dc)
 {
     $key = $GLOBALS['TL_LANG']['orm_avisota_message_category']['recipients'][0];
     $add[$key] = array();
     $category = AvisotaNewsletterCategory::load($dc->id);
     $fallback = $category->recipientsMode == 'byNewsletterOrCategory';
     $selectedRecipients = $category->getRecipients();
     $recipients = AvisotaBackend::getInstance()->getRecipients(true);
     foreach ($recipients as $group => $lists) {
         list($source, $group) = explode(':', $group, 2);
         foreach ($lists as $listKey => $list) {
             if (in_array($listKey, $selectedRecipients)) {
                 $add[$key][] = sprintf('<a href="contao/main.php?do=avisota_recipient_source&act=edit&id=%d">%s &raquo; %s</a>%s', $source, $group, $list, $fallback ? ' ' . $GLOBALS['TL_LANG']['orm_avisota_message']['fallback'] : '');
             }
         }
     }
     $add[$key] = implode('<br>', $add[$key]);
     if ($category->themeMode == 'byNewsletterOrCategory') {
         $key = $GLOBALS['TL_LANG']['orm_avisota_message_category']['theme'][0];
         $add[$key] .= ' ' . $GLOBALS['TL_LANG']['orm_avisota_message']['fallback'];
     }
     return $add;
 }