<?php

session_start();?>
<?php
ob_start();?>

<?php require_once('open_connection.php');?>
<!--link href='blue/style.css' rel='stylesheet' type='text/css' /-->
<link href='css/imagetable.css' rel='stylesheet' type='text/css' />
<html>
<head>
      <title>PICCSB e-Directory System</title>

</head>
<body bgcolor="#333333"> 
<table width="100%" border="0" align="center">
<tr>
<td width="15%" bgcolor="#333333">&nbsp;</td>
<td width="70%" align="center" bgcolor="#FFFFFF" > 

<table width="100%" border="0" align="center">

<!-- row for header picc 1 -->
<tr>  
     <th width="100%" colspan="4"><img src="images/header-cox.jpg" width="100%" height="30%"></th>
</tr>
<!-- row for header picc 2 -->
<tr>
     <th width="100%" colspan="4"><img src="images/eoffice-cox.jpg" width="100%" height="40%"></th>
</tr>
<!-- calling frame -->	
<tr>
    <td colspan="1" width="100%" align="center"><?php include("header.php");?></td>
	
</tr>
<tr>

<td colspan="3" width="90%" align="center" >
<tr><td>&nbsp;</td></tr>
<tr><td align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<?php
								echo 'Welcome: ' . $_SESSION['username'];
								?>
							<a href="staff_logout.php"><img src="images/logout3.gif" align="right"></a>
							</td>
</tr>
<tr><td>
<h2 align="center">STAFF ADMIN PAGE</h2>

<form action="staff_admin.php" method="post">
<table border=0 align=center class="imagetable" >
<tr><td>INFO SEARCH</td>
<td><input type="text" name="directory" />
<input type="submit" class="myButton"  value="SEARCH"/>&nbsp;
<input type="button" class="myButton"  value="NEW STAFF"  onClick="window.location.href='staff_insert.php'">&nbsp;
<input type="button" class="myButton"  value="NEW DESIGNATION"    onClick="window.location.href='add_designation.php'">
<!--input type="button" class="myButton"  value="GROUP EMAIL"    onClick="window.location.href='staff_groupemail.php'"-->
<input type="hidden" name="staff_id" value="<?php echo $staff_id; ?>">
 </td>
</tr>
</table>
</form>
<br>

<!--hr /-->
<div align="right">

  <?php
$rowsPerPage =20; 
				$pageNum = $_REQUEST['page']; 
				if(empty($pageNum))
						{
					$offset =0;
					$pageNum=1;
						}
				else
						{
					$offset = ($pageNum - 1) * $rowsPerPage;
						}	
					$result=mysql_query("SELECT * from tbl_dir_staff WHERE staff_name LIKE '%".$_POST[directory]."%' OR staff_section LIKE '%".$_POST[directory]."%' 
					                     OR staff_designation LIKE '%".$_POST[directory]."%' OR staff_emel LIKE '%".$_POST[directory]."%' 
										 OR staff_ext LIKE '%".$_POST[directory]."%' OR staff_hp LIKE '%".$_POST[directory]."%' 
										 OR staff_assign LIKE '%".$_POST[directory]."%' ORDER BY staff_id, staff_ext ASC LIMIT $offset, $rowsPerPage");
		
		  			$i=$offset;
		  
echo "<center><span class=style16><table class=imagetable id=user>";
echo "<thead>";
echo"<tr align='center'><th>NO</th><th  width=300>NAME</th><th  width=80>SECTION</th><th>DESIGNATION</th><th  width=50>EXT NUMBER</th><th width=150>HP NUMBER</th><th>EMAIL</th><!--th>ASSIGN NAME</th--><th colspan=2>ACTION</th></tr>";
echo "</thead>";
echo "<tbody>";	 
while($row=mysql_fetch_array($result))
{
					 $staff_id = $row['staff_id']; 
		 		   $staff_name = $row['staff_name'];
		        $staff_section = $row['staff_section'];
		    $staff_designation = $row['staff_designation'];
				    $staff_ext = $row['staff_ext'];
			         $staff_hp = $row['staff_hp'];
			 	   $staff_emel = $row['staff_emel'];
				//$staff_assign = $row['staff_assign'];
			$i++;
					echo"<tr>";
						echo "<td align=center>".$i."</td>";
						echo "<td align=left >".$row['staff_name']."</td>";
						echo "<td>".$row['staff_section']."</td>";
						echo "<td>".$row['staff_designation']."</td>";
						echo "<td>".$row['staff_ext']."</td>";
						echo "<td>".$row['staff_hp']."</td>";
						echo "<td>".$row['staff_emel']."</td>";
						//echo "<td align=center >".$row['staff_assign']."</td>";
						echo "<td align=center >"."<a href=staff_update.php?staff_id=$staff_id>Update</a>"."</td>";
						echo "<td align=center >"."<a href=staff_delete.php?staff_id=$staff_id>Delete</a>"."</td>";
					echo"</tr>";
					}
					
					echo "</span></table>";
echo "</tbody>";
//mysql_close($con);

?>
  <tr><td>
  <div align="right"> <span class="style16"  >
    <?php
				$query1 = "SELECT COUNT(staff_id) AS numrows FROM tbl_dir_staff";
				$result1 = mysql_query($query1) or die('Error, query failed');
				$row1 = mysql_fetch_array($result1, MYSQL_ASSOC);
				$numrows = $row1['numrows'];
				$maxPage = ceil($numrows/$rowsPerPage);
				// print the link to access each page
				$self = $_SERVER['PHP_SELF'];
				$nav = '';
				for($page = 1; $page <= $maxPage; $page++){
				if ($page == $pageNum){
				$nav .= " $page ";}
				else{
				$nav .= " <a href=\"$self?page=$page\">$page</a> ";
					}
				}
				if ($pageNum > 1)
				{
					$page = $pageNum - 1;
					$color="#FFFFFF";
					$prev = " <a href=\"$self?page=$page\">[Previous]</a> ";
					$first = " <a href=\"$self?page=1\">[First]</a> ";
				}
					else{
					$prev = ' ';
					$first = ' ';
				}
					if ($pageNum < $maxPage)
				{
						$page = $pageNum + 1;
						$next = " <a href=\"$self?page=$page\">[Next]</a> ";
						$last = " <a href=\"$self?page=$maxPage\">[Last]</a> ";
				}
					else{
					$next = ' ';
					$last = ' ';
				}
		echo  $first . $prev . $nav . $next . $last;?>
  </span></div>
  </td>
  </tr>
  
</div>
</body>
<script type='text/javascript' src='tablesorter/jquery-latest.js'>
</script>
<script type='text/javascript' src='tablesorter/jquery.tablesorter.min.js'>
</script>


<script type='text/javascript'>
	$(document).ready(function() { 
		$("#user").tablesorter({ 
			//for example we want to disable the 
			//password column (5th column) from sorting
			//we will specify '4' since it was indexed
			//(count starts at '0')
			//and set its property to 'false'
			headers: { 
				8: {    
					sorter: false 
				}
			}
		}); 
	});
	
</script>
  </td></tr>
  
  </div>
  </td></tr>
<!-- row for footer -->	
<tr>
	<th align="center" colspan="4">
	<?php include ('footer.php'); ?>
		
	</th>
</tr>

<!--- end for ruang kerja 80% -->
</table>

</td>

<td width="15%" bgcolor="#333333">&nbsp;</td>

</tr>

<!--- end for ruang kerja 100% -->
</table>

</body>
</html>


