Location: PHPKode > projects > O - OpenSource GroupWare > osgw/osgw/classes/class.osgw.php
<?php
/**************************************************************************
   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.

   @Authors:	Ryan Thompson(hide@address.com)
***************************************************************************/
/*$Id: class.osgw.php,v 1.26 2004/05/29 01:14:34 rthomp Exp $*/
class osgw
{

	var $url;
	var $dir;
	var $uri = '/';
	var $current_service;
	var $current_location;
	var $version_check = FALSE;
	var $server_os;
	var $debug;
	var $ssl = FALSE;

	
	/*!
		@function update_service_version()
		@author Ryan Thompson
		@abstract Sets new version information in database for service
		@version 0.1
		@param $service_location - Location of service to update
		@return TRUE/FALSE
		@since 06-11-2003
	*/		
		
	function update_service_version($service_location)
	{
		GLOBAL $O, $db;
		
		include_once("{$O->dir}/$service_location/data.php");
		$sql = "UPDATE o_services SET version='{$service['version']}' WHERE code='{$service['code']}'";
		$db->query($sql);
		
		return TRUE;
	}
	/*!
		@function get_services()
		@author Ryan Thompson
		@abstract Retrieve an array of all services on system
		@version 0.1
		@return $services[] - array of installed services
		@since 06-11-2003
	*/	
	function get_services()
	{
		GLOBAL $db;
		$sql = "SELECT location FROM o_services";
		$db->query($sql);

		while($db->fetch_results())
		{
			$services[] = $db->record['location'];	
	
		}
		
		return $services;
	
	}
	
	/*!
		@function verify_version()
		@author Ryan Thompson
		@abstract Checks to see whether the system versions match between script and database.
		@version 0.1
		@return TRUE/FALSE
		@since 05-11-2003
	*/
	function verify_version()
	{
		GLOBAL $O, $db, $security, $lang;
		if($security->global_page())
		{
			return TRUE;
		}
		$sql = "SELECT value FROM o_info WHERE name='version'";
		$db->query($sql);
	
		$db->fetch_results($db->query_count);
	
		$db_version = $db->record['value'];
		
		if($db_version < VERSION)
		{
			
			$message = $lang->get_msg('script_newer','gl');
			$message = str_replace('%UPGRADE_LINK%', $O->create_link("/config/upgrade_config.php", $lang->get_msg('upgrade_now', 'gl')), $message);
			exit($message);
		} elseif ($db_version > VERSION)
		{
			exit('The version recorded in the database is newer the the current script. Script Halted');
		}
		
	}
	
	/*
	@Function: 	get_server_os()
 	@Date: 	29-March-2003
 	@Author: 	Ryan Thompson
 	@Description:	Return Server Operating System
 	@Variables:
 	@Deprecated
 	*/
	function get_server_os()
	{
		return PHP_OS;
	}
	
	/*
	@Function: 	get_php_version()
 	@Date: 	29-March-2003
 	@Author: 	Ryan Thompson
 	@Description:	Return version of PHP running on server
 	@Variables:
 	@Deprecated
 	*/
	function get_php_version()
	{
		return PHP_VERSION;
	}


/*
	@Function: 	redirect()
 	@Date: 	24-Mar-2003
 	@Author: 	Ryan Thompson
 	@Description:	Handles page redirection
 	@Variables:
*/

	function redirect($page)
	{
		GLOBAL $O;

		$url = $this->create_link($page);
		if($this->server_os == "WINNT")
		{
			//HTTP REFRESH

			echo "\n<HTML>\n<HEAD>\n";
			echo "\n<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL=$url\" />";
			echo "\n</HEAD><BODY>";
			echo "\n</BODY></HTML>";
			exit;
		} else {

			header("Location: $url");

			exit;
		}
	}

/*
	@Function: 	create_link()
 	@Date: 	24-Mar-2003
 	@Author: 	Ryan Thompson
 	@Description:	Handles all local links
 	@Variables:
*/

	function create_link($link, $title = '', $class = '', $attr = '')
	{
		GLOBAL $security;

		$protocol = $security->protocol();
		
		if(substr($link, 0, 10) == 'javascript')
		{
			
			return "<a href=\"$link\">$title</a>";
		}
		if('http://' != substr($link, 0, 7) && 'https://' != substr($link, 0, 8))
		{
			$url = $protocol . $this->url . $link;
		} else {
			$url = $link;	
		}

		if(strlen($title) == 0)
		{

			return $url;
		}

		$link = "<a href=\"$url\"";
		
		if(!empty($class))
		{
		 	$link .= " class=\"$class\"";
		}
		if(!empty($attr))
		{
			$link .= " ". $attr;	
		}

		$link .= ">$title</a>\n";

		return $link;


	}

/*
	@Function: 	create_image()
 	@Date: 	24-Mar-2003
 	@Author: 	Ryan Thompson
 	@Description:	Handles creation of local images
 	@Variables:
*/

	function create_image($src, $alt, $class = '', $align = '')
	{
		GLOBAL $O;
		//Source, class, title, alignemnt
		$image = $O->dir . $src;
		
		if($O->layout->image_ext == '.gif')
		{
			
			$ext = $O->layout->image_ext;
			$image = str_replace('.png', $ext, $image);
			if(is_file($image))
			{
				//
				$src = str_replace('.png', $ext, $src);
			}
		}
		$img_size = @getimagesize($image);

		$src = $this->create_link($src);
		$img = "\n<img src=\"$src\" title=\"$alt\" alt=\"$alt\" class=\"$class\" align=\"$align\" style=\"border:0px;height:{$img_size[1]}px;width:$img_size[0]}px\" />\n";
		return $img;
	}
	


	function change_str($string)
	{
		if(PHP_OS == "WINNT")
		{
			$new_string = str_replace("/", "\\", $string);
		} else {
			$new_string = $string;
		}

		return $new_string;

	}	

	
	function mailer($to, $subject, $message)
	{
		if(mail($to, $subject, $message))
		{
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	/*!
		@function delete_items()
		@author Ryan Thompson
		@abstract Delete Items from the database
		@version 0.1
		@params $service
		@params $service_table
		@params $primary_key
		@params $delete_values
		@params $user_id
		@params $user_field
		@return $items
		@since 10-12-2003
	*/	
	function delete_items($service, $service_table, $primary_key, $delete_values, $user_id = NULL, $user_field = 'user_id')
	{
		GLOBAL $db, $category, $share;
		$items = unserialize(stripslashes($delete_values));
		
		
		foreach($items AS $key => $value)
		{

			if($this->is_owner($service_table, $primary_key, $value, $user_id, $user_field))
			{
				$sql = "DELETE FROM $service_table WHERE $primary_key='$value'";
		
				$db->query($sql);
				$db->error;
				$category->delete($value, $service);
				$share->delete($value, $service);
				
			}

		}	
		return $items;
		
	}
	
	/*!
		@function is_owner()
		@author Ryan Thompson
		@abstract Verifies where user owns item
		@version 0.1
		@params $service_table
		@params $primary_key
		@params $value
		@params $user_id
		@return TRUE/FALSE
		@since 10-12-2003
	*/
	function is_owner($service_table, $primary_key, $value, $user_id, $user_field)
	{
		GLOBAL $db;
		$sql = "SELECT $primary_key FROM $service_table WHERE $primary_key='$value' AND $user_field='$user_id'";
		$db->query($sql);
		echo $db->error;
		if($db->num_rows == 1)
		{

			return TRUE;
		} else {
			return FALSE;
		}
		
	}

}

?>
Return current item: O - OpenSource GroupWare