<?php	
		$db = new etamineDB();
		$dropDown = new DropDownOptions();
		$showFile = "pdf/costanalysis.html";
		$ajax = new etamineAjax();
		$ajax->showLoading();	
		$listBox = new ListBox();
		$class_etamine_com->UseClass("docmanager");	
		//$ajax->exportFunction("add");
		$ajax->setRequestType("POST");
		$ajax->exportFunction("wardChange"); 
		$ajax->exportFunction("DeptName");
		$ajax->exportFunction("updateRMS","theform");
		$db = new etamineDB();
		$ajax->process();		
		

	//	system('winexe //192.168.1.125 \cmd /c  C:\>Program Files/wkhtmltopdf/wkhtmltopdf.exe \"http://192.168.1.125/fms/?module=pdf\" \"documents/receipt/receipt.pdf\" ');
		exec("xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf http://cvc.vigeyegpms.org/ documents/pdf/download.pdf");

	//	$last_line = system("winexe -A pfile //172.16.1.186 \"cmd /c  C:\\XcryptI\\Xcrypt.exe \"{$source}\" \"{$dist}\" \"{$adopt}\"\" > /dev/null ");
	//	exec("xvfb-run -a wkhtmltopdf includes/template/cwgpublic/costanalysis.html documents/pdf/download.pdf");
	//	exec('"C:/Program Files/wkhtmltopdf/wkhtmltopdf.exe" "http://cvc.vigeyegpms.org/?module=cwgpublic&action=costanalysis&organizationid=1&nomenu=1" documents/pdf/download.pdf');

		
		function pdfEncrypt ($origFile, $password, $destFile)
		{
			require_once('includes/pdf/fpdi/FPDI_Protection.php');
			$pdf =& new FPDI_Protection();
			$pdf->FPDF('P', 'in');
			//Calculate the number of pages from the original document.
			$pagecount = $pdf->setSourceFile($origFile);
			//Copy all pages from the old unprotected pdf in the new one.
			for ($loop = 1; $loop <= $pagecount; $loop++) {
				$tplidx = $pdf->importPage($loop);
				$pdf->addPage();
				$pdf->useTemplate($tplidx);
			}

			//Protect the new pdf file, and allow no printing, copy, etc. and
			//leave only reading allowed.
			//unlink($origFile);
			$pdf->SetProtection(array(), $password);
			$pdf->Output($destFile, 'F');
			return $destFile;
		}

		//Password for the PDF file (I suggest using the email adress of the purchaser).
		$password = 'demo';
		//Name of the original file (unprotected).
		$origFile = "documents/pdf/download.pdf";
		//Name of the destination file (password protected and printing rights removed).
		$destFile ="documents/pdf/downloadpdf.pdf";
		
		//Encrypt the book and create the protected file.
		pdfEncrypt($origFile, $password, $destFile );
		
		header('Content-disposition: attachment; filename=documents/pdf/downloadpdf.pdf');
		header('Content-type: application/pdf');
		readfile('documents/pdf/downloadpdf.pdf');

		unlink("documents/pdf/download.pdf");
		unlink("documents/pdf/downloadpdf.pdf");
	
		  
		/************* to store session value ****************/
		$_SESSION['SEARCH']['TABLEBORDERCOLOR'] = $cfg['TABLEBORDERCOLOR'];
		$_SESSION['SEARCH']['STRIPCOLOR'] = $cfg["STRIPCOLOR"][0];
		$_SESSION['SEARCH']['STRIPCOLOR1'] = $cfg["STRIPCOLOR"][1];
		$_SESSION['SEARCH']['BGMENULIGHT'] = $cfg['BGMENULIGHT'];
		$_SESSION['SEARCH']['BGMENU'] = $cfg['BGMENU'];
		$_SESSION['STRIPCOLOR'] = $cfg["STRIPCOLOR"];
		$_SESSION['SKINS'] = $GLOBALS['skins'];
		$_SESSION['JSDIR'] = $GLOBALS['javascript'];
		/************* to store session value ****************/

		$middleValues[] = array(
			"AJAXCONTENT"		=>	$ajax->getJavaScript(false, true),
			"STARTNO"			=>	(($currentpage - 1) * $pagelength)+1,
			"GROUPID"			=>	$_SESSION['GROUPID'],
			"DISPLAYSEARCH"		=>	$lan['SEARCH'],
			"FORMACTION"		=>	$p_action,
			"MODULE"			=>	$p_module,
			"PAGECONTENTS"		=>	$pageContents,
			"JSDIR"				=>	$GLOBALS['javascript'],
			"SKINS"				=>	$GLOBALS['skins'],
			"WARDOPTION"		=>	$wardoption,
			
		);	
		$topValues[] = array(
			"USERNAME"	=>	$_SESSION['username'],
			"GROUPID"	=>	$_SESSION['GROUPID'],			
			"DOMAIN"	=>	$_SERVER['HTTP_HOST'],
			"APPID"		=>	$appid,
			"APPCODE"	=>	$appcode,			
		);
	$topContents = $etamineParser->Parse($topFile,$topValues);
	$etamineParser->assign("dbvaluestoday", $dbValuesToday);
	
	$etamineParser->assign($middleValues);
	$etamineParser->assign($_SESSION['ACCESSINFO']['Front Workcode']);
	$middleContents = $etamineParser->Parse(TEMPLATE . $showFile , $middleValues);
?>
