0){
$visit_id = $_GET['visit_id'];
} else {
$visit_id =-1;}
if($_GET['new_user_id']>0){
$new_user_id = $_GET['new_user_id'];
} else {
$new_user_id = -1;
}
if($_GET['contact_id']>0){
$contact_id = $_GET['contact_id'];
} else {
$contact_id = -1;
}
//shop_date
if(ISSET($_GET['shop_date'])){
$shop_date_filter = $_GET['shop_date'];
} else {
$shop_date_filter = current_date();}
//dayname
if($_GET['shop_dayname']=='alldays'){
$shop_dayname = '';
} elseif(isset($_GET['shop_dayname'])) {
$shop_dayname = "AND DAYNAME(DATE(time_in)) = '" . $_GET['shop_dayname'] . "'";
} else {
$shop_dayname = '';
}
//record_count
if($_GET['record_count']>0){
$record_count = $_GET['record_count'];
} else {
$record_count = 40;}
$query_Recordset1 = "SELECT shop_id, shop_hours.shop_visit_id, shop_hours.contact_id, shop_hours.shop_user_role, shop_hours.project_id, DATE(shop_hours.time_in) AS date, DAYNAME(shop_hours.time_in) AS dayname, shop_hours.time_in, shop_hours.time_out, TIME_FORMAT(TIMEDIFF(time_out, time_in),'%k:%i') as et, shop_hours.comment, CONCAT(contacts.last_name, ', ', contacts.first_name, ' ',contacts.middle_initial) AS full_name, contacts.first_name FROM shop_hours
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role=shop_user_roles.shop_user_role_id
LEFT JOIN contacts ON shop_hours.contact_id=contacts.contact_id
WHERE shop_hours.contact_id = {$contact_id} AND DATE(shop_hours.time_in) <= '{$shop_date_filter}' {$shop_dayname} ORDER BY time_in DESC
LIMIT 0, {$record_count};";
$Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error());
//$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_YBDB, $YBDB);
$query_Recordset2 = "SELECT * FROM shops WHERE shop_id = $individual_shop_id;";
$Recordset2 = mysql_query($query_Recordset2, $YBDB) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$shop_date = $row_Recordset2['date'];
$shop_location = $row_Recordset2['shop_location'];
$shop_type = $row_Recordset2['shop_type'];
//sets the default time for users to sign in
$shop_start_time = current_datetime();
$current_date = current_date();
//Action on form update
//shop_log2.php?shop_id=2&visit_id=4
$editFormAction = $_SERVER['PHP_SELF'] . "?contact_id=$contact_id&visit_id=$visit_id";
$editFormAction_novisit = $_SERVER['PHP_SELF'] . "?contact_id=$contact_id";
//if (isset($_SERVER['QUERY_STRING'])) {
// $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
//}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_new") && ($_POST["contact_id"] == "no_selection")){
//if no contact is selected
$error_message = 'Please Select a User
';
} elseif ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_new")) {
$insertSQL = sprintf("INSERT INTO shop_hours (contact_id, shop_id, shop_user_role, time_in, comment, project_id) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['contact_id'], "int"),
GetSQLValueString($individual_shop_id, "int"),
GetSQLValueString($_POST['user_role'], "text"),
GetSQLValueString(dateandtimein($_POST['date'], $_POST['time_in']), "date"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['project'], "text"));
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($insertSQL, $YBDB) or die(mysql_error());
$insertGoTo = "shop_log2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $editFormAction_novisit));
}
//$_POST["MM_insert"] is in the form: FormUpdate_$VisitID OR FormUpdate_142. This line seperates the visit id from the
//list($is_UpdateForm, $visit_id) = split('[_]', $_POST["MM_insert"]);
//Update Record isset($_POST["MM_update"])
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormUpdate")) {
$updateSQL = sprintf("UPDATE shop_hours SET time_out=%s WHERE shop_visit_id=%s",
GetSQLValueString($_POST['time_out'], "date"),
GetSQLValueString($_POST['shop_visit_id'], "int"));
//"2006-10-12 18:15:00"
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
$gotopage = "index.html";
header(sprintf("Location: %s",$editFormAction )); //$editFormAction
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
$updateSQL = sprintf("UPDATE shop_hours SET contact_id=%s, shop_user_role=%s, project_id=%s, time_in=%s, time_out=%s, comment=%s WHERE shop_visit_id=%s",
GetSQLValueString($_POST['contact_id'], "int"),
GetSQLValueString($_POST['user_role'], "text"),
GetSQLValueString($_POST['project'], "text"),
GetSQLValueString(dateandtimein($_POST['date'], $_POST['time_in']), "date"),
GetSQLValueString($_POST['time_out'], "date"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['shop_visit_id'], "int"));
//"2006-10-12 18:15:00"
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
header(sprintf("Location: %s",$editFormAction_novisit )); //$editFormAction
}
//Change Date isset($_POST["MM_update"])
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
$editFormAction = $_SERVER['PHP_SELF'] . "?contact_id=$contact_id&shop_date={$_POST['shop_date']}&shop_dayname={$_POST['dayname']}&record_count={$_POST['record_count']}";
header(sprintf("Location: %s",$editFormAction )); //$editFormAction
}
?>
Shop ID: ; Location: ; Date: ; Shop Type: | |||||||
|