<?php
	require_once '../../autoload.php';
	require( '../GetDataFromDB.php' );

	RightsCheck ("VIEW_STAFFMEMBER");

	$toProcess = true;
	
	$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']);
	}

	$whereclause2='';
  
  	if(isset($_GET['hasactivejob']))
  	{
	  	if($_GET['hasactivejob']=='false')
			$whereclause2 = "where jobactif!=".$_GET['hasactivejob']."::integer";
  	}

  	// $psql = "select id,lastname,firstname,login,password,email,active::integer,login_role_id, ris_name, pacs_name, dacs_name from staff_member where removed = false";

  	$psql = "select staff_member.id,lastname,firstname,login,password,email,active::integer,login_role_id, ris_name, pacs_name, dacs_name,civility_id, civilitylist.name as civility_name from staff_member left join civilitylist on staff_member.civility_id=civilitylist.id where removed = false";

	
	$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;
	
 
?>