Esempio n. 1
0
<?php

require '../include/global_functions.php';
startSession();
$language_fields_addition = $_SESSION['language'] == 'en_US' ? '' : '_' . $_SESSION['language'];
//select all the categories in the database
$category_dao = new CategoryDAO();
$categories = $category_dao->getAllCategories();
$specification_dao = new SpecificationDAO();
if (isset($_GET['path'])) {
    $_SESSION['path_selection'] = 'choose old device';
}
if (isset($_GET['action'])) {
    $product_dao = new ProductDAO();
    if ($_GET['action'] == 'Search') {
        $product = $product_dao->findBySerialNumber($_GET['serial_number']);
    }
    if ($_GET['action'] == 'Select your new device' || $_GET['action'] == 'Compare') {
        if ($_GET['modelchoice'] == 'yes') {
            $product = $product_dao->findOldProduct($_GET['category'], $_GET['specification'], $_GET['brand'], $_GET['model']);
        } else {
            //put the average consumption of all the products according to the category in a session
            $_SESSION['old_energy_consumption'] = $product_dao->avgconsumptionByCategory($_GET['category']);
            //put the average price of all the products according to the category in a session
            $_SESSION['old_puchase_price'] = $product_dao->avgPriceByCategory($_GET['category']);
            $_SESSION['purchase_year'] = $_GET['purchase_year'];
            $_SESSION['old_product_id'] = 0;
            //if the user chose to select his old device first, we redirect him in the page new_device.php so he can select his new device
            if ($_SESSION['path_selection'] == 'choose old device') {
                header('Location: new_device.php?category=' . $_GET['category'] . '&specification=' . $_GET['specification']);
            } else {