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

	require( '../../GetDataFromDB.php' );
	

	$toProcess = true;

	$description 	= '';

	if ( isset ($_GET ['description'] ) )  		$description 	= $_GET['description'];

	$draw			= $_GET ['draw'];
	$start			= $_GET ['start'];
	$length			= $_GET ['length'];

	$columns 		= $_GET ['columns'];
	$order			= $_GET ['order'];
	$orderCol		= $order [0]['column'];
	$orderDir		= $order [0]['dir'];
	$orderColName	= $columns [$orderCol]['data'];
	$orderby		= " ORDER BY ".$orderColName." ".$orderDir;

	$limit = '';


	if ( isset($_GET['start']) && $_GET['length'] != -1 )
	{
		$limit = " OFFSET ".intval($_GET['start'])." LIMIT ".intval($_GET['length']);
	}

	$G_MODIDENTITY_STATUS = array("0"=>"New","1"=>"Active","2"=>"Rejected");

	$mod_id = -1;
	if ( isset($_GET ['mod_id'] ) ) $mod_id = $_GET['mod_id'];

	$psql =	"select
				modident_id,
				mod_id,
				modality_identity.device_uid as device_uid,
				stationname,
				stationaet,
				performedstationname,
				performedstationaet,
				manufacturer,
				manufacturermodel,
				status,
				CASE
					WHEN status=0 THEN 'New'
					WHEN status=1 THEN 'Active'
					WHEN status=2 THEN 'Rejected'
					ELSE 'Unknow'
				END as status_label
			from
				modality_identity where mod_id=".$mod_id;


	error_log ( "GetAFCNExamList : " .$psql );

		$recordsTotal 		= 1000;
		$recordsFiltered	= 0;

		$data				= Array ();

		if ( $toProcess == true )
				$data = GetDataFromDB ( $psql, $recordsFiltered, $limit, $orderby );

		$arr = array (
				"draw"            => intval( $draw ),
				"recordsTotal"    => intval( $recordsTotal ),
				"recordsFiltered" => intval( $recordsFiltered ),
				"data"            => $data,
				"sql"			  => $psql.$orderby.$limit
			);

		$result = json_encode ( $arr );

		echo $result;

?>