<?php
ob_start();
require_once("init.php");
if(!permission("speedbar")){
	echo error($langadmin['noperms']);
	exit();
}
if((!isset($area)) || ($_REQUEST['area']=="")){
	$area = 1;
	}else{
	$area = $_REQUEST['area'];
}

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

if(!isset($_REQUEST['action'])){ 
	
	
	if($_REQUEST['do']=="delete"){
		$sql = new dbc("DELETE FROM ".PREFIX."_speedbar WHERE id='$_REQUEST[id]'");
		header("Location:speedbar.php?area=".$_REQUEST['area']."");
	}
	
	if($_REQUEST['do']=="new"){
		$sql = new dbc("INSERT INTO ".PREFIX."_speedbar (id,section,posi,slink,linkname,aktiv,target) VALUES ('','$_REQUEST[area]','$_REQUEST[posi]','$_REQUEST[slink]','$_REQUEST[linkname]','$_REQUEST[aktiv]','$_REQUEST[target]')");
		header("Location:speedbar.php?area=".$_REQUEST['area']."");
	}
	
	if($_REQUEST['send']==1){
		
		$data = $_REQUEST['data'];
		$dsql = new dbc("SELECT id FROM ".PREFIX."_speedbar WHERE section='$area' order by posi asc");
		while ( $row = $dsql->fetcharray()) { 
			$i = $row['id'];
			$dbs = new dbc("UPDATE ".PREFIX."_speedbar set posi='".$data[$i]["posi"]."',  slink='".$data[$i]["link"]."', linkname='".$data[$i]["title"]."', aktiv='".$data[$i]["aktiv"]."', target='".$data[$i]["target"]."' WHERE id='".$data[$i]["sid"]."' AND section='$_REQUEST[area]'");
		}
	}
	
	$dbs = new dbc("SELECT * FROM ".PREFIX."_speedbar WHERE section='$area' order by posi asc");
	$speedbar = array();
	while ( $row = $dbs->fetchrow()) { 
		array_push($speedbar,$row);
	}
	
	// ===============================================
	// <<-- Zuweisen -->>
	// ===============================================
	$tmpl->assign("speedbar", $speedbar);
	$tmpl->assign("pagerubs", $pagerubs);
	$tmpl->display("speedbar.tpl");	
}

?>