3482 lines
132 KiB
PHP
3482 lines
132 KiB
PHP
<?php
|
|
/** \file include\db_project.php
|
|
* \brief DI webinterface database functions
|
|
* \author Rob Schalken, Core|Vision
|
|
* \version 1.0
|
|
* \date 17-10-2008
|
|
*
|
|
* This file contains the project database functions. This file is always included.
|
|
*/
|
|
|
|
|
|
/*
|
|
* Required pages
|
|
*/
|
|
require_once("secure_server.php");
|
|
|
|
/**
|
|
* Search all projects which match current db id customer
|
|
*
|
|
* Inputs:
|
|
* - project_type: Project type (rc/normal/natws)
|
|
* - customer_id: Customer database id
|
|
* - finished All projects (0)/Only unfinished projects(1)/Only finished projects(2)
|
|
* Return: Array containing all projects information
|
|
*/
|
|
function db_search_projects($project_type = "", $customer_id = "", $finished = 0)
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
// Initial return value
|
|
$result = array();
|
|
|
|
if (strlen($customer_id)) {
|
|
$row_customers = array(array(id => $customer_id));
|
|
} else {
|
|
// Search for all underlying customers
|
|
$row_customers = db_search_customers();
|
|
|
|
// Add own id to array => when not in array
|
|
$found_cust = 0;
|
|
if (is_array($row_customers)) {
|
|
foreach ($row_customers as $row_customer) {
|
|
if ($row_customer['id'] == $_PAGE_INFO['login']['customer']['id']) {
|
|
$found_cust = 1;
|
|
}
|
|
}
|
|
}
|
|
if (!$found_cust) {
|
|
$current_customer = db_fetch_customer($_PAGE_INFO['login']['customer']['id'], 1);
|
|
array_push($row_customers, $current_customer);
|
|
}
|
|
}
|
|
|
|
if (is_array($row_customers)) {
|
|
foreach ($row_customers as $row_customer) {
|
|
// Retrieve all project from this customer
|
|
$row_projects = db_fetch_projects("", $row_customer['id'], $finished, $project_type);
|
|
|
|
if (is_array($row_projects)) {
|
|
foreach ($row_projects as $row_project) {
|
|
array_push($result, $row_project);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return array_sort($result, "naam");
|
|
}
|
|
|
|
/**
|
|
* Search all user with projectleider rights (down the pyramid)
|
|
*
|
|
* Return: Array containing all projectsleader from all primair and secundair customers
|
|
*/
|
|
function db_search_projectleaders()
|
|
{
|
|
// Initial return value
|
|
$result = array();
|
|
|
|
// Retrieve all users
|
|
$row_users = db_search_users();
|
|
|
|
// Check if projectleider rights are available
|
|
if (is_array($row_users)) {
|
|
foreach ($row_users as $row_user) {
|
|
if (db_ver_rights_user_one_valid($row_user['id'], "projectleider,projectleider-rc")) {
|
|
array_push($result, $row_user);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch project which match project database id
|
|
*
|
|
* Inputs:
|
|
* - project: Project database id/project name
|
|
* - customer_id: Customer database id
|
|
* - db_id: Project name (0)/ Project database id (1)
|
|
*
|
|
* Return: Array containing project info
|
|
*/
|
|
function db_fetch_project($project, $customer_id = "", $db_id = 0)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch project info (unique)
|
|
if (!$db_id) {
|
|
$row_project = db_fetch_data("SELECT * FROM project WHERE naam='" . specialchars($project) . "' AND klant='" . $customer_id . "' AND parent IS NULL", 1);
|
|
} else {
|
|
$row_project = db_fetch_data("SELECT * FROM project WHERE id='" . $project . "'", 1);
|
|
}
|
|
|
|
// Parse into result
|
|
if (!empty($row_project)) {
|
|
// Convert date (strip off hours/minutes/seconds)
|
|
if (!is_null($row_project[0]['begin'])) {
|
|
$row_project[0]['begin'] = strip_time($row_project[0]['begin']);
|
|
}
|
|
if (!is_null($row_project[0]['eind'])) {
|
|
$row_project[0]['eind'] = strip_time($row_project[0]['eind']);
|
|
}
|
|
|
|
$result = $row_project[0];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch the following project id available
|
|
*
|
|
* Return: String containing number
|
|
*/
|
|
function db_fetch_project_newid()
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
$max_id_project = db_fetch_data("SELECT MAX(id) FROM project", 1);
|
|
|
|
// Parse into result
|
|
if (!empty($max_id_project)) {
|
|
$result = ++$max_id_project[0]['MAX(id)'];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch project periods which match project database id
|
|
*
|
|
* Inputs:
|
|
* - project: Project database id/project name
|
|
* - hide_locked: Hide locked periods
|
|
*
|
|
* Return: Array containing period info
|
|
*/
|
|
function db_fetch_project_periods($project, $hide_locked = TRUE, $hideRemoved = true)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
$query = "SELECT * FROM project WHERE parent='" . $project . "' ";
|
|
|
|
// Hide locked project/periods
|
|
if ($hide_locked) {
|
|
$query .= "AND status!='afgesloten' ";
|
|
}
|
|
|
|
if ($hideRemoved) {
|
|
// Hide removed periods
|
|
$query .= "AND naam not like '" . $project . "_%_#REMOVED#%' ";
|
|
}
|
|
|
|
// Sort by id
|
|
$query .= "ORDER BY id";
|
|
|
|
// Fetch periods info
|
|
$row_period = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_period)) {
|
|
$result = array();
|
|
foreach ($row_period as $period) {
|
|
// Convert date (strip off hours/minutes/seconds)
|
|
$period['begin'] = strip_time($period['begin']);
|
|
$period['eind'] = strip_time($period['eind']);
|
|
|
|
array_push($result, $period);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch projectleaders which match customer id and projectleader with wildcard!!!!
|
|
*
|
|
* Inputs:
|
|
* - customer_id: Customer id
|
|
*
|
|
* Return: Multidimensional array containing all users information
|
|
*/
|
|
function db_fetch_projectleaders($customer_id)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch customer info
|
|
$row_users = db_fetch_data("SELECT * FROM gebruiker WHERE klant='" . $customer_id . "'");
|
|
|
|
// Parse into result
|
|
if (!empty($row_users)) {
|
|
$j = 0;
|
|
for ($i = 0; $i < sizeof($row_users); $i++) {
|
|
if (db_ver_rights_user_one_valid($row_users[$i]['id'], "projectleider,projectleider-rc")) {
|
|
$result[$j] = $row_users[$i];
|
|
$j++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch all project information and project with wildcard!!!!
|
|
*
|
|
* Inputs:
|
|
* - project_id: Project database id
|
|
* - customer_id Customer database id
|
|
* - finished All projects (0)/Only unfinished projects(1)/Only finished projects(2)
|
|
* - Project_type Type of project (RC, normal, NATWS)
|
|
*
|
|
* Return: Array containing projects
|
|
*/
|
|
function db_fetch_projects($project, $customer_id = "", $finished = 0, $project_type = "")
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch customer info
|
|
if (!strlen($customer_id)) {
|
|
$query = "SELECT * FROM project WHERE id='" . $project . "'";
|
|
switch ($finished) {
|
|
case 1:
|
|
$query .= " AND status!='afgesloten' ";
|
|
break;
|
|
case 2:
|
|
$query .= " AND status='afgesloten' ";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (strlen($project_type)) {
|
|
$query .= " AND type='" . $project_type . "' ";
|
|
}
|
|
$query .= "ORDER BY naam";
|
|
} else {
|
|
$query = "SELECT * FROM project WHERE klant='" . $customer_id . "' AND naam LIKE '%" . specialchars($project) . "%' AND parent IS NULL ";
|
|
switch ($finished) {
|
|
case 1:
|
|
$query .= " AND status!='afgesloten' ";
|
|
break;
|
|
case 2:
|
|
$query .= " AND status='afgesloten' ";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (strlen($project_type)) {
|
|
$query .= " AND type='" . $project_type . "' ";
|
|
}
|
|
$query .= "ORDER BY naam";
|
|
}
|
|
|
|
$row_projects = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_projects)) {
|
|
for ($i = 0; $i < sizeof($row_projects); $i++) {
|
|
// Convert date (strip off hours/minutes/seconds)
|
|
$row_projects[$i]['begin'] = strip_time($row_projects[$i]['begin']);
|
|
$row_projects[$i]['eind'] = strip_time($row_projects[$i]['eind']);
|
|
|
|
// Parse result
|
|
$result[$i] = $row_projects[$i];
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch amount of device types
|
|
*
|
|
* Inputs:
|
|
* - project_id: Project database id
|
|
* - device Device type
|
|
*
|
|
* Return: Array containing amount info
|
|
*/
|
|
function db_fetch_project_amounts($project_id, $device)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch project amounts info
|
|
$row_amounts = db_fetch_data("SELECT aantal FROM project_device WHERE project='" . $project_id . "' AND device='" . $device . "'");
|
|
|
|
// Parse into result
|
|
if (!empty($row_amounts)) {
|
|
$result = $row_amounts[0];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch all users attached to project
|
|
*
|
|
* Inputs:
|
|
* - project_id: Project database id
|
|
* - user_id: User database id
|
|
* - part: User part (projectleider, project:a, etc)
|
|
*
|
|
* Return: Array containing project users
|
|
*/
|
|
function db_fetch_project_users($project_id, $user_id = "", $part = "", $level = "")
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
$query = "SELECT gebruiker.*,project_gebruiker.* FROM project_gebruiker,gebruiker WHERE project_gebruiker.project='" . $project_id . "' AND project_gebruiker.gebruiker=gebruiker.id";
|
|
|
|
// Select for specific user
|
|
if (strlen($user_id)) {
|
|
$query .= " AND gebruiker.id='" . $user_id . "'";
|
|
}
|
|
|
|
// Select for specific part
|
|
if ((!is_array($part)) && (strlen($part))) {
|
|
$query .= " AND rol='" . $part . "'";
|
|
} else if (is_array($part)) {
|
|
$query .= " AND (";
|
|
for ($i = 0; $i < sizeof($part); $i++) {
|
|
if ($i) {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " rol='" . $part[$i] . "'";
|
|
}
|
|
$query .= ")";
|
|
}
|
|
|
|
// Select for specific level
|
|
if (strlen($level)) {
|
|
$query .= " AND level='" . $level . "'";
|
|
}
|
|
|
|
// Fetch customer info
|
|
$row_users = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_users)) {
|
|
$result = $row_users;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch all projects attached to user (only on the parent and non projectleider)
|
|
*
|
|
* Inputs:
|
|
* - user_id: User database id
|
|
* - part: Specific user part (projecten:a, projecten:b)
|
|
* - project_type: Project type (normaal/rc)
|
|
* - project_finished: Display finished projects
|
|
* - project_sstatus: Specific project status (can also be array = OR)
|
|
* - project_ostatus: Specific project design status (can also be array = OR)
|
|
* - project_pstatus: Specific project plan status (can also be array = OR)
|
|
*
|
|
* Return: Array containing projects
|
|
*/
|
|
function db_fetch_user_projects($user_id, $part = "", $project_type = "", $project_finished = 1, $project_sstatus = "", $project_ostatus = "", $project_pstatus = "")
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Create query
|
|
$query = "SELECT project_gebruiker.project FROM project_gebruiker,project WHERE project_gebruiker.project=project.id AND project_gebruiker.gebruiker='" . $user_id . "' ";
|
|
|
|
// Specific part?
|
|
if (strlen($part)) {
|
|
// Exception is "schakelen" => Placed on a period not on the parent
|
|
if ($part != "schakelen") {
|
|
$query .= "AND project.parent is NULL AND project_gebruiker.rol='" . $part . "'";
|
|
} else {
|
|
$query .= "AND project_gebruiker.rol='normaal' and project.id in (select parent from project_gebruiker,project where project_gebruiker.project=project.id and gebruiker='" . $user_id . "' and rol='schakelen')";
|
|
}
|
|
} else {
|
|
$query .= "AND project.parent is NULL";
|
|
}
|
|
|
|
// Project type?
|
|
if (strlen($project_type)) {
|
|
$query .= " and project.type='" . $project_type . "'";
|
|
}
|
|
|
|
// Project type?
|
|
if (!$project_finished) {
|
|
$query .= " and project.status!='afgesloten'";
|
|
}
|
|
|
|
// Specific project status?
|
|
if (((!is_array($project_sstatus)) && (strlen($project_sstatus))) && (!is_array($project_sstatus))) {
|
|
$query .= " and project.sstatus='" . $project_sstatus . "'";
|
|
} else if (is_array($project_sstatus)) {
|
|
$query .= " AND (";
|
|
for ($i = 0; $i < sizeof($project_sstatus); $i++) {
|
|
if ($i) {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " project.sstatus='" . $project_sstatus[$i] . "'";
|
|
}
|
|
$query .= ")";
|
|
}
|
|
|
|
// Specific project design status?
|
|
if ((!is_array($project_ostatus)) && (strlen($project_ostatus))) {
|
|
$query .= " and project.ostatus='" . $project_ostatus . "'";
|
|
} else if (is_array($project_ostatus)) {
|
|
$query .= " AND (";
|
|
for ($i = 0; $i < sizeof($project_ostatus); $i++) {
|
|
if ($i) {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " project.ostatus='" . $project_ostatus[$i] . "'";
|
|
}
|
|
$query .= ")";
|
|
}
|
|
|
|
// Specific project plan status?
|
|
if ((!is_array($project_pstatus)) && (strlen($project_pstatus))) {
|
|
$query .= " and project.pstatus='" . $project_pstatus . "'";
|
|
} else if (is_array($project_pstatus)) {
|
|
$query .= " AND (";
|
|
for ($i = 0; $i < sizeof($project_pstatus); $i++) {
|
|
if ($i) {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " project.pstatus='" . $project_pstatus[$i] . "'";
|
|
}
|
|
$query .= ")";
|
|
}
|
|
|
|
// Fetch projects
|
|
$row_projects = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_projects)) {
|
|
$result = array();
|
|
if (is_array($row_projects)) {
|
|
foreach ($row_projects as $row_project) {
|
|
array_push($result, db_fetch_project($row_project['project'], "", 1));
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch device remark for equipment at specific project
|
|
*
|
|
* Inputs:
|
|
* - project_id: project database id
|
|
* - equip_id: specific id
|
|
* - childs: only childs?
|
|
*
|
|
* Return: Array lances and remarks
|
|
*/
|
|
function db_fetch_project_lances_remark($project_id, $equip_id = "", $childs = 0)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
$query = "SELECT project_zkl.* FROM project,project_zkl WHERE project.status!='afgesloten' AND project.id=project_zkl.project AND ";
|
|
|
|
// Only childs?
|
|
if ($childs) {
|
|
$query .= "project_zkl.project IN (SELECT id FROM project WHERE parent='" . $project_id . "')";
|
|
} else {
|
|
$query .= "project_zkl.project='" . $project_id . "'";
|
|
}
|
|
|
|
// Type selection
|
|
if (strlen($equip_id)) {
|
|
$query .= " AND project_zkl.zkl='" . $equip_id . "'";
|
|
}
|
|
|
|
$remarks = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($remarks)) {
|
|
$result = $remarks;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Fetch all lances attached to project
|
|
*
|
|
* Inputs:
|
|
* - project_id: project database id
|
|
* - device: device type
|
|
* - options: device options array (gps AND gsm, ect.) multi array => or function
|
|
* - hide_rentals: hide rented equipment
|
|
* - lance_status: show device with this lance status
|
|
* - cust_status: show device with this customer status
|
|
*
|
|
* Return: Array containing lances
|
|
*/
|
|
function db_fetch_project_lances($project_id, $device = "", $options = "", $hide_rentals = 0, $lance_status = "", $cust_status = "")
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
$query = "SELECT zkl.* FROM zkl,project_zkl,project,device WHERE ";
|
|
if (strlen($project_id)) {
|
|
$query .= "project_zkl.project='" . $project_id . "' AND ";
|
|
}
|
|
$query .= "project_zkl.zkl=zkl.id AND project.id=project_zkl.project AND zkl.device=device.id ";
|
|
|
|
// Type selection
|
|
if (strlen($device)) {
|
|
$query .= "AND zkl.device='" . $device . "' ";
|
|
}
|
|
|
|
// Option selection
|
|
if (is_array($options)) {
|
|
foreach ($options as $option) {
|
|
if (is_array($option)) {
|
|
$query .= "AND (";
|
|
for ($i = 0; $i < sizeof($option); $i++) {
|
|
if ($i) {
|
|
$query .= "OR ";
|
|
}
|
|
$query .= "FIND_IN_SET('" . ($option[$i]) . "',device.capabilities) > 0 ";
|
|
}
|
|
$query .= ") ";
|
|
} else {
|
|
$query .= "AND FIND_IN_SET('" . ($option) . "',device.capabilities) > 0 ";
|
|
}
|
|
}
|
|
}
|
|
|
|
// hide rented equipment
|
|
if ($hide_rentals) {
|
|
$query .= "AND (((zkl.gebruiker=zkl.eigenaar AND zkl.eigenaar=project.klant) OR (zkl.gebruiker is NULL AND zkl.eigenaar=project.klant)) OR (zkl.gebruiker=project.klant)) ";
|
|
} else {
|
|
$query .= "AND ((zkl.eigenaar=project.klant) OR (zkl.gebruiker=project.klant)) ";
|
|
}
|
|
|
|
// Show lance status
|
|
if (((!is_array($lance_status)) && (strlen($lance_status))) || (is_array($lance_status))) {
|
|
if (is_array($lance_status)) {
|
|
for ($i = 0; $i < sizeof($lance_status); $i++) {
|
|
if (!$i) {
|
|
$query .= " AND (";
|
|
} else {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " zkl.lans_status='" . $lance_status[$i] . "'";
|
|
}
|
|
$query .= ") ";
|
|
} else {
|
|
$query .= " AND zkl.lans_status='" . $lance_status . "'";
|
|
}
|
|
}
|
|
|
|
// Show customer status
|
|
if (((!is_array($cust_status)) && (strlen($cust_status))) || (is_array($cust_status))) {
|
|
if (is_array($cust_status)) {
|
|
for ($i = 0; $i < sizeof($cust_status); $i++) {
|
|
if (!$i) {
|
|
$query .= " AND (";
|
|
} else {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " zkl.klant_status='" . $cust_status[$i] . "'";
|
|
}
|
|
$query .= ") ";
|
|
} else {
|
|
$query .= " AND zkl.klant_status='" . $cust_status . "'";
|
|
}
|
|
}
|
|
|
|
// Group
|
|
$query .= " GROUP BY zkl.id";
|
|
|
|
$row_lances = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_lances)) {
|
|
$result = $row_lances;
|
|
}
|
|
|
|
return array_sort($result, "idcode");
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch all lances which are double assigned (hired, not rented and only for the parent project!)
|
|
*
|
|
* Inputs:
|
|
* - customer_id: customer id
|
|
* - device: device type
|
|
* - lance_status: show device with this lance status
|
|
* - cust_status: show device with this customer status
|
|
*
|
|
* Return: Array containing unassigned lances
|
|
*/
|
|
function db_fetch_project_double_assigned_lances($customer_id, $device = "", $lance_status = "", $cust_status = "")
|
|
{
|
|
// Initial return value
|
|
$result = array();
|
|
|
|
if (strlen($device)) {
|
|
$query = "SELECT project_zkl.zkl FROM zkl,project_zkl,project WHERE project_zkl.project=project.id AND project_zkl.zkl=zkl.id AND project.klant='" . $customer_id . "' AND project.status!=\"afgesloten\" ";
|
|
$query .= "AND zkl.id=project_zkl.zkl AND zkl.device='" . $device . "' AND project.parent is NULL ";
|
|
} else {
|
|
$query = "SELECT project_zkl.zkl FROM zkl,project_zkl,project WHERE project_zkl.project=project.id AND project_zkl.zkl=zkl.id AND project.klant='" . $customer_id . "' AND project.status!=\"afgesloten\" AND project.parent IS NULL ";
|
|
}
|
|
|
|
// Not rented!
|
|
$query .= " AND (zkl.gebruiker=project.klant or (zkl.eigenaar=project.klant AND (zkl.gebruiker is NULL OR zkl.gebruiker=zkl.eigenaar))) ";
|
|
|
|
// Show lance status
|
|
if ((is_array($lance_status)) || (strlen($lance_status))) {
|
|
if (is_array($lance_status)) {
|
|
for ($i = 0; $i < sizeof($lance_status); $i++) {
|
|
if (!$i) {
|
|
$query .= " AND (";
|
|
} else {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " zkl.lans_status='" . $lance_status[$i] . "'";
|
|
}
|
|
$query .= ") ";
|
|
} else {
|
|
$query .= " AND zkl.lans_status='" . $lance_status . "'";
|
|
}
|
|
}
|
|
|
|
// Show customer status
|
|
if ((is_array($cust_status)) || (strlen($cust_status))) {
|
|
if (is_array($cust_status)) {
|
|
for ($i = 0; $i < sizeof($cust_status); $i++) {
|
|
if (!$i) {
|
|
$query .= " AND (";
|
|
} else {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " zkl.klant_status='" . $cust_status[$i] . "'";
|
|
}
|
|
$query .= ") ";
|
|
} else {
|
|
$query .= " AND zkl.klant_status='" . $cust_status . "'";
|
|
}
|
|
}
|
|
|
|
// Group
|
|
$query .= "GROUP BY project_zkl.zkl HAVING COUNT(*) > 1";
|
|
$row_lances = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_lances)) {
|
|
if (is_array($row_lances)) {
|
|
foreach ($row_lances as $lance) {
|
|
array_push($result, $lance['zkl']);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch all lances which are rented
|
|
*
|
|
* Inputs:
|
|
* - customer_id: customer id
|
|
* - device: device type
|
|
* - status: valid status
|
|
*
|
|
* Return: Array containing rented lances
|
|
*/
|
|
function db_fetch_project_rented_lances($customer_id, $device = "", $status = "")
|
|
{
|
|
// Initial return value
|
|
$result = array();
|
|
|
|
$query = "SELECT id FROM zkl WHERE eigenaar='" . $customer_id . "' AND (gebruiker!='" . $customer_id . "' AND gebruiker IS NOT NULL) ";
|
|
|
|
if (strlen($device)) {
|
|
$query .= " and device='" . $device . "' ";
|
|
}
|
|
|
|
// Specific status
|
|
if ((strlen($status)) || (is_array($status))) {
|
|
if (is_array($status)) {
|
|
for ($i = 0; $i < sizeof($status); $i++) {
|
|
if (!$i) {
|
|
$query .= " AND (";
|
|
} else {
|
|
$query .= " OR ";
|
|
}
|
|
$query .= " lans_status='" . $status[$i] . "'";
|
|
}
|
|
$query .= ") ";
|
|
} else {
|
|
$query .= " lans_status='" . $status . "'";
|
|
}
|
|
}
|
|
|
|
$row_lances = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_lances)) {
|
|
if (is_array($row_lances)) {
|
|
foreach ($row_lances as $lance) {
|
|
array_push($result, $lance['id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch all projects attached to lance (only parent project)
|
|
*
|
|
* Inputs:
|
|
* - lance_id: Lance database id
|
|
* - skip_finished Skip all finished/removed projects
|
|
* - customer Specific customer
|
|
* - parent_only Search parent only
|
|
*
|
|
* Return: Array containing projects
|
|
*/
|
|
function db_fetch_lance_projects($lance_id, $skip_finished = 0, $customer = "", $parent_only = 1)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch lance info
|
|
$query = "SELECT project.* FROM project_zkl,project WHERE project_zkl.zkl='" . $lance_id . "' AND project_zkl.project=project.id";
|
|
|
|
if ($parent_only) {
|
|
$query .= " AND project.parent is NULL";
|
|
}
|
|
|
|
if ($skip_finished) {
|
|
$query .= " AND project.status!='afgesloten'";
|
|
}
|
|
|
|
if (strlen($customer)) {
|
|
$query .= " AND klant='" . $customer . "'";
|
|
}
|
|
|
|
$row_projects = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_projects)) {
|
|
$result = $row_projects;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch all released projects where lance is used (top level checking)
|
|
*
|
|
* Inputs:
|
|
* - lance_id: Lance database id
|
|
* - Customer: Customer specific projects
|
|
* - request_for_release: Check request for release
|
|
*
|
|
* Return: Array containing projects
|
|
*/
|
|
function db_fetch_lance_released_projects($lance_id, $customer = null, $request_for_release = FALSE)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Create query
|
|
$query = "SELECT project.* FROM project_zkl,project WHERE project_zkl.zkl='" . $lance_id . "' AND project_zkl.project=project.id";
|
|
$query .= " AND project.parent is NULL and (project.sstatus='vrijgegeven'";
|
|
|
|
if ($request_for_release) {
|
|
$query .= " OR project.sstatus='verzoek tot vrijgeven'";
|
|
}
|
|
|
|
if (!is_null($customer)) {
|
|
$query .= " AND project.klant='" . $customer . "'";
|
|
}
|
|
$query .= ")";
|
|
|
|
$row_projects = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_projects)) {
|
|
$result = $row_projects;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch all projects where user has been projectleader (only on parent project)
|
|
*
|
|
* Inputs:
|
|
* - user_id: User database id
|
|
* - type: type project (normaal/rc/natws)
|
|
*
|
|
* Return: Array containing projects
|
|
*/
|
|
function db_fetch_projectleader_projects($user_id, $type = "")
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// RC or regular project?
|
|
if ($type == "rc") {
|
|
$query = "rol='projectleider-rc'";
|
|
} else if ($type == "normaal") {
|
|
$query = "rol='projectleider'";
|
|
} else {
|
|
$query = "(rol='projectleider' OR rol='projectleider-rc')";
|
|
}
|
|
|
|
// Fetch customer info
|
|
$row_projects = db_fetch_data("SELECT project FROM project_gebruiker,project WHERE " . $query . " AND gebruiker='" . $user_id . "' AND project.id=project_gebruiker.project AND project.status!='afgesloten'");
|
|
|
|
// Parse into result
|
|
if (is_array($row_projects)) {
|
|
$result = array();
|
|
|
|
foreach ($row_projects as $row_project) {
|
|
// Get project info
|
|
$project_info = db_fetch_project($row_project['project'], "", 1);
|
|
|
|
array_push($result, $project_info);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch all projectleader on this project
|
|
*
|
|
* Inputs:
|
|
* - user_id: User database id
|
|
* - type: type project (normaal/rc/natws)
|
|
*
|
|
* Return: Array containing projects
|
|
*/
|
|
function db_fetch_project_projectleader($project_id)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Create query
|
|
$query = "SELECT gebruiker.*,project_gebruiker.project FROM project_gebruiker,gebruiker WHERE project_gebruiker.gebruiker=gebruiker.id AND ";
|
|
$query .= "(project_gebruiker.rol='projectleider' or project_gebruiker.rol='projectleider-rc') AND project_gebruiker.project='" . $project_id . "'";
|
|
|
|
// Fetch projectleader info
|
|
$row_projectleaders = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_projectleaders)) {
|
|
$result = $row_projectleaders;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Store new project (parent only including users)
|
|
*
|
|
* Inputs:
|
|
* - user_array: Array containing all user info
|
|
*
|
|
* Return: 1 (OK)/ 0(Error)
|
|
*/
|
|
function db_store_project($project_array)
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
// Initial return value
|
|
$result = 1;
|
|
|
|
// Query storing new project
|
|
$query = "INSERT INTO project (";
|
|
$query .= "klant, parent, naam, wbi_nummer, beschrijving, begin, eind, type, ostatus, pstatus, sstatus, status) VALUES (";
|
|
$query .= "'" . ($project_array['klant']) . "',";
|
|
if (strlen($project_array['parent'])) {
|
|
$query .= "'" . ($project_array['parent']) . "',";
|
|
} else {
|
|
$query .= "NULL,";
|
|
}
|
|
$query .= "'" . specialchars($project_array['naam']) . "',";
|
|
if (strlen($project_array['wbi_nummer'])) {
|
|
$query .= "'" . specialchars($project_array['wbi_nummer']) . "',";
|
|
} else {
|
|
$query .= "NULL,";
|
|
}
|
|
if (strlen($project_array['beschrijving'])) {
|
|
$query .= "'" . specialchars($project_array['beschrijving']) . "',";
|
|
} else {
|
|
$query .= "NULL,";
|
|
}
|
|
if (strlen($project_array['begin'])) {
|
|
$query .= "'" . ($project_array['begin']) . "',";
|
|
} else {
|
|
$query .= "NULL,";
|
|
}
|
|
if (strlen($project_array['eind'])) {
|
|
$query .= "'" . ($project_array['eind']) . "',";
|
|
} else {
|
|
$query .= "NULL,";
|
|
}
|
|
if (strlen($project_array['type'])) {
|
|
$query .= "'" . ($project_array['type']) . "',";
|
|
} else {
|
|
$query .= "NULL,";
|
|
}
|
|
$query .= "'" . ($project_array['ostatus']) . "',";
|
|
$query .= "'" . ($project_array['pstatus']) . "',";
|
|
$query .= "'" . ($project_array['sstatus']) . "',";
|
|
$query .= "'" . ($project_array['status']) . "')";
|
|
|
|
if (db_store_data($query)) {
|
|
// Retrieve project id
|
|
$log_entry = db_fetch_last_id();
|
|
$project_array['id'] = $log_entry;
|
|
|
|
// Log user-project action (new entry => empty array)
|
|
db_log_user_project($project_array['id'], "menu:projecten:nieuw", serialize($project_array), array());
|
|
|
|
// Store users
|
|
$user_info = array();
|
|
$handle_parts = array();
|
|
|
|
// Store log_entry id
|
|
$user_info['log'] = db_fetch_last_id();
|
|
|
|
// Store project id
|
|
$user_info['id'] = $project_array['id'];
|
|
|
|
// Fetch all parts possible for the users on a project
|
|
$part = db_fetch_set("project_gebruiker", "rol");
|
|
|
|
if (is_array($part)) {
|
|
foreach ($part as $item) {
|
|
if (isset($project_array[str_replace(array("-", ":"), "_", $item) . "_left_ids"])) {
|
|
// Add users
|
|
$user_info[str_replace(array("-", ":"), "_", $item)] = $project_array[str_replace(array("-", ":"), "_", $item) . "_left_ids"];
|
|
|
|
// Retrieve all ids and store date/time
|
|
if ($item == "schakelen") {
|
|
$ids = explode(",", $project_array[str_replace(array("-", ":"), "_", $item) . "_left_ids"]);
|
|
if (is_array($ids)) {
|
|
foreach ($ids as $id) {
|
|
$user_info["begin_datum_" . $id] = $project_array["begin_datum_" . $id];
|
|
$user_info["begin_tijd_" . $id] = $project_array["begin_tijd_" . $id];
|
|
$user_info["eind_datum_" . $id] = $project_array["eind_datum_" . $id];
|
|
$user_info["eind_tijd_" . $id] = $project_array["eind_tijd_" . $id];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Handle these parts
|
|
array_push($handle_parts, $item);
|
|
} else if (($item == "wbv") || ($item == "wbu")) {
|
|
// Add user info
|
|
$user_info[$item] = $project_array[$item];
|
|
|
|
// Handle these parts always
|
|
array_push($handle_parts, $item);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!empty($handle_parts)) {
|
|
if (!db_store_project_users($user_info, $handle_parts)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
|
|
// Store equipment
|
|
if ($result) {
|
|
// Store equipment
|
|
$equipment_info = array();
|
|
$handle_equip = array();
|
|
|
|
// Store log entry
|
|
$equipment_info['log'] = $log_entry;
|
|
|
|
// Store project id
|
|
$equipment_info['id'] = $project_array['id'];
|
|
|
|
// Retrieve all device types
|
|
$types = db_fetch_system_devices($_PAGE_INFO['i18n']);
|
|
|
|
if (is_array($types)) {
|
|
foreach ($types as $type) {
|
|
if (isset($project_array[$type['id'] . "_left_ids"])) {
|
|
// Add equipment
|
|
$equipment_info[$type['id']] = $project_array[$type['id'] . "_left_ids"];
|
|
$equipment_info["aantal_" . $type['id']] = $project_array["aantal_" . $type['id']];
|
|
|
|
// Retrieve all ids and store remarks
|
|
$ids = explode(",", $project_array[$type['id'] . "_left_ids"]);
|
|
if (is_array($ids)) {
|
|
foreach ($ids as $id) {
|
|
$equipment_info["opmerking_" . $id] = $project_array["opmerking_" . $id];
|
|
}
|
|
}
|
|
|
|
// Handle these equipment type
|
|
array_push($handle_equip, $type['id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store equipment
|
|
if (!empty($handle_equip)) {
|
|
if (!db_store_project_lances($equipment_info, $handle_equip)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store log/comment
|
|
if ($result) {
|
|
if (strlen($project_array['remark'])) {
|
|
$log_info['project'] = $project_array['id'];
|
|
$log_info['gebruiker'] = $_PAGE_INFO['login']['user']['id'];
|
|
$log_info['datum'] = date('Y-m-d H:i:s');
|
|
$log_info['tekst'] = $project_array['remark'];
|
|
|
|
if (!db_store_project_comment($log_info)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store new work instruction to secure server => always concept, no checking needed!
|
|
if ($result) {
|
|
$result = (intval(sc_wi($project_array['id'], (strlen($project_array['parent'])) ? FALSE : TRUE), 16) == TCPSTAT_OK) ? TRUE : FALSE;
|
|
}
|
|
|
|
// Mail to project users
|
|
if ($result) {
|
|
// No parent => project else child => period
|
|
if (!strlen($project_array['parent'])) {
|
|
db_project_sendmail($project_array);
|
|
}
|
|
}
|
|
} else {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Update exisiting project
|
|
*
|
|
* Inputs:
|
|
* - project_array: Array containing all project info
|
|
* - update: Update parent always: child (bit 0), sw equip (bit 1), users (bit 2), non-sw equip (bit 3), feedback template (bit 4)
|
|
* - update_periods: Array containing period update fields
|
|
* - WI update reason Wi update reason (not required)
|
|
* - data data reference (containing result)
|
|
* - mail send project mail (TRUE/FALSE/Array containing original info)
|
|
* - users_changed Users changed on project/period
|
|
* - equip_changed Equipment changed on project/period
|
|
*
|
|
* Return: 1 (OK)/ 0(Error)
|
|
*/
|
|
function db_update_project($project_array, $update = 0xE, $update_periods = "", $update_reason = "", &$data = NULL, $mail = TRUE, &$users_changed = FALSE, &$equip_changed = FALSE)
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
// Initial values
|
|
$result = 1;
|
|
|
|
// SET sema on parent
|
|
if (is_null($project_array['parent'])) {
|
|
$_PAGE_INFO['sema_id'] = db_sema_acquire(RemoveExtension(basename(__FILE__)) . "_" . $project_array['id']);
|
|
}
|
|
|
|
// Retrieve original data (using for the secure server and the mailing)
|
|
$orig_project = db_fetch_project($project_array['id'], "", 1);
|
|
|
|
$orig_project_all_equip = db_fetch_project_lances($project_array['id'], "", array(array("gsm", "gprs")));
|
|
$orig_project_equip = $orig_project_all_equip;
|
|
|
|
$orig_project_users = db_fetch_project_users($project_array['id'], "", "schakelen");
|
|
$orig_project_all_users = db_fetch_project_users($project_array['id']);
|
|
|
|
// Get non-switching equipment from parent (and store!)
|
|
if (is_null($orig_project['parent'])) {
|
|
$_PAGE_INFO['orig_project_equip_non'] = db_fetch_project_lances($project_array['id'], "", array(array("gsm", "gprs")));
|
|
}
|
|
|
|
// "Get" non-switching equipment from parent (including RS3000)
|
|
if (!is_null($orig_project['parent'])) {
|
|
if (is_array($_PAGE_INFO['orig_project_equip_non'])) {
|
|
foreach ($_PAGE_INFO['orig_project_equip_non'] as $item) {
|
|
// non-switching?
|
|
if (!db_check_system_device_capabilities($item['device'], array("kortsluiting schakelen"))) {
|
|
|
|
// valid array?
|
|
if (!is_array($orig_project_equip)) {
|
|
$orig_project_equip = array();
|
|
}
|
|
array_push($orig_project_equip, $item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get all existing periods => Only when project (parent is NULL)
|
|
if (is_null($project_array['parent'])) {
|
|
$old_periods_info = db_fetch_project_periods($project_array['id']);
|
|
|
|
$old_periods = array();
|
|
if (is_array($old_periods_info)) {
|
|
foreach ($old_periods_info as $item) {
|
|
array_push($old_periods, $item['id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Query updating project (parent only)
|
|
$query = "UPDATE project SET ";
|
|
$query .= "klant='" . ($project_array['klant']) . "'";
|
|
|
|
if (!is_null($project_array['naam'])) {
|
|
// Prevent duplicated name
|
|
if ($_SESSION[$_PAGE_INFO['id']]['action'] == "project_design") {
|
|
$query .= ",naam='" . specialchars($project_array['naam'] . '_#NEW') . "'";
|
|
} else {
|
|
$query .= ",naam='" . specialchars($project_array['naam']) . "'";
|
|
}
|
|
}
|
|
|
|
if (!is_null($project_array['wbi_nummer'])) {
|
|
if (strlen($project_array['wbi_nummer'])) {
|
|
$query .= ",wbi_nummer='" . specialchars($project_array['wbi_nummer']) . "'";
|
|
} else {
|
|
$query .= ",wbi_nummer=NULL";
|
|
}
|
|
}
|
|
|
|
if (!is_null($project_array['beschrijving'])) {
|
|
if (strlen($project_array['beschrijving'])) {
|
|
$query .= ",beschrijving='" . specialchars($project_array['beschrijving']) . "'";
|
|
} else {
|
|
$query .= ",beschrijving=NULL";
|
|
}
|
|
}
|
|
|
|
if (!is_null($project_array['begin'])) {
|
|
if (strlen($project_array['begin'])) {
|
|
$query .= ",begin='" . ($project_array['begin']) . "'";
|
|
} else {
|
|
$query .= ",begin=NULL";
|
|
}
|
|
}
|
|
|
|
if (!is_null($project_array['eind'])) {
|
|
if (strlen($project_array['eind'])) {
|
|
$query .= ",eind='" . ($project_array['eind']) . "'";
|
|
} else {
|
|
$query .= ",eind=NULL";
|
|
}
|
|
}
|
|
|
|
if (!is_null($project_array['type'])) {
|
|
$query .= ",type='" . ($project_array['type']) . "'";
|
|
|
|
}
|
|
|
|
if (!is_null($project_array['status'])) {
|
|
$query .= ",status='" . ($project_array['status']) . "'";
|
|
}
|
|
|
|
if (!is_null($project_array['ostatus'])) {
|
|
$query .= ",ostatus='" . ($project_array['ostatus']) . "'";
|
|
}
|
|
|
|
if (!is_null($project_array['pstatus'])) {
|
|
$query .= ",pstatus='" . ($project_array['pstatus']) . "'";
|
|
}
|
|
|
|
if (!is_null($project_array['sstatus'])) {
|
|
$query .= ",sstatus='" . ($project_array['sstatus']) . "'";
|
|
}
|
|
|
|
$query .= " WHERE id='" . ($project_array['id']) . "'";
|
|
|
|
if (!db_store_data($query)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
|
|
if ($result) {
|
|
// Log user-project action (new entry => empty array)
|
|
db_log_user_project($project_array['id'], "menu:projecten:wijzigen", serialize($project_array), $orig_project);
|
|
|
|
// Update users?
|
|
if (($result) && ($update & 0x04)) {
|
|
// Store users?
|
|
$user_info = array();
|
|
$handle_parts = array();
|
|
|
|
// Store log_entry id
|
|
$log_entry = db_fetch_last_id();
|
|
$user_info['log'] = $log_entry;
|
|
|
|
// Store project id
|
|
$user_info['id'] = $project_array['id'];
|
|
|
|
// Fetch all parts possible for the users on a project
|
|
$part = db_fetch_set("project_gebruiker", "rol");
|
|
|
|
if (is_array($part)) {
|
|
foreach ($part as $item) {
|
|
// Extra actions?
|
|
switch ($item) {
|
|
case 'normaal':
|
|
$set_handle_parts = FALSE;
|
|
|
|
for ($level = 8; $level <= 10; $level++) {
|
|
// Type of users used?
|
|
if (isset($project_array[str_replace(array("-", ":"), "_", $item) . "_" . $level . "_left_ids"])) {
|
|
// Add users
|
|
$user_info[str_replace(array("-", ":"), "_", $item) . "_" . $level] = $project_array[str_replace(array("-", ":"), "_", $item) . "_" . $level . "_left_ids"];
|
|
|
|
// Set flag
|
|
$set_handle_parts = TRUE;
|
|
}
|
|
}
|
|
|
|
if ($set_handle_parts) {
|
|
// Handle these parts
|
|
array_push($handle_parts, $item);
|
|
}
|
|
break;
|
|
case "wbv":
|
|
case "wbu":
|
|
// Add user info
|
|
$user_info[$item] = $project_array[$item];
|
|
|
|
// Handle these parts always
|
|
array_push($handle_parts, $item);
|
|
break;
|
|
default:
|
|
// Type of users used?
|
|
if (isset($project_array[str_replace(array("-", ":"), "_", $item) . "_left_ids"])) {
|
|
// Add users
|
|
$user_info[str_replace(array("-", ":"), "_", $item)] = $project_array[str_replace(array("-", ":"), "_", $item) . "_left_ids"];
|
|
|
|
// Retrieve all ids and store date/time
|
|
if ($item == "schakelen") {
|
|
$ids = explode(",", $project_array[str_replace(array("-", ":"), "_", $item) . "_left_ids"]);
|
|
if (is_array($ids)) {
|
|
foreach ($ids as $id) {
|
|
$user_info["begin_datum_" . $id] = $project_array["begin_datum_" . $id];
|
|
$user_info["begin_tijd_" . $id] = $project_array["begin_tijd_" . $id];
|
|
$user_info["eind_datum_" . $id] = $project_array["eind_datum_" . $id];
|
|
$user_info["eind_tijd_" . $id] = $project_array["eind_tijd_" . $id];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Handle these parts
|
|
array_push($handle_parts, $item);
|
|
}
|
|
break;
|
|
|
|
// Does the old period have users with switching rights? => Handle also, because then they are removed
|
|
if (!in_array("schakelen", $handle_parts)) {
|
|
if ((is_array($orig_project_users)) && (!empty($orig_project_users))) {
|
|
array_push($handle_parts, "schakelen");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store users => When needed
|
|
if (!empty($handle_parts)) {
|
|
if (!db_store_project_users($user_info, $handle_parts)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($result) {
|
|
// Store switching equipment?
|
|
if (($result) && ($update & 0x02)) {
|
|
// Store equipment
|
|
$equipment_info = array();
|
|
$handle_equip = array();
|
|
|
|
// Store log entry
|
|
$equipment_info['log'] = $log_entry;
|
|
|
|
// Store project id
|
|
$equipment_info['id'] = $project_array['id'];
|
|
|
|
// Retrieve all device types
|
|
$types = db_fetch_system_devices($_PAGE_INFO['i18n']);
|
|
|
|
if (is_array($types)) {
|
|
foreach ($types as $type) {
|
|
// Switching capabilities?
|
|
if (db_check_system_device_capabilities($type['id'], array("kortsluiting schakelen"))) {
|
|
// Add equipment
|
|
$equipment_info[$type['id']] = $project_array[$type['id'] . "_left_ids"];
|
|
$equipment_info["aantal_" . $type['id']] = $project_array["aantal_" . $type['id']];
|
|
|
|
// Retrieve all ids and store remarks
|
|
$ids = explode(",", $project_array[$type['id'] . "_left_ids"]);
|
|
if (is_array($ids)) {
|
|
foreach ($ids as $id) {
|
|
$equipment_info["opmerking_" . $id] = $project_array["opmerking_" . $id];
|
|
}
|
|
}
|
|
|
|
// Handle these equipment type
|
|
array_push($handle_equip, $type['id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store equipment
|
|
if (!empty($handle_equip)) {
|
|
if (!db_store_project_lances($equipment_info, $handle_equip)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($result) {
|
|
// Store non switching equipment?
|
|
if (($result) && ($update & 0x08)) {
|
|
// Store equipment
|
|
$equipment_info = array();
|
|
$handle_equip = array();
|
|
|
|
// Store log entry
|
|
$equipment_info['log'] = $log_entry;
|
|
|
|
// Store project id
|
|
$equipment_info['id'] = $project_array['id'];
|
|
|
|
// Retrieve all device types
|
|
$types = db_fetch_system_devices($_PAGE_INFO['i18n']);
|
|
|
|
if (is_array($types)) {
|
|
foreach ($types as $type) {
|
|
// No switching capabilities?
|
|
if (!db_check_system_device_capabilities($type['id'], array("kortsluiting schakelen"))) {
|
|
// Add equipment
|
|
$equipment_info[$type['id']] = $project_array[$type['id'] . "_left_ids"];
|
|
$equipment_info["aantal_" . $type['id']] = $project_array["aantal_" . $type['id']];
|
|
|
|
// Retrieve all ids and store remarks
|
|
$ids = explode(",", $project_array[$type['id'] . "_left_ids"]);
|
|
if (is_array($ids)) {
|
|
foreach ($ids as $id) {
|
|
$equipment_info["opmerking_" . $id] = $project_array["opmerking_" . $id];
|
|
}
|
|
}
|
|
|
|
// Handle these equipment type
|
|
array_push($handle_equip, $type['id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store equipment
|
|
if (!empty($handle_equip)) {
|
|
if (!db_store_project_lances($equipment_info, $handle_equip)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($result) {
|
|
// Store feedback templates
|
|
if (($result) && ($update & 0x10)) {
|
|
$selected_templates = array();
|
|
|
|
// Instruction list always available
|
|
array_push($selected_templates, array('id' => ENQ_SUBSCRIPTION_LIST, 'level' => 10));
|
|
|
|
foreach ($project_array as $key => $item) {
|
|
// Find feedback form
|
|
if (stristr($key, "feedback_templ") !== FALSE) {
|
|
// Skip levels (only the checkboxes)
|
|
if (stristr($key, "_level") === FALSE) {
|
|
// Default level
|
|
$level = 10;
|
|
if (isset($project_array[$key . "_level"])) {
|
|
$level = $project_array[$key . "_level"];
|
|
}
|
|
array_push($selected_templates, array('id' => str_replace("feedback_templ", "", $key), 'level' => $level));
|
|
|
|
// Exceptions?
|
|
switch (str_replace("feedback_templ", "", $key)) {
|
|
case ENQ_WECO:
|
|
// Store WECO subitems
|
|
array_push($selected_templates, array('id' => ENQ_WECO_TRDL, 'level' => $level));
|
|
array_push($selected_templates, array('id' => ENQ_WECO_WORKPLACE, 'level' => $level));
|
|
array_push($selected_templates, array('id' => ENQ_WECO_WORKTIME, 'level' => $level));
|
|
array_push($selected_templates, array('id' => ENQ_WECO_NOVOLTAGE, 'level' => $level));
|
|
array_push($selected_templates, array('id' => ENQ_WECO_SAFETY, 'level' => $level));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!db_store_project_questionaire($project_array['id'], $selected_templates)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store log/comment
|
|
if ($result) {
|
|
if (strlen($project_array['remark'])) {
|
|
$log_info['project'] = $project_array['id'];
|
|
$log_info['gebruiker'] = $_PAGE_INFO['login']['user']['id'];
|
|
$log_info['datum'] = date('Y-m-d H:i:s');
|
|
$log_info['tekst'] = $project_array['remark'];
|
|
|
|
if (!db_store_project_comment($log_info)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update work instruction on secure server
|
|
if ($result) {
|
|
// Get new stored values, needed to fill up the NULL values (the non-updated values)
|
|
$project_new = db_fetch_project($project_array['id'], "", 1);
|
|
|
|
// Fill in original values when values is NULL (NULL is skip by update)
|
|
// We can do this because the update has already been done!
|
|
if (is_array($project_array)) {
|
|
foreach ($project_array as $key => $item) {
|
|
if (is_null($item)) {
|
|
$project_array[$key] = $project_new[$key];
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = (intval(sc_wi($project_array['id'], (is_null($orig_project['parent'])) ? TRUE : FALSE, $data, array("general" => $orig_project, "equip" => $orig_project_equip, "users" => $orig_project_users), $update_reason), 16) == TCPSTAT_OK) ? TRUE : FALSE;
|
|
|
|
// The only exception is the return! Remove the warnings => Otherwhise no mail has been done
|
|
$result = ($update_reason == "teruggegeven") ? TRUE : $result;
|
|
|
|
// Get current users/equipment (stored)
|
|
$project['equip'] = db_fetch_project_lances($project_array['id'], "", array(array("gsm", "gprs")));
|
|
$project['users'] = db_fetch_project_users($project_array['id']);
|
|
|
|
if (!$users_changed) {
|
|
// Users changed? => Needed for the mailing
|
|
if (((is_array($project['users'])) && (!is_array($orig_project_all_users))) ||
|
|
((!is_array($project['users'])) && (is_array($orig_project_all_users)))
|
|
) {
|
|
$users_changed = TRUE;
|
|
} else if ((is_array($project['users'])) && (is_array($orig_project_all_users))) {
|
|
// Users added?
|
|
foreach ($project['users'] as $item) {
|
|
if (!in_array($item, $orig_project_all_users)) {
|
|
$users_changed = TRUE;
|
|
}
|
|
}
|
|
|
|
// Users removed?
|
|
foreach ($orig_project_all_users as $item) {
|
|
if (!in_array($item, $project['users'])) {
|
|
$users_changed = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$equip_changed) {
|
|
// Equipment changed? => Needed for the mailing
|
|
if (((is_array($project['equip'])) && (!is_array($orig_project_all_equip))) ||
|
|
((!is_array($project['equip'])) && (is_array($orig_project_all_equip)))
|
|
) {
|
|
$equip_changed = TRUE;
|
|
} else if ((is_array($project['equip'])) && (is_array($orig_project_all_equip))) {
|
|
// Equipment added?
|
|
foreach ($project['equip'] as $item) {
|
|
if (!in_array($item, $orig_project_all_equip)) {
|
|
$equip_changed = TRUE;
|
|
}
|
|
}
|
|
|
|
// Equipment removed?
|
|
foreach ($orig_project_all_equip as $item) {
|
|
if (!in_array($item, $project['equip'])) {
|
|
$equip_changed = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Periods removed (only for the project, not for the periods)? => needed for the mailing
|
|
if (!$equip_changed && !$users_changed) {
|
|
if (is_null($project['parent'])) {
|
|
// Get all new/old periods needed for the check
|
|
$new_per_check = array();
|
|
|
|
// When periods == NULL => No possibility periods are removed or added!
|
|
if (!is_null($project_array['period'])) {
|
|
if (strlen($project_array['period'])) {
|
|
$new_per_check = explode(",", $project_array['period']);
|
|
}
|
|
} else if (is_array($old_periods)) {
|
|
// Use old periods
|
|
$new_per_check = $old_periods;
|
|
}
|
|
|
|
$old_per_check = array();
|
|
if (is_array($old_periods)) {
|
|
$old_per_check = $old_periods;
|
|
}
|
|
|
|
// Periods removed?
|
|
foreach ($old_per_check as $item) {
|
|
if (!in_array($item, $new_per_check)) {
|
|
// Equipment on period?
|
|
if (is_array(db_fetch_project_lances($item, "", array(array("gsm", "gprs"))))) {
|
|
$equip_changed = TRUE;
|
|
}
|
|
// Users on period?
|
|
if (is_array(db_fetch_project_users($item))) {
|
|
$users_changed = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// update childs?
|
|
if (($result) && ($update & 0x01)) {
|
|
// Update/Store periods periods
|
|
$periods = "";
|
|
// When periods == NULL => No possibility periods are removed or added!
|
|
if (!is_null($project_array['period'])) {
|
|
if (strlen($project_array['period'])) {
|
|
$periods = explode(",", $project_array['period']);
|
|
}
|
|
} else if (is_array($old_periods)) {
|
|
// Use old periods
|
|
$periods = $old_periods;
|
|
}
|
|
|
|
// Remove old periods
|
|
// This must be done before the new are added, which could result in conflict in db key (parent, name)
|
|
if (is_array($old_periods)) {
|
|
foreach ($old_periods as $period) {
|
|
// Not a part of the new periods => Remove
|
|
if ((!is_array($periods)) || (!in_array($period, $periods))) {
|
|
db_delete_project($period);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (is_array($periods)) {
|
|
foreach ($periods as $period) {
|
|
// Gather period info
|
|
$period_info = array();
|
|
$period_info['klant'] = $project_array['klant'];
|
|
if (!is_null($project_array["naam_" . $period])) {
|
|
$period_info['naam'] = $project_array['id'] . "_" . $project_array["naam_" . $period];
|
|
}
|
|
$period_info['type'] = $project_array['type'];
|
|
$period_info['beschrijving'] = $project_array['beschrijving'];
|
|
$period_info['status'] = $project_array['status'];
|
|
$period_info['ostatus'] = $project_array['ostatus'];
|
|
$period_info['pstatus'] = $project_array['pstatus'];
|
|
$period_info['sstatus'] = $project_array['sstatus'];
|
|
$period_info['parent'] = $project_array['id'];
|
|
|
|
if (strlen($project_array["opmerking_" . $period])) {
|
|
$log_info['project'] = $period;
|
|
$log_info['gebruiker'] = $_PAGE_INFO['login']['user']['id'];
|
|
$log_info['datum'] = date('Y-m-d H:i:s');
|
|
$log_info['tekst'] = $project_array["opmerking_" . $period];
|
|
|
|
if (!db_store_project_comment($log_info, TRUE)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
|
|
// Users with switching rights exists?
|
|
if (strlen($project_array["schakelen_" . $period . "_left_ids"])) {
|
|
$period_info["schakelen_left_ids"] = $project_array["schakelen_" . $period . "_left_ids"];
|
|
|
|
// Retrieve all switching ids and store date/time
|
|
$ids = explode(",", $project_array["schakelen_" . $period . "_left_ids"]);
|
|
if (is_array($ids)) {
|
|
foreach ($ids as $id) {
|
|
$period_info["begin_datum_" . $id] = $project_array["begin_datum_" . $id . "_" . $period];
|
|
$period_info["begin_tijd_" . $id] = $project_array["begin_tijd_" . $id . "_" . $period];
|
|
$period_info["eind_datum_" . $id] = $project_array["eind_datum_" . $id . "_" . $period];
|
|
$period_info["eind_tijd_" . $id] = $project_array["eind_tijd_" . $id . "_" . $period];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check all equipment types
|
|
if (is_array($types)) {
|
|
foreach ($types as $type) {
|
|
// Device name
|
|
$device = $type['id'];
|
|
|
|
if (strlen($project_array[$device . "_" . $period . "_left_ids"])) {
|
|
$period_info[$device . "_left_ids"] = $project_array[$device . "_" . $period . "_left_ids"];
|
|
|
|
// Retrieve all ids and store remarks
|
|
$ids = explode(",", $project_array[$device . "_" . $period . "_left_ids"]);
|
|
if (is_array($ids)) {
|
|
foreach ($ids as $id) {
|
|
$period_info["opmerking_" . $id] = $project_array["opmerking_" . $period . "_" . $id];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!in_array($period, $old_periods)) {
|
|
// New project
|
|
db_store_project($period_info);
|
|
} else {
|
|
// Restore id
|
|
$period_info['id'] = $period;
|
|
|
|
// Update existing project (parent only including equipment/users (defined by parent), otherwhise the pyramid is to deep!)
|
|
db_update_project($period_info, $update, "", $update_reason, $data, $mail, $users_changed, $equip_changed);
|
|
}
|
|
}
|
|
}
|
|
} else if (($result) && (is_array($update_periods))) {
|
|
// Only update requested fields of period (non-removal)
|
|
if (is_array($old_periods_info)) {
|
|
foreach ($old_periods_info as $period_info) {
|
|
foreach ($update_periods as $item) {
|
|
$period_info[$item] = $project_array[$item];
|
|
}
|
|
|
|
// Update db (only parent no equipment/users!)
|
|
if (!db_update_project($period_info, 0, "", $update_reason, $data, $users_changed, $equip_changed)) {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Periods added (only for the project, not for the periods)? => needed for the mailing
|
|
if (!$equip_changed && !$users_changed) {
|
|
if (is_null($project['parent'])) {
|
|
// Get all new/old periods needed for the check
|
|
$new_per_check = array();
|
|
$new_periods_info = db_fetch_project_periods($project_array['id']);
|
|
if (is_array($new_periods_info)) {
|
|
foreach ($new_periods_info as $item) {
|
|
array_push($new_per_check, $item['id']);
|
|
}
|
|
}
|
|
|
|
$old_per_check = array();
|
|
if (is_array($old_periods)) {
|
|
$old_per_check = $old_periods;
|
|
}
|
|
|
|
// Periods added?
|
|
foreach ($new_per_check as $item) {
|
|
if (!in_array($item, $old_per_check)) {
|
|
// Equipment on new period?
|
|
if (is_array(db_fetch_project_lances($item, "", array(array("gsm", "gprs"))))) {
|
|
$equip_changed = TRUE;
|
|
}
|
|
// Users on new period?
|
|
if (is_array(db_fetch_project_users($item))) {
|
|
$users_changed = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// No parent => project else child => period
|
|
if (is_null($orig_project['parent'])) {
|
|
if ($_SESSION[$_PAGE_INFO['id']]['action'] == "project_design") {
|
|
// Update all project names
|
|
db_store_data("UPDATE project SET naam=substr(naam, 1, (length(naam) - length('_#NEW'))) WHERE (id='" . $orig_project['id'] . "' OR parent='" . $orig_project['id'] . "') AND naam LIKE '%_#NEW'");
|
|
}
|
|
}
|
|
|
|
// Do we need to generate project code?
|
|
if ($result) {
|
|
// only for the parent
|
|
if (is_null($orig_project['parent'])) {
|
|
if ((($project_array['type'] == "rc") && ($project_array['sstatus'] == "vrijgegeven") && ($orig_project['sstatus'] != "vrijgegeven")) ||
|
|
((($project_array['type'] == "normaal") || ($orig_project['type'] == "normaal")) && ($project_array['pstatus'] == "gereed") && ($orig_project['pstatus'] != "gereed"))
|
|
) {
|
|
// Retrieve all new stored users
|
|
$users = db_fetch_project_users($project_array['id']);
|
|
|
|
foreach ($users as $user) {
|
|
// Generate code for all level 1 and 2 users
|
|
if ($user['level'] < 10) {
|
|
generateAndStoreSignInCode($user['id'], $project_array['id'], 'gebruiker_inlogcode', 'gebruiker');
|
|
}
|
|
}
|
|
} // Do we need to clear project code?
|
|
else if ((($project_array['type'] == "rc") && ($project_array['sstatus'] != "vrijgegeven") && ($orig_project['sstatus'] == "vrijgegeven")) ||
|
|
((($project_array['type'] == "normaal") || ($orig_project['type'] == "normaal")) && ($project_array['pstatus'] != "gereed") && ($orig_project['pstatus'] == "gereed"))
|
|
) {
|
|
// Delete project code from complete project
|
|
db_store_data("DELETE FROM gebruiker_inlogcode WHERE project='" . $project_array['id'] . "'");
|
|
db_store_data("DELETE FROM gebruiker_profiel_inlogcode WHERE project='" . $project_array['id'] . "'");
|
|
}
|
|
}
|
|
}
|
|
|
|
// Mail to project users (Everything must be ok before this message is send)
|
|
if (($result) && (($mail) || (is_array($mail)))) {
|
|
// No parent => project else child => period
|
|
if (is_null($orig_project['parent'])) {
|
|
// Original project
|
|
$orig_project = (is_array($mail)) ? $mail : $orig_project;
|
|
|
|
// Send project mail
|
|
db_project_sendmail($project_array, $orig_project, $users_changed, $equip_changed);
|
|
}
|
|
}
|
|
|
|
// Release sempaphore on parent
|
|
if (is_null($project_array['parent'])) {
|
|
// Release sema
|
|
db_sema_release($_PAGE_INFO['sema_id']);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Duplicate project
|
|
*
|
|
* Inputs:
|
|
* - original_id: Original project id
|
|
* - new_name: New project name
|
|
*
|
|
* Return: TRUE (OK)/ FALSE (Error)
|
|
*/
|
|
function db_duplicate_project($original_id, $new_name)
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
// Initial values
|
|
$result = TRUE;
|
|
$parent_new_id = NULL;
|
|
|
|
// Initial project array
|
|
$projects = array(db_fetch_project($original_id, "", 1));
|
|
|
|
// Get all periods
|
|
$periods = db_fetch_project_periods($original_id, FALSE);
|
|
|
|
// Add periods to project array
|
|
if (is_array($periods)) {
|
|
foreach ($periods as $period) {
|
|
array_push($projects, $period);
|
|
}
|
|
}
|
|
|
|
// Parse all "project"
|
|
if (is_array($projects)) {
|
|
foreach ($projects as $project) {
|
|
if ($result) {
|
|
// Get table items
|
|
$items = db_fetch_set("project");
|
|
|
|
// Query storing "new" project
|
|
$query = "INSERT INTO project (";
|
|
|
|
$values = "";
|
|
if (is_array($items)) {
|
|
foreach ($items as $item) {
|
|
$item_value = "";
|
|
|
|
// Add items
|
|
switch ($item) {
|
|
case 'id':
|
|
break;
|
|
default:
|
|
$item_value = $item;
|
|
break;
|
|
}
|
|
|
|
if (strlen($item_value)) {
|
|
if (strlen($values)) {
|
|
$values .= ",";
|
|
}
|
|
|
|
$values .= $item_value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$query .= $values . ") VALUES (";
|
|
|
|
$values = "";
|
|
if (is_array($items)) {
|
|
foreach ($items as $item) {
|
|
$item_value = "";
|
|
|
|
switch ($item) {
|
|
case 'id':
|
|
break;
|
|
case 'status':
|
|
$item_value .= "''";
|
|
break;
|
|
case 'ostatus':
|
|
case 'pstatus':
|
|
$item_value .= "'concept'";
|
|
break;
|
|
case 'sstatus':
|
|
$item_value .= "'niet vrijgegeven'";
|
|
break;
|
|
case 'beschrijving':
|
|
$item_value .= "NULL";
|
|
break;
|
|
case 'parent':
|
|
// Project or period?
|
|
if (is_null($project[$item])) {
|
|
$item_value .= "NULL";
|
|
} else {
|
|
$item_value .= $parent_new_id;
|
|
}
|
|
break;
|
|
case 'naam':
|
|
// Project or period?
|
|
if (is_null($project['parent'])) {
|
|
$item_value .= "'" . specialchars($new_name) . "'";
|
|
} else {
|
|
$item_value .= "'" . specialchars($parent_new_id . stristr($project[$item], '_')) . "'";
|
|
}
|
|
break;
|
|
case 'wbi_nummer':
|
|
$item_value .= "NULL";
|
|
break;
|
|
default:
|
|
if (!strlen($project[$item])) {
|
|
$item_value .= "NULL";
|
|
} else {
|
|
$item_value .= "'" . ($project[$item]) . "'";
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (strlen($item_value)) {
|
|
if (strlen($values)) {
|
|
$values .= ",";
|
|
}
|
|
|
|
$values .= $item_value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$query .= $values . ")";
|
|
|
|
// Store "projects"
|
|
if (db_store_data($query)) {
|
|
// Get new project id
|
|
$new_id = db_fetch_last_id();
|
|
|
|
// Project or period?
|
|
if (is_null($project['parent'])) {
|
|
// Get new project id
|
|
$parent_new_id = db_fetch_last_id();
|
|
}
|
|
|
|
$tables = array("project_gebruiker", "project_zkl", "project_device", "enquete_project");
|
|
|
|
if (is_array($tables)) {
|
|
foreach ($tables as $table) {
|
|
// Get new items
|
|
$items = db_fetch($table, "*", "project=" . $project['id']);
|
|
|
|
if (is_array($items)) {
|
|
foreach ($items as $item) {
|
|
// Get table entries
|
|
$entries = db_fetch_set($table);
|
|
|
|
// Query storing "new" items
|
|
$query = "INSERT INTO " . $table . " (";
|
|
|
|
$values = "";
|
|
if (is_array($entries)) {
|
|
foreach ($entries as $entry) {
|
|
$entry_value = "";
|
|
|
|
// Add items
|
|
switch ($entry) {
|
|
default:
|
|
$entry_value = $entry;
|
|
break;
|
|
}
|
|
|
|
if (strlen($entry_value)) {
|
|
if (strlen($values)) {
|
|
$values .= ",";
|
|
}
|
|
|
|
$values .= $entry_value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$query .= $values . ") VALUES (";
|
|
|
|
$values = "";
|
|
if (is_array($entries)) {
|
|
foreach ($entries as $entry) {
|
|
$entry_value = "";
|
|
|
|
switch ($entry) {
|
|
case 'project':
|
|
$entry_value .= $new_id;
|
|
break;
|
|
default:
|
|
if (!strlen($item[$entry])) {
|
|
$entry_value .= "NULL";
|
|
} else {
|
|
$entry_value .= "'" . ($item[$entry]) . "'";
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (strlen($entry_value)) {
|
|
if (strlen($values)) {
|
|
$values .= ",";
|
|
}
|
|
|
|
$values .= $entry_value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$query .= $values . ")";
|
|
|
|
// Store items
|
|
if (!db_store_data($query)) {
|
|
// Result NOK
|
|
$result = FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Everything ok => store wi
|
|
if ($result) {
|
|
$result = (intval(sc_wi($new_id, ((is_null($project['parent'])) ? TRUE : FALSE))) == TCPSTAT_OK) ? TRUE : FALSE;
|
|
}
|
|
|
|
// Everything ok => store comment (parent only)
|
|
if (($result) && (is_null($project['parent']))) {
|
|
db_store_project_comment(array(project => $new_id,
|
|
gebruiker => $_SESSION[$_PAGE_INFO['id']]['login']['user']['id'],
|
|
datum => date('Y-m-d H:i:s'),
|
|
tekst => ucfirst(_("duplicated of")) . ": " . $project['naam']));
|
|
}
|
|
} else {
|
|
// Result NOK
|
|
$result = FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Everything ok => store project code
|
|
|
|
|
|
// Everything ok? => send project mail
|
|
if (($result) && (!is_null($parent_new_id))) {
|
|
db_project_sendmail(db_fetch_project($parent_new_id, "", 1));
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Delete project and project users
|
|
*
|
|
* Inputs:
|
|
* - project_id: Project database id
|
|
* - skip_parent: Remove only childs (periods) or all
|
|
*
|
|
* Return: 1 (OK)/ 0(Error)
|
|
*/
|
|
function db_delete_project($project_id, $skip_parent = 0)
|
|
{
|
|
// Initial return value
|
|
$result = 0;
|
|
|
|
// Get all periods
|
|
$periods = db_fetch_data("SELECT id FROM project WHERE parent='" . $project_id . "'");
|
|
|
|
// valid array
|
|
$periods = (is_array($periods)) ? $periods : array();
|
|
|
|
// add parent to periods
|
|
if (!$skip_parent) {
|
|
array_push($periods, array(id => $project_id));
|
|
}
|
|
|
|
// Initial arrays
|
|
$query = array();
|
|
$orig_period = array();
|
|
|
|
foreach ($periods as $period) {
|
|
// Get original data
|
|
$orig_period[$period['id']] = db_fetch_project($period['id'], "", 1);
|
|
|
|
// Get period info
|
|
$period_info = db_fetch_data("SELECT * FROM project WHERE id='" . $period['id'] . "'");
|
|
|
|
if (is_array($period_info)) {
|
|
if ($period_info[0]['status'] != "afgesloten") {
|
|
// "Delete" project
|
|
array_push($query, "UPDATE project SET status='afgesloten' WHERE ID='" . $period['id'] . "'");
|
|
|
|
// Reset counter
|
|
$counter = 0;
|
|
do {
|
|
// Increment counter
|
|
$counter++;
|
|
|
|
// Check if name already exists
|
|
$period_name = db_fetch_data("SELECT * FROM project WHERE parent='" . $period_info[0]['parent'] . "' AND naam='" . $period_info[0]['naam'] . "_#REMOVED#" . $counter . "'");
|
|
} while (is_array($period_name));
|
|
|
|
// Delete project
|
|
array_push($query, "UPDATE project SET naam='" . $period_info[0]['naam'] . "_#REMOVED#" . $counter . "' WHERE ID='" . $period['id'] . "'");
|
|
}
|
|
}
|
|
}
|
|
|
|
// Start transaction
|
|
db_start_transaction();
|
|
|
|
foreach ($query as $item) {
|
|
db_store_data($item);
|
|
}
|
|
|
|
// Commit transaction
|
|
if (db_commit_transaction()) {
|
|
if (!$skip_parent) {
|
|
// Log user-project action
|
|
db_log_user_project($project_id, "menu:projecten:verwijderen");
|
|
}
|
|
|
|
// Parse result
|
|
$result = 1;
|
|
}
|
|
|
|
if ($result) {
|
|
foreach ($periods as $period) {
|
|
// Remove work instruction from secure server
|
|
$result = (intval(sc_wi($period['id'], (is_null($orig_period[$period['id']]['parent'])) ? TRUE : FALSE, $data, array("general" => $orig_period[$period['id']])), 16) == TCPSTAT_OK) ? TRUE : FALSE;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Delete project log files (called by the garbage collector)
|
|
* Inputs:
|
|
* - timeout: Max time it may take
|
|
* - limit: Max delete items each time
|
|
*
|
|
* Return: Array containing time and affected rows
|
|
*/
|
|
function db_delete_project_logs($timeout, $limit = 100)
|
|
{
|
|
GLOBAL $_PAGE_INFO;
|
|
|
|
// Initial values
|
|
$affected = 0;
|
|
|
|
// Get start time;
|
|
$start = microtime_float();
|
|
|
|
// All log tables
|
|
$log_table = array("project_device",
|
|
"project_documenten",
|
|
"project_gebruiker",
|
|
"project_zkl");
|
|
|
|
do {
|
|
// Initial value
|
|
$finished = 1;
|
|
|
|
// all log files
|
|
foreach ($log_table as $table) {
|
|
// Initial values
|
|
$project_ids = "";
|
|
$project_max = "";
|
|
|
|
// Get all project ids => Create array and determine max value
|
|
$query = "SELECT id FROM project ORDER BY id ASC";
|
|
$rows = db_fetch_data($query);
|
|
if (is_array($rows)) {
|
|
$project_ids = "(";
|
|
for ($i = 0; $i < sizeof($rows); $i++) {
|
|
// Add comma
|
|
if ($i) {
|
|
$project_ids .= ",";
|
|
}
|
|
// Add id
|
|
$project_ids .= $rows[$i]['id'];
|
|
|
|
// Get highest project index
|
|
$project_max = $rows[$i]['id'];
|
|
}
|
|
$project_ids .= ")";
|
|
}
|
|
|
|
// Delete entries from table
|
|
if (strlen($project_ids)) {
|
|
$query = "DELETE FROM " . $table . " WHERE project <= " . $project_max . " AND project NOT IN " . $project_ids . " LIMIT " . ($limit - $affected) . "";
|
|
db_store_data($query);
|
|
|
|
// Finished?
|
|
$affected += mysql_affected_rows($_PAGE_INFO['mysql_db_resource']['default']);
|
|
$finished = ($affected >= $limit) ? 1 : 0;
|
|
}
|
|
}
|
|
|
|
// Get end time
|
|
$end = microtime_float();
|
|
} while ((!$finished) && (($end - $start) < $timeout));
|
|
|
|
// Return info
|
|
return array(time => ($end - $start), affected => $affected);
|
|
}
|
|
|
|
|
|
/**
|
|
* Store new project users
|
|
*
|
|
* Inputs:
|
|
* - project_array: Array containing project id and project users
|
|
* - handle_parts: Parts which must be handled
|
|
*
|
|
* Return: 1 (OK)/ 0(Error)
|
|
*/
|
|
function db_store_project_users($project_array, $handle_parts)
|
|
{
|
|
// Initial return value
|
|
$result = 0;
|
|
|
|
// Start transaction
|
|
db_start_transaction();
|
|
|
|
// Delete project user with specific part
|
|
if (is_array($handle_parts)) {
|
|
foreach ($handle_parts as $part) {
|
|
$query = "DELETE FROM project_gebruiker WHERE project='" . $project_array['id'] . "' AND rol='" . ($part) . "'";
|
|
db_store_data($query);
|
|
}
|
|
}
|
|
|
|
// Fetch all parts possible for the users on a project
|
|
$part = db_fetch_set("project_gebruiker", "rol");
|
|
|
|
if (is_array($part)) {
|
|
foreach ($part as $item) {
|
|
if (in_array($item, $handle_parts)) {
|
|
switch ($item) {
|
|
case 'normaal':
|
|
for ($level = 8; $level <= 10; $level++) {
|
|
// Query storing new users
|
|
if (strlen($project_array[str_replace(array("-", ":"), "_", $item) . "_" . $level])) {
|
|
$users = explode(",", $project_array[str_replace(array("-", ":"), "_", $item) . "_" . $level]);
|
|
foreach ($users as $user) {
|
|
$query = "INSERT INTO project_gebruiker (project, gebruiker, rol, level, begin, eind) VALUES (";
|
|
$query .= "'" . ($project_array['id']) . "',";
|
|
$query .= "'" . ($user) . "',";
|
|
$query .= "'" . ($item) . "',";
|
|
$query .= "'" . ($level) . "',";
|
|
$query .= "NULL,NULL)";
|
|
|
|
// Log user-user action
|
|
db_log_user_user($user, "", "", $item);
|
|
|
|
// Store data
|
|
db_store_data($query);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 'wbu':
|
|
case 'wbv':
|
|
// Query storing new wbu/wbv => Always level 8
|
|
if (strlen($project_array[str_replace(array("-", ":"), "_", $item)])) {
|
|
$users = explode(",", $project_array[str_replace(array("-", ":"), "_", $item)]);
|
|
foreach ($users as $user) {
|
|
$query = "INSERT INTO project_gebruiker (project, gebruiker, rol, level, begin, eind) VALUES (";
|
|
$query .= "'" . ($project_array['id']) . "',";
|
|
$query .= "'" . ($user) . "',";
|
|
$query .= "'" . ($item) . "',";
|
|
$query .= "'8',";
|
|
$query .= "NULL,NULL)";
|
|
|
|
// Log user-user action
|
|
db_log_user_user($user, "", "", $item);
|
|
|
|
// Store data
|
|
db_store_data($query);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
// Query storing new users
|
|
if (strlen($project_array[str_replace(array("-", ":"), "_", $item)])) {
|
|
$users = explode(",", $project_array[str_replace(array("-", ":"), "_", $item)]);
|
|
foreach ($users as $user) {
|
|
$query = "INSERT INTO project_gebruiker (project, gebruiker, rol, begin, eind) VALUES (";
|
|
$query .= "'" . ($project_array['id']) . "',";
|
|
$query .= "'" . ($user) . "',";
|
|
$query .= "'" . ($item) . "',";
|
|
|
|
// Begin/end only suited for switch rights
|
|
if ($item == "schakelen") {
|
|
// Begin date/time
|
|
if ((isset($project_array["begin_datum_" . $user])) && (strlen($project_array["begin_datum_" . $user]))) {
|
|
$query .= "'" . ($project_array["begin_datum_" . $user] . " " . $project_array["begin_tijd_" . $user]) . "',";
|
|
} else {
|
|
$query .= "NULL,";
|
|
}
|
|
|
|
// End date/time
|
|
if ((isset($project_array["eind_datum_" . $user])) && (strlen($project_array["eind_datum_" . $user]))) {
|
|
$query .= "'" . ($project_array["eind_datum_" . $user] . " " . $project_array["eind_tijd_" . $user]) . "')";
|
|
} else {
|
|
$query .= "NULL)";
|
|
}
|
|
} else {
|
|
$query .= "NULL,NULL)";
|
|
}
|
|
|
|
// Log user-user action
|
|
db_log_user_user($user, "", "", $item);
|
|
|
|
// Store data
|
|
db_store_data($query);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Commit transaction
|
|
if (db_commit_transaction()) {
|
|
$result = 1;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch project comment
|
|
*
|
|
* Inputs:
|
|
* - project: Project database id/project name
|
|
*
|
|
* Return: Array containing project comment
|
|
*/
|
|
function db_fetch_project_comment($project_id)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Fetch project comment
|
|
$comment = db_fetch_data("SELECT * FROM project_comment WHERE project='" . $project_id . "' ORDER BY datum DESC");
|
|
|
|
// Parse into result
|
|
if (!empty($comment)) {
|
|
$result = $comment;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Store new project comment
|
|
*
|
|
* Inputs:
|
|
* - project_array: Array containing project comment
|
|
*
|
|
* Return: 1 (OK)/ 0(Error)
|
|
*/
|
|
function db_store_project_comment($project_array, $remove_old = FALSE)
|
|
{
|
|
// Initial return value
|
|
$result = 1;
|
|
|
|
// Remove old
|
|
if ($remove_old) {
|
|
if (!db_store_data("DELETE FROM project_comment WHERE project='" . $project_array['project'] . "'")) {
|
|
// Ok
|
|
$result = 0;
|
|
}
|
|
}
|
|
|
|
if ($result) {
|
|
// Create query
|
|
$query = "INSERT INTO project_comment (project, gebruiker, datum, tekst) VALUES (";
|
|
$query .= "'" . ($project_array['project']) . "',";
|
|
$query .= "'" . ($project_array['gebruiker']) . "',";
|
|
$query .= "'" . ($project_array['datum']) . "',";
|
|
$query .= "'" . specialchars($project_array['tekst']) . "')";
|
|
|
|
if (db_store_data($query)) {
|
|
// OK
|
|
$result = 1;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Store new project lances
|
|
*
|
|
* Inputs:
|
|
* - project_array: Array containing project id and project users
|
|
* - handle_equip: Type equipment which must be handled
|
|
*
|
|
* Return: 1 (OK)/ 0(Error)
|
|
*/
|
|
function db_store_project_lances($project_array, $handle_equip)
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
// Initial return value
|
|
$result = 0;
|
|
|
|
// Start transaction
|
|
db_start_transaction();
|
|
|
|
// Delete equipment/type
|
|
if (is_array($handle_equip)) {
|
|
foreach ($handle_equip as $item) {
|
|
$query = "DELETE FROM project_zkl WHERE project='" . $project_array['id'] . "' AND zkl IN (SELECT id FROM zkl WHERE device='" . $item . "')";
|
|
db_store_data($query);
|
|
|
|
// Query delete old project_device entries
|
|
$query = "DELETE FROM project_device WHERE project='" . $project_array['id'] . "' AND device='" . $item . "'";
|
|
db_store_data($query);
|
|
}
|
|
}
|
|
|
|
// Retrieve all device types
|
|
$types = db_fetch_system_devices($_PAGE_INFO['i18n']);
|
|
|
|
// Clear all types
|
|
if (is_array($types)) {
|
|
foreach ($types as $type) {
|
|
// Device name
|
|
$device = $type['id'];
|
|
|
|
// Query storing new equipment
|
|
if (strlen($project_array[$device])) {
|
|
// Retrieve all ids
|
|
$ids = explode(",", $project_array[$device]);
|
|
|
|
foreach ($ids as $id) {
|
|
$query = "INSERT INTO project_zkl (project, zkl, opmerking) VALUES (";
|
|
$query .= "'" . ($project_array['id']) . "',";
|
|
$query .= "'" . ($id) . "',";
|
|
if (strlen($project_array["opmerking_" . $id])) {
|
|
$query .= "'" . specialchars($project_array["opmerking_" . $id]) . "')";
|
|
} else {
|
|
$query .= "NULL)";
|
|
}
|
|
|
|
// Log user-user action
|
|
db_log_user_lance($id, "", "");
|
|
|
|
// Store data
|
|
db_store_data($query);
|
|
}
|
|
}
|
|
|
|
// Query storing new device entries
|
|
if (strlen($project_array["aantal_" . $device])) {
|
|
$query = "INSERT INTO project_device (project, device, aantal) VALUES (";
|
|
$query .= "'" . ($project_array['id']) . "',";
|
|
$query .= "'" . ($type['id']) . "',";
|
|
$query .= "'" . ($project_array["aantal_" . $device]) . "')";
|
|
db_store_data($query);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Commit transaction
|
|
if (db_commit_transaction()) {
|
|
$result = 1;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Color assignment?
|
|
*
|
|
* Inputs:
|
|
* - project_id: project database id
|
|
* - device_type: device type
|
|
* - customer: customer
|
|
* - customer: project info
|
|
*
|
|
* Return: color
|
|
*/
|
|
function db_check_project_color($project_id, $device_type, $customer, $project_array = "")
|
|
{
|
|
// Initial value
|
|
$color = "";
|
|
|
|
// Get project info
|
|
if (is_array($project_array)) {
|
|
$project_info = $project_array;
|
|
} else {
|
|
$project_info = db_fetch_project($project_id, "", 1);
|
|
|
|
}
|
|
|
|
// Get all project equipment
|
|
$equipment = db_fetch_project_lances($project_id);
|
|
|
|
// in service?
|
|
if (is_array($equipment)) {
|
|
foreach ($equipment as $item) {
|
|
// Check on device type and on lance status service/winkel
|
|
if (((!strlen($device_type)) || ($item['device'] == $device_type)) && (($item['lans_status'] == "service") || ($item['lans_status'] == "winkel"))) {
|
|
$color = "service";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Rented?
|
|
if (!strlen($color)) {
|
|
if (is_array($equipment)) {
|
|
foreach ($equipment as $item) {
|
|
// Check on device type and on lance status active
|
|
if (((!strlen($device_type)) || ($item['device'] == $device_type)) && ($item['lans_status'] == "actief")) {
|
|
// Check if rented
|
|
if (((!strlen($customer)) || ($item['eigenaar'] == $customer)) && (($item['gebruiker'] != $customer) && (!is_null($item['gebruiker'])))) {
|
|
$color = "rented";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Inactive?
|
|
if (!strlen($color)) {
|
|
if (is_array($equipment)) {
|
|
foreach ($equipment as $item) {
|
|
// Check on device type and on lance status active and customer status inactive and hide rentals
|
|
if (((!strlen($device_type)) || ($item['device'] == $device_type)) && ($item['lans_status'] == "actief") && ($item['klant_status'] == "inactief") &&
|
|
((($item['gebruiker'] == $item['eigenaar']) && ($item['eigenaar'] == $project_info['klant'])) ||
|
|
((is_null($item['gebruiker'])) && ($item['eigenaar'] == $project_info['klant'])) ||
|
|
(($item['gebruiker'] == $project_info['klant'])))
|
|
) {
|
|
$color = "inactive";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Multiple assigned?
|
|
if (!strlen($color)) {
|
|
if (is_array($equipment)) {
|
|
foreach ($equipment as $item) {
|
|
// Check on device type and on lance status active and customer status active and hide rentals
|
|
if (((!strlen($device_type)) || ($item['device'] == $device_type)) && ($item['lans_status'] == "actief") && ($item['klant_status'] == "actief") &&
|
|
((($item['gebruiker'] == $item['eigenaar']) && ($item['eigenaar'] == $project_info['klant'])) ||
|
|
((is_null($item['gebruiker'])) && ($item['eigenaar'] == $project_info['klant'])) ||
|
|
(($item['gebruiker'] == $project_info['klant'])))
|
|
) {
|
|
if (is_array(db_fetch_lance_projects($item['id'], 1, $customer, 1))) {
|
|
$color = "d_assigned_project";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $color;
|
|
}
|
|
|
|
|
|
/**
|
|
* Store changes in project
|
|
*
|
|
* Inputs:
|
|
* - Log_id: Log enty
|
|
* - project_id: Project database id
|
|
* - orig_data: Original data before update
|
|
*
|
|
*/
|
|
function db_update_project_version($log_id, $project_id, $orig_data)
|
|
{
|
|
// Get all fields
|
|
$fields = db_fetch_set("log_gebruiker_project");
|
|
|
|
// Get project info
|
|
$project = db_fetch_project($project_id, "", 1);
|
|
|
|
if ((is_array($fields)) && (!empty($fields)) && (is_array($project)) && (!empty($project))) {
|
|
// Query inserting new log_gebruiker_project
|
|
$query = "INSERT INTO log_gebruiker_project (";
|
|
|
|
for ($i = 0; $i < sizeof($fields); $i++) {
|
|
$query .= $fields[$i];
|
|
|
|
// Add comma?
|
|
if (($i + 1) != sizeof($fields)) {
|
|
$query .= ",";
|
|
}
|
|
}
|
|
|
|
$query .= ") VALUES (";
|
|
|
|
for ($i = 0; $i < sizeof($fields); $i++) {
|
|
switch (strtolower($fields[$i])) {
|
|
case "id":
|
|
$query .= "'" . ($log_id) . "'";
|
|
break;
|
|
case "project":
|
|
$query .= "'" . addslashes($project_id) . "'";
|
|
break;
|
|
case "wijzigingen":
|
|
// Initial value
|
|
$first = 1;
|
|
|
|
// Original data?
|
|
if (is_array($orig_data)) {
|
|
$change_set = db_fetch_set("log_gebruiker_project", "wijzigingen");
|
|
if (is_array($change_set)) {
|
|
foreach ($change_set as $item) {
|
|
// different then orig data
|
|
if ((!is_null($project[$item])) && ((!isset($orig_data[$item])) || ($project[$item] != $orig_data[$item]))) {
|
|
if ($first) {
|
|
$first = 0;
|
|
$query .= "'";
|
|
} else {
|
|
$query .= ",";
|
|
}
|
|
$query .= $item;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Item added => null
|
|
if (!$first) {
|
|
$query .= "'";
|
|
} else {
|
|
$query .= "'null'";
|
|
}
|
|
break;
|
|
default:
|
|
if ((is_array($orig_data)) && (!is_null($project[$fields[$i]])) && ((!isset($orig_data[$fields[$i]])) || ($project[$fields[$i]] != $orig_data[$fields[$i]]))) {
|
|
$query .= "'" . addslashes($project[$fields[$i]]) . "'";
|
|
} else {
|
|
$query .= "NULL";
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Add comma?
|
|
if (($i + 1) != sizeof($fields)) {
|
|
$query .= ",";
|
|
}
|
|
}
|
|
|
|
$query .= ")";
|
|
}
|
|
|
|
if (db_store_data($query)) {
|
|
// Result OK
|
|
$result = 1;
|
|
} else {
|
|
// Result NOK
|
|
$result = 0;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch last project release (top level checking)
|
|
*
|
|
* Inputs:
|
|
* - project_id: Project database id
|
|
*
|
|
* Return: Array containing log_gebruiker info with last released info
|
|
*/
|
|
function db_fetch_last_release_project($project_id)
|
|
{
|
|
// Initial return value
|
|
$result = "";
|
|
|
|
// Create query
|
|
$query = "SELECT * FROM log_gebruiker WHERE id=";
|
|
$query .= "(select min(id) from log_gebruiker_project where wijzigingen='sstatus' and sstatus='niet vrijgegeven' ";
|
|
$query .= "and id > (select max(id) from log_gebruiker_project where project='" . $project_id . "' and wijzigingen='sstatus' and sstatus='vrijgegeven'))";
|
|
|
|
$row_projects = db_fetch_data($query);
|
|
|
|
// Parse into result
|
|
if (!empty($row_projects)) {
|
|
$result = $row_projects[0];
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Send mail to all project users
|
|
*
|
|
* Inputs:
|
|
* - project: Project array
|
|
* - project_orig: Project array original
|
|
* - users_changed Users changed on project/period
|
|
* - equip_changed Equipment changed on project/period
|
|
*
|
|
*/
|
|
function db_project_sendmail($project, $project_orig = "", $users_changed = FALSE, $equip_changed = FALSE)
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
// Add mail functionality
|
|
require_once("include/mail.php");
|
|
|
|
// Initial values
|
|
$email = array();
|
|
$changed_item = array();
|
|
|
|
// Fix sstatus => 'request for release' equals 'non-released' => Needed to power the devices
|
|
if (is_array($project_orig)) {
|
|
$project_orig['sstatus'] = ($project_orig['sstatus'] == "verzoek tot vrijgeven") ? "niet vrijgegeven" : $project_orig['sstatus'];
|
|
}
|
|
$project['sstatus'] = ($project['sstatus'] == "verzoek tot vrijgeven") ? "niet vrijgegeven" : $project['sstatus'];
|
|
|
|
// Get project changes
|
|
if (is_array($project_orig)) {
|
|
$change_set = array("sstatus", "ostatus", "pstatus", "status", "users", "equip");
|
|
foreach ($change_set as $item) {
|
|
switch ($item) {
|
|
case "sstatus":
|
|
case "ostatus":
|
|
case "pstatus":
|
|
case "status":
|
|
if ($project[$item] != $project_orig[$item]) {
|
|
array_push($changed_item, $item);
|
|
}
|
|
break;
|
|
case "users":
|
|
if ($users_changed) {
|
|
array_push($changed_item, $item);
|
|
}
|
|
break;
|
|
case "equip":
|
|
if ($equip_changed) {
|
|
array_push($changed_item, $item);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Something changed? => Send mail
|
|
if ((!is_array($project_orig)) || (!empty($changed_item))) {
|
|
// Get all supported languages (check al project users)
|
|
$i18n_languages = array();
|
|
|
|
// Get all users
|
|
$project_users = db_fetch_project_users($project['id']);
|
|
|
|
// Get i18n
|
|
if (is_array($project_users)) {
|
|
foreach ($project_users as $project_user) {
|
|
if (!in_array($project_user['i18n'], $i18n_languages)) {
|
|
array_push($i18n_languages, $project_user['i18n']);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get report settings from ini file
|
|
$ini_file = get_all_files($_PAGE_INFO['base_path'] . SKIN_DIR . $_PAGE_INFO['skin'] . "/", array("ini"));
|
|
$_PAGE_INFO['ini'] = parse_ini_file($ini_file[0], true);
|
|
|
|
if (is_array($i18n_languages)) {
|
|
foreach ($i18n_languages as $i18n) {
|
|
// Set language
|
|
i18n_settext_language($i18n, $_PAGE_INFO['base_path'] . "locale/");
|
|
|
|
// Define font family
|
|
$content[$i18n] = mail_default_stylesheet();
|
|
|
|
/************************************/
|
|
/* Welcome text */
|
|
/************************************/
|
|
$content[$i18n] .= _("Dear MTinfo user") . ",<br><br>";
|
|
|
|
if (!is_array($project_orig)) {
|
|
$content[$i18n] .= _("You are assigned to the new project");
|
|
} else {
|
|
$content[$i18n] .= _("The following project, you are assigned to, has been changed");
|
|
}
|
|
$content[$i18n] .= ": <b>" . $project['naam'] . "</b><br><br>";
|
|
$content[$i18n] .= _("Hereby the project overview") . ":" . "<br><br>";
|
|
|
|
/************************************/
|
|
/* General info */
|
|
/************************************/
|
|
$content[$i18n] .= "<h1>" . _("General info") . "</h1>";
|
|
$content[$i18n] .= "<table>\n<th width=\"25%\">" . _("Item") . "</th><th>" . _("Value") . "</th>\n";
|
|
|
|
$content[$i18n] .= "<tr><td>" . _("Name") . "</td><td>" . ucfirst($project['naam']) . "</td></tr>\n";
|
|
$description = (strlen($project['beschrijving'])) ? $project['beschrijving'] : "-";
|
|
$content[$i18n] .= "<tr><td>" . _("Description") . "</td><td>" . ucfirst($description) . "</td></tr>\n";
|
|
|
|
// Add dummy (needed for the subject)
|
|
$size_changed_items = (sizeof($changed_item) > 0) ? sizeof($changed_item) : 1;
|
|
|
|
for ($i = 0; $i < $size_changed_items; $i++) {
|
|
// Initial values
|
|
$from = "";
|
|
$to = "";
|
|
$changed = "";
|
|
|
|
switch ($changed_item[$i]) {
|
|
case "ostatus":
|
|
$changed = _("Design") . " " . ("status");
|
|
$from = $project_orig['ostatus'];
|
|
$to = $project['ostatus'];
|
|
break;
|
|
case "pstatus":
|
|
if ($project['type'] == "rc") {
|
|
$changed = _("Planning") . " " . ("status");
|
|
$from = $project_orig['pstatus'];
|
|
$to = $project['pstatus'];
|
|
} else {
|
|
$changed = _("Project") . " " . ("status");
|
|
$from = ($project_orig['pstatus'] == "gereed") ? "vrijgegeven" : $project_orig['sstatus'];
|
|
$from = ($project_orig['status'] == "afgesloten") ? "Finished" : $from;
|
|
$to = ($project['pstatus'] == "gereed") ? "vrijgegeven" : $project['sstatus'];
|
|
$to = ($project['status'] == "afgesloten") ? "Finished" : $to;
|
|
}
|
|
break;
|
|
case "sstatus":
|
|
case "status":
|
|
$changed = _("Project") . " " . ("status");
|
|
$from = ($project_orig['status'] == "afgesloten") ? "Finished" : $project_orig['sstatus'];
|
|
$to = ($project['status'] == "afgesloten") ? "Finished" : $project['sstatus'];
|
|
break;
|
|
case "users":
|
|
$changed = _("Users");
|
|
break;
|
|
case "equip":
|
|
$changed = _("Equipment");
|
|
break;
|
|
default:
|
|
// Dummy to generate correct subject
|
|
break;
|
|
}
|
|
|
|
// Add line?
|
|
if (strlen($changed)) {
|
|
if (!$i) {
|
|
$content[$i18n] .= "<tr><td>" . _("Changes") . "</td>";
|
|
} else {
|
|
$content[$i18n] .= "<tr><td></td>";
|
|
}
|
|
|
|
$content[$i18n] .= "<td>" . $changed;
|
|
if (strlen($from)) {
|
|
$content[$i18n] .= ": " . ucfirst(_($from));
|
|
}
|
|
if (strlen($to)) {
|
|
$content[$i18n] .= " => " . ucfirst(_($to));
|
|
}
|
|
$content[$i18n] .= "</td></tr>\n";
|
|
}
|
|
|
|
if (!strlen($subject[$i18n])) {
|
|
// Define subject
|
|
if (!is_array($project_orig)) {
|
|
$subject[$i18n] = _("MTinfo new project");
|
|
} else {
|
|
$subject[$i18n] = _("MTinfo project update");
|
|
}
|
|
$subject[$i18n] .= ": " . $project['naam'];
|
|
|
|
// Changed project => Display changes
|
|
if (is_array($project_orig)) {
|
|
$subject[$i18n] .= ", " . _("Change") . " " . strtolower($changed);
|
|
if (strlen($from)) {
|
|
$subject[$i18n] .= ": " . ucfirst(_($from));
|
|
}
|
|
if (strlen($to)) {
|
|
$subject[$i18n] .= " => " . ucfirst(_($to));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$content[$i18n] .= "<tr><td>" . _("Changes made by") . "</td><td>" . getUser($_SESSION[$_PAGE_INFO['id']]['login']['user']['id']) . "</td></tr>\n";
|
|
|
|
// Add customer info to subject
|
|
$cust_info = db_fetch_customer($project['klant'], 1);
|
|
$subject[$i18n] .= " (" . $cust_info['bedrijfsnaam'] . ")";
|
|
|
|
if ($project['type'] == "rc") {
|
|
$status = ($project['status'] == "afgesloten") ? "Finished" : $project['sstatus'];
|
|
$content[$i18n] .= "<tr><td>" . _("Project") . " " . _("status") . "</td><td>" . ucfirst(_($status)) . "</td></tr>\n";
|
|
$content[$i18n] .= "<tr><td>" . _("Design") . " " . _("status") . "</td><td>" . ((($status == "vrijgegeven") || ($status == "Finished")) ? ucfirst(_($status)) : ucfirst(_($project['ostatus']))) . "</td></tr>\n";
|
|
$content[$i18n] .= "<tr><td>" . _("Planning") . " " . _("status") . "</td><td>" . ((($status == "vrijgegeven") || ($status == "Finished")) ? ucfirst(_($status)) : ucfirst(_($project['pstatus']))) . "</td></tr>\n";
|
|
} else {
|
|
$status = ($project['pstatus'] == "gereed") ? "vrijgegeven" : $project['sstatus'];
|
|
$status = ($project['status'] == "afgesloten") ? "Finished" : $status;
|
|
$content[$i18n] .= "<tr><td>" . _("Project") . " " . _("status") . "</td><td>" . ucfirst(_($status)) . "</td></tr>\n";
|
|
}
|
|
|
|
$content[$i18n] .= "</table><br>";
|
|
|
|
/************************************/
|
|
/* Project equipment */
|
|
/************************************/
|
|
// Get all project equipment
|
|
$project_equipment = db_fetch_project_lances($project['id']);
|
|
|
|
// Sort
|
|
$project_equipment = array_sort($project_equipment, "type");
|
|
|
|
if (is_array($project_equipment)) {
|
|
$content[$i18n] .= "<h1>" . _("Project") . " " . _("equipment") . "</h1>";
|
|
$content[$i18n] .= "<table>\n<th style=\"text-align:left\">" . _("ID code") . "</th><th>" . _("Status") . " " . ucwords($_PAGE_INFO['skin_name']) . "</th><th>" . _("Status") . " " . _("owner") . "</th><th>" . _("Equipment type") . "</th>\n";
|
|
|
|
foreach ($project_equipment as $equipment) {
|
|
$idcode = $equipment['idcode'];
|
|
if ((strlen($equipment['serienr'])) && ($equipment['idcode'] != $equipment['serienr'])) {
|
|
$idcode .= " - " . $equipment['serienr'];
|
|
}
|
|
|
|
$content[$i18n] .= "<tr><td>" . $idcode . "</td><td>" . ucfirst(_($equipment['lans_status'])) . "</td><td>" . ucfirst(_($equipment['klant_status'])) . "</td><td>" . db_fetch_system_device_name($i18n, $equipment['device']) . "</td></tr>\n";
|
|
}
|
|
$content[$i18n] .= "</table><br>";
|
|
}
|
|
|
|
/************************************/
|
|
/* Project users */
|
|
/************************************/
|
|
$rollen = array("normaal", "administratie", "beheerder", "evaluatie", "urenadministratie");
|
|
foreach ($rollen as $rol) {
|
|
// Get all project users
|
|
$project_users = db_fetch_project_users($project['id'], "", $rol);
|
|
|
|
// Sort
|
|
$project_users = array_sort($project_users, "voornaam");
|
|
|
|
if (is_array($project_users)) {
|
|
$content[$i18n] .= "<h1>" . _("Project") . " " . _("rol:" . $rol) . "</h1>";
|
|
$content[$i18n] .= "<table>\n<th style=\"text-align:left\">" . _("Username") . "</th>";
|
|
|
|
foreach ($project_users as $project_user) {
|
|
$content[$i18n] .= "<tr><td>" . getUser($project_user['id']) . "</td></tr>\n";
|
|
|
|
// Return or release project action?
|
|
if ((($project['sstatus'] == "vrijgegeven") || (($project['type'] == "normaal") && ($project['pstatus'] == "gereed"))) ||
|
|
(($project_orig['sstatus'] == "vrijgegeven") && ($project['sstatus'] == "niet vrijgegeven")) ||
|
|
(($project['type'] == "normaal") && (($project_orig['pstatus'] == "gereed") && ($project['pstatus'] != "gereed")))
|
|
) {
|
|
// Add to email array?
|
|
array_push($email, array(email => $project_user['email'], i18n => $project_user['i18n']));
|
|
}
|
|
}
|
|
$content[$i18n] .= "</table><br>";
|
|
}
|
|
}
|
|
|
|
/************************************/
|
|
/* Period Equipment/users */
|
|
/************************************/
|
|
$periods = db_fetch_project_periods($project['id']);
|
|
|
|
if (is_array($periods)) {
|
|
foreach ($periods as $period) {
|
|
$content[$i18n] .= "<h1>" . _("Period") . " " . substr($period['naam'], strlen($project['id'] . "_")) . "</h1>";
|
|
$content[$i18n] .= "<table>\n";
|
|
|
|
// Get all period users & sort
|
|
$period_users = array_sort(db_fetch_project_users($period['id'], "", "schakelen"), "voornaam");
|
|
|
|
// Add header
|
|
$content[$i18n] .= "<h2>" . _("Users") . "</h2>";
|
|
$content[$i18n] .= "<table>\n<th style=\"text-align:left\">" . _("Username") . "</th><th>" . _("Start switching period") . "</th><th>" . _("End switching period") . "</th>\n";
|
|
|
|
if (is_array($period_users)) {
|
|
foreach ($period_users as $project_user) {
|
|
$content[$i18n] .= "<tr><td>" . getUser($project_user['id']) . "</td><td>" . (strlen($project_user['begin']) ? $project_user['begin'] : "-") . "</td><td>" . (strlen($project_user['begin']) ? $project_user['eind'] : "-") . "</td></tr>\n";
|
|
}
|
|
} else {
|
|
$content[$i18n] .= "<tr><td>-</td><td>-</td><td>-</td></tr>\n";
|
|
}
|
|
|
|
$content[$i18n] .= "</table><br>\n";
|
|
|
|
// Get all period equipment & sort
|
|
$period_equipment = array_sort(db_fetch_project_lances($period['id']), "type");
|
|
|
|
// Add header
|
|
$content[$i18n] .= "<h2>" . _("Equipment") . "</h2>";
|
|
$content[$i18n] .= "<table>\n<th style=\"text-align:left\">" . _("ID code") . "</th><th>" . _("Remark") . "</th>\n";
|
|
|
|
if (is_array($period_equipment)) {
|
|
foreach ($period_equipment as $equipment) {
|
|
$idcode = $equipment['idcode'];
|
|
if ((strlen($equipment['serienr'])) && ($equipment['idcode'] != $equipment['serienr'])) {
|
|
$idcode .= " - " . $equipment['serienr'];
|
|
}
|
|
$remark = db_fetch_project_lances_remark($period['id'], $equipment['id']);
|
|
$content[$i18n] .= "<tr><td>" . $idcode . "</td><td>" . (strlen($remark[0]['opmerking']) ? $remark[0]['opmerking'] : "-") . "</td></tr>\n";
|
|
}
|
|
} else {
|
|
$content[$i18n] .= "<tr><td>-</td><td>-</td></tr>\n";
|
|
}
|
|
$content[$i18n] .= "</table><br>\n";
|
|
|
|
// Get all period comment
|
|
$period_comment = db_fetch_project_comment($period['id']);
|
|
|
|
if (is_array($period_comment)) {
|
|
// Add header
|
|
$content[$i18n] .= "<h2>" . _("Period") . " " . _("Remark") . "</h2>";
|
|
$content[$i18n] .= "<table>\n<th width=\"25%\">" . _("Timestamp") . "</th><th width=\"25%\">" . _("User") . "</th><th>" . _("Remark") . "</th>\n";
|
|
|
|
foreach ($period_comment as $comment) {
|
|
$content[$i18n] .= "<tr><td>" . $comment['datum'] . "</td><td>" . getUser($comment['gebruiker']) . "</td><td>" . $comment['tekst'] . "</td></tr>\n";
|
|
}
|
|
$content[$i18n] .= "</table><br>";
|
|
}
|
|
|
|
$content[$i18n] .= "</table><br>\n";
|
|
}
|
|
}
|
|
|
|
/************************************/
|
|
/* Project setup */
|
|
/************************************/
|
|
if ($project['type'] == "rc") {
|
|
$parts = array("projectleider-rc", "projecten:a", "projecten:b", "projecten:c", "projecten:d", "projecten:e", "projecten:f", "projecten:g", "projecten:h");
|
|
} else {
|
|
$parts = array("projectleider", "projecten:d");
|
|
}
|
|
|
|
// New project?
|
|
if (is_array($project_orig)) {
|
|
// Define whom we want to send an email
|
|
$send_email = array("projectleider", "projectleider-rc");
|
|
|
|
// Change in design status
|
|
if ($project['ostatus'] != $project_orig['ostatus']) {
|
|
switch ($project['ostatus']) {
|
|
case "concept":
|
|
array_push($send_email, "projecten:a");
|
|
break;
|
|
case "gereed":
|
|
array_push($send_email, "projecten:b");
|
|
break;
|
|
case "gevalideerd":
|
|
array_push($send_email, "projecten:c");
|
|
break;
|
|
case "geverifieerd":
|
|
array_push($send_email, "projecten:g");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Change in plan status
|
|
if ($project['pstatus'] != $project_orig['pstatus']) {
|
|
switch ($project['pstatus']) {
|
|
case "concept":
|
|
array_push($send_email, "projecten:d");
|
|
break;
|
|
case "gereed":
|
|
array_push($send_email, "projecten:e");
|
|
break;
|
|
case "gevalideerd":
|
|
array_push($send_email, "projecten:f");
|
|
break;
|
|
case "geverifieerd":
|
|
array_push($send_email, "projecten:g");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Change in project status
|
|
if ($project['sstatus'] != $project_orig['sstatus']) {
|
|
switch ($project['sstatus']) {
|
|
case "vrijgegeven":
|
|
array_push($send_email, "projecten:h");
|
|
break;
|
|
case "niet vrijgegeven":
|
|
array_push($send_email, "projecten:g");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
// New project => Send to all parts
|
|
$send_email = $parts;
|
|
}
|
|
|
|
$content[$i18n] .= "<h1>" . _("Project setup") . "</h1>";
|
|
$content[$i18n] .= "<table>\n";
|
|
for ($i = 0; $i < sizeof($parts); $i++) {
|
|
$content[$i18n] .= "<table>\n<th style=\"text-align:left\">" . ucfirst(_($parts[$i])) . "</th>\n";
|
|
|
|
// Get all users on this project with specific part
|
|
$project_users = db_fetch_project_users($project['id'], "", $parts[$i]);
|
|
|
|
// Sort
|
|
$project_users = array_sort($project_users, "voornaam");
|
|
|
|
if (is_array($project_users)) {
|
|
foreach ($project_users as $project_user) {
|
|
$content[$i18n] .= "<tr><td>" . getUser($project_user['id']);
|
|
if (($parts[$i] == "projectleider-rc") || ($parts[$i] == "projectleider")) {
|
|
$content[$i18n] .= " (" . $project_user['alarmnr'] . ")";
|
|
}
|
|
$content[$i18n] .= "</td></tr>\n";
|
|
|
|
// Add to email array?
|
|
if (in_array($parts[$i], $send_email)) {
|
|
array_push($email, array(email => $project_user['email'], i18n => $project_user['i18n']));
|
|
}
|
|
}
|
|
} else {
|
|
$content[$i18n] .= "<tr><td>-</td></tr>\n";
|
|
}
|
|
$content[$i18n] .= "</table>";
|
|
|
|
if (($i + 1) < sizeof($parts)) {
|
|
$content[$i18n] .= "<br>";
|
|
}
|
|
}
|
|
$content[$i18n] .= "</table><br>\n";
|
|
|
|
/************************************/
|
|
/* Log */
|
|
/************************************/
|
|
// Get all project log info
|
|
$project_comment = db_fetch_project_comment($project['id']);
|
|
|
|
if (is_array($project_comment)) {
|
|
$content[$i18n] .= "<h1>" . _("Project") . " " . _("Remark") . "</h1>";
|
|
$content[$i18n] .= "<table>\n<th width=\"25%\">" . _("Timestamp") . "</th><th width=\"25%\">" . _("User") . "</th><th>" . _("Remark") . "</th>\n";
|
|
|
|
foreach ($project_comment as $comment) {
|
|
$content[$i18n] .= "<tr><td>" . $comment['datum'] . "</td><td>" . getUser($comment['gebruiker']) . "</td><td>" . $comment['tekst'] . "</td></tr>\n";
|
|
}
|
|
$content[$i18n] .= "</table><br>";
|
|
}
|
|
|
|
/************************************/
|
|
/* Exit text */
|
|
/************************************/
|
|
$content[$i18n] .= _("Best regards") . ",<br><br>";
|
|
$content[$i18n] .= $_PAGE_INFO['skin_name'] . "<br><br>";
|
|
$content[$i18n] .= $_PAGE_INFO['ini']['report']['mail'] . "<br>";
|
|
$content[$i18n] .= $_PAGE_INFO['ini']['report']['website'];
|
|
if (strlen($_PAGE_INFO['ini']['report']['footer_text'])) {
|
|
$content[$i18n] .= "<br><br>" . $_PAGE_INFO['ini']['report']['footer_text'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Restore old language
|
|
i18n_settext_language($_PAGE_INFO['i18n'], $_PAGE_INFO['base_path'] . "locale/");
|
|
|
|
if (is_array($i18n_languages)) {
|
|
foreach ($i18n_languages as $i18n) {
|
|
// Sort on i18n
|
|
if (is_array($email)) {
|
|
$mail[$i18n] = array();
|
|
foreach ($email as $item) {
|
|
if ($item['i18n'] == $i18n) {
|
|
array_push($mail[$i18n], $item['email']);
|
|
}
|
|
}
|
|
|
|
// Send mail
|
|
send_mail(implode(",", array_unique($mail[$i18n])), "", $_PAGE_INFO['ini']['report']['bcc'], $_PAGE_INFO['ini']['report']['no-reply'], $subject[$i18n], $content[$i18n]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// done and okay
|
|
return TRUE;
|
|
}
|
|
|
|
/*
|
|
* Send mail with upload to selected user
|
|
*/
|
|
function db_project_send_mail_for_file_upload($project, $role, $file, $extra_receivers = array())
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
$admin_users = db_fetch_project_users($project, "", $role);
|
|
$project_info = db_fetch_project($project, "", 1);
|
|
|
|
// Get all supported languages (check al project users)
|
|
$email = array();
|
|
$i18n_languages = array();
|
|
|
|
// Get i18n
|
|
if (is_array($admin_users)) {
|
|
foreach ($admin_users as $project_user) {
|
|
if (!in_array($project_user['i18n'], $i18n_languages)) {
|
|
array_push($i18n_languages, $project_user['i18n']);
|
|
}
|
|
|
|
// Add to email array?
|
|
array_push($email, array('email' => $project_user['email'], 'i18n' => $project_user['i18n']));
|
|
}
|
|
}
|
|
|
|
// Add some non-project related receivers
|
|
if ((is_array($extra_receivers)) && (!empty($extra_receivers))) {
|
|
foreach ($extra_receivers as $extra_receiver) {
|
|
if (!in_array($extra_receiver['i18n'], $i18n_languages)) {
|
|
array_push($i18n_languages, $extra_receiver['i18n']);
|
|
}
|
|
|
|
// Add to email array?
|
|
array_push($email, array('email' => $extra_receiver['email'], 'i18n' => $extra_receiver['i18n']));
|
|
}
|
|
}
|
|
|
|
// Get report settings from ini file
|
|
$ini_file = get_all_files($_PAGE_INFO['base_path'] . SKIN_DIR . $_PAGE_INFO['skin'] . "/", array("ini"));
|
|
$_PAGE_INFO['ini'] = parse_ini_file($ini_file[0], true);
|
|
|
|
if (is_array($i18n_languages)) foreach ($i18n_languages as $i18n) {
|
|
unset($mail); // email addresses that use this 'i18n'
|
|
|
|
// Set language
|
|
i18n_settext_language($i18n, $_PAGE_INFO['base_path'] . "locale/");
|
|
|
|
// Subject for the mail
|
|
switch ($role) {
|
|
case 'administratie':
|
|
$subject = _("A new work order has been uploaded");
|
|
$msg_text = $subject . ".";
|
|
break;
|
|
case 'beheerder':
|
|
$subject = _("A new item has been uploaded");
|
|
$msg_text = $subject . ".";
|
|
break;
|
|
case 'evaluatie':
|
|
$subject = _("An evaluation form has been filled in");
|
|
$msg_text = $subject . ".";
|
|
break;
|
|
case 'urenadministratie':
|
|
$subject = _("A new work order has been filled in");
|
|
$msg_text = $subject . ".";
|
|
break;
|
|
default:
|
|
// wrong call
|
|
trigger_error("role \"" . $role . "\" not implemented", E_USER_ERROR);
|
|
return FALSE;
|
|
}
|
|
|
|
// Add project info to subject
|
|
$subject .= " (" . $project_info['naam'] . ")";
|
|
|
|
// Define font family
|
|
$content = mail_default_stylesheet();
|
|
|
|
/************************************/
|
|
/* Welcome text */
|
|
/************************************/
|
|
$content .= _("Dear MTinfo user") . ",<br><br>";
|
|
|
|
/************************************/
|
|
/* Body text */
|
|
/************************************/
|
|
// (filled in above while determining the recipients's role)
|
|
$content .= $msg_text;
|
|
$content .= "<br><br>";
|
|
|
|
/************************************/
|
|
/* Exit text */
|
|
/************************************/
|
|
$content .= _("Best regards") . ",<br><br>";
|
|
$content .= $_PAGE_INFO['skin_name'] . "<br><br>";
|
|
$content .= $_PAGE_INFO['ini']['report']['mail'] . "<br>";
|
|
$content .= $_PAGE_INFO['ini']['report']['website'];
|
|
if (strlen($_PAGE_INFO['ini']['report']['footer_text'])) {
|
|
$content .= "<br><br>" . $_PAGE_INFO['ini']['report']['footer_text'];
|
|
}
|
|
|
|
// Sort email addresses on i18n
|
|
if (is_array($email)) {
|
|
$mail = array();
|
|
foreach ($email as $item) {
|
|
if ($item['i18n'] == $i18n) {
|
|
array_push($mail, $item['email']);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($mail) {
|
|
// Send mail
|
|
send_mail(implode(",", array_unique($mail)), "", "", $_PAGE_INFO['ini']['report']['no-reply'], $subject, $content, $file);
|
|
}
|
|
|
|
// Restore old language
|
|
i18n_settext_language($_PAGE_INFO['i18n'], $_PAGE_INFO['base_path'] . "locale/");
|
|
}
|
|
|
|
// done and okay
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/**
|
|
* Store project transfer
|
|
*
|
|
* Inputs:
|
|
* - info : Array with information
|
|
*
|
|
*/
|
|
function db_store_project_transfer($info, $userId, $userTable = 'gebruiker')
|
|
{
|
|
// Check or array
|
|
if (is_array($info)) {
|
|
|
|
$query = "INSERT INTO project_overdracht (project,gebruiker,t,latitude,longitude,platform,status,gebruiker_tabel) VALUES (";
|
|
$query .= "'" . specialchars($info['projectid']) . "',";
|
|
$query .= "'" . specialchars($userId) . "',";
|
|
$query .= "'" . specialchars(convert_datetime($info['timestamp'], 0)) . "',";
|
|
|
|
// Get latitude and longitude from gps string (example: 51.3434;5.53434)
|
|
$gps = explode(";", $info['gps']);
|
|
|
|
//Check if there is GPS
|
|
if (($gps[0] == '0') && ($gps[1] == '0')) {
|
|
$query .= "NULL,";
|
|
$query .= "NULL,";
|
|
} else {
|
|
$query .= "'" . specialchars($gps[0]) . "',";
|
|
$query .= "'" . specialchars($gps[1]) . "',";
|
|
}
|
|
$query .= "'" . specialchars($info['platform']) . "',";
|
|
$query .= "'" . specialchars($info['status']) . "',";
|
|
$query .= "'$userTable'";
|
|
$query .= ")";
|
|
|
|
// Store data
|
|
if (db_store_data($query)) {
|
|
// Data succesfully stored in database`
|
|
return 1;
|
|
} else {
|
|
// Fail to succesfully store data in database`
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// Store fail
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Fetch project transfer
|
|
*
|
|
* Inputs:
|
|
* - project : project id
|
|
* - user : user id
|
|
*
|
|
*/
|
|
function db_fetch_project_transfer($project, $user, $userTable = null)
|
|
{
|
|
$result = 0;
|
|
|
|
// Check if search values are set
|
|
if (isset($project) && isset($user)) {
|
|
$query = "SELECT * FROM project_overdracht WHERE project='$project' AND gebruiker='$user'";
|
|
if ($userTable) {
|
|
$query .= " AND gebruiker_tabel='$userTable'";
|
|
}
|
|
$query .= " ORDER BY t DESC LIMIT 1";
|
|
$result = db_fetch_data($query);
|
|
}
|
|
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch removed user project transfer
|
|
*
|
|
* Inputs:
|
|
* - project : project id
|
|
* - user : user id
|
|
*
|
|
*/
|
|
function db_fetch_project_transfer_removed_users($project)
|
|
{
|
|
$result = 0;
|
|
|
|
// Check if search values are set
|
|
if (isset($project)) {
|
|
$query = "SELECT * FROM project_overdracht WHERE project='" . $project . "' ";
|
|
$query .= "AND gebruiker NOT IN (SELECT gebruiker FROM project_gebruiker WHERE rol='normaal' AND project='" . $project . "') GROUP BY gebruiker";
|
|
$result = db_fetch_data($query);
|
|
}
|
|
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch user and project with signin cod
|
|
*
|
|
* Inputs:
|
|
* - code : signin code
|
|
*
|
|
*/
|
|
function db_fetch_project_user_login_code($settings)
|
|
{
|
|
return db_fetch_login_code($settings, 'gebruiker_inlogcode', 'gebruiker');
|
|
}
|
|
|
|
/**
|
|
* Fetch user and project with signin cod
|
|
*
|
|
* Inputs:
|
|
* - code : signin code
|
|
*
|
|
*/
|
|
function db_fetch_project_profile_login_code($settings)
|
|
{
|
|
return db_fetch_login_code($settings, 'gebruiker_profiel_inlogcode', 'gebruiker_profiel');
|
|
}
|
|
|
|
/**
|
|
* Fetch user and project with signin cod
|
|
*
|
|
* Inputs:
|
|
* - code : signin code
|
|
*
|
|
*/
|
|
function db_fetch_login_code($settings, $table, $userIdColumn)
|
|
{
|
|
$result = 0;
|
|
|
|
// Check if code is set and not empty
|
|
if (is_array($settings) && !empty($settings)) {
|
|
|
|
// Get user and project with code
|
|
if (isset($settings['code']) && !empty($settings['code'])) {
|
|
$query = "SELECT * FROM $table WHERE code='" . $settings['code'] . "' ";
|
|
}
|
|
|
|
// Get code with project and user
|
|
if (isset($settings['project']) && !empty($settings['project']) && isset($settings['user']) && !empty($settings['user'])) {
|
|
$query = "SELECT * FROM $table WHERE project='" . $settings['project'] . "' AND $userIdColumn=" . $settings['user'];
|
|
}
|
|
|
|
// #53 Query could be null
|
|
if (isset($query)) {
|
|
$result = db_fetch_data($query);
|
|
$result = $result[0];
|
|
}
|
|
}
|
|
|
|
|
|
return $result;
|
|
}
|