<?php
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");

require_once("include/dbcommon.php");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); 

$query = $_SERVER['QUERY_STRING'];
$parameters = explode( '&', $query);
$parameter = explode( '=', $parameters[0]);

if ($parameter[0] == 'id') {
    $task_id = $parameter[1];
} else {
	addNotification( "error parameter(1)!!!!!! $query" , "Task moved", "fa-envelope",'',1440,Security::getUserName() );
    // echo "error parameter(1)!!!!!!". $query;
    die();
}

$parameter = explode( '=', $parameters[1]);
if ($parameter[0] == 'lane') {
    $lane_name = $parameter[1];
} else {
    addNotification( "error parameter(2)!!!!!! $query" , "Task moved", "fa-envelope",'',1440,Security::getUserName() );
	// echo "error parameter(2)!!!!!!" . $query;
    die();
}

// Update task for lane
global $conn;
$sql="SELECT `idlanes`, `is_end` FROM lanes where `name` = '$lane_name'"; 
$resql=DB::Query($sql);
if ($row = $resql->fetchAssoc()) {
		$lane_id = $row['idlanes'];
		$is_end = $row['is_end'];
		if ( $is_end == 0 ) {
				$sql_2 ="update tasks set `status` = $lane_id, end_date = null, access = 0  where `task_id` = $task_id";
		} else {
				$sql_2 ="update tasks set `status` = $lane_id, end_date = now(), access = 1  where `task_id` = $task_id";
		}
		$resql_2=DB::Exec($sql_2);
		echo "OK";
		// Ok
		addNotification( "Task $task_id moved to $lane_name" , "Task moved", "fa-envelope",'',1440,Security::getUserName() ); 
 
	} else {
		addNotification( "error parameter(3)!!!!!! $lane_name not exist" , "Task moved", "fa-envelope",'',1440,Security::getUserName() );
		// echo "error parameter(3)!!!!!!" . $lane_name ." not exist";
		die();
	}
?>