Example #1
0
 /**
  * Lists all items in the basket.
  * @attribute[RequestParam('error','string',false)]
  */
 function Index($error)
 {
     // display any given error message
     if ($error) {
         $this->content(uiMessage::Error($error));
     }
     // prepare basket variable
     if (!isset($_SESSION['basket'])) {
         $_SESSION['basket'] = array();
     }
     if (count($_SESSION['basket']) == 0) {
         $this->content(uiMessage::Hint('Basket is empty'));
     } else {
         // list all items in the basket ...
         $ds = model_datasource('system');
         $price_total = 0;
         foreach ($_SESSION['basket'] as $id => $amount) {
             $prod = $ds->Query('products')->eq('id', $id)->current();
             //... each using a template
             $this->content(Template::Make('product_basket'))->set('title', $prod->title)->set('amount', $amount)->set('price', $prod->price)->set('image', resFile($prod->image))->set('add', buildQuery('Basket', 'Add', array('id' => $prod->id)))->set('remove', buildQuery('Basket', 'Remove', array('id' => $prod->id)));
             $price_total += $amount * $prod->price;
         }
         // display total price and the button to go on
         $this->content("<div class='basket_total'>Total price: {$price_total}</div>");
         $this->content(uiButton::Make("Buy now"))->onclick = "location.href = '" . buildQuery('Basket', 'BuyNow') . "'";
     }
 }
Example #2
0
 function Index()
 {
     $this->_login();
     // require admin to be logged in
     // add products table and a button to create a new product
     $this->content("<h1>Products</h1>");
     $this->content(new uiDatabaseTable(model_datasource('system'), false, 'products'))->AddPager(10)->AddRowAction('trash', 'Delete', $this, 'DelProduct');
     $this->content(uiButton::Make('Add product'))->onclick = AjaxAction::Post('Admin', 'AddProduct');
     // add orders table
     $this->content("<h1>Orders</h1>");
     $this->content(new uiDatabaseTable(model_datasource('system'), false, 'orders'))->AddPager(10)->OrderBy = 'id DESC';
     // add customers table
     $this->content("<h1>Customers</h1>");
     $this->content(new uiDatabaseTable(model_datasource('system'), false, 'customers'))->AddPager(10)->OrderBy = 'id DESC';
 }