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

require_once('../models/dao/ClientareaDAO.class.php');
require_once('../models/dto/Clientarea.class.php');
require_once('../models/mysql/ClientareaMySqlDAO.class.php');
require_once('../models/mysql/ext/ClientareaMySqlExtDAO.class.php');

//Client
require_once('../models/dao/ClientDAO.class.php');
require_once('../models/dto/Client.class.php');
require_once('../models/mysql/ClientMySqlDAO.class.php');
require_once('../models/mysql/ext/ClientMySqlExtDAO.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');

//Government
require_once('../models/dao/GovernmentDAO.class.php');
require_once('../models/dto/Government.class.php');
require_once('../models/mysql/GovernmentMySqlDAO.class.php');
require_once('../models/mysql/ext/GovernmentMySqlExtDAO.class.php');

//GovernArea
require_once('../models/dao/GoverareaDAO.class.php');
require_once('../models/dto/Goverarea.class.php');
require_once('../models/mysql/GoverareaMySqlDAO.class.php');
require_once('../models/mysql/ext/GoverareaMySqlExtDAO.class.php');

$do = $_GET['do'];

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

/* ======================

  Controller Name :- userCTRL

  OPERTATION in Controller

  1-display add form
  2- add in user tble
  3-display sucess or error
  4-display show form
  5-delete from user tbl
  6-edit in user data

  ======================== */


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



//here goes the instances and general variables
//Clientarea
$Clientarea = new Clientarea();
$ClientareaDAO = new ClientareaMySqlDAO();
$ClientareaEX = new ClientareaMySqlExtDAO();

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

//Client
$client = new Client();
$clientDAO = new ClientMySqlDAO();
$clientExt = new ClientMySqlExtDAO();

// Government
$government = new Government();
$governmentDAO = new GovernmentMySqlDAO();
$governmentExt = new GovernmentMySqlExtDAO();

// GovernArea
$governArea = new Goverarea();
$governAreaDAO = new GoverareaMySqlDAO();
$governAreaExt = new GoverareaMySqlExtDAO();

