public function genupdAction() { $generic = new Model_Generic(); $table = $this->_getParam('tbl'); $key_name = $this->_getParam('kn'); $key_value = $this->_getParam('kv'); $knkv = array('kn' => $key_name, 'kv' => $key_value, 'tbl' => $table); $this->view->knkv = $knkv; $cond = $key_name . "=" . $key_value; $data = $generic->getData($table, $cond); $this->view->data = $data; $this->view->table_properties = $generic->tableProperties($table); // if form is submiited if ($_POST) { $newdata = $_POST; $key = $cond; // update data $genupd = $generic->updateData($table, $newdata, $key); $this->_redirect('/encoder/genform/tbl/' . $table); } }
public function productscreateAction() { $generic = new Model_Generic(); $generic_call = $generic->genericForm("Products"); $this->view->genform = $generic_call; $product_data = array(); if ($_POST) { foreach ($_POST as $key => $val) { if ($key != 'BrandID' && $key != 'CategoryID' && $key != 'Price' && $key != 'DiscPrice' && $key != 'WholePrice' && $key != 'DiscRate' && $key != 'Quantity' & $key != 'Minimum') { $product_data[$key] = $val; } } //1. Create Product $product_data['URLSegment'] = Model_Page::urlFriendly($_POST['Name']); if (isset($_POST['ProductID'])) { //update $product_id = $_POST['ProductID']; unset($product_data['ProductID']); $generic->updateData("Products", $product_data, "ID=" . $product_id); } else { $product_id = $generic->insertData("Products", $product_data); } //2. Create Price Relations $price_data = array(); $price_data['Created'] = $_POST['Created']; $price_data['LastEdited'] = $_POST['LastEdited']; $price_data['ProductID'] = $product_id; $price_data['Currency'] = 'USD'; // we'll set this to USD for now $price_data['Price'] = $_POST['Price']; $price_data['WholePrice'] = $_POST['WholePrice']; $price_data['DiscPrice'] = $_POST['DiscPrice']; $price_data['DiscRate'] = $_POST['DiscRate']; if (isset($_POST['ProductID'])) { $generic->oldSkul("delete from Prices where ProductID =" . $product_id, false); $price = $generic->insertData("Prices", $price_data); } else { $price = $generic->insertData("Prices", $price_data); } //3. Create Store Data $store_data = array(); $store_data['ProductID'] = $product_id; //$store_data['CategoryID'] = 0; $store_data['BrandID'] = $_POST['BrandID']; $store_data['Quantity'] = $_POST['Quantity']; $store_data['Minimum'] = $_POST['Minimum']; if (isset($_POST['ProductID'])) { $generic->oldSkul("delete from Store where ProductID =" . $product_id, false); $store = $generic->insertData("Store", $store_data); } else { $store = $generic->insertData("Store", $store_data); } //4. Create Category Relations //See productscategoriesAction $this->_redirect('/admin/productsdisplay/pid/' . $product_id . '/?sysmsg=success'); } $this->view->data = array(); $this->view->Brands = $generic->getData("Brands", "", "Name"); $this->view->Categories = $generic->getData("Category", "", "Name asc"); }