Flash::store('Admin Update Successfull', true); // redirect kills form resubmission } catch (MyException $e) { Flash::store('Admin Update FAILED !', true); // redirect kills form resubmission } } $meta['title'] = GAME_NAME . ' Administration'; $meta['head_data'] = ' <script type="text/javascript" src="scripts/admin.js"></script> '; $hints = array('Here you can administrate your ' . GAME_NAME . ' installation.', 'Click anywhere on a row to mark that row for action.'); $contents = ''; // grab the lists $player_list = GamePlayer::get_list(); $game_list = Game::get_list(); // go through the player list and remove the root admin and ourselves foreach ($player_list as $key => $player) { if ($GLOBALS['_ROOT_ADMIN'] == $player['username']) { unset($player_list[$key]); } if ($_SESSION['player_id'] == $player['player_id']) { unset($player_list[$key]); } } $table_meta = array('sortable' => true, 'no_data' => '<p>There are no players to show</p><!-- NO_PLAYERS -->', 'caption' => 'Players'); $table_format = array(array('ID', 'player_id'), array('Player', 'username'), array('First Name', 'first_name'), array('Last Name', 'last_name'), array('Email', 'email'), array('Admin', '###(([[[full_admin]]] | [[[half_admin]]]) ? \'<span class="notice">Yes</span>\' : \'No\')'), array('Approved', '###(([[[is_approved]]]) ? \'Yes\' : \'<span class="notice">No</span>\')'), array('Last Online', '###date(Settings::read(\'long_date\'), strtotime(\'[[[last_online]]]\'))', null, ' class="date"'), array('<input type="checkbox" id="player_all" />', '<input type="checkbox" name="ids[]" value="[[[player_id]]]" class="player_box" />', 'false', 'class="edit"')); $table = get_table($table_format, $player_list, $table_meta); if (false === strpos($table, 'NO_PLAYERS')) { $contents .= ' <form method="post" action="' . $_SERVER['REQUEST_URI'] . '"><div class="action">
$message_count = (int) Message::check_new($_SESSION['player_id']); $turn_count = (int) Game::check_turns($_SESSION['player_id']); $turn_msg_count = $message_count + $turn_count; $meta['title'] = 'Game List'; $meta['head_data'] = ' <script type="text/javascript" src="scripts/jquery.jplayer.min.js"></script> <script type="text/javascript" src="scripts/index.js"></script> <script type="text/javascript">//<![CDATA[ var turn_msg_count = ' . $turn_msg_count . '; //]]></script> '; $meta['foot_data'] = ' <div id="sounds"></div> '; // grab the list of games $list = Game::get_list($_SESSION['player_id']); $contents = ''; $table_meta = array('sortable' => true, 'no_data' => '<p>There are no games to show</p>', 'caption' => 'Current Games'); $table_format = array(array('SPECIAL_HTML', 'true', 'id="g[[[game_id]]]"'), array('SPECIAL_CLASS', '(1 == \'[[[highlight]]]\')', 'highlight'), array('ID', 'game_id'), array('Name', 'clean_name'), array('State', '###(([[[paused]]]) ? \'Paused\' : ((\'Waiting\' == \'[[[state]]]\') ? ((\'\' != \'[[[password]]]\') ? \'<span class="highlight password">[[[state]]]</span>\' : \'<span class="highlight">[[[state]]]</span>\') : \'[[[state]]]\'))'), array('Current Player', '###((\'\' == \'[[[username]]]\') ? \'[[[hostname]]]\' : \'[[[username]]]\')'), array('Extra Info', '<abbr title="Fortify: [[[get_fortify]]] | Kamikaze: [[[get_kamikaze]]] | Warmonger: [[[get_warmonger]]] | FoW Armies: [[[get_fog_of_war_armies]]] | FoW Colors: [[[get_fog_of_war_colors]]] | Conquer Limit: [[[get_conquer_limit]]] | Custom Rules: [[[clean_custom_rules]]]">Hover</abbr>'), array('Players', '[[[players]]] / [[[capacity]]]'), array('Last Move', '###ldate(Settings::read(\'long_date\'), strtotime(\'[[[last_move]]]\'))', null, ' class="date"')); $contents .= ' <div class="tableholder"> ' . get_table($table_format, $list, $table_meta) . ' </div>'; // create the lobby $Chat = new Chat($_SESSION['player_id'], 0); $chat_data = $Chat->get_box_list(); // temp storage for gravatar imgs $gravatars = array(); $lobby = ' <div id="lobby"> <div class="caption">Lobby</div>
/** function get_header * Generate the HTML header portion of the page * * @param array [optional] meta variables * @option string 'title' the page title * @option string 'head_data' any HTML to be inserted in the head tag * @option array 'menu_data' the data for the counts in the menu * @option array 'game_data' the game data for my game list under the menu * @option bool 'show_menu' show the menu * @option string 'file_name' becomes the body id with _page appended * @return string HTML header for page */ function get_header($meta = null) { if (!defined('GAME_NAME')) { define('GAME_NAME', 'Game'); } $title = !empty($meta['title']) ? GAME_NAME . ' :: ' . $meta['title'] : GAME_NAME; $show_menu = isset($meta['show_menu']) ? (bool) $meta['show_menu'] : true; $show_nav_links = isset($meta['show_nav_links']) ? (bool) $meta['show_nav_links'] : true; $menu_data = isset($meta['menu_data']) ? $meta['menu_data'] : false; $head_data = isset($meta['head_data']) ? $meta['head_data'] : ''; $file_name = isset($meta['file_name']) ? $meta['file_name'] : basename($_SERVER['SCRIPT_NAME']); $file_name = substr($file_name, 0, strrpos($file_name, '.')); // make sure we have these $GLOBALS['_&_DEBUG_QUERY'] = !empty($GLOBALS['_&_DEBUG_QUERY']) ? $GLOBALS['_&_DEBUG_QUERY'] : ''; $GLOBALS['_?_DEBUG_QUERY'] = !empty($GLOBALS['_?_DEBUG_QUERY']) ? $GLOBALS['_?_DEBUG_QUERY'] : (defined('DEBUG') && DEBUG ? '?' : ''); $flash = ''; if (class_exists('Flash')) { $flash = Flash::retrieve(); } if ($show_menu) { if (!$menu_data) { $menu_data = array('my_turn' => 0, 'my_games' => 0, 'games' => 0, 'in_vites' => 0, 'out_vites' => 0, 'open_vites' => 0, 'new_msgs' => 0, 'msgs' => 0); list($menu_data['games'], ) = Game::get_count(); list($menu_data['setups'], $menu_data['my_setups']) = Setup::get_count($_SESSION['player_id']); list($menu_data['my_games'], $menu_data['my_turn']) = Game::get_my_count($_SESSION['player_id']); list($menu_data['in_vites'], $menu_data['out_vites'], $menu_data['open_vites']) = Game::get_invite_count($_SESSION['player_id']); $messages = Message::get_count($_SESSION['player_id']); $menu_data['msgs'] = (int) @$messages[0]; $menu_data['new_msgs'] = (int) @$messages[1]; $allow_blink = 'index.php' == basename($_SERVER['PHP_SELF']); } // highlight the important menu values foreach ($menu_data as $key => $value) { switch ($key) { case 'my_turn': case 'new_msgs': case 'in_vites': if (0 < $value) { $menu_data[$key] = '<span class="notice">' . $value . '</span>'; } break; default: // do nothing break; } } $game_data = isset($meta['game_data']) ? $meta['game_data'] : Game::get_list($_SESSION['player_id'], false); } // if we are admin logged in as someone else, let us know $admin_css = $admin_div = ''; if (isset($_SESSION['admin_id']) && isset($_SESSION['player_id']) && $_SESSION['player_id'] != $_SESSION['admin_id']) { $admin_css = ' <style type="text/css"> html { border: 5px solid red; } #admin_username { background: red; color: black; position: fixed; top: 0; left: 50%; z-index: 99999; width: 200px; margin-left: -100px; text-align: center; font-weight: bold; font-size: larger; padding: 3px; } </style>'; $admin_div = '<div id="admin_username">' . $GLOBALS['Player']->username . ' [ ' . $GLOBALS['Player']->id . ' ]</div>'; } $query_strings = 'var debug_query_ = "' . $GLOBALS['_&_DEBUG_QUERY'] . '"; var debug_query = "' . $GLOBALS['_?_DEBUG_QUERY'] . '";'; $debug_string = defined('DEBUG') && DEBUG ? 'var debug = true;' : 'var debug = false;'; $nav_links = ''; if ($show_nav_links && class_exists('Settings') && Settings::test()) { $nav_links = Settings::read('nav_links'); } $GAME_NAME = GAME_NAME; $html = <<<EOF <!DOCTYPE html> <html lang="en-us"> <head> \t<title>{$title}</title> \t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> \t<script type="text/javascript"> \t\t{$debug_string} \t\t{$query_strings} \t</script> \t<script type="text/javascript" src="scripts/json.js"></script> \t<script type="text/javascript" src="scripts/jquery-1.8.0.min.js"></script> \t<script type="text/javascript" src="scripts/jquery.tablesorter.js"></script> \t<!-- fancybox --> \t<link rel="stylesheet" type="text/css" media="screen" href="scripts/jquery.fancybox/jquery.fancybox-1.3.4.css" /> \t<script type="text/javascript" src="scripts/jquery.fancybox/jquery.fancybox-1.3.4.pack.js"></script> \t<script type="text/javascript"> \t\t\$(document).ready( function( ) { \t\t\t// set fancybox defaults \t\t\t\$.fn.fancybox.defaults['overlayColor'] = '#000'; \t\t\t\$('a.help').fancybox({ \t\t\t\tautoDimensions : false, \t\t\t\twidth: 500, \t\t\t\tpadding : 10, \t\t\t\thideOnContentClick : false \t\t\t}); \t\t}); \t</script> \t<!-- hide the fancybox titles --> \t<style type="text/css"> \t\t#fancy_title { display: none !important; } \t</style> \t<link rel="stylesheet" type="text/css" media="screen" href="css/layout.css" /> \t{$head_data} \t{$flash} \t<link rel="stylesheet" type="text/css" media="screen" href="css/c_{$GLOBALS['_DEFAULT_COLOR']}.css" /> \t{$admin_css} </head> <body id="{$file_name}_page"> \t{$admin_div} \t<header> \t\t<h1><a href="index.php">{$GAME_NAME}</a></h1> \t\t<nav class="site">{$nav_links}</nav> \t</header> EOF; if ($show_menu) { $html .= ' <aside id="nav">'; if ($menu_data) { $html .= ' <nav id="menu" class="box"> <ul> <li' . get_active('index') . '><a href="index.php' . $GLOBALS['_?_DEBUG_QUERY'] . '" title="(Your Turn | Your Games | Total Games)"' . ($allow_blink && $menu_data['my_turn'] ? ' class="blink"' : '') . '>Games <span class="sep">(</span> ' . $menu_data['my_turn'] . ' <span class="sep">|</span> ' . $menu_data['my_games'] . ' <span class="sep">|</span> ' . $menu_data['games'] . ' <span class="sep">)</span></a></li> <li' . get_active('invite') . '><a href="invite.php' . $GLOBALS['_?_DEBUG_QUERY'] . '" title="(Received | Open | Sent)"' . ($allow_blink && $menu_data['in_vites'] ? ' class="blink"' : '') . '>Invitations <span class="sep">(</span> ' . $menu_data['in_vites'] . ' <span class="sep">|</span> ' . $menu_data['open_vites'] . ' <span class="sep">|</span> ' . $menu_data['out_vites'] . ' <span class="sep">)</span></a></li> <li' . get_active('messages', 'read', 'send') . '><a href="messages.php' . $GLOBALS['_?_DEBUG_QUERY'] . '" title="(New Messages | Total Messages)"' . ($allow_blink && $menu_data['new_msgs'] ? ' class="blink"' : '') . '>Messages <span class="sep">(</span> ' . $menu_data['new_msgs'] . ' <span class="sep">|</span> ' . $menu_data['msgs'] . ' <span class="sep">)</span></a></li> <li' . get_active('setups') . '><a href="setups.php' . $GLOBALS['_?_DEBUG_QUERY'] . '" title="(Yours | Total)">Setups <span class="sep">(</span> ' . $menu_data['my_setups'] . ' <span class="sep">|</span> ' . $menu_data['setups'] . ' <span class="sep">)</span></a></li> <li' . get_active('stats') . '><a href="stats.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Statistics</a></li> <li' . get_active('prefs') . '><a href="prefs.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Preferences</a></li> <li' . get_active('profile') . '><a href="profile.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Profile</a></li> '; if (true == $GLOBALS['Player']->is_admin) { $html .= '<li' . get_active('admin') . '><a href="admin.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Admin</a></li>'; } $html .= ' <li><a href="login.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Logout</a></li> </ul> </nav><!-- #menu -->'; } if ($game_data) { $html .= ' <div id="mygames_title">My Games</div> <nav id="mygames" class="box"> <ul>'; foreach ($game_data as $game) { $class = $game['my_turn'] ? 'playing' : (in_array($game['state'], array('Finished', 'Draw')) ? 'finished' : 'waiting'); $html .= ' <li class="' . $class . '"><a href="game.php?id=' . $game['game_id'] . $GLOBALS['_&_DEBUG_QUERY'] . '">' . htmlentities($game['opponent'], ENT_QUOTES, 'ISO-8859-1', false) . '</a></li>'; } $html .= ' </ul> </nav><!-- #mygames -->'; } $html .= ' </aside><!-- #nav -->'; } return $html; }
/** function get_header * Generate the HTML header portion of the page * * @param array [optional] meta variables * @option string 'title' the page title * @option string 'head_data' any HTML to be inserted in the head tag * @option array 'menu_data' the data for the counts in the menu * @option array 'game_data' the game data for my game list under the menu * @option bool 'show_menu' show the menu * @option string 'file_name' becomes the body id with _page appended * @return string HTML header for page */ function get_header($meta = null) { if (!defined('GAME_NAME')) { define('GAME_NAME', 'Game'); } $title = !empty($meta['title']) ? GAME_NAME . ' :: ' . $meta['title'] : GAME_NAME; $show_menu = isset($meta['show_menu']) ? (bool) $meta['show_menu'] : true; $show_nav_links = isset($meta['show_nav_links']) ? (bool) $meta['show_nav_links'] : true; $menu_data = isset($meta['menu_data']) ? $meta['menu_data'] : false; $head_data = isset($meta['head_data']) ? $meta['head_data'] : ''; $file_name = isset($meta['file_name']) ? $meta['file_name'] : basename($_SERVER['SCRIPT_NAME']); $file_name = substr($file_name, 0, strrpos($file_name, '.')); // make sure we have these $GLOBALS['_&_DEBUG_QUERY'] = isset($GLOBALS['_&_DEBUG_QUERY']) ? $GLOBALS['_&_DEBUG_QUERY'] : ''; $GLOBALS['_?_DEBUG_QUERY'] = isset($GLOBALS['_?_DEBUG_QUERY']) ? $GLOBALS['_?_DEBUG_QUERY'] : ''; $flash = ''; if (class_exists('Flash')) { $flash = Flash::retrieve(); } if ($show_menu) { if (!$menu_data) { $menu_data = array('my_turn' => 0, 'my_games' => 0, 'games' => 0, 'new_msgs' => 0, 'msgs' => 0, 'in_vites' => 0, 'out_vites' => 0); $list = Game::get_list($_SESSION['player_id']); $invites = Game::get_invites($_SESSION['player_id']); if (is_array($list)) { foreach ($list as $game) { ++$menu_data['games']; if ($game['in_game'] && !in_array($game['state'], array('Finished', 'Draw'))) { ++$menu_data['my_games']; } if ($game['my_turn'] && 'Placing' != $game['state']) { ++$menu_data['my_turn']; } } } if (is_array($invites)) { foreach ($invites as $game) { if ($game['invite']) { ++$menu_data['in_vites']; } else { ++$menu_data['out_vites']; } } } $messages = Message::get_count($_SESSION['player_id']); $menu_data['msgs'] = (int) @$messages[0]; $menu_data['new_msgs'] = (int) @$messages[1]; $allow_blink = 'index.php' == basename($_SERVER['PHP_SELF']); } // highlight the important menu values foreach ($menu_data as $key => $value) { switch ($key) { case 'my_turn': case 'new_msgs': case 'in_vites': if (0 < $value) { $menu_data[$key] = '<span class="notice">' . $value . '</span>'; } break; default: // do nothing break; } } $game_data = isset($meta['game_data']) ? $meta['game_data'] : Game::get_list($_SESSION['player_id'], false); } // if we are admin logged in as someone else, let us know $admin_css = $admin_div = ''; if (isset($_SESSION['admin_id']) && isset($_SESSION['player_id']) && $_SESSION['player_id'] != $_SESSION['admin_id']) { $admin_css = ' <style type="text/css"> html { border: 5px solid red; } #admin_username { background: red; color: black; position: fixed; top: 0; left: 50%; width: 200px; margin-left: -100px; text-align: center; font-weight: bold; font-size: larger; padding: 3px; } </style>'; $admin_div = '<div id="admin_username">' . $GLOBALS['Player']->username . ' [ ' . $GLOBALS['Player']->id . ' ]</div>'; } $query_strings = 'var debug_query_ = "' . $GLOBALS['_&_DEBUG_QUERY'] . '"; var debug_query = "' . $GLOBALS['_?_DEBUG_QUERY'] . '";'; $debug_string = defined('DEBUG') && DEBUG ? 'var debug = true;' : 'var debug = false;'; $nav_links = ''; if ($show_nav_links && class_exists('Settings') && Settings::test()) { $nav_links = Settings::read('nav_links'); } $GAME_NAME = GAME_NAME; $html = <<<EOF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" \t"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> \t<title>{$title}</title> \t<meta http-equiv="Content-Language" content="en-us" /> \t<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> \t<meta http-equiv="Content-Style-Type" content="text/css" /> \t<script type="text/javascript">//<![CDATA[ \t\t{$debug_string} \t\t{$query_strings} \t/*]]>*/</script> \t<link rel="stylesheet" type="text/css" media="screen" href="css/reset.css" /> \t<link rel="stylesheet" type="text/css" media="screen" href="css/layout.css" /> \t<link rel="stylesheet" type="text/css" media="screen" href="css/datatable.css" /> \t<link rel="stylesheet" type="text/css" media="screen" href="css/forms.css" /> \t<link rel="stylesheet" type="text/css" media="screen" href="css/c_{$GLOBALS['_DEFAULT_COLOR']}.css" /> \t<script type="text/javascript" src="scripts/json.js"></script> \t<script type="text/javascript" src="scripts/jquery-1.4.2.min.js"></script> \t<script type="text/javascript" src="scripts/jquery.tablesorter.js"></script> \t<!-- fancybox --> \t<link rel="stylesheet" type="text/css" media="screen" href="scripts/jquery.fancybox/jquery.fancybox-1.3.1.css" /> \t<script type="text/javascript" src="scripts/jquery.fancybox/jquery.fancybox-1.3.1.pack.js"></script> \t<script type="text/javascript">//<![CDATA[ \t\t\$(document).ready( function( ) { \t\t\t\$('a.help').fancybox({ \t\t\t\tautoDimensions : false, \t\t\t\twidth: 500, \t\t\t\theight: 400, \t\t\t\tpadding : 10, \t\t\t\toverlayOpacity : 0.7, \t\t\t\thideOnContentClick : false \t\t\t}); \t\t}); \t/*]]>*/</script> \t<!-- hide the fancybox titles --> \t<style type="text/css">/*<![CDATA[*/ \t\t#fancy_title { display: none !important; } \t/*]]>*/</style> \t{$head_data} \t{$flash} \t{$admin_css} </head> <body id="{$file_name}_page"> \t{$admin_div} \t<div id="links">{$nav_links}</div> \t<h1><a href="index.php">{$GAME_NAME}</a></h1> \t<div id="wrapper"> EOF; if ($show_menu) { $html .= ' <div id="menuholder">'; if ($menu_data) { $html .= ' <div id="menu"> <ul> <li' . get_active('index') . '><a href="index.php' . $GLOBALS['_?_DEBUG_QUERY'] . '" title="(Your Turn | Your Games | Total Games)"' . ($allow_blink && $menu_data['my_turn'] ? ' class="blink"' : '') . '>Games (' . $menu_data['my_turn'] . '|' . $menu_data['my_games'] . '|' . $menu_data['games'] . ')</a></li> <li' . get_active('invite') . '><a href="invite.php' . $GLOBALS['_?_DEBUG_QUERY'] . '" title="(Invites Recieved | Invites Sent)"' . ($allow_blink && $menu_data['in_vites'] ? ' class="blink"' : '') . '>Invitations (' . $menu_data['in_vites'] . '|' . $menu_data['out_vites'] . ')</a></li> <li' . get_active('messages') . '><a href="messages.php' . $GLOBALS['_?_DEBUG_QUERY'] . '" title="(New Messages | Total Messages)"' . ($allow_blink && $menu_data['new_msgs'] ? ' class="blink"' : '') . '>Messages (' . $menu_data['new_msgs'] . '|' . $menu_data['msgs'] . ')</a></li> <li' . get_active('stats') . '><a href="stats.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Statistics</a></li> <li' . get_active('prefs') . '><a href="prefs.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Preferences</a></li> <li' . get_active('profile') . '><a href="profile.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Profile</a></li> '; if (true == $GLOBALS['Player']->is_admin) { $html .= '<li' . get_active('admin') . '><a href="admin.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Admin</a></li>'; } $html .= ' <li><a href="login.php' . $GLOBALS['_?_DEBUG_QUERY'] . '">Logout</a></li> </ul> </div>'; } if ($game_data) { $html .= ' <div id="mygames_title"><strong>My Games</strong></div> <div id="mygames"> <ul>'; foreach ($game_data as $game) { $class = $game['my_turn'] ? 'playing' : 'waiting'; $html .= ' <li class="' . $class . '"><a href="game.php?id=' . $game['game_id'] . $GLOBALS['_&_DEBUG_QUERY'] . '">' . htmlentities($game['opponent'], ENT_QUOTES, 'ISO-8859-1', false) . '</a></li>'; } $html .= ' </ul> </div>'; } $html .= ' </div>'; } return $html; }