<!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" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "AD-tracking";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<?php

require_once('../include/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-31");
	}
		
	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) );	 
	
	//$endsearch = date('Y-m-d', strtotime('+1 day', strtotime($end)));
	
	
	
$table_name2 = $_SESSION['db_prefix']."_reports";
$alert_query = "SELECT * FROM $table_name2 WHERE user_name = '".$_SESSION['username']."' AND generated >= '".$start."' AND generated <= '".$end."' ORDER BY report_id DESC ";
$alert_result = mySQL_query($alert_query);
$alert_num = mysql_num_rows($alert_result);


?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/go_to_url.js"  type="text/javascript"></script> 
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 3, "desc" ]],
					"aoColumns": [
								{"iDataSort": 3},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
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>
</head>

<body>
<div class="main_frame" style="height:auto;">
<div class="page_middle_frame" > <label class="label_page_head">Reports</label></div>
        <br />
<br />
<br />
<br />

<div class="page_middle_frame" >	
  <form action="tracking_sales.php" method="get" name="dateform" class="today" id="dateform">
    <table width="686"  id='table_calendar'>
      <tr>
        <td height="20" colspan="3" align="left" valign="middle"><label class="label_std">Select time period to display</label></td>
        <td valign="middle">&nbsp;</td>
        <td colspan="2" valign="middle"><input name="date" type="hidden" id="date" value="1" /></td>
        </tr>
      <tr>
        <td width="12" height="25" valign="middle">&nbsp;&nbsp; </td>
        <td width="43" valign="middle"><label class="label_std">  from:</label> </td>
        <td width="244" valign="middle"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
	 	$myCalendar->writeScript();?></td>
        <td width="31" valign="middle"><label class="label_std">to:</label></td>
        <td width="297" valign="middle"><?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
		$myCalendar->writeScript();?></td>
        <td width="71" valign="middle"><input name="button5" type="submit" class="linkbutton"  id="button5" value="Go" /></td>
        </tr>
    </table>
  </form>
</div>  
<div  class="page_middle_frame">
<table width="680" id="scroll_table" class="data_display" >
  <thead>
  <tr>
    <th>date</th>
    <th >report</th>
    <th>report title</th>
    <th width="64">&nbsp;</th>
    </tr>
   </thead>
<?php 

$i=0;

while ($i<$alert_num) {
    $b0  =  mysql_result($alert_result, $i, "report_id");
	$b1 =  mysql_result($alert_result, $i, "generated");
	$b2 =  mysql_result($alert_result, $i, "report");
	$b3 =  mysql_result($alert_result, $i, "text_id");
	$b4 =  mysql_result($alert_result, $i, "detail_2");
	$b5 =  mysql_result($alert_result, $i, "detail_3");
	
	$table_name = $_SESSION['db_prefix']."_reports_text";
	$text_query = "SELECT report_text FROM $table_name WHERE report_text_id = '".$b3."' ";
	$text_result = mySQL_query($text_query);
	$report_text = mysql_result($text_result, 0, "report_text");
	
	
	$alert='';
	$message='';
	switch ($b2) {
    case 10:
        $alert = 'Sales report';
		
		//$table_name = $_SESSION['db_prefix']."_captured_jobs";
//		$job_query = "SELECT cust_id, designer, value FROM $table_name WHERE job_no = '".$b3."'  ";
//		$job_result = mySQL_query($job_query);
//		$cust_id = mysql_result($job_result, 0, "cust_id");
//		$designer = mysql_result($job_result, 0, "designer");
//		$value = mysql_result($job_result, 0, "value");
//				
//		$table_name = $_SESSION['db_prefix']."_customer";
//		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
//		$cust_name_result = mySQL_query($cust_name_query);
//		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
//		
//		$message = '<a href=../production/captured_job.php?job_no='.$b3.'>J'.$b3.'</a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'>'.$cust_name.'</a>. Value: P'.number_format($value, 2, '.', ',').', designer: '.$designer.', received by: '.$b4.'.';
		$message=$report_text;
        break;
			
	}
	?>
  
  
  <tr>
    <td width="59" align="left" valign="top"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="71" align="left" valign="top" ><?php echo $alert ?><br />
      <br />
      <input name="view_button" type="button" class="linkbutton" id="view_button" onclick="MM_goToURL('parent','reports_view.php?report_text_id=<?php echo $b3 ?>');return document.MM_returnValue" value="View" /></td>
    <td width="466" align="left" valign="top"><div style="height:80px; width:475px; border-color:#06F; overflow:auto;"><?php echo $message ?></div></td>
    <td align="left"><?php echo $b1?></td>
    </tr>
  <?php
  $i++;
}
?>

</table>
</div>

</div>
</body>
<?php } else {
$_SESSION['denied_return'] = "admin_module/user_list.php";	
    include ("../navigation/admin_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</html>