<?php

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

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

//here the db files that include in the file
include("../public/include_dao.php");

//Programsetting
require_once('../models/dao/ProgramsettingsDAO.class.php');
require_once('../models/dto/Programsetting.class.php');
require_once('../models/mysql/ProgramsettingsMySqlDAO.class.php');
require_once('../models/mysql/ext/ProgramsettingsMySqlExtDAO.class.php');


//get the do the action
$do = $_GET['do'];

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

  Controller Name :- clientTypeCTRL

  OPERTATION in Controller

  1-
  2-
  3-
  4-

  ======================== */
$userID = $_SESSION['userid'];

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

//here goes the instances and general variables
//Programsetting
$Programsetting = new Programsetting();
$ProgramsettingDAO = new ProgramsettingsMySqlDAO();
$ProgramsettingEX = new ProgramsettingsMySqlExtDAO();




//check and use the condetion that suite this action
if (empty($do)) {


    $programsettingsdata = $ProgramsettingDAO->load(1);
    $smarty->assign('programsettingsdata', $programsettingsdata);
    $smarty->display("programsettingsview/add.html");
} elseif ($do == "update") {
    try {
        update();
        header("location:programsettingsController.php");
    } catch (Exception $e) {
        header("location:?do=error");
        //echo $e;
    }
} elseif ($_GET['do'] == "sucess") {
    $smarty->display("succes.html");
} elseif ($_GET['do'] == "error") {
    $smarty->display("error.html");
}




$smarty->display("footer.html");

//******************    Functions    ************************//
//update row
function update() {
    global $ProgramsettingEX;
    global $ProgramsettingDAO;
    global $Programsetting;



    $programsettingsid = $_POST['programsettingsid'];
    $companyname = $_POST['companyname'];
    $address = $_POST['address'];
    $specializtion = $_POST['specializtion'];
    $phone = $_POST['phone'];
    $faxnumber = $_POST['faxnumber'];
    $email = $_POST['email'];
    $website = $_POST['website'];
    $logo = $_POST['logo'];
    $roundnumbers = $_POST['roundnumbers'];
    $saveprinting = $_POST['saveprinting'];
    $deptprinting = $_POST['deptprinting'];
    $userid = $_SESSION["userid"];
    $printingpapersize = $_POST['printingpapersize'];
    $previousPrice = $_POST['previousPrice'];
    $searchvalue = $_POST['searchvalue'];
    $parcode = $_POST['parcode'];
    $priceing = $_POST['priceing'];
    $lastprice = $_POST['lastprice'];
    $updateproductprice = $_POST['updateproductprice'];

    $allowfinsldelete = $_POST['allowfinsldelete'];
    $updateclientprice = $_POST['updateclientprice'];
    $partition = $_POST['partition'];


    $taxcard = $_POST['taxcard'];
    $commercialregistration = $_POST['commercialregistration'];
    $costcenter = $_POST['costcenter'];

    $clinic = $_POST['clinic'];
    $workshop = $_POST['workshop'];
    $transport = $_POST['transport'];
    $manufacturing = $_POST['manufacturing'];
    $masterCopy = $_POST['masterCopy'];

    $workerbetweenstores = $_POST['workerbetweenstores'];
    $workshoptimeout = $_POST['workshoptimeout'];
    $drivertimeout = $_POST['drivertimeout'];
    $currency = $_POST['currancy'];




    $handle = new upload($_FILES['logo']);
    $image = updateImages($handle, "oldlogo", '../views/default/images/upload', 250, 250);
    //print_r($image);
    $alldata = $ProgramsettingDAO->load(1);

    $Programsetting->address = $address;
    $Programsetting->companyname = $companyname;
    $Programsetting->deptprinting = $deptprinting;
    $Programsetting->email = $email;
    $Programsetting->faxnumber = $faxnumber;
    $Programsetting->logo = $image;
    $Programsetting->phone = $phone;
    $Programsetting->printingpapersize = 0; //$printingpapersize;
    $Programsetting->roundnumbers = $roundnumbers;
    $Programsetting->saveprinting = $saveprinting;
    $Programsetting->specializtion = $specializtion;
    $Programsetting->website = $website;
    $Programsetting->userid = $_SESSION["userid"];

    $Programsetting->showPreviousPrice = 0; //$previousPrice;
    $Programsetting->searchvalue = $searchvalue;
    $Programsetting->parcode = 0; //$parcode;
    $Programsetting->priceing = 0; //$priceing;
    $Programsetting->lastprice = 0; //$lastprice;
    $Programsetting->updateproductprice = 0; // $updateproductprice;

    $Programsetting->allowfinsldelete = 0; //$allowfinsldelete;
    $Programsetting->updateclientprice = 0; //$updateclientprice;
    $Programsetting->partition = ""; //$partition;
    $Programsetting->taxcard = $taxcard;
    $Programsetting->commercialregistration = $commercialregistration;
    $Programsetting->costcenter = 0; //$costcenter;
    //fatma
    $Programsetting->clinic = $clinic;
    $Programsetting->workshop = $workshop;
    $Programsetting->transport = $transport;
    $Programsetting->manufacturing = $manufacturing;
    $Programsetting->masterCopy = $masterCopy;

    $Programsetting->workerbetweenstores = $workerbetweenstores;
    $Programsetting->workshoptimeout = $workshoptimeout;
    $Programsetting->drivertimeout = $drivertimeout;
    $Programsetting->currancy = $currency;


    /* print_r('<pre>');
      print_r($Programsetting);
      print_r('</pre>'); */

    // print_r($Programsetting);
    if (count($alldata) > 0) {

        $Programsetting->programsettingsid = 1;
        $ProgramsettingDAO->update($Programsetting);
    } else {
        $ProgramsettingDAO->insert($Programsetting);
    }
}

?>