<?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://gekkoware.sourceforge.net
	*/

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

	define("IN-BLOCK", 1);

	require_once GEKKO_ROOT."modules/blocks/main.lib.php";

	$q = $db->query("
	SELECT
		Icon, Title, Content, Modules, Position, ScriptPath, ScriptVars, cssText,
		blockClass, auth_Access
	FROM ".db_table("block")."
	WHERE (Status = '1' AND (Modules LIKE '%$module%' OR Modules LIKE '%*%'))
	ORDER BY OrderID ASC
	", __FILE__, __LINE__, true);

	// setting blocks as null
	$bp = explode(",", Conf::getKey("blocks", "block_positions"));
	foreach ($bp as $p) {
		$L["M_BLOCK".$p] = "";
	}

	// filling blocks
	while ($row = $db->fetch_row($q)) {

		if (!blockCheckAuth($module, $row["Modules"], $row["auth_Access"])) continue;

		saneHTML($row, "Title,Content,ScriptVars,ScriptPath");

		// default block skeleton
		$row["blockSkeleton"] = "default.block";

		$row["Icon"] = mkIcon($row["Icon"], 16);
		$row["cssText"] = preg_replace("/\n|\t/", "", $row["cssText"]);

		if (blockscript_exists($row["ScriptPath"])) {
			$row["Content"] .= loadBlockScript($row);
		} elseif ($row["ScriptPath"]) {
			$row["Content"] .= "<b>Missing blockscript:</b> \"{$row["ScriptPath"]}\".";
		}

		$btpl = new ContentBlock("block", "blocks/".$row["blockSkeleton"]);

		$btpl->vren("BLOCK_TITLE", "TITLE");
		$btpl->vren("BLOCK_CONTENT", "CONTENT");
		$btpl->vren("BLOCK_ICON", "ICON");

		$btpl->set_arr($row);

		$L["M_BLOCK".$row["Position"]] .= user_env_vars($btpl->make());
	}
?>