Location: PHPKode > projects > WB News > includes/admin-functions.php
<?php

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v1.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2005                          #||
||#     Created:  1st August 2005                        #||
||#     Filename: admin-functions.php                    #||
||#                                                      #||
||########################################################||
/*========================================================*/

/**
 *  @author $Author: pmcilwaine $
 *	@version $Id: admin-functions.php,v 1.2.2.4 2008/06/21 02:19:28 pmcilwaine Exp $
 */

/**
 *
 *	@param mixed $section
 *	@param boolean $accesskey
 *	@param array $attrs
 */
function buildmenu( $section=NULL, $accesskey=TRUE, $attrs=array(), $show_home=FALSE,$show_logout=FALSE )
{
	global $DB;

	if ( FALSE === $section )
	{
		return array();
	}
	
	$cond = array();
	
	switch ( $section )
	{
	case "section":
		$section = intval( GetSection() );
		$cond[] = "\"parent\"='$section'";
		break;
	case "children":
		$cond[] = "\"parent\" IS NOT NULL";
		break;
	default:
		$cond[] = "\"parent\" IS NULL";
		break;
	}
	
	if ( !$show_logout )
	{
		$cond[] = "lower(\"label\") NOT LIKE '%logout'";
	}
	if ( !$show_home )
	{
		$cond[] = "lower(\"label\") NOT LIKE '%home'";
	}
	$cond = join( " AND ", $cond );
	
	$DB2 = $DB;
	
	$fields = count($attrs) > 0 ? $attrs : array("*");
	$records = $DB2->ListBy( TBL_MENU, $cond, $fields, "\"id\"" );

	$ret = array();
	foreach ( $records as $record )
	{
		if ( count($attrs) > 0 )
		{
			foreach ( $attrs as $attr )
			{
				if ( "label" == $attr && !$accesskey )
				{
					$record[$attr] = str_replace( "&", "", $record[$attr] );
				}
				else if ( "attrs" == $attr && "" != $record[$attr] )
				{
					$record[$attr] = unserialize( $record[$attr] );
				}
				$array[$attr] = $record[$attr];
			}
			$ret[] = $array;
		}
		else
		{
			$ret[] = array(
				"url" => $record["url"],
				"label" => !$accesskey ? str_replace( "&", "", $record["label"] ) : $record["label"],
				"desc" => $record["desc"],
				"auth" => $record["auth"],
				"icon" => $record["icon"],
				"parent" => $record["parent"],
				"attrs" => unserialize($record["attrs"])
				);
		}
	}

	return $ret;
}

function toolbarmenu()
{
	return buildmenu( NULL, FALSE, array("url", "label", "attrs", "auth"), TRUE, TRUE );
}

function usergroups()
{
	global $DB;
	
	$DB2 = $DB;
	$DB2->query( "SELECT \"usergroupid\", \"title\" FROM " . TBL_UGROUPS . "" );
	
	$ret = array();
	while ( $DB2->next_record() )
	{
		$ret[ htmlspecialchars($DB2->field("usergroupid")) ] = htmlspecialchars( $DB2->field( "title" ) );
	}

	return merge_array( array(""=>"Choose.."), $ret );
}

function getThemes()
{
	global $DB;

	$DB2 = $DB;
	$DB2->query( "SELECT \"themeid\", \"title\" FROM " . TBL_THEMES . "" );
	
	$ret = array();
	while ( $DB2->next_record() )
	{
		$ret[ htmlspecialchars($DB2->field("themeid")) ] = htmlspecialchars( $DB2->field( "title" ) );
	}

	return merge_array( array(""=>"Choose.."), $ret );
}

/**
 *	Builds an array of Timezones
 *	
 *	@return array
 */
