コード例 #1
0
 /**
  * Do the migration.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $sourceIds = array_filter(array_map('intval', $dc->getData('source')));
     $usePersonals = $dc->getData('personals') ? true : false;
     $force = $dc->getData('force') ? true : false;
     if (count($sourceIds)) {
         $source = implode(',', $sourceIds);
         $insertPersonals = '';
         $selectPersonals = '';
         if ($usePersonals) {
             $this->loadDataContainer('orm_avisota_recipient');
             $this->loadDataContainer('tl_member');
             foreach ($GLOBALS['TL_DCA']['orm_avisota_recipient']['fields'] as $fieldName => $fieldConfig) {
                 if (!in_array($fieldName, array('pid', 'tstamp', 'email', 'confirmed', 'addedOn', 'addedBy', 'token')) && isset($fieldConfig['eval']['importable']) && $fieldConfig['eval']['importable'] && isset($GLOBALS['TL_DCA']['tl_member']['fields'][$fieldName])) {
                     $insertPersonals .= ',' . $fieldName;
                     $selectPersonals .= ',IFNULL(m.' . $fieldName . ', "")';
                 }
             }
         }
         $stmt = \Database::getInstance()->prepare("INSERT INTO\n\t\t\t\t\t\torm_avisota_recipient (pid,tstamp,email" . $insertPersonals . ",confirmed,addedOn,addedBy,token)\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t?,r.tstamp,r.email" . $selectPersonals . ",r.active,?,?,r.token\n\t\t\t\t\tFROM\n\t\t\t\t\t\ttl_newsletter_recipients r\n\t\t\t\t\t" . ($usePersonals ? "\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\ttl_member m\n\t\t\t\t\tON\n\t\t\t\t\t\tr.email = m.email\n\t\t\t\t\t" : "") . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tr.pid IN ({$source})\n\t\t\t\t\tAND\n\t\t\t\t\t\tr.email NOT IN (SELECT email FROM orm_avisota_recipient WHERE pid=?)\n\t\t\t\t\t" . ($force ? "" : "\n\t\t\t\t\tAND\n\t\t\t\t\t\tMD5(r.email) NOT IN (SELECT email FROM orm_avisota_recipient_blacklist WHERE pid=?)\n\t\t\t\t\t"))->execute($this->Input->get('id'), time(), $this->User->id, $this->Input->get('id'), $this->Input->get('id'));
         $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_migrate']['migrated'], $stmt->affectedRows);
         if ($force) {
             \Database::getInstance()->prepare("DELETE FROM\n\t\t\t\t\t\t\torm_avisota_recipient_blacklist\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tpid=?\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t\temail IN (SELECT MD5(email) FROM orm_avisota_recipient WHERE pid=?)")->execute($this->Input->get('id'), $this->Input->get('id'));
         }
     }
     setcookie('BE_PAGE_OFFSET', 0, 0, '/');
     $this->reload();
 }
コード例 #2
0
 /**
  *
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $categoryId = $dc->getData('category');
     $subject = $dc->getData('subject');
     $draftId = $dc->getData('draft');
     $newsletterDraft = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_message_draft WHERE id=?")->execute($draftId);
     if ($newsletterDraft->next()) {
         $newsletterDraftData = $newsletterDraft->row();
         // remove unwanted fields
         unset($newsletterDraftData['id'], $newsletterDraftData['tstamp'], $newsletterDraftData['title'], $newsletterDraftData['description'], $newsletterDraftData['alias']);
         // set pid
         $newsletterDraftData['pid'] = $categoryId;
         // set subject
         $newsletterDraftData['subject'] = $subject;
         // call hook
         // TODO AvisotaHelper::callHook('prepareNewsletterCreateFromDraft', array(&$arrRow));
         $value = '';
         for ($i = 0; $i < count($newsletterDraftData); $i++) {
             if ($i > 0) {
                 $value .= ',';
             }
             $value .= '?';
         }
         $newsletter = \Database::getInstance()->prepare("INSERT INTO orm_avisota_message (" . implode(",", array_keys($newsletterDraftData)) . ") VALUES ({$value})")->execute($newsletterDraftData);
         $newsletterId = $newsletter->insertId;
         $content = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_message_draft_content WHERE pid=?")->execute($draftId);
         while ($content->next()) {
             $newsletterDraftData = $content->row();
             // remove unwanted fields
             unset($newsletterDraftData['id'], $newsletterDraftData['tstamp']);
             // set pid
             $newsletterDraftData['pid'] = $newsletterId;
             // call hook
             // TODO AvisotaHelper::callHook('prepareNewsletterContentCreateFromDraft', array(&$arrRow));
             // prevent pid changing
             $newsletterDraftData['pid'] = $newsletterId;
             $value = '';
             for ($i = 0; $i < count($newsletterDraftData); $i++) {
                 if ($i > 0) {
                     $value .= ',';
                 }
                 $value .= '?';
             }
             $newsletter = \Database::getInstance()->prepare("INSERT INTO orm_avisota_message_content (" . implode(",", array_keys($newsletterDraftData)) . ") VALUES ({$value})")->execute($newsletterDraftData);
         }
         $_SESSION['TL_INFO'][] = $GLOBALS['TL_LANG']['orm_avisota_message_create_from_draft']['created'];
         $this->redirect('contao/main.php?do=avisota_newsletter&table=orm_avisota_message_content&id=' . $newsletterId);
     }
 }
コード例 #3
0
 /**
  * Do the import.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $recipientId = $dc->getData('recipient');
     if ($recipientId != $this->Input->get('id')) {
         $this->redirect('contao/main.php?do=avisota_recipient&amp;table=orm_avisota_recipient_notify&amp;act=edit&amp;id=' . $recipientId);
     }
     $confirmations = $dc->getData('confirmations');
     $notifications = $dc->getData('notifications');
     $overdue = $dc->getData('overdue');
     $recipient = new AvisotaIntegratedRecipient(array('id' => $recipientId));
     $recipient->load();
     if (is_array($confirmations) && count($confirmations)) {
         $recipient->sendSubscriptionConfirmation($confirmations);
     }
     if (is_array($notifications) && count($notifications)) {
         $recipient->sendRemind($notifications, true);
     }
     if (is_array($overdue) && count($overdue)) {
         $recipient->sendRemind($overdue, true);
     }
 }
コード例 #4
0
 /**
  * Do the import.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $source = $dc->getData('source');
     $upload = $dc->getData('upload');
     $emails = $dc->getData('emails');
     $totalCount = 0;
     if (is_array($source)) {
         foreach ($source as $csvFile) {
             $file = new File($csvFile);
             $this->removeRecipients($file->getContent(), $totalCount);
         }
     }
     if ($upload) {
         $this->removeRecipients(file_get_contents($upload['tmp_name']), $totalCount);
     }
     if ($emails) {
         $this->removeRecipients($emails, $totalCount);
     }
     $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_remove']['confirm'], $totalCount);
     setcookie('BE_PAGE_OFFSET', 0, 0, '/');
     $this->reload();
 }
コード例 #5
0
 /**
  * Do the import.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $source = $dc->getData('source');
     $upload = $dc->getData('upload');
     // Get delimiter
     switch ($dc->getData('delimiter')) {
         case 'semicolon':
             $delimiter = ';';
             break;
         case 'tabulator':
             $delimiter = "\t";
             break;
         case 'linebreak':
             $delimiter = "\n";
             break;
         default:
             $delimiter = ',';
             break;
     }
     // Get enclosure
     switch ($dc->getData('enclosure')) {
         case 'single':
             $enclosure = '\'';
             break;
         default:
             $enclosure = '"';
             break;
     }
     // Get columns
     $rawColumns = $dc->getData('columns');
     $overwrite = $dc->getData('overwrite') ? true : false;
     $force = $dc->getData('force') ? true : false;
     $this->Session->set('AVISOTA_IMPORT', array('delimiter' => $dc->getData('delimiter'), 'enclosure' => $dc->getData('enclosure'), 'columns' => $dc->getData('columns')));
     if ($this->validateFieldSelectorArray($rawColumns)) {
         $columns = array();
         foreach ($rawColumns as $row) {
             $columns[$row['values']['colnum']] = $row['values']['field'];
         }
         $startTime = time();
         $totalCount = 0;
         $overwriteCount = 0;
         $skipCount = 0;
         $invalidCount = 0;
         if (is_array($source)) {
             foreach ($source as $csvFile) {
                 $file = new File($csvFile);
                 if ($file->extension != 'csv') {
                     $_SESSION['TL_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $file->extension);
                     continue;
                 }
                 $this->importRecipients($file->handle, $delimiter, $enclosure, $columns, $overwrite, $force, $startTime, $totalCount, $overwriteCount, $skipCount, $invalidCount);
                 $file->close();
             }
         }
         if ($upload) {
             $resFile = fopen($upload['tmp_name'], 'r');
             $this->importRecipients($resFile, $delimiter, $enclosure, $columns, $overwrite, $force, $startTime, $totalCount, $overwriteCount, $skipCount, $invalidCount);
             fclose($resFile);
         }
         if ($totalCount > 0) {
             $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['confirmed'], $totalCount);
         }
         if ($overwriteCount > 0) {
             $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['overwritten'], $overwriteCount);
         }
         if ($skipCount > 0) {
             $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['skipped'], $skipCount);
         }
         if ($invalidCount > 0) {
             $_SESSION['TL_INFO'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['invalid'], $invalidCount);
         }
     }
     setcookie('BE_PAGE_OFFSET', 0, 0, '/');
     $this->reload();
 }
コード例 #6
0
 /**
  * Do the export.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     // Get delimiter
     switch ($dc->getData('delimiter')) {
         case 'semicolon':
             $delimiter = ';';
             break;
         case 'tabulator':
             $delimiter = "\t";
             break;
         case 'linebreak':
             $delimiter = "\n";
             break;
         default:
             $delimiter = ',';
             break;
     }
     // Get enclosure
     switch ($dc->getData('enclosure')) {
         case 'single':
             $enclosure = '\'';
             break;
         default:
             $enclosure = '"';
             break;
     }
     // Get fields
     $fields = $dc->getData('fields');
     // Get field labels
     $labels = array();
     foreach ($fields as $field) {
         switch ($field) {
             default:
                 $fieldConfig = $GLOBALS['TL_DCA']['orm_avisota_recipient']['fields'][$field];
                 if (empty($fieldConfig['label'][0])) {
                     $labels[] = $field;
                 } else {
                     $labels[] = $fieldConfig['label'][0] . ' [' . $field . ']';
                 }
                 break;
         }
     }
     $this->Session->set('AVISOTA_EXPORT', array('delimiter' => $dc->getData('delimiter'), 'enclosure' => $dc->getData('enclosure'), 'fields' => $dc->getData('fields')));
     // search for the list
     $list = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_mailing_list WHERE id=?")->execute($this->Input->get('id'));
     if (!$list->next()) {
         $this->log('The recipient list ID ' . $this->Input->get('id') . ' does not exists!', 'orm_avisota_recipient_export', TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // create temporary file
     $temporaryPathname = substr(tempnam(TL_ROOT . '/system/tmp', 'recipients_export_') . '.csv', strlen(TL_ROOT) + 1);
     // create new file object
     $temporaryFile = new File($temporaryPathname);
     // open file handle
     $temporaryFile->write('');
     // write the headline
     fputcsv($temporaryFile->handle, $labels, $delimiter, $enclosure);
     // write recipient rows
     $recipient = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_recipient WHERE pid=?")->execute($this->Input->get('id'));
     while ($recipient->next()) {
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 default:
                     $row[] = $recipient->{$field};
             }
         }
         fputcsv($temporaryFile->handle, $row, $delimiter, $enclosure);
     }
     // close file handle
     $temporaryFile->close();
     // create temporary zip file
     $zipFile = $temporaryPathname . '.zip';
     // create a zip writer
     $zip = new ZipWriter($zipFile);
     // add the temporary csv
     $zip->addFile($temporaryPathname, $list->title . '.csv');
     // close the zip
     $zip->close();
     // create new file object
     $zip = new File($zipFile);
     // Open the "save as …" dialogue
     header('Content-Type: ' . $zip->mime);
     header('Content-Transfer-Encoding: binary');
     header('Content-Disposition: attachment; filename="' . $list->title . '.zip"');
     header('Content-Length: ' . $zip->filesize);
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Expires: 0');
     // send the zip file
     $resFile = fopen(TL_ROOT . '/' . $zipFile, 'rb');
     fpassthru($resFile);
     fclose($resFile);
     // delete temporary files
     $temporaryFile->delete();
     $zip->delete();
     exit;
 }
コード例 #7
0
ファイル: View.php プロジェクト: fuelphp/display
 /**
  * Retrieves all view data from the view and the viewManager
  *
  * @return array
  */
 public function getData()
 {
     $data = parent::getData();
     $global = $this->viewManager->getData();
     return array_merge($global, $data);
 }