<?php
include 'connect/cms-config.php' ;
include 'requires/function.php' ;
include 'requires/session.php' ;

// include the class
include 'requires/class_resize.php' ;

// keep parameter in value
$id 				= escapeString($_GET['id']) ;
$page 				= escapeString($_GET['page']) ;
$page_mode 			= escapeString($_GET['page_mode']) ;
$type 				= escapeString($_GET['type']) ;
$search 			= escapeString($_GET['search']) ;

// active menu bar
$active_main_menu 	= 'hr' ;
$active_sub_menu 	= 'hr-announcement' ;
$active_menu 		= 'hr-announcement' ;

// query type
$search_query = '' ;

// pagination
if (isset($page) && !empty($page)) { $product_page = $page ; } else { $product_page = 1 ; } // next and prev page (5 thing need to change)
$start_from = ($product_page - 1) * LIMIT ; //end next and prev page

// set search url
$search_url = 'id='.$id.'&search='.$search ;

// page query
$mysqli_query = "SELECT * FROM announcement_receiver a
				 LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
				 WHERE a.deleted_at IS NULL AND announcement_id = '".$id."' " . $search_query ;
$mysqli_page = $mysqli->query($mysqli_query." ORDER BY a.announcement_receiver_id DESC LIMIT $start_from, " . LIMIT) ;

// load pagination
$page_pagination = nextPrevious($product_page, LIMIT, $search_url, $mysqli_query) ;

// start header here
include 'requires/page_header.php' ;
include 'requires/page_top.php' ;
?>
<!-- Header Ends -->
<div class="warper container-fluid">   	
	
	<div class="page-header">
		<h1><?= $lang['Announcement View']?> <small><?= $lang['list']?></small></h1>
		<a href="hr-announcement.php?page_mode=new" class="btn btn-purple" target="_blank"><?= $lang['add_new']?></a>
	</div>

    <form method="post">
        <div class="panel panel-default">
            <div class="panel-heading"></div>
            <div class="panel-body">
				<table cellpadding="0" cellspacing="0" border="0" class="responsive table table-striped table-bordered" id="basic-datatable">
					<thead>
						<tr>
							<th><?= $lang['Staff Name']?></th>
							<th><?= $lang['status']?></th>
							<th><?= $lang['File']?></th>
							<th><?= $lang['date']?></th>
						</tr>
					</thead>
					<tbody>
						<?php
						if ($mysqli_page->num_rows > 0){
							while ($row_page = $mysqli_page->fetch_array(MYSQLI_ASSOC)){

								// default variable
								$id         = $row_page['announcement_id'] ;
								$staff_idno = ucwords($row_page['staff_idno']) ;

								echo '
								 <tr class="odd gradeX">
									<td>'.dataFilter($row_page['staff_name']).' ('.$staff_idno.')</td>
									<td class="text-center">' ;
										if ( $row_page['announcement_receiver_status'] == 1 ){
											echo '<button class="btn btn-xs bg-red margin" type="button"><b>'.$lang['Pending'].'</b></button>' ;
										}else{
											echo '<button class="btn btn-xs bg-green margin" type="button"><b>'.$lang['view'].'</b></button>' ;
										}
									echo '
									</td>
									<td class="text-center">'.( $row_page['announcement_receiver_sign'] != '' ? '<img src="'.$row_page['announcement_receiver_sign'].'" style="width:150px" />' : '' ).'</td>
									<td class="text-center">'.resetDateFormat($row_page['created_at']).'</td>
								</tr>';
							}
						}else{
							echo '
							<tr class="odd gradeX">
								<td class="border_none">'.$lang['no_data'].'</td>
								<td class="border_none"></td>
								<td class="border_none"></td>
								<td class="border_none"></td>
							</tr>' ;
						}
						?>
					</tbody>
				</table>
				<?= $page_pagination['page_pagination'] ?>
            </div>
        </div>
	</form>
</div>

<?php
// footer
include 'requires/page_footer.php' ;
?>