<?php
class CFlowStatus
{
	var $status_id     ;
	var $chart_state_id;
	var $state_name    ;
	var $state_type    ;
	var $state_title   ;
	var $coord_left    ;
	var $coord_top     ;
};

class CFlowAction
{
	var $action_id      ;
	var $chart_action_id;
	var $action_name    ;
	var $action_title   ;
	var $src_status  ;
	var $dst_status  ;
	var $points         ;
	var $coord_left     ;
	var $coord_top      ;
};

class CFlowInfo
{
	var $flow_id;
	var $flow_name;
	var $status;
	var $actions;
	
	function CFlowInfo()
	{
		$this->status = array();
		$this->actions = array();	
	}
	
	function InitStatus($db)
	{
		$sql = "select * from tb_flow_status where flow_id=".$this->flow_id ." order by chart_state_id";
		$db->ExeQuerySql($sql);
		while($db->FetchRow())
		{			
			$mod = new CFlowStatus();
			$mod->status_id     =$db->Get("status_id");
			$mod->chart_state_id=$db->Get("chart_state_id");
			$mod->state_name    =$db->Get("state_name");
			$mod->state_type    =$db->Get("state_type");
			$mod->state_title   =$db->Get("state_title");
			$mod->coord_left    =$db->Get("coord_left");
			$mod->coord_top     =$db->Get("coord_top");		
			$this->status[sizeof($this->status)] = $mod;
		}
		$db->FreeResult();
	}
	
	function InitActions($db)
	{
		$sql = "select * from tb_flow_action where flow_id=".$this->flow_id ." order by chart_action_id";
		
		$db->ExeQuerySql($sql);
		while($db->FetchRow())
		{			
			$mod = new CFlowAction();
			$mod->action_id       = $db->Get("action_id");
			$mod->chart_action_id = $db->Get("chart_action_id");
			$mod->action_name     = $db->Get("action_name");
			$mod->action_title    = $db->Get("action_title");
			$mod->src_status   	 = $db->Get("src_status");
			$mod->dst_status   	 = $db->Get("dst_status");
			$mod->points          = $db->Get("points");
			$mod->coord_left      = $db->Get("coord_left");
			$mod->coord_top       = $db->Get("coord_top");	
			$this->actions[sizeof($this->actions)] = $mod;
		}
		$db->FreeResult();
	}
};

class CModuleFlow extends CModuleBase
{
	function Init()
	{
		$sql = "select * from tb_flow order by 1";		
		$this->db->ExeQuerySql($sql);
	
		while($this->db->FetchRow())
		{			
			$mod = new CFlowInfo();
			$mod->flow_id = $this->db->Get("flow_id");
			$mod->flow_name = $this->db->Get("flow_name");			
			$this->modules[$this->GetSize()] = $mod;
		}
		$this->db->FreeResult();
	}
	
	function InitModule($module_id)
	{
		$sql = "select * from tb_flow where flow_id=".$module_id;
		
		$this->db->ExeQuerySql($sql);
		if($this->db->FetchRow())
		{			
			$this->module = new CFlowInfo();
			$this->module->flow_id = $this->db->Get("flow_id");
			$this->module->flow_name = $this->db->Get("flow_name");
			$this->db->FreeResult();
			
			$this->module->InitStatus($this->db);
			$this->module->InitActions($this->db);
		}
	}
	
	//获取名称相同的数量
	function GetCount($module_name, $module_id=0)
	{
			$sql = "select count(*) nCount from tb_flow where flow_name = '".$module_name."' and  flow_id<>".$module_id;
		
			$this->db->ExeQuerySql($sql);
			$nCount = 0;
			if($this->db->FetchRow())
				$nCount = $this->db->Get("nCount");
			$this->db->FreeResult();	
			return $nCount;
	}
	
	function InitModuleByType($type_id)
	{
		$sql = "select a.* from tb_flow a, tb_project_issue_type b where a.flow_id=b.flow_id and b.issue_type_id=".$type_id;
		
		$this->db->ExeQuerySql($sql);
		if($this->db->FetchRow())
		{			
			$this->module = new CFlowInfo();
			$this->module->flow_id = $this->db->Get("flow_id");
			$this->module->flow_name = $this->db->Get("flow_name");
			$this->db->FreeResult();
			
			$this->module->InitStatus($this->db);
			$this->module->InitActions($this->db);
		}
	}
	
};
?>
