<?php
///////////////////////////////////////////////////////////////////////////////////////
// PHPizabi 0.844b C1 [ALICIA]                               http://www.phpizabi.net //
///////////////////////////////////////////////////////////////////////////////////////
// Please read the license.txt file before using / modifying this software           //
// Original author:         Claude Desjardins, R - feedback@realitymedias.com        //
// Last modification date:  August 13th 2006                                         //
// Version:                 PHPizabi 0.844b C1                                       //
//                                                                                   //
// (C) 2005, 2006 Real!ty Medias / PHPizabi - All rights reserved                    //
///////////////////////////////////////////////////////////////////////////////////////
	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");
	/* Administrative restriction */
	(!me('is_administrator')&&!me('is_superadministrator')?throwerror("Access restricted"):NULL);

	$tpl = new template;

	$tpl -> Load("editarr");
	

	if (isset($_POST["Submit"]) && isset($_POST["id"]) && isset($_POST["topid"]) && isset($_POST["topkey1"])) {

$topid = $_POST["topid"];

$topkey1 = $_POST["topkey1"];

$topkey2 = $_POST["topkey2"];

$datfile = unserialize(@file_get_contents($_POST["id"]));

if(strlen($topkey2) > 1){

$datfile[$topid][$topkey1][$topkey2] = $_POST["arrval"];

} else $datfile[$topid][$topkey1] = $_POST["arrval"];


		if ($handle = fopen($_POST["id"], "w")) {

			fwrite($handle, serialize($datfile));

			fclose($handle);

			reload(0, "?L=admin.templates.datlist");
		}
	}

if(isset($_GET["id"]) && isset($_GET["topid"]) && isset($_GET["topkey1"])){

$topid = $_GET["topid"];

$topkey1 = $_GET["topkey1"];

$topkey2 = $_GET["topkey2"];

$datfile = unserialize(@file_get_contents($_GET["id"]));

if(count($datfile) > 0){

$tpl -> Zone('datelement','enabled');

if(strlen($topkey2) > 1){

$tpl->Assignarray(array("top.id" => $topid,"top.key1" => $topkey1,"top.key2" => $topkey2,"top.val" => $datfile[$topid][$topkey1][$topkey2]));

}

else $tpl->Assignarray(array("top.id" => $topid,"top.key1" => $topkey1,"top.key2" => $topkey2,"top.val" => $datfile[$topid][$topkey1]));

} else $tpl -> Zone('datelement','disabled');

} else echo "error";


	$tpl -> AssignArray(array("dat.name" =>(strpos($_GET["id"],'questionnaires') !== false ? base64_decode(substr(strrchr($_GET["id"],'/'),1,-3)) : substr(strrchr($_GET["id"],'/'),1,-3)),"dat.file" => $_GET["id"]));
	
	if (!is_writable($_GET["id"])) {
		$tpl -> Zone("error", "writeLock");
	}
	
	
	// 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();
	
?>