<?php require_once('../Connections/lancrox.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $theValue) : ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $theValue) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
}
mysqli_select_db( $lancrox, $database_lancrox);
$query_Recordset1 = sprintf("SELECT * FROM admin WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysqli_query( $lancrox, $query_Recordset1) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);


?>
<!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>Welcome</title>
<link href="../macss.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
  <div id="header">
    <div id="main">
      <div id="logo"></div>
      
      <? include('nav.php');?>
    </div>
  </div>
  <div id="thebody">
    <div id="mainbody">
      <p>Welcome <?php echo $row_Recordset1['fullname']; ?></p>
      <p>
        <?php
$sn = 0;
if ($_REQUEST[dgem]==1){$p='Admin';$tb='admin';}
else if ($_REQUEST[dgem]==2){$p='Doctor';$tb='doc';}
else if ($_REQUEST[dgem]==3){$p='pharmacy';$tb='pha';}
else if ($_REQUEST[dgem]==4){$p='Nurse';$tb='nur';}
else if ($_REQUEST[dgem]==5){$p='Lab';$tb='lab';}
else if ($_REQUEST[dgem]==6){$p='Reception';$tb='recp';}
else if ($_REQUEST[dgem]==7){$p='Cashier';$tb='cashi';}
else if ($_REQUEST[dgem]==8){$p='Store Keeper';$tb='store';}

else if ($_REQUEST[dgem]==9){$p='Manager';$tb='manag';}
$initStartLimit = 0;
$limitPerPage = 100;

$startLimit = $_REQUEST['startLimit'];
$numberOfRows = $_REQUEST['rows'];
$sortBy = $_REQUEST['sortBy'];
$sortOrder = $_REQUEST['sortOrder'];

if ($startLimit=="")
{
		$startLimit = $initStartLimit;
}

if ($numberOfRows=="")
{
		$numberOfRows = $limitPerPage;
}

if ($sortOrder=="")
{
		$sortOrder  = "DESC";
}
if ($sortOrder == "DESC") { $newSortOrder = "ASC"; } else  { $newSortOrder = "DESC"; }
$limitQuery = " LIMIT ".$startLimit.",".$numberOfRows;
$nextStartLimit = $startLimit + $limitPerPage;
$previousStartLimit = $startLimit - $limitPerPage;
$sql = "SELECT fullname,logst.datein from logst inner join $tb on $tb.username= logst.username where logst.username = '$_REQUEST[code]' and user='$p' order by logst.datein desc".$orderByQuery.$limitQuery;
//echo $sql."<br>"; status was not pending before n order by desc

$result = mysqli_query($lancrox, $sql);
$row = mysqli_fetch_assoc($sql);
$numberOfRows = mysqli_num_rows($result);
if ($numberOfRows==0) {  
?>
            <?
}
else if ($numberOfRows>0) {

	$i=0;
?>
      </p>
      <h2> View <? echo $p ?> Logs</h2>
      <p>
              <?
if ($_REQUEST['startLimit'] != "")
{
?>
              <a href="<? echo  $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $previousStartLimit; ?>&amp;limitPerPage=<? echo $limitPerPage; ?>&amp;sortBy=<? echo $sortBy; ?>&amp;sortOrder=<? echo $sortOrder; ?>">Previous <? echo $limitPerPage; ?> Results</a>....
              <? } ?>
              <?
if ($numberOfRows == $limitPerPage)
{
?>
              <a href="<? echo $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $nextStartLimit; ?>&amp;limitPerPage=<? echo $limitPerPage; ?>&amp;sortBy=<? echo $sortBy; ?>&amp;sortOrder=<? echo $sortOrder; ?>">Next <? echo $limitPerPage; ?> Results</a>
              <? } ?>
            </p>
      <table width="600" border="0" align="left" cellpadding="3" cellspacing="3">
      <tr>
        <td width="18%"><table width="98%" border="1" align="center" cellpadding="3" cellspacing="3">
          <tr>
            <td width="5%"><a href="<? echo $PHP_SELF; ?>?sortBy=sn&amp;sortOrder=<? echo $newSortOrder; ?>&amp;startLimit=<? echo $startLimit; ?>&amp;rows=<? echo $limitPerPage; ?>"> <b>Sn</b></a></td>
            <td width="24%"><a href="#"><b>Date</b></a></td>
            <td width="71%"><strong>Fullname</strong></td>
            </tr>
          <?
	do 
	{

		


	
	$sn = ++$sn;
$bgColor = ($sn % 2 == 0) ? '#FFFFFF' : '#C0C0C0';
	$fullname = $row[fullname];
		
$datein = $row[datein];

?>
          <tr bgcolor="<? echo $bgColor; ?>">
            <td align="left" valign="top" bgcolor="<? echo $bgColor; ?>"><? echo $sn; ?></td>
            <td align="left" valign="top" bgcolor="<? echo $bgColor; ?>"><?  echo date('d-M-Y  h:i:s A', $datein);?></td>
            <td align="left" valign="top" bgcolor="<? echo $bgColor; ?>"><? echo $fullname; ?></td>
            </tr>
         <?php } while ($row = mysqli_fetch_assoc($result)); ?>  
        </table>          <strong><a href="#"></a></strong></td>
      </tr>
      </table>
      <p>
        <?
if ($_REQUEST['startLimit'] != "")
{
?>
        <a href="<? echo  $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $previousStartLimit; ?>&amp;limitPerPage=<? echo $limitPerPage; ?>&amp;sortBy=<? echo $sortBy; ?>&amp;sortOrder=<? echo $sortOrder; ?>">Previous <? echo $limitPerPage; ?> Results</a>....
        <? } ?>
        <?
if ($numberOfRows == $limitPerPage)
{
?>
        <a href="<? echo $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $nextStartLimit; ?>&amp;limitPerPage=<? echo $limitPerPage; ?>&amp;sortBy=<? echo $sortBy; ?>&amp;sortOrder=<? echo $sortOrder; ?>">Next <? echo $limitPerPage; ?> Results</a>
        <? } ?>
        <br />
              <?
} // end of if numberOfRows > 0 
 ?></p>
      <p>&nbsp;</p>
    </div>
  </div>
</div>
</body>
</html>
<?php
((mysqli_free_result($Recordset1) || (is_object($Recordset1) && (get_class($Recordset1) == "mysqli_result"))) ? true : false);
?>
