<?php

// كنترول الموظفين
//
//the global file operation
include("../public/impOpreation.php");

//global varable
global $showoutside;

//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
include("../public/include_dao.php");

require_once('../models/dao/EmployeeDAO.class.php');
require_once('../models/dto/Employee.class.php');
require_once('../models/mysql/EmployeeMySqlDAO.class.php');
require_once('../models/mysql/ext/EmployeeMySqlExtDAO.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');


$do = $_GET['do'];

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

$smarty->display("header.html");


//create object  from employee
$employeeDAO = new EmployeeMySqlDAO();
$employee = new Employee();
$employeeEX = new EmployeeMySqlExtDAO();

$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();



//create object from user
//dispaly  add form
if (empty($do)) {
    include_once("../public/authentication.php");

    if ($_SESSION['branchId'] > 0)
    $queryStringAll = ' AND  branchid = ' . $_SESSION['branchId'];

    $allemployee = $employeeEX->queryAllSimple($queryStringAll);
    $smarty->assign('allemployee', $allemployee);

    $empid = filter_input(INPUT_POST, "chooseEmp");
    $queryString = "";
    if (!empty($empid)) {
        $queryString = " and employeeId =" . $empid;
    }

    if ($_SESSION['branchId'] > 0)
    $queryString = ' AND  branchid = ' . $_SESSION['branchId'];
    $allData = $employeeEX->queryAllSimple($queryString);
    foreach ($allData as $value) {
        if (!empty($value->employeeBOD) && $value->employeeBOD != "0000-00-00") {
            $value->employeeBOD = floor((time() - strtotime($value->employeeBOD)) / (60 * 60 * 24 * 365));
        } else {
            $value->employeeBOD = "";
        }
    }
    $smarty->assign('allData', $allData);
    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);

    $smarty->display("employeereportview/show.html"); //the template page
}
//success
elseif ($_GET['do'] == "sucess") {
    $smarty->display("succes.html");
} elseif ($_GET['do'] == "error") {
    $smarty->display("error.html");
}
$smarty->assign("customValidation", 1);
$smarty->display("footer.html");
?>