// $ClientDAO= new Client
//check and use the condetion that suite this action
if (empty($do)) {
    //here the permssion check
    include_once("../public/authentication.php");

    // collect all areaid which selected and convert it to array 
    $governmentData = $governmentDAO->queryAll();
    $goverString ;
    foreach ($governmentData as $government){
        $goverString .= ','.$government->clientareaid ;
    }
    $goverArray = explode(',', $goverString) ;
    $smarty->assign("goverArray", $goverArray);
    // here the function that do the action
    $clientareaData = showArea();
    $smarty->assign("clientareaData", $clientareaData);

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

    //here the permssion check
    include_once("../public/authentication.php");

    try {
        // here the function that do the action
        add();
        header("location:?do=sucess");
    } catch (Exception $e) {
       // print_r($e);
        header("location:?do=error");
    }
}
##
elseif ($do == "show") {

    //here the permssion check
    include_once("../public/authentication.php");

    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);
    // here the function that do the action
    show();

    //here the smarty templates
    $smarty->display("governmentview/show.html");

    $smarty->assign("customBank", 1);
    $smarty->assign("customCheck", 1);
}
##
elseif ($do == "delete") {
    //here the permssion check
    include_once("../public/authentication.php");

    $id = $_GET['id'];

    try {
        // here the function that do the action
        $policyValid = delete($id);
        if ($policyValid == 1) {
            $url = "governmentController.php?do=show";

            $smarty->assign('urldirect', $url);
            $note = "لا يمكن حذف هذه المحافظة لوجود شركات مرتبطه بها";

            $smarty->assign('msgnote', $note);
            $smarty->display("notes2.html");
        } else {
           header("location:?do=sucess");
        }
    } catch (Exception $e) {
        header("location:?do=error");
    }
}
##
elseif ($do == "edit") {
    //here the permssion check
    include_once("../public/authentication.php");
    $id = $_GET['id'];
    
    edit($id);
    //here the smarty templates
    $smarty->display("governmentview/edit.html");
}
##
elseif ($do == "update") {
    //here the permssion check
    include_once("../public/authentication.php");

    try {
        // here the function that do the action
        update();

        header("location:?do=sucess");
    } catch (Exception $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");
}

$smarty->assign('government', 1);
$smarty->assign('customValidation', 1);
//here the global templates
$smarty->display("footer.html");

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

// add in user tbl
function add() {

    //to use the variable out side the funcion
    global $governArea;
    global $governAreaDAO;
    global $government;
    global $governmentDAO;


    $area_itration = $_POST['area_itration'];
    $governmentame = $_POST['governmentname'];
  

    if(!empty($governmentame)){
        $government->governmentname = $governmentame;
        $governmentid=$governmentDAO->insert($government);
    }

    for($i = 0; $i<= $area_itration; $i++){
        $areaid = $_POST['areaid_'.$i.''];
        if(isset($areaid) && $areaid != '-1' && !empty($governmentid) ){
            $governArea->governmentid= $governmentid ;
            $governArea->clientareaid= $areaid ;
            $governAreaDAO->insert($governArea);
        }
    }
    


}

function delete($id) {

    //to use the variable out side the funcion
 
    global $governmentDAO;
    global $governAreaDAO;

    $loadgovernmentData= $governAreaDAO->deleteByGovernmentid($id);

    if($loadgovernmentData == ''){
       return 1; 
    }
    
    $governmentDAO->delete($id);
    return 0;
  
}

// show the form
function show() {
    //to use the variable out side the funcion
    global $smarty;
    global $governmentDAO;
    $countResult =0;
    $governmentData = $governmentDAO->queryAll();


    if (count($governmentData)>0){
        $countResult=1;
    }
    $smarty->assign("governmentData", $governmentData);
    $smarty->assign("countResult", $countResult);

}

function showArea() {
    //to use the variable out side the funcion
    global $ClientareaDAO;
    global $smarty;
    $flag=0;

    $clientareaData = $ClientareaDAO->queryAll();
    if(!empty($clientareaData )){
        $flag=1;
    }
    $smarty->assign("flag", $flag);

    return $clientareaData;
}

// edit in table
function edit($id) {
    //to use the variable out side the funcion
    global $governmentDAO;
    global $ClientareaEX;
    global $ClientareaDAO;
    global $governArea;
    global $governAreaDAO;
    global $governAreaExt;
    global $smarty;

    $governmentClientareaData = $governAreaDAO->queryByGovernmentid($id);
    
    $governmentData = $governmentDAO->load($id);

    $smarty->assign("governmentData", $governmentData);   
    $smarty->assign("governmentClientareaData", $governmentClientareaData);   

    $loadAreaIds = count($governmentClientareaData);
    $loadAreaIds = $loadAreaIds - 1;
    $smarty->assign("loadAreaIds", $loadAreaIds);   
    $allClientarea= $ClientareaDAO->queryAll();
    $smarty->assign("allClientarea", $allClientarea);   


}

// update table
function update() {
    //to use the variable out side the funcion
    global $government;
    global $governmentDAO;
    global $governAreaDAO;
    global $governArea;
     
    // variables
    $oldGovernmentId =$_POST['oldGovernmentId'];
    $governmentame = $_POST['governmentname'];
    $area_itration = $_POST['area_itration'];

    if(!empty($oldGovernmentId)){
        // update government name
        $government->governmentname= $governmentame ;
        $government->governmetid= $oldGovernmentId ;
    
        $governmentDAO->update($government);
        
        $governAreaDAO->deleteByGovernmentid($oldGovernmentId);
        
        for($i = 0; $i<= $area_itration; $i++){
        $areaid = $_POST['areaid_'.$i.''];

        if(isset($areaid) && $areaid != '-1' ){
            $governArea->governmentid= $oldGovernmentId ;
            $governArea->clientareaid= $areaid ;
            $governAreaDAO->insert($governArea);       
        }
    }
      
    }
}

?>