Example #1
0
 function saveMailing(&$mailingId, $listId)
 {
     global $database;
     $list = lists::getOneList($listId);
     $allow_html = compa::allow_html();
     $erro = new xerr(__FILE__, __FUNCTION__, __CLASS__);
     $xf = new xonfig();
     $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);
     $delay = $delay * 24 * 60;
     $attachments = mosGetParam($_REQUEST, 'attachments', '');
     $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";
             }
         }
     }
     $images = mosGetParam($_REQUEST, 'images', '');
     if ($html == 0) {
         $alt_content = $content;
     }
     if ($senddate != '0000-00-00 00:00:00' and $senddate > acajoom::getNow()) {
         $published = 2;
     }
     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()) {
             $subscribers = subscribers::getSubscribers(-1, -1, '', $total, $listId, '', 1, 1, '');
             $subsId = acajoom::convertObjectToIdList($subscribers, 'id');
             if (!empty($subsId)) {
                 if ($new_list == 1) {
                     if (class_exists('auto')) {
                         $erro->ck = auto::insertQueuesForScheduledNews($subsId, $listId, $acc_level, $mailingId, $senddate);
                     }
                 } else {
                     $queues = queue::getQueueFromMailingId($mailingId);
                     if (!empty($queues)) {
                         $erro->ck = queue::updateQueueData('', $subsId, 1, $listId, $mailingId, $issue_nb, $senddate, 0, $acc_level, 2);
                         return $erro->Eck(__LINE__, '8417', 'put here 1 $d');
                     } else {
                         if (class_exists('auto')) {
                             $erro->ck = auto::insertQueuesForScheduledNews($subsId, $listId, $acc_level, $mailingId, $senddate);
                         }
                     }
                 }
                 return $erro->Eck(__LINE__, '8416', 'put here 2 $d');
             }
         }
         return true;
     }
 }
Example #2
0
 function updateSuscription($suscription)
 {
     $erro = new xerr(__FILE__, __FUNCTION__, __CLASS__);
     //$i = 0;
     //do  {
     //$i++;
     foreach ($suscription->sub_list_id as $i => $value) {
         $queues = queue::suscriptionExist($suscription->user_id, $suscription->sub_list_id[$i]);
         if (!empty($queues)) {
             if (isset($suscription->subscribed[$i])) {
                 if ($suscription->subscribed[$i] == 0) {
                     $erro->ck = queue::deleteSubsQueue($suscription->user_id, $suscription->sub_list_id[$i]);
                     $erro->Eck(__LINE__, '8520');
                 } else {
                     $updatedQueue = $queues;
                     $updatedQueue->acc_level = $suscription->acc_level[$i];
                     if ($queues->mailing_id < 1) {
                         $mailingId = xmailing::getFirstMailingId($queues->list_id);
                         if (!empty($mailingId)) {
                             $list = lists::getOneList($queues->list_id);
                             $mailing = queue::getValidMailing($list, $mailingId);
                             if (!empty($mailing)) {
                                 $updatedQueue->type = $mailing->list_type;
                                 $updatedQueue->list_id = $list->id;
                                 $updatedQueue->mailing_id = $mailing->id;
                                 $updatedQueue->published = $list->published;
                                 $updatedQueue->send_date = acajoom::getNow();
                                 if ($mailing->list_type == 1 or $mailing->list_type == 7) {
                                     $updatedQueue->issue_nb = 0;
                                     $updatedQueue->send_date = '0000-00-00 00:00:00';
                                     $updatedQueue->delay = 0;
                                 } else {
                                     $updatedQueue->issue_nb = $mailing->issue_nb;
                                     $updatedQueue->send_date = acajoom::getNow();
                                     $updatedQueue->delay = $mailing->delay;
                                 }
                             }
                         }
                         $qid = '';
                         $qid[0] = $updatedQueue->qid;
                         $erro->ck = queue::updateQueueData($qid, '', $updatedQueue->type, $updatedQueue->list_id, $updatedQueue->mailing_id, $updatedQueue->issue_nb, $updatedQueue->send_date, $updatedQueue->delay, $updatedQueue->acc_level, $updatedQueue->published);
                         $erro->Eck(__LINE__, '8521');
                     } else {
                         queue::updateAccessLevel($updatedQueue);
                     }
                 }
             }
         } else {
             if (isset($suscription->subscribed[$i])) {
                 if ($suscription->subscribed[$i] == 1) {
                     $subId = array();
                     $subId[0] = $suscription->user_id;
                     $subList = isset($suscription->sub_list_id[$i]) ? $suscription->sub_list_id[$i] : 0;
                     $subLevel = isset($suscription->acc_level[$i]) ? $suscription->acc_level[$i] : 29;
                     $erro->ck = queue::updateQueues($subId, '', $subList, $subLevel, true);
                     $erro->Eck(__LINE__, '8522');
                 }
             }
         }
     }
     //while (count($suscription->sub_list_id ) > $i );
     return $erro->R();
 }