<?php

session_start();

if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include("Functions_UserAccess.php");
include("function.inc.php");
include("function2.inc.php");

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

$visit_id = $_POST["visit_id"]; if ($visit_id == ""){$visit_id = $_GET["visit_id"];}		
$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}		
$ledger_number = $_POST["ledger_number"]; if ($ledger_number == ""){$ledger_number = $_GET["ledger_number"];}		
$ledger_name = $_POST["ledger_name"]; if ($ledger_name == ""){$ledger_name = $_GET["ledger_name"];}		
$visit_latitude = $_POST["visit_latitude"]; if ($visit_latitude == ""){$visit_latitude = $_GET["visit_latitude"];}		
$visit_logitude = $_POST["visit_logitude"]; if ($visit_logitude == ""){$visit_logitude = $_GET["visit_logitude"];}		

if ($actionmode == 'deletevisit') {

$query = "delete from visits where visit_id = '".$visit_id."'";
$result = mysql_query($query);

 draw_preparingvisits($connection);


}

if ($actionmode == 'editvisit') {

$query = "update visits set ledger_number = '".$ledger_number."' , ledger_name ='".$ledger_name."',visit_latitude ='".$visit_latitude."', visit_logitude ='".$visit_logitude."'  where visit_id = '".$visit_id."'";

$result = mysql_query($query);

 draw_preparingvisits($connection);


}

if ($actionmode == 'insertvisit') {

if($visit_latitude=='')
	$visit_latitude=0;

if($visit_logitude=='')
	$visit_logitude=0;




$query = "insert into visits (ledger_number,ledger_name,visit_latitude,visit_logitude) values ('".$ledger_number."','".$ledger_name."',".$visit_latitude.",".$visit_logitude.")";

$result = mysql_query($query);

 draw_preparingvisits($connection);


}



















?>