<?php
/**
 * pdf_ajax_view.php - The pdf view to use ajax to make it more user friendly
 *
 * @author $Author: dtong $
 * @version $Id: pdf_ajax_view.php,v 1.8 2011/04/08 08:22:33 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<script type="text/javascript" src="<?php echo osa_include_path()?>js/sys.js"></script>
<script type="text/javascript" src="<?php echo osa_include_path()?>js/app.js"></script>
<?php
	osa_appcss_include();
	$this->load->view('template/jscript_globalvars_view');
?>
<script type="text/javascript">
	function process_pdf() {
		window.parent.ajax_is_running++;
		force_update_session();
		var mypostrequest=new ajaxRequest();
		mypostrequest.onreadystatechange = function(){
			if (mypostrequest.readyState==4){
				if (mypostrequest.status==200){
					if ( mypostrequest.responseText.search('pdfgen') != 0 ) {
						alert('<?php echo lang('gen_pdf_failed_msg')?>');
						window.close();
					}
					else {
						pdf_read_url = '<?php echo base_url()?>pdf/pdfgen/read/' +
							mypostrequest.responseText + '/<?php echo $dummy_pdfname?>';
						window.location = pdf_read_url;
					}
				}
				else {
					alert('<?php echo lang('gen_pdf_failed_msg')?>');
					window.close();
				}
			}
		} //function
		var parameters = 'bustcache=' + new Date().getTime();
		var pef_exe_url = '<?php echo base_url()?>pdf/pdfgen/create/' + '<?php echo $url?>/1';
		//confirm(pef_exe_url);
		try {
			mypostrequest.open('POST',pef_exe_url,true);
			mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			mypostrequest.send(parameters);
		}
		catch(e) {
			alert('<?php echo lang('gen_pdf_failed_msg')?>');
			window.close();
			window.parent.ajax_is_running--;
			return false;
		}
		window.parent.ajax_is_running--;
		return true;
	}
</script>
</head>
<body onload="process_pdf();">
<div style="margin-top:30%;text-align:center;border:solid 0px">
<div style="margin-bottom:50px"><?php echo lang('gen_pdf_wait_msg') ?></div>
<img src="<?php echo osa_imagepath();?>wait_bar.gif" /></div>
<div style="margin-bottom:30%;text-align:center;border:solid 0px"></div>
</body>
</html>