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

/*
 * HelpCORE source file 
 * ====================
 * 
 * CVS:
 * ----
 * $header$
 * 
 * Purpose:
 * --------
 * groups.php uses this file to set group rights within HelpCORE
 * 
 * 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
 */ 
 
// These are meta actions
if ( isset( $_POST['ulsMetaAction'] ) && ( $_POST['ulsMetaAction'] != '' ) && isset( $_POST['groupId'] ) && ( $_POST['groupId'] != '' ) && is_numeric( $_POST['groupId'] ) )
{
	if ( ! include_once( '../coreapm/coreapm.php' ) )
	{
		die( 'Cannot include CORE APM' );
	} 
	$GLOBALS['security']->secure( ADMIN );
	
	$groupId = $_POST['groupId'];
	
	switch ( $_POST['ulsMetaAction'] )
	{
		case 'delete':
			$GLOBALS['db']->query( 'DELETE FROM security_group_hardware_organisation  WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_hardware_buildings WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_hardware_rooms WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_hardware_departments WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_hardware_groups WHERE group_id='.$groupId );

			$GLOBALS['db']->query( 'DELETE FROM security_group_incidents_organisation WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_incidents_buildings WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_incidents_rooms WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_incidents_departments WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_incidents_groups WHERE group_id='.$groupId );

			$GLOBALS['db']->query( 'DELETE FROM security_group_users_organisation WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_users_buildings WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_users_rooms WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_users_departments WHERE group_id='.$groupId );
			$GLOBALS['db']->query( 'DELETE FROM security_group_users_groups WHERE group_id='.$groupId );
			
			$script = 'alert(\'' . text('delete') .' ' . text('ok').'\');';

			break;
			
		default:
			$script = 'alert(\'uls_group_functions: ILLEGAL META ACTION(' . $_POST['ulsMetaAction'] . ') for group ( '.$groupId.' )!\');';
			break;
	} 

	echo "<script  type=\"text/javascript\">\n function returnData() { \n" . $script . "\n } \nonLoad = returnData(); \n</script>";
	
}
 

