Location: PHPKode > projects > HelpCORE > helpcore/module_helpcore_secure/rooms.php
<?php

/*
 * HelpCORE source file 
 * ====================
 * 
 * CVS:
 * ----
 * $header$
 * 
 * Purpose:
 * --------
 * Manages rooms
 * 
 * Copyright:
 * ----------
 * Copyright (C) 2002-2003 Dennis Fleurbaaij <hide@address.com>
 * Copyright (C) 2002-2005 IO Software <hide@address.com>
 * 
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software Foundation;
 * either version 2 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, 
 * Cambridge, MA 02139, USA.
 * 
 * Please note that this software is dual licensed. For the commercial use of this 
 * software you will need a Commercial License. Please see http://www.io-software.nl
 * for the terms and conditions.
 * 
 * For more information you can contact IO Software at http://www.io-software.nl
 */ 
 
if ( ! include( '../coreapm/coreapm.php' ) )
{
	die( 'Cannot include CORE APM' );
} 
include_once( 'uls_object_functions.php' );
$GLOBALS['security']->secure();
$coreapm->start();

$limits = null;

// ULS
$uls_buildings_limiter = null;
$uls_buildings_limiter_string = '';
if( O_RIGHTS_USERLEVELSECURITY && (! $GLOBALS['security']->is_admin) && (! $GLOBALS['security']->global_view) )
{
	$has_access = false; 
	
	// Edit/update/add/insert/delete
	if( isset( $_GET['roomsaction'] ) && ( $_GET['roomsaction'] == 'edit' ) )
	{
		$has_access = uls_secure_object_rooms( $_GET['roomseditid'], 'write_ok' );
		$uls_buildings_limiter = uls_secure_building_show(); 
	} 
	elseif( isset( $_POST['roomsaction'] ) && $_POST['roomsaction'] == 'update' )
	{
		$has_access = uls_secure_object_rooms( $_POST['roomsupdateid'], 'write_ok' );
		$uls_buildings_limiter = uls_secure_building_show(); 
		$limits = $limits | OBLIGATORY_WHERE( uls_secure_room_show() ); 
	} 
	elseif( isset( $_GET['roomsaction'] ) && ( $_GET['roomsaction'] == 'add' ) )
	{
		$uls_buildings_limiter = uls_secure_building_show( 'buildings.id', 'add_ok' );
		if( $uls_buildings_limiter[2] != '-1' ) {
			$has_access = true;
		} 
		else {
			$has_access = false;
			$limits |= NO_ADD;
		}
	} 
	elseif( isset( $_POST['roomsaction'] ) && $_POST['roomsaction'] == 'insert' )
	{
		$uls_buildings_limiter = uls_secure_building_show( 'buildings.id', 'add_ok' );
		if( $uls_buildings_limiter[2] != '-1' ) {
			$has_access = true;
		} 
		else {
			$has_access = false;
		}
		$limits = $limits | OBLIGATORY_WHERE( uls_secure_room_show() );
	} 
	elseif( isset( $_GET['roomsaction'] ) && ( $_GET['roomsaction'] == 'delete' ) )
	{
		$has_access = uls_secure_object_rooms( $_GET['roomsdeleteid'], 'add_ok' );
		$uls_buildings_limiter = uls_secure_building_show(); 
	} 
	
	// List or index action
	else
	{
		$uls_buildings_limiter = uls_secure_building_show(); 
		$limits = $limits | OBLIGATORY_WHERE( uls_secure_room_show() ); 
		$has_access = true;
	} 
	
	// User has no common rights-points with this object
	if( ! $has_access )
	{
		$GLOBALS['box']->add( text( 'uls' ), text( 'uls_in_violation' ) );
		$GLOBALS['coreapm']->finish();
		die;
	}
} 
else {
	if ( ! $GLOBALS['security']->is_admin )
	{
		$limits = $limits | NO_ADD | NO_EDIT | NO_DELETE;
	} 
}



$b_id = false;
if ( isset( $_GET['roomsshowid'] ) && is_numeric( $_GET['roomsshowid'] ) )
{
	include_once( 'tree_locator.php' );
	tree_locator( '', '', $_GET['roomsshowid'] );
} elseif ( isset( $_GET['roomseditid'] ) && is_numeric( $_GET['roomseditid'] ) )
{
	include_once( 'tree_locator.php' );
	tree_locator( '', '', $_GET['roomseditid'] );
} elseif ( isset( $_GET['roomsbuildings_id'] ) && is_numeric( $_GET['roomsbuildings_id'] ) )
{
	include_once( 'tree_locator.php' );
	tree_locator( '', '', '', $_GET['roomsbuildings_id'] );
	$b_id = $_GET['roomsbuildings_id'];
} elseif ( isset( $_GET['buildingsshowid'] ) && is_numeric( $_GET['buildingsshowid'] ) )
{
	$b_id = $_GET['buildingsshowid'];
} 

/**
 * Callback function for CoreAPM to show all related data when showing rooms
 */
function rooms_post_show( $id )
{
	relational_1_to_n( 'hardware.php', array( 'hardware.rooms_id', '=', $id ) );
	
	if( USE_SOFTWARE )
	{
		include_once( 'device_software_handler.php' );
		software_allowed_handler( 'rooms', 'room_id', 'show', $id, false );
	}
} 

/**
 * Callback function for CoreAPM to show all related data when editing rooms
 */
function rooms_post_edit( $id )
{
	if( USE_SOFTWARE )
	{
		include_once( 'device_software_handler.php' );
		software_allowed_handler( 'rooms', 'room_id', 'edit', $id, true );
	}

}


