public function index() { $this->addComponent('menu', $this->getMenu('list')); $lang = OW::getLanguage(); $limit = 20; $page = !empty($_GET['page']) ? abs((int) $_GET['page']) : 1; $offset = ($page - 1) * $limit; $sortFields = $this->service->getSortFields(); $sortBy = !empty($_GET['sort']) && in_array($_GET['sort'], $sortFields) ? $_GET['sort'] : 'registerStamp'; $sortOrder = !empty($_GET['order']) && in_array($_GET['order'], array('asc', 'desc')) ? $_GET['order'] : 'desc'; $sortUrls = array(); $baseUrl = OW::getRouter()->urlForRoute('ocsaffiliates.admin') . '/?'; foreach ($sortFields as $field) { $sortUrls[$field] = $baseUrl . 'sort=' . $field . '&order=' . ($sortBy != $field ? 'desc' : ($sortOrder == 'desc' ? 'asc' : 'desc')); } $this->assign('sortUrls', $sortUrls); $list = $this->service->getAffiliateList($offset, $limit, $sortBy, $sortOrder); $this->assign('list', $list); $total = $this->service->countAffiliates(); $unverified = $this->service->countUnverifiedAffiliates(); $this->assign('unverified', $unverified); // Paging $pages = (int) ceil($total / $limit); $paging = new BASE_CMP_Paging($page, $pages, $limit); $this->assign('paging', $paging->render()); $billingService = BOL_BillingService::getInstance(); $this->assign('currency', $billingService->getActiveCurrency()); $logo = OW::getPluginManager()->getPlugin('ocsaffiliates')->getStaticUrl() . 'img/oxwallcandystore-logo.jpg'; $this->assign('logo', $logo); $script = '$(".action_delete").click(function(){ if ( !confirm(' . json_encode($lang->text('ocsaffiliates', 'delete_confirm')) . ') ) { return false; } var affId = $(this).attr("affid"); $.ajax({ url: ' . json_encode(OW::getRouter()->urlForRoute('ocsaffiliates.action_delete')) . ', type: "POST", data: { affiliateId: affId }, dataType: "json", success: function(data) { if ( data.result == true ) { document.location.reload(); } else if ( data.error != undefined ) { OW.warning(data.error); } } }); });'; OW::getDocument()->addOnloadScript($script); // TODO: remove this code when a sale event is available $this->service->processUntrackedSales(); OW::getDocument()->setHeading($lang->text('ocsaffiliates', 'admin_page_heading')); }