HEX
Server: Apache
System: Linux server1.royalgt4.com 4.18.0-553.89.1.lve.el8.x86_64 #1 SMP Wed Dec 10 13:58:50 UTC 2025 x86_64
User: mostafedeg (1125)
PHP: 5.6.40
Disabled: mail,passthru,parse_ini_file,show_source,eval,assert,pcntl_exec,dl,putenv,proc_open,popen
Upload Files
File: /home/mostafedeg/public_html/erp/controllers/typeSupplierController.php
<?php

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

// get the config file
include_once("../public/config.php");

//here the db files that include in the file
include("../public/include_dao.php");
include("../library/uploadImages.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");
//here the global templates
$smarty->display("header.html");
//$smarty->display("maintennanceHeader.html");
//here goes the instances and general variables
//Typesupplier
require_once('../models/dao/TypesupplierDAO.class.php');
require_once('../models/dto/Typesupplier.class.php');
require_once('../models/mysql/TypesupplierMySqlDAO.class.php');
require_once('../models/mysql/ext/TypesupplierMySqlExtDAO.class.php');

//Productcat
require_once('../models/dao/ProductcatDAO.class.php');
require_once('../models/dto/Productcat.class.php');
require_once('../models/mysql/ProductcatMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductcatMySqlExtDAO.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');
//check and use the condetion that suite this action
//typeSupplier
$typeSupplier = new Typesupplier();
$TypeSupplierDAO = new TypesupplierMySqlDAO();
$TypeSupplierEX = new TypesupplierMySqlExtDAO();

//Productcat
$productCat = new Productcat();
$productCatDAO = new ProductcatMySqlDAO();
$productCatExt = new ProductcatMySqlExtDAO();

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


if (empty($do)) {

    include_once("../public/authentication.php");

    //get product categories
    $allParents = getProductCatParents();
    $smarty->assign("allParents", $allParents);

    $smarty->display("typeSupplierview/add.html");
    //date
} elseif ($do == "add") {
    // include_once("../public/authentication.php");
    include_once("../public/authentication.php");
    //add();
    try {
        // here the function that do the action
        add();
        header("location:?do=sucess");
    } catch (Exception $e) {
//        var_dump($e);
        header("location:?do=error");
    }
} elseif ($do == "show") {
    include_once("../public/authentication.php");

    $allbranches = show();

    $smarty->assign("allbranches", $allbranches);

    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);
    $smarty->display("typeSupplierview/show.html");
}

//edit
elseif ($do == "edit") {

    include_once("../public/authentication.php");
    $allParents = getProductCatParents();
    $smarty->assign("allParents", $allParents);

    $alldata = edit();
    $smarty->assign("alldata", $alldata);
    $smarty->display("typeSupplierview/edit.html");
} elseif ($do == "editprint") {

    include_once("../public/authentication.php");
    $alldata = edit();
    $smarty->assign("alldata", $alldata);
    //print_r($alldata);
    $smarty->display("typeSupplierview/editprint.html");
} elseif ($do == "update") {


    include_once("../public/authentication.php");

    try {
        // here the function that do the action
        update();
        header("location:?do=sucess");
    } catch (Exception $e) {
//        echo $e;
        header("location:?do=error");
    }
} elseif ($do == "delete") {


    include_once("../public/authentication.php");
    //add();
    try {
        // here the function that do the action
        delete();
        header("location:?do=sucess");
    } catch (Exception $e) {
        header("location:?do=error");
    }
} elseif ($do == "sucess") {

    //here the smarty templates
    $smarty->display("succes.html");
}elseif ($do == "returndelete") {//returndelete
    include_once("../public/authentication.php");
    try {
        $note = returndelete();
        if ($note != "success") {
            $smarty->assign('msgnote', $note);
            $smarty->display("notes.html");
        } else {
            header("location:?do=sucess");
        }
    } catch (Exception $e) {
        header("location:?do=error");
    }
}elseif ($do == "tempdelete") {//tempdelete
    include_once("../public/authentication.php");
    try {
        $note = tempdelete();
        if ($note != "success") {
            $smarty->assign('msgnote', $note);
            $smarty->display("notes.html");
        } else {
            header("location:?do=sucess");
        }
    } catch (Exception $e) {
        header("location:?do=error");
    }
}elseif ($do == "error") {

    //here the smarty templates
    $smarty->display("error.html");
}
$smarty->assign("clientPremium", 1);
//$smarty->assign("GeneralSearch", 1);
$smarty->display("footer.html");

////****************************  Functions  ********************///

/* ===============================
  function in this CONTROLLER
  ================================ */


function add() {
    global $typeSupplier;
    global $TypeSupplierDAO;
    global $productCatDAO;

    $typename = $_POST['typename'];
    $comments = $_POST['comments'];
//    $category_id = implode(',', $_POST['category_id']);

    $typeSupplier->typeName = $typename;
    $typeSupplier->conditions = 0;
    $typeSupplier->typeDate = date("Y-m-d");
    $typeSupplier->comments = $comments;
//    $typeSupplier->category_id = $category_id;

    $TypeSupplierDAO->insert($typeSupplier);
}

function show() {
    global $TypeSupplierDAO;

    $allbranches = $TypeSupplierDAO->queryAll();

    return $allbranches;
}

function edit() {
    global $TypeSupplierDAO;

    $id = $_GET['id'];
    $alldata = $TypeSupplierDAO->load($id);

//    $alldata->category_id = explode(',', $alldata->category_id);


    return $alldata;
}

function update() {
    global $typeSupplier;
    global $TypeSupplierDAO;

    $typename = $_POST['typename'];
    $typeconditions = $_POST['conditions'];
    $typeid = $_POST['typeid'];
    $comments = $_POST['comments'];
//    $category_id = implode(',', $_POST['category_id']);


    $typeSupplier->typeId = $typeid;
    $typeSupplier->typeName = $typename;
    $typeSupplier->conditions = $typeconditions;
    $typeSupplier->typeDate = date("Y-m-d");
    $typeSupplier->comments = $comments;
//    $typeSupplier->category_id = $category_id;

    $TypeSupplierDAO->update($typeSupplier);
}

function delete() {
    global $TypeSupplierDAO;

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

function tempdelete($clientid) {
    global $TypeSupplierEX;
    $note;
    if (empty($clientid)) {
        $clientid = $_GET['id'];
    }

    if (!empty($clientid)) {
        try {
            $TypeSupplierEX->deletetemp($clientid);
            $note = "success";
        } catch (Exception $e) {
            $note = "حدث خطأ أثناء إتمام العملية";
        }
    } else {
        $note = "حدث خطأ أثناء إتمام العملية";
    }
    return $note;
}

function returndelete($clientid) {
    global $TypeClientEX;
    $note;
    if (empty($clientid)) {
        $clientid = $_GET['id'];
    }

    if (!empty($clientid)) {
        try {
            $TypeClientEX->returndelete($clientid);
            $note = "success";
        } catch (Exception $e) {
            $note = "حدث خطأ أثناء إلغاء حذف العميل";
        }
    } else {
        $note = "حدث خطأ أثناء إتمام العملية";
    }
    return $note;
}

function getProductCatParents() {
    global $productCatExt;

    $allParents = $productCatExt->getProductCatParents();
    return $allParents;
}

?>