<?php require_once('../Connections/oprmConn.php'); include('check-admin-session.php');
if(!isset($_GET['uid'])){

mysql_select_db($database_oprmConn, $oprmConn);
$query_MembersList = "SELECT weby_profiles.user_id, weby_profiles.full_name, weby_leave.leave_id, weby_leave.user_id, weby_leave.start_date, weby_leave.end_date, weby_leave.leave_duration, weby_leave.leave_reason, weby_leave.leave_type_id, weby_leave.status, weby_leave.created_date, weby_users.user_id FROM weby_profiles, weby_leave, weby_users WHERE weby_leave.user_id = weby_users.user_id AND weby_leave.user_id = weby_profiles.user_id AND weby_profiles.status = 'A' order by weby_leave.updated_date desc";
$MembersList = mysql_query($query_MembersList, $oprmConn) or die(mysql_error());
$row_MembersList = mysql_fetch_assoc($MembersList);
$totalRows_MembersList = mysql_num_rows($MembersList);
}
if(isset($_GET['uid'])){
$uidd = $_GET['uid'];
mysql_select_db($database_oprmConn, $oprmConn);
$query_MembersList = "SELECT weby_profiles.user_id, weby_profiles.full_name, weby_leave.leave_id, weby_leave.user_id, weby_leave.start_date, weby_leave.end_date, weby_leave.leave_duration, weby_leave.leave_type_id, weby_leave.leave_reason, weby_leave.status, weby_leave.created_date, weby_users.user_id FROM weby_profiles, weby_leave, weby_users WHERE weby_leave.user_id = weby_users.user_id AND weby_leave.user_id = weby_profiles.user_id and weby_leave.user_id = '$uidd' AND weby_profiles.status = 'A' order by weby_leave.updated_date desc";
$MembersList = mysql_query($query_MembersList, $oprmConn) or die(mysql_error());
$row_MembersList = mysql_fetch_assoc($MembersList);
$totalRows_MembersList = mysql_num_rows($MembersList);
}

Header("Content-Disposition: attachment; filename=leave-list.csv");
?>Resource Name,From Date,To Date,Duration,Leave Type,Reason,Status<?php do { ?>

<?php echo $row_MembersList['full_name']; ?>,<?php echo $row_MembersList['start_date']; ?>,<?php if($row_MembersList['end_date'] != ''){ echo $row_MembersList['end_date']; } ?>,<?php echo $row_MembersList['leave_duration']; ?>,<?php $query_getleavetype = "SELECT * FROM weby_leave_types WHERE status = 'A' AND leave_type_id = '$row_MembersList[leave_type_id]'";
$getleavetype = mysql_query($query_getleavetype, $oprmConn) or die(mysql_error());
$row_getleavetype = mysql_fetch_assoc($getleavetype);
$totalRows_getleavetype = mysql_num_rows($getleavetype);
if($totalRows_getleavetype>0){ echo $row_getleavetype['leave_type_name']; } else { echo '-'; } ?>,<?php echo $row_MembersList['leave_reason']; ?>,<?php if($row_MembersList['status']=="P"){

	   $s = "Pending";} if($row_MembersList['status']=="R"){

	   $s = "Rejected";} if($row_MembersList['status']=="C"){

	   $s = "Cancled";} if($row_MembersList['status']=="A"){

	   $s = "Aproved";}

	    echo $s; ?>
		<?php } while ($row_MembersList = mysql_fetch_assoc($MembersList)); ?>

<?php
mysql_free_result($MembersList);
?>
