Example #1
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();
 }