<?php 
class CActionQuery extends CActionBase
{
	function doAction()
	{	
		$ret = 0;
		$job = $_POST["job"];
		GetCookie();
		
		switch($job)
		{
			case "add":
				$ret = $this->Add();
			break;
		}
		
		return $ret;
	}
	
	function Add()
	{
		global $UserInfo;
		
		$project_id  			= $_POST["project_id"];    
		$module_id   			= $_POST["module_id"];   
		$query_str 				= $this->HtmlEncode($_POST["query_str"]);    
		$query_field  		= $_POST["query_field"];     
		$query_property 	= $_POST["query_property"];   
		$query_date 			= $_POST["query_date"];       
		$issue_type  			= $_POST["issue_type"];      
		$issue_status 		= $_POST["issue_status"];    
		$serverity   			= $_POST["serverity"];      
		$priority    			= $_POST["priority"];
		$create_user  		= $this->HtmlEncode($_POST["create_user"]);     
		$process_user    	= $this->HtmlEncode($_POST["process_user"]);   
		$create_date_begin= $this->HtmlEncode($_POST["create_date_begin"]);
		$create_date_end 	= $this->HtmlEncode($_POST["create_date_end"]);  
		$close_date_begin = $this->HtmlEncode($_POST["close_date_begin"]); 
		$close_date_end  	= $this->HtmlEncode($_POST["close_date_end"]);
		$query_id = 0;
		
		$sql = "select query_id from tb_query_view where query_type=0 and user_id=".$UserInfo['UID']; 
		$this->db->ExeQuerySql($sql);	
		if($this->db->FetchRow())
		{
				$query_id = $this->db->Get("query_id");
				$sql = "update tb_query_view set ";
				$sql = $sql . "project_id       = ".$project_id.",";																							
		    $sql = $sql . "module_id        = ".$module_id.",";																							
		    $sql = $sql . "query_str	     = '".$query_str."',";																							
		    $sql = $sql . "query_field      = ".$query_field.",";																							
		    $sql = $sql . "query_property   = ".$query_property.",";																							
		    $sql = $sql . "query_date       = ".$query_date.",";																							
		    $sql = $sql . "issue_type       = ".$issue_type.",";																							
		    $sql = $sql . "issue_status     = ".$issue_status.",";																							
		    $sql = $sql . "serverity        = ".$serverity.",";																							
		    $sql = $sql . "priority         = ".$priority.",";																							
		    $sql = $sql . "create_user      = '".$create_user."',";																							
		    $sql = $sql . "process_user     = '".$process_user."',";																							
		    $sql = $sql . "create_date_begin= '".$create_date_begin."',";																							
		    $sql = $sql . "create_date_end  = '".$create_date_end."',";																							
		    $sql = $sql . "close_date_begin = '".$close_date_begin."',";																							
		    $sql = $sql . "close_date_end   = '".$close_date_end."'";	
				$sql = $sql . " where query_id=".$query_id;
		}
		else
		{
				$query_id = $this->db->GetMaxField('tb_query_view', 'query_id')+1;
				$sql = "insert into tb_query_view ( ";
				$sql = $sql . "query_id         ,";																																														
		    $sql = $sql . "query_type       ,";																							
		    $sql = $sql . "user_id          ,";																							
		    $sql = $sql . "project_id       ,";																							
		    $sql = $sql . "module_id        ,";																							
		    $sql = $sql . "query_str	     ,";																							
		    $sql = $sql . "query_field      ,";																							
		    $sql = $sql . "query_property   ,";																							
		    $sql = $sql . "query_date       ,";																							
		    $sql = $sql . "issue_type       ,";																							
		    $sql = $sql . "issue_status     ,";																							
		    $sql = $sql . "serverity        ,";																							
		    $sql = $sql . "priority         ,";																							
		    $sql = $sql . "create_user      ,";																							
		    $sql = $sql . "process_user     ,";																							
		    $sql = $sql . "create_date_begin,";																							
		    $sql = $sql . "create_date_end  ,";																							
		    $sql = $sql . "close_date_begin ,";																							
		    $sql = $sql . "close_date_end   ";																							
				$sql = $sql . ") values (";
				$sql = $sql . $query_id . ",";
				$sql = $sql . "0,";
				$sql = $sql . $UserInfo['UID'] . ",";
				$sql = $sql . $project_id . ",";   			
				$sql = $sql . $module_id . ",";    			
				$sql = $sql . "'".$query_str . "',";  				
				$sql = $sql . $query_field . ",";   		
				$sql = $sql . $query_property . ",";  	
				$sql = $sql . $query_date . ",";  			
				$sql = $sql . $issue_type . ",";   			
				$sql = $sql . $issue_status . ",";  		
				$sql = $sql . $serverity . ",";    			
				$sql = $sql . $priority . ",";     			
				$sql = $sql . "'".$create_user . "',";  		
				$sql = $sql . "'".$process_user . "',";   	
				$sql = $sql . "'".$create_date_begin . "',"; 
				$sql = $sql . "'".$create_date_end . "',";  	
				$sql = $sql . "'".$close_date_begin . "',";  
				$sql = $sql . "'".$close_date_end . "')";   	
		}
		
		$this->db->ExeSql($sql);
		
		return $query_id;
	}	
};
?>
