<?php
	require_once '../../autoload.php';

	$result = array (
			"status"	=> 'KO',
			"results"	=> -1
	);


	$pdo = getPDO ();
		
	if ( $pdo )
	{
		$dep_id 	= -1;
		
		if ( isset($_POST['dep_id']) )		$dep_id 	= $_POST['dep_id'];

		$s0 = null;

		$sql ="update department set removed = true  where dep_id = :dep_id;";
				
		$s0 = $pdo->prepare ( $sql );

		$s0->bindParam ( ':dep_id',	$dep_id );
		
		if ( $s0->execute () == true )
		{
			$sql ="update room set removed = true  where dep_id = :dep_id;";
			
			$s1 = $pdo->prepare ( $sql );

			$s1->bindParam ( ':dep_id', $dep_id );

			if ( $s1->execute () == true )
			{
				$sql ="update modality set removed = true from room where modality.room_id = room.room_id and  room.dep_id = :dep_id;";
				
				$s2 = $pdo->prepare ( $sql );

				$s2->bindParam ( ':dep_id',	$dep_id );
		
				if ( $s2->execute () == true )
				{
					$result['status'] = 'OK';
					$result['results'] = $dep_id;
				}
			}
		}
	}
	
	header('Content-type: application/json');
	
	echo json_encode ( $result );
?>