<?php
function add2QaStat($act, $type, $admin){
	global $db,$dbback;

	if($admin == "")
	{
		return false;
	}

	if($type != 'pass' && $type != 'no')
	{
		return false;
	}
	
	$field = "";
	switch($act)
	{
		case 'surface': $field = "surface_".$type;
						break;
		case 'sort0':	$field = "sort0_".$type;
						break;
		case 'sort1':	$field = "sort1_".$type;
						break;
		case 'sort2':	$field = "sort2_".$type;
						break;
		default:		$field = "remark_".$type;
						break;
	}

	$tbl = "admin_house_qa_stat";
	
	$nowdate = date("Y-m-d");
	$operarr = $db->GetRow("SELECT id,surface_pass,surface_no,sort0_pass,sort0_no,sort1_pass,sort1_no,sort2_pass,sort2_no,remark_pass,remark_no FROM ".$tbl." WHERE dateline = '".$nowdate."' AND admin = '".$admin."'");

	$operarr['id'] = intval($operarr['id']);

	$data['dateline']		 = $nowdate;
	$data['admin']			 = $admin;
	$operarr['surface_pass'] = intval($operarr['surface_pass']);
	$data['surface_pass']	 = $field == 'surface_pass' ? $operarr['surface_pass'] + 1 : $operarr['surface_pass'];
	$operarr['surface_no']   = intval($operarr['surface_no']);
	$data['surface_no']		 = $field == 'surface_no' ? $operarr['surface_no'] + 1 : $operarr['surface_no'];

	$operarr['sort0_pass']	 = intval($operarr['sort0_pass']);
	$data['sort0_pass']		 = $field == 'sort0_pass' ? $operarr['sort0_pass'] + 1 : $operarr['sort0_pass'];
	$operarr['sort0_no']	 = intval($operarr['sort0_no']);
	$data['sort0_no']		 = $field == 'sort0_no' ? $operarr['sort0_no'] + 1 : $operarr['sort0_no'];

	$operarr['sort1_pass']   = intval($operarr['sort1_pass']);
	$data['sort1_pass']		 = $field == 'sort1_pass' ? $operarr['sort1_pass'] + 1 : $operarr['sort1_pass'];
	$operarr['sort1_no']	 = intval($operarr['sort1_no']);
	$data['sort1_no']		 = $field == 'sort1_no' ? $operarr['sort1_no'] + 1 : $operarr['sort1_no'];

	$operarr['sort2_pass']	 = intval($operarr['sort2_pass']);
	$data['sort2_pass']		 = $field == 'sort2_pass' ? $operarr['sort2_pass'] + 1 : $operarr['sort2_pass'];
	$operarr['sort2_no']	 = intval($operarr['sort2_no']);
	$data['sort2_no']		 = $field == 'sort2_no' ? $operarr['sort2_no'] + 1 : $operarr['sort2_no'];

	$operarr['remark_pass']  = intval($operarr['remark_pass']);
	$data['remark_pass']	 = $field == 'remark_pass' ? $operarr['remark_pass'] + 1 : $operarr['remark_pass'];
	$operarr['remark_no']	 = intval($operarr['remark_no']);
	$data['remark_no']		 = $field == 'remark_no' ? $operarr['remark_no'] + 1 : $operarr['remark_no'];
	
	$sql = "";
	if($operarr['id'] > 0)
	{
		$sql = update_sql($tbl, $data, " WHERE id = '".$operarr['id']."'");
	}
	else
	{
		$sql = insert_sql($tbl, $data);
	}

	$db->Execute($sql);
}

function add2BrokerQaStat($act, $type, $admin){
	global $db,$dbback;

	if($admin == ""){
		return false;
	}

	if($type != 'pass' && $type != 'no'){
		return false;
	}
	
	$field = "";
	switch($act){
		case 'head': 
			$field = "head_".$type;
			break;
		case 'cert':	
			$field = "cert_".$type;
			break;
		case 'real':	
			$field = "real_".$type;
			break;
	    default:
			$field = "account_".$type;
			break;
	}

	$tbl = "admin_broker_qa_stat";
	
	$nowdate = date("Y-m-d");
	$operarr = $db->GetRow("SELECT id,head_pass,head_no,cert_pass,cert_no,real_pass,real_no,account_pass,account_no  FROM ".$tbl." WHERE dateline = '".$nowdate."' AND admin = '".$admin."'");

	$operarr['id'] = intval($operarr['id']);
	$data['dateline']		 = $nowdate;
	$data['admin']			 = $admin;
	$operarr['head_pass'] = intval($operarr['head_pass']);
	$data['head_pass']	 = $field == 'head_pass' ? $operarr['head_pass'] + 1 : $operarr['head_pass'];
	$operarr['head_no']   = intval($operarr['head_no']);
	$data['head_no']	 = $field == 'head_no' ? $operarr['head_no'] + 1 : $operarr['head_no'];

	$operarr['cert_pass']	 = intval($operarr['cert_pass']);
	$data['cert_pass']	 = $field == 'cert_pass' ? $operarr['cert_pass'] + 1 : $operarr['sort0_pass'];
	$operarr['cert_no']	 = intval($operarr['cert_no']);
	$data['cert_no']  = $field == 'cert_no' ? $operarr['cert_no'] + 1 : $operarr['cert_no'];

	$operarr['real_pass']   = intval($operarr['real_pass']);
	$data['real_pass']	 = $field == 'real_pass' ? $operarr['real_pass'] + 1 : $operarr['sort1_pass'];
	$operarr['real_no']	 = intval($operarr['real_no']);
	$data['real_no']	 = $field == 'real_no' ? $operarr['real_no'] + 1 : $operarr['real_no'];

	$operarr['account_pass']	 = intval($operarr['account_pass']);
	$data['account_pass'] = $field == 'account_pass' ? $operarr['account_pass'] + 1 : $operarr['account_pass'];
	$operarr['account_no']	 = intval($operarr['account_no']);
	$data['account_no']		 = $field == 'account_no' ? $operarr['account_no'] + 1 : $operarr['account_no'];

	$sql = "";
	if($operarr['id'] > 0){
		$sql = update_sql($tbl, $data, " WHERE id = '".$operarr['id']."'");
	}
	else{
		$sql = insert_sql($tbl, $data);
	}
    //print_r($data);die;
	$db->Execute($sql);
}
?>