<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://www.gekkoware.org
	*/

	/*
		Those are core functions supposed for being used in every
		script.
	*/

	if (!defined("IN-GEKKO")) die("Get a life!");

	/*
		WARNING: This is a RELATIVE is_admin() function, will return true
		when user owns administrator privileges for the main requested module.
		Use with care.
	*/
	function is_admin($absolute = false) {
		return gauth((defined("ACTION_MODULE") && !$absolute) ? ACTION_MODULE : "admin");
	}

	function table_simpleSwitchOrder($table, $id, $orderid) {
		$q = $GLOBALS["db"]->query ("SELECT OrderID FROM ".db_table($table)."
		WHERE ID = '{$id}'",
		__FILE__, __LINE__, true);

		if ($GLOBALS["db"]->num_rows($q)) {
			$row = $GLOBALS["db"]->fetch_row($q);
			if ($orderid != $row["OrderID"]) {
				$GLOBALS["db"]->query ("UPDATE ".db_table($table)."
				SET OrderID = '{$row["OrderID"]}'
				WHERE OrderID = '{$orderid}'", __FILE__, __LINE__, true);
			}
		}
	}

	function gpGet($index, $globalize = false) {
		$val = null;
		if (isset($_GET[$index])) $val = $_GET[$index];
		if (isset($_POST[$index])) $val = $_POST[$index];
		if ($globalize) {
			$GLOBALS[$index] = $val;
		} else {
			return $val;
		}
	}
	function gpGlobalize($index) {
		$index = explode(",", $index);
		foreach ($index as $varname) {
			$varname = trim($varname);
			gpGet($varname, 1);
		}
	}
	function requireVars() {
		$argv = func_get_args();
		foreach ($argv as $check) {
			if (!$check) {
				abort(_l("L_INSUFFICIENT_DATA"));
			}
		}
	}
	function getDateField ($date) {
		return mktime(0, 0, 0, $date["d"], $date["m"], $date["y"]);
	}
?>