<?php
ob_start();
require_once("init.php");
$area = ( (!isset($area)) || ($_REQUEST['area']=="") ) ? 1 : $_REQUEST['area'] ;

if(!permission('smileys')){
	echo error($langadmin['noperms']);
	exit();
}

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

$info = $langadmin['icon_path_info'];
$info = str_replace("__TEMPLATE__", "<b style=color:red>" . USERTHEME . "</b>",$info);

$tmpl->assign('info', $info);
switch($_REQUEST['action']){
	case "" :
	case "view" :
	
	$icons = array();
	$sql = new dbc("SELECT * FROM ".PREFIX."_posticons order by posi asc");
	while($row = $sql->fetchrow()){
		array_push($icons, $row);
	}
	
	$tmpl->assign('icons', $icons);
	$tmpl->display('show_posticons.tpl');
	break;
	
	case "save" :
	
	// aktiv ja nein
	if($_POST['active']>=1){
		foreach ($_POST['active'] as $id => $active) {
			if( $active != "")  {
				$result = new dbc("UPDATE ".PREFIX."_posticons set active='$active' WHERE id = '$id'");
			}
		}
	}
	
	// pfad
	if($_POST['path']>=1){
		foreach ($_POST['path'] as $id => $path) {
			if( $path != "")  {
				$result = new dbc("UPDATE ".PREFIX."_posticons  set path='$path' WHERE id = '$id'");
			}
		}
	}
	// loeschen
	if($_POST['del']>=1){
		foreach ($_POST['del'] as $id => $del) {
			if( $del != "")  {
				$result = new dbc("DELETE FROM  ".PREFIX."_posticons WHERE id = '$id'");
			}
		}
		alog("alog_delsmilies");
	}
	// position
	if($_POST['posi']>=1){
		foreach ($_POST['posi'] as $id => $posi) {
			if( $posi != "")  {
				$result = new dbc("UPDATE ".PREFIX."_posticons  set posi='$posi' WHERE id = '$id'");
			}
		}
	}
	
	header("Location:posticons.php?area=$_REQUEST[area]");
	break;
	
	
	// icon hinzufuegen
	case "new" :
	$smileys = array();
	for ($i = 0; $i < count($_POST['path']); $i++) {
		if( $_POST['path'][$i] != "" ) {
			$sql = new dbc("INSERT INTO ".PREFIX."_posticons (id,active,path) VALUES ('','1','".$_POST['path'][$i]."')");
		}
		
	}
	alog("del_topic_icon");
	header("Location:posticons.php?area=$_REQUEST[area]");
	break;
}

?>