<?php require_once('../Connections/oprmConn.php');
include('check-admin-session.php'); 

	
$maxRows_getpaysliplist = 20;
$pageNum_getpaysliplist = 0;
if (isset($_GET['pageNum_getpaysliplist'])) {
  $pageNum_getpaysliplist = $_GET['pageNum_getpaysliplist'];
}
$startRow_getpaysliplist = $pageNum_getpaysliplist * $maxRows_getpaysliplist;

//$maxRows_getpaysliplist = 10;
//	$pageNum_getpaysliplist = 0;
//	if (isset($_GET['pageNum_getpaysliplist'])) {
//	  $pageNum_getpaysliplist = $_GET['pageNum_getpaysliplist'];
//	}
//	$startRow_getpaysliplist = $pageNum_getpaysliplist * $maxRows_getpaysliplist;

//select configuration data
mysql_select_db($database_oprmConn, $oprmConn);
$query_getpaysliplist = "SELECT * FROM weby_payslips WHERE status != 'D' order by created_on desc";
$getpaysliplist = mysql_query($query_getpaysliplist, $oprmConn) or die(mysql_error());
$row_getpaysliplist = mysql_fetch_assoc($getpaysliplist);
$totalRows_getpaysliplist = mysql_num_rows($getpaysliplist);

if (isset($_GET['totalRows_getpaysliplist'])) {
	  $totalRows_getpaysliplist = $_GET['totalRows_getpaysliplist'];
	} else {
	  $all_getpaysliplist = mysql_query($query_getpaysliplist);
	  $totalRows_getpaysliplist = mysql_num_rows($all_getpaysliplist);
	}
	$totalPages_getpaysliplist = ceil($totalRows_getpaysliplist/$maxRows_getpaysliplist)-1;

$queryString_getpaysliplist = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_getpaysliplist") == false && 
        stristr($param, "totalRows_getpaysliplist") == false) {
      array_push($newParams, $param);
    }
  }
}



/*$maxRows_getTimeSheet = 10;
$pageNum_getTimeSheet = 0;
if (isset($_GET['pageNum_getTimeSheet'])) {
  $pageNum_getTimeSheet = $_GET['pageNum_getTimeSheet'];
}
$startRow_getTimeSheet = $pageNum_getTimeSheet * $maxRows_getTimeSheet;*/

/*mysql_select_db($database_oprmConn, $oprmConn);
$query_getTimeSheet = "SELECT weby_timesheets.timesheet_id, weby_timesheets.user_id, weby_timesheets.total_hrs, weby_timesheets.hr_rate, weby_timesheets.total_amount, weby_profiles.full_name, weby_projects.project_name, weby_timesheets.created_date, weby_timesheetstatus.status_label FROM weby_timesheets, weby_profiles, weby_projects, weby_timesheetstatus WHERE weby_timesheets.created_by = weby_profiles.user_id  AND weby_projects.projetc_id = weby_timesheets.project_id AND weby_timesheetstatus.status = 'A'  AND weby_timesheetstatus.status_key = weby_timesheets.status AND weby_timesheetstatus.status_label!= 'Deleted' order by weby_timesheets.updated_date desc";
$query_limit_getTimeSheet = sprintf("%s LIMIT %d, %d", $query_getTimeSheet, $startRow_getTimeSheet, $maxRows_getTimeSheet);
$getTimeSheet = mysql_query($query_limit_getTimeSheet, $oprmConn) or die(mysql_error());
$row_getTimeSheet = mysql_fetch_assoc($getTimeSheet);*/

/*if (isset($_GET['totalRows_getTimeSheet'])) {
  $totalRows_getTimeSheet = $_GET['totalRows_getTimeSheet'];
} else {
  $all_getTimeSheet = mysql_query($query_getTimeSheet);
  $totalRows_getTimeSheet = mysql_num_rows($all_getTimeSheet);
}
$totalPages_getTimeSheet = ceil($totalRows_getTimeSheet/$maxRows_getTimeSheet)-1;

$maxRows_getRes = 2;
$pageNum_getRes = 0;
if (isset($_GET['pageNum_getRes'])) {
  $pageNum_getRes = $_GET['pageNum_getRes'];
}
$startRow_getRes = $pageNum_getRes * $maxRows_getRes;*/

