169 lines
5.7 KiB
PHP
169 lines
5.7 KiB
PHP
<?php
|
|
/** \file include\db_workorder.php
|
|
* \brief DI webinterface database functions - workorders
|
|
* \author Bram Lentjes, Core|Vision
|
|
* \version 1.0
|
|
* \date: 10-03-2014
|
|
*
|
|
* This file contains database functions for the workorders
|
|
*/
|
|
|
|
|
|
/**
|
|
* Fetch work order on id
|
|
*
|
|
* Inputs:
|
|
* - project_id: work order id
|
|
*
|
|
* Return: Array containing workorder
|
|
*/
|
|
function fetch_workorder($id) {
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch work orders
|
|
$workorder = db_fetch_data("SELECT * FROM project_werkbon WHERE id='" . $id . "'", 1);
|
|
|
|
// Parse into result
|
|
if (!empty($workorder)) {
|
|
$result = $workorder[0];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch workorder on requested project
|
|
*
|
|
* Inputs:
|
|
* - project_id: Project database id
|
|
*
|
|
* Return: Array containing workorders
|
|
*/
|
|
function fetch_workorder_project($project_id) {
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch work orders
|
|
$workorders = db_fetch_data("SELECT * FROM project_werkbon WHERE project='" . $project_id . "' ORDER BY id DESC", 1);
|
|
|
|
// Parse into result
|
|
if (!empty($workorders)) {
|
|
$result = $workorders;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch workorder on requested project
|
|
*
|
|
* Inputs:
|
|
* - user_id: User database id
|
|
*
|
|
* Return: Array containing workorders
|
|
*/
|
|
function fetch_workorder_user($user_id) {
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch work orders
|
|
$workorders = db_fetch_data("SELECT * FROM project_werkbon WHERE gebruiker='" . $user_id . "' ORDER BY id DESC", 1);
|
|
|
|
// Parse into result
|
|
if (!empty($workorders)) {
|
|
$result = $workorders;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Store workorder in database
|
|
*
|
|
* Inputs:
|
|
* - workorder_info array with workorder info
|
|
*
|
|
* Returns: if store is succesfully stored or not (1/0)
|
|
*/
|
|
function store_workorder($workorder_info){
|
|
GLOBAL $_PAGE_INFO;
|
|
|
|
$query = "INSERT INTO project_werkbon (project, gebruiker, functie, klantnaam, projectnaam_klant, project_beschrijving, project_km, t_begin, t_eind, t_pauze, t_totaal, email, handtekening, naam_ondertekening, datum_ondertekening, latitude, longitude, locatie) VALUES (";
|
|
$query .= "'" . specialchars($workorder_info['project_name']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['user_name']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['function_name']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['company_name_cust']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['project_name_cust']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['project_description']) . "',";
|
|
if (strlen($workorder_info['project_kilometers'])) {
|
|
$query .= "'" . specialchars($workorder_info['project_kilometers']) . "',";
|
|
}
|
|
else {
|
|
$query .= "NULL,";
|
|
}
|
|
$query .= "'" . specialchars(convert_datetime($workorder_info['start_date'],0)) . "',";
|
|
$query .= "'" . specialchars(convert_datetime($workorder_info['end_date'],0)) . "',";
|
|
|
|
// Convert to seconds
|
|
$gethour_min = explode(":" ,$workorder_info['pause_date']);
|
|
$workorder_info['pause_date'] = ($gethour_min[0] * 3600) + ($gethour_min[1] * 60);
|
|
|
|
$query .= "'" . specialchars($workorder_info['pause_date']) . "',";
|
|
|
|
// Convert to seconds
|
|
$gethour_min = explode(":" ,$workorder_info['total_times']);
|
|
$workorder_info['total_times'] = ($gethour_min[0] * 3600) + ($gethour_min[1] * 60);
|
|
|
|
$query .= "'" . specialchars($workorder_info['total_times']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['email']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['workorder_signature']) . "',";
|
|
$query .= "'" . specialchars($workorder_info['signing_name']) . "',";
|
|
|
|
$query .= "'" . specialchars($workorder_info['signing_time']) . "',";
|
|
|
|
// Get latitude and longitude from gps string (example: 51.3434;5.53434)
|
|
$gps = explode(";" ,$workorder_info['workorder_gps']);
|
|
$query .= "'" . specialchars($gps[0]) . "',";
|
|
$query .= "'" . specialchars($gps[1]) . "',";
|
|
$query .= "'" . specialchars($workorder_info['project_location']) . "')";
|
|
|
|
|
|
if(db_store_data($query)){
|
|
// Project filled in
|
|
if( $workorder_info['project_name'] ) {
|
|
require_once("include/report_workorder.php");
|
|
|
|
// Get stored id
|
|
$id = db_fetch_last_id();
|
|
|
|
// Get work order
|
|
$file['filename'] = _("MTinfo") . "_" . strtolower(_("Project")) . "_" . strtolower(_("work order1")) . "_" . str_replace(" ","_",getUser($workorder_info['user_name'])) . "_" . str_replace("-", "", strip_time($workorder_info['start_date'])) . ".pdf";
|
|
$file['mimetype'] = "application/pdf";
|
|
$file['document'] = report_workorder(db_fetch_last_id(), "S");
|
|
|
|
// Send work order
|
|
$extra_receivers = array();
|
|
if (strlen($workorder_info['email'])) {
|
|
$receivers = explode(";",$workorder_info['email']);
|
|
if (is_array($receivers)) {
|
|
foreach($receivers as $receiver) {
|
|
array_push($extra_receivers, array('email' => $receiver, 'i18n' => $_SESSION[$_PAGE_INFO['id']]['i18n']));
|
|
}
|
|
}
|
|
}
|
|
|
|
db_project_send_mail_for_file_upload($workorder_info['project_name'], 'urenadministratie', $file, $extra_receivers);
|
|
}
|
|
|
|
// data succesfully stored in database`
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
?>
|