public function __construct($parameter) { if (isset($_SESSION['user'])) { if (isset($_GET['ordersubmitted'])) { //write order to db $customer = unserialize($_SESSION['user']); $cart = unserialize($_SESSION['cart']); $id = $customer->__get('id'); //create json array for order-entry $products = []; foreach ($cart->getProducts() as $product) { $products[] = array($product->__get('number'), $product->__get('amount'), $product->__get('selectedoption')); } $products = json_encode($products); $db = DatabaseController::getInstance(); $mysqli = $db->getConnection(); $sql_query = "INSERT INTO `product_order` (`customer_id`, `order_products`) VALUES ('{$id}', '{$products}');"; $mysqli->query($sql_query); $mysqli->commit(); //send email to admin and customer //mail("*****@*****.**", "Bestellung", "Jemand hat eine Bestellung getÃĪtigt" ); mail($customer->__get('email'), "Your Order", "Hello " . $customer->__get('firstname') . " " . $customer->__get('lastname') . "\n\n Thanks for your Order!\n You have ordered " . $cart->count() . " Product(s) with a total price of CHF " . $cart->getCartBalance() . ".\nYou'll never get it HAHAHA. \n\n Best wishes\nYour myshop Team"); //unset cart unset($_SESSION['cart']); $this->view = new OrderCompleteView(); } else { $this->view = new CheckoutView(); } } else { $_SESSION['checkout'] = 1; $this->view = new LoginView(); } $langselect = new LanguageView(null); $langselect->render(); }
public function __construct($parameter) { if (isset($_SESSION['user'])) { //logout if logout link is called if ($parameter[1] == "logout") { $this->view = new LoginView(); $this->logout(); } else { $this->view = new CustomerView(unserialize($_SESSION['user'])); } } else { if (isset($_POST["login"]) && isset($_POST["password"])) { $username = $_POST["login"]; $password = $_POST["password"]; $this->view = new LoginView(); //authenticate if ($this->login($username, $password)) { //if checkout was startet, but not logged in if (isset($_SESSION['checkout']) && $_SESSION['checkout'] == 1) { $this->view = new CheckoutView(); } else { $this->view = new CustomerView(unserialize($_SESSION['user'])); } } } else { $this->view = new LoginView(); } } $langselect = new LanguageView($this->model); $langselect->render(); }
public function __construct() { if (isset($_SESSION['user'])) { $this->view = new CustomerView(unserialize($_SESSION['user'])); } else { $this->view = new LoginView(); } $langselect = new LanguageView(null); $langselect->render(); }
public function __construct($parameter) { $this->parameter = $parameter; if (isset($_POST['reggo']) && $_POST['reggo'] == 1) { $this->registerCustomer(); $this->view = new LoginView(); } else { $this->view = new RegisterView(); } $langselect = new LanguageView(null); $langselect->render(); }
public function __construct($parameter) { $cart = unserialize($_SESSION['cart']); // set variables if (isset($parameter[2])) { $action = $parameter[2]; } if (isset($parameter[3])) { $productnr = $parameter[3]; $uid = $parameter[3]; } if (isset($parameter[4])) { $amount = $parameter[4]; } if (isset($parameter[5])) { $option = $parameter[5]; } //update if (!empty($action) && $action == "update" && !empty($uid) && !empty($amount)) { $cart->update($uid, $amount); } //delete if (!empty($action) && $action == "delete" && !empty($uid)) { $cart->remove($uid); } //add if (!empty($action) && $action == "add") { //connect to db and get productid $db = DatabaseController::getInstance(); $mysqli = $db->getConnection(); $sql_query = "SELECT `product_id` FROM `product` WHERE `product_number` = '" . $productnr . "';"; if ($result = $mysqli->query($sql_query)) { $product_id = $result->fetch_array(); $product_id = $product_id['product_id']; } else { $product_id = 1; } //create new product for cart and update its values according selection $newproduct = new Product($product_id); $newproduct->__set('selectedoption', $option); $newproduct->updateUid(); $newproduct->__set('amount', $amount); $cart->add($newproduct); } $_SESSION['cart'] = serialize($cart); $this->view = new CartView($cart); $langselect = new LanguageView(null); $langselect->render(); }
public function __construct($parameter) { $nicename = $parameter[1]; //connect to db and get pageid $db = DatabaseController::getInstance(); $mysqli = $db->getConnection(); $sql_query = "SELECT `page_id` FROM `pages` WHERE `nicename` = '" . $nicename . "' AND `hidden` != 1;"; $result = $mysqli->query($sql_query); $page_id = $result->fetch_array(); $page_id = $page_id['page_id']; //change language to language of selected page $page = new Page($page_id); $this->view = new PageView($page); $this->model = $page; $langselect = new LanguageView($this->model); $langselect->render(); }
public function __construct($parameter) { if (!isset($parameter[2])) { $product_id = 1; } else { //connect to db and get productid $db = DatabaseController::getInstance(); $mysqli = $db->getConnection(); $sql_query = "SELECT `product_id` FROM `product` WHERE `product_nicename` = '" . $parameter[2] . "' AND `hidden` != 1;"; if ($result = $mysqli->query($sql_query)) { $product_id = $result->fetch_array(); $product_id = $product_id['product_id']; } else { $product_id = 1; } } $product = new Product($product_id); $this->view = new SingleProductView($product); $this->model = $product; $langselect = new LanguageView($product); $langselect->render(); }
public function __construct() { $this->view = new ContactView(); $langselect = new LanguageView(null); $langselect->render(); }
public function __construct() { $langselect = new LanguageView(null); $langselect->render(); }
public function renderView() { foreach ($this->model->getUris() as $key => $value) { if (preg_match("#^{$value}\$#", $this->uriView)) { if ($this->model->getView($key) === "PageView") { //connect to db and get pageid $db = DatabaseController::getInstance(); $mysqli = $db->getConnection(); $sql_query = "SELECT `page_id` FROM `pages` WHERE `nicename` = '" . str_replace('/', '', $value) . "' AND `hidden` != 1;"; $result = $mysqli->query($sql_query); $page_id = $result->fetch_array(); $page_id = $page_id['page_id']; //change language to language of selected page $page = new Page($page_id); $view = new PageView($page); $langselect = new LanguageView($page); $langselect->render(); } else { if ($this->model->getView($key) === "ProductView") { $products = new Products(); $view = new ProductView($products); } else { if ($this->model->getView($key) === "SingleProductView") { $params = $this->additionalParam; if (!isset($params[2])) { $product_id = 1; } else { //connect to db and get pageid $db = DatabaseController::getInstance(); $mysqli = $db->getConnection(); $sql_query = "SELECT `product_id` FROM `product` WHERE `product_nicename` = '" . $params[2] . "' AND `hidden` != 1;"; if ($result = $mysqli->query($sql_query)) { $product_id = $result->fetch_array(); $product_id = $product_id['product_id']; } else { $product_id = 1; } } $product = new Product($product_id); $view = new SingleProductView($product); $langselect = new LanguageView($product); $langselect->render(); } else { if ($this->model->getView($key) === "LoginView") { if (isset($_SESSION['user'])) { //logout if logout link is called if (str_replace('/', '', $value) == "logout") { $view = new LoginView(); $controller = new LoginController($view); $controller->logout(); } else { $view = new CustomerView(unserialize($_SESSION['user'])); } } else { if (isset($_POST["login"]) && isset($_POST["password"])) { $username = $_POST["login"]; $password = $_POST["password"]; $view = new LoginView(); $controller = new LoginController($view); //authenticate if ($controller->login($username, $password)) { $view = new CustomerView(unserialize($_SESSION['user'])); } } else { $view = new LoginView(); } } } else { if ($this->model->getView($key) === "CustomerView") { if (isset($_SESSION['user'])) { $view = new CustomerView(unserialize($_SESSION['user'])); } else { $view = new LoginView(); } } else { if ($this->model->getView($key) === "CartView") { if (isset($_SESSION['cart'])) { $cart = unserialize($_SESSION['cart']); $params = $this->additionalParam; //update article if (isset($params[2])) { $action = $params[2]; } if (isset($params[3])) { $productnr = $params[3]; } if (isset($params[4])) { $newamount = $params[4]; } if (!empty($action) && $action == "update" && !empty($productnr) && !empty($newamount)) { $cart->update($productnr, $newamount); } if (!empty($action) && $action == "delete" && !empty($productnr)) { $cart->remove($productnr); } $_SESSION['cart'] = serialize($cart); $view = new CartView($cart); } else { $cart = new Cart(); //test-data $cart->add(new Product(1)); $cart->add(new Product(2)); $cart->add(new Product(3)); $cart->add(new Product(4)); //$cart->remove(10001); $_SESSION['cart'] = serialize($cart); $view = new CartView($cart); } } else { $useView = $this->model->getView($key); $view = new $useView(); } } } } } } $view->render(); } } }