<?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'];

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

	/* ======================
	
	 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'];
		$parcode = $_POST['parcode'];
		$priceing  = $_POST['priceing'];
		$lastprice  = $_POST['lastprice'];
		$searchvalue=$_POST["searchvalue"];
		$updateproductprice=$_POST["updateproductprice"];
		
		
		
		$handle = new upload($_FILES['logo']);
		$image = updateImages($handle,"oldlogo", '../views/default/images/upload',250,250);
		//print_r($image);
		$alldata=$ProgramsettingDAO->load(1);
		//$Programsetting->programsettingsid=1;
		$Programsetting->address=$address;
		$Programsetting->companyname=$companyname;
		$Programsetting->deptprinting=$deptprinting;
		$Programsetting->email=$email;
		$Programsetting->faxnumber=$faxnumber;
		$Programsetting->logo=$image;
		$Programsetting->phone=$phone;
		$Programsetting->printingpapersize=$printingpapersize;
		$Programsetting->roundnumbers=$roundnumbers;
		$Programsetting->saveprinting=$saveprinting;
		$Programsetting->specializtion=$specializtion;
		$Programsetting->website=$website;
		$Programsetting->userid=$_SESSION["userid"];;
		$Programsetting->showPreviousPrice = $previousPrice;
		$Programsetting->parcode=$parcode;
		$Programsetting->priceing=$priceing;
		$Programsetting->lastprice=$lastprice;
		$Programsetting->searchvalue=$searchvalue;
		$Programsetting->updateproductprice=$updateproductprice;

		
		
		
//print_r($Programsetting);
	 // print_r($Programsetting);
		if(count($alldata) >0)
		{
			
			$Programsetting->programsettingsid=1;
			
			$ProgramsettingDAO->update($Programsetting);
			
		}
		else
		{
			print_r($Programsetting);
			$ProgramsettingDAO->insert($Programsetting);
		}
	
		
	}




?>