/*mysql_select_db($database_oprmConn, $oprmConn);
$query_getRes = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_users.status = 'P' AND weby_profiles.user_id = weby_users.user_id";
$query_limit_getRes = sprintf("%s LIMIT %d, %d", $query_getRes, $startRow_getRes, $maxRows_getRes);
$getRes = mysql_query($query_limit_getRes, $oprmConn) or die(mysql_error());
$row_getRes = mysql_fetch_assoc($getRes);*/

/*if (isset($_GET['totalRows_getRes'])) {
  $totalRows_getRes = $_GET['totalRows_getRes'];
} else {
  $all_getRes = mysql_query($query_getRes);
  $totalRows_getRes = mysql_num_rows($all_getRes);
}
$totalPages_getRes = ceil($totalRows_getRes/$maxRows_getRes)-1;

$maxRows_getRes1 = 5;
$pageNum_getRes1 = 0;
if (isset($_GET['pageNum_getRes1'])) {
  $pageNum_getRes1 = $_GET['pageNum_getRes1'];
}
$startRow_getRes1 = $pageNum_getRes1 * $maxRows_getRes1;*/

/*mysql_select_db($database_oprmConn, $oprmConn);
$query_getRes1 = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_profiles.status = 'A' AND weby_users.status = 'A' AND weby_users.user_role <> 1 AND weby_profiles.user_id = weby_users.user_id order by weby_profiles.profile_id desc";
$query_limit_getRes1 = sprintf("%s LIMIT %d, %d", $query_getRes1, $startRow_getRes1, $maxRows_getRes1);
$getRes1 = mysql_query($query_limit_getRes1, $oprmConn) or die(mysql_error());
$row_getRes1 = mysql_fetch_assoc($getRes1);*/

