<?php
require_once("init.php");
$incdir = dirname(__FILE__);
define("INC", $incdir);

$area = ((!isset($area)) || ($_REQUEST['area']=="")) ? 1 : $_REQUEST['area'];
if( !permission('perm_genre')) { echo error($langadmin['noperms']); exit(); }


$tmpl = new Koobi("templates/".ADMINTHEME."/genres/");
$tmpl->assign("theme", ADMINTHEME);
$tmpl->assign("langadmin", $langadmin);
$tmpl->assign("area", $area);
$tmpl->assign("kversion", KVERSION);
$tmpl->assign("rmode", $_REQUEST['mode']);
$tmpl->assign('uid', UID);
$tmpl->assign('pref', $pref);


switch($_REQUEST['action']){
	case "del" :
	$result = new dbc("DELETE FROM ".PREFIX."_genres WHERE id = '$_REQUEST[id]'");
	header("location:genre.php?area=$_REQUEST[area]");
	break;
	
	
	case "new" :
	if($_REQUEST['newgenre'] != "") {
		$result = new dbc("INSERT INTO ".PREFIX."_genres (id,genre,area) VALUES ('','$_POST[newgenre]','$_REQUEST[area]')");
	}
	header("location:genre.php?area=$_REQUEST[area]");
	break;
	
	
	case "save" :
	if($_POST['genre']>=1){
		foreach ($_POST['genre'] as $id => $genre) {
			if( $genre != "")  {
				$result = new dbc("UPDATE ".PREFIX."_genres SET genre='$genre' WHERE id = '$id'");
			}
		}
	}
	header("location:genre.php?area=$_REQUEST[area]");
	break;
}

$items = array();
$sql = new dbc("SELECT * FROM ".PREFIX."_genres  WHERE  area='$area' ORDER by genre ASC");
while($row = $sql->fetchrow()){
	array_push($items,$row);
}
$tmpl->assign('items',$items);
$tmpl->display('genre_show.tpl');
?>