示例#1
0
 public function cleanup()
 {
     $productDAO = new ProductDAO(DataSource::getInstance());
     $file_names = $productDAO->findAllPics();
     $c = clean_upload_images($file_names);
     $this->registry->template->deleted_files = $c;
     $this->registry->template->tile_title = 'Dọn dẹp thư mục upload';
     $this->registry->template->tile_content = 'admin/upload-cleanup.php';
     $this->registry->template->show('admin/layout/admin.php');
 }
示例#2
0
 public function delete($id)
 {
     $ps = new PreparedStatement("DELETE FROM categories WHERE id = ?");
     $ps->setInt(1, $id);
     if ($this->ds->execute($ps->getSql())) {
         $productDAO = new ProductDAO($this->ds);
         $productDAO->updateCat($id, 'NULL');
         return TRUE;
     }
     return FALSE;
 }
示例#3
0
 public function index()
 {
     if (empty($_GET['seo_url'])) {
         $this->notFound();
         return;
     }
     $productDAO = new ProductDAO(DataSource::getInstance());
     $product = $productDAO->findBySeoUrl($_GET['seo_url']);
     if (!$product) {
         $this->notFound();
         return;
     }
     $categoryDAO = new CatDAO(DataSource::getInstance());
     $brandDAO = new BrandDAO(DataSource::getInstance());
     $cat_id = $product['category_id'];
     $brand_id = $product['brand_id'];
     $categories_list = $categoryDAO->findByAll_Navigation();
     $brands_list = $brandDAO->findByAll();
     $products_list_in_cat = $productDAO->findByCatId($cat_id);
     $products_list_in_brand = $productDAO->findByBrandId($brand_id);
     $promoDAO = new PromoDAO(DataSource::getInstance());
     $this->registry->template->promo_seo_url_newest = $promoDAO->findNewestSeoUrl();
     $this->registry->template->cart = getCart();
     $this->registry->template->categories_list = $categories_list;
     $this->registry->template->brands_list = $brands_list;
     $this->registry->template->current_cat_id = $cat_id;
     $this->registry->template->current_brand_id = $brand_id;
     $this->registry->template->products_list_in_cat = $products_list_in_cat;
     $this->registry->template->products_list_in_brand = $products_list_in_brand;
     $this->registry->template->product = $product;
     $this->registry->template->product_pics = explode_pics($product['pics']);
     $this->registry->template->tile_title = $categories_list[$cat_id]['name'] . ' / ' . $brands_list[$brand_id] . ' / ' . $product['code'];
     $this->registry->template->facebook_description = $product['description'];
     $this->registry->template->facebook_image = __SITE_CONTEXT . __UPLOAD_DIR . get_pic_at($product['pics'], 1);
     $this->registry->template->body_class = 'product-template';
     $this->registry->template->tile_content = 'product.php';
     $this->registry->template->tile_footer = 'footer.php';
     $this->registry->template->show('layout/user.php');
 }
示例#4
0
function loadProducts()
{
    $products = ProductDAO::getProducts();
    echo "<center><h1>.:Productos:.</h1><br>";
    echo "<table border=\"3px\">";
    foreach ($products as $product) {
        if ($product->getStock() > 0) {
            echo "<tr>";
            //create row
            echo "<td>\n\t\t\t\t\t\t\t\t<img src=\"../imagens/" . $product->getImage() . "\" alt=\"product image\" width=\"600px\" height=\"400px\"\\><br>\n\t\t\t\t\t\t\t\t<a href=\"Buy.php?barcode=" . $product->getBarcode() . "&expiration=" . $product->getExpiration() . "\">mostrar informacion</a><br>\n\t\t\t\t\t\t\t\t</td>";
            echo "</tr>";
        }
    }
    echo "</table></center>";
}
 /**
  * ProductOption constructor.
  * @param int $id
  * @param Product $product
  * @param Option $option
  * @param Option $parentOption
  * @param bool $required
  * @param int $afcId
  * @param bool $loadValues Defines whether option values should be loaded from DB or not
  */
 public function __construct($id, $product, $option, $parentOption, $required, $afcId, $loadValues = true)
 {
     $this->id = $id;
     $this->product = $product;
     $this->option = $option;
     $this->parentOption = $parentOption;
     $this->required = $required;
     $this->afcId = $afcId;
     if ($loadValues) {
         $this->value = ProductDAO::getInstance()->getProductOptionValues($this);
     } else {
         if ($this->getOption()->isMultiValueType()) {
             $this->value = new ProductOptionValueCollection();
         }
     }
 }
 function getProducts()
 {
     $dao = new ProductDAO();
     return $dao->listProducts();
 }
示例#7
0
function displaydevices($category_id, $specification_id)
{
    $product_dao = new ProductDAO();
    $products = $product_dao->findByCategoryAndSpecification($category_id, $specification_id);
    ?>
	<div class="table-responsive">
    	<table class="table table-hover table-bordered"">
    		<thead>
        	<tr>
            	<th></th>
				<th><?php 
    echo t('Serial number');
    ?>
</th>
				<th><?php 
    echo t('Purchase price');
    ?>
</th>
				<th><?php 
    echo t('Periodical discount');
    ?>
</th>
            	<th><?php 
    echo t('Brand');
    ?>
</th>
            	<th><?php 
    echo t('Model');
    ?>
</th>
            	<th><?php 
    echo t('Classification');
    ?>
</th>
            	<th><?php 
    echo t('Consumption');
    ?>
</th>
            	<th><?php 
    echo t('Description');
    ?>
</th>
        	</tr>
        	</thead>
	<?php 
    //display the devices data in a table
    foreach ($products as $product) {
        ?>
       <tr <?php 
        echo 'data-href="?action&category=' . $category_id . '&specification=' . $specification_id . '&product_id=' . $product->id . '"';
        ?>
 >
            <td><img height="150" width="150" src="data:image;base64,<?php 
        echo $product->image;
        ?>
"></td>
    <?php 
        foreach (['serial_number', 'purchase_price', 'periodical_discount', 'brand', 'model', 'classification', 'consumption', 'description'] as $property_name) {
            ?>
            <td><?php 
            echo $product->{$property_name};
            ?>
</td>
            <?php 
        }
        ?>
        </tr>
	<?php 
    }
    ?>
    	</table>
    </div>

<?php 
}
示例#8
0
<?php

include '../modelo/ProductDAO.php';
if ($_POST['removeProduct']) {
    if ($_POST['haveExpiration'] == "no") {
        $expiration = "0000-00-00";
    } else {
        $expiration = $_POST['expiration'];
    }
    $product = ProductDAO::getProduct($_POST['barcode'], $expiration);
    unlink("../imagens/" . $product->getImage());
    if (ProductDAO::removeProduct($_POST['barcode'], $expiration) != false) {
        echo "product removed succefull<br>";
    } else {
        echo "error removing product<br>";
    }
}
示例#9
0
 public function sortSave()
 {
     $list_id_str = $_POST['listIdSort'];
     $productDAO = new ProductDAO(DataSource::getInstance());
     if ($productDAO->resort($list_id_str)) {
         echo '0';
     } else {
         echo '1';
     }
 }
示例#10
0
 public function parseProducts()
 {
     $products = new Products();
     $keyParams = array();
     $currencies = $this->parseCurrencies();
     $measurements = $this->parseMeasurements();
     foreach ($this->xmlProducts as $xmlProduct) {
         $code = $xmlProduct->getCode();
         $name = $xmlProduct->getName();
         $isAGroup = $xmlProduct->isAGroup();
         $articul = $xmlProduct->getArticul();
         $basicMeasurementUnitCode = $xmlProduct->getBasicMeasurementUnit();
         $basicMeasurementUnit = $measurements->getUnitByCode($basicMeasurementUnitCode);
         $price = $xmlProduct->getPrice();
         $currencyCode = $xmlProduct->getCurrency();
         $currency = $currencies->getUnitByCode($currencyCode);
         $measurementUnitCode = $xmlProduct->getBasicMeasurementUnit();
         $measurementUnit = $measurements->getUnitByCode($measurementUnitCode);
         if (!empty($code) && !in_array($code, $keyParams)) {
             array_push($keyParams, $code);
             $product = new Product();
             $product->setIsAGroup($isAGroup);
             $product->setCode($code);
             $product->setName($name);
             $product->setArticul($articul);
             $product->setBasicMeasurementUnit($basicMeasurementUnit);
             $product->setPrice($price);
             $currency == null ? '' : $product->setCurrency($currency);
             $measurementUnit == null ? '' : $product->setMeasurementUnit($measurementUnit);
             $products->setItem($product);
         }
     }
     $categories = $this->parseCategories();
     foreach ($this->xmlProducts as $xmlProduct) {
         $catCode = $xmlProduct->getCategoryCode();
         $code = $xmlProduct->getCode();
         $current = $products->getItemByCode($code);
         $parent = $categories->getItemByCode($catCode);
         if ($parent != null) {
             $current->setParent($parent);
         }
     }
     $productDAO = new ProductDAO();
     $productDAO->insertItems($products);
     return $products;
 }
示例#11
0
<?php

require '../../include/global_functions.php';
loggedInOrRedirect();
$language_fields_addition = $_SESSION['language'] == 'en_US' ? '' : '_' . $_SESSION['language'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $image = base64_encode(file_get_contents($_FILES['image']['tmp_name']));
    $daoprod = new ProductDAO();
    //We insert the product in the database
    $resprod = $daoprod->insert($_POST["category"], $_POST["specification"], $_POST['serial_number'], $_POST['purchase_price'], $_POST['periodical_discount'], $_POST['brand'], $_POST['model'], $_POST['classification'], $_POST['cost'], $_POST['consumption'], $_POST['release_year'], $_POST['description'], $image);
}
?>

<script type="text/javascript">
<!-- This function display the specifications according to the category choose -->
function displayspecification(category_id) {

	var xhttp = new XMLHttpRequest();
	  xhttp.onreadystatechange = function() {
	    if (xhttp.readyState == 4 && xhttp.status == 200) {
	      document.getElementById("specification").innerHTML = xhttp.responseText;
	    }
	  }

	  xhttp.open("GET", "../getspecification.php?idcategory="+category_id, true);
	  xhttp.send();
}
</script>
<?php 
$category_dao = new CategoryDAO();
$categories = $category_dao->getAllCategories();
示例#12
0
 public static function getProductFromId($id)
 {
     $arrProduct = ProductDAO::getProductFromId($id);
     return $arrProduct;
 }
示例#13
0
function displaydevices($category_id, $specification_id)
{
    //select all the devices according to the category and the specification
    $daoprod = new ProductDAO();
    $resprod = $daoprod->findByCategoryAndSpecification($category_id, $specification_id);
    //if the query has no product, we show a error message
    if (!$resprod) {
        echo '<span class="text-danger">*' . t('No result found') . '</span>';
    }
    ?>
	<form action="?<?php 
    echo 'idcategory=' . $category_id . '&idspecification=' . $specification_id;
    ?>
" method="POST">
		<table class="table table-bordered">
			<tr>
				<th></th>
				<th></th>
				<th><?php 
    echo t('Serial number');
    ?>
</th>
				<th><?php 
    echo t('Purchase price');
    ?>
</th>
				<th><?php 
    echo t('Discount');
    ?>
</th>
            	<th><?php 
    echo t('Brand');
    ?>
</th>
            	<th><?php 
    echo t('Model');
    ?>
</th>
            	<th><?php 
    echo t('Classification');
    ?>
</th>
            	<th><?php 
    echo t('Electricity cost');
    ?>
</th>
            	<th><?php 
    echo t('Consumption');
    ?>
</th>
            	<th><?php 
    echo t('Release year');
    ?>
</th>
            	<th><?php 
    echo t('Description');
    ?>
</th>
			</tr>
		<?php 
    //display the devices
    foreach ($resprod as $product) {
        ?>
	                <tr>
	                	<!-- create a radiobutton for each row and put the productid as the value
	                    it will be useful when the users wants to delete or modify a product -->
	                    <td><input type="radio" name="radioval" value="<?php 
        echo $product->id;
        ?>
"></td>
	                	<!-- image not implement yet -->
	                	<td><img height="150" width="150" src="data:image;base64,<?php 
        echo $product->image;
        ?>
"></td>
	                	<td><?php 
        echo $product->serial_number;
        ?>
</td>
	                	<td><?php 
        echo $product->purchase_price;
        ?>
</td>
	                	<td><?php 
        echo $product->periodical_discount;
        ?>
</td>
	                    <td><?php 
        echo $product->brand;
        ?>
</td>
	                    <td><?php 
        echo $product->model;
        ?>
</td>
	                    <td><?php 
        echo $product->classification;
        ?>
</td>
	                    <td><?php 
        echo $product->cost;
        ?>
</td>
	                    <td><?php 
        echo $product->consumption;
        ?>
</td>
	                    <td><?php 
        echo $product->release_year;
        ?>
</td>
	                    <td><?php 
        echo $product->description;
        ?>
</td>
	                </tr>
	             <?php 
    }
    ?>
		</table>
		<br>
		<button class="btn btn-primary" type="submit" name="action" value="Modify"><?php 
    echo t('Modify');
    ?>
</button>
		<button class="btn btn-primary" type="submit" name="action" value="Delete"><?php 
    echo t('Delete');
    ?>
</button>
	</form>
<?php 
}
示例#14
0
<?php

require '../include/global_functions.php';
startSession();
//Select the new product for the comparison according to the id
$product_dao = new ProductDAO();
$new_product = $product_dao->find($_SESSION['new_product_id']);
$old_product = new Product();
$language_fields_addition = $_SESSION['language'] == 'en_US' ? '' : '_' . $_SESSION['language'];
if (!isset($_COOKIE['uniqueID'])) {
    $expire = time() + 10 * 365 * 24 * 60 * 60;
    setcookie('uniqueID', uniqid(), $expire);
}
if (isset($_GET['action'])) {
    $purchase_dao = new PurchaseDAO();
    $respurchase = $purchase_dao->insert($_SESSION['new_product_id'], $_SERVER['REQUEST_TIME'], $_COOKIE['uniqueID']);
}
if (isset($_SESSION['old_product_id'])) {
    if ($_SESSION['old_product_id'] != 0) {
        $old_product = $product_dao->find($_SESSION['old_product_id']);
        $old_product->release_year = $_SESSION['purchase_year'];
    } else {
        $old_product->release_year = $_SESSION['purchase_year'];
        $old_product->purchase_price = $_SESSION['old_puchase_price'];
        $old_product->consumption = $_SESSION['old_energy_consumption'];
    }
}
function remainingLifetime($product)
{
    date_default_timezone_set('Europe/Bucharest');
    $currentYear = date('Y');
示例#15
0
<?php

include '../modelo/ProductDAO.php';
function upgradeImage()
{
    $path = "../imagens/";
    $path .= basename($_FILES['image']['name']);
    if (move_uploaded_file($_FILES['image']['tmp_name'], $path)) {
        echo "file " . basename($_FILES['image']['name']) . " was uploaded<br>";
    } else {
        exit("file " . basename($_FILES['image']['name']) . " NOT was uploaded<br>");
    }
}
if ($_POST['addProduct']) {
    if ($_POST['haveExpiration'] == "no") {
        $expiration = "";
    } else {
        $expiration = $_POST['expiration'];
    }
    upgradeImage();
    $product = new Product($_POST['barcode'], $_POST['saleType'], $_POST['name'], $_POST['buyPrice'], $_POST['salePrice'], $_POST['description'], $expiration, basename($_FILES['image']['name']), $_POST['stock']);
    if (ProductDAO::addProduct($product) != false) {
        echo "product added succeful<br>";
    } else {
        echo "error adding product<br>";
    }
}
示例#16
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 {
示例#17
0
<?php

require '../../include/global_functions.php';
loggedInOrRedirect();
$product_dao = new ProductDAO();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (file_exists($_FILES['image']['tmp_name']) && is_uploaded_file($_FILES['image']['tmp_name'])) {
        $image = base64_encode(file_get_contents($_FILES['image']['tmp_name']));
    } else {
        $image = '';
    }
    //update the product
    $product_dao->updateproduct($_GET['idproduct'], $_GET['idcategory'], $_GET['idspecification'], $_POST['serial_number'], $_POST['purchase_price'], $_POST['periodical_discount'], $_POST['brand'], $_POST['model'], $_POST['classification'], $_POST['cost'], $_POST['consumption'], $_POST['release_year'], $_POST['description'], $image);
    header('Location: manage_products.php?&idcategory=' . $_GET['idcategory'] . '&idspecification=' . $_GET['idspecification']);
}
//Select the product according to the id
$product = $product_dao->find($_GET['idproduct']);
$page['title'] = 'Modify product';
require '../../include/header.inc';
require '../../include/index.inc';
?>
<h3><?php 
echo t('Modify product');
?>
</h3>
<form class="form-horizontal" action = "?<?php 
echo 'idproduct=' . $_GET['idproduct'] . '&idcategory=' . $_GET['idcategory'] . '&idspecification=' . $_GET['idspecification'];
?>
" method="POST" enctype="multipart/form-data">

	<div class="form-group">
示例#18
0
<?php

include '../modelo/Sale.php';
session_start();
if ($_GET['barcode'] != "null") {
    $productToAdd = ProductDAO::getProduct($_GET['barcode'], $_GET['expiration']);
    ProductDAO::setStock($_GET['barcode'], $_GET['expiration'], $productToAdd->getStock() - 1);
    //		$productToAdd->setStock($productToAdd->getStock()-1);
    if (isset($_SESSION['buyCar'])) {
        $sale = $_SESSION['buyCar'];
        $sale->addProductToBuyCar($productToAdd);
    } else {
        $sale = new Sale($_SESSION['user']);
        $sale->addProductToBuyCar($productToAdd);
        $_SESSION['buyCar'] = $sale;
    }
}
?>
<!DOCTYPE html>
<html>
	<head>
		<link rel="stylesheet" type="text/css" src="../vista/styles.css">
		<title>Product</title>
		<script type="text/javascript" src="../vista/s"></script>
	</head>
	<body>
		<header>
			<h1>
				<?php 
echo $_SESSION['user'];
?>