// This is used by the RPC code to fetch data and it is also used to return data into the database
if ( isset( $_GET['dataType'] ) && ( $_GET['dataType'] != '' ) && isset( $_GET['groupId'] ) && ( $_GET['groupId'] != '' ) && is_numeric( $_GET['groupId'] ) )
{
	if ( ! include_once( '../coreapm/coreapm.php' ) )
	{
		die( 'Cannot include CORE APM' );
	} 
	$GLOBALS['security']->secure( ADMIN );
	$GLOBALS['coreapm']->start();

	$commit = false;
	$list = '';

	$implied_array = array(); // Naar boven toe, als je rechten op een kamer hebt dan ook rechten op het gebouw
	$inherited_array = array(); // Naar onder toe, als je rechten hebt in een gebouw, dan ook in alle kamers
	$parent_array = array(); // Naar links toe, rechten geerft van de ouders
	$user_array = array(); // Persoonlijke rechten
	
	
	$data_type = $_GET['dataType'];
	$groupId = $_GET['groupId'];
	$i = 0;
	$script = 'var selRead = window.parent.document.getElementById( "' . $data_type . '_read[]" );' . "\n" . 
			  'var selWrite = window.parent.document.getElementById( "' . $data_type . '_write[]" );' . "\n" . 
			  'var selAdd = window.parent.document.getElementById( "' . $data_type . '_add[]" );' . "\n";
	
	if ( isset( $_POST['commit'] ) && ( $_POST['commit'] == 'true' ) )
		$commit = true;
		
	$boom = explode( '_', $data_type );
	$group_name = $boom[0];

	switch ( $group_name )
	{
		case 'incidents':
		case 'users':
		case 'hardware':

			$table_name = $boom[1];
			$table_name_simple = $table_name;
			if ( $table_name[ strlen( $table_name ) -1 ] == 's' )
			{
				$table_name_simple = substr( $table_name, 0, -1 );
			} 
			// If we are committing clear database
			if ( $commit )
			{
				$GLOBALS['db']->query( 'DELETE FROM security_group_' . $group_name . '_' . $table_name . ' WHERE group_id=' . $groupId );
				$db2 = new class_database;
				$script .= 'alert("' . text( 'security_updated' ) . '");' . "\n";
				
				// This is for IE6 which doesn't understand my frames
				$script .= "\nif( top.frames.length == 0 ) { window.close(); };\n";
			} 
			// Query for  all not defined
			$GLOBALS['db']->query( 'SELECT sc.read_ok AS read_ok,
										  sc.write_ok AS write_ok,
										  sc.add_ok AS add_ok
									 FROM security_group_' . $group_name . '_' . $table_name . ' AS sc 
									WHERE sc.group_id=' . $groupId . ' 
									  AND sc.' . $table_name_simple . '_id = 0' );
			$row = $GLOBALS['db']->fetch_array();
			$read = $write = $add = 'false';

			if ( $commit )
			{
				$db_read = $db_write = $db_add = database_boolean( false );
				$do_transaction = false;

				if ( isset( $_POST[ $data_type . '_read'] ) && in_array( $row['id'], $_POST[ $data_type . '_read'] ) )
				{
					$db_read = database_boolean( true );
					$read = 'true';
					$do_transaction = true;
				} 
				if ( isset( $_POST[ $data_type . '_write'] ) && in_array( $row['id'], $_POST[ $data_type . '_write'] ) )
				{
					$db_write = database_boolean( true );
					$write = 'true';
					$do_transaction = true;
				} 
				if ( isset( $_POST[ $data_type . '_add'] ) && in_array( $row['id'], $_POST[ $data_type . '_add'] ) )
				{
					$db_add = database_boolean( true );
					$add = 'true';
					$do_transaction = true;
				} 

				if ( $do_transaction )
				{
					if( $table_name_simple == 'group' ) $table_name_simple = 'uls_group';

					$db2->query( 'INSERT INTO security_group_' . $group_name . '_' . $table_name . '(group_id, ' . $table_name_simple . '_id, read_ok, write_ok, add_ok  ) VALUES(' . $groupId . ', \'\', ' . $db_read . ', ' . $db_write . ', ' . $db_add . ' );' );
				} 
			} 
			// No commit, just show the database values
			else
			{
				if ( $row != false )
				{
					if ( returned_database_boolean( $row['read_ok'] ) == true ) $read = 'true';
					if ( returned_database_boolean( $row['write_ok'] ) == true ) $write = 'true';
					if ( returned_database_boolean( $row['add_ok'] ) == true ) $add = 'true';
				} 
			} 

			$script .= "selRead.options[" . $i . "]=new Option( \" - " . text( 'all_not_defined' ) . " - \", \"\", false, " . $read . ");\n" . "selWrite.options[" . $i . "]=new Option( \" - " . text( 'all_not_defined' ) . " - \", \"\", false, " . $write . ");\n" . "selAdd.options[" . $i . "]=new Option( \" - " . text( 'all_not_defined' ) . " - \", \"\", false, " . $add . ");\n";
			$i++; 
			
			// Show implied and inherited items
			switch ( $table_name )
			{ 
				// See all inherited rights
				case 'organisation': 
				
					// Select all the organisations in which we have inherted access from higher order rights
					$GLOBALS['db']->query( 'SELECT distinct organisation_id AS id,
												   add_ok,
												   write_ok
										      FROM security_group_' . $group_name . '_organisation AS sc
										     WHERE group_id=' . $groupId . '
											   AND ( sc.add_ok = ' . database_boolean( true ) . ' OR sc.write_ok = ' . database_boolean( true ) . ' )' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						if( $row['write_ok'] == database_boolean(true) ) $parent_array[ $row['id'] ][0] = true;
						
						if( $row['add_ok'] == database_boolean(true) ) {
							$parent_array[ $row['id'] ][0] = true;
							$parent_array[ $row['id'] ][1] = true;
						}
					} 
					
					// Select all the buildings in which we have room access
					$GLOBALS['db']->query( 'SELECT distinct organisation_id AS id
										      FROM rooms,
											       buildings,
											       security_group_' . $group_name . '_rooms AS sc
										     WHERE group_id=' . $groupId . '
											   AND rooms.id = sc.room_id
											   AND buildings.id = rooms.buildings_id
											   AND ( read_ok='.database_boolean(true).' OR write_ok='.database_boolean(true).' OR add_ok='.database_boolean(true).' ) ' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $implied_array[ $row['id'] ] ) ) $implied_array[ $row['id'] ] = array( false, false, false );
						$implied_array[ $row['id'] ][0] = true;
					} 
					
					// Now select all buildings in which we have rights
					$GLOBALS['db']->query( 'SELECT distinct buildings.organisation_id AS id
										      FROM buildings,
											       security_group_' . $group_name . '_buildings AS sc
										     WHERE group_id=' . $groupId . '
											   AND buildings.id = sc.building_id
											   AND ( read_ok='.database_boolean(true).' OR write_ok='.database_boolean(true).' OR add_ok='.database_boolean(true).' ) ' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $implied_array[ $row['id'] ] ) ) $implied_array[ $row['id'] ] = array( false, false, false );
						$implied_array[ $row['id'] ][0] = true;
					} 
					
					// Now select all departments in which we have rights
					$GLOBALS['db']->query( 'SELECT distinct distinct departments.organisation_id AS id
										     FROM security_group_' . $group_name . '_departments AS sc,
											      departments
										    WHERE group_id=' . $groupId . '
											  AND departments.id = sc.department_id
											  AND ( read_ok='.database_boolean(true).' OR write_ok='.database_boolean(true).' OR add_ok='.database_boolean(true).' ) ' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $implied_array[ $row['id'] ] ) ) $implied_array[ $row['id'] ] = array( false, false, false );
						$implied_array[ $row['id'] ][0] = true;
					} 
					break;

				case 'buildings': 
					
					// Select all the buildings in which we have inherted access from higher order rights
					$GLOBALS['db']->query( 'SELECT distinct building_id AS id,
												   add_ok,
												   write_ok
										      FROM security_group_' . $group_name . '_buildings AS sc
										     WHERE group_id=' . $groupId . '
											   AND ( sc.add_ok = ' . database_boolean( true ) . ' OR sc.write_ok = ' . database_boolean( true ) . ' )' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						if( $row['write_ok'] == database_boolean(true) ) $parent_array[ $row['id'] ][0] = true;
						
						if( $row['add_ok'] == database_boolean(true) ) {
							$parent_array[ $row['id'] ][0] = true;
							$parent_array[ $row['id'] ][1] = true;
						}
					} 

					// Select all the buildings in which we have room access
					$GLOBALS['db']->query( 'SELECT distinct rooms.buildings_id AS id
										     FROM rooms,
											      security_group_' . $group_name . '_rooms AS sc
										    WHERE group_id=' . $groupId . '
											  AND rooms.id = sc.room_id
											   AND ( read_ok='.database_boolean(true).' OR write_ok='.database_boolean(true).' OR add_ok='.database_boolean(true).' ) ' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $implied_array[ $row['id'] ] ) ) $implied_array[ $row['id'] ] = array( false, false, false );
						$implied_array[ $row['id'] ][0] = true;
					} 
					
					// Select in which organtions we have access
					$GLOBALS['db']->query( 'SELECT buildings.id AS id,
												  sc.read_ok AS read_ok,
												  sc.write_ok AS write_ok,
												  sc.add_ok AS add_ok
										     FROM buildings,
											 	  security_group_' . $group_name . '_organisation AS sc
										    WHERE buildings.organisation_id = sc.organisation_id
											  AND sc.group_id =' . $groupId );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $inherited_array[ $row['id'] ] ) ) $inherited_array[ $row['id'] ] = array( false, false, false );
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						
						if( ( $inherited_array[ $row['id'] ][0] != true ) && ( $row['read_ok'] == database_boolean( true ) ) ) {
							$inherited_array[ $row['id'] ][0] = true;
						}
						if( ( $inherited_array[ $row['id'] ][1] != true ) && ( $row['write_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0] = $inherited_array[ $row['id'] ][1] = true;
						}
						if( ( $inherited_array[ $row['id'] ][2] != true ) && ( $row['add_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0]  = $parent_array[ $row['id'] ][1] = $inherited_array[ $row['id'] ][2] = true;
						}
					} 

					break;

				case 'rooms': 
					// Select all the rooms in which we have inherted access from higher order rights
					$GLOBALS['db']->query( 'SELECT distinct room_id AS id,
												   add_ok,
												   write_ok
										      FROM security_group_' . $group_name . '_rooms AS sc
										     WHERE group_id=' . $groupId . '
											   AND ( sc.add_ok = ' . database_boolean( true ) . ' OR sc.write_ok = ' . database_boolean( true ) . ' )' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						if( $row['write_ok'] == database_boolean(true) ) $parent_array[ $row['id'] ][0] = true;
						
						if( $row['add_ok'] == database_boolean(true) ) {
							$parent_array[ $row['id'] ][0] = true;
							$parent_array[ $row['id'] ][1] = true;
						}
					} 

					// Select from what buildings  we have inherited access
					$GLOBALS['db']->query( 'SELECT rooms.id AS id,
												  sc.read_ok AS read_ok,
												  sc.write_ok AS write_ok,
												  sc.add_ok AS add_ok
										     FROM rooms,
											 	  security_group_' . $group_name . '_buildings AS sc
										    WHERE rooms.buildings_id = sc.building_id
											  AND sc.group_id =' . $groupId );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $inherited_array[ $row['id'] ] ) ) $inherited_array[ $row['id'] ] = array( false, false, false );
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						
						if( ( $inherited_array[ $row['id'] ][0] != true ) && ( $row['read_ok'] == database_boolean( true ) ) ) {
							$inherited_array[ $row['id'] ][0] = true;
						}
						if( ( $inherited_array[ $row['id'] ][1] != true ) && ( $row['write_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0] = $inherited_array[ $row['id'] ][1] = true;
						}
						if( ( $inherited_array[ $row['id'] ][2] != true ) && ( $row['add_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0] = $parent_array[ $row['id'] ][1] = $inherited_array[ $row['id'] ][2] = true;
						}
					} 
					
					// Select in which organtions we have access
					$GLOBALS['db']->query( 'SELECT rooms.id AS id,
												  sc.read_ok AS read_ok,
												  sc.write_ok AS write_ok,
												  sc.add_ok AS add_ok
										     FROM rooms,
											      buildings,
											 	  security_group_' . $group_name . '_organisation AS sc
										    WHERE rooms.buildings_id = buildings.id
											  AND buildings.organisation_id = sc.organisation_id
											  AND sc.group_id =' . $groupId );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $inherited_array[ $row['id'] ] ) ) $inherited_array[ $row['id'] ] = array( false, false, false );
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						
						if( ( $inherited_array[ $row['id'] ][0] != true ) && ( $row['read_ok'] == database_boolean( true ) ) ) {
							$inherited_array[ $row['id'] ][0] = true;
						}
						if( ( $inherited_array[ $row['id'] ][1] != true ) && ( $row['write_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0] = $inherited_array[ $row['id'] ][1] = true;
						}
						if( ( $inherited_array[ $row['id'] ][2] != true ) && ( $row['add_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0] = $parent_array[ $row['id'] ][1] = $inherited_array[ $row['id'] ][2] = true;
						}
					} 

					break;

				case 'departments': 
					// Select all the departments in which we have inherted access from higher order rights
					$GLOBALS['db']->query( 'SELECT distinct department_id AS id,
												   add_ok,
												   write_ok
										      FROM security_group_' . $group_name . '_departments AS sc
										     WHERE group_id=' . $groupId . '
											   AND ( sc.add_ok = ' . database_boolean( true ) . ' OR sc.write_ok = ' . database_boolean( true ) . ' )' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						if( $row['write_ok'] == database_boolean(true) ) $parent_array[ $row['id'] ][0] = true;
						
						if( $row['add_ok'] == database_boolean(true) ) {
							$parent_array[ $row['id'] ][0] = true;
							$parent_array[ $row['id'] ][1] = true;
						}
					} 

					// Select from what departments we have inherited access
					$GLOBALS['db']->query( 'SELECT departments.id AS id,
												  sc.read_ok AS read_ok,
												  sc.write_ok AS write_ok,
												  sc.add_ok AS add_ok
										     FROM departments,
											 	  security_group_' . $group_name . '_organisation AS sc
										    WHERE departments.organisation_id = sc.organisation_id
											  AND sc.group_id =' . $groupId );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $inherited_array[ $row['id'] ] ) ) $inherited_array[ $row['id'] ] = array( false, false, false );
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						
						if( ( $inherited_array[ $row['id'] ][0] != true ) && ( $row['read_ok'] == database_boolean( true ) ) ) {
							$inherited_array[ $row['id'] ][0] = true;
						}
						if( ( $inherited_array[ $row['id'] ][1] != true ) && ( $row['write_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0] = $inherited_array[ $row['id'] ][1] = true;
						}
						if( ( $inherited_array[ $row['id'] ][2] != true ) && ( $row['add_ok'] == database_boolean( true ) ) ) { 
							$parent_array[ $row['id'] ][0] = $parent_array[ $row['id'] ][1] = $inherited_array[ $row['id'] ][2] = true;
						}
					} 
					break;

				case 'groups': 
				
					// Select all the groups in which we have inherted access from higher order rights
					$GLOBALS['db']->query( 'SELECT distinct uls_group_id AS id,
												   add_ok,
												   write_ok
										      FROM security_group_' . $group_name . '_groups AS sc
										     WHERE uls_group_id=' . $groupId . '
											   AND ( sc.add_ok = ' . database_boolean( true ) . ' OR sc.write_ok = ' . database_boolean( true ) . ' )' );
					while( ( $row = $GLOBALS['db']->fetch_array() ) )
					{
						if( ! isset( $parent_array[ $row['id'] ] ) ) $parent_array[ $row['id'] ] = array( false, false, false );
						if( $row['write_ok'] == database_boolean(true) ) $parent_array[ $row['id'] ][0] = true;
						
						if( $row['add_ok'] == database_boolean(true) ) {
							$parent_array[ $row['id'] ][0] = true;
							$parent_array[ $row['id'] ][1] = true;
						}
					} 

			} 
			
			// Query for normal data excluding the '' ( all not defined )
			$GLOBALS['db']->query( 'SELECT ' . $table_name . '.id AS id, 
										  ' . $table_name . '.name AS name,
										  sc.' . $table_name_simple . '_id AS sc_id,
										  sc.read_ok AS read_ok,
										  sc.write_ok AS write_ok,
										  sc.add_ok AS add_ok
									 FROM ' . $table_name . '
		   					    LEFT JOIN security_group_' . $group_name . '_' . $table_name . ' AS sc ON ( sc.group_id=' . $groupId . ' AND sc.' . $table_name_simple . '_id = ' . $table_name . '.id )
								 ORDER BY ' . $table_name . '.name' );
			while( ( $row = $GLOBALS['db']->fetch_array() ) )
			{
				$read = $write = $add = 'false'; 
				// if( $row['sc_id'] == '' ) continue;
				if ( $commit )
				{
					$db_read = $db_write = $db_add = database_boolean( false );
					$do_transaction = false;

					if ( isset( $_POST[ $data_type . '_read'] ) && in_array( $row['id'], $_POST[ $data_type . '_read'] ) )
					{
						$db_read = database_boolean( true );
						$read = 'true';
						$do_transaction = true;
					} 
					if ( isset( $_POST[ $data_type . '_write'] ) && in_array( $row['id'], $_POST[ $data_type . '_write'] ) )
					{
						$db_write = database_boolean( true );
						$write = 'true';
						$do_transaction = true;
					} 
					if ( isset( $_POST[ $data_type . '_add'] ) && in_array( $row['id'], $_POST[ $data_type . '_add'] ) )
					{
						$db_add = database_boolean( true );
						$add = 'true';
						$do_transaction = true;
					} 

					if ( $do_transaction )
					{
						// Exception
						if( $table_name_simple == 'group' ) $table_name_simple = 'uls_group';
						
						$db2->query( 'INSERT INTO security_group_' . $group_name . '_' . $table_name . '(group_id, ' . $table_name_simple . '_id, read_ok, write_ok, add_ok  ) VALUES(' . $groupId . ', ' . $row['id'] . ', ' . $db_read . ', ' . $db_write . ', ' . $db_add . ' );' );
					} 
				} 
				// No commit, just show the database values
				else
				{
					if ( returned_database_boolean( $row['read_ok'] ) == true ) $read = 'true';
					if ( returned_database_boolean( $row['write_ok'] ) == true ) $write = 'true';
					if ( returned_database_boolean( $row['add_ok'] ) == true ) $add = 'true';

					$script .= "selRead.options[" . $i . "]=new Option( \"" . addslashes($row['name']) . "\", \"" . $row['id'] . "\", false, " . $read . ");\n" . "selWrite.options[" . $i . "]=new Option( \"" . addslashes($row['name']) . "\", \"" . $row['id'] . "\", false, " . $write . ");\n" . "selAdd.options[" . $i . "]=new Option( \"" . addslashes($row['name']) . "\", \"" . $row['id'] . "\", false, " . $add . ");\n";
				} 

				$readClass = '';
				$writeClass = '';
				$addClass = ''; 
				// Show implied
				if ( isset( $implied_array[ $row['id'] ] ) )
				{
					$values = $implied_array[ $row['id'] ];
					if ( $values[0] ) $readClass = 'ULSImpliedRights';
					if ( $values[1] ) $writeClass = 'ULSImpliedRights';
					if ( $values[2] ) $addClass = 'ULSImpliedRights';
				} 

				if ( isset( $inherited_array[ $row['id'] ] ) )
				{
					$values = $inherited_array[ $row['id'] ];
					if ( $values[0] ) $readClass = 'ULSInheritedRights';
					if ( $values[1] ) $writeClass = 'ULSInheritedRights';
					if ( $values[2] ) $addClass = 'ULSInheritedRights';
				} 
				
				// First show rights from parents
				if( isset( $parent_array[ $row['id'] ] ) )
				{
					$values = $parent_array[ $row['id'] ];
					if ( $values[0] ) $readClass = 'ULSParentRights';
					if ( $values[1] ) $writeClass = 'ULSParentRights';
					if ( $values[2] ) $addClass = 'ULSParentRights';
				} 

				$script .= "selRead.options[" . $i . "].className='" . $readClass . "';\n";
				$script .= "selWrite.options[" . $i . "].className='" . $writeClass . "';\n";
				$script .= "selAdd.options[" . $i . "].className='" . $addClass . "';\n";

				$i++;
			} 

			break;
		default:
			$script = 'alert(\'uls_group_functions: ILLEGAL ACTION for switch(' . $table_name . ') from ( '.$data_type.' )!\');';
			break;
	} 

	echo "<script  type=\"text/javascript\">\n function returnData() { \n" . $script . "\n } \nonLoad = returnData(); \n</script>";

	$coreapm->finish();
	die;
} 

// Shows the read write add boxes
function __uls_show_group_rights( $name, $groupid = '' )
{
	$content = '<table width="100%" border="0" align="center"><tr>' . "\n";

	$content .= form_start( $name . '_rights', BASE_URL . 'module_helpcore_secure/uls_group_functions.php?groupId=' . $groupid . '&dataType=' . $name . '', '', '', $name ) . "\n";
	$content .= form_hiddenfield( 'commit', 'true' ) . "\n"; 
	// $content .= form_hiddenfield( 'groupId', $groupid );
	// $content .= form_hiddenfield( 'dataType', $name );
	// Read rights
	$content .= '<td align="center">' . "\n";
	$content .= text( 'read_access' ) . '<br />' . "\n";
	$content .= form_multiple_select( $name . '_read', $rows ) . "\n";
	$content .= '</td>' . "\n"; 
	// Write rights
	$content .= '<td align="center">' . "\n";
	$content .= text( 'write_access' ) . '<br />' . "\n";
	$content .= form_multiple_select( $name . '_write', $rows ) . "\n";
	$content .= '</td>' . "\n"; 
	// Add rights
	$content .= '<td align="center">' . "\n";
	$content .= text( 'add_access' ) . '<br />' . "\n";
	$content .= form_multiple_select( $name . '_add', $rows ) . "\n";
	$content .= '</td>';

	$content .= '</tr></table>' . "\n";
	$content .= form_submit_button( $name . '_submit', text( 'submit' ) ) . "\n";
	$content .= form_button( $name . '_show', 'Reload', 'onclick="callToNamedUrl( \'' . $name . '\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=' . $name . '&groupId=' . $groupid . '\');"' ) . "\n";

	$content .= '<table border="0" >' . "\n" . 
				'<tr><td class="ULSInheritedRightsBox" nowrap="nowrap">&nbsp;</td><td align="left">' . text( 'inherited_rights' ) . '</td></tr>' . "\n" . 
				'<tr><td class="ULSImpliedRightsBox" nowrap="nowrap">&nbsp;</td><td align="left">' . text( 'implied_rights' ) . '</td></tr>' . "\n" . 
				'<tr><td class="ULSParentRightsBox" nowrap="nowrap">&nbsp;</td><td align="left">' . text( 'parent_rights' ) . '</td></tr>' . "\n" . 
				'</table>' . "\n";

	$content .= form_finish() . "\n" . "\n";
	return $content;
} 

// Show an admin
function uls_show_group_manager( $groupid )
{ 
	// Build up the ULS columns
	$uls_area_tab = new class_tabsheets; 
	
	// incidents
	$uls_part_tab = new class_tabsheets;
	$uls_part_tab->addDataPanel( text( 'organisations' ), $GLOBALS['box']->data( text( 'incidents' ) . ' -&gt; ' . text( 'organisations' ), __uls_show_group_rights( 'incidents_organisation', $groupid ) ), false, 'callToNamedUrl( \'incidents_organisation\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=incidents_organisation&groupId=' . $groupid . '\');' );
	$uls_part_tab->addDataPanel( text( 'buildings' ), $GLOBALS['box']->data( text( 'incidents' ) . ' -&gt; ' . text( 'buildings' ), __uls_show_group_rights( 'incidents_buildings', $groupid ) ), false, 'callToNamedUrl( \'incidents_buildings\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=incidents_buildings&groupId=' . $groupid . '\')' );
	$uls_part_tab->addDataPanel( text( 'rooms' ), $GLOBALS['box']->data( text( 'incidents' ) . ' -&gt; ' . text( 'rooms' ), __uls_show_group_rights( 'incidents_rooms', $groupid ) ), false, 'callToNamedUrl( \'incidents_rooms\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=incidents_rooms&groupId=' . $groupid . '\');' );
	$uls_part_tab->addTabSpacer();
	$uls_part_tab->addDataPanel( text( 'departments' ), $GLOBALS['box']->data( text( 'incidents' ) . ' -&gt; ' . text( 'departments' ), __uls_show_group_rights( 'incidents_departments', $groupid ) ), false, 'callToNamedUrl( \'incidents_departments\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=incidents_departments&groupId=' . $groupid . '\');' );
	$uls_part_tab->addDataPanel( text( 'groups' ), $GLOBALS['box']->data( text( 'incidents' ) . ' -&gt; ' . text( 'groups' ), __uls_show_group_rights( 'incidents_groups', $groupid ) ), false, 'callToNamedUrl( \'incidents_groups\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=incidents_groups&groupId=' . $groupid . '\');' );
	$uls_area_tab->addDataPanel( text( 'incidents' ), $GLOBALS['box']->data( text( 'incidents' ), '' ) . $uls_part_tab->show(), false, 'document.getElementById("pn2_0_tab_clickable").onclick();' );
	unset( $uls_part_tab ); 
	
	// hardware
	$uls_part_tab = new class_tabsheets;
	$uls_part_tab->addDataPanel( text( 'organisations' ), $GLOBALS['box']->data( text( 'hardware' ) . ' -&gt; ' . text( 'organisations' ), __uls_show_group_rights( 'hardware_organisation', $groupid ) ), false, 'callToNamedUrl( \'hardware_organisation\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=hardware_organisation&groupId=' . $groupid . '\')' );
	$uls_part_tab->addDataPanel( text( 'buildings' ), $GLOBALS['box']->data( text( 'hardware' ) . ' -&gt; ' . text( 'buildings' ), __uls_show_group_rights( 'hardware_buildings', $groupid ) ), false, 'callToNamedUrl( \'hardware_buildings\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=hardware_buildings&groupId=' . $groupid . '\');' );
	$uls_part_tab->addDataPanel( text( 'rooms' ), $GLOBALS['box']->data( text( 'hardware' ) . ' -&gt; ' . text( 'rooms' ), __uls_show_group_rights( 'hardware_rooms', $groupid ) ), false, 'callToNamedUrl( \'hardware_rooms\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=hardware_rooms&groupId=' . $groupid . '\');' );
	$uls_part_tab->addTabSpacer();
	$uls_part_tab->addDataPanel( text( 'departments' ), $GLOBALS['box']->data( text( 'hardware' ) . ' -&gt; ' . text( 'departments' ), __uls_show_group_rights( 'hardware_departments', $groupid ) ), false, 'callToNamedUrl( \'hardware_departments\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=hardware_departments&groupId=' . $groupid . '\');' );
	$uls_part_tab->addDataPanel( text( 'groups' ), $GLOBALS['box']->data( text( 'hardware' ) . ' -&gt; ' . text( 'groups' ), __uls_show_group_rights( 'hardware_groups', $groupid ) ), false, 'callToNamedUrl( \'hardware_groups\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=hardware_groups&groupId=' . $groupid . '\');' );
	$uls_area_tab->addDataPanel( text( 'hardware' ), $GLOBALS['box']->data( text( 'hardware' ), '' ) . $uls_part_tab->show(), false, 'document.getElementById("pn3_0_tab_clickable").onclick();' );
	unset( $uls_part_tab ); 
	
	// users
	$uls_part_tab = new class_tabsheets;
	$uls_part_tab->addDataPanel( text( 'organisations' ), $GLOBALS['box']->data( text( 'users' ) . ' -&gt; ' . text( 'organisations' ), __uls_show_group_rights( 'users_organisation', $groupid ) ), false, 'callToNamedUrl( \'users_organisation\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=users_organisation&groupId=' . $groupid . '\')' );
	$uls_part_tab->addDataPanel( text( 'buildings' ), $GLOBALS['box']->data( text( 'users' ) . ' -&gt; ' . text( 'buildings' ), __uls_show_group_rights( 'users_buildings', $groupid ) ), false, 'callToNamedUrl( \'users_buildings\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=users_buildings&groupId=' . $groupid . '\');' );
	$uls_part_tab->addDataPanel( text( 'rooms' ), $GLOBALS['box']->data( text( 'users' ) . ' -&gt; ' . text( 'rooms' ), __uls_show_group_rights( 'users_rooms', $groupid ) ), false, 'callToNamedUrl( \'users_rooms\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=users_rooms&groupId=' . $groupid . '\');' );
	$uls_part_tab->addTabSpacer();
	$uls_part_tab->addDataPanel( text( 'departments' ), $GLOBALS['box']->data( text( 'users' ) . ' -&gt; ' . text( 'departments' ), __uls_show_group_rights( 'users_departments', $groupid ) ), false, 'callToNamedUrl( \'users_departments\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=users_departments&groupId=' . $groupid . '\');' );
	$uls_part_tab->addDataPanel( text( 'groups' ), $GLOBALS['box']->data( text( 'groups' ) . ' -&gt; ' . text( 'groups' ), __uls_show_group_rights( 'users_groups', $groupid ) ), false, 'callToNamedUrl( \'users_groups\', \'' . BASE_URL . 'module_helpcore_secure/uls_group_functions.php?dataType=users_groups&groupId=' . $groupid . '\');' );
	$uls_area_tab->addDataPanel( text( 'users' ), $GLOBALS['box']->data( text( 'users' ), '' ) . $uls_part_tab->show(), false, 'document.getElementById("pn4_0_tab_clickable").onclick();' );
	unset( $uls_part_tab ); 
	
	/*
	// Software
	$uls_area_tab->addDataPanel( text( 'software' ),
		$GLOBALS['box']->data( text( 'software' ),
			form_get_start( 'software_rights' ) .
			form_checkfield( 'software_read_rights' ) . text( 'read_access' ) . '<br /><br />' .
			form_checkfield( 'software_write_rights' ) . text( 'write_access' ) . '<br /><br />' .
			form_checkfield( 'software_add_rights' ) . text( 'add_access' ) . '<br /><br />' .
			form_submit_button( 'submitForm', text( 'submit' ) ) .
			form_finish() ) ); 
	*/
	$uls_area_tab->addDataPanel( text( 'meta_action' ),
		$GLOBALS['box']->data( text( 'meta_action' ),
			form_start( 'meta_action' ) .
			form_hiddenfield( 'ulsMetaAction', 'delete' ) .
			form_hiddenfield( 'groupId', $groupid ) .
			form_submit_button( 'submitForm', text( 'delete' ) ) .
			form_finish() ) ); 
	
	$GLOBALS['tabs']->addDataPanel( text( 'uls_groups' ), $GLOBALS['box']->data( text( 'uls_groups' ), '' ) .  $uls_area_tab->show(), false,
									'document.getElementById("pn1_0_tab_clickable").onclick(); document.getElementById("pn2_0_tab_clickable").onclick(); ' );
} 


?>
Return current item: HelpCORE