File: /home/mostafedeg/public_html/erp/controllers/clientareaController.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');
//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");
/* ======================
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();
// $ClientDAO= new Client
//check and use the condetion that suite this action
if (empty($do)) {
//here the permssion check
include_once("../public/authentication.php");
$associatedtags = R::getAll('SELECT associatedtags.* FROM `associatedtags` WHERE conditions = 0');
$smarty->assign('associatedtags', $associatedtags);
//here the smarty templates
$smarty->display("clientareaview/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) {
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
$clientareaData = show();
foreach($clientareaData as $Data){
$associatedtag = R::load('associatedtags', $Data->associatedtag_id);
$Data->associatedtag = $associatedtag->tagname;
}
$smarty->assign("clientareaData", $clientareaData);
//here the smarty templates
$smarty->display("clientareaview/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 = "clientareaController.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'];
$loadData = edit($id);
$smarty->assign("loadData", $loadData);
$associatedtags = R::getAll('SELECT associatedtags.* FROM `associatedtags` WHERE conditions = 0');
$smarty->assign('associatedtags', $associatedtags);
//here the smarty templates
$smarty->display("clientareaview/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('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 $Clientarea;
global $ClientareaDAO;
$name = $_POST['name'];
$associatedtag_id = $_POST['associatedtag_id'];
$comment = $_POST['comment'];
$Clientarea->comment = $comment;
$Clientarea->name = $name;
$Clientarea->associatedtag_id = $associatedtag_id;
$ClientareaDAO->insert($Clientarea);
}
function delete($id) {
//to use the variable out side the funcion
global $Clientarea;
global $ClientareaDAO;
global $clientExt;
$allclientdata = $clientExt->queryAllbyarea($id);
if (count($allclientdata) > 0) {
return 1;
} else {
$ClientareaDAO->delete($id);
} return 0;
}
// show the form
function show() {
//to use the variable out side the funcion
global $Clientarea;
global $ClientareaDAO;
$ClientareaData = $ClientareaDAO->queryAll();
return $ClientareaData;
}
// edit in table
function edit($id) {
//to use the variable out side the funcion
global $Clientarea;
global $ClientareaDAO;
//load Shippercompanies data
$loadData = $ClientareaDAO->load($id);
//load representativecompany data
return ($loadData);
}
// update table
function update() {
//to use the variable out side the funcion
global $Clientarea;
global $ClientareaDAO;
$name = $_POST['name'];
$comment = $_POST['comment'];
$associatedtag_id = $_POST['associatedtag_id'];
$id = $_POST['id'];
$Clientarea->comment = $comment;
$Clientarea->name = $name;
$Clientarea->id = $id;
$Clientarea->associatedtag_id = $associatedtag_id;
$ClientareaDAO->update($Clientarea);
//insert Data in Representativecompany tbl
}
?>