Exemplo n.º 1
0
 /**
  * Show_Send_Step_30
  * This shows a summary report of the split test campaign
  * after a user has paused the campaign
  * and they want to resume sending it
  *
  * It shows:
  * - which lists/segments it will be sent to
  * - the split test name
  * - which campaigns it will send
  *
  * and a "resume" button.
  *
  * If cron is enabled, then it will mark the job as "waiting" to send again in the database,
  * set a flash message and redirect the user back to the "manage split tests" page.
  *
  * @uses GetApi
  * @uses Splittest_API::Load
  * @uses Jobs_API::LoadJob
  * @uses CheckCronEnabled
  * @uses Splittest_Send_API::ResumeJob
  */
 public function Show_Send_Step_30()
 {
     $splitid = 0;
     if (isset($_GET['id'])) {
         $splitid = (int) $_GET['id'];
     }
     $api = $this->GetApi();
     $split_campaign_details = $api->Load($splitid);
     if (empty($split_campaign_details)) {
         FlashMessage(GetLang('Addon_splittest_Send_InvalidSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url);
         return;
     }
     $jobid = 0;
     if (isset($split_campaign_details['jobid'])) {
         $jobid = (int) $split_campaign_details['jobid'];
     }
     require_once SENDSTUDIO_API_DIRECTORY . '/jobs.php';
     $jobApi = new Jobs_API();
     $job = $jobApi->LoadJob($jobid);
     if (empty($job)) {
         FlashMessage(GetLang('Addon_splittest_Send_InvalidSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url);
         return;
     }
     /**
      * If we're sending via cron,
      * then mark the job as "waiting" to send again
      * and then show an appropriate message.
      */
     if (self::CheckCronEnabled()) {
         $send_api = $this->GetApi('SplitTest_Send');
         $resumed = $send_api->ResumeJob($jobid, $splitid);
         if ($resumed) {
             FlashMessage(GetLang('Addon_splittest_Send_Resumed_Success'), SS_FLASH_MSG_SUCCESS, $this->admin_url);
         } else {
             FlashMessage(GetLang('Addon_splittest_Send_Resumed_Failure'), SS_FLASH_MSG_ERROR, $this->admin_url);
         }
         return;
     }
     $sendingCampaigns = array();
     $send_details['newsletters'] = array();
     foreach ($split_campaign_details['splittest_campaigns'] as $campaignid => $campaignname) {
         $sendingCampaigns[$campaignid] = htmlspecialchars($campaignname, ENT_QUOTES, SENDSTUDIO_CHARSET);
         $send_details['newsletters'][] = $campaignid;
     }
     $send_list = array();
     switch ($job['jobdetails']['sendingto']['sendtype']) {
         case 'list':
             require_once SENDSTUDIO_API_DIRECTORY . '/lists.php';
             $list_api = new Lists_API();
             foreach ($job['jobdetails']['sendingto']['sendids'] as $listid) {
                 $list_api->Load($listid);
                 $send_list[] = htmlspecialchars($list_api->Get('name'), ENT_QUOTES, SENDSTUDIO_CHARSET);
             }
             $this->template_system->Assign('SendingToLists', true);
             break;
         case 'segment':
             require_once SENDSTUDIO_API_DIRECTORY . '/segment.php';
             $segment_api = new Segment_API();
             foreach ($job['jobdetails']['sendingto']['sendids'] as $segmentid) {
                 $segment_api->Load($segmentid);
                 $send_list[] = htmlspecialchars($segment_api->Get('segmentname'), ENT_QUOTES, SENDSTUDIO_CHARSET);
             }
             $this->template_system->Assign('SendingToSegments', true);
             break;
     }
     /**
      * Set everything in the session ready to go.
      */
     $job['jobdetails']['Job'] = $job['jobid'];
     IEM::sessionSet('SplitTestSendDetails', $job['jobdetails']);
     /**
      * Work out how many more emails there are to send.
      */
     $send_size = $job['jobdetails']['sendinfo']['sendsize_left'];
     if ($send_size == 1) {
         $send_size_msg = GetLang('Addon_splittest_Send_Step3_Size_One');
     } else {
         $send_size_msg = sprintf(GetLang('Addon_splittest_Send_Step3_Size_Many'), $this->PrintNumber($send_size));
     }
     $this->template_system->Assign('SendingToNumberOfContacts', $send_size_msg);
     $this->template_system->Assign('sendingCampaigns', $sendingCampaigns);
     $this->template_system->Assign('sendLists', $send_list);
     $this->template_system->Assign('AdminUrl', $this->admin_url, false);
     $this->template_system->ParseTemplate('send_step3');
 }
Exemplo n.º 2
0
	/**
	* ResendJob_Setup
	* This sets up the scheduled send 'job' ready for a resend.
	* This includes fixing up user statistics, moving the unsent recipients from the unsent queue to the live queue and making the job ready to go.
	*
	* If an invalid jobid is passed in (not an in or it's less than 0) this will return false.
	* There needs to be a user object set up so statistics can be re-allocated properly. If this is not set up, the function returns false.
	*
	* @param Int $jobid The job we are re-setting up.
	*
	* @uses Jobs_API::GetJobQueue
	* @uses Jobs_API::GetJobQueueSize
	* @uses Jobs_API::RestoreUnsentQueue
	* @uses Stats_API::ChangeUserStats
	*
	* @return Boolean Returns false if there is an invalid jobid provided or if the user object is not set up properly. Otherwise, it does all of it's work and returns true.
	*/
	function ResendJob_Setup($jobid=0)
	{
		$jobid = (int)$jobid;
		if ($jobid <= 0) {
			return false;
		}

		if ($this->jobowner <= 0) {
			return false;
		}

		require_once(dirname(__FILE__) . '/jobs.php');
		require_once(dirname(__FILE__) . '/stats.php');

		$jobapi = new Jobs_API();
		$stats_api = new Stats_API();

		$sendqueue = $jobapi->GetJobQueue($jobid);

		// if we're resending a newsletter, restore the 'unsent' queue back to the original.
		$jobsize_info_before = $jobapi->GetJobQueueSize($jobid);

		$jobapi->RestoreUnsentQueue($jobid, $sendqueue, $this->jobowner, 'send');

		// then make sure we mark the emails as allocated in statistics.
		$restore_size = $jobapi->QueueSize($sendqueue, 'send');
		$new_size = $jobsize_info_before['totalsent'] + $restore_size;

		$stats_api->ChangeUserStats($this->jobowner, $jobid, $new_size);

		unset($jobapi);
		unset($stats_api);

		return true;
	}
	/**
	* Constructor
	* Calls the parent object to set up the database.
	* Sets up references to the email api, list api and subscriber api.
	*
	* @see Email_API
	* @see Lists_API
	* @see Subscriber_API
	* @see newsletter_api
	*
	* @see Jobs_API::Jobs_API
	*/
	function Jobs_Autoresponders_API()
	{
		$this->LogFile = TEMP_DIRECTORY . '/autoresponder_debug.'.getmypid().'.log';

		if ($this->Debug) {
			error_log(time() . "\t" . __FILE__ . "\t" . __LINE__ . "\t" . "---------------------\n", 3, $this->LogFile);
		}

		$this->currenttime = $this->GetServerTime();

		Jobs_API::Jobs_API(false);
		SendStudio_Functions::LoadLanguageFile('jobs_autoresponders');

		if ($this->Debug) {
			$this->Db->QueryLog = TEMP_DIRECTORY . '/autoresponder_queries.'.getmypid().'.log';
			$this->Db->LogQuery('-----------');

			$this->Db->TimeLog = TEMP_DIRECTORY . '/autoresponder_queries_timed.'.getmypid().'.log';
			$this->Db->TimeQuery('-----------', 0, 0);
		}

		if (is_null($this->Email_API)) {
			if (!class_exists('ss_email_api', false)) {
				require_once(dirname(__FILE__) . '/ss_email.php');
			}
			$email = new SS_Email_API();
			$this->Email_API = &$email;
		}

		if ($this->Debug) {
			$this->Email_API->Debug = true;
		}

		if (is_null($this->Subscriber_API)) {
			if (!class_exists('subscribers_api', false)) {
				require_once(dirname(__FILE__) . '/subscribers.php');
			}
			$subscribers = new Subscribers_API();
			$this->Subscriber_API = &$subscribers;
		}

		if (is_null($this->Lists_API)) {
			if (!class_exists('lists_api', false)) {
				require_once(dirname(__FILE__) . '/lists.php');
			}
			$lists = new Lists_API();
			$this->Lists_API = &$lists;
		}

		if (is_null($this->autoresponder_api)) {
			require_once(dirname(__FILE__) . '/autoresponders.php');
			$newsl = new Autoresponders_API();
			$this->autoresponder_api = &$newsl;
		}

		if (is_null($this->Stats_API)) {
			if (!class_exists('stats_api', false)) {
				require_once(dirname(__FILE__) . '/stats.php');
			}
			$statsapi = new Stats_API();
			$this->Stats_API = &$statsapi;
		}

		$this->_queues_done = array();
	}
Exemplo n.º 4
0
 /**
  * DeleteSchedules
  * If scheduled items are going to be deleted, this processes the jobs it needs to.
  *
  * The data passed in contains lots of data:
  * jobids - the job id's that need to be processed
  * message - the current success/failure message
  * success - the current success counter (how many jobs have successfully been deleted previous to getting here)
  * failure - the current failure counter (how many jobs have not successfully been deleted previous to getting here)
  *
  * Any non-"splittest" job types are skipped
  * Any "in progress" splittest jobs are skipped and the failure counter is incremented
  * Any jobs that can be deleted are - as well as figuring out whether a job needs to give back any email credits.
  *
  * Any appropriate messages are added to the "message" item in the passed in array.
  *
  * @param EventData_IEM_SCHEDULE_DELETEJOBS $data The data array containing the jobs to process, the current message, success and failure counts.
  *
  * @uses Jobs_API::LoadJob()
  * @uses Stats_API::DeleteUserStats()
  * @uses Stats_API::MarkNewsletterFinished()
  * @uses Splittest_Send_API::DeleteJob()
  * @uses User_API::ReduceEmails()
  * @uses EventData_IEM_SCHEDULE_DELETEJOBS
  */
 public static function DeleteSchedules(EventData_IEM_SCHEDULE_DELETEJOBS $data)
 {
     $jobids =& $data->jobids;
     $message =& $data->Message;
     $success =& $data->success;
     $failure =& $data->failure;
     $user = GetUser();
     require_once SENDSTUDIO_API_DIRECTORY . '/jobs.php';
     require_once SENDSTUDIO_API_DIRECTORY . '/stats.php';
     require_once dirname(__FILE__) . '/api/splittest_send.php';
     $jobapi = new Jobs_API();
     $stats_api = new Stats_API();
     $send_api = new Splittest_Send_API();
     foreach ($jobids as $p => $jobid) {
         $jobinfo = $jobapi->LoadJob($jobid);
         if (empty($jobinfo)) {
             continue;
         }
         if ($jobinfo['jobtype'] !== 'splittest') {
             continue;
         }
         if ($jobinfo['jobstatus'] == 'i') {
             $failure++;
             unset($jobids[$p]);
             continue;
         }
         $statids = array();
         if (isset($jobinfo['jobdetails']['Stats'])) {
             $statids = array_values($jobinfo['jobdetails']['Stats']);
         }
         /**
          * If there are no stats, then the send hasn't started yet.
          * So just credit the user back with the number of emails they were trying to send.
          * Use 'ReduceEmails' to re-add the credits by using a double negative :)
          */
         if (empty($statids) && $jobinfo['jobstatus'] == 'w') {
             $stats_api->DeleteUserStats($jobinfo['ownerid'], $jobid);
             $user->ReduceEmails(-(int) $jobinfo['jobdetails']['SendSize']);
         }
         /**
          * If a send is started (ie it has stats),
          * but is not completed,
          * We need to mark it as complete.
          *
          * This also credits a user back if they have any limits in place.
          *
          * This needs to happen before we delete the 'job' from the database
          * as deleting the job cleans up the queues/unsent items.
          */
         if (!empty($statids) && $jobinfo['jobstatus'] != 'c') {
             $stats_api->MarkNewsletterFinished($statids, $jobinfo['jobdetails']['SendSize']);
             // Credits needs to be returned too whenever the job is canceled AFTER it has been scheduled, but before it was sent
         } elseif ($jobinfo['jobstatus'] != 'c') {
             $stats_api->RefundFixedCredit($jobid);
         }
         $result = $send_api->DeleteJob($jobid);
         if ($result) {
             $success++;
         } else {
             $failure++;
         }
         unset($jobids[$p]);
     }
     /**
      * Only failure messages get added to the message stack.
      * Successful deletes are handled in the calling code
      * in case:
      * - a non-addon deletes an item
      * - other addons delete their own items
      */
     if ($failure > 0) {
         if ($failure == 1) {
             FlashMessage(GetLang('Addon_splittest_Schedule_JobDeleteFail'), SS_FLASH_MSG_ERROR);
         } else {
             FlashMessage(sprintf(GetLang('Addon_splittest_Schedule_JobsDeleteFail'), self::PrintNumber($failure)), SS_FLASH_MSG_SUCCESS);
         }
     }
     $message .= GetFlashMessages();
 }