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

include_once (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."_ajaxManipulators/_class/class.treeData.php");
include_once (PATH_TO_ROOT.'webuserspool/UsersPoolinit.php');
include_once(PATH_TO_ROOT."config.php");

$interviewer = '_Interviewer';
$intStructure = '_InterviewerStructure';

class wupTreeManipulator extends TreeDataManipulator
{
	
	function selectAction()
	{
		$id = $_POST['node'];
		//fieds have a special subtree!
		if($id == 4 || substr($id,0,5) == 'field' )
		{
			$this->table = WUP_INTERVIEWERSTRUCTURE;
			$this->lab = 'field_name';
			$_POST['boldRoots'] = false;
			
			if($id == 4)
			{ //we add the extra links
				$node['id'] = 'extraLinks';
				$node['text'] = 'Extra links';
				
				$node['children'][] = array('id' => 'field_projLink','text' => 'Project Link','leaf' => true);
				$node['children'][] = array('id' => 'field_redirectLink','text' => 'Redirect Link','leaf' => true);
				$node['children'][] = array('id' => 'field_removeLink','text' => 'Removal request link','leaf' => true);
				$this->nodes[] = $node;
				
                $node = array();
                $node['id'] = "webPoints";
                $node['text'] = "Web points";
                $node['children'][] = array('id' => 'field_gainedPoints','text' => 'Gained points','leaf' => true);
				$node['children'][] = array('id' => 'field_usedPoints','text' => 'Used points','leaf' => true);
				$node['children'][] = array('id' => 'field_totalPoints','text' => 'Total points','leaf' => true);
                $this->nodes[] = $node;
                
				$_POST['node'] = 0;
			}
			else 
				$_POST['node'] = substr($id,6);
			
				$this->idPrefix = 'field_';
		}
		
		return parent::selectAction();
	}

}

	

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

if($_POST['RMcomp']=='tree')
	$manipulator = new wupTreeManipulator($db,$_REQUEST['RMtable']);

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


?>
