<?php
/*********************************************
  CPG Dragonfly - DF_Arcade Admin
  ********************************************
  CPG Dragonfly is copyright © 2004 - 2005 by CPG Dev Team
  http://www.dragonflycms.com

  Dragonfly is released under the terms and conditions
  of the GNU GPL version 2 or any later version

  port of pnFlashGames - http://pnflashgames.com/
  Written by gerry@redgerry.com
  redgerry.com - Home of RG_Sports
  Revision Date: 16/10/2005 11:46
  Version Number 1.00

  UNDER NO CIRCUMSTANCES MAY THIS CODE BE USED FOR ANY COMMERCIAL
  PURPOSES UNDER THE GUISE OF V.I.P. OR ANY OTHER DESCRIPTION
********************************************************/
// Admin function List
// DF_Arcade - default
// DF_ArcadeCatMenu
// addCategory
// modifyCat
// upCat
// deleteCat
// deleteCatConf
// DF_ArcadeGameMenu
// addGame
// modifyGame
// upGame
// deleteGame
// deleteGameConf
// End Function list
// Header bits
if (!defined('ADMIN_PAGES')) { exit; }
if (!can_admin('DF_Arcade')) { die('Access Denied'); }
$module_name = "DF_Arcade";
$mode =  (isset($_POST['mode']) ? Fix_Quotes($_POST['mode']): (isset($_GET['mode']) ? Fix_Quotes($_GET['mode']) : ''));
require_once('language/'.$language.'/DF_Arcade.php');
require_once ( "header.php" );
GraphicAdmin('_AMENU8');
// End Header bits
function DF_Arcade(){
	OpenTable();
	echo "<div align=\"center\"><font class=\"title\">"._RGAACP."</font><br/><br/>"
	."<a href=\"".adminlink('&amp;mode=DF_ArcadeCatMenu')."\">"._RGAACOPT."</a>&nbsp;|&nbsp;"
	."<a href=\"".adminlink('&amp;mode=DF_ArcadeGameMenu')."\">"._RGAAGOPT."</a></div>";
	CloseTable();
}
function DF_ArcadeCatMenu(){
	global $prefix, $db, $module_name;
	DF_Arcade();
//	UploadMenu();
	OpenTable();
	echo "<div align=\"center\"><font class=\"title\">"._RGAAMDC."</font><br/><br/>";
	$result = $db->sql_query("SELECT COUNT(*) FROM ".$prefix."_rgarcade_cat");
	list($anycat) = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);
	if ($anycat > 0){
		echo "<form action=\"".adminlink('&amp;mode=DF_ArcadeCatMod')."\" method=\"post\" name=\"rgarcade\">"
		."<select name=\"cat_id\">"
		."<option value=\"\" SELECTED>"._RGAASELCAT."</option>/n";
		$result = $db->sql_query("SELECT cat_id, cname FROM ".$prefix."_rgarcade_cat ORDER BY cname ASC");
		while (list($cat_id, $cname) = $db->sql_fetchrow($result)) {
			echo "<option value=\"$cat_id\">$cname ($cat_id)</option>/n";
		}
		echo "</select>&nbsp;&nbsp;"
		."<input type=\"submit\" value=\""._RGACMOD."\">"
		."</form></center>";
	} else {
		echo "<font class=\"title\">"._RGAANOXCAT."</font>"
		."<br/><br/>";
	}
	CloseTable();
	OpenTable();
	echo "<div align=\"center\"><font class=\"title\">"._RGAAACAT."</font><br/><br/>"
	."<form action=\"".adminlink('&amp;mode=addCategory')."\" method=\"post\" name=\"rgarcade\">"
	."<table border=\"0\" width=\"100%\">"
	."<tr>"
	."<td><font class=\"content\">"._RGAACATNAME."</font></td>"
	."<td><input type=\"text\" name=\"add_catname\" size=\"30\" maxlength=\"25\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAACATDESC."</font></td>"
	."<td><input type=\"text\" name=\"add_catdesc\" size=\"50\" maxlength=\"255\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAACATPIC."</font></td><td>";
	$handle = opendir('images/DF_Arcade/cat');
	$clist = array();
	while ($file = readdir($handle)) {
		if (ereg("^([a-zA-Z0-9_\-]+)([.]{1})([a-zA-Z0-9_\-]{3})$",$file) && $file != 'template.psd') {
			$clist[] = $file;
		}
	}
	closedir($handle);
	sort($clist);
	echo "".select_option('cimage', $cimage, $clist)."</td></tr>"
	."<tr><td>&nbsp;</td>"
	."<td><font class=\"small\"><i>Location: images/DF_Arcade/cat</i></font></td></tr>"
	."<input type=\"hidden\" name=\"op\" value=\"addCategory\">"
       ."<tr><td colspan=\"2\" bgcolor=\"$bgcolor1\" height=\"25\" align=\"center\"><input type=\"submit\" value=\""._RGAAADDCAT."\"></td></tr></form>"
       ."</table>";
       CloseTable();
}
function addCategory(){
	global $prefix, $db;
	if (isset($_POST['add_catname'])) { $cname = Fix_Quotes($_POST['add_catname']); }
	if (isset($_POST['add_catdesc'])) { $cdescription = Fix_Quotes($_POST['add_catdesc']); }
	if (isset($_POST['cimage'])) { $cimage = Fix_Quotes($_POST['cimage']); }
	$result = $db->sql_query("INSERT INTO ".$prefix."_rgarcade_cat (cat_id, cname, cdescription, cimage, hits) VALUES (NULL,'$cname','$cdescription','$cimage','0')");
	url_redirect(adminlink('&amp;mode=DF_ArcadeCatMenu'));
}
function modifyCat(){
	global $prefix, $db, $bgcolor1;
	if (isset($_POST['cat_id'])) { $cat_id = intval($_POST['cat_id']); }
	DF_Arcade();
	$result = $db->sql_query("SELECT cname, cdescription, cimage FROM ".$prefix."_rgarcade_cat WHERE cat_id='$cat_id'");
	list($cname, $cdescription, $cimage) = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);
	$showpic = "<img src=\"images/DF_Arcade/cat/$cimage\" border=\"0\" alt=\"Current Category image for $cname\">";
	OpenTable();
	echo "<table border=\"1\" width=\"100%\">"
	."<tr bgcolor=\"$bgcolor1\"><td align=\"center\">$showpic</td>"
	."<td align=\"center\"><font class=\"title\">"._RGACMOD."</font></td></tr>"
	."<form action=\"".adminlink('&amp;mode=upCat')."\" method=\"post\" name=\"rgarcade\">"
	."<input type=\"hidden\" name=\"cat_id\" value=\"$cat_id\">"
	."<tr>"
	."<td><font class=\"content\">"._RGAACATNAME."</font></td>"
	."<td><input type=\"text\" name=\"add_catname\" value=\"$cname\" size=\"30\" maxlength=\"25\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAACATDESC."</font></td>"
	."<td><input type=\"text\" name=\"add_catdesc\" value=\"$cdescription\" size=\"50\" maxlength=\"255\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAACATPIC."</font></td><td>";
	$handle = opendir('images/DF_Arcade/cat');
	$clist = array();
	while ($file = readdir($handle)) {
		if (ereg("^([a-zA-Z0-9_\-]+)([.]{1})([a-zA-Z0-9_\-]{3})$",$file) && $file != 'template.psd') {
			$clist[] = $file;
		}
	}
	closedir($handle);
	sort($clist);
	echo "".select_option('cimage', $cimage, $clist)."</td></tr>"
       ."<tr bgcolor=\"$bgcolor1\">"
       ."<td height=\"25\" align=\"center\"><a href=\"".adminlink('DF_Arcade&amp;mode=deleteCat&amp;cat_id='.$cat_id.'')."\">"._RGACDEL."</a></td>"
       ."<td height=\"25\" align=\"center\"><input type=\"submit\" value=\""._RGACUPCAT."\"></td>"
       ."</tr></form></table>";
       CloseTable();
}
function upCat(){
	global $prefix, $db;
	if (isset($_POST['cat_id'])) { $cat_id = intval($_POST['cat_id']); }
	if (isset($_POST['add_catname'])) { $cname = Fix_Quotes($_POST['add_catname']); }
	if (isset($_POST['add_catdesc'])) { $cdescription = Fix_Quotes($_POST['add_catdesc']); }
	if (isset($_POST['cimage'])) { $cimage = Fix_Quotes($_POST['cimage']); }
	$result = $db->sql_query("UPDATE ".$prefix."_rgarcade_cat set cname='$cname', cdescription='$cdescription', cimage='$cimage' where cat_id='$cat_id'");
	url_redirect(adminlink('&amp;mode=DF_ArcadeCatMenu'));
}
function deleteCat(){
	global $prefix, $db, $bgcolor1;
	if (isset($_GET['cat_id'])) { $cat_id = intval($_GET['cat_id']); }
	DF_Arcade();
	$result = $db->sql_query("SELECT cname FROM ".$prefix."_rgarcade_cat WHERE cat_id='$cat_id'");
	list($cname) = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);
	$result = $db->sql_query("SELECT COUNT(*) FROM ".$prefix."_rgarcade_games WHERE gcid='$cat_id'");
	list($catgames) = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);
	OpenTable();
	echo "<div align=\"center\">"
	."<table width=\"80%\" border=\"1\" cellpadding=\"4\"><tr><td align=\"center\">"
	."<font class=\"title\">"._RGAACATNAME." - $cname</font><br/><br/>"
	."<font class=\"content\">"._RGAASDCAT."</font><br/>"
	."<font class=\"small\">(<b>$catgames</b> "._RGAAWGDEL.")</font><br/><br>"
	."<a href=\"".adminlink('DF_Arcade&amp;mode=DF_ArcadeCatMenu')."\">"._NO."</a>&nbsp;&nbsp;:"
	."&nbsp;&nbsp;<a href=\"".adminlink('DF_Arcade&amp;mode=deleteCatConf&amp;cat_id='.$cat_id.'')."\">"._YES."</a>"
	."</td></tr></table></div>";
	CloseTable();
}
function deleteCatConf(){
	global $prefix, $db, $bgcolor1;
	if (isset($_GET['cat_id'])) { $cat_id = intval($_GET['cat_id']); }
	$db->sql_query("DELETE FROM ".$prefix."_rgarcade_cat WHERE cat_id='$cat_id'");
	$result = $db->sql_query("SELECT game_id FROM ".$prefix."_rgarcade_games WHERE gcid='$cat_id'");
	while (list($game_id) = $db->sql_fetchrow($result)) {
		$db->sql_query("DELETE FROM ".$prefix."_rgarcade_hiscores WHERE game_id='$game_id'");
	}
	$db->sql_query("DELETE FROM ".$prefix."_rgarcade_games WHERE gcid='$cat_id'");
	url_redirect(adminlink('DF_Arcade&amp;mode=DF_ArcadeCatMenu'));
}
function DF_ArcadeGameMenu(){
	global $prefix, $db, $module_name, $bgcolor2;
	DF_Arcade();
//	UploadMenu();
	$gcolor = "#ffffff";
	OpenTable();
	echo "<div align=\"center\"><font class=\"title\">"._RGAAMDG."</font><br/><br/>";
	$result = $db->sql_query( 'SELECT game_id, gname, gimage, gfilename FROM ' . $prefix . '_rgarcade_games ORDER BY gname ASC' );
    	$games_list = array();
    	$gimage_list = array();
    	while( $row = $db->sql_fetchrow( $result ) ) {
    		$games_list[$row['gfilename']] = $row;
      		$gimage_list[$row['gimage']] = $row;
    	}
    	$db->sql_freeresult( $result );
    	if ( count( $games_list ) ) {
        	echo "<form action=\"".adminlink('&amp;mode=DF_ArcadeUpGame')."\" method=\"post\" name=\"rgarcade\">"
        	."<select name=\"game_id\">"
        	."<option value=\"\" SELECTED>"._RGAASELG."</option>/n";
        	foreach( $games_list as $game ) {
            		echo '<option value="' . $game['game_id'] . '">' . $game['gname'] . ' (' . $game['game_id'] . ")</option>\n";
        	}
        	echo "</select>&nbsp;&nbsp;"
        	."<input type=\"submit\" value=\""._RGAGMOD."\">"
        	."</form></center>";
    	} else {
    		echo "<font class=\"content\">"._RGAANGAV."</font>"
    		."<br/><br/>";
  	}
    	echo "</div>";
	CloseTable();
	OpenTable();
	echo "<div align=\"center\"><font class=\"title\">"._RGAAAG."</font><br/><br/>"
	."<form action=\"".adminlink('&amp;mode=addGame')."\" method=\"post\" name=\"rgarcade\">"
	."<table border=\"0\" width=\"100%\">"
	."<tr>"
	."<td><font class=\"content\">"._RGAAGN."</font></td>"
	."<td><input type=\"text\" name=\"gname\" size=\"30\" maxlength=\"35\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAAGC."</font></td>"
	."<td><select name=\"gcid\">"
	."<option value=\"\" SELECTED>"._RGAASCAT."</option>";;
	$result = $db->sql_query("SELECT cat_id, cname FROM ".$prefix."_rgarcade_cat ORDER BY cname ASC");
	while (list($cat_id, $cname) = $db->sql_fetchrow($result)) {
		echo "<option value=\"$cat_id\">$cname ($cat_id)</option>";
	}
	$db->sql_freeresult($result);
	echo "</select></td></tr><tr>"
	."<td><font class=\"content\">"._RGAAGTYPE."</font></td>"
	."<td><select name=\"gtype\">"
	."<option value=\"\" SELECTED>"._RGAASGT."</option>";
	$result = $db->sql_query("SELECT gtype_id, typename FROM ".$prefix."_rgarcade_gtype_cat ORDER BY gtype_id ASC");
	while (list($gtype_id, $typename) = $db->sql_fetchrow($result)) {
		echo "<option value=\"$gtype_id\">$typename ($gtype_id)</option>";
	}
	$db->sql_freeresult($result);
	echo "</select></td></tr><tr>"
    	."<td><font class=\"content\">"._RGAAAVSWF."</font></td><td>";
    	$handle = opendir('modules/'.$module_name.'/games');
	$flist = array();
	while ($file = readdir($handle)) {
		if ( eregi( "^([a-z0-9_\-]+)([.]{1})(swf)$", $file ) && !isset( $games_list[$file] ) ) {
			$flist[] = $file;
		}
	}
	closedir($handle);
	sort($flist);
	echo "".select_option('gfilename', $gfilename, $flist)."</td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><font class=\"small\"><i>"._RGAASWFLOC."</i></font></td>"
	."<td><font class=\"small\"><i>modules/$module_name/games/</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAAGIMG."</font></td><td>";
	$handle = opendir('modules/'.$module_name.'/screenshot');
	$tlist = array();
	while ($file = readdir($handle)) {
		if (ereg("^([a-zA-Z0-9_\-]+)([.]{1})([a-zA-Z0-9_\-]{3})$",$file) && $file != 'template.psd' && !isset( $gimage_list[$file] ) ) {
			$tlist[] = $file;
		}
	}
	closedir($handle);
	sort($tlist);
	echo "".select_option('gimage', $gimage, $tlist)."</td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><i>"._RGAAIMGFL."</i></td><td><i>modules/$module_name/screenshot/</i></td></tr>"
	."<tr><td valign=\"top\"><font class=\"content\">"._RGAAGD."</font></td>"
	."<td><textarea cols=50 rows=12 name=\"gdesc\"></textarea><br/><font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><font class=\"content\">"._RGAAAN."</font></td>"
	."<td><input type=\"text\" name=\"gauthorname\" size=\"30\" maxlength=\"55\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
    	."<td>&nbsp;</td><td><font class=\"small\"><i>"._RGAAAUK."</i></font></td>"
    	."</tr><tr>"
    	."<td><font class=\"content\">"._RGAAAH."</font></td>"
	."<td><input type=\"text\" name=\"gauthorurl\" size=\"30\" maxlength=\"255\"></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><font class=\"content\">"._RGAASWFW."</font></td>"
	."<td><input type=\"text\" name=\"gwidth\" size=\"3\" maxlength=\"3\">&nbsp;<font class=\"small\">"._RGAADU."</font></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><font class=\"small\"><i>Default Width</i></font></td>"
	."<td><font class=\"content\"><b>"._RGAASWFDW."</b></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAASWFH."</font></td>"
	."<td><input type=\"text\" name=\"gheight\" size=\"3\" maxlength=\"3\">&nbsp;<font class=\"small\">"._RGAADU."</font></td>"
	."</tr><tr>"
	."<td><font class=\"small\"><i>Default Height</i></font></td>"
	."<td><font class=\"content\"><b>"._RGAASWFDH."</b></font></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><font class=\"content\">"._RGAASWFBC."</font></td>"
	."<td><input type=\"text\" name=\"gcolor\" value=\"$gcolor\" size=\"7\" maxlength=\"7\"></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td align=\"center\" colspan=\"2\"><font class=\"small\"><i>"._RGAASWFBCD."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAALK."</font></td>"
	."<td><input type=\"text\" name=\"glicensekey\" size=\"55\"></td>"
	."</tr>"
    	."<tr><td align=\"center\" height=\"25\" colspan=\"2\"><input type=\"submit\" value=\""._RGAAAG."\"></td></tr>"
    	."</form></table>";
	CloseTable();
}
function addGame(){
	global $prefix, $db, $module_name;
	$gcid = (isset($_POST['gcid']) ? intval($_POST['gcid']) : '');
	$gtype = (isset($_POST['gtype']) ? intval($_POST['gtype']) : '');
	$gname = (isset($_POST['gname']) ? Fix_Quotes($_POST['gname']) : '');
	$gdescription = (isset($_POST['gdesc']) ? Fix_Quotes($_POST['gdesc']) : '');
	$gimage = (isset($_POST['gimage']) ? Fix_Quotes($_POST['gimage']) : '');
	$gfilename = (isset($_POST['gfilename']) ? Fix_Quotes($_POST['gfilename']) : '');
	$gauthorname = (isset($_POST['gauthorname']) ? Fix_Quotes($_POST['gauthorname']) : '');
	$gauthorurl = (isset($_POST['gauthorurl']) ? Fix_Quotes($_POST['gauthorurl']) : '');
	$gwidth = (isset($_POST['gwidth']) ? intval($_POST['gwidth']) : '');
	$gheight = (isset($_POST['gheight']) ? intval($_POST['gheight']) : '');
	$gcolor = (isset($_POST['gcolor']) ? Fix_Quotes($_POST['gcolor']) : '');
	$glicensekey = (isset($_POST['glicensekey']) ? Fix_Quotes($_POST['glicensekey']) : '');
// Error checking
	$errorstate = 0;
	$errormsg = NULL;
	if ($gcid == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM1;
	} elseif ($gtype == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM2;
	} elseif ($gname == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM3;
	} elseif ($gdescription == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM4;
	} elseif ($gfilename == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM5;
	}
	if ($gauthorname == ''){
		$gauthorname = _RGAUK;
	}
	if ($gauthorurl == ''){
		$gauthorurl = _RGAUV;
	}
	if ($gwidth == ''){
		$gwidth = 400;
	}
	if ($gheight == ''){
		$gheight = 510;
	}
	if ($gcolor == ''){
		$gcolor = "#ffffff";
	}
// End of error checking
	if ($errorstate == 1){
		DF_Arcade();
		OpenTable();
		echo "<div align=\"center\">"
		."<table width=\"80%\" border=\"1\" cellpadding=\"4\"><tr><td align=\"center\">"
		."<br/><font class=\"title\">"._RGAGEMPROB."</font><br/><br/>"
		."<font class=\"content\">$errormsg</font><br/><br/>"
		."<a href=\"".adminlink('&amp;mode=DF_ArcadeGameMenu')."\">"._RGAAGOPT."</a><br/><br/>";
		CloseTable();
	} else {
		$result = $db->sql_query("INSERT INTO ".$prefix."_rgarcade_games (game_id, gcid, gtype, gname, gdescription, gimage, gfilename, gauthorname, gauthorurl, gwidth, gheight, gcolor, hits, glicensekey, gratings, gscore) VALUES (NULL, '$gcid', '$gtype', '$gname', '$gdescription', '$gimage', '$gfilename', '$gauthorname', '$gauthorurl', '$gwidth', '$gheight', '$gcolor', '0', '$glicensekey', '0', '0')");
		url_redirect(adminlink('&amp;mode=DF_ArcadeGameMenu'));
	}
}
function modifyGame(){
	global $prefix, $db, $module_name, $bgcolor1, $bgcolor2;
	if (isset($_POST['game_id'])) { $game_id = intval($_POST['game_id']); }
	DF_Arcade();
	$result = $db->sql_query( 'SELECT game_id, gname, gimage, gfilename FROM ' . $prefix . '_rgarcade_games ORDER BY gname ASC' );
    	$games_list = array();
    	$gimage_list = array();
    	while( $row = $db->sql_fetchrow( $result ) ) {
    		$games_list[$row['gfilename']] = $row;
      		$gimage_list[$row['gimage']] = $row;
    	}
	$result = $db->sql_query("SELECT gcid, gtype, gname, gdescription, gimage, gfilename, gauthorname, gauthorurl, gwidth, gheight, gcolor, glicensekey FROM ".$prefix."_rgarcade_games WHERE game_id='$game_id'");
	list($gcid, $gtype, $gname, $gdescription, $gimage, $gfilename, $gauthorname, $gauthorurl, $gwidth, $gheight, $gcolor, $glicensekey) = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);
	$showpic = "<img src=\"modules/$module_name/screenshot/$gimage\" border=\"0\" alt=\"Current game image for $gname\" height=\"50\">";
	OpenTable();
	echo "<table border=\"1\" width=\"100%\"><tr>"
	."<td align=\"center\">$showpic</td>"
	."<td align=\"center\"><font class=\"title\">"._RGAGMOD."</font></td></tr>"
	."<form action=\"".adminlink('&amp;mode=upGame')."\" method=\"post\" name=\"rgarcade\">"
	."<input type=\"hidden\" name=\"game_id\" value=\"$game_id\">"
	."<tr>"
	."<td><font class=\"content\">"._RGAAGN."</font></td>"
	."<td><input type=\"text\" name=\"gname\" value=\"$gname\" size=\"30\" maxlength=\"35\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAAGC."</font></td>"
	."<td><select name=\"gcid\">"
	."<option value=\"\" SELECTED>"._RGAASELCAT."</option>";;
	$result = $db->sql_query("SELECT cat_id, cname FROM ".$prefix."_rgarcade_cat ORDER BY cname ASC");
	while (list($cat_id, $cname) = $db->sql_fetchrow($result)) {
			$sel = ($gcid == $cat_id) ? 'selected="selected" ' : '';
		echo "<option $sel value=\"$cat_id\">$cname ($cat_id)</option>";
	}
	$db->sql_freeresult($result);
	echo "</td></tr><tr>"
	."<td><font class=\"content\">"._RGAAGTYPE."</font></td>"
	."<td><select name=\"gtype\">"
	."<option value=\"\" SELECTED>"._RGAASGT."</option>";
	$result = $db->sql_query("SELECT gtype_id, typename FROM ".$prefix."_rgarcade_gtype_cat ORDER BY gtype_id ASC");
	while (list($gtype_id, $typename) = $db->sql_fetchrow($result)) {
			$sel = ($gtype == $gtype_id) ? 'selected="selected" ' : '';
		echo "<option $sel value=\"$gtype_id\">$typename ($gtype_id)</option>";
	}
	$db->sql_freeresult($result);
	echo "</td></tr><tr>"
    	."<td><font class=\"content\">"._RGAAAVSWF."</font></td><td>";
    	$handle = opendir('modules/'.$module_name.'/games');
	$flist = array();
	while ($file = readdir($handle)) {
		if ( eregi( "^([a-z0-9_\-]+)([.]{1})(swf)$", $file ) && !isset( $games_list[$file] ) ) {
			$flist[] = $file;
		}
	}
	closedir($handle);
	sort($flist);
	echo "".select_option('gfilename', $gfilename, $flist)."</td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><font class=\"small\"><i>"._RGAASWFLOC."</i></font></td>"
	."<td><font class=\"small\"><i>modules/$module_name/games/</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAAGIMG."</font></td><td>";
	$handle = opendir('modules/'.$module_name.'/screenshot');
	$tlist = array();
	while ($file = readdir($handle)) {
		if (ereg("^([a-zA-Z0-9_\-]+)([.]{1})([a-zA-Z0-9_\-]{3})$",$file) && $file != 'template.psd' && !isset( $gimage_list[$file] ) ) {
			$tlist[] = $file;
		}
	}
	closedir($handle);
	sort($tlist);
	echo "".select_option('gimage', $gimage, $tlist)."</td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td><i>"._RGAAIMGFL."</i></td><td><i>modules/$module_name/screenshot/</i></td></tr>"
	."<tr><td valign=\"top\"><font class=\"content\">"._RGAAGD."</font></td>"
	."<td><textarea cols=50 rows=12 name=\"gdescription\">$gdescription</textarea><br/><font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAAAN."</font></td>"
	."<td><input type=\"text\" name=\"gauthorname\" value=\"$gauthorname\" size=\"30\" maxlength=\"55\">&nbsp;<font class=\"small\"><i>"._REQUIRED."</i></font></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
    	."<td>&nbsp;</td><td><font class=\"small\"><i>"._RGAAAUK."</i></font></td>"
    	."</tr><tr>"
    	."<td><font class=\"content\">"._RGAAAH."</font></td>"
	."<td><input type=\"text\" name=\"gauthorurl\" value=\"$gauthorurl\" size=\"30\" maxlength=\"255\"></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAASWFW."</font></td>"
	."<td><input type=\"text\" name=\"gwidth\" value=\"$gwidth\" size=\"3\" maxlength=\"3\">&nbsp;<font class=\"small\">"._RGAADU."/font></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td align=\"center\" colspan=\"2\"><font class=\"content\">"._RGAASWFDW."</font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAASWFH."</font></td>"
	."<td><input type=\"text\" name=\"gheight\" value=\"$gheight\" size=\"3\" maxlength=\"3\">&nbsp;<font class=\"small\">"._RGAADU."</font></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td align=\"center\" colspan=\"2\"><font class=\"content\">"._RGAASWFDH."</font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAASWFBC."</font></td>"
	."<td><input type=\"text\" name=\"gcolor\" value=\"$gcolor\" size=\"7\" maxlength=\"7\"></td>"
	."</tr><tr bgcolor=\"$bgcolor2\">"
	."<td align=\"center\" colspan=\"2\"><font class=\"content\">"._RGAASWFBCD."</font></td>"
	."</tr><tr>"
	."<td><font class=\"content\">"._RGAALK."</font></td>"
	."<td><input type=\"text\" name=\"glicensekey\" value=\"$glicensekey\"size=\"55\"></td>"
	."</tr>"
       ."<tr bgcolor=\"$bgcolor1\">"
       ."<td height=\"25\" align=\"center\"><a href=\"".adminlink('DF_Arcade&amp;mode=deleteGame&amp;game_id='.$game_id.'')."\">"._RGAGDEL."</a></td>"
       ."<td height=\"25\" align=\"center\"><input type=\"submit\" value=\""._RGACUPGAME."\"></td>"
       ."</tr></form></table>";
       CloseTable();
}
function upGame(){
	global $prefix, $db;
	$gname = (isset($_POST['gname']) ? Fix_Quotes($_POST['gname']) : '');
	$game_id = (isset($_POST['game_id']) ? intval($_POST['game_id']) : '');
	$gcid = (isset($_POST['gcid']) ? intval($_POST['gcid']) : '');
	$gtype = (isset($_POST['gtype']) ? intval($_POST['gtype']) : '');
	$gdescription = (isset($_POST['gdescription']) ? Fix_Quotes($_POST['gdescription']) : '');
	$gimage = (isset($_POST['gimage']) ? Fix_Quotes($_POST['gimage']) : '');
	$gfilename = (isset($_POST['gfilename']) ? Fix_Quotes($_POST['gfilename']) : '');
	$gauthorname = (isset($_POST['gauthorname']) ? Fix_Quotes($_POST['gauthorname']) : '');
	$gauthorurl = (isset($_POST['gauthorurl']) ? Fix_Quotes($_POST['gauthorurl']) : '');
	$gwidth = (isset($_POST['gwidth']) ? intval($_POST['gwidth']) : '');
	$gheight = (isset($_POST['gheight']) ? intval($_POST['gheight']) : '');
	$gcolor = (isset($_POST['add_gcolor']) ? Fix_Quotes($_POST['add_gcolor']) : '');
	$glicensekey = (isset($_POST['glicensekey']) ? Fix_Quotes($_POST['glicensekey']) : '');
// Error checking
	$errorstate = 0;
	$errormsg = NULL;
	if ($game_id == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM0;
	} elseif ($gcid == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM1;
	} elseif ($gtype == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM2;
	} elseif ($gname == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM3;
	} elseif ($gdescription == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM4;
	} elseif ($gfilename == ''){
		$errorstate = 1;
		$errormsg = _RGAGEM5;
	}
	if ($gauthorname == ''){
		$gauthorname = _RGAUK;
	}
	if ($gauthorurl == ''){
		$gauthorurl = _RGAUV;
	}
	if ($gwidth == ''){
		$gwidth = 400;
	}
	if ($gheight == ''){
		$gheight = 510;
	}
	if ($gcolor == ''){
		$gcolor = "#ffffff";
	}
// End of error checking
	if ($errorstate == 1){
		DF_Arcade();
		OpenTable();
		echo "<div align=\"center\">"
		."<table width=\"80%\" border=\"1\" cellpadding=\"4\"><tr><td align=\"center\">"
		."<br/><font class=\"title\">"._RGAGEMPROB."</font><br/><br/>"
		."<font class=\"content\">$errormsg</font><br/><br/>"
		."<a href=\"".adminlink('&amp;mode=DF_ArcadeGameMenu')."\">"._RGAAGOPT."</a><br/><br/>";
		CloseTable();
	} else {
		$result = $db->sql_query("UPDATE ".$prefix."_rgarcade_games set gcid='$gcid', gtype='$gtype', gname='$gname', gdescription='$gdescription', gimage='$gimage', gfilename='$gfilename', gauthorname='$gauthorname', gauthorurl='$gauthorurl', gwidth='$gwidth', gheight='$gheight', gcolor='$gcolor', glicensekey='$glicensekey' where game_id='$game_id'");
		url_redirect(adminlink('&amp;mode=DF_ArcadeGameMenu'));
	}
}
function deleteGame(){
	global $prefix, $db;
	if (isset($_GET['game_id'])) { $game_id = intval($_GET['game_id']); }
	$result = $db->sql_query("SELECT gname FROM ".$prefix."_rgarcade_games WHERE game_id='$game_id'");
	list($gname) = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);
	OpenTable();
	echo "<table width=\"80%\" border=\"1\" cellpadding=\"4\"><tr><td align=\"center\">"
	."<font class=\"title\">$gname</font><br/><br>"
	."<font class=\"content\">"._RGAASDGAM."</font><br/><br>"
	."<a href=\"".adminlink('DF_Arcade&amp;mode=DF_ArcadeGameMenu')."\">"._NO."</a>&nbsp;&nbsp;:"
	."&nbsp;&nbsp;<a href=\"".adminlink('DF_Arcade&amp;mode=deleteGameConf&amp;game_id='.$game_id.'')."\">"._YES."</a>";
	CloseTable();
}
function deleteGameConf(){
	global $prefix, $db;
	if (isset($_GET['game_id'])) { $game_id = intval($_GET['game_id']); }
	$db->sql_query("DELETE FROM ".$prefix."_rgarcade_hiscores WHERE game_id='$game_id'");
	$db->sql_query("DELETE FROM ".$prefix."_rgarcade_games WHERE game_id='$game_id'");
	url_redirect(adminlink('DF_Arcade&amp;mode=DF_ArcadeGameMenu'));
}
switch ($mode) {
	default:
	DF_Arcade();
	break;

	case "DF_ArcadeCatMenu":
	DF_ArcadeCatMenu();
	break;

	case "DF_ArcadeCatMod":
	modifyCat();
	break;

	case "addCategory":
	addCategory();
	break;

	case "DF_ArcadeUpCat":
	modifyCat();
	break;

	case "upCat":
	upCat();
	break;

	case "deleteCat":
	deleteCat();
	break;

	case "deleteCatConf":
	deleteCatConf();
	break;

	case "DF_ArcadeGameMenu":
	DF_ArcadeGameMenu();
	break;

	case "addGame":
	addGame();
	break;

	case "DF_ArcadeUpGame":
	modifyGame();
	break;

	case "upGame":
	upGame();
	break;

	case "deleteGame":
	deleteGame();
	break;

	case "deleteGameConf":
	deleteGameConf();
	break;
}
