<?php
	session_name("eoQUAL");
	session_start();

	if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === TRUE )
	{
		unset($_SESSION['autolog']);
	}
	else
	{
		//autologon
		$_SESSION['loggedin'] = TRUE;
		$_SESSION['autolog'] = 1;
	}

	session_commit();

	include '../autoload.php';

	// include 'SurveyCompletingRender.php';

	// echo "<div>Blabla</div>";


?>


<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<title>Enquête de satisfaction</title>
		<link rel="stylesheet" href="/eoQUALBootstrap/eoQUAL/SubFW/css/paper.css">
	</head>

	<body class="A4">
		
		<section class="sheet" style="padding: 5px; height: auto !important;min-height: 297mm;">

			<?php
			$rootPath = $GLOBALS['approot'];

			$tags_id 		= $_REQUEST['tags_id'];

			error_log ( "tags_id : " .$tags_id );

			$pdo = getPDO ();
			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    		// $stmt = $pdo->prepare ( "SELECT photo,lastname FROM staff_member WHERE id = :id" );
    		// $stmt->bindParam ( ':id', $id, PDO::PARAM_INT );
    		// $stmt = $pdo->prepare ( "SELECT id,UPPER(lastname) as lastname,firstname FROM staff_member where removed=false order by lastname" );
    		// select * from v_staffmember_taglistdep_active_staffjob where taglistdep_id @> string_to_array('3,12',',')::int[]

    		$stmt = $pdo->prepare ( "SELECT id,UPPER(lastname) as lastname,firstname FROM staff_member sm,v_staffmember_taglistdep_active_staffjob vsm where sm.removed=false and sm.id=vsm.staff_id and vsm.taglistdep_id @> string_to_array('{$tags_id}',',')::int[] order by lastname" );

    		$stmt->execute();
    
    		$results = $stmt->fetchAll ( PDO::FETCH_ASSOC );

    		

    		echo '<div class="container m-0 p-0" style="position: relative !important;">';

    		// echo '<button id="floating_print_button" onclick="window.print()">Imprimer...</button>';

    		echo 	'<div class="row row-cols-auto m-0 p-0">';
			for ( $i=0; $i<count($results); $i++ )
			{
				$row = $results[$i];

				$id 		= $row ['id'];
    			$lastname	= $row ['lastname'];
    			$firstname	= $row ['firstname'];

    			echo '<div class="col-sm-3 m-0 p-0 ms-1 mb-2 border">';
    			echo 	'<div class="preview-container1">';
				echo 		"<img src=\"".$rootPath."/eoQUAL/SubFW/database/staff/get_staff_member_image.php?id=".$id."\"/>";
    			echo 	"</div>";
    			echo 	'<div class="m-0 p-0 ps-2 fw-bold">'.$lastname.' '.$firstname.'</div>';
    			echo '</div>';
    		}
    		echo 	'</div>';
    		echo '</div>';
			?>

		</section>

	</body>

</html>
