Example #1
0
 /**
  * Function executed from scheduler.
  * Creates a new newsletter record, and sets the scheduled time to "now"
  *
  * @return	bool
  */
 public function execute()
 {
     if ($this->draftUid > 0) {
         $this->initializeHookObjects();
         $hookParams = array();
         $draftRecord = BackendUtility::getRecord('sys_dmail', $this->draftUid);
         // get some parameters from tsConfig
         $tsConfig = BackendUtility::getModTSconfig($draftRecord['pid'], 'mod.web_modules.dmail');
         $defaultParams = $tsConfig['properties'];
         // make a real record out of it
         unset($draftRecord['uid']);
         $draftRecord['tstamp'] = time();
         // set the right type (3 => 1, 2 => 0)
         $draftRecord['type'] -= 2;
         // check if domain record is set
         if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI && (int) $draftRecord['type'] !== 1 && empty($draftRecord['use_domain'])) {
             throw new \Exception('No domain record set!');
         }
         // Insert the new dmail record into the DB
         $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_dmail', $draftRecord);
         $this->dmailUid = $GLOBALS['TYPO3_DB']->sql_insert_id();
         // Call a hook after insertion of the cloned dmail record
         // This hook can get used to modify fields of the direct mail.
         // For example the current date could get appended to the subject.
         $hookParams['draftRecord'] =& $draftRecord;
         $hookParams['defaultParams'] =& $defaultParams;
         $this->callHooks('postInsertClone', $hookParams);
         // fetch the cloned record
         $mailRecord = BackendUtility::getRecord('sys_dmail', $this->dmailUid);
         // fetch mail content
         $result = DirectMailUtility::fetchUrlContentsForDirectMailRecord($mailRecord, $defaultParams, TRUE);
         if ($result['errors'] !== array()) {
             throw new \Exception('Failed to fetch contents: ' . implode(', ', $result['errors']));
         }
         $mailRecord = BackendUtility::getRecord('sys_dmail', $this->dmailUid);
         if ($mailRecord['mailContent'] && $mailRecord['renderedsize'] > 0) {
             $updateData = array('scheduled' => time(), 'issent' => 1);
             // Call a hook before enqueuing the cloned dmail record into
             // the direct mail delivery queue
             $hookParams['mailRecord'] =& $mailRecord;
             $hookParams['updateData'] =& $updateData;
             $this->callHooks('enqueueClonedDmail', $hookParams);
             // Update the cloned dmail so it will get sent upon next
             // invocation of the mailer engine
             $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_dmail', 'uid = ' . intval($this->dmailUid), $updateData);
         }
     }
     return true;
 }
Example #2
0
 /**
  * Show the categories table for user to categorize the directmail content
  * TYPO3 content)
  *
  * @param array $row The dmail row.
  *
  * @return string HTML form showing the categories
  */
 public function makeCategoriesForm(array $row)
 {
     $indata = GeneralUtility::_GP('indata');
     if (is_array($indata['categories'])) {
         $data = array();
         foreach ($indata['categories'] as $recUid => $recValues) {
             $enabled = array();
             foreach ($recValues as $k => $b) {
                 if ($b) {
                     $enabled[] = $k;
                 }
             }
             $data['tt_content'][$recUid]['module_sys_dmail_category'] = implode(',', $enabled);
         }
         /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
         $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
         $tce->stripslashes_values = 0;
         $tce->start($data, array());
         $tce->process_datamap();
         // remove cache
         $tce->clear_cacheCmd($this->pages_uid);
         $out = DirectMailUtility::fetchUrlContentsForDirectMailRecord($row, $this->params);
     }
     // Todo Perhaps we should here check if TV is installed and fetch content from that instead of the old Columns...
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('colPos, CType, uid, pid, header, bodytext, module_sys_dmail_category', 'tt_content', 'pid=' . intval($this->pages_uid) . BackendUtility::deleteClause('tt_content') . BackendUtility::BEenableFields('tt_content'), '', 'colPos,sorting');
     if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
         $theOutput = $this->doc->section($this->getLanguageService()->getLL('nl_cat'), $this->getLanguageService()->getLL('nl_cat_msg1'), 1, 1, 0, true);
     } else {
         $out = '';
         $colPosVal = 99;
         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             $categoriesRow = '';
             $resCat = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid_foreign', 'sys_dmail_ttcontent_category_mm', 'uid_local=' . $row['uid']);
             while ($rowCat = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resCat)) {
                 $categoriesRow .= $rowCat['uid_foreign'] . ',';
             }
             $GLOBALS['TYPO3_DB']->sql_free_result($resCat);
             $categoriesRow = rtrim($categoriesRow, ',');
             if ($colPosVal != $row['colPos']) {
                 $out .= '<tr><td colspan="3" bgcolor="' . $this->doc->bgColor5 . '">' . $this->getLanguageService()->getLL('nl_l_column') . ': <strong>' . BackendUtility::getProcessedValue('tt_content', 'colPos', $row['colPos']) . '</strong></td></tr>';
                 $colPosVal = $row["colPos"];
             }
             $out .= '<tr>';
             $out .= '<td valign="top" width="75%">' . $this->iconFactory->getIconForRecord('tt_content', $row, Icon::SIZE_SMALL) . $row['header'] . '<br />' . GeneralUtility::fixed_lgd_cs(strip_tags($row['bodytext']), 200) . '<br /></td>';
             $out .= '<td nowrap valign="top">';
             $checkBox = '';
             if ($row['module_sys_dmail_category']) {
                 $checkBox .= '<strong style="color:red;">' . $this->getLanguageService()->getLL('nl_l_ONLY') . '</strong>';
             } else {
                 $checkBox .= '<strong style="color:green">' . $this->getLanguageService()->getLL('nl_l_ALL') . '</strong>';
             }
             $checkBox .= '<br />';
             $this->categories = DirectMailUtility::makeCategories('tt_content', $row, $this->sys_language_uid);
             reset($this->categories);
             foreach ($this->categories as $pKey => $pVal) {
                 $checkBox .= '<input type="hidden" name="indata[categories][' . $row["uid"] . '][' . $pKey . ']" value="0">' . '<input type="checkbox" name="indata[categories][' . $row['uid'] . '][' . $pKey . ']" value="1"' . (GeneralUtility::inList($categoriesRow, $pKey) ? ' checked' : '') . '> ' . htmlspecialchars($pVal) . '<br />';
             }
             $out .= $checkBox . '</td></tr>';
         }
         $GLOBALS['TYPO3_DB']->sql_free_result($res);
         $out = '<table border="0" cellpadding="0" cellspacing="0" class="table table-striped table-hover">' . $out . '</table>';
         $out .= '<input type="hidden" name="pages_uid" value="' . $this->pages_uid . '">' . '<input type="hidden" name="CMD" value="' . $this->CMD . '"><br />' . '<input type="submit" name="update_cats" value="' . $this->getLanguageService()->getLL('nl_l_update') . '">';
         $theOutput = $this->doc->section($this->getLanguageService()->getLL('nl_cat') . BackendUtility::cshItem($this->cshTable, 'assign_categories', $GLOBALS['BACK_PATH']), $out, 1, 1, 0, true);
     }
     return $theOutput;
 }