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

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


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

		$s0 = null;

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

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

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

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

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

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