src.dualinventive.com/mtinfo/dist/webroot/rc-4.05/scripts/page/project.php

236 lines
10 KiB
PHP

<?php
/** \file scripts\page\project.php
* \brief DI webinterface project script.
* \author Rob Schalken, Core|Vision
* \version 1.0
* \date 17-10-2008
*
* This file contains the project script. This file creates the menu on which the user
* can select out of different projects.
*/
//== Required settings ======================
$_PAGE_INFO['page_title'] = _("projects");
$_SESSION[$_PAGE_INFO['id']]['title'] = _("Project overview");
//===========================================
// Clear previous session info
unset($_SESSION[$_PAGE_INFO['id']]['login']['project']);
unset($_SESSION[$_PAGE_INFO['id']]['main_menu']);
// Update global variables
UpdateGlobals();
// Verify "login" rights!
if (Ver_Rights_Project_Log("login", "projecten")) {
// Check if projects are available
$projects = db_fetch_projects("", $_SESSION[$_PAGE_INFO['id']]['login']['customer']['id']);
// Check id current user is member of these projects and if these are unfinished
$user_projects = array();
if (is_array($projects)) {
foreach ($projects as $project) {
// Check for non-released projects
// normal project => planning status must be finished (and non-RS3000)
// rc project => planning and design status must be validated
if (($project['status'] != "afgesloten") &&
((($project['type'] == "normaal") && ($project['pstatus'] == "gereed") && (is_dev("DESKTOP"))) ||
(($project['type'] == "rc") && (($project['pstatus'] == "gevalideerd") && ($project['ostatus'] == "gevalideerd"))))) {
$users = db_fetch_project_users($project['id'], $_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], array("normaal","wbv","wbu"));
if (is_array($users)) {
if (is_dev("DESKTOP")) {
array_push($user_projects, $project);
}
else {
// Initial values
$valid_project = 0;
// Get all periods for this project
$periods = db_fetch_project_periods($project['id']);
// Check all active periods
if (is_array($periods)) {
foreach($periods as $period) {
// Get "all" switching users for this period
$period_users = db_fetch_project_users($period['id'], $_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "schakelen");
// "users" assigned to this period?
if (is_array($period_users)) {
$valid_project = 1;
}
}
// Valid project?
if ($valid_project) {
// Get all project equipment and check if imei is on project
$equipment = db_fetch_project_lances($project['id'], "", "", 0, array("actief"), array("actief"));
if (is_array($equipment)) {
$finished = 0;
foreach($equipment as $item) {
if (!$finished) {
$item_info = db_fetch_lance($item['id'],"", 1);
if ($item_info['imei'] == $_SESSION[$_PAGE_INFO['id']]['login']['imei']) {
array_push($user_projects, $project);
// Set flag
$finished = 1;
}
}
}
}
}
}
}
}
}
}
}
// When no project and not the magazijbeheer/project root rights => redirect to main menu (or to login when RS3000)
if ((empty($user_projects)) && ((!is_dev("DESKTOP")) || (!db_ver_rights_user_one_valid($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "menu:projecten&projecten:d,menu:projecten:root")))) {
if ((is_dev("DESKTOP")) && (db_ver_rights_user_one_valid($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "hoofdmenu"))) {
// Redirect to main page and set project skip values
unset($_SESSION[$_PAGE_INFO['id']]['login']['project']);
$_SESSION[$_PAGE_INFO['id']]['login']['project']['skip'] = 1;
header("Location: ?id=" . $_PAGE_INFO['id'] . "&href=" . PAGE_MENU . "");
// Update global variables
UpdateGlobals();
}
else {
if (!is_dev("RS3000")) {
// log out
$_SESSION[$_PAGE_INFO['id']]['login_info']['errormsg'] = "No projects available";
header("Location: ?id=" . $_PAGE_INFO['id'] . "&href=" . PAGE_LOGIN . "");
}
else {
SendMessageRS3000(array("status='1'","message='no_projects_available'"));
}
}
}
else {
if (!is_dev("RS3000")) {
// Show page header
print_page_header();
// Set project links and rights
if (!empty($user_projects)) {
for ($i = 0; $i < (sizeof($user_projects)); $i++) {
if ($user_projects[$i]['status'] != "afgesloten") {
$menuitems[$i] = $user_projects[$i]['naam'];
$menulinks[$i] = "?id=" . $_PAGE_INFO['id'] . "&href=action/_a_project&link=page/menu&project=" . $user_projects[$i]['naam'] . "&project_id=" . $user_projects[$i]['id'] . "&page_project=" . urlencode($user_projects[$i]['id']);
$menurights[$i] = valid_timestamp($user_projects[$i]['begin'], $user_projects[$i]['eind'], 0);
$extra_info[$i]['text'] = ($user_projects[$i]['type'] == "normaal") ? "" : strtoupper($user_projects[$i]['type']);
// Project locked?
$lock = 0;
if ($user_projects[$i]['type'] == "rc") {
// Periods locked?
if ($user_projects[$i]['sstatus'] == "vrijgegeven") {
$periods = db_fetch_project_periods($user_projects[$i]['id']);
if (is_array($periods)) {
foreach($periods as $period) {
if ($period['sstatus'] != "vrijgegeven") {
// Not yet released
$lock = 1;
}
}
}
}
else {
// Not yet released
$lock = 1;
}
}
$extra_info[$i]['icon'] = ($lock) ? "lock.png" : "";
}
}
// Display menu
print_menu(_("Project overview"), $menuitems, $menulinks, $menurights, 1, 0, $extra_info);
}
// Clear menu items
$menuitems = array();
$menulinks = array();
$menurights = array();
// Display menu overview menu
$menuitems[] = _("Main menu");
$menulinks[] = "?id=" . $_PAGE_INFO['id'] . "&href=action/_a_project&link=page/menu&project=skip&project_id=-1";
$menurights[] = db_ver_rights_user_one_valid($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "hoofdmenu");
$menuitems[] = _("Service and repair");;
$menulinks[] = "?id=" . $_PAGE_INFO['id'] . "&href=action/_a_project&link=page/menu_lance&action=service_repair_overview&project=skip&project_id=-1";
$menurights[] = db_ver_rights_user_one_valid($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "menu:lansen:root,menu:lansen&menu:lansen:onderhoudsrapporten,menu:lansen&productie,menu:lansen&administratie");
$menuitems[] = _("Assign equipment");
$menulinks[] = "?id=" . $_PAGE_INFO['id'] . "&href=action/_a_project&link=page/menu_project_search&action=material_overview&project=skip&project_id=-1";
$menurights[] = db_ver_rights_user_one_valid($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'], "menu:projecten&projecten:d,menu:projecten:root");
print_menu(_("Menu overview"), $menuitems, $menulinks, $menurights);
// Show page footer
print_page_footer();
}
else {
// Get ids, names and status
$project = array();
$id = array();
$locked = array();
// Sort array
$users_projects = array_sort($users_projects, "naam");
foreach($user_projects as $user_project) {
array_push($project, $user_project['naam']);
array_push($id, $user_project['id']);
// Project locked?
$lock = 0;
if ($user_project['type'] == "rc") {
// Periods locked?
if ($user_project['sstatus'] == "vrijgegeven") {
$periods = db_fetch_project_periods($user_project['id']);
if (is_array($periods)) {
foreach($periods as $period) {
if ($period['sstatus'] != "vrijgegeven") {
// Not yet released
$lock = 1;
}
}
}
}
else {
// Not yet released
$lock = 1;
}
}
array_push($locked, $lock);
}
// Catch CSV character
if (is_array($project)) {
for($i=0; $i<sizeof($project); $i++) {
$project[$i] = str_replace(",", " ", $project[$i]);
}
}
// RS3000 send message
SendMessageRS3000(array("status='0'","project='" . implode(",", $project) . "'","project_id='" . implode(",", $id) . "'","project_locked='" . implode(",", $locked) . "'"));
}
}
}
else {
// Redirect to login page (and logout)
$_SESSION[$_PAGE_INFO['id']]['login_info']['errormsg'] = "Account has been blocked";
$_SESSION[$_PAGE_INFO['id']]['login_info']['username'] = $_SESSION[$_PAGE_INFO['id']]['login']['user']['name'];
$_SESSION[$_PAGE_INFO['id']]['login_info']['customer'] = $_SESSION[$_PAGE_INFO['id']]['login']['customer']['name'];
header("Location: ?id=" . $_PAGE_INFO['id'] . "&href=" . PAGE_LOGIN . "");
}
?>