<?php
define('YUKEY', true);
require(str_replace('sicms','',dirname(__FILE__)) . '/includes/init.php');
check_login();
require(ROOT_PATH . 'includes/lib_reports.php');
$active=!empty($_GET['active']) ? intval($_GET['active']) : 2;
if($act=='ready')
{
	$total=count_item('','','reports',''); //总记录条数
	$page_num=20;  //每页显示的记录数
	$allpage=ceil($total/$page_num); //总页数
	$current_page=!empty($_GET['nowpage']) ? intval($_GET['nowpage']) : 1; //目前页数 
	$start_num=$page_num*($current_page-1); //$start_num 起始笔数
	$smarty->assign('active',$active);
	$smarty->assign('pre',$pre);
	$smarty->assign('list_rep',report_list('','',$start_num,$page_num));
	$smarty->assign('all_page',$allpage);
	$smarty->assign('all_pages',listpage($allpage));
	$smarty->assign('now_page',$current_page);
	$smarty->display('reports.dwt');
}

elseif($act=='loadresult'){
	     $id=!empty($_POST['id']) ? $_POST['id'] : '';
		 $s=get_row('',"tbPN,tbReportNumber,tbProductName,tbClientID,tbInspectionDate,tbLotQty,tbResult,tbApproval,tbAppDate,tbModify,tbIssue,tbModifyReason","tbPN",$id,"reports");
		 echo json_encode($s);
}
elseif($act=='loadman'){
	$cid=!empty($_POST['cid']) ? $_POST['cid'] : '';
	$s=get_users('tbCompanyID',$cid);
	echo json_encode($s);
}
elseif($act=='chgresult'){
	$tbPN = !empty($_POST['tbPN']) ? $_POST['tbPN'] : '';
	$approvaled = !empty($_POST['approvaled']) ? $_POST['approvaled'] : '';
	$tbModify = !empty($_POST['tbModify']) ? $_POST['tbModify'] : '';
	$tbAppDate = !empty($_POST['tbAppDate']) ? $_POST['tbAppDate'] : '';
	$result = !empty($_POST['result']) ? $_POST['result'] : '';
	$tbIssue = !empty($_POST['tbIssue']) ? $_POST['tbIssue'] : '';
	$tbReason = !empty($_POST['tbReason']) ? $_POST['tbReason'] : '';
	$sql="UPDATE " .$GLOBALS['prefix']->table('reports'). " SET" . " tbResult='$result',tbApproval='$approvaled',tbModify='$tbModify',tbAppDate='$tbAppDate',tbIssue='$tbIssue',tbModifyReason='$tbReason' WHERE tbPN='$tbPN'";
	if($tbPN!=''){
		if($GLOBALS['db']->query($sql)){
			echo $tbPN;
		}else{
			echo "<script type='text/JavaScript'>alert('Modify Fail,query error!');</script>";
			exit;
		}
	}else{
			echo "<script type='text/JavaScript'>alert('Get report id fail!');</script>";
			exit;
	}
}
?>