<?php
session_start();

if($_SESSION['dbName']==""){
header("location:../index.php");
}
include("config.inc.php");
include("Functions_UserAccess.php");
include("function.inc.php");
include("function2.inc.php");

		
$roundedcorner = '	-moz--radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;';

$vTabFocus = $_POST["vTabFocus"]; if ($vTabFocus == ""){$vTabFocus = $_GET["vTabFocus"];}		
$loadclients =  $_GET["loadclients"];	

$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");

 class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
	var $focusfields=Array();
	var $TabVisibility=Array();
	
function start($name,$connection){

		if (empty($this->active) && CheckTab($name,$_SESSION['dbLabel'],$_SESSION['accessschemaid'],'parameterform',$connection)==1){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run($connection){
	
	//	$focusfields['Info']='clientfirstname';
	//	$focusfields['Locations']='clientlocation';
	//	$focusfields['LoginUser']='accesscode';
		
		$TabVisibility['Parameters']=CheckTab('Parameters',$_SESSION['dbLabel'],$_SESSION['accessschemaid'],'parameterform',$connection);
		
			
		
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
			
				if($TabVisibility[$tabname]==1) {
					$tabid = "tab_".$this->name."_$tabname";
					$contentid = "tabcontent_".$this->name."_$tabname";
					
					$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
					$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
				}
			}
			
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			
			echo "	$jsClear";
			echo "	\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "	\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			echo"	if(fieldname!='')
						document.getElementById(fieldname).focus();";
			echo "}\n";
					
			echo "</script>\n";
			
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$tabfield=$focusfields[$tabname];
				
				if($TabVisibility[$tabname]==1) {
					echo "<DIV CLASS='";
					if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
					echo "' ID='$tabid' ";
					echo "onClick=\"tab_".$this->name."('$tabname','$tabfield');\">$tabname</DIV>\n";
				}
			}
			
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				
				if($TabVisibility[$tabname]==1) {
					echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
					if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
					echo ";'>$tabcontent</DIV>\n";
				}
				else{
					echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display:none ";
					
						echo ";'>$tabcontent</DIV>\n";
				
				}		
			}
			echo "<DIV STYLE='clear: both;'></DIV>";
			echo "</DIV>";
			
		}
	}
}	
	



print <<<HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>

input:focus {border:1px solid #1e87a5;background-color:#f2f2f2;}
select:focus {border:1px solid #1e87a5;}

input:hover {border:1px solid #1e87a5;background-color:#f2f2f2;}
select:hover {border:1px solid #1e87a5;}

#table1:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	cursor:pointer;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;

}
#table2:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table3:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#tabledt1:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#tabledt2:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;

}

#tabledt3:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table5:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table6:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table7:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table8:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}

table.sample {
	border-width: 0px;
	border-spacing: 3px;
	border-style: double;
	border-color: gray;
	border-collapse: collapse;
	background-color: white;
}
table.sample th {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #DCDCDC;
	-moz-border-radius: ;
}
table.sample td {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #E5E5E5;
	-moz-border-radius: ;
}


tablesalary.sample {
	border-width: 0px;
	border-spacing: 3px;
	border-style: double;
	border-color: gray;
	border-collapse: collapse;
	background-color: white;
}
tablesalary.sample th {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #DCDCDC;
	-moz-border-radius: ;
}
tablesalary.sample td {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #E5E5E5;
	-moz-border-radius: ;
}


</style>


<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<link type="text/css" rel="stylesheet" href="js/calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>

<script type="text/javascript">


function editvisit(vrec,id) {


var ledger_number = 'ledger_number['+vrec+']';
var ledger_name = 'ledger_name['+vrec+']';
var visit_latitude = 'visit_latitude['+vrec+']';
var visit_logitude = 'visit_logitude['+vrec+']';



var ledger_number = document.getElementById(ledger_number).value;
var ledger_name = document.getElementById(ledger_name).value;
var visit_latitude = document.getElementById(visit_latitude).value;
var visit_logitude = document.getElementById(visit_logitude).value;




if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {			
					document.getElementById('commission').innerHTML=xmlhttp.responseText;
			
					
					
				
		}
  }

  

xmlhttp.open("GET","form_preparingvisits_Actions.php?visit_id="+id
											+"&ledger_number="+ledger_number
											+"&ledger_name="+ledger_name
											+"&visit_latitude="+visit_latitude
											+"&visit_logitude="+visit_logitude
											+"&actionmode=editvisit",true);


xmlhttp.send();



}

function insertvisit(vrec) {


var ledger_number = 'ledger_number['+vrec+']';
var ledger_name = 'ledger_name['+vrec+']';
var visit_latitude = 'visit_latitude['+vrec+']';
var visit_logitude = 'visit_logitude['+vrec+']';



var ledger_number = document.getElementById(ledger_number).value;
var ledger_name = document.getElementById(ledger_name).value;
var visit_latitude = document.getElementById(visit_latitude).value;
var visit_logitude = document.getElementById(visit_logitude).value;




if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {		
					document.getElementById('commission').innerHTML=xmlhttp.responseText;
			
					
					
				
		}
  }

  

xmlhttp.open("GET","form_preparingvisits_Actions.php?&ledger_number="+ledger_number
											+"&ledger_name="+ledger_name
											+"&visit_latitude="+visit_latitude
											+"&visit_logitude="+visit_logitude
											+"&actionmode=insertvisit",true);


xmlhttp.send();



}




