<?php
include("../include/session.php");
if( !$session->isAdmin()){
	//header("Location: ../Store/storeMenu.php");?>
<script language="javascript" type="text/javascript">
        <!--
		  window.location="denied.php";
        -->
       </script>
<?php 
}else{
	include("../storeHeader.php");
	
	$timezone = date_default_timezone_get();
    //echo "The current server timezone is: " . $timezone;
	
	date_default_timezone_set('Africa/Khartoum');
	$entryDate = date("Y-m-d H:i:s",time()-3600); 
	//echo "entry date and time: ".$entryDate;
	
	require_once('classes/tc_calendar.php');
	$date = mysql_real_escape_string($_GET['date']);
	
		
	if ($date==1) {
	$start = mysql_real_escape_string($_GET['date1']);
    $end = mysql_real_escape_string($_GET['date2']);
	}
	else {
	$start = date("Y-m-01");
	$end = date("Y-m-d");
	}
	
		
	if ($date!=1) {
	   $ds = "1"; }
	   else {
		$ds = date("d", strtotime($start) );
	   }
	$ms = date("m", strtotime($start) );
	$ys = date("Y", strtotime($start) );
	
	
	$de = date("d", strtotime($end) );
	$me = date("m", strtotime($end) );
	$ye = date("Y", strtotime($end) );
	
	
	$user_name = mysql_real_escape_string($_GET['search_select']);	
	$action = $_GET['action_select'];
	
	
	if ($user_name=="All") {
		  $uq_user = ""; }
		  else { 
			  $uq_user = " AND user = '" . $user_name . "'";
		  }
		  
	if ($action=="All") {
		  $aq_action="";
	}
	else {
	  $aq_action = " AND action = '". $action ."'";
	}
	
		
    $query =  "SELECT * FROM nam_action_tracking WHERE entry_date >= '".$start ."' AND entry_date <= '".$end ."' ". $uq_user . "  " . $aq_action . " ORDER BY entry_date   DESC";
	$result = mySQL_query($query) or die ("Error in query:   $query . * ". mySQL_error());
	$i = 0;
	$num = mysql_num_rows($result);
  

?>
<script type="text/javascript" src="../css/tablesort.js"></script>
<link href="../css/main.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<div class="headerbox2">Action tracking</div><br />
<br />

<div id="coloredContainer">
  <form action="trackingList.php" method="get" name="dateform" class="today" id="dateform">
    from:
    &nbsp;&nbsp;
    <?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2009, 2020);
	 	$myCalendar->writeScript();?>
    &nbsp;&nbsp;to:&nbsp;&nbsp;
    <?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2009, 2020);
		$myCalendar->writeScript();?>
    &nbsp;&nbsp;
    <label>
      <input name="date" type="hidden" id="date" value="1" />
      <br />
    </label>
    
    Select user:
    <select name="search_select" id="search_select" >
<option value="All">All</option>
<option value="daveth">daveth</option>
<option value="Corvanos">Corvanos</option>
<option value="kegor">kegor</option>
<option value="keipelege">keipelege</option>
<option value="<?php echo $user_name ?>"><?php echo $user_name ?></option>
<option value="huubvm">huubvm</option>
    </select>
    </span>&nbsp;&nbsp;Select action:
    <select name="action_select" id="action_select">
      <option value="Delivery">Delivery</option>
      <option value="New customer">New customer</option>
      <option value="New received">New received</option>
      <option value="New Rep:">New Rep</option>
      <option value="New Tocotex account">New Tocotex account</option>
      <option value="New vehicle">New vehicle</option>
      <option value="Store issue">Store issue</option>
      <option value="All">All</option>
      <option value="<?php echo $action  ?>" selected="selected"><?php echo $action ?></option>
    </select>
    <input name="button" type="submit" class="smalllinkbuttonblue" id="button" value="Go" />
  </form>
</div>
<br />

<table width="578" class="sortable-onload-0r rowstyle-alt no-arrow " id="tableList"  >
  <thead>
    <tr>
      <th width="57" class="sortable-date-dmy"><span class="sortable-date-dmy">Date</span></th>
      <th width="49" >Time</th>
      <th width="97" class="sortable-text">User </th>
      <th width="111" class="sortable-text">action</th>
      <th width="240" class="sortable-text">Details</th>
    </tr>
  </thead>
  <tbody>
    <?php 
	while ($i < $num) {
		$b4 = mysql_result($result, $i, "action_id");
	    $b0 = mysql_result($result, $i, "entry_date");
		$b1 = mysql_result($result, $i, "user");
	    $b2 = mysql_result($result, $i, "action");
	    $b3a = mysql_result($result, $i, "details");
		$b3 = $b3a;
		
		if ($b2=="Delivery") { $b3 = " <a href=viewDelivery.php?DelNoText=$b3a> ".$b3a." </a> ";} 
		if ($b2=="New order") { $b3 = " <a href=displayOrder.php?OrderNoText=$b3a> ".$b3a." </a> ";} 
		//if ($b2=="New Rep:") { $b3 = " <a href=displayRep.php?repId=$b3a> ".$b3a." </a> ";} 
			?>
    <tr >
      <td><?php  echo date("d-m-Y", strtotime($b0 )) ?></td>
      <td><?php  echo date("H:i", strtotime($b0 ))  ?></td>
      <td><?php echo $b1?></td>
      <td><?php echo $b2?></td>
      <td><?php echo $b3 ?></td>
    </tr>
    <?php 
	$i++;
	}
	?>
  </tbody>
</table>
<?php
	}
	include("../footer.php");

?>
