/** * 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'); }
/** * 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(); }