/** * Main handler. Does all the checks * * @param void * @return void */ public function audit() { /* If no user, some checks may be skipped... */ // Get user $jUser = User::getRoot(); // User specific checks if (!$jUser->get('guest')) { if ($sId = $this->getSku()) { // Check if the current user reached the max count of downloads for this SKU $sku = new Sku($sId); $skuDownloadLimit = $sku->getMeta('downloadLimit'); if ($skuDownloadLimit > 0) { // Get SKU download count $skuDownloadCount = CartDownload::countUserSkuDownloads($this->sId, $this->uId); // Check if the limit is reached if ($skuDownloadCount >= $skuDownloadLimit) { $this->setResponseStatus('error'); $this->setResponseNotice('You have reached the maximum number of allowed downloads for this product.'); $this->setResponseError(': you have reached the maximum number of allowed downloads for this product.'); } } return $this->getResponse(); } } // Check SKU-related stuff if this is a SKU if ($sId = $this->getSku()) { // Check if SKU is reached the download max count $sku = new Sku($sId); $skuDownloadLimit = $sku->getMeta('globalDownloadLimit'); if ($skuDownloadLimit > 0) { // Get SKU download count $skuDownloadCount = CartDownload::countSkuDownloads($this->sId); // Check if the limit is reached if ($skuDownloadCount >= $skuDownloadLimit) { $this->setResponseStatus('error'); $this->setResponseNotice('This product has reached the maximum number of allowed downloads and cannot be downloaded.'); $this->setResponseError(': this product has reached the maximum number of allowed downloads and cannot be downloaded.'); } } return $this->getResponse(); } // Get product download limit $productDownloadLimit = Product::getMeta($this->pId, 'globalDownloadLimit'); // Get product downloads count if ($productDownloadLimit > 0) { $productDownloadCount = CartDownload::countProductDownloads($this->pId); // Check if the limit is reached if ($productDownloadCount >= $productDownloadLimit) { $this->setResponseStatus('error'); $this->setResponseNotice('This product has reached the maximum number of allowed downloads and cannot be downloaded.'); $this->setResponseError(': this product has reached the maximum number of allowed downloads and cannot be downloaded.'); } } return $this->getResponse(); }
/** * Edit a category * * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); $obj = new Archive(); // Get types $this->view->types = $obj->getProductTypes(); // Get collections $this->view->collections = $obj->collections('list', array('sort' => 'cType')); // Get all option groups $this->view->optionGroups = $obj->optionGroups('list', array('sort' => 'ogName')); if (is_object($row)) { $id = $row->getId(); $this->view->row = $row; $this->view->task = 'edit'; } else { // Incoming $id = Request::getVar('id', array(0)); if (is_array($id) && !empty($id)) { $id = $id[0]; } // Load product $this->view->row = $obj->product($id); } // Get product option groups $this->view->productOptionGroups = $this->view->row->getOptionGroups(); $this->view->config = $this->config; // Check if meta is needed for this product $pType = $this->view->row->getType(); $this->view->metaNeeded = false; // Only software needs meta if ($pType == 30) { $this->view->metaNeeded = true; } // Get number of downloads $downloaded = CartDownload::countProductDownloads($id); $this->view->downloaded = $downloaded; // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->setLayout('edit')->display(); }
/** * Download CSV report (SKU) * * @return void */ public function downloadSkuTask() { // Get filters $filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'dDownloaded'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC')); $rowsRaw = CartDownload::getDownloadsSku('array', $filters); $rows = array(); foreach ($rowsRaw as $row) { $rows[] = array($row['pName'], $row['sSku'], $row['downloaded']); } $date = date('d-m-Y'); header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=cart-downloads-sku-" . $date . ".csv"); // Disable caching header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 header("Pragma: no-cache"); // HTTP 1.0 header("Expires: 0"); // Proxies $output = fopen("php://output", "w"); $row = array('Product', 'SKU', 'Downloaded (times)'); fputcsv($output, $row); foreach ($rows as $row) { // replace($row) empty vals with n/a foreach ($row as $k => $val) { if (empty($val)) { $row[$k] = 'n/a'; } } fputcsv($output, $row); } fclose($output); die; }
/** * Edit a SKU * * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); $obj = new Archive(); if (is_object($row)) { $id = $row->getId(); // If this is a new SKU, set product ID if (!$id) { $pId = Request::getVar('pId'); $row->setProductId($pId); } $this->view->row = $row; $this->view->task = 'edit'; } else { // Incoming $id = Request::getVar('id', array(0)); if (is_array($id) && !empty($id)) { $id = $id[0]; } // Get correct SKU instance $pId = Request::getVar('pId'); if ($id) { $row = Sku::getInstance($id); } elseif ($pId) { // create new SKU $row = Sku::newInstance($pId); } else { throw new \Exception('SKU was not found'); } $this->view->row = $row; } // Get product's info $pId = $row->getProductId(); $warehouse = new Warehouse(); $pInfo = $warehouse->getProductInfo($pId, true); $this->view->pInfo = $pInfo; //print_r($pInfo); die; // Get available product-defined option groups and options $this->view->allOptions = $obj->getProductOptions($pId); // Get current SKU options $this->view->options = $row->getOptions(); // Get number of downloads $downloaded = CartDownload::countSkuDownloads($id); $this->view->downloaded = $downloaded; // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->setLayout('edit')->display(); }
/** * Download CSV report * * @return void */ public function downloadTask() { // Get filters $filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'dDownloaded'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC')); $rowsRaw = CartDownload::getDownloads('array', $filters); $date = date('d-m-Y'); $rows = array(); foreach ($rowsRaw as $row) { $status = 'active'; if (!$row['dStatus']) { $status = 'inactive'; } $rows[] = array($row['dDownloaded'], $row['pName'], $row['sSku'], $row['dName'], $row['username'], $row['uId'], $row['dIp'], $status); } header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=cart-downloads-" . $date . ".csv"); // Disable caching header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 header("Pragma: no-cache"); // HTTP 1.0 header("Expires: 0"); // Proxies $output = fopen("php://output", "w"); $row = array('Downloaded', 'Product', 'SKU', 'User', 'Username', 'User ID', 'IP', 'Status'); fputcsv($output, $row); foreach ($rows as $row) { fputcsv($output, $row); } fclose($output); die; }