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

/*
 * HelpCORE source file 
 * ====================
 * 
 * CVS:
 * ----
 * $header$
 * 
 * Purpose:
 * --------
 * Mananages software images
 * 
 * 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( 'software_images_callbacks.php' ) ) {
	__FATAL__( __FILE__, __LINE__, __CLASS__, __FUNCTION__, 'Cannot load callbacks' );	
}

$GLOBALS['security']->secure();
$coreapm->start();

if( ( ! USE_SOFTWARE ) || ( O_MENU_ONLYADMINSSEESOFTWARE && ( ! $GLOBALS['security']->is_admin ) ) )
{
	$GLOBALS['box']->add( text( 'warning' ), text( 'administrator_disabled' ) );
	$coreapm->finish();
	die;
} 

$limits = null;
if( ! $GLOBALS['security']->is_admin )
{
	$limits = NO_ADD | NO_EDIT | NO_DELETE;
} 

/**
 * Adds or removes software from software images
 */
function software_images_selected_software( $action, $image_id, $editable = false )
{
	$content = '';

	// Manipulate database
	if ( isset( $_GET['imageaction'] ) &&
	 	 isset( $_GET['softwareid'] ) &&
		 is_numeric( $_GET['softwareid'] ) && $editable ) {
			
		switch ( $_GET['imageaction'] )
		{
			case 'allow':
				$GLOBALS['db']->query( 'DELETE FROM software_to_image WHERE software_id='.$_GET['softwareid'].' AND image_id='.$image_id );
				$GLOBALS['db']->query( 'INSERT INTO software_to_image( software_id, image_id ) values( ' . $_GET['softwareid'] . ', ' . $image_id . ' );' );
				break;

			case 'deny':
				$GLOBALS['db']->query( 'DELETE FROM software_to_image WHERE software_id='.$_GET['softwareid'].' AND image_id='.$image_id );
				break;

			default:
				echo 'software_images_selected_software(): "'.$_GET['imageaction'].'" is not a valid action';
				die;
				break;
		} 
	}
		
	// Show a list of software that we allow
	$table = new class_table;

	$GLOBALS['db']->query( 'SELECT software.id as id, 
								   software.name  as name,
								   software.version as version
                           	  FROM software,
							       software_to_image AS sti
					         WHERE sti.image_id='.$image_id.'
							  AND sti.software_id = software.id
						 ORDER BY software.name, software.version' );
	$amount = $GLOBALS['db']->num_rows();

	// Editable
	if( $editable ) {	
		$table->table_columns = 3;
		$table->add_header_row( array( text( 'name' ), text('version'), text('action') ) );
		while ( $row = $GLOBALS['db']->fetch_array() )
		{
			$table->add_row( array( '<a href="software.php?softwareaction=show&softwareshowid=' . $row['id'] . '">' . $row['name'] . '</a>', 
									$row['version'], 
									'<a href="'.$_SERVER['PHP_SELF'].'?software_imagesaction='.$action.
																     '&software_images'.$action.'id='.$image_id.
																	 '&selectedtab='. text('software') .
																	 '&imageaction=deny&softwareid='.$row['id'].'">'.
																	 '<img src="'.BASE_URL.'images/delete_small.gif" border="0" alt="'.text('delete').'" /></a>' ) );
		} 	
	}

	// Not editable
	else {

		$table->table_columns = 2;
		$table->add_header_row( array( text( 'name' ), text('version')) );
		while ( $row = $GLOBALS['db']->fetch_array() )
		{
			$table->add_row( array( '<a href="software.php?softwareaction=show&softwareshowid=' . $row['id'] . '">' . $row['name'] . '</a>', $row['version'] ) );
		} 	
	
	}
	
	if( $editable ) {
	
		$option_array=array();
		$GLOBALS['db']->query( 'SELECT id,
									   name,
									   version
								  FROM software 
							  ORDER BY name,version' );
		while ( $row = $GLOBALS['db']->fetch_array() )
		{
			array_push( $option_array, array( $row['id'], $row['name'].' ( '.$row['version'].' )') );
		}
	
		$content =  form_get_start( 'device_select' ). 
					form_select( 'softwareid', $option_array, find_value( 'softwareid' ) ).
					'<a href="software.php?softwareaction=add"><img src="'.BASE_URL.'images/add_small.gif" alt="'.text('add').'" border="0" /></a>'.
					form_hiddenfield( 'software_imagesaction', $action ).
					form_hiddenfield( 'software_images'.$action.'id', $image_id ).
					form_hiddenfield( 'imageaction', 'allow' ).
					form_hiddenfield( 'selectedtab', text('software') ).
					form_submit_button( 'submitForm', text('add')).
					form_finish();
	}
	

	return $GLOBALS['tabs']->addDataPanel( text( 'software' ).' ('.$amount.')', $GLOBALS['box']->data( text( 'software' ), $content.$table->finish() ) );
}




$GLOBALS['relational']->add_table_column( 'name', text( 'name' ), TYPE_STRING( 255 ) | REL_UNIQUE | REL_OBLIGATORY );
$GLOBALS['relational']->add_table_column( 'description', text( 'description' ), TYPE_TEXT() );
$GLOBALS['relational']->add_table_column( 'location', text( 'location' ), TYPE_TEXT() );
$GLOBALS['relational']->manage( 'software_images', text( 'software_images' ), $limits );

$coreapm->finish();

?>
Return current item: HelpCORE