<?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']) ;
$today_year       = date('Y', time()) ;
$today_minus_1    = date('Y-m-d', strtotime('-1 days')) ;

// active menu bar
$active_main_menu = 'transaction' ;
$active_sub_menu  = 'uom-list' ;

switch($page_mode){
	case 'list' :
	default :
		// 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_idno='.$search_idno.'&search_ic='.$search_ic.'&search_email='.$search_email.'&search_mobile='.$search_mobile.'&lf_type='.$lf_type.'&lf_branch='.$lf_branch.'&sort_by='.$sort_by.'&sort_by_type='.$sort_by_type.'&gender_12='.$gender_12.'&created_date='.$created_date ;

		// page query
		$mysqli_query = "SELECT * FROM uom
						 WHERE deleted_at IS NULL " . $search_query ;

		$end_form=LIMIT;

		$mysqli_page = $mysqli->query($mysqli_query."ORDER BY $sort LIMIT $start_from, $end_form") ;

		// 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' ;

		// reset sort by type
		$sort_by_type = ( $sort_by_type == 'DESC' ? 'ASC' : 'DESC' ) ;
		?>
			<div class="warper container-fluid">   	
				<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['Action'] ?></th>
									<th><?= $lang['Reference Number'] ?></th>
									<th><?= $lang['Title'] ?></th>
									<th><?= $lang['Company Name'] ?></th>
									<th><?= $lang['Amount'] ?></th>
									<th><?= $lang['created_date'] ?></th>
									<th><?= $lang['status'] ?></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['transaction2_id'] ;
										$staff_idno  = ucwords($row_page['staff_idno']) ;

										if($row_page['gender_id'] == '1'){
											$gender_1=$lang['Male'];
										}else{
											$gender_1=$lang['Female'];
										}

										// staff_birthdate
										$staff_birthdate     = $today_year . date( '-m-d', strtotime( $row_page['staff_birthdate'] ) ) ;

										if ( TODAYDAY == $staff_birthdate || date('Y-m-d', strtotime('-1 days',strtotime($staff_birthdate))) ==  TODAYDAY){
											$last_4_class = 'table-background-green' ;
										}
		
										echo '
										 <tr class="odd gradeX '.$last_4_class.'">
										 	<td class="align_center">
										 		<a title="'.$lang['Edit Current'].$lang['Order'].'2" href="transaction2.php?page_mode=edit&page='.$id.'"><i class="fa fa-edit"></i></a>
										 	</td>
											<td class="align_center">'.dataFilter( $row_page['reference_num'] ).'</td>
											<td class="align_center">'.dataFilter($row_page['title']).'</td>
											<td class="align_center">'.dataFilter( $row_page['company_name'] ).'</td>
											<td class="align_center">'.dataFilter( $row_page['amount'] ).'</td>
											<td class="align_center">'.dataFilter( $row_page['created_at'] ).'</td>
											<td class="align_center domain_'.$row_page['status'].'">'.dataFilter( $row_page['status'] ).'</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>
										<td class="border_none"></td>
									</tr>' ;
								}
								?>
							</tbody>
						</table>
						<?= $page_pagination['page_pagination'] ?>
                    </div>
                </div>
			</form>
		</div>

		<?php
	break;
}

?>