<?php 
include_once ("_dirinfo.php");

include_once (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."_ajaxManipulators/_class/class.treeData.php");
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL ^ E_NOTICE);
class IncentiveopmMan extends TreeDataManipulator {
	
	
	public function selectAction()
	{
		$_POST['SQLwhere'] = 'deleted = 0';
		return parent::selectAction();
	}
	public function insertItemAction()
	{
		$tmp = array();
		//insert one line into properties
		if( $this->db->get($this->table,"idLab = '{$_POST['nodeText']}'") )
		{
			$error = "A project with name '{$_POST['nodeText']}' already exists";
            $tmp['warning'] = $error;
            $tmp['success'] = TRUE;
		}
        else
        {
           $insrt = parent::insertItemAction();
           $tmp = json_decode($insrt,1);
           $id = $tmp['insertId'];
           $sql = "INSERT INTO _IncentiveProperties ( id, start_date, end_date ) VALUES ( $id, '".date("Y-m-d"). "','".date("Y-m-d",time() + 604800 )."' )";
           $this->db->SQLexecute($sql); 
        }    
	
		return json_encode($tmp);
		
	}
	
	public function deleteAction()
	{
	/*	$sql = "DELETE FROM _RedirectLinks WHERE id_project = " .$this->id_project;	
		$this->db->SQLexecute($sql);
		
		$sql = "DELETE FROM _RedirectProperties WHERE id = " .$this->id_project;	
		$this->db->SQLexecute($sql);
		
		$sql = "DELETE FROM _RedirectStatus WHERE id_project = " .$this->id_project;	
		$this->db->SQLexecute($sql);*/
		
		
		//return parent::deleteAction();
		$sql = "UPDATE _IncentiveGroups SET deleted = 1 WHERE id = ".$_POST['nodeId'];
		$this->db->SQLexecute($sql);
		return "{success:true}";
	}
}
	
	
	$db->ChangeDatabase($_POST['database']);
	
	$manipulator = new IncentiveopmMan($db,$_POST['RMtable']);	
	$manipulator->id_project = $_POST['id_project'];
	$comm = $_POST['action'].'Action';
	if(method_exists($manipulator,$comm))
		echo $manipulator->$comm();
	else 
	{
		echo '{success:false,error:"Unknown action!"}';	
	}

?>