<?php

include getenv("DOCUMENT_ROOT")."/include/session_include.php";

//$func->checkAdmin("index.php");

/*
for($i=0; $i<sizeof($_POST); $i++) {
	list($key, $value) = each($_POST);
	$$key = $value;

	if(is_array($value))
	{
		$count = 10;
		for($i = 0; $i < $count; $i ++) {
			if ($value[$i]) echo "ARRAY[$key][$value[$i]]<br>";
		}
	}
	else 	echo "[$key][$value]<br>";
	//print_r($_POST);
}

//exit;
*/

$mode = $_POST['mmode'];

if($mode == "update" && $dr_uid == "") {
			echo 0;
			exit();
}
		
		
$columns = array();
$values = array();

if($mode == "create") {
			$columns[] = "dr_createdate";
			$columns[] = "dr_initial";			
}

$columns[] = "dr_firstname";
$columns[] = "dr_lastname";

$columns[] = "dr_cell";
$columns[] = "dr_status";

	



////////////	
// data
////////////	
if($mode == "create") {
			$values[] = date("YmdHis");
			$values[] = str_replace("\\", "", trim($dr_initial));
}


$values[] = str_replace("\\", "", trim($dr_firstname));
$values[] = str_replace("\\", "", trim($dr_lastname));
$values[] = str_replace("-", "", trim($dr_cell));

$values[] = $dr_status;


//for ($i=0; $i < count($columns); $i++)
//echo "[$columns[$i]][$values[$i]]<br>";
//echo "[UID=$uid][ID=$userid][MAXUID=$maxuid]";
//exit;	

if($mode == "create") {

			$query = "SELECT dr_uid FROM tbl_driver WHERE dr_initial = '".strtoupper(str_replace("\\", "", trim($dr_initial)))."' ";
			$result=$jdb->fQuery($query, "fetch query error");
			
			if ($result['dr_uid'] != ""){
				echo 2;
				exit();
			}
				
			$jdb->iQuery("tbl_driver", $columns, $values);
			echo 1;
			exit();
}

else if($mode == "update") {
			$jdb->uQuery("tbl_driver", $columns, $values, " where dr_uid = '$dr_uid' ");
			echo 1;
			exit();
			
}

exit();

?>