<?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 editmobile(vrec,id) {

	

var mobile_buildnumber = 'mobile_buildnumber['+vrec+']';
var mobile_name = 'mobile_name['+vrec+']';
var mobile_active = 'mobile_active['+vrec+']';



var mobile_buildnumber = document.getElementById(mobile_buildnumber).value;
var mobile_name = document.getElementById(mobile_name).value;

if(document.getElementById(mobile_active).checked)

var mobile_active = 1;
else 
var mobile_active = 0;



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_mobile_Actions.php?mobile_id="+id
											+"&mobile_buildnumber="+mobile_buildnumber
											+"&mobile_name="+mobile_name
									
											+"&mobile_active="+mobile_active
											+"&actionmode=editmobile",true);


xmlhttp.send();



}

function insertmobile(vrec) {

	

var mobile_buildnumber = 'mobile_buildnumber['+vrec+']';
var mobile_name = 'mobile_name['+vrec+']';
var mobile_active = 'mobile_active['+vrec+']';




var mobile_buildnumber = document.getElementById(mobile_buildnumber).value;
var mobile_name = document.getElementById(mobile_name).value;

if(document.getElementById(mobile_active).checked)

var mobile_active = 1;
else 
var mobile_active = 0;

alert(mobile_active);

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_mobile_Actions.php?&mobile_buildnumber="+mobile_buildnumber
											+"&mobile_name="+mobile_name
											+"&mobile_active="+mobile_active
								
											+"&actionmode=insertmobile",true);


xmlhttp.send();



}

function editmobile2(id,vrec) {
var mobile_active = 'mobile_active['+vrec+']';


if(document.getElementById(mobile_active).checked)

var mobile_active = 1;
else 
var mobile_active = 0;

if (mobile_active == 1) 
var str = "Are You Sure Do You Want To Set This Phone Active";
else 
var str = "Are You Sure Do You Want To Set This Phone Inactive";
if (confirm (str)){


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_mobile_Actions.php?mobile_id="+id+"&actionmode=editmobile2&mobile_active="+mobile_active,true);

xmlhttp.send();

	}



}




function deletemobile(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_mobile_Actions.php?mobile_id="+id+"&actionmode=deletemobile",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'});
		});
	
	
	
	
	});
	
	
</script>


<title>Mobiles</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">Mobiles</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;

if($loadclients == 1 && $fromdate != "" && $todate != "") {

$query = "delete from visits";
$result = mysql_query($query);

$query  = "insert into visits (ledger_number,ledger_name) select distinct client_Code,ledger_name from deliveries
left join ledger on ledger.ledger_number= deliveries.client_code where 1=1";
$query = $query." and delivery_date >= '".explodeword2($fromdate)."'";
$todate2 = explodeword2($todate). " 23:59:59";
$query = $query." and delivery_date <= '".$todate2."'";

$result = mysql_query($query);
$query  = "insert into visits (ledger_number,ledger_name)
 select distinct supplier_Code,ledger_name from porder
left join ledger on ledger.ledger_number= porder.supplier_Codewhere 1=1";
$query = $query." and Porder_date >= '".explodeword2($fromdate)."'";
$todate2 = explodeword2($todate). " 23:59:59";
$query = $query." and Porder_date <= '".$todate2."'";

$result = mysql_query($query);
}
	
	

	
		
		
		
	
	

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:1150px;'><tr align = left><td>";

	
echo"<div id='commission' style='overflow-x:auto;height:450px;width:1150px'>";
draw_mobiles($connection,$config['dbName_log']);
echo"</div></tr>";
echo" <tr align = left><td><br>";

	


echo"</table><br>";

		





echo "<input name='employeeid'  id='employeeid' type='hidden'  >";

echo "<input name='absentismid'  id='absentismid' type='hidden'  >";

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);
if($loadclients == 1 ) {

echo "<script>

x=document.preparing_visits;
document.getElementById('loadclients').value = 0;
x.action='form_preparingvisits.php';
x.submit();


</script>";


}
	function explodeword2($date)
	{

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

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