<?php

session_start();


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

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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

//User Access
$querylog=" select ifNull(login_belongstogrp,0) As FI_BelongsToGrp from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}



$service_description = ereg_replace("'", "\'", $service_description);


if($actionmode=='insert'){
		
	$query="Insert into service (service_description,service_frequency,service_repeattype,service_odometer)
			values ('".$service_description."','".$service_frequency."','".$service_repeattype."','".$service_odometer."')";

	//echo$query;				
	
	$result  = mysql_query($query, $connection);
	$service_id = mysql_insert_id($connection);
	$message = mysql_error();

			   

}

if($actionmodedelete=='delete')
{	
	$query="delete from service where service_Id='".$serviceid."'";
	$result  = mysql_query($query, $connection);
	$message = mysql_error();

	
}


if($actionmode=='edit'){
	$query_update=" update service set	
				service_description='".$service_description."' 
				,service_frequency='".$service_frequency."' 		  
				,service_repeattype='".$service_repeattype."' 
				,service_odometer='".$service_odometer."' 	  
				
				where service_id='".$service_id."'";
					  
	

	$resultedit = mysql_query($query_update, $connection);
	$message    = mysql_error();


}

$message = ereg_replace(' ','%20',$message);

if($actionmode=='delete')			   
	header ("Location: ./Form_ServicesSearch.php?service_id=$service_id&mode=view&message=".$message);
else
	header ("Location: ./Form_Services.php?service_id=$service_id&mode=view&message=".$message);

mysql_close($connection);



?>