File: /home/mostafedeg/public_html/erp/controllers/branchesController.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
//Branch
require_once('../models/dao/BranchDAO.class.php');
require_once('../models/dto/Branch.class.php');
require_once('../models/mysql/BranchMySqlDAO.class.php');
require_once('../models/mysql/ext/BranchMySqlExtDAO.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
//Branch
$Branch = new Branch();
$BranchDAO = new BranchMySqlDAO();
$BranchEX = new BranchMySqlExtDAO();
$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();
if (empty($do)) {
include_once("../public/authentication.php");
$smarty->display("branchesview/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) {
//print_r($e);
header("location:?do=error");
}
} elseif ($do == "show") {
include_once("../public/authentication.php");
$youtubes = $youtubeLinkDAO->queryAll();
$smarty->assign("youtubes", $youtubes);
$allbranches = show();
$smarty->assign("allbranches", $allbranches);
$smarty->display("branchesview/show.html");
}
//edit
elseif ($do == "edit") {
include_once("../public/authentication.php");
$alldata = edit();
$smarty->assign("alldata", $alldata);
//print_r($alldata);
$smarty->display("branchesview/edit.html");
} elseif ($do == "editprint") {
include_once("../public/authentication.php");
$alldata = edit();
$smarty->assign("alldata", $alldata);
//print_r($alldata);
$smarty->display("branchesview/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) {
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 == "error") {
//here the smarty templates
$smarty->display("error.html");
}
$smarty->assign("customreceipt", 1);
$smarty->assign("GeneralSearch", 1);
$smarty->display("footer.html");
////**************************** Functions ********************///
/* ===============================
function in this CONTROLLER
================================ */
function add() {
global $Branch;
global $BranchDAO;
$branchname = $_POST['branchname'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];
$branchNo = $_POST['branchNo'];
$branchAddress = $_POST['branchAddress'];
$message = $_POST['message'];
$branchTaxNo = $_POST['branchTaxNo'];
$Branch->branchName = $branchname;
$Branch->branchDate = date("Y-m-d");
$Branch->phone = $phone;
$Branch->mobile = $mobile;
$Branch->branchNo = $branchNo;
$Branch->branchAddress = $branchAddress;
$Branch->branchTaxNo = $branchTaxNo;
$handle = new upload($_FILES['logo']);
$image = uploadImages($handle, '../views/default/images/branch_image', 250, 250);
$Branch->logo = $image;
$Branch->message = $message;
$BranchDAO->insert($Branch);
}
function show() {
global $BranchDAO;
$allbranches = $BranchDAO->queryAll();
return $allbranches;
}
function edit() {
global $BranchDAO;
$id = $_GET['id'];
$alldata = $BranchDAO->load($id);
return $alldata;
}
function update() {
global $Branch;
global $BranchDAO;
$branchname = $_POST['branchname'];
$branchid = $_POST['branchid'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];
$branchNo = $_POST['branchNo'];
$branchAddress = $_POST['branchAddress'];
$message = $_POST['message'];
$branchTaxNo = $_POST['branchTaxNo'];
$Branch->branchId = $branchid;
$Branch->branchName = $branchname;
$Branch->branchDate = date("Y-m-d");
$Branch->phone = $phone;
$Branch->mobile = $mobile;
$Branch->branchNo = $branchNo;
$Branch->branchAddress = $branchAddress;
$Branch->branchTaxNo = $branchTaxNo;
$handle = new upload($_FILES['logo']);
$image = updateImages($handle, "oldlogo", '../views/default/images/branch_image', 250, 250);
$Branch->logo = $image;
$Branch->message = $message;
$BranchDAO->update($Branch);
}
function delete() {
global $BranchDAO;
$id = $_GET['id'];
$BranchDAO->delete($id);
}
?>