/*if (isset($_GET['totalRows_getRes1'])) {
  $totalRows_getRes1 = $_GET['totalRows_getRes1'];
} else {
  $all_getRes1 = mysql_query($query_getRes1);
  $totalRows_getRes1 = mysql_num_rows($all_getRes1);
}
$totalPages_getRes1 = ceil($totalRows_getRes1/$maxRows_getRes1)-1;*/


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SS WEB TECHNOLOGIES- Pay Slips</title>
<link rel="stylesheet" href="../css/style.css" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/colorbox.css"> 
<!-- IE Fix for HTML5 Tags -->
<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]-->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" crossorigin="anonymous"><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script>
<style>
.act_payslips  { 
background: #373938;
  color: #fff;}
  .timesheet_table .x-item_wide{
	  width:170px;
	  display:inline-table;
  }
  .timesheet_table .x-big_wide{
	  width:270px;
	  display:inline-table;
  }
.timesheet_table .item_wide:last-child{
	float:right;
}
.timesheet_table .column_title {
	color:#fff;
}
.view_annonce input{
	    margin: 0;
    padding: 0;
    outline: none;
    cursor: pointer;
    background: none;
    color: #428BCA;
    font-weight: bold;
}
.timesheet_table .x-item_wide {
    width: 155px;
    display: inline-table;
}
</style>
<script>
function redirect(){
// var created_by = document.getElementById('created_by').options[document.getElementById('created_by').selectedIndex].value;
// window.location = "payslips-list.php?created_by="+created_by+"";
}
</script>
<?php if(isset($_GET['msgcrtpayslip'])) { $msgcrtpayslip = "Pay slip created successfully"; ?><script>alert("<?php echo $msgcrtpayslip; ?>");</script><?php } ?>
	
<?php if(isset($_GET['msguppayslip'])) { $msguppayslip = "Pay slip updated successfully"; ?><script>alert("<?php echo $msguppayslip; ?>");</script><?php } ?>
	
<?php if(isset($_GET['msgdelpayslip'])) { $msgdelpayslip = "Pay slip deleted successfully"; ?><script>alert("<?php echo $msgdelpayslip; ?>");</script><?php } ?>
</head>

<body>

<!-- Wrapper Starts -->

<div class="wrapper">

  <?php  require_once('../includes/header.php'); ?>
  <?php  require_once('../includes/tools-menu.php'); ?>
  <!-- Content Goes here --> 
  
  <!-- Content Goes here -->
  
  <article class="inside_wrapper clear_fix"> 
    
    <!-- Main Content Goes here -->
    
    <section class="main_content" style="width:100%">
      <h1 style="float:left">Pay Slips List</h1>
      <div class="add_announce"><a href="create-payslip">Create Payslip</a></div>	  <div class="col-sm-2 pull-right"></div>
	  <!-- <div class="welcome_box1 welcome_2box" >



<div class="welcome_txt" ><strong>Select Resource: </strong>
<select name="created_by" id="created_by" onChange="redirect();"><option value="ALL">ALL</option>
<?php /*mysql_select_db($database_oprmConn, $oprmConn);
$query_getSelect = "SELECT weby_users.user_id,  weby_users.caeated_date, weby_profiles.full_name, weby_users.status FROM weby_users, weby_profiles WHERE weby_profiles.user_id = weby_users.user_id AND weby_users.status = 'A' AND weby_profiles.status = 'A' AND weby_users.user_role != '1' ";
$getSelect = mysql_query($query_getSelect, $oprmConn) or die(mysql_error());
$row_getSelect = mysql_fetch_assoc($getSelect);
$totalRows_getSelect = mysql_num_rows($getSelect);
if($totalRows_getSelect>0){ do { ?>
<option value="<?php echo $row_getSelect['user_id']; ?>"  <?php if($row_getSelect['user_id'] == $_GET['created_by']){ ?> selected="selected" <?php } ?> > <?php echo $row_getSelect['full_name']; ?> </option>
<?php } while($row_getSelect = mysql_fetch_assoc($getSelect)); }*/ ?>
</select>
</div>
</div> -->
      
      
      <div class="timesheet_table clear_fix" style="width:915px;">
        <div class="column_title" >
        <span class="item_wide" style="width:180px;">User </span>
		<span class="item_wide" style="width:180px;"> Payslip Month</span>
        <span class="item_wide" style="width:165px;">Number of days</span>
		<span class="x-item_wide" style="width:120px;">Notes</span>
		<!-- <span class="item_wide" style="width:140px;">Status</span>  -->
        <span class="item_wide" style="width:100px;"></span>
        </div>
        <?php if($totalRows_getpaysliplist > 0) { do { ?>
    <div class="row <?php if($n==0) { echo "yellow"; $n=1; } else $n=0; ?>">
	
	<span class="item_wide" style="width:180px;">
	<?php mysql_select_db($database_oprmConn, $oprmConn);
$query_getresource = "SELECT weby_profiles.full_name FROM weby_users, weby_profiles WHERE weby_profiles.user_id = weby_users.user_id AND weby_users.status in ('A','P','R') AND weby_profiles.status = 'A' AND weby_users.user_role != '1' AND weby_profiles.user_id = '$row_getpaysliplist[user_id]'";
$getresource = mysql_query($query_getresource, $oprmConn) or die(mysql_error());
$row_getresource = mysql_fetch_assoc($getresource);
$totalRows_getresource = mysql_num_rows($getresource);
echo $row_getresource['full_name']; ?></span>
  
  <span class="item_wide" style="width:180px;">
  <?php echo $row_getpaysliplist['payslip_month']; ?></span>

  <span class="item_wide" style="width:180px;">
  <?php echo $row_getpaysliplist['number_of_days']; ?></span>

  <span class="item_wide" style="width:180px;">
  <?php echo substr($row_getpaysliplist['payslip_notes'], 0,50).'...'; ?></span>

	
	<span class="item_wide" style="width:180px;">
    <?php 
      if(!empty($row_getpaysliplist['payslip_file'])){
        ?>
          &nbsp;&nbsp;&nbsp;&nbsp;<a href="/RM<?php echo $row_getpaysliplist['payslip_file']; ?>" download target="_BLANK">Download</a>
        <?php 
      }
    ?>
	<form action="view-paylist" method="post" class="view_annonce"> <input type="hidden" name="payslip_id" id="payslip_id" value="<?php echo $row_getpaysliplist['payslip_id']; ?>"><input type="submit" value="View" /></form>
	<form class="delete_annonce" action="delete-paylist" method="post">
	<input type="hidden" name="payslip_id" id="payslip_id" value="<?php echo $row_getpaysliplist['payslip_id']; ?>"><input type="submit" value="Delete" name="delete" id="delete" class="exit" onclick="return confirm('Are you sure you want to delete task?')"/></form></span> </div>
    <?php } while ($row_getpaysliplist = mysql_fetch_assoc($getpaysliplist)); ?>
	
        <div class="nav-right">
<table border="0" align="center" cellpadding="2" style="clear:both">
<tr><td colspan="4" align="center"><?php echo ($startRow_getpaysliplist + 1) ?> to <?php echo min($startRow_getpaysliplist + $maxRows_getpaysliplist, $totalRows_getpaysliplist) ?> of <?php echo $totalRows_getpaysliplist ?></td></tr>

<tr><td align="center"><?php if ($pageNum_getpaysliplist > 0) { // Show if not first page ?><a href="<?php printf("%s?pageNum_getpaysliplist=%d%s", $currentPage, 0, $queryString_getpaysliplist); ?>">&lt;&lt; START</a><?php } // Show if not first page ?></td>

<td align="center"><?php if ($pageNum_getpaysliplist > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_getpaysliplist=%d%s", $currentPage, max(0, $pageNum_getpaysliplist - 1), $queryString_getpaysliplist); ?>">&lt; PREVIOUS</a>
<?php } // Show if not first page ?></td>

<td align="center"><?php if ($pageNum_getpaysliplist < $totalPages_getpaysliplist) { // Show if not last page ?><a href="<?php printf("%s?pageNum_getpaysliplist=%d%s", $currentPage, min($totalPages_getpaysliplist, $pageNum_getpaysliplist + 1), $queryString_getpaysliplist); ?>">NEXT &gt;</a><?php } // Show if not last page ?></td>

<td align="center"><?php if ($pageNum_getpaysliplist < $totalPages_getpaysliplist) { // Show if not last page ?><a href="<?php printf("%s?pageNum_getpaysliplist=%d%s", $currentPage, $totalPages_getpaysliplist, $queryString_getpaysliplist); ?>">LAST &gt;&gt;</a>
<?php } // Show if not last page ?></td>
	</tr>
</table>
</div>
    <?php } else echo "<div class='no-rows'>No payslips found</div>";?>
      </div>
            
    </section>
    
    <!-- Sidebar Goes here -->
    
    <!-- aside class="sidebar">
      <!-- h2>ACTIVE RESOURCES</h2 -->
      <!-- form action="resources-list.php" method="post" id="act_resource_search">
        <input name="search" class="search" type="text" size="30" />
        <input name="submit" type="submit" class="search-sub" value="Search" />
      </form -->
      <?php //if($totalRows_getRes1>0) { do { ?>
      <!-- div class="profile_box"> <a href="resources-view.php?user_id=<?php //echo $row_getRes1['user_id']; ?>"><img src="/RM/images/<?php //if(!empty($row_getRes1['profile_pic'])) echo $row_getRes1['profile_pic']; else echo "black-img.jpg";?>" width="68" /></a>
        <p class="profile_title"><a href="resources-view.php?user_id=<?php //echo $row_getRes1['user_id']; ?>"><?php //echo $row_getRes1['full_name']; ?></a><span class="desig"><br />
          <?php //echo $row_getRes1['job_title']; ?></span></p>
        <p class="profile_desc"><?php //echo $row_getRes1['skill_set']; ?></p>
        <div class="clear-fix">&nbsp;</div>
      </div -->
      <?php // } while ($row_getRes1 = mysql_fetch_assoc($getRes1)); } else { echo "<div>No Active Resources</div>";} ?>
      
      <!-- p><a href="resources-list.php">View all >></a></p -->
    </aside -->
    <div class="clear-fix">&nbsp;</div>
  </article>
  <div class="clear-fix">&nbsp;</div>
  
  <!-- Footer Goes here -->
  
  <?php  require_once('../includes/footer.php'); ?>
</div>
</body>
</html>
