コード例 #1
0
ファイル: Cart.php プロジェクト: anas/feedstore
 /**
  * Build and return admin interface
  * 
  * Any module providing an admin interface is required to have this function, which
  * returns a string containing the (x)html of it's admin interface.
  * @return string
  */
 public function getAdminInterface()
 {
     switch (@$_REQUEST['section']) {
         case 'attributes':
             $this->addJS('/modules/Cart/js/optionvalueedit.js');
             switch (@$_REQUEST['action']) {
                 case 'values':
                     $option = new CartProductOption($_REQUEST['id']);
                     return json_encode($option->getValues());
                     die;
                 case 'addedit':
                     $option = new CartProductOption(@$_REQUEST['cartproductoption_id']);
                     $form = $option->getAddEditForm();
                     if (isset($_REQUEST['delete_value'])) {
                         $v = new CartProductOptionValue(trim($_REQUEST['delete_value'], 'delete_'));
                         $v->delete();
                         die;
                     }
                     if (isset($_REQUEST['value'])) {
                         foreach (@$_REQUEST['value'] as $key => $value) {
                             $v = new CartProductOptionValue($key);
                             $v->setName($value);
                             $v->save();
                         }
                     }
                     if (isset($_REQUEST['newvalue'])) {
                         foreach (@$_REQUEST['newvalue'] as $key => $value) {
                             $v = new CartProductOptionValue();
                             $v->setName($value);
                             $v->setLanguage_id(1);
                             $v->optionid = $option->getId();
                             $v->save();
                         }
                     }
                     if (!$form->validate() || !$form->isSubmitted() || !isset($_REQUEST['cartproductoption_submit']) && !isset($_REQUEST['valuesubmit'])) {
                         $this->smarty->assign('form', $form);
                         $this->smarty->assign('option', $option);
                         if ($option->getId()) {
                             $this->smarty->assign('values', $option->getOptionsValues());
                         }
                         return $this->smarty->fetch('admin/optionsedit.tpl');
                     }
                     break;
                 case 'delete':
                     $option = new CartProductOption(@$_REQUEST['cartproductoption_id']);
                     $option->delete();
             }
             $options = CartProductOption::getAllCartProductOptions();
             $this->smarty->assign('options', $options);
             return $this->smarty->fetch('admin/options.tpl');
         case 'products':
             require_once 'include/CartProduct.php';
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     if (isset($_REQUEST['delete_att'])) {
                         $a = new CartProductAttribute($_REQUEST['delete_att']);
                         $a->delete();
                         die;
                     }
                     if (isset($_REQUEST['delete_altimage'])) {
                         $sql = 'delete from cart_products_images where id=' . e($_REQUEST['delete_altimage']);
                         Database::singleton()->query($sql);
                         die;
                     }
                     $this->addJS('/modules/Cart/js/productedit.js');
                     $product = new CartProduct(@$_REQUEST['cartproduct_products_id']);
                     $form = $product->getAddEditForm();
                     if (!isset($_REQUEST['cartproduct_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $product = new CartProduct(@$_REQUEST['cartproduct_products_id']);
                     $product->delete();
                     break;
                 case 'auto':
                     $array = CartProduct::toArray($_REQUEST['value']);
                     $rs = array_slice($array, 1, count($array), true);
                     $str = '<ul>';
                     foreach ($rs as $key => $r) {
                         $str .= '<li id="' . $key . '">' . $r . '</li>';
                     }
                     $str .= '</ul>';
                     return $str;
             }
             require_once 'Pager.php';
             $pagerOptions = array('mode' => 'Sliding', 'delta' => 5, 'perPage' => 20, 'append' => false, 'path' => '/', 'fileName' => "Cart&section=products&pageID=%d", 'totalItems' => CartProduct::getCountCartProducts());
             $pager =& Pager::factory($pagerOptions);
             list($from, $to) = $pager->getOffsetByPageId();
             $items = CartProduct::getAllCartProducts($from, 20);
             $this->smarty->assign('pager_links', $pager->links);
             $this->smarty->assign('page_numbers', array('current' => $pager->getCurrentPageID(), 'total' => $pager->numPages()));
             $this->smarty->assign('products', $items);
             return $this->smarty->fetch('admin/products.tpl');
             break;
         case 'categories':
             require_once 'include/CartCategory.php';
             error_reporting(E_ALL);
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $category = new CartCategory(@$_REQUEST['cartcategory_categories_id']);
                     $form = $category->getAddEditForm();
                     if (!$form->validate() || !$form->isSubmitted() || !isset($_REQUEST['cartcategory_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $category = new CartCategory(@$_REQUEST['cartcategory_categories_id']);
                     $category->delete();
                     break;
             }
             $this->smarty->assign('categories', CartCategory::getCartCategorys(array('parent_id' => 0)));
             return $this->smarty->fetch('admin/categories.tpl');
             break;
         case 'product_types':
             require_once 'include/CartProductType.php';
             error_reporting(E_ALL);
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $productType = new CartProductType(@$_REQUEST['cartproducttype_type_id']);
                     $form = $productType->getAddEditForm();
                     if (!$form->validate() || !$form->isSubmitted() || !isset($_REQUEST['cartproducttype_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $productType = new CartProductType(@$_REQUEST['cartproducttype_type_id']);
                     $productType->delete();
                     break;
             }
             $this->smarty->assign('productTypes', CartProductType::getAllCartProductTypes());
             return $this->smarty->fetch('admin/product_types.tpl');
             break;
         case 'shipping':
             require_once 'include/CartShippingRate.php';
             $this->addJS('/modules/Cart/js/cartEvent.js');
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $rate = new CartShippingRate(@$_REQUEST['cartshippingrate_id']);
                     $form = $rate->getAddEditForm();
                     if (!$form->validate() || !isset($_REQUEST['cartshippingrate_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $rate = new CartShippingRate(@$_REQUEST['cartshippingrate_id']);
                     $rate->delete();
                     break;
             }
             $rates = CartShippingRate::getAllCartShippingRates();
             $this->smarty->assign('rates', $rates);
             return $this->smarty->fetch('admin/shippingrates.tpl');
             break;
         case 'tax_classes':
             require_once 'include/CartTaxClass.php';
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $class = new CartTaxClass(@$_REQUEST['carttaxclass_tax_class_id']);
                     $form = $class->getAddEditForm();
                     if (!$form->validate() || !isset($_REQUEST['carttaxclass_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $class = new CartTaxClass(@$_REQUEST['carttaxclass_tax_class_id']);
                     $class->delete();
                     break;
             }
             $classes = CartTaxClass::getAllCartTaxClasses();
             $this->smarty->assign('taxclasses', $classes);
             return $this->smarty->fetch('admin/taxclasses.tpl');
             break;
         case 'tax_rates':
             require_once 'include/CartTaxRate.php';
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $rate = new CartTaxRate(@$_REQUEST['carttaxrate_tax_rates_id']);
                     $form = $rate->getAddEditForm();
                     if (!$form->validate() || !isset($_REQUEST['carttaxrate_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $rate = new CartTaxRate(@$_REQUEST['carttaxrate_tax_rates_id']);
                     $rate->delete();
                     break;
             }
             $rates = CartTaxRate::getAllCartTaxRates();
             $this->smarty->assign('taxrates', $rates);
             return $this->smarty->fetch('admin/taxrates.tpl');
             break;
         case 'manufacturers':
             require_once 'include/CartManufacturer.php';
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $man = new CartManufacturer(@$_REQUEST['cartmanufacturer_manufacturers_id']);
                     $form = $man->getAddEditForm();
                     if (!isset($_REQUEST['cartmanufacturer_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $man = new CartManufacturer(@$_REQUEST['cartmanufacturer_manufacturers_id']);
                     $man->delete();
                     break;
             }
             $manufacturers = CartManufacturer::getAllCartManufacturers();
             $this->smarty->assign('manufacturers', $manufacturers);
             return $this->smarty->fetch('admin/manufacturers.tpl');
             break;
         case 'orders':
             require_once 'include/CartOrder.php';
             $this->addCSS('/modules/Cart/css/cart.css');
             $this->addJS('/modules/Cart/js/cart.js');
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $order = new CartOrder(@$_REQUEST['cartorder_orders_id']);
                     $form = $order->getAddEditForm();
                     if (!$form->validate() || !isset($_REQUEST['cartorder_submit'])) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $order = new CartOrder(@$_REQUEST['cartorder_orders_id']);
                     $order->delete();
                     break;
                 case 'details':
                     $order = new CartOrder(@$_REQUEST['cartorder_orders_id']);
                     $this->smarty->assign('order', $order);
                     return $this->smarty->fetch('admin/order_details.tpl');
                     break;
             }
             $orders = CartOrder::getAllCartOrders();
             $this->smarty->assign('orders', $orders);
             return $this->smarty->fetch('admin/orders.tpl');
             break;
         default:
             require_once 'include/CartCategory.php';
             require_once 'include/CartProduct.php';
             $cats = CartCategory::getCartCategorys();
             $prods = CartProduct::getCountCartProducts();
             $this->smarty->assign('categories', $cats);
             $this->smarty->assign('products', $prods);
             return $this->smarty->fetch('admin/dashboard.tpl');
             break;
     }
 }