/** * printPage * * @return Void Doesn't return anything. */ public function printPage() { $user = GetUser(); $split_api = $this->GetApi('Splittest'); // for permission checks $subaction = $this->_getGetRequest('subaction', 'print'); $perpage = $this->_getGetRequest('PerPageDisplay', null); $jobids = $this->_getGETRequest('jobids', null); $listids = $this->_getGETRequest('split_statids', null); $jobids = explode(",", $jobids); $listids = explode(",", $listids); SendStudio_Functions::LoadLanguageFile('Stats'); if (!SplitTest_API::OwnsJobs($user->Get('userid'), $jobids) && !$user->Admin()) { FlashMessage(GetLang('NoAccess'), SS_FLASH_MSG_ERROR, $this->base_url); return; } // Get some setup parameters for the API $sortdetails = array('sort' => 'splitname', 'direction' => 'asc'); $page_number = 0; $perpage = 20; $displayAll = false; // just show a single splitest campaign send. If you want every campaign send for a split test set to true $dateFromat = self::getDateFormat(); $statitics = array(); $jobid = 0; for ($i = 0; $i < count($jobids); $i++) { $stats = array(); $stats_api = new Splittest_Stats_API(); $jobid = $jobids[$i]; $splitid = $listids[$i]; // get the array of stats data $stats = $stats_api->GetStats(array($splitid), $sortdetails, false, $page_number, $perpage, $displayAll, $jobid); foreach ($stats as $stats_id => $stats_details) { $stats[$stats_id]['splitname'] = htmlspecialchars($stats_details['splitname'], ENT_QUOTES, SENDSTUDIO_CHARSET); $stats[$stats_id]['campaign_names'] = htmlspecialchars($stats_details['campaign_names'], ENT_QUOTES, SENDSTUDIO_CHARSET); $stats[$stats_id]['list_names'] = htmlspecialchars($stats_details['list_names'], ENT_QUOTES, SENDSTUDIO_CHARSET); } // A Splittest can be sent multiple times hence we might have multiple campaign record sets here while (list($id, $data) = each($stats)) { $charts = $this->generateCharts($data['splitname'], $data['campaigns'], $subaction); foreach ($charts as $type => $data) { $stats[$id][$type] = $data; } } $statistics[] = $stats; } $template = GetTemplateSystem(dirname(__FILE__) . '/templates'); $template->Assign('DateFormat', $dateFromat); $template->Assign('statsData', $statistics); $template->Assign('subaction', $subaction); $options = $this->_getGETRequest('options', null); for ($i = 0; $i < count($options); $i++) { $template->Assign($options[$i], $options[$i]); } $template->ParseTemplate('Stats_Summary_Splittest'); }
/** * ManageStats * Displays a list of statistics. * * @return String The HTML to output. */ private function ManageStats() { $user = GetUser(); $subAction = $this->_getPOSTRequest('SubAction', null); $jobid = $this->_getPOSTRequest('jobid', null); $exportFileName = $this->_getGETRequest('exportFileName', null); $split_api = $this->GetApi('Splittest'); $stats_api = $this->GetApi('Splittest_Stats'); $dateFormat = self::getDateFormat(); $displayAll = true; $templateName = 'stats_display'; if ($subAction == 'Delete' || $subAction == 'MultiDelete') { if ($subAction == 'Delete') { $jobids = array($jobid); } else { $jobids = $this->_getPOSTRequest('jobids', null); } // if they can't delete split tests, we won't let them delete split test stats $access = SplitTest_API::OwnsJobs($user->Get('userid'), $jobids); $access = $access && $user->HasAccess('splittest', 'delete'); $access = $access || $user->Admin(); if (!$access) { FlashMessage(GetLang('NoAccess'), SS_FLASH_MSG_ERROR, $this->base_url); exit; } if ($stats_api->DeleteSplittestStats($jobids)) { FlashMessage(GetLang('Addon_splittest_StatsDeleted_Success'), SS_FLASH_MSG_SUCCESS, $this->base_url); } else { FlashMessage(GetLang('Addon_splittest_StatsDeleted_Fail'), SS_FLASH_MSG_ERROR, $this->base_url); } exit; } // Get the listids associated with this user $lists = $user->GetLists(); $listids = array_keys($lists); $number_of_stats = $stats_api->GetStats($listids, array(), true); if ($number_of_stats == 0) { $curr_template_dir = $this->template_system->GetTemplatePath(); $this->template_system->SetTemplatePath(SENDSTUDIO_TEMPLATE_DIRECTORY); $GLOBALS['Success'] = GetLang('Addon_splittest_Stats_NoneSent'); $msg = $this->template_system->ParseTemplate('successmsg', true); $this->template_system->SetTemplatePath($curr_template_dir); $this->template_system->Assign('Addon_splittest_Stats_Empty', $msg, false); $this->template_system->Assign('AdminUrl', $this->admin_url, false); $this->template_system->Assign('SplitTest_Create_Button', $this->template_system->ParseTemplate('create_button', true)); $this->template_system->ParseTemplate('stats_empty'); return; } $paging = $this->SetupPaging($this->base_url, $number_of_stats); $page_number = $this->GetCurrentPage(); $perpage = $this->GetPerPage(); $sortdetails = $this->GetSortDetails(); $stats = $stats_api->GetStats($listids, $sortdetails, false, $page_number, $perpage, $displayAll, $jobid); if (in_array($subAction, array('Export', 'MultiExport'))) { if ($subAction == 'MultiExport') { $jobids = $this->_getPOSTRequest('jobids', null); $splitName = 'splittests'; } else { $jobids = array($jobid); $splitName = null; } if (!SplitTest_API::OwnsJobs($user->Get('userid'), $jobids) && !$user->Admin()) { FlashMessage(GetLang('NoAccess'), SS_FLASH_MSG_ERROR, $this->base_url); return; } $exportFileName = self::ExportStats($stats, $jobids, $splitName); FlashMessage(sprintf(GetLang('Addon_splittest_Stats_DownloadExportedFile'), $exportFileName), SS_FLASH_MSG_SUCCESS, $this->base_url); } foreach ($stats as $stats_id => $stats_details) { $stats[$stats_id]['splitname'] = htmlspecialchars($stats_details['splitname'], ENT_QUOTES, SENDSTUDIO_CHARSET); $stats[$stats_id]['campaign_names'] = htmlspecialchars($stats_details['campaign_names'], ENT_QUOTES, SENDSTUDIO_CHARSET); //$stats[$stats_id]['list_names'] = htmlspecialchars($stats_details['list_names'], ENT_QUOTES, SENDSTUDIO_CHARSET); } if ($exportFileName != null) { $this->template_system->Assign('exportFileName', $exportFileName); } //$this->template_system->Assign('SplitTest_Send_Button', $send_button, false); $this->template_system->Assign('AdminUrl', $this->admin_url, false); $this->template_system->Assign('ApplicationUrl', $this->application_url, false); $this->template_system->Assign('Paging', $paging, false); $this->template_system->Assign('DateFormat', $dateFormat); $this->template_system->Assign('Statistics', $stats); $this->template_system->Assign('FlashMessages', GetFlashMessages()); $this->template_system->ParseTemplate($templateName); }