<?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
$page 				= escapeString($_GET['page']) ;
$page_mode 			= escapeString($_GET['page_mode']) ;
$type 				= escapeString($_GET['type']) ;
$search 			= escapeString($_GET['search']) ;
$nomination_id		= escapeString($_GET['nomination_id']) ;

// active menu bar
$active_main_menu   = 'service' ;
$active_sub_menu    = 'ourinbox' ;
$active_menu        = 'ourinbox-nomination-list' ;

// get all branch
$branch_all     = [] ;
$get_branch = $mysqli->query( "SELECT * FROM branch
                               WHERE deleted_at IS NULL " . $user_branch_permission_sql_123 ) ;
if ( $get_branch->num_rows > 0 ){
    while ( $row_branch = $get_branch->fetch_assoc() ){
        $branch_all[$row_branch['branch_id']] = $row_branch['branch_name'] ;
    }
}

// check permission
if ( !permissionCheck($row_user, 'our-nomination-view') ){
	header('Location: index.php') ;
	exit ;
}

// mode type | all list | new | edit
switch($page_mode){
	
	// edit nomination
	case 'new' :
	case 'edit' :

		// check query exsits
		$submit_type = 'new' ;
		$mysqli_page = $mysqli->query("SELECT * FROM nomination
									   WHERE nomination_id = '".$nomination_id."' LIMIT 1");
		if ($mysqli_page->num_rows > 0){
			// keep query value in array
			$row_page    = $mysqli_page->fetch_array(MYSQLI_ASSOC) ;
			$submit_type = 'edit' ;
		}

		// update database
		if ( isset($type) && ( $type == 'new' || $type == 'edit' ) && $_POST['hide'] == 1 ){

			// keep value in variable
			$page_title      = escapeString($_POST['title']) ;
			$page_title      = ($page_title != '' ? $page_title : 'No Title') ;
			if ( $nomination_id == '' ){
				$mysqli->query( "INSERT INTO nomination 
							    ( created_at ) VALUES 
							    ( '".TODAYDATE."' )" ) ;
				$nomination_id = $mysqli->insert_id ;	
			}

			// resize image
	        // set image in variable
			$image 		  = $_FILES["image"]["name"] ;
			$image_query  = '' ;
			$remove_photo = $_POST['remove_photo'] ;
			if ($remove_photo == 1){
				$image = '' ;	
				$image_query = "file = ''," ;
			}

			if ( $image != '' ){
				$get_image = pathinfo($image) ;

				$create_image = reCreateImage('Nomination', $nomination_id, $nomination_id, '', $image, $_FILES["image"]["type"], $_FILES['image']['tmp_name']) ;
				// Image uploads when exists
				if ($create_image['result'] && is_array($create_image['crop']) && count($create_image['result']) > 0){
					$resizeObj = new resize($create_image['original']) ; // Initialise load image
					foreach($create_image['crop'] as $value){
						// Resize image (options: exact, portrait, landscape, auto, crop)
						$resizeObj -> resizeImage($value['width'], $value['height'], $value['type']) ;
						$resizeObj -> saveImage($value['source'], 70) ; // Save image	
					}
					$get_image   = pathinfo($create_image['image']) ;
					$image_query = "file = '".$create_image['image']."'," ;
				}
			}

			$array_branch = [] ;
			foreach ( $_POST['branch'] as $k_branch => $v_branch ){
				$array_branch[] = escapeString( $v_branch ) ;
			}

			// update database
			$mysqli->query( "UPDATE nomination SET
							".$image_query."
							branch                = '/".implode('/', $array_branch)."/',
							status   			  = '".escapeString($_POST['status'])."'
							WHERE nomination_id     = '".$nomination_id."'" ) ;

			$title_en = '' ;
			foreach ( $LANGS as $klang => $vlang ){
				$title        = escapeString( $_POST['title_'.$klang] ) ;
				$content      = escapeString( $_POST['content_'.$klang] ) ;

				if ( $klang  == 'en' ){ $title_en = $title ; }

				checkLangUpdate( 'nomination_translation', 'nomination_id', $nomination_id, $klang, [ 
					'title' 	=> [ 'type' => 'input', 'value' => $title   ], 
					'content' 	=> [ 'type' => 'input', 'value' => $content ]
				] ) ;
			}

			if ( $submit_type == 'new' ){
				pushToBranchUser( $array_branch, [], 'nomination', $nomination_id, 'New Nomination', ( $title_en != '' ? $title_en : 'New nomination has been submitted.' ) ) ;
			}

			// refresh page
			header("Location:app-nomination.php?page_mode=edit&nomination_id=".$nomination_id."&success=1") ;
			$_SESSION['system_result'] = 'success-updated' ;
			exit ;
		}

		if ( ( $page_mode == 'new' && !permissionCheck($row_user, 'our-nomination-new') ) ||
			 ( $page_mode == 'edit' && !permissionCheck($row_user, 'our-nomination-edit') ) ){
			header('Location: app-nomination.php') ;
			exit ;
		}

		// start header here
		include 'requires/page_header.php';
		include 'requires/page_top.php';
		?>

		<div class="warper container-fluid">   	
			<div class="page-header"><h1>Nomination <small><?= $lang[$page_mode] ?></small></h1></div>
			<?php
            if ($_SESSION['system_result'] != ''){
                switch($_SESSION['system_result']){
                    case 'success-updated' :
                        echo '<div class="result_success">'.$lang['Thank you details has been updated'].'</div>' ;	
                    break ;
                }
                unset($_SESSION['system_result']) ;
            }
            ?>
            <div class="panel panel-default">
                <div class="panel-heading"></div>
                <div class="panel-body">
                    <form method="post" class="form-horizontal" id="quotationForm" enctype="multipart/form-data" action="app-nomination.php?page_mode=edit&nomination_id=<?= $nomination_id ?>&type=edit" novalidate="novalidate">

                        <div class="form-group show_branch_action">
                            <div class="col-sm-2 control-label"><?= $lang['branch']?></div>
                            <div class="col-sm-9">
                                <select name="branch[]" class="form-control ui-search-input chosen-select select2-basic-single" multiple required>
                                	<?php
                            		foreach ( $branch_all as $key => $value ) {
                            			echo '<option value="'.$key.'" '. ( strpos( $row_page['branch'], '/'.$key.'/' ) !== false ? 'selected' : '' ) .' >'.$value.'</option>';
                            		}
                                	?>
                                </select>
                            </div>
                        </div>


                        <?php 
                		echo showTabs( 'nomination_translation', 'nomination_id', $nomination_id, [ 
                			'title'   => [
                				'type'    => 'input', 
                				'title'   => $lang['title']
                			], 
                			'content' => [
                				'type'    => 'textarea', 
                				'title'   => $lang['Content']
                			]
                		]) ; 
                    	?>

                        <div class="form-group">
                            <div class="col-sm-2 control-label"><?= $lang['photo']?></div>
                            <div class="col-sm-9">
                                <div class="file_upload">
                                    <div class="file_form">
                                        <input type="hidden" name="hide_image" value="<?= dataFilter($row_page['file']) ?>" />
                                        <input type="hidden" name="remove_photo" value="">
                                        <input type="file" name="image" class="file_button control-label" <?= $input_block ?> />
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php if ($row_page['file'] != ''){ ?>
	                        <div class="form-group form-group-pdf">
	                            <div class="col-sm-2 control-label"><?= $lang['preview']?></div>
	                            <div class="col-sm-9">
	                            	<label class="remove_photo"><input type="checkbox" name="remove_photo" class="ui-checkbox tick" value="1">&nbsp;<?= $lang['Remove File']?></label>
	                            	<a href="<?= PATH.'uploads/Nomination/'.dataFilter($row_page['file']) ?>" target="_blank">
	                            		<img src="<?= PATH.'uploads/Nomination/'.dataFilter($row_page['file']) ?>" style="width:100px;" />
	                            	</a>
		                        </div>
	                        </div>
                        <?php }else{ ?>
                            <input type="hidden" name="remove_photo" value="" />
                        <?php } ?>

                        <div class="form-group">
                            <div class="col-sm-2 control-label">Status</div>
                            <div class="col-sm-9">
                                <select name="status" id="status" class="form-control ui-search-input">
                                	<option value="inactive" <?= ( $row_page['status'] == 'inactive' ? 'selected' : '' ) ?> >Inactive</option>
                                	<option value="active"  <?= ( $row_page['status'] == 'active' ? 'selected' : '' ) ?> >Active</option>
								</select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label"></div>
                            <div class="col-sm-9">
                                <button type="submit" class="btn btn-purple" style="float:right"><?= $lang['submit']?></button>
                                <input type="hidden" name="hide" value="1">
                                <input type="hidden" name="page_status" value="<?= $submit_type ?>">
                            </div>
                        </div>   
                    </form>
                </div>
            </div>
		</div>

		<?php
		
	break ;



	// view nomination
	case 'view' :

		// check query exsits
		$submit_type  = 'new' ;
		$mysqli_page  = $mysqli->query("SELECT a.nomination_id, b.title, b.content FROM nomination a
						   			    LEFT JOIN nomination_translation b ON ( a.nomination_id = b.nomination_id )
									    WHERE a.nomination_id = '".$nomination_id."' LIMIT 1");
		if ($mysqli_page->num_rows == 0){
			exit ;
		}

		$row_page     = $mysqli_page->fetch_assoc() ;

		// update database
		if ( $_POST['hide'] == 1 ){
			$update_status   = escapeString( $_POST['update_status'] ) ;

			foreach ( $_POST['multiple_status'] as $kk => $vv ){
				$mysqli->query( "UPDATE staff_nomination SET
								 status 	   = '".$update_status."'
								 WHERE view_id = '".$kk."'" ) ;

				if ( $update_status == 'rejected' ){
					pushToUserCron( 'staff_nomination', $kk, $vv, 'Nomination', 'Nomination has been reject.' ) ;
				}else{
					pushToUserCron( 'staff_nomination', $kk, $vv, 'Nomination', 'Nomination has been update.' ) ;
				}
			}

			header( "Refresh: 0;" ) ;
			exit ;
		}

		// related staff
		// 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   = 'page_mode='.$page_mode.'&nomination_id='.$nomination_id.'search='.$search ;
		
		// page query
		$mysqli_query = "SELECT a.view_id, a.nomination_so, a.created_at, a.updated_at, a.status, b.staff_id, b.staff_idno, b.staff_name, b.staff_image FROM staff_nomination a
						 LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
						 WHERE a.deleted_at IS NULL AND a.nomination_id = '".$nomination_id."' " . $search_query ;
		$mysqli_list  = $mysqli->query( $mysqli_query." ORDER BY a.view_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';
		?>

		<div class="warper container-fluid">   	
			<div class="page-header"><h1>Nomination <small>View</small></h1></div>

			<form method="post">
            	
                <div class="panel panel-default">
                    <div class="panel-body">
                        <select name="update_status" class="form-control selectpicker">
                            <option value="pending">Pending</option>
                            <option value="approved">Approved</option>
                            <option value="confirmed">Confirmed</option>
                            <option value="rejected">Rejected</option>
                            <option value="cancelled">Cancelled</option>
                        </select>
                        <input type="hidden" name="hide" value="1" />
                        <input type="hidden" name="hide_status" value="action" />
                        <input type="submit" class="btn btn-purple" value="<?= $lang['submit'] ?>" />
                    </div>
                </div>

				<div class="panel panel-default">
	                <div class="panel-heading">Join Staff</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></th>
									<th>So Number</th>
									<th>Profile</th>
									<th>Staff ID</th>
									<th>Name</th>
									<th>Status</th>
									<th>Created At</th>
									<th>Updated At</th>
								</tr>
							</thead>
							<tbody>
								<?php
								if ( $mysqli_list->num_rows > 0 ){
									while ( $row_list = $mysqli_list->fetch_assoc() ){
										$staff_image  = ( $row_list['staff_image'] != '' ? PATH.'uploads/Staff/'.dataFilter($row_list['staff_image']) : '' ) ;

										echo '
										<tr class="odd gradeX">
											<td>' ;
												if ( $row_list['status'] == 'pending' || $row_list['status'] == 'approved' ){
													echo '
													<div class="checkbox multiple_trash">
														<input type="checkbox" name="multiple_status['.$row_list['view_id'].']" class="trash_button" value="'.$row_list['staff_id'].'" />
														<label for="checkbox1"></label>
													</div>' ;
												}
											echo '
											</td>
											<td>'.dataFilter($row_list['nomination_so']).'</td>
										 	<td class="text-center">'.( $staff_image != '' ? '<a href="'.$staff_image.'" target="_blank"><img src="'.$staff_image.'" style="width:80px;" /></a>' : '' ).'</td>
											<td>'.dataFilter($row_list['staff_idno']).'</td>
											<td>'.dataFilter($row_list['staff_name']).'</td>
											<td class="text-center">'.resetStatus($row_list['status']).'</td>
											<td class="text-center">'.resetDateFormat($row_list['created_at']).'</td>
											<td class="text-center">'.resetDateFormat($row_list['updated_at']).'</td>
										</tr>';
									}
								}
								?>
							</tbody>
						</table>
						<?= $page_pagination['page_pagination'] ?>
	                </div>
	            </div>

	        </form>
            
            <div class="panel panel-default">
                <div class="panel-heading"></div>
                <div class="panel-body">
                    <form method="post" class="form-horizontal" id="quotationForm" enctype="multipart/form-data" action="app-nomination.php?page_mode=edit&nomination_id=<?= $nomination_id ?>&type=edit" novalidate="novalidate">

                        <div class="form-group">
                            <div class="col-sm-2 control-label">Title</div>
                            <div class="col-sm-9">
                                <input type="text" name="title" class="form-control ui-search-input" value="<?= dataFilter($row_page['title']) ?>" placeholder="Title" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">Content</div>
                            <div class="col-sm-9">
                            	<textarea name="content" class="content" id="editor1" rows="10" cols="80"><?= dataFilter($row_page['content']) ?></textarea>
		                        <script>
		                        CKEDITOR.replace('editor1') ;
		                        </script>
                            </div>
                        </div>

                        <?php if ($row_page['file'] != ''){ ?>
	                        <div class="form-group form-group-pdf">
	                            <div class="col-sm-2 control-label"><?= $lang['preview']?></div>
	                            <div class="col-sm-9">
	                            	<label class="remove_photo"><input type="checkbox" name="remove_photo" class="ui-checkbox tick" value="1">&nbsp;<?= $lang['Remove File']?></label>
	                            	<a href="<?= PATH.'uploads/Nomination/'.dataFilter($row_page['file']) ?>" target="_blank">
	                            		<img src="<?= PATH.'uploads/Nomination/'.dataFilter($row_page['file']) ?>" style="width:100px;" />
	                            	</a>
		                        </div>
	                        </div>
                        <?php }else{ ?>
                            <input type="hidden" name="remove_photo" value="" />
                        <?php } ?>

                        <div class="form-group">
                            <div class="col-sm-2 control-label">Status</div>
                            <div class="col-sm-9">
                                <select name="status" id="status" class="form-control ui-search-input">
                                	<option value="inactive" <?= ( $row_page['status'] == 'inactive' ? 'selected' : '' ) ?> >Inactive</option>
                                	<option value="active"  <?= ( $row_page['status'] == 'active' ? 'selected' : '' ) ?> >Active</option>
								</select>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

		</div>

		<?php
		
	break ;



	// view nomination
	case 'view_all' :
		
		// query type
		$search_query = '' ;
		$search_name = escapeString($_GET['search_name']) ;
		$search_idno = escapeString($_GET['search_idno']) ;
		$search_mobile = escapeString($_GET['search_mobile']) ;
		$search_mail = escapeString($_GET['search_mail']) ;
		$search_date = ( $_GET['search_date']!= '' ? date('Y-m-d', strtotime($_GET['search_date'])) : '' ) ;
		$search_type = $_GET['search_type'] ;
		
		$search_query = '';

		if( $search_name != ''){
			$search_query .= " AND b.staff_name LIKE '%".$search_name."%'" ;
		}
		if( $search_idno != ''){
			$search_query .= " AND b.staff_idno LIKE '%".$search_idno."%'" ;
		}
		if( $search_mobile != ''){
			$search_query .= " AND b.staff_mobileno LIKE '%".$search_mobile."%'" ;
		}
		if( $search_mail != ''){
			$search_query .= " AND b.staff_email LIKE '%".$search_mail."%'" ;
		}
		if ( $search_date != '' ){
		    $search_query .= " AND a.created_at >= '".$search_date."' " ;
		}
		// search query
		if ($search  != ''){
			$search_query .= " AND ( title LIKE '%".$search."%' )" ;
		}
		if( $search_type != ''){
			$search_query .= " AND a.status IN ('".implode("', '",$search_type)."') " ;
		}

		// related staff
		// 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 = 'search='.$search.'&search_name='.$search_name.'&search_date='.$search_date.'&page_mode='.$page_mode.'&search_idno='.$search_idno.'&search_mobile='.$search_mobile.'&search_mail='.$search_mail;
		
		// page query
		$mysqli_query = "SELECT a.view_id, a.nomination_so, a.created_at, a.updated_at, a.status, b.staff_idno, b.staff_name, b.staff_image FROM staff_nomination a
						 LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
						 WHERE a.deleted_at IS NULL " . $search_query ;
		$mysqli_list  = $mysqli->query( $mysqli_query." ORDER BY a.view_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';
		?>

		<div class="warper container-fluid">   	
			<div class="page-header"><h1>Nomination <small>View</small></h1></div>

		    <div class="panel panel-default" id="basic-table-title">
		        <div class="panel-heading"></div>
		        <div class="panel-body">
		            <form method="get" class="form-horizontal" style="max-width:600px;">
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['Name'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_name" value="<?= $search_name ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['ID No'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_idno" value="<?= $search_idno ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['Mobile'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_mobile" value="<?= $search_mobile ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['email'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_mail" value="<?= $search_mail ?>" class="form-control" />
		                    </div>
		                </div>
	                    <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['date'] ?></label>
		                    <div class="col-sm-9">
		                        <input class="form-control" name="search_date" type="date" value="<?= $search_date ?>" placeholder="Date Resigned">
		                    </div>
		                </div>
	                    <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['status'] ?></label>
		                    <div class="col-sm-9">
		                        <select name="search_type" class="form-control">
		                        	<option value=""><?= $lang['All'] ?></option>
		                        	<option value="pending" <?= ($search_type == 'pending' ? 'selected' : '') ?>>Pending</option>
		                        	<option value="confirmed" <?= ($search_type == 'confirmed' ? 'selected' : '') ?>>Confirmed</option>
		                        	<option value="approved" <?= ($search_type == 'approved' ? 'selected' : '') ?>>Approved</option>\
		                        	<option value="rejected" <?= ($search_type == 'rejected' ? 'selected' : '') ?>>Rejected</option>
		                        	<option value="cancelled" <?= ($search_type == 'cancelled' ? 'selected' : '') ?>>Cancelled</option>
		                        </select>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <div class="col-sm-11">
		                        <input type="hidden" name="page_mode" value="<?= $page_mode ?>" />
		                        <input type="hidden" name="search" value="<?= $search ?>" />
		                        <button type="submit" class="btn btn-purple" style="float:right"><?= $lang['submit'] ?></button>
		                    </div>
		                </div>
		            </form>
		        </div>
		    </div>

				<div class="panel panel-default">
	                <div class="panel-heading">Join Staff</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></th>
									<th>So Number</th>
									<th>Profile</th>
									<th>Staff ID</th>
									<th>Name</th>
									<th>Status</th>
									<th>Created At</th>
									<th>Updated At</th>
								</tr>
							</thead>
							<tbody>
								<?php
								if ( $mysqli_list->num_rows > 0 ){
									while ( $row_list = $mysqli_list->fetch_assoc() ){
										$staff_image  = ( $row_list['staff_image'] != '' ? PATH.'uploads/Staff/'.dataFilter($row_list['staff_image']) : '' ) ;

										echo '
										<tr class="odd gradeX">
											<td>' ;
												if ( $row_list['status'] == 'pending' || $row_list['status'] == 'approved' ){
													echo '
													<div class="checkbox multiple_trash">
														<input type="checkbox" name="multiple_status['.$row_list['view_id'].']" class="trash_button" value="1">
														<label for="checkbox1"></label>
													</div>' ;
												}
											echo '
											</td>
											<td>'.dataFilter($row_list['nomination_so']).'</td>
										 	<td class="text-center">'.( $staff_image != '' ? '<a href="'.$staff_image.'" target="_blank"><img src="'.$staff_image.'" style="width:80px;" /></a>' : '' ).'</td>
											<td>'.dataFilter($row_list['staff_idno']).'</td>
											<td>'.dataFilter($row_list['staff_name']).'</td>
											<td class="text-center">'.resetStatus($row_list['status']).'</td>
											<td class="text-center">'.resetDateFormat($row_list['created_at']).'</td>
											<td class="text-center">'.resetDateFormat($row_list['updated_at']).'</td>
										</tr>';
									}
								}
								?>
							</tbody>
						</table>
						<?= $page_pagination['page_pagination'] ?>
	                </div>
	            </div>

		</div>

		<?php
		
	break ;
	
	// all announcement list
	case 'all' :
	default :
		
		$search_title 		= escapeString($_GET['search_title']) ;
		$search_date 		= ( $_GET['search_date']!= '' ? date('Y-m-d', strtotime($_GET['search_date'])) : '' ) ;
		
		// query type
		$search_query 		= '' ;
		
		// search query
		if( $search_title  != ''){
			$search_query  .= " AND b.title LIKE '%".$search_title."%'" ;
		}
		if ( $search_date  != '' ){
		    $search_query  .= " AND a.created_at like '%".$search_date."%' " ;
		}
		
		// form submit
		if ( $_POST['hide'] == '1' && $_POST['hide_status'] == 'action' ){
			switch($_POST['page_action']){
				case 'trash':
					$mysqli_query 	= "UPDATE nomination SET deleted_at = '".TODAYDATE."' WHERE nomination_id = " ;
					$trash_page 	= trashPage('nomination', $mysqli, $mysqli_query, $_POST['multiple_trash']) ;
				break;
			}
		}
		
		// 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 	= 'search='.$search.'&search_title='.$search_title.'&search_date='.$search_date.'&page_mode='.$page_mode ;
		
		// page query
		$mysqli_query 	= "SELECT a.nomination_id, a.status, a.created_at, b.title FROM nomination a
						   LEFT JOIN nomination_translation b ON ( a.nomination_id = b.nomination_id )
						   WHERE a.deleted_at IS NULL AND b.lang = 'en' " . $search_query . $user_branch_permission_sql_symbol ;
		$mysqli_page 	= $mysqli->query( $mysqli_query." ORDER BY a.nomination_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>Nomination <small><?= $lang['list']?></small></h1>
				<?php if ( permissionCheck($row_user, 'our-nomination-new') ){ ?>
					<a href="app-nomination.php?page_mode=new" class="btn btn-purple" target="_blank"><?= $lang['add_new']?></a>
				<?php } ?>

				<a href="app-nomination.php?page_mode=view_all" class="btn btn-purple" target="_blank">View all</a>
			</div>
			
		    <div class="panel panel-default" id="basic-table-title">
		        <div class="panel-heading"></div>
		        <div class="panel-body">
		            <form method="get" class="form-horizontal" style="max-width:600px;">
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['Subject'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_title" value="<?= $search_title ?>" class="form-control" />
		                    </div>
		                </div>
	                    <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['date'] ?></label>
		                    <div class="col-sm-9">
		                        <input class="form-control" name="search_date" type="date" value="<?= $search_date ?>" placeholder="Date Resigned">
		                    </div>
		                </div>
		                <div class="form-group">
		                    <div class="col-sm-11">
		                        <input type="hidden" name="page_mode" value="<?= $page_mode ?>" />
		                        <input type="hidden" name="search" value="<?= $search ?>" />
		                        <button type="submit" class="btn btn-purple" style="float:right"><?= $lang['submit'] ?></button>
		                    </div>
		                </div>
		            </form>
		        </div>
		    </div>

            <form method="post">
                
                <?php if ( permissionCheck($row_user, 'our-nomination-trash') ){ ?>
                <div class="panel panel-default">
                    <div class="panel-body">
                        <select name="page_action" class="form-control selectpicker">
                            <option value=""><?= $lang['select']?></option>
                            <option value="trash"><?= $lang['move_to_trash']?></option>
                        </select>
                        <input type="hidden" name="hide" value="1" />
                        <input type="hidden" name="hide_status" value="action" />
                        <input type="submit" class="btn btn-purple" value="<?= $lang['submit']?>" />
                    </div>
                </div>
                <?php } ?>

                <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['Action']?></th>
									<th><?= $lang['Subject']?></th>
									<th><?= $lang['status']?></th>
									<th>Created Date</th>
                                    <th width="50"><?= $lang['trash']?></th>
								</tr>
							</thead>
							<tbody>
								<?php
								if ( $mysqli_page->num_rows > 0 ){
									while ( $row_page = $mysqli_page->fetch_assoc() ){

										$staff_nomination    = $mysqli->query( "SELECT view_id FROM staff_nomination
																			  WHERE deleted_at IS NULL AND nomination_id = '".$row_page['nomination_id']."' AND status IN ( 'pending' )" ) ;
										$total_nomination    = $staff_nomination->num_rows ;		  

										echo '
										 <tr class="odd gradeX">
										 	<td class="align_center">' ;
												if ( permissionCheck($row_user, 'our-nomination-edit') ){
													echo '
										 			<a title="Edit Current nomination" href="app-nomination.php?page_mode=edit&nomination_id='.$row_page['nomination_id'].'"><i class="fa fa-edit"></i></a>' ;
												}else{
													echo '-' ;
												}
												echo '
												<span class="split">|</span>
												<a title="View Current nomination" href="app-nomination.php?page_mode=view&nomination_id='.$row_page['nomination_id'].'"><i class="fa fa-eye"></i> ( '.$total_nomination.' )</a>
										 	</td>
											<td>'.dataFilter($row_page['title']).'</td>
											<td class="text-center">'.resetStatus($row_page['status']).'</td>
											<td class="text-center">'.resetDateFormat($row_page['created_at']).'</td>
											<td>
												<div class="checkbox multiple_trash">
													<input type="checkbox" name="multiple_trash['.$row_page['nomination_id'].']" class="trash_button" value="1">
													<label for="checkbox1"></label>
												</div>
											</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>
										<td class="border_none"></td>
										<td class="border_none"></td>
									</tr>' ;
								}
								?>
							</tbody>
						</table>
						<?= $page_pagination['page_pagination'] ?>
                    </div>
                </div>
			</form>
		</div>
		<?php
	break ;

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