/**
 * Callback function for CoreAPM to delete all related data when deleting rooms
 */
function rooms_post_delete( $id, &$message )
{
	$GLOBALS['db']->query( 'UPDATE incidents SET rooms_id=NULL WHERE rooms_id='.$id );
	$GLOBALS['db']->query( 'UPDATE users SET rooms_id=NULL WHERE rooms_id='.$id );
	$GLOBALS['db']->query( 'UPDATE hardware SET rooms_id=NULL WHERE rooms_id='.$id );
	
	$GLOBALS['db']->query( 'DELETE FROM security_hardware_rooms WHERE room_id='.$id );
	$GLOBALS['db']->query( 'DELETE FROM security_incidents_rooms WHERE room_id='.$id );
	$GLOBALS['db']->query( 'DELETE FROM security_users_rooms WHERE room_id='.$id );
	$GLOBALS['db']->query( 'DELETE FROM security_group_hardware_rooms WHERE room_id='.$id );
	$GLOBALS['db']->query( 'DELETE FROM security_group_incidents_rooms WHERE room_id='.$id );
	$GLOBALS['db']->query( 'DELETE FROM security_group_users_rooms WHERE room_id='.$id );

	$GLOBALS['db']->query( 'DELETE FROM allowed_software_rooms WHERE room_id='.$id );	
	$GLOBALS['db']->query( 'UPDATE incidents SET date_sla_cache=NULL WHERE rooms_id='.$id );
	
	return true;
}

/**
 * Callback function for CoreAPM to update all related data when updating rooms
 */

function rooms_post_update( $table_name, $id, &$row, &$message ) {
	$GLOBALS['db']->query( 'UPDATE incidents SET date_sla_cache=NULL WHERE rooms_id='.$id );
}

$GLOBALS['relational']->add_table_column( 'name', text( 'name' ), TYPE_STRING( 255 ) | REL_OBLIGATORY );

if( is_array( $uls_buildings_limiter) ) {
	$uls_buildings_limiter_string = ' AND '.$uls_buildings_limiter[0] .' ' .$uls_buildings_limiter[1] .' ' .$uls_buildings_limiter[2];
}

if ( $b_id ) $GLOBALS['relational']->add_table_column( 'buildings_id', text( 'building' ), TYPE_JOIN( 'buildings', 'name', $uls_buildings_limiter ) | REL_OBLIGATORY | NO_SHOW );
else $GLOBALS['relational']->add_table_column( 'buildings_id', text( 'building' ), TYPE_ADVANCED_JOIN( 'buildings',
																										'name,oname',
																										'SELECT buildings.id AS id,
																							       		   		  buildings.name AS name, 
																									 	   		  organisation.name as oname 
																									  		 FROM buildings,
																										   		  organisation 
																									  		WHERE buildings.organisation_id=organisation.id ' . $uls_buildings_limiter_string ) );

if( USE_SLA )
{
	$GLOBALS['relational']->add_table_column( 'sla_level_id', text( 'sla_levels' ), TYPE_JOIN( 'sla_levels', 'name' ) | VIS_NO_INDEX | VIS_NO_SEARCH );
} 

$GLOBALS['relational']->add_table_column( 'description', text( 'description' ), TYPE_STRING( 255 ) );

$GLOBALS['relational']->add_line( text( 'address' ) );
$GLOBALS['relational']->add_table_column( 'address', text( 'address' ), TYPE_STRING( 255 ) | VIS_NO_INDEX | VIS_NO_SEARCH );
$GLOBALS['relational']->add_table_column( 'postal', text( 'postal' ), TYPE_STRING( 255 ) | VIS_NO_INDEX | VIS_NO_SEARCH );
$GLOBALS['relational']->add_table_column( 'city', text( 'city' ), TYPE_STRING( 255 ) | VIS_NO_INDEX | VIS_NO_SEARCH );
$GLOBALS['relational']->add_table_column( 'country', text( 'country' ), TYPE_STRING( 255 ) | VIS_NO_INDEX | VIS_NO_SEARCH );

$GLOBALS['relational']->add_line( text( 'tel_nr' ) );
$GLOBALS['relational']->add_table_column( 'tel', text( 'tel_nr' ), TYPE_STRING( 255 ) | VIS_NO_INDEX | VIS_NO_SEARCH );
$GLOBALS['relational']->add_table_column( 'fax', text( 'fax_nr' ), TYPE_STRING( 255 ) | VIS_NO_INDEX | VIS_NO_SEARCH );

if( USE_MAINTAINANCE )
{
	$GLOBALS['relational']->add_line( text( 'maintainance' ) );
	$GLOBALS['relational']->add_table_column( 'maint_cyclus', text( 'maint_cycle' ), TYPE_INTEGER() | OTH_DEFAULT( '0' ) | VIS_NO_INDEX | VIS_NO_SEARCH | ADD_OPTION( text( 'days' ) . ' ' . text( 'or' ) . ' ' . form_input( 'cycle_weeks', '', 4, 'onchange="javascript:document.forms[\'rooms\'].elements[\'roomsmaint_cyclus\'].value=(this.value*7);"' ) . ' ' . text( 'weeks' ) ) );
	if( O_MAINT_USE_NOTES ) {
		$GLOBALS['relational']->add_table_column( 'notes', text( 'notes' ), TYPE_TEXT() | VIS_NO_INDEX | VIS_NO_SEARCH );
	}
} 

$GLOBALS['relational']->manage( 'rooms', text( 'rooms' ), $limits );

$coreapm->finish();

?>
Return current item: HelpCORE