<?php
// ======================================================================== //
//                                                                          //
//   KooBI- Webportalsystem                                                 //
//   SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS                     //
//                                                                          //
//   ====================================================================   //
//                                                                          //   
//   dream4 | webservices - Am Michelsgrund 7 - 69469 Weinheim - Germany    //    
//   tel. +49(0) 6201 - 980442 / fax. +49(0) 6201 - 64809                   //
//                                                                          //
// ======================================================================== //
ob_start();
require_once("init.php");
if(!permission("sectionedit")){
	echo error($langadmin['noperms']);
	exit();
}

$tmpl = new Koobi("templates/".ADMINTHEME."/container/");
$tmpl->assign("theme", ADMINTHEME);
$tmpl->assign("langadmin", $langadmin);
$tmpl->assign("area", $area);
$tmpl->assign("kversion", KVERSION);
$tmpl->assign('pref', $pref);

if($_REQUEST['typ']=="in"){
	$inout = "in";
	$folder = "container";
	} else {
	$inout = "out"; 
	$folder = "page";
}
if(!isset($_REQUEST['action'])){ 
	
	// ===============================================
	// <<-- Speichern -->>
	// ===============================================
	if($_REQUEST['send']==1){
		if(!permission("sectionedit")) { echo error($langadmin['noperms']); exit();}
		
		$data = $_REQUEST['data'];
		$dsql = new dbc("SELECT id FROM ".PREFIX."_container where area='$_REQUEST[area]' order by name asc");
		while ( $row = $dsql->fetcharray()) { 
			$i = $row['id'];
			$dbs = new dbc("UPDATE ".PREFIX."_container SET typ='".$inout."', tpl='".trim($data[$i]["tpl"])."' WHERE id='".$data[$i]["sid"]."' AND area='$_REQUEST[area]'");
		}
	}
	
	// ===============================================
	// <<-- Vorschaulinks -->>
	// ===============================================
	$verzname = "../templates/$THEME/$folder/";
	$handle=opendir (''.$verzname.'');
	
	while (false !== ($file = readdir ($handle))) {
		$thecontainer = explode(".",$file);
		if($thecontainer[1]=="tpl"){ 
			$previewlink .='<a target="_blank" href="../index.php?p=misc&amp;do=containerpreview&amp;id='.$thecontainer[0].'&amp;typ='.$inout.'&amp;area='.$area.'">';
			$previewlink .= strtoupper($thecontainer[0]).'<br /></a>';
		}
	}
	closedir($handle); 
	
	// ==============================================
	// <<-- Seitenbereiche auslesen... -->>
	// ==============================================
	$sql = new dbc("SELECT * FROM ".PREFIX."_container WHERE typ='".$inout."' and area='$_REQUEST[area]' ORDER BY id ASC");
	$rowspan = $sql->numrows();
	
	$pagerubs = array();
	
	while ($row = $sql->fetchrow()){
		// =============================================
		// <<-- Dropdown erzeugen -->>
		// =============================================
		$verzname = "../templates/$THEME/$folder/";
		$handle=opendir (''.$verzname.'');
		$dropdown = "";
		while (false !== ($file = readdir ($handle))) {
			$thecontainer = explode(".",$file);
			if($thecontainer[1]=="tpl"){ 
				$dropdown .='<option value="'.$thecontainer[0].'"';
				if($row->tpl==$thecontainer[0]){
					$dropdown .= "selected";
				} 
				$dropdown .='>'.strtoupper($thecontainer[0]).'</option>';
				
			}
		}
		closedir($handle); 
		
		$row->lang = $langadmin['container_'.$row->id];
		$row->dropdown = $dropdown;
		array_push($pagerubs, $row);
	}
	
	
	// ===============================================
	// <<-- Zuweisen -->>
	// ===============================================
	$tmpl->assign("rowspan", $rowspan+1);
	$tmpl->assign("previewlink", $previewlink);
	$tmpl->assign("pagerubs", $pagerubs);
	$tmpl->display("container.tpl");	
}
?>