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

/*
 * HelpCORE source file 
 * ====================
 * 
 * CVS:
 * ----
 * $header$
 * 
 * Purpose:
 * --------
 * Mananages departments
 * 
 * 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' );
} 

if( ! include( 'departments_callbacks.php' ) ) {
	__FATAL__( __FILE__, __LINE__, __CLASS__, __FUNCTION__, 'Cannot load callbacks' );	
}


include_once( 'uls_object_functions.php' );
$GLOBALS['security']->secure();
$coreapm->start();

$limits = null;

// ULS
$uls_organisations_limiter = null;
if( O_RIGHTS_USERLEVELSECURITY && (! $GLOBALS['security']->is_admin) && (! $GLOBALS['security']->global_view) )
{
	$has_access = false; 
	
	// Edit/update/add/insert/delete
	if( isset( $_GET['departmentsaction'] ) && ( $_GET['departmentsaction'] == 'edit' ) )
	{
		$has_access = uls_secure_object_departments( $_GET['departmentseditid'], 'write_ok' );
		$uls_organisations_limiter = uls_secure_organisation_show();
	} 
	elseif( isset( $_POST['departmentsaction'] ) && $_POST['departmentsaction'] == 'update' )
	{
		$has_access = uls_secure_object_departments( $_POST['departmentsupdateid'], 'write_ok' );
		$uls_organisations_limiter = uls_secure_organisation_show();
		$limits = $limits | OBLIGATORY_WHERE( uls_secure_department_show() ); 
	} 
	elseif( isset( $_GET['departmentsaction'] ) && ( $_GET['departmentsaction'] == 'add' ) )
	{
		$uls_organisations_limiter = uls_secure_organisation_show( 'organisation.id', 'add_ok' );
		if( $uls_organisations_limiter[2] != '-1' ) {
			$has_access = true;
		} 
		else {
			$has_access = false;
			$limits |= NO_ADD;
		}
	} 
	elseif( isset( $_POST['departmentsaction'] ) && $_POST['departmentsaction'] == 'insert' )
	{
		$uls_organisations_limiter = uls_secure_organisation_show( 'organisation.id', 'add_ok' );
		if( $uls_organisations_limiter[2] != '-1' ) {
			$has_access = true;
		} 
		else {
			$has_access = false;
		}
		$limits = $limits | OBLIGATORY_WHERE( uls_secure_department_show() );
	} 
	elseif( isset( $_GET['departmentsaction'] ) && ( $_GET['departmentsaction'] == 'delete' ) )
	{
		$has_access = uls_secure_object_departments( $_GET['departmentsdeleteid'], 'add_ok' );
		$uls_organisations_limiter = uls_secure_organisation_show();
	} 
	
	// List or index action
	else
	{
		$limits = $limits | OBLIGATORY_WHERE( uls_secure_department_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;
	} 
}


if ( isset( $_GET['departmentsshowid'] ) && is_numeric( $_GET['departmentsshowid'] ) )
{
	include( 'tree_locator.php' );
	tree_locator( '', '', '', '', '', $_GET['departmentsshowid'] );
} 




$GLOBALS['relational']->add_table_column( 'name', text( 'name' ), TYPE_STRING( 255 ) | REL_UNIQUE | REL_OBLIGATORY );
$GLOBALS['relational']->add_table_column( 'organisation_id', text( 'organisation' ), TYPE_JOIN( 'organisation', 'name', $uls_organisations_limiter ) );

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_TEXT() );

$GLOBALS['relational']->add_line( text( 'notification' ) );
$GLOBALS['relational']->add_table_column( 'email_notification', text( 'email_notification' ), 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[\'departments\'].elements[\'departmentsmaint_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( 'departments', text( 'departments' ), $limits );

$coreapm->finish();

?>
Return current item: HelpCORE