function loadclients2 () {
if (confirm ( "Are you sure you want to load and Delete all the  Record ?")){
x=document.preparing_visits;
document.getElementById('loadclients').value = 1;
x.action='form_preparingvisits.php?loadclients=1';
x.submit();

}
}
function deletevisit(id) {

if (confirm ( "Are you sure you want to Delete this Record ?")){


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('commission').innerHTML=xmlhttp.responseText;
				
				
				}
		}
  }


xmlhttp.open("GET","Form_preparingvisits_Actions.php?visit_id="+id+"&actionmode=deletevisit",true);

xmlhttp.send();

	}



}

</script>

	<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus','.roundedtext_datee', function() {
			$('.roundedtext_datee').datepick({showTrigger: '#calImg'});
		});
	
	
	
	
	});
	
	
</script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus','.roundedtext2', function() {
			$('.roundedtext2').datepick({showTrigger: '#calImg'});
		});
	
	
	
	
	});
	
function showledgers(vwidth,vheight){

	 

	win = window.open('list_ledgerss.php', 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}	
	
	function showusers(vwidth,vheight){

	 

	win = window.open('list_users.php', 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}	
	
	function PrintPreview(exp) {
	for (var i=0; i < document.preparing_visits.groupby.length; i++)
  {
    if (document.preparing_visits.groupby[i].checked)
    {
      var groupby = document.preparing_visits.groupby[i].value;
    }
  }
	
	printerror = document.preparing_visits.r1.value;
	var ledger_number = document.getElementById('ledger_number').value;
	var users = document.getElementById('users').value;
	var fromdate = document.getElementById('fromdate').value;
	var todate = document.getElementById('todate').value;
	window.open("rep_dailyvisits.php?ledger_number="+ledger_number+"&users="+users+"&export="+exp+"&printerror="+printerror+"&fromdate="+fromdate+"&todate="+todate+"&groupby="+groupby,"Rep_Services", "width=900,height=600,screenX=0,left=50,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
}
</script>


<title>Preparing Visits</title>

</head>
<body >
<form  enctype="multipart/form-data"  id='preparing_visits' name='preparing_visits' method='post' >
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='mandatoryfields' value='$vMandatoryFields'>
<input type='hidden' name='loadclients' id ='loadclients' value='$loadclients'>
<input type='hidden' name='user' value='$user' >
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";



				

echo'<table cellpadding="0" cellspacing="0" border="0"  align="center"  class ="layout-width" >';

print <<<HERE

<tr>
  <td  height="26"  valign="top" align=center id='content-top'>
	<table class ="layout-width" border="0" cellpadding="0" cellspacing="0">
	<tr  height='26'>
      <td width="38" height="26">&nbsp;</td>
      <td width="300" valign="middle" height="26" align = left><span class="title">Preparing Visits</span></td><td class='message' valign="middle">&nbsp; $message</td>
	</tr>
	
	</table></td></tr>
HERE;

print <<<HERE



<tr>
  <td  height="34"  valign="top" id='content-top2'>
	<table class ="layout-width" border="0" cellpadding="0" cellspacing="0">
	<tr  >
      <td width="38"  height="34">&nbsp; </td>
	<td valign='middle' height="34">
HERE;


	
	

	
		
		
		
	echo"</td>	<td colspan = 9>
	<button type='button' id='btnClear' name='btnClear' onclick='PrintPreview(0);' title='Print'><span><span>Print</span></span></button>
	<button  type='button'  id='btnExcel' name='btnExcel' onclick='PrintPreview(1); return false;' title='Export'><span><span>Export</span></span></button>
	
	</td></tr>";
	
	
echo"	</table></td></tr>";
echo"<tr height=480><td id='content-body' valign=top align=left>";



echo"<br><table border=0  style='table-layout:fixed;border:0px solid black;border-spacing:0;width:800px;'><tr height = '30' ><td></td><td align = right>";

	

echo"
<span class='style4'>From Date:</span>


";

echo"</td><td align = left><input type='text'   style='width:120px;' readonly  name='fromdate' id='fromdate'    class='roundedtext2' value='".$fromdate."' ".$KeyDown." ></td><td align = right><span class='style4'>User:</span></td><td align = left><input type='text'   style='width:120px;'   name='users' id='users'    class='roundedtext' value='".$users."' ".$KeyDown." >&nbsp;&nbsp;<img src='img/openlist.png' onmouseover=\"style.cursor='pointer'\"  title='Open List' onclick=\"showusers('750','500')\"></td></tr>";
echo "<tr height = '30'><td></td><td align = right><span class='style4'>To Date:</span>&nbsp;</td><td align = left>
<input type='text'   style='width:120px;' readonly  name='todate' id='todate'    class='roundedtext2' value='".$todate."' ".$KeyDown." ></span></span><span class='style4'></td><td align = right><span class='style4'>Ledger Number:</span></td><td align = left><input type='text'   style='width:120px;'   name='ledger_number' id='ledger_number'    class='roundedtext' value='".$ledger_number."' ".$KeyDown." >&nbsp;&nbsp;<img src='img/openlist.png' onmouseover=\"style.cursor='pointer'\" title='Open List' onclick=\"showledgers('750','500')\"></td></tr>";


echo"<tr height = '30'><td></td><td><b>Location</b></td></td>";
echo"<tr height = '30'><td></td>
<td align = left colspan=3>&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp
	<span class='style4'>Right<input type='radio' name='r1' id='r1' checked value='e'>&nbsp;&nbsp
	<span class='style4'>Wrong<input type='radio' name='r1' id='r1' value='o'>&nbsp;&nbsp;&nbsp;
	<span class='style4'>Both<input type='radio' name='r1' id='r1' value='b'>&nbsp;&nbsp;&nbsp;
</td></tr><br>";

echo "<tr height = '30'><td></td><td align = right><span class='style4'>Group By:</span></td><td align = left><input name='groupby'  id='groupby' type='radio' checked value='users' ><span class='style4'>Users</td><td align = right></td><td align = left></td></tr>";
echo "<tr height = '30'><td></td><td align = right><span class='style4'></span></td><td align = left><input name='groupby'  id='groupby' type='radio'  value='clients' ><span class='style4'>Client/Suppliers</td><td align = right></td><td align = left></td></tr>";


echo"</table><br>";

		






echo"   <tr height='30'><td colspan='4' align='center' id='content-bottom' ></td></tr>";

include("footer.php");	
echo" </table>";



if($vTabFocus!=''){
	echo'<script type="text/javascript" language="javascript">';
	echo"tab_('$vTabFocus','');";
	echo'</script>';	
}
	
mysql_close($connection);

	function explodeword2($date)
	{

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

		return $trim;
	}	
echo"</form>";
print <<< HERE
</body>
<html>
HERE;
?>	