<?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 appointmentMultiActions extends GridDataManipulator
{
	
	public function MultiCancelAction($manipulatedIDs)
	{
		$sql = "UPDATE $this->table SET status = 89 WHERE status=91 AND id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();

		$sql = "UPDATE $this->table SET status = 24 WHERE status=25 AND id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();
		
		$sql = "UPDATE $this->table SET status = 21 WHERE status=22 AND id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();
		
		return "{success:true}";
	}

	
	public function MultiRestoreAction($manipulatedIDs)
	{
		$sql = "UPDATE $this->table SET status = 91 WHERE status=89 AND id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();

		$sql = "UPDATE $this->table SET status = 25 WHERE status=24 AND id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();
		
		$sql = "UPDATE $this->table SET status = 22 WHERE status=21 AND id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();
		
		return "{success:true}";
	}
	
	
	public function MultiDeleteAction($manipulatedIDs)
	{
		$sql = "UPDATE $this->table SET status = 3 WHERE id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();
		return "{success:true}";
	}

	
	public function MultiReactivateAction($manipulatedIDs)
	{
		$sql = "UPDATE $this->table SET status = 0 WHERE id IN (".$manipulatedIDs.")";
		if(!$this->db->SQLexecute($sql)) return $this->db->JsonError();
		return "{success:true}";
	}
		
}



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

$tableName = $_POST['RMtable'];

$manipulator = new appointmentMultiActions($db,$_POST['RMtable']);
$comm = $_POST['action'].'Action';
if(method_exists($manipulator,$comm)) {
	$manipulatedIDs = implode(",", json_decode($_POST['selRecords']));
	if ($manipulatedIDs) echo $manipulator->$comm($manipulatedIDs);
}
else 
{
	echo '{success:false,error:"Unknown action!"}';	
}

?>
