示例#1
0
 /**
  * Function mailModule main()
  *
  * @return	string	HTML (steps)
  */
 public function moduleContent()
 {
     $theOutput = "";
     $isExternalDirectMailRecord = false;
     $markers = array('WIZARDSTEPS' => '', 'FLASHMESSAGES' => '', 'NAVIGATION' => '', 'TITLE' => '');
     if ($this->CMD == 'delete') {
         $this->deleteDMail(intval(GeneralUtility::_GP('uid')));
     }
     $row = array();
     if (intval($this->sys_dmail_uid)) {
         $row = BackendUtility::getRecord('sys_dmail', intval($this->sys_dmail_uid));
         $isExternalDirectMailRecord = is_array($row) && $row['type'] == 1;
     }
     $hideCategoryStep = false;
     if ($GLOBALS['BE_USER']->userTS['tx_directmail.']['hideSteps'] && $GLOBALS['BE_USER']->userTS['tx_directmail.']['hideSteps'] == 'cat' || $isExternalDirectMailRecord) {
         $hideCategoryStep = true;
     }
     if (GeneralUtility::_GP('update_cats')) {
         $this->CMD = 'cats';
     }
     if (GeneralUtility::_GP('mailingMode_simple')) {
         $this->CMD = 'send_mail_test';
     }
     $backButtonPressed = GeneralUtility::_GP('back');
     if ($backButtonPressed) {
         // CMD move 1 step back
         switch (GeneralUtility::_GP('currentCMD')) {
             case 'info':
                 $this->CMD = '';
                 break;
             case 'cats':
                 $this->CMD = 'info';
                 break;
             case 'send_test':
                 // Sameas send_mail_test
             // Sameas send_mail_test
             case 'send_mail_test':
                 if ($this->CMD == 'send_mass' && $hideCategoryStep) {
                     $this->CMD = 'info';
                 } else {
                     $this->CMD = 'cats';
                 }
                 break;
             case 'send_mail_final':
                 // The same as send_mass
             // The same as send_mass
             case 'send_mass':
                 $this->CMD = 'send_test';
                 break;
             default:
                 // Do nothing
         }
     }
     $nextCmd = "";
     if ($hideCategoryStep) {
         $totalSteps = 4;
         if ($this->CMD == 'info') {
             $nextCmd = 'send_test';
         }
     } else {
         $totalSteps = 5;
         if ($this->CMD == 'info') {
             $nextCmd = 'cats';
         }
     }
     $navigationButtons = "";
     switch ($this->CMD) {
         case 'info':
             $fetchMessage = "";
             // step 2: create the Direct Mail record, or use existing
             $this->currentStep = 2;
             $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz2_detail');
             // greyed out next-button if fetching is not successful (on error)
             $fetchError = true;
             // Create DirectMail and fetch the data
             $shouldFetchData = GeneralUtility::_GP('fetchAtOnce');
             $quickmail = GeneralUtility::_GP('quickmail');
             $createMailFromInternalPage = intval(GeneralUtility::_GP('createMailFrom_UID'));
             $createMailFromExternalUrl = GeneralUtility::_GP('createMailFrom_URL');
             // internal page
             if ($createMailFromInternalPage && !$quickmail['send']) {
                 $createMailFromInternalPageLang = (int) GeneralUtility::_GP('createMailFrom_LANG');
                 $newUid = DirectMailUtility::createDirectMailRecordFromPage($createMailFromInternalPage, $this->params, $createMailFromInternalPageLang);
                 if (is_numeric($newUid)) {
                     $this->sys_dmail_uid = $newUid;
                     // Read new record (necessary because TCEmain sets default field values)
                     $row = BackendUtility::getRecord('sys_dmail', $newUid);
                     // fetch the data
                     if ($shouldFetchData) {
                         $fetchMessage = DirectMailUtility::fetchUrlContentsForDirectMailRecord($row, $this->params);
                         $fetchError = strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false ? false : true;
                     }
                     $theOutput .= '<input type="hidden" name="CMD" value="' . ($nextCmd ? $nextCmd : 'cats') . '">';
                 } else {
                     // TODO: Error message - Error while adding the DB set
                 }
                 // external URL
             } elseif ($createMailFromExternalUrl && !$quickmail['send']) {
                 // $createMailFromExternalUrl is the External URL subject
                 $htmlUrl = GeneralUtility::_GP('createMailFrom_HTMLUrl');
                 $plainTextUrl = GeneralUtility::_GP('createMailFrom_plainUrl');
                 $newUid = DirectMailUtility::createDirectMailRecordFromExternalURL($createMailFromExternalUrl, $htmlUrl, $plainTextUrl, $this->params);
                 if (is_numeric($newUid)) {
                     $this->sys_dmail_uid = $newUid;
                     // Read new record (necessary because TCEmain sets default field values)
                     $row = BackendUtility::getRecord('sys_dmail', $newUid);
                     // fetch the data
                     if ($shouldFetchData) {
                         $fetchMessage = DirectMailUtility::fetchUrlContentsForDirectMailRecord($row, $this->params);
                         $fetchError = strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false ? false : true;
                     }
                     $theOutput .= '<input type="hidden" name="CMD" value="send_test">';
                 } else {
                     // TODO: Error message - Error while adding the DB set
                     $this->error = 'no_valid_url';
                 }
                 // Quickmail
             } elseif ($quickmail['send']) {
                 $fetchMessage = $this->createDMail_quick($quickmail);
                 $fetchError = strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false ? false : true;
                 $row = BackendUtility::getRecord('sys_dmail', $this->sys_dmail_uid);
                 $theOutput .= '<input type="hidden" name="CMD" value="send_test">';
                 // existing dmail
             } elseif ($row) {
                 if ($row['type'] == '1' && (empty($row['HTMLParams']) || empty($row['plainParams']))) {
                     // it's a quickmail
                     $fetchError = false;
                     $theOutput .= '<input type="hidden" name="CMD" value="send_test">';
                     // add attachment here, since attachment added in 2nd step
                     $unserializedMailContent = unserialize(base64_decode($row['mailContent']));
                     $theOutput .= $this->compileQuickMail($row, $unserializedMailContent['plain']['content'], false);
                 } else {
                     if ($shouldFetchData) {
                         $fetchMessage = DirectMailUtility::fetchUrlContentsForDirectMailRecord($row, $this->params);
                         $fetchError = strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false ? false : true;
                     }
                     if ($row['type'] == 0) {
                         $theOutput .= '<input type="hidden" name="CMD" value="' . $nextCmd . '">';
                     } else {
                         $theOutput .= '<input type="hidden" name="CMD" value="send_test">';
                     }
                 }
             }
             $navigationButtons = '<input type="submit" class="btn btn-default" value="' . $this->getLanguageService()->getLL('dmail_wiz_back') . '" name="back"> &nbsp;';
             $navigationButtons .= '<input type="submit" value="' . $this->getLanguageService()->getLL('dmail_wiz_next') . '" ' . ($fetchError ? 'disabled="disabled" class="next btn btn-default disabled"' : ' class="btn btn-default"') . '>';
             if ($fetchMessage) {
                 $markers['FLASHMESSAGES'] = $fetchMessage;
             } elseif (!$fetchError && $shouldFetchData) {
                 /* @var $flashMessage FlashMessage */
                 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $this->getLanguageService()->getLL('dmail_wiz2_fetch_success'), FlashMessage::OK);
                 $markers['FLASHMESSAGES'] = $flashMessage->render();
             }
             if (is_array($row)) {
                 $theOutput .= '<div id="box-1" class="toggleBox">';
                 $theOutput .= $this->renderRecordDetailsTable($row);
                 $theOutput .= '</div>';
             }
             $theOutput .= '<input type="hidden" name="sys_dmail_uid" value="' . $this->sys_dmail_uid . '">';
             $theOutput .= !empty($row['page']) ? '<input type="hidden" name="pages_uid" value="' . $row['page'] . '">' : '';
             $theOutput .= '<input type="hidden" name="currentCMD" value="' . $this->CMD . '">';
             break;
         case 'cats':
             // shows category if content-based cat
             $this->currentStep = 3;
             $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz3_cats');
             $navigationButtons = '<input type="submit" class="btn btn-default " value="' . $this->getLanguageService()->getLL('dmail_wiz_back') . '" name="back">&nbsp;';
             $navigationButtons .= '<input type="submit" class="btn btn-default " value="' . $this->getLanguageService()->getLL('dmail_wiz_next') . '">';
             $theOutput .= '<div id="box-1" class="toggleBox">';
             $theOutput .= $this->makeCategoriesForm($row);
             $theOutput .= '</div></div>';
             $theOutput .= '<input type="hidden" name="CMD" value="send_test">';
             $theOutput .= '<input type="hidden" name="sys_dmail_uid" value="' . $this->sys_dmail_uid . '">';
             $theOutput .= '<input type="hidden" name="pages_uid" value="' . $this->pages_uid . '">';
             $theOutput .= '<input type="hidden" name="currentCMD" value="' . $this->CMD . '">';
             break;
         case 'send_test':
             // Same as send_mail_test
         // Same as send_mail_test
         case 'send_mail_test':
             // send test mail
             $this->currentStep = 4 - (5 - $totalSteps);
             $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz4_testmail');
             $navigationButtons = '<input type="submit" class="btn btn-default" value="' . $this->getLanguageService()->getLL('dmail_wiz_back') . '" name="back">&nbsp;';
             $navigationButtons .= '<input type="submit" class="btn btn-default" value="' . $this->getLanguageService()->getLL('dmail_wiz_next') . '">';
             if ($this->CMD == 'send_mail_test') {
                 // using Flashmessages to show sent test mail
                 $markers['FLASHMESSAGES'] = $this->cmd_send_mail($row);
             }
             $theOutput .= '<br /><div id="box-1" class="toggleBox">';
             $theOutput .= $this->cmd_testmail();
             $theOutput .= '</div></div>';
             $theOutput .= '<input type="hidden" name="CMD" value="send_mass">';
             $theOutput .= '<input type="hidden" name="sys_dmail_uid" value="' . $this->sys_dmail_uid . '">';
             $theOutput .= '<input type="hidden" name="pages_uid" value="' . $this->pages_uid . '">';
             $theOutput .= '<input type="hidden" name="currentCMD" value="' . $this->CMD . '">';
             break;
         case 'send_mail_final':
             // same as send_mass
         // same as send_mass
         case 'send_mass':
             $this->currentStep = 5 - (5 - $totalSteps);
             if ($this->CMD == 'send_mass') {
                 $navigationButtons = '<input type="submit" class="btn btn-default" value="' . $this->getLanguageService()->getLL('dmail_wiz_back') . '" name="back">';
             }
             if ($this->CMD == 'send_mail_final') {
                 $selectedMailGroups = GeneralUtility::_GP('mailgroup_uid');
                 if (is_array($selectedMailGroups)) {
                     $markers['FLASHMESSAGES'] = $this->cmd_send_mail($row);
                     break;
                 } else {
                     $theOutput .= 'no recipients';
                 }
             }
             // send mass, show calendar
             $theOutput .= '<div id="box-1" class="toggleBox">';
             $theOutput .= $this->cmd_finalmail($row);
             $theOutput .= '</div>';
             $theOutput = $this->doc->section($this->getLanguageService()->getLL('dmail_wiz5_sendmass'), $theOutput, 1, 1, 0, true);
             $theOutput .= '<input type="hidden" name="CMD" value="send_mail_final">';
             $theOutput .= '<input type="hidden" name="sys_dmail_uid" value="' . $this->sys_dmail_uid . '">';
             $theOutput .= '<input type="hidden" name="pages_uid" value="' . $this->pages_uid . '">';
             $theOutput .= '<input type="hidden" name="currentCMD" value="' . $this->CMD . '">';
             break;
         default:
             // choose source newsletter
             $this->currentStep = 1;
             $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz1_new_newsletter') . ' - ' . $this->getLanguageService()->getLL('dmail_wiz1_select_nl_source');
             $showTabs = array('int', 'ext', 'quick', 'dmail');
             $hideTabs = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->userTS['tx_directmail.']['hideTabs']);
             foreach ($hideTabs as $hideTab) {
                 $showTabs = ArrayUtility::removeArrayEntryByValue($showTabs, $hideTab);
             }
             if (!$GLOBALS['BE_USER']->userTS['tx_directmail.']['defaultTab']) {
                 $GLOBALS['BE_USER']->userTS['tx_directmail.']['defaultTab'] = 'dmail';
             }
             $i = 1;
             $countTabs = count($showTabs);
             foreach ($showTabs as $showTab) {
                 $open = false;
                 if ($GLOBALS['BE_USER']->userTS['tx_directmail.']['defaultTab'] == $showTab) {
                     $open = true;
                 }
                 switch ($showTab) {
                     case 'int':
                         $theOutput .= $this->makeFormInternal('box-' . $i, $countTabs, $open);
                         break;
                     case 'ext':
                         $theOutput .= $this->makeFormExternal('box-' . $i, $countTabs, $open);
                         break;
                     case 'quick':
                         $theOutput .= $this->makeFormQuickMail('box-' . $i, $countTabs, $open);
                         break;
                     case 'dmail':
                         $theOutput .= $this->makeListDMail('box-' . $i, $countTabs, $open);
                         break;
                     default:
                 }
                 $i++;
             }
             $theOutput .= '<input type="hidden" name="CMD" value="info" />';
     }
     $markers['NAVIGATION'] = $navigationButtons;
     $markers['CONTENT'] = $theOutput;
     $markers['WIZARDSTEPS'] = $this->showSteps($totalSteps);
     return $markers;
 }