<?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

require_once('../models/dao/ManufacuresettingDAO.class.php');
require_once('../models/dto/Manufacuresetting.class.php');
require_once('../models/mysql/ManufacuresettingMySqlDAO.class.php');
require_once('../models/mysql/ext/ManufacuresettingMySqlExtDAO.class.php');


// GOES HERE ....................
include("../public/include_dao.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");
$id = $_GET['id'];
//$id=$_GET['id'];
//here the global templates
$smarty->display("header.html");

//here goes the instances and general variables
$ManufacuresettingDAO = new ManufacuresettingMySqlDAO();
$Manufacuresetting = new Manufacuresetting();
$ManufacuresettingEX = new ManufacuresettingMySqlExtDAO();

//check and use the condetion that suite this action
if (empty($do)) {
    include_once("../public/authentication.php");
    $smarty->display("manufacuresetting/add.html");
} elseif ($do == "add") {
    include_once("../public/authentication.php");
    try {
        add();
        header("location:?do=sucess");
    } catch (Exception $e) {
        //echo $e;
        header("location:?do=error");
    }
} elseif ($do == "show") {
    include_once("../public/authentication.php");
    $allmanufacures = show();
    $smarty->assign("allmanufacures", $allmanufacures);
    $smarty->display("manufacuresetting/show.html");
} elseif ($do == "delete") {
    include_once("../public/authentication.php");
    try {
        delete();
        header("location:?do=sucess");
    } catch (Exception $e) {
        //echo $e;
        header("location:?do=error");
    }
} elseif ($do == "edit") {
    include_once("../public/authentication.php");

    $loadmanfacure = edit();
    $smarty->assign("loadmanfacure", $loadmanfacure);
    $smarty->display("manufacuresetting/edit.html");
} elseif ($do == "update") {
    include_once("../public/authentication.php");
    try {
        update();
        header("location:?do=sucess");
    } catch (Exception $e) {
        //echo $e;
        header("location:?do=error");
    }
} elseif ($do == "sucess") {

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

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

$smarty->assign("customstage", 1);
//here the global templates
$smarty->display("footer.html");
/* ===============================
  function in this CONTROLLER
  ================================ */

function add() {
    global $ManufacuresettingDAO;
    global $Manufacuresetting;
    global $ManufacuresettingEX;


    $manufacurename = $_POST['manufacurename'];
    $manufacuretype = $_POST['manufacuretype'];

    $Manufacuresetting->ordername = $manufacurename;
    $Manufacuresetting->excahangeorder = $manufacuretype;

    $ManufacuresettingDAO->insert($Manufacuresetting);
}

function show() {
    global $ManufacuresettingDAO;
    global $Manufacuresetting;
    global $ManufacuresettingEX;

    $allmanufacures = $ManufacuresettingDAO->queryAll();

    return $allmanufacures;
}

function delete() {
    global $ManufacuresettingDAO;
    global $Manufacuresetting;
    global $ManufacuresettingEX;


    $id = $_GET['id'];
    $ManufacuresettingDAO->delete($id);
}

function edit() {
    global $ManufacuresettingDAO;
    global $Manufacuresetting;
    global $ManufacuresettingEX;

    $id = $_GET['id'];
    $loadmanfacure = $ManufacuresettingDAO->load($id);

    return $loadmanfacure;
}

function update() {
    global $ManufacuresettingDAO;
    global $Manufacuresetting;
    global $ManufacuresettingEX;


    $manufacurename = $_POST['manufacurename'];
    $manufacuretype = $_POST['manufacuretype'];
    $manufacureid = $_POST['settingid'];

    $Manufacuresetting->manufacuresettingid = $manufacureid;
    $Manufacuresetting->ordername = $manufacurename;
    $Manufacuresetting->excahangeorder = $manufacuretype;
    print_r($Manufacuresetting);
    $ManufacuresettingDAO->update($Manufacuresetting);
}
