/** * Admin_Action_Delete * This function handles what happens when you delete a split test. * It checks you are doing a form post. * Then it grabs the api and passes the id(s) across to the api to delete. * * It checks what the api returns and creates a flash message based on the result. * Eg you can't delete a split test campaign while it's sending. * * After that, it returns you to the 'Manage' page. * * @uses SplitTest_API::Delete * @see Admin_Action_Default * @uses GetApi */ public function Admin_Action_Delete() { $user = GetUser(); $api = $this->GetApi(); $split_ids = $this->_getPOSTRequest('splitids', null); if (is_null($split_ids)) { $split_ids = $this->_getPOSTRequest('splitid', null); } if (is_null($split_ids)) { FlashMessage(GetLang('Addon_splittest_ChooseSplittestsToDelete'), SS_FLASH_MSG_ERROR, $this->admin_url); return; } $split_ids = SplitTest_API::FilterIntSet($split_ids); if (!SplitTest_API::OwnsSplitTests($user->Get('userid'), $split_ids) && !$user->Admin()) { FlashMessage(GetLang('NoAccess'), SS_FLASH_MSG_ERROR, $this->admin_url); return; } $deleted = 0; $not_deleted = 0; foreach ($split_ids as $split_id) { $delete_success = $api->Delete($split_id); if ($delete_success) { $deleted++; continue; } $not_deleted++; } /** * If there are only "delete ok" messages, then just work out the number to show * and then create a flash message. */ $url = $this->admin_url; if ($not_deleted > 0) { $url = null; } if ($deleted == 1) { FlashMessage(GetLang('Addon_splittest_SplittestDeleted_One'), SS_FLASH_MSG_SUCCESS, $url); if ($not_deleted == 0) { return; } } if ($deleted > 1) { FlashMessage(sprintf(GetLang('Addon_splittest_SplittestDeleted_Many'), self::PrintNumber($deleted)), SS_FLASH_MSG_SUCCESS, $url); if ($not_deleted == 0) { return; } } if ($not_deleted == 1) { $msg = GetLang('Addon_splittest_SplittestNotDeleted_One'); } else { $msg = sprintf(GetLang('Addon_splittest_SplittestNotDeleted_Many'), self::PrintNumber($not_deleted)); } FlashMessage($msg, SS_FLASH_MSG_ERROR, $this->admin_url); }
/** * ShowStats * Displays statistics for a split test. * * @param Int $split_id The ID of a split test. * * @return String The HTML to output. */ private function ShowStats($split_id) { $user = GetUser(); $template_name = 'splittest_campaign_stats'; $split_api = $this->GetApi('Splittest'); $stats_api = $this->GetApi('Splittest_Stats'); $date_format = self::getDateFormat(); $jobid = $this->_getGETRequest('jobid', null); if (!SplitTest_API::OwnsSplitTests($user->Get('userid'), $split_id) && !$user->Admin()) { FlashMessage(GetLang('NoAccess'), SS_FLASH_MSG_ERROR, $this->base_url); return; } $stats = $stats_api->GetStats(array($split_id), array(), false, 0, 1, false, $jobid); $stats = $stats[$jobid]; $stats['splitname'] = htmlspecialchars($stats['splitname'], ENT_QUOTES, SENDSTUDIO_CHARSET); $stats['campaign_names'] = htmlspecialchars($stats['campaign_names'], ENT_QUOTES, SENDSTUDIO_CHARSET); $stats['list_names'] = htmlspecialchars($stats['list_names'], ENT_QUOTES, SENDSTUDIO_CHARSET); $charts = $this->generateCharts($stats['splitname'], $stats['campaigns']); foreach ($charts as $type => $data) { $stats[$type] = $data; } $this->template_system->Assign('AdminUrl', $this->admin_url, false); $this->template_system->Assign('ApplicationUrl', $this->application_url, false); $this->template_system->Assign('DateFormat', $date_format); $this->template_system->Assign('statsDetails', $stats); $this->template_system->Assign('FlashMessages', GetFlashMessages()); $this->template_system->ParseTemplate($template_name); }