<?php 
class CActionConfigModule extends CActionBase
{
	function doAction()
	{
		$ret = 0;
		$job = $_POST["job"];
		switch($job)
		{
			case "add":
				$ret = $this->Add();
			break;
			case "mod":
				$ret = $this->Mod();
			break;
			case "del":
				$ret = $this->Del();
			break;
		}
		
		return $ret;
	}	
	
	function Add()
	{
		$project_id	 = $_POST["project_id"];
		$parent_id = $_POST["parent_id"];
		$module_name = $_POST["module_name"];
		$module_desc = $_POST["module_desc"];
		$manager_id = $_POST["manager_id"];
		$module_id = $this->db->GetMaxField('tb_project_module', 'module_id')+1;
		
		$sql = "insert into tb_project_module (module_id,parent_module_id,project_id,user_id,module_name,module_desc) values (";
		$sql = $sql . $module_id . ",";
		$sql = $sql . $parent_id . ",";
		$sql = $sql . $project_id . ",";
		$sql = $sql . $manager_id . ",";
		$sql = $sql . "'".$module_name."',";
		$sql = $sql . "'".$module_desc."'";
		$sql = $sql . ")";
		//return $sql;
		$this->db->ExeSql($sql);
		
		return 0;
	}
	
	function Mod()
	{
		$module_id = $_POST["module_id"];
		$module_name = $_POST["module_name"];
		$module_desc = $_POST["module_desc"];
		$manager_id = $_POST["manager_id"];
		
		$sql = "update tb_project_module set ";
		$sql = $sql . "module_name ='".$module_name."',";
		$sql = $sql . "module_desc ='".$module_desc."',";
		$sql = $sql . "user_id = ".$manager_id;		
		$sql = $sql . " where module_id=".$module_id;
		$this->db->ExeSql($sql);
		
		return 0;
	}
	
	function Del()
	{
		$module_id = $_POST["module_id"];
		require_once("../module/module.base.php");
		require_once("../module/module.project_module.php");
		$module = new CModuleProjectModule();
		$module->InitModule($module_id);
		$module->module->DelTree($this->db);
		//$sql = "delete from tb_project_module where module_id=".$module_id;
		//$this->db->ExeSql($sql);
		
		return 0;
	}
	
};
?>
