<?php

	include_once ("_dirinfo.php");
	include_once (PATH_TO_ROOT."init.php");
	include_once (PATH_TO_ROOT."_ajaxManipulators/_class/class.gridData.php");
	include_once(PATH_TO_ROOT."config.php");
	
	
	class userDefineManipulator extends GridDataManipulator
	{
		public function selectAction()
		{		
			// ready for data manipulation, if needed once...
			$this->addWhere("is_leaf=1");
			$gridData = parent::selectAction();
			$gridData = $this->setFolderGrid($gridData);
			return $gridData; 
		}
		
		
		protected function setFolderGrid($gridData) {
			$searchGrid[] = "\"id_sup\":\"0\"";
			$replaceGrid[] = "\"id_sup\":\"root\"";
			
			$this->db->ChangeDatabase($_POST['database']);
			$sql = "SELECT id,idLab FROM `_userDefineModules` WHERE `is_leaf` =0";
			$res = $this->db->SQLexecute($sql);
			while ($row = $this->db->fetchAssoc($res)) {
				$searchGrid[] = "\"id_sup\":\"".$row['id']."\"";
				$replaceGrid[] = "\"id_sup\":\"".$row['idLab']."\"";
			}
			
			$gridData = str_replace($searchGrid,$replaceGrid,$gridData);
			return $gridData;
		}
		
		
		public function getModulesPropertyAction() {
			$this->db->ChangeDatabase($_POST['database']);
			$sql = "SELECT * FROM `_userDefineModules` WHERE id=".$_POST['nodeId'];
			$res = $this->db->SQLexecute($sql);
			$row = $this->db->fetchAssoc($res);

			return "{success:'ok',file_name:'".$row['file_name']."',module_type:".$row['module_type']."}";
		}
				
	}

	

	$db->ChangeDatabase($_POST['database']);
	

	$manipulator = new userDefineManipulator($db,$_POST['RMtable']);

	$comm = $_REQUEST['action'].'Action';
	if(method_exists($manipulator,$comm))
		echo $manipulator->$comm();
	else 
	{
		echo '{success:false,error:"Unknown action!"}';	
	}


?>