<?php


session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}
	 
print <<< HERE

<HTML>
<HEAD>
<TITLE> List Of Salesmen </TITLE>

<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top: 2 solid #000000;
				  border-bottom: 1 solid #000000;
				 }
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }

</style>


</HEAD>


HERE;

include("config.inc.php");
include 'function.inc.php';


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to DB");

mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
//maroun 30.03.2011
$querylog="SELECT print as printaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}


if ($printaccess==0 or $printaccess=='')
echo'<BODY oncontextmenu="return false;">';
else
echo'<BODY>';
						
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, report_color1, report_color2 grid_color1, grid_color2, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	//User Access
$querylog=" select ifNull(login_belongstogrp,0) As FI_BelongsToGrp from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);



$flag=0;
    echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'></td></tr></table>";
	echo "<table border=0 width='950' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=120>
		  <col width=470>
		  <col width=300> 
		  <col width=150>";   

	ShowReportHeader1('Salesman Report','portrait', $connection);

	   

		$query = "select ledger_number , ledger_name , salesman_Address , salesman_telephone1 from salesmen";

				 
$colorblue = 'background-color:#ABD4F1';
$colorred = 'background-color : red';
$styletd = 'border-right:1px solid #9494b8; padding-left:2px;';
$styleth = 'border-right:1px solid #9494b8; border-left:1px solid #9494b8; border-top:1px solid #9494b8; border-bottom:1px solid #9494b8;';
$styleth1 = 'border-right:1px solid #9494b8; border-top:1px solid #9494b8; border-bottom:1px solid #9494b8;';

$stylegroup = 'background-color:lightgrey; border-right:1px solid #9494b8 ; border-left:1px solid #9494b8';
	
	echo "<table border=0 cellspacing=0 cellpadding=0>
		  <col width=150>
		  <col width=470>
		  <col width=350> 
		  <col width=80>";
	echo "<tr height='20'>";
	echo "<td align='center' style='$styleth'><b>Number</b></td>";
	echo "<td align='center' style='$styleth1'><b>Name</b></td>";
	echo "<td align='center' style='$styleth1'><b>Address</b></td>";
    echo"<td align='center' style='$styleth1'><b>Phone <b></td>";
    echo "</tr>";
	
$col=0;	
$temp_code = '*';
$result = mysql_query ($query , $connection);
while ( $row = mysql_fetch_row ($result ) ) {
	
			if ( $col%2==0) {
		echo "<tr height='20' style='$colorblue'>";
		echo "<td align='center' style='$styletd ; border-left:1px solid #9494b8;'> $row[0]</td>";
		echo "<td align='center' style='$styletd'>$row[1]</td>";
		echo "<td align='center' style='$styletd'>$row[2]</td>";
		echo"<td align='center' style='$styletd'>$row[3] </td>";
		echo "</tr>";
		}
		else {
		echo "<tr height='20'>";
		echo "<td align='center' style='$styletd; border-left:1px solid #9494b8'>$row[0]</td>";
		echo "<td align='center' style='$styletd'>$row[1]</td>";
		echo "<td align='center' style='$styletd'>$row[2]</td>";
		echo"<td align='center' style='$styletd'> $row[3] </td>";
		echo "</tr>";
		}		
	$col++;
} // end of while 


echo "<tr height=1> <td colspan='4' style=' border-top:1px solid #9494b8' ></td></table>";


function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}

function explodeword($date)
{

	$trim = explode('/',$date);
	$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
	return $trim;
}

if ($printaccess==1)
print <<< HERE





<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
?>