/** * Show_Send_Step_2 * This handles the second step of the send process where * * 1) the first step is verified in php * - checks you are choosing a list or segment * - checks the list/segment id's are valid (ie they are proper id's and not non-numeric values) * - checks the list or segment has contacts in it * * If that checks out ok, the second step shows the form where you set: * - from details * - bounce details * - whether to send the campaigns as multipart (where possible) * - whether to embed images or not (where possible) * - choose the first/last name custom fields * - when to send the split test (if cron is enabled) * * @uses FlashMessage * @uses GetFlashMessages * @uses List_API::Load * @uses List_API::GetCustomFields * @uses Segment_API::Load * @uses GetUser * @uses User_API::HasAccess * @uses CheckCronEnabled */ public function Show_Send_Step_2() { $send_details = IEM::sessionGet('SplitTestSend'); /** * Check the user has been through step 1 successfully. */ if (!$send_details || !isset($send_details['splitid']) || (int) $send_details['splitid'] <= 0) { FlashMessage(GetLang('Addon_splittest_Send_InvalidSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url); return; } $step1_url = $this->admin_url . '&Action=Send&id=' . $send_details['splitid']; $flash_messages = GetFlashMessages(); /** * If we are not posting a form, maybe we're being redirected back to this step from step 3. * If we are, we'll have flash messages. * * If there are no post variables and we are not showing any messages, then go back to step 1. */ if (empty($_POST) && empty($flash_messages)) { FlashMessage(GetLang('Addon_splittest_Send_ChooseListOrSegment'), SS_FLASH_MSG_ERROR, $step1_url); return; } /** * If we are posting a form, check we are posting a proper form (we should have lists or segments chosen) */ if (!empty($_POST)) { /** * Work out which option the user chose */ $sending_to = array(); $send_type = ''; switch ((int) $_POST['ShowFilteringOptions']) { case 1: $send_type = 'list'; if (isset($_POST['lists'])) { $sending_to = $_POST['lists']; } break; case 2: $send_type = 'segment'; if (isset($_POST['segments'])) { $sending_to = $_POST['segments']; } break; default: FlashMessage(GetLang('Addon_splittest_Send_ChooseListOrSegment'), SS_FLASH_MSG_ERROR, $step1_url); return; break; } /** * Make sure the user actually chose some options. */ if (empty($sending_to)) { FlashMessage(GetLang('Addon_splittest_Send_ChooseListOrSegment'), SS_FLASH_MSG_ERROR, $step1_url); return; } /** * Make sure the id's the user chose are valid * If any area invalid (not int's), the user is thrown back to the first step. */ foreach ($sending_to as $id) { $id = (int) $id; if ($id <= 0) { FlashMessage(GetLang('Addon_splittest_Send_ChooseListOrSegment'), SS_FLASH_MSG_ERROR, $step1_url); return; } } /** * After everything has been validated, store the settings and display the next form. */ $send_details['sendingto'] = array('sendtype' => $send_type, 'sendids' => $sending_to); IEM::sessionSet('SplitTestSend', $send_details); } $user = GetUser(); /** * Re-set these variables. * They may be coming from the session if we are being redirected back to step 2 from another step. */ $send_type = $send_details['sendingto']['sendtype']; $sending_to = $send_details['sendingto']['sendids']; /** * Get the first list or segment we're sending to. * We need this to set the defaults for the from name, email, reply-to email and bounce details. * It doesn't really matter what the id is, the user can override the options anyway through the form. */ $id = $sending_to[0]; $send_size = 0; /** * We always need the list api * so we can load the right details regardless of whether the user is sending to a segment or list. */ require_once SENDSTUDIO_API_DIRECTORY . '/lists.php'; $list_api = new Lists_API(); switch ($send_type) { case 'list': $list_id = $id; $listids = $sending_to; $user_lists = $user->GetLists(); foreach ($user_lists as $user_list_id => $user_list_details) { if (!in_array($user_list_id, $sending_to)) { continue; } $send_size += $user_list_details['subscribecount']; } // this is used at a later step to check duplicates etc. $send_details['sendingto']['Lists'] = $sending_to; break; case 'segment': require_once SENDSTUDIO_API_DIRECTORY . '/subscribers.php'; $api = new Subscribers_API(); $segment_info = $api->GetSubscribersFromSegment($sending_to, true); $send_size = $segment_info['count']; /** * Since a segment can go across lists, * we only need one list - so just get the first one we come across. * The user can change the details on the fly anyway. */ $listids = $segment_info['lists']; $list_id = $listids[0]; // this is used at a later step to check duplicates etc. $send_details['sendingto']['Lists'] = $listids; break; } if ($send_size <= 0) { $var = 'Addon_splittest_Send_NoContacts_'; if (sizeof($sending_to) == 1) { $var .= 'One_'; } else { $var .= 'Many_'; } $var .= $send_type; FlashMessage(GetLang($var), SS_FLASH_MSG_ERROR, $step1_url); return; } $send_details['sendsize'] = $send_size; IEM::sessionSet('SplitTestSend', $send_details); /** * Get the flashmessage to draw the box. * then add to the existing messages (eg we're back here from step 3). */ if ($send_size == 1) { FlashMessage(GetLang('Addon_splittest_Send_Step2_Size_One'), SS_FLASH_MSG_SUCCESS); } else { FlashMessage(sprintf(GetLang('Addon_splittest_Send_Step2_Size_Many'), $this->PrintNumber($send_size)), SS_FLASH_MSG_SUCCESS); } $flash_messages .= GetFlashMessages(); $this->template_system->Assign('FlashMessages', $flash_messages, false); if (self::CheckCronEnabled()) { $this->template_system->Assign('CronEnabled', true); /** * Get the sendstudio functions file to create the date/time box. */ require_once SENDSTUDIO_FUNCTION_DIRECTORY . '/sendstudio_functions.php'; /** * also need to load the 'send' language file so it can put in the names/descriptions. */ $ssf = new SendStudio_Functions(); $ssf->LoadLanguageFile('send'); $timebox = $ssf->CreateDateTimeBox(0, false, 'datetime', true); $this->template_system->Assign('ScheduleTimeBox', $timebox, false); } $this->template_system->Assign('ShowBounceInfo', $user->HasAccess('Lists', 'BounceSettings')); $this->template_system->Assign('DisplayEmbedImages', SENDSTUDIO_ALLOW_EMBEDIMAGES); $this->template_system->Assign('EmbedImagesByDefault', SENDSTUDIO_DEFAULT_EMBEDIMAGES); $list_api->Load($list_id); $details = array('fromname' => $list_api->Get('ownername'), 'fromemail' => $list_api->Get('owneremail'), 'replytoemail' => $list_api->Get('replytoemail'), 'bounceemail' => $list_api->Get('bounceemail')); $customfield_settings = array(); $list_customfields = $list_api->GetCustomFields($listids); foreach ($list_customfields as $fieldid => $fielddetails) { if (strtolower($fielddetails['fieldtype']) != 'text') { continue; } $customfield_settings[$fieldid] = htmlspecialchars($fielddetails['name'], ENT_QUOTES, SENDSTUDIO_CHARSET); } $show_customfields = false; if (!empty($customfield_settings)) { $show_customfields = true; } $this->template_system->Assign('CustomFields', $customfield_settings); $this->template_system->Assign('ShowCustomFields', $show_customfields); foreach ($details as $name => $value) { $this->template_system->Assign($name, $value); } $this->template_system->Assign('AdminUrl', $this->admin_url, false); $this->template_system->ParseTemplate('send_step2'); }
/** * EditSchedule * This prints out the "edit schedule" page * which in reality isn't much different to a normal edit schedule page except: * - list multiple campaigns (each name being clickable to show a preview of that campaign) * * The data passed in contains the "jobdetails" array from the job being edited. * That array contains the splitid - which can then be used to work out the campaigns etc being used. * * If it's not a 'splittest' job type, this function/method just returns and doesn't do anything. * * @param EventData_IEM_SCHEDULE_EDITJOB $data The array of jobdetails for the scheduled event being edited. * * @uses InterspireEventData::preventDefault * @uses User_API::GetLists * @uses User_API::GetSegmentList * @uses SendStudio_Functions::CreateDateTimeBox */ public static function EditSchedule(EventData_IEM_SCHEDULE_EDITJOB $data) { $jobinfo =& $data->jobrecord; if (empty($jobinfo) || !isset($jobinfo['jobtype'])) { FlashMessage(GetLang('Addon_splittest_Schedule_JobInvalid'), SS_FLASH_MSG_ERROR, self::application_url . 'index.php?Page=Schedule'); return; } if ($jobinfo['jobtype'] != 'splittest') { return; } $data->preventDefault(); $self = new self(); $user = GetUser(); $splitid = $jobinfo['jobdetails']['splitid']; /** * Check for messages. * If there are no flash messages, maybe it's being set in the "GLOBALS[Message]" string instead * by the admin/functions/schedule.php file. * Check that too :) */ $flash_messages = GetFlashMessages(); if (isset($GLOBALS['Message'])) { $flash_messages .= $GLOBALS['Message']; } $self->template_system->Assign('FlashMessages', $flash_messages, false); $self->template_system->Assign('Jobid', $jobinfo['jobid']); require_once SENDSTUDIO_API_DIRECTORY . '/newsletters.php'; require_once SENDSTUDIO_API_DIRECTORY . '/jobs.php'; require_once SENDSTUDIO_API_DIRECTORY . '/stats.php'; $job_api = new Jobs_API(); $stats_api = new Stats_API(); $news_api = new Newsletters_API(); $splitapi = $self->GetApi(); $splitdetails = $splitapi->Load($splitid); $sendtype = $jobinfo['jobdetails']['sendingto']['sendtype']; $sending_to = $jobinfo['jobdetails']['sendingto']['sendids']; $sendinglist = array(); if ($sendtype == 'list') { $user_lists = $user->GetLists(); foreach ($sending_to as $listid) { $sendinglist[$listid] = htmlspecialchars($user_lists[$listid]['name'], ENT_QUOTES, SENDSTUDIO_CHARSET); } } if ($sendtype == 'segment') { $user_segments = $user->GetSegmentList(); foreach ($sending_to as $segmentid) { $sendinglist[$segmentid] = htmlspecialchars($user_segments[$segmentid]['segmentname'], ENT_QUOTES, SENDSTUDIO_CHARSET); } } /** * Get the sendstudio functions file to create the date/time box. */ require_once SENDSTUDIO_FUNCTION_DIRECTORY . '/sendstudio_functions.php'; /** * also need to load the 'send' language file so it can put in the names/descriptions. */ require_once SENDSTUDIO_LANGUAGE_DIRECTORY . '/default/send.php'; $ssf = new SendStudio_Functions(); $timebox = $ssf->CreateDateTimeBox($jobinfo['jobtime'], false, 'datetime', true); $self->template_system->Assign('ApplicationUrl', $self->application_url, false); $self->template_system->Assign('ScheduleTimeBox', $timebox, false); $self->template_system->Assign('SendType', $sendtype); $self->template_system->Assign('campaigns', $splitdetails['splittest_campaigns']); $self->template_system->Assign('sendinglist', $sendinglist); $self->template_system->ParseTemplate('schedule_edit'); }