<?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
	*/

	/*
		runscript.php
		This script will load and display some small script.
		Very useful when programming an AJAX application
	*/

	define("IN-GEKKO", true);

	require_once "conf.php";
	require_once "lib/gzenc.lib.php";

	gzinit();

	header("Content-type: text/html; encoding=UTF-8");

	require_once "lib/template.lib.php";
	require_once "lib/actions.lib.php";

	db_init();

	// this script needs a partial url as parameter
	if (!isset($_SERVER["PATH_INFO"])) die();

	$_SERVER["PATH_INFO"] = trim($_SERVER["PATH_INFO"], "/");

	$path = explode("/", $_SERVER["PATH_INFO"]);

	unset($file);

	switch (count($path)) {
		case "2":
			// runscript.php/module/script
			$file = GEKKO_ROOT."modules/{$path[0]}/run/{$path[1]}.php";
		break;
		case "1":
			// runscript.php/library
			$file = GEKKO_ROOT."lib/php/{$path[0]}.php";
		break;
		default:
			abort();
		break;
	}

	if ((ereg("\.\.", $file) === false) && file_exists($file)) {
		include $file;
	} else {
		abort(accessDenied(true, __FILE__, __LINE__));
	}

	db_exit();

	gzoutput();
?>
