Example #1
0
 /**
  * Return a string containing the admin interface for the EComm Module
  *
  * @return string
  */
 public function getAdminInterface()
 {
     $this->smarty->assign('CurrencySign', SiteConfig::get("EComm::CurrencySign"));
     $section = @$_REQUEST['section'];
     switch ($section) {
         case 'ProductType':
         case 'Supplier':
         case 'Category':
         case 'TaxClass':
         case 'TaxRate':
             //$section will be the name of the class, the name of the PHP file, and the name of the .tpl file as well
             require_once "include/{$section}.php";
             $obj = new $section(@$_REQUEST[call_user_func(array($section, 'getQuickFormPrefix')) . 'id']);
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $form = $obj->getAddEditForm("/admin/EComm");
                     if (!$form->isProcessed()) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $obj->delete();
                     return 1;
                     break;
             }
             $results = call_user_func(array($section, 'getAll'), false);
             //Get all the records
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/{$section}.tpl");
             break;
         case 'Plugins':
             require_once 'plugins/products/ECommProduct.php';
             $ECommPlugins = new ECommProduct();
             $page = @$_REQUEST["page"];
             if ($page && $ECommPlugins->getPlugin($page) && $ECommPlugins->getPlugin($page)->hasAdminInterface()) {
                 $this->smarty->assign('ECommPlugins', $ECommPlugins);
                 $this->smarty->assign('plugin', $_REQUEST["page"]);
                 return $this->smarty->fetch("admin/ProductPluginAdminArea.tpl");
             } else {
                 $this->smarty->assign('ECommPlugins', $ECommPlugins);
                 $this->smarty->assign('plugins', $ECommPlugins->getActivePluginIDs());
                 return $this->smarty->fetch("admin/ProductPlugin.tpl");
             }
             break;
         case 'Product':
             require_once "include/Product.php";
             require_once 'plugins/products/ECommProduct.php';
             $this->addJS("/modules/EComm/js/ecomm.js");
             $this->addCSS("/modules/EComm/css/ecomm.css");
             $obj = new Product(@$_REQUEST['product_id']);
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $form = $obj->getAddEditForm("/admin/EComm");
                     if (!$form->isProcessed()) {
                         return $form->display();
                     }
                     $hookResults = ECommProduct::adminPluginHooks("AfterSave", $obj, $form);
                     break;
                 case 'delete':
                     $hookResults = ECommProduct::adminPluginHooks("BeforeDelete", $obj);
                     $obj->delete();
                     $hookResults = ECommProduct::adminPluginHooks("AfterDelete", $obj);
                     break;
                 case 'autoComplete':
                     $array = Product::searchProducts(array('Name' => @$_REQUEST['productName']), false);
                     $str = '<ul>';
                     foreach ($array as $key => $product) {
                         $str .= '<li id="' . $product->getId() . '">' . $product->getName() . '</li>';
                     }
                     $str .= '</ul>';
                     return $str;
             }
             require_once 'Pager.php';
             $productsPerPage = 10;
             $ecommStatus = $this->getECommStatus();
             $pagerOptions = array('mode' => 'Sliding', 'delta' => 1, 'perPage' => $productsPerPage, 'append' => false, 'path' => '/', 'fileName' => "EComm&section=Product&pageID=%d", 'totalItems' => $ecommStatus['products']);
             $pager =& Pager::factory($pagerOptions);
             list($from, $to) = $pager->getOffsetByPageId();
             $this->smarty->assign('pager_links', $pager->links);
             $this->smarty->assign('page_numbers', array('current' => $pager->getCurrentPageID(), 'total' => $pager->numPages()));
             $results = Product::getAll(false, $from, $productsPerPage);
             $this->smarty->assign('msg', @$_REQUEST["msg"]);
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/Product.tpl");
             break;
         case 'Shipping':
             require_once 'plugins/shipping/ECommShipping.php';
             $ECommShipping = new ECommShipping();
             if (@$_REQUEST["plugin"]) {
                 $plugin = $ECommShipping->getPlugin($_REQUEST["plugin"]);
                 if (!$plugin) {
                     return "Plugin not found";
                 }
                 return $this->smarty->fetch('admin/subnavi.tpl') . $plugin->getAdminInterface($this);
             } else {
                 $this->smarty->assign('ECommShipping', $ECommShipping);
                 $this->smarty->assign('plugins', $ECommShipping->getActivePluginIDs());
                 return $this->smarty->fetch("admin/ShippingNavi.tpl");
             }
             break;
         case 'Order':
             require_once "include/Order.php";
             $obj = new Order(@$_REQUEST['order_id']);
             switch (@$_REQUEST['action']) {
                 case 'View':
                     $orderItems = OrderDetail::getAll($obj->getId());
                     $orderComments = OrderComment::getAll($obj->getId());
                     $this->smarty->assign('order', $obj);
                     $this->smarty->assign('orderItems', $orderItems);
                     $this->smarty->assign('orderComments', $orderComments);
                     return $this->smarty->fetch("admin/OrderDetail.tpl");
                     break;
                 case 'Comment':
                     $orderComment = new OrderComment();
                     $orderComment->setStatus($obj->getStatus());
                     $orderComment->setOrderNb($obj->getId());
                     $form = $orderComment->getAddEditForm("/admin/EComm");
                     if (!$form->isProcessed()) {
                         return $form->display();
                     }
                     $obj->setStatus(@$_REQUEST["ordercomment_status"]);
                     $obj->save();
                     break;
             }
             $results = Order::getAll(@$_REQUEST["allOrders"]);
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/Order.tpl");
         case 'Transaction':
             require_once "include/Transaction.php";
             $results = Transaction::getAll();
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/Transaction.tpl");
             break;
         default:
             $this->smarty->assign('status', $this->getECommStatus());
             return $this->smarty->fetch('admin/dashBoard.tpl');
     }
 }