public function actionIndex() { if (isset($_POST['ajax'])) { $slideShows = Slideshow::model()->findAll(); $images = array(); if ($slideShows) { foreach ($slideShows as $slideShow) { $images[] = $slideShow->imageLink; } echo json_encode($images); } } else { $newProducts = NewProducts::model()->findAll(); $hotProducts = HotProducts::model()->findAll(array("limit" => 17)); $amthucs = Amthuc::model()->findAll(array("order" => 'id DESC', "limit" => 4)); if ($newProducts || $hotProducts) { $newProduct = array(); foreach ($newProducts as $newProduct1) { $product = Products::model()->findByPk($newProduct1->product_id); if ($product) { $newProduct[$newProduct1->id] = $product; } } foreach ($hotProducts as $key => $value) { $product = Products::model()->find('id=:product_id', array(':product_id' => $value->product_id)); if ($product) { $products[] = $product; } } if ($newProduct && $products || $amthucs) { $this->render('index', array('newProduct' => $newProduct, 'products' => $products, 'amthucs' => $amthucs)); } else { $this->render('index'); } } } }
/** * lookups () * Provides fast db lookups with as little overhead as possible */ function lookups($wp) { $db =& DB::get(); // Grab query requests from permalink rewriting query vars $admin = false; $download = isset($wp->query_vars['shopp_download']) ? $wp->query_vars['shopp_download'] : ''; $lookup = isset($wp->query_vars['shopp_lookup']) ? $wp->query_vars['shopp_lookup'] : ''; // Admin Lookups if (isset($_GET['page']) && $_GET['page'] == "shopp-lookup") { $admin = true; $image = $_GET['id']; $download = $_GET['download']; } if (!empty($download)) { $lookup = "download"; } if (empty($lookup)) { $lookup = isset($_GET['lookup']) ? $_GET['lookup'] : ''; } switch ($lookup) { case "purchaselog": if (!defined('WP_ADMIN') || !is_user_logged_in() || !current_user_can('manage_options')) { die('-1'); } $db =& DB::get(); if (!isset($_POST['settings']['purchaselog_columns'])) { $_POST['settings']['purchaselog_columns'] = array_keys(array_merge($Purchase, $Purchased)); $_POST['settings']['purchaselog_headers'] = "on"; } $this->Flow->settings_save(); $format = $this->Settings->get('purchaselog_format'); if (empty($format)) { $format = 'tab'; } switch ($format) { case "csv": new PurchasesCSVExport(); break; case "xls": new PurchasesXLSExport(); break; case "iif": new PurchasesIIFExport(); break; default: new PurchasesTabExport(); } exit; break; case "customerexport": if (!defined('WP_ADMIN') || !is_user_logged_in() || !current_user_can('manage_options')) { die('-1'); } $db =& DB::get(); if (!isset($_POST['settings']['customerexport_columns'])) { $Customer = Customer::exportcolumns(); $Billing = Billing::exportcolumns(); $Shipping = Shipping::exportcolumns(); $_POST['settings']['customerexport_columns'] = array_keys(array_merge($Customer, $Billing, $Shipping)); $_POST['settings']['customerexport_headers'] = "on"; } $this->Flow->settings_save(); $format = $this->Settings->get('customerexport_format'); if (empty($format)) { $format = 'tab'; } switch ($format) { case "csv": new CustomersCSVExport(); break; case "xls": new CustomersXLSExport(); break; default: new CustomersTabExport(); } exit; break; case "receipt": if (!defined('WP_ADMIN') || !is_user_logged_in() || !current_user_can('manage_options')) { die('-1'); } if (preg_match("/\\d+/", $_GET['id'])) { $this->Cart->data->Purchase = new Purchase($_GET['id']); $this->Cart->data->Purchase->load_purchased(); } else { die('-1'); } echo "<html><head>"; echo '<style type="text/css">body { padding: 20px; font-family: Arial,Helvetica,sans-serif; }</style>'; echo "<link rel='stylesheet' href='" . SHOPP_TEMPLATES_URI . "/shopp.css' type='text/css' />"; echo "</head><body>"; echo $this->Flow->order_receipt(); if (isset($_GET['print']) && $_GET['print'] == 'auto') { echo '<script type="text/javascript">window.onload = function () { window.print(); window.close(); }</script>'; } echo "</body></html>"; exit; break; case "zones": $zones = $this->Settings->get('zones'); if (isset($_GET['country'])) { echo json_encode($zones[$_GET['country']]); } exit; break; case "shipcost": @session_start(); $this->ShipCalcs = new ShipCalcs($this->path); if (isset($_GET['method'])) { $this->Cart->data->Order->Shipping->method = $_GET['method']; $this->Cart->retotal = true; $this->Cart->updated(); $this->Cart->totals(); echo json_encode($this->Cart->data->Totals); } exit; break; case "category-menu": echo $this->Flow->category_menu(); exit; break; case "category-products-menu": echo $this->Flow->category_products(); exit; break; case "spectemplate": $db = DB::get(); $table = DatabaseObject::tablename(Category::$table); $result = $db->query("SELECT specs FROM {$table} WHERE id='{$_GET['cat']}' AND spectemplate='on'"); echo json_encode(unserialize($result->specs)); exit; break; case "optionstemplate": $db = DB::get(); $table = DatabaseObject::tablename(Category::$table); $result = $db->query("SELECT options,prices FROM {$table} WHERE id='{$_GET['cat']}' AND variations='on'"); if (empty($result)) { exit; } $result->options = unserialize($result->options); $result->prices = unserialize($result->prices); foreach ($result->options as &$menu) { foreach ($menu['options'] as &$option) { $option['id'] += $_GET['cat']; } } foreach ($result->prices as &$price) { $optionids = explode(",", $price['options']); foreach ($optionids as &$id) { $id += $_GET['cat']; } $price['options'] = join(",", $optionids); $price['optionkey'] = ""; } echo json_encode($result); exit; break; case "newproducts-rss": $NewProducts = new NewProducts(array('show' => 5000)); header("Content-type: application/rss+xml; charset=utf-8"); echo shopp_rss($NewProducts->rss()); exit; break; case "category-rss": $this->catalog($wp); header("Content-type: application/rss+xml; charset=utf-8"); echo shopp_rss($this->Category->rss()); exit; break; case "download": if (empty($download)) { break; } if ($admin) { $Asset = new Asset($download); } else { $db = DB::get(); $pricetable = DatabaseObject::tablename(Purchase::$table); $pricetable = DatabaseObject::tablename(Price::$table); $assettable = DatabaseObject::tablename(Asset::$table); require_once "core/model/Purchased.php"; $Purchased = new Purchased($download, "dkey"); $Purchase = new Purchase($Purchased->purchase); $target = $db->query("SELECT target.* FROM {$assettable} AS target LEFT JOIN {$pricetable} AS pricing ON pricing.id=target.parent AND target.context='price' WHERE pricing.id={$Purchased->price} AND target.datatype='download'"); $Asset = new Asset(); $Asset->populate($target); $forbidden = false; // Purchase Completion check if ($Purchase->transtatus != "CHARGED" && !SHOPP_PREPAYMENT_DOWNLOADS) { new ShoppError(__('This file cannot be downloaded because payment has not been received yet.', 'Shopp'), 'shopp_download_limit'); $forbidden = true; } // Account restriction checks if ($this->Settings->get('account_system') != "none" && (!$this->Cart->data->login || $this->Cart->data->Order->Customer->id != $Purchase->customer)) { new ShoppError(__('You must login to access this download.', 'Shopp'), 'shopp_download_limit', SHOPP_ERR); header('Location: ' . $this->link('account')); exit; } // Download limit checking if ($this->Settings->get('download_limit') && $Purchased->downloads + 1 > $this->Settings->get('download_limit')) { new ShoppError(__('This file can no longer be downloaded because the download limit has been reached.', 'Shopp'), 'shopp_download_limit'); $forbidden = true; } // Download expiration checking if ($this->Settings->get('download_timelimit') && $Purchased->created + $this->Settings->get('download_timelimit') < mktime()) { new ShoppError(__('This file can no longer be downloaded because it has expired.', 'Shopp'), 'shopp_download_limit'); $forbidden = true; } // IP restriction checks if ($this->Settings->get('download_restriction') == "ip" && !empty($Purchase->ip) && $Purchase->ip != $_SERVER['REMOTE_ADDR']) { new ShoppError(__('The file cannot be downloaded because this computer could not be verified as the system the file was purchased from.', 'Shopp'), 'shopp_download_limit'); $forbidden = true; } do_action_ref_array('shopp_download_request', array(&$Purchased)); } if ($forbidden) { header("Status: 403 Forbidden"); return; } if ($Asset->download($download)) { $Purchased->downloads++; $Purchased->save(); do_action_ref_array('shopp_download_success', array(&$Purchased)); exit; } break; } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $categorys = Categorys::model()->findAll(array('order' => 'name')); if (isset($_POST['Products'])) { $_POST['Products']['imageLink'] = $model->imageLink; $model->attributes = $_POST['Products']; $model->update_time = date("Y-m-d H:i:s"); if (isset($_POST['category'])) { $model->category = $_POST['category']; } $uploadedFile = CUploadedFile::getInstance($model, 'imageLink'); if ($uploadedFile) { $fileExtensionName = $uploadedFile->extensionName; $md5FileName = md5($uploadedFile); $fileName = "{$md5FileName}.{$fileExtensionName}"; // random number + file name $model->imageLink = $fileName; } if ($model->save()) { //if click checkbox it will insert product_id to newProduct vs hotProduct table in database if (isset($_POST['newProduct_check'])) { $product = Products::model()->find('name=:name', array(':name' => $model->name)); $id = $product->id; $tableName = 'newproducts'; $newProduct = NewProducts::model()->find('product_id=:product_id', array(':product_id' => $id)); if (!$newProduct) { $this->insertData($tableName, $id); } } if (isset($_POST['hotProduct_check'])) { $product = Products::model()->find('name=:name', array(':name' => $model->name)); $id = $product->id; $tableName = 'hotproducts'; $hotProduct = HotProducts::model()->find('product_id=:product_id', array(':product_id' => $id)); if (!$hotProduct) { $this->insertData($tableName, $id); } } if (!empty($uploadedFile)) { $uploadedFile->saveAs(Yii::app()->basePath . '/../images/Product/' . $model->imageLink); } $this->redirect(array('admin')); } } $this->render('update', array('model' => $model, 'categorys' => $categorys)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return NewProducts the loaded model * @throws CHttpException */ public function loadModel($id) { $model = NewProducts::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }