<?php

//the global file operation
include("../public/impOpreation.php");

//to check if the page from .htacess
//$showoutside = $_GET['sn'];
// get the config file
include_once("../public/config.php");


//here the db files that include in the file
// GOES HERE ....................
include("../public/include_dao.php");


//Product
require_once('../models/dao/ProductDAO.class.php');
require_once('../models/dto/Product.class.php');
require_once('../models/mysql/ProductMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductMySqlExtDAO.class.php');

require_once('../models/dao/YoutubeLinkDAO.class.php');
require_once('../models/dto/YoutubeLink.class.php');
require_once('../models/mysql/YoutubeLinkMySqlDAO.class.php');
require_once('../models/mysql/ext/YoutubeLinkMySqlExtDAO.class.php');



//get the do the action
$do = $_GET['do'];

$langs = $_SESSION['erp_lang'];
include_once("../views/languages/$langs/success.php");
include_once("../views/languages/$langs/error.php");

/* ======================
  Controller Name :-storeCTRL
  ======================== */

//here the global templates
$smarty->display("header.html");
//Product
$product = new Product();
$productDAO = new ProductMySqlDAO();
$productEX = new ProductMySqlExtDAO();
//Store
$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();
//check and use the condetion that suite this action
if ($do == "cat") {
    //here the permssion check
    include_once("../public/authentication.php");
    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);


    $result = $productEX->runSelectQuery('select count(*) as productId from productcat where conditions = 0 ');
    $smarty->assign('notDelCount', $result[0]->productId);
    $result = $productEX->runSelectQuery('select count(*) as productId from productcat where conditions = 0 and logo != "." and logo != "" and logo != "no image" ');
    $smarty->assign('withImageCount', $result[0]->productId);
    $result = $productEX->runSelectQuery('select count(*) as productId from productcat where conditions = 0 and productCatDescription != "" ');
    $smarty->assign('withDescription', $result[0]->productId);
    $result = $productEX->runSelectQuery('select count(*) as productId from productcat where conditions = 0 and productCatDescription != "" and logo != "." and logo != "" and logo != "no image" ');
    $smarty->assign('withImageAndDescription', $result[0]->productId);


    //here the smarty templates
    $smarty->display("catandproductstatisticsview/cat.html");
} elseif ($do == "pro") {
    //here the permssion check
    include_once("../public/authentication.php");

    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);

    $result = $productEX->runSelectQuery('select count(*) as productId from product where conditions = 0 ');
    $smarty->assign('notDelCount', $result[0]->productId);
    $result = $productEX->runSelectQuery('select count(*) as productId from product where conditions = 0 and logo != "." and logo != "" and logo != "no image" ');
    $smarty->assign('withImageCount', $result[0]->productId);
    $result = $productEX->runSelectQuery('select count(*) as productId from product where conditions = 0 and productDescription != "" ');
    $smarty->assign('withDescription', $result[0]->productId);
    $result = $productEX->runSelectQuery('select count(*) as productId from product where conditions = 0 and productDescription != "" and logo != "." and logo != "" and logo != "no image" ');
    $smarty->assign('withImageAndDescription', $result[0]->productId);


    //here the smarty templates
    $smarty->display("catandproductstatisticsview/pro.html");
} elseif ($do == "sucess") {

    //here the smarty templates
    $smarty->display("succes.html");
} elseif ($do == "error") {

    //here the smarty templates
    $smarty->display("error.html");
}

$smarty->assign("customValidation", 1);

//here the global templates
$smarty->display("footer.html");

/* ===============================
  function in this CONTROLLER
  ================================ */
?>