<?php

	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");
	/* Administrative restriction */
	(!me('is_administrator')&&!me('is_superadministrator')?die("Access restricted"):NULL);

	$tpl = new template;
	$tpl -> Load("index");

	if (isset($_POST["Submit"])) {
		_fnc("saveConfig", "VIDEO_HOST_MODE:LOCAL", $_POST["VIDEO_HOST_MODE"]);
		$CONF["VIDEO_HOST_MODE"] = $_POST["VIDEO_HOST_MODE"];
		_fnc("saveConfig", "VIDEO_CALLBACK_URL", $_POST["VIDEO_CALLBACK_URL"]);
		$CONF["VIDEO_RETURN_URL"] = $_POST["VIDEO_RETURN_URL"];
		_fnc("saveConfig", "VIDEO_RETURN_URL", $_POST["VIDEO_RETURN_URL"]);
		$CONF["VIDEO_SERVICE_USERNAME"] = $_POST["VIDEO_SERVICE_USERNAME"];
		_fnc("saveConfig", "VIDEO_SERVICE_USERNAME", $_POST["VIDEO_SERVICE_USERNAME"]);
	}
	
	if (isset($_POST["CategoriesSubmit"])) {
		_fnc("saveConfig", "VIDEO_CATEGORIES", str_replace("\r\n", "|", $_POST["VIDEO_CATEGORIES"]));
		$CONF["VIDEO_CATEGORIES"] = str_replace("\r\n", "|", $_POST["VIDEO_CATEGORIES"]);
	}



	$tpl -> AssignArray(array(
		"mode.remote" => (ckBool($CONF["VIDEO_HOST_MODE:LOCAL"]) ? NULL : "selected"),
		"mode.local" =>	(ckBool($CONF["VIDEO_HOST_MODE:LOCAL"]) ? "selected" : NULL),
		"callback" => $CONF["VIDEO_CALLBACK_URL"],
		"return" => $CONF["VIDEO_RETURN_URL"],
		"service" => $CONF["VIDEO_SERVICE_USERNAME"],
		"categories" => str_replace("|", "\r\n", $CONF["VIDEO_CATEGORIES"])
	));
	
	// TEMPLATE REPROCESS & FLUSH ////////////////////////////////////////////////////
	$tpl -> CleanZones();

	/* Get the frame templates, flush the TPL result into it */
	$frame = new template;
	$frame -> Load("!theme/{$GLOBALS["THEME"]}/templates/admin/frame.tpl");
	$frame -> AssignArray(array(
		"jump" => $tpl->Flush(1)
	));
	
	/* Assign Location Value */
	$locationArray = explode(".", $_GET["L"]);
	for ($i=0; $i<count($locationArray); $i++) {
		$locationAppendResult[] = $locationArray[$i];
		if ($i > 0) $location[] = "<a href=\"?L=".implode(".", $locationAppendResult)."\">{$locationArray[$i]}</a>";
	}
	$frame -> AssignArray(array("location" => implode(" &raquo; ", $location)));
	
	/* Set the forced chromeless mode, flush the template */
	$GLOBALS["CHROMELESS_MODE"] = 1;
	$frame -> Flush();
	
?>