function timezone()
{
	$array["-12"] = "(GMT -12:00 hours) Eniwetok, Kwajalein";
	$array["-11"] = "(GMT -11:00 hours) Midway Island, Samoa";
	$array["-10"] = "(GMT -10:00 hours) Hawaii";
	$array["-9"] = "(GMT -9:00 hours) Alaska";
	$array["-8"] = "(GMT -8:00 hours) Pacific Time (US & Canada)";
	$array["-7"] = "(GMT -7:00 hours) Mountain Time (US & Canada)";
	$array["-6"] = "(GMT -6:00 hours) Central Time (US & Canada)";
	$array["-5"] = "(GMT -5:00 hours) Eastern Time (US & Canada)";
	$array["-4"] = "(GMT -4:00 hours) Atlantic Time (Canada), Caracas";
	$array["-3.5"] = "(GMT -3:30 hours) Newfoundland";
	$array["-3"] = "(GMT -3:00 hours) Brazil, Buenos Aires, Georgetown";
	$array["-2"] = "(GMT -2:00 hours) Mid-Atlantic";
	$array["-1"] = "(GMT -1:00 hours) Azores, Cape Verde Islands";
	$array["+0"] = "(GMT) Western Europe Time, London, Lisbon";
	$array["+1"] = "(GMT +1:00 hours) CET(Central Europe Time)";
	$array["+2"] = "(GMT +2:00 hours) EET(Eastern Europe Time)";
	$array["+3"] = "(GMT +3:00 hours) Baghdad, Riyadh, Moscow";
	$array["+3.5"] = "(GMT +3:30 hours) Tehran";
	$array["+4"] = "(GMT +4:00 hours) Abu Dhabi, Muscat, Baku, Tbilisi";
	$array["+4.5"] = "(GMT +4:30 hours) Kabul";
	$array["+5"] = "(GMT +5:00 hours) Ekaterinburg, Islamabad, Karachi";
	$array["+5.5"] = "(GMT +5:30 hours) Bombay, Calcutta, Madras";
	$array["+6"] = "(GMT +6:00 hours) Almaty, Dhaka, Colombo";
	$array["+7"] = "(GMT +7:00 hours) Bangkok, Hanoi, Jakarta";
	$array["+8"] = "(GMT +8:00 hours) Beijing, Perth, Singapore";
	$array["+9"] = "(GMT +9:00 hours) Tokyo, Seoul, Osaka, Sapporo";
	$array["+9.5"] = "(GMT +9:30 hours) Adelaide, Darwin";
	$array["+10"] = "(GMT +10:00 hours) AEST(Australian East Standard)";
	$array["+11"] = "(GMT +11:00 hours) Magadan, Solomon Islands";
	$array["+12"] = "(GMT +12:00 hours) Auckland, Wellington, Fiji";

	$t_array = array();
	foreach ( $array as $k => $v )
	{
		$t_array[ htmlspecialchars($k) ] = htmlspecialchars( $v );
	}
	
	return $t_array;
}

function log_activity( $userinfo )
{
	global $DB;

	$string = NULL;
	switch ( basename($_SERVER["PHP_SELF"]) )
	{
	case "index.php":
		break;
	default:
		$string = "Unknown";
		break;
	}

	$sql = array();
	$sql[] = "INSERT INTO " . TBL_ADMIN_LOG;
	$sql[] = "(\"id\",\"modified\",\"owner\",\"created_ts\",\"user\",\"urlstring\",\"action\")";

	$DB2 = $DB;
	$DB2->query( join( " ", $sql ) );
	
}

function GetSection()
{
	global $DB;
	$url = addslashes( basename( $_SERVER["PHP_SELF"] ) );

	$cond = array();
	$cond[] = "\"url\"='$url'";
	$cond = join( " AND ", $cond );

	$sql = "SELECT \"id\" FROM " . TBL_MENU . " WHERE $cond";
	$DB->query( $sql );

	if ( $DB->next_record() )
	{
		return $DB->field( "id" );
	}

	return FALSE;
}

function Message( $msg, $unique = FALSE )
{
	if ( NULL == $msg )
	{
		return FALSE;
	}

	if ( !isset($_SESSION["msg"]) )
	{
		$_SESSION["msg"] = array();
	}

	if ( $unique && in_array( $msg, $_SESSION["msg"] ) )
	{
		return TRUE;
	}

	$_SESSION["msg"][] = htmlspecialchars( $msg );
	return TRUE;
}

return;

?>
Return current item: WB News