Esempio n. 1
0
 public function weeklycampDirectSend($arr)
 {
     $arc = count($arr);
     $sendmessage = new Application_Model_Message();
     if ($arc != 0) {
         $sendtime = date('Y-m-d H:i:s');
         $cn = 0;
         foreach ($arr as $cind => $cobj) {
             $cn++;
             if ($cobj instanceof stdClass) {
                 // read the object
                 if (!$sendmessage->directcheckScheduled($cobj->campaignid)) {
                     //                        echo $cobj->campaignid;
                     $folders = explode(',', $cobj->folder);
                     $totalfolders = count($folders);
                     $totalsubscribers = array();
                     ini_set('memory_limit', '512M');
                     for ($sbr = 0; $sbr < $totalfolders; $sbr++) {
                         $subscribers = $this->subscribersByFolderid($folders[$sbr]);
                         foreach ($subscribers as $usr_fid => $v) {
                             $totalsubscribers[$v['phonenumber']] = $v['phonenumber'];
                         }
                     }
                     $msg = $cobj->msghead ? "{$cobj->msghead}:" : '';
                     $msg .= "{$cobj->message}\n{$cobj->msgfoot}";
                     $msg = trim($msg);
                     //                    $sendmessage = new Application_Model_Message();
                     if (!empty($totalsubscribers)) {
                         $i_default = 0;
                         // Construct the message
                         $sendmessage->selectedfolders = $cobj->folder;
                         // Set the folderid this message is being sent to
                         $sendmessage->folderid = 1;
                         // Set the user description
                         $sendmessage->description = $cobj->name;
                         // Set a unique identifier for all messages that go out on this campaign
                         $sendmessage->campaignid = $cobj->campaignid;
                         //                     echo $sendtime = date('Y-m-d').' '.$cobj->sendtime;
                         $sendtime = date($cobj->sendtime);
                         //                        $timezone = $cobj->timezone;
                         //                        $userid = $cobj->createuser;
                         $shortcode = $cobj->shortcode;
                         $source = 404;
                         $totalmsg = count($totalsubscribers);
                         $sendmessage->weeklycampaignUpdate($cobj->id, $cobj->createuser, "second", $totalmsg);
                         $regidforcampaign = $this->save_api_outbound($cobj->campaignid, $cobj->createuser);
                         //                        $this->save_api_recipients($regidforcampaign,$totalsubscribers,$source,$cobj->createuser);
                         //                            echo $cobj->createuser; exit;
                         $this->save_api_recipients_collection($msg, $totalsubscribers, $source, $shortcode, $cobj->createuser);
                         //                        $send = $this->direct_send($shortcode,$totalsubscribers,$msg,$regidforcampaign);
                     } else {
                         $this->_writeLog("There are no subscribers in the chosen folder(s)");
                     }
                 }
                 unset($totalsubscribers);
                 //                    unset($cobj);
                 echo date('Y-m-d H:i:s') . ' C# ' . $cn . ' sbcr: ' . $totalmsg . '<br>Failed: ' . $send . '<br>';
                 if ($send == "success") {
                     sleep(20);
                 }
             }
             // end of object
         }
         echo date('Y-m-d H:i:s') . '<br>';
     }
 }