File: /home/mostafedeg/public_html/erp/controllers/capitalController.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");
include_once("dailyentryfun.php");
//here the db files that include in the file
include("../public/include_dao.php");
//Capital
require_once('../models/dao/CapitalDAO.class.php');
require_once('../models/dto/Capital.class.php');
require_once('../models/mysql/CapitalMySqlDAO.class.php');
require_once('../models/mysql/ext/CapitalMySqlExtDAO.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 :- capitalController
OPERTATION in Controller
1- edit capital
======================== */
//here the global templates
$smarty->display("header.html");
//here goes the instances and general variables
//Capital
$capital = new Capital();
$capitalDAO = new CapitalMySqlDAO();
$capitalExt = new CapitalMySqlExtDAO();
//Accountstree
$accountsTree = new Accountstree();
$accountsTreeDAO = new AccountstreeMySqlDAO();
$accountsTreeEX = new AccountstreeMySqlExtDAO();
$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();
$today = date("Y-m-d");
//check and use the condition that suite this action
if (empty($do) || $do == "edit") {
//here the permission check
include_once("../public/authentication.php");
$youtubes = $youtubeLinkDAO->queryAll();
$smarty->assign("youtubes", $youtubes);
$capitalData = edit();
$smarty->assign("capitalData", $capitalData);
$smarty->display("capitalview/edit.html");
} elseif ($do == "editprint") {//edit
include_once("../public/authentication.php");
$capitalData = edit();
$smarty->assign("capitalData", $capitalData);
$smarty->display("capitalview/editprint.html");
$smarty->assign("customPrint", 1);
} elseif ($do == "update") { //edit update
include_once("../public/authentication.php");
try {
update();
header("location:?do=sucess");
} catch (Exception $e) {
header("location:?do=error");
}
} elseif ($do == "sucess") {
//here the smarty templates
$smarty->display("capitalview/succes.html");
} elseif ($do == "error") {
//here the smarty templates
$smarty->display("capitalview/error.html");
}
//here the global templates
$smarty->assign("customValidation", 1);
$smarty->display("footer.html");
/* ===============================
function in this CONTROLLER
================================ */
function edit() {
global $capitalDAO;
$capitalId = 1;
$capitalData = $capitalDAO->load($capitalId);
if (!isset($capitalData)) {
$capitalData = new stdClass();
$capitalData->capitalamount = 0;
$capitalData->capitalid = 0;
}
return $capitalData;
}
function update() {
global $capitalDAO;
global $capital;
global $accountsTreeDAO;
global $accountsTree;
$capitalid = $_POST['capitalid'];
$capitalamount = $_POST['capitalamount'];
if ($capitalid == 0) { //Insert
$capital->capitalamount = $capitalamount;
$capital->treeId = 50;
$capitalDAO->insert($capital);
if ($capital->treeId > 0) {
$capitalTreeId = $capital->treeId;
$accountsTree = $accountsTreeDAO->load($capitalTreeId);
$accountsTree->theValue = $capitalamount;
editTreeElement($accountsTree);
} else {
$treeId = addTreeElement("رأس المال", 120, 1, 0, 1, '', 0, $capitalamount);
$capitalDAO->update($capital);
}
} else { //Update
$oldData = $capitalDAO->load($capitalid);
$capital->capitalamount = $capitalamount;
$capital->treeId = $oldData->treeId;
$capital->capitalid = 1; //$capitalid;
if ($capital->treeId > 0) {
$capitalTreeId = $capital->treeId;
$accountsTree = $accountsTreeDAO->load($capitalTreeId);
$accountsTree->theValue = $capitalamount;
editTreeElement($accountsTree);
} else {
$treeId = addTreeElement("رأس المال", 120, 1, 0, 1, '', 0, $capitalamount);
}
$capitalDAO->update($capital);
}
}
?>