Exemple #1
0
 function saveMailing(&$mailingId, $listId)
 {
     $list = lists::getOneList($listId);
     $allow_html = compa::allow_html();
     $erro = new xerr(__FILE__, __FUNCTION__, __CLASS__);
     $xf = new xonfig();
     if (ACA_CMSTYPE) {
         $database =& JFactory::getDBO();
         $listType = JRequest::getVar('listype', 0);
         $senddate = JRequest::getVar('senddate', '0000-00-00 00:00:00');
         if (JRequest::getVar('task', '') == 'saveSend') {
             $senddate = acajoom::getNow();
         }
         $subject = JRequest::getVar('subject', '', 'request', 'string', $allow_html);
         $content = JRequest::getVar('content', '', 'request', 'string', $allow_html);
         $alt_content = JRequest::getVar('alt_content', '', _MOS_ALLOWRAW);
         $published = JRequest::getVar('published', 0);
         $visible = JRequest::getVar('visible', 1);
         $html = JRequest::getVar('html', 1);
         $new_list = JRequest::getVar('new_list', 0);
         $fromname = JRequest::getVar('fromname', '');
         $fromemail = JRequest::getVar('fromemail', '');
         $frombounce = JRequest::getVar('frombounce', '');
         $userid = JRequest::getVar('userid', 0);
         $delay = JRequest::getVar('delay', 1);
         $acc_level = JRequest::getVar('acc_level', $list->acc_id);
         $issue_nb = JRequest::getVar('issue_nb', 1);
         $attachments = JRequest::getVar('attachments', '');
     } else {
         global $database;
         $listType = mosGetParam($_REQUEST, 'listype', 0);
         $senddate = mosGetParam($_REQUEST, 'senddate', '0000-00-00 00:00:00');
         if (mosGetParam($_REQUEST, 'task', '') == 'saveSend') {
             $senddate = acajoom::getNow();
         }
         $subject = mosGetParam($_REQUEST, 'subject', '', $allow_html);
         $content = mosGetParam($_REQUEST, 'content', '', $allow_html);
         $alt_content = mosGetParam($_REQUEST, 'alt_content', '', _MOS_ALLOWRAW);
         $published = mosGetParam($_REQUEST, 'published', 0);
         $visible = mosGetParam($_REQUEST, 'visible', 1);
         $html = mosGetParam($_REQUEST, 'html', 1);
         $new_list = mosGetParam($_REQUEST, 'new_list', 0);
         $fromname = mosGetParam($_REQUEST, 'fromname', '');
         $fromemail = mosGetParam($_REQUEST, 'fromemail', '');
         $frombounce = mosGetParam($_REQUEST, 'frombounce', '');
         $userid = mosGetParam($_REQUEST, 'userid', 0);
         $delay = mosGetParam($_REQUEST, 'delay', 1);
         $acc_level = mosGetParam($_REQUEST, 'acc_level', $list->acc_id);
         $issue_nb = mosGetParam($_REQUEST, 'issue_nb', 1);
         $attachments = mosGetParam($_REQUEST, 'attachments', '');
     }
     //endif
     $delay = $delay * 24 * 60;
     $attach = '';
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $attach .= $attachment . "\n";
         }
     }
     if (!empty($_FILES['file_0']['name'])) {
         $otherAttachs = xmailing::uploadFiles();
         if (!empty($otherAttachs)) {
             foreach ($otherAttachs as $otherAttach) {
                 $attach .= '/' . $otherAttach . "\n";
             }
         }
     }
     if (ACA_CMSTYPE) {
         // joomla 15
         $images = JRequest::getVar('images', '');
     } else {
         //joomla 1x
         $images = mosGetParam($_REQUEST, 'images', '');
     }
     //endif
     if ($html == 0) {
         $alt_content = $content;
     }
     if ($senddate != '0000-00-00 00:00:00' and $senddate > acajoom::getNow()) {
         $published = 2;
     }
     if (!empty($list->footer)) {
         if (substr_count($content, '[SUBSCRIPTIONS]') < 1) {
             $content .= "<br/> [SUBSCRIPTIONS] <br/>";
         }
         if (strlen($alt_content) > 10 and substr_count($alt_content, '[SUBSCRIPTIONS]') < 1) {
             $alt_content .= "\r\n [SUBSCRIPTIONS] \r\n";
         }
     }
     if ($new_list != 0) {
         $query = 'INSERT INTO `#__acajoom_mailings` (`list_id`, `list_type`, `send_date`, `subject`, `htmlcontent`, `textonly`, `attachments`, `images`, `published`, `html`, `visible`, `fromname`, `fromemail`, `frombounce`, `author_id`, `delay`, `issue_nb` , `acc_level` , `createdate`) VALUES( \'' . $listId . '\', \'' . $listType . '\', \'' . $senddate . '\', \'' . addslashes($subject) . '\', \'' . addslashes($content) . '\', \'' . addslashes($alt_content) . '\', \'' . $attach . '\', \'' . $images . '\', \'' . $published . '\', \'' . $html . '\', \'' . $visible . '\', \'' . $fromname . '\', \'' . $fromemail . '\', \'' . $frombounce . '\', \'' . $userid . '\', \'' . $delay . '\', \'' . $issue_nb . '\', \'' . $acc_level . '\' , \'' . acajoom::getNow() . '\' ) ';
         $database->setQuery($query);
         $database->query();
         $erro->err = $database->getErrorMsg();
         $query = 'SELECT max(id) FROM `#__acajoom_mailings` WHERE `list_id` = ' . $listId . ' AND `issue_nb` = \'' . $issue_nb . '\'';
         $query .= ' AND `published` != -1 ';
         $database->setQuery($query);
         $mailingId = $database->loadResult();
         $erro->err .= $database->getErrorMsg();
         if ($mailingId == 1) {
             $xf->update('firstmailing', $listType);
         }
         $xf->plus('totalmailing0', 1);
         $xf->plus('act_totalmailing0', 1);
         $xf->plus('totalmailing' . $listType, 1);
         $xf->plus('act_totalmailing' . $listType, 1);
         xmailing::insertStatsGlobal($mailingId);
     } else {
         $query = "UPDATE `#__acajoom_mailings` SET " . "\t`subject` = '" . addslashes($subject) . "', " . "\t`htmlcontent` = '" . addslashes($content) . "', " . "\t`textonly` = '" . addslashes($alt_content) . "', " . "\t`attachments` = '{$attach}', " . "\t`images` = '{$images}', " . "\t`published` = '{$published}', " . "\t`html` = {$html} , " . "\t`visible` = {$visible} , " . "\t`fromname` = '{$fromname}', " . "\t`fromemail` = '{$fromemail}', " . "\t`frombounce` = '{$frombounce}', " . "\t`author_id` =  '{$userid}' , " . "\t`delay` = {$delay} , " . "\t`acc_level` = {$acc_level} , " . "\t`send_date` = '{$senddate}' " . "\tWHERE `id` = {$mailingId} ";
         $database->setQuery($query);
         $database->query();
         $erro->err = $database->getErrorMsg();
     }
     if (!$erro->E(__LINE__, '8414', $database)) {
         return false;
     } else {
         lisType::updateNewsletters();
         if ($listType == 2) {
             if ($new_list) {
                 $subscribers = subscribers::getSubscribers(-1, -1, '', $total, $listId, '', 1, 1, '');
             } else {
                 $subscribers = subscribers::getSubscribers(-1, -1, '', $total, $listId, $mailingId, 1, 1, '');
             }
             $subsId = acajoom::convertObjectToIdList($subscribers, 'id');
             if (!empty($subsId)) {
                 $queues = queue::getAllOneList($listId);
                 if (!empty($queues)) {
                     if ($queues[0]->mailing_id == 0) {
                         $qids = acajoom::convertObjectToIdList($queues, 'qid');
                         $erro->ck = queue::updateQueues('', $qids, $listId, $acc_level, false);
                     } else {
                         $erro->ck = queue::updateQueues($subsId, '', $listId, $acc_level, false);
                     }
                 } else {
                     return true;
                 }
                 if (!$erro->Eck(__LINE__, '8415')) {
                     return false;
                 }
             }
         } elseif ($listType == 1 and $senddate > acajoom::getNow()) {
             if (class_exists('auto')) {
                 $erro->ck = queue::insert_subs_to_mailing($listId, $mailingId, $senddate, $acc_level);
                 if ($new_list != 1) {
                     $erro->ck = queue::update_subs_to_mailing($listId, $mailingId, $senddate, $issue_nb, $acc_level);
                 }
             }
         }
         return true;
     }
 }