<?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['smilie_path_info'];
$info = str_replace("__TEMPLATE__", "<b style=color:red>" . USERTHEME . "</b>",$info);

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

?>