<?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."/platforms/");
$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."_platform WHERE id = '$_REQUEST[id]'");
	header("location:platform.php?area=$_REQUEST[area]");
	break;
	
	
	case "new" :
	if($_REQUEST['newplatform'] != "") {
		$result = new dbc("INSERT INTO ".PREFIX."_platform (id,platform,area) VALUES ('','$_POST[newplatform]','$_REQUEST[area]')");
	}
	header("location:platform.php?area=$_REQUEST[area]");
	break;
	
	
	case "save" :
	if($_POST['platform']>=1){
		foreach ($_POST['platform'] as $id => $platform) {
			if( $platform != "")  {
				$result = new dbc("UPDATE ".PREFIX."_platform SET platform='$platform' WHERE id = '$id'");
			}
		}
	}
	header("location:platform.php?area=$_REQUEST[area]");
	break;
}

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