<?php
define('YUKEY', true);
require(str_replace('sicms','',dirname(__FILE__)) . '/includes/init.php');
check_login();
$hint=$sql='';
$active=!empty($_REQUEST['active']) ? intval($_REQUEST['active']) : 2;
$cat_val=!empty($_REQUEST['category']) ? $_REQUEST['category'] : '';
$keywords=!empty($_REQUEST['keywords']) ? trim($_REQUEST['keywords']) : '';
require(ROOT_PATH . 'includes/lib_projects.php');
require(ROOT_PATH . 'includes/lib_reports.php');
if ($act=='get_hint')
{   		
	if($cat_val==1 || $cat_val==4){
			$hint[]='';
			$today=substr(date('Y-m-d'),-2);
			 for($k=1;$k<=intval($today);$k++)
			  {
				  $hint[].=substr(date('Y-m-d'),0,-2).sprintf("%02d",$k);
			  }
		}else if($cat_val==2 || $cat_val==5){
			$hint=get_rows("si","tbCompanyID,tbType,tbNickName","`tbType`=2","companys","tbNickName");
		}else if($cat_val==3 || $cat_val==7){
			$hint=get_products_list();
		}else{}
	echo json_encode($hint);
}
else if ($act=='search')
{ 
		 //var_dump($cat_val);exit;
		 $smarty->assign('act',$act);
		 $smarty->assign('cat_val',$cat_val);
		 $smarty->assign('keywords',$keywords);
		 switch ($cat_val)
		 {
			case '1':
				$total=count_item('tbInspectionDate',$keywords,'projects',''); //总记录条数
				require(ROOT_PATH . 'includes/get_sdata.php');
				$smarty->assign('active',1);
				$smarty->assign('pre',$pre);
				$smarty->assign('list_pro',get_projects('tbInspectionDate',$keywords,$start_num,$page_num,'',''));
				$smarty->display('projects.dwt');
				 break;
			case '2':
				$factory_id=get_row('si','*','tbNickName',$keywords,'companys');
				$total=count_item('tbFactoryID',$factory_id['tbCompanyID'],'projects',''); //总记录条数
				require(ROOT_PATH . 'includes/get_sdata.php');
				$smarty->assign('active',1);
				$smarty->assign('pre',$pre);
				$smarty->assign('list_pro',get_projects('tbFactoryID',$factory_id['tbCompanyID'],$start_num,$page_num,'',''));
				$smarty->display('projects.dwt');
				 break;
			case '3':
				$total=count_item('tbProductName',$keywords,'reports','');//总记录条数
				require(ROOT_PATH . 'includes/get_sdata.php');
				$smarty->assign('active',2);
				$smarty->assign('pre',$pre);
				$smarty->assign('list_rep',report_list('tbProductName',$keywords,$start_num,$page_num));
				$smarty->display('reports.dwt');
				 break;
			case '4':
				$total=count_item('tbInspectionDate',$keywords,'reports','');//总记录条数
				require(ROOT_PATH . 'includes/get_sdata.php');
				$smarty->assign('active',2);
				$smarty->assign('pre',$pre);
				$smarty->assign('list_rep',report_list('tbInspectionDate',$keywords,$start_num,$page_num));
				$smarty->display('reports.dwt');
				 break;
			case '5':
				$factory_id=get_row('si','*','tbNickName',$keywords,'companys');
				$total=count_item('tbFactoryID',$factory_id['tbCompanyID'],'reports','');//总记录条数
				require(ROOT_PATH . 'includes/get_sdata.php');
				$smarty->assign('active',2);
				$smarty->assign('pre',$pre);
				$smarty->assign('list_rep',report_list('tbFactoryID',$factory_id['tbCompanyID'],$start_num,$page_num));
				$smarty->display('reports.dwt');
				 break;
			case '6':
				if($keywords!='')//搜索页面翻页会出问题
				 {
					$serial=get_serials("tbSerialNumber",$keywords,"serial1","serial2","tbSN",'true');
					$total=count_item('tbReportNumber',$serial['tbReportNumber'],'reports','');//总记录条数
					require(ROOT_PATH . 'includes/get_sdata.php');
					$smarty->assign('active',2);
					$smarty->assign('pre',$pre);
					$smarty->assign('list_rep',report_list('tbReportNumber',$serial['tbReportNumber'],$start_num,$page_num));
					$smarty->display('reports.dwt');
				 }
				 break;
			case '7':
				$total=count_item('tbProductName',$keywords,'reports','');//总记录条数
				require(ROOT_PATH . 'includes/get_sdata.php');
				$smarty->assign('active',2);
				$smarty->assign('pre',$pre);
				$smarty->assign('list_rep',report_list('tbProductName',$keywords,$start_num,$page_num));
				$smarty->display('report_serial.dwt');
				 break;
			default:
				 break;
		 }
}
?>