function exec_ogp_module()
{
    global $db;
    echo "<h2>" . get_lang('game_monitor') . "</h2>";
    $refresh = new refreshed(100000);
    set_time_limit(0);
    $stats_servers_online = 0;
    $stats_servers = 0;
    $stats_players = 0;
    $stats_maxplayers = 0;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if ($isAdmin) {
        $server_homes = $db->getIpPorts();
    } else {
        $server_homes = $db->getIpPortsForUser($_SESSION['user_id']);
    }
    if ($server_homes === FALSE) {
        // If there are no games, then there can not be any mods either.
        print_failure(get_lang('no_game_homes_assigned'));
        if ($isAdmin) {
            echo "<p><a href='?m=user_games&amp;p=assign&amp;user_id={$_SESSION['user_id']}'>" . get_lang('assign_game_homes') . "</a></p>";
        }
        return;
    }
    if (empty($_GET['home_id-mod_id-ip-port'])) {
        unset($_GET['home_id-mod_id-ip-port']);
    }
    if (empty($_GET['home_id'])) {
        unset($_GET['home_id']);
    }
    if ($_GET['home_cfg_id'] == get_lang('game_type')) {
        unset($_GET['home_cfg_id']);
    }
    create_home_selector_game_type($_GET['m'], $_GET['p'], $server_homes);
    if (!isset($_GET['home_id-mod_id-ip-port']) and !isset($_GET['home_id']) and !isset($_GET['home_cfg_id'])) {
        create_home_selector_address($_GET['m'], $_GET['p'], $server_homes);
        $show_all = TRUE;
    } else {
        create_home_selector_address($_GET['m'], $_GET['p'], $server_homes);
        create_home_selector($_GET['m'], $_GET['p'], "show_all");
        $show_all = FALSE;
    }
    require "protocol/lgsl/lgsl_protocol.php";
    ?>
		<form>
			<b><?php 
    print_lang('search');
    ?>
:</b>
			<input type="text" id="search">
		</form>
	<?php 
    $info = $db->getUser($_SESSION['users_login']);
    $chk_expire = $info['user_expires'];
    $exptime = read_expire($chk_expire);
    $time_to_expire = str_replace('hr', 'hours', $exptime);
    if ($exptime != "X") {
        ?>
		<span style="color:black;font-weight:bold;">
		 <center>
			<?php 
        echo print_lang('account_expiration');
        ?>
: <span style="color:green;"><?php 
        echo date("l, F jS, Y, H:i:s", $chk_expire) . " ( " . $time_to_expire . ")";
        ?>
</span>
		 </center>
		</span>
	<?php 
    }
    ?>
		<table id="servermonitor" class="tablesorter">
		<thead> 
		<tr> 
			<th style="width:16px;background-position: center;"></th> 
			<th style="width:16px;background-position: center;"></th> 
			<th><?php 
    print_lang('server_name');
    ?>
</th> 
			<th><?php 
    print_lang('address');
    ?>
</th> 
			<th><?php 
    print_lang('owner');
    ?>
</th> 
			<th>
			  <?php 
    print_lang('operations');
    ?>
			  <img style="border:0;height:15px;" id="action-stop" src="images/stop.png"/>
			  <img style="border:0;height:15px;" id="action-restart" src="images/restart.png"/>
			  <img style="border:0;height:15px;" id="action-start" src="images/start.png"/>
			</th>
		</tr> 
		</thead> 
		<tbody> 
	<?php 
    foreach ($server_homes as $server_home) {
        $stats_servers++;
        //Unset variables.
        if (isset($_GET['home_id-mod_id-ip-port'])) {
            $pieces = explode("-", $_GET['home_id-mod_id-ip-port']);
            $post_home_id = $pieces[0];
            $post_mod_id = $pieces[1];
            $post_ip = $pieces[2];
            $post_port = $pieces[3];
        }
        if ($show_all or isset($_GET['home_id']) and $_GET['home_id'] == $server_home['home_id'] or isset($_GET['home_id-mod_id-ip-port']) and $server_home['home_id'] == $post_home_id and $server_home['mod_id'] == $post_mod_id and $post_ip == $server_home['ip'] and $post_port == $server_home['port'] or isset($_GET['home_cfg_id']) and $_GET['home_cfg_id'] == $server_home['home_cfg_id']) {
            unset($map, $trclass, $first, $second, $onlineT, $ts3opt, $offlineT, $halfT, $ministart, $player_list, $groupsus, $name, $mod_name, $SrvCtrl, $lite_fm, $manager, $user, $pos, $ftp, $addonsmanager, $ctrlChkBoxes);
            //End
            if ($isAdmin) {
                $server_home['access_rights'] = "ufpet";
            } else {
                $home_info = $db->getUserGameHome($_SESSION['user_id'], $server_home['home_id']);
                $server_home['access_rights'] = $home_info['access_rights'];
            }
            $litefm_installed = $db->isModuleInstalled('litefm');
            $ftp_installed = $db->isModuleInstalled('ftp');
            $addonsmanager_installed = $db->isModuleInstalled('addonsmanager');
            $mysql_installed = $db->isModuleInstalled('mysql');
            if ($server_home['mod_name'] == "none" or $server_home['mod_name'] == "None") {
                $mod_name = "";
            } elseif ($server_home['mod_name'] != $server_home['game_name']) {
                $mod_name = " ( " . $server_home['mod_name'] . " )";
            }
            $get_size = "<table align='left' class='monitorbutton' ><tr>" . "<td align='middle' class='size' id='" . $server_home["home_id"] . "'>" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/file_size.png' title='" . get_lang('get_size') . "'/>\n<br /><span style='font-weight:bold;'>" . get_lang('get_size') . "</span></td></tr></table>";
            $manager = "<a href='?m=user_games&amp;p=edit&amp;home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/edit.png' title='" . get_lang('edit') . "'/>\n<br />" . get_lang('edit') . "\n</td></tr></table></a>";
            // Only show the filemanager link when the litefm is installed.
            if (preg_match("/f/", $server_home['access_rights']) > 0 && $litefm_installed) {
                $lite_fm = "<a href='?m=litefm&amp;home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/txt.png' title='" . get_lang('file_manager') . "'/>\n<br />" . get_lang('file_manager') . "\n</td></tr></table></a>";
            }
            if (preg_match("/t/", $server_home['access_rights']) > 0 && $ftp_installed) {
                $ftp = "<a href='?m=ftp&amp;home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/ftp.png' title='" . get_lang('ftp') . "'/>\n<br>" . get_lang('ftp') . "\n</td></tr></table></a>";
            }
            if ($addonsmanager_installed) {
                $addons = $db->resultQuery("SELECT DISTINCT addon_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE home_cfg_id=" . $server_home['home_cfg_id']);
                $addons_qty = count($addons);
                if ($addons and $addons_qty >= 1) {
                    $addonsmanager = "<a href='?m=addonsmanager&amp;p=user_addons&amp;home_id=" . $server_home['home_id'] . "&amp;ip=" . $server_home['ip'] . "&amp;port=" . $server_home['port'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='modules/administration/images/addons_manager.png' title='" . get_lang('addons') . "'/>\n<br />" . get_lang('addons') . "\n<b style='font-size:0.9em' >(" . $addons_qty . ")</td></tr></table></a>";
                }
            }
            if ($mysql_installed) {
                $mysql_dbs = $db->resultQuery("SELECT db_id FROM OGP_DB_PREFIXmysql_databases WHERE enabled=1 AND home_id=" . $server_home['home_id']);
                if (!empty($mysql_dbs)) {
                    $mysql = "<a href='?m=mysql&p=user_db&home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='modules/administration/images/mysql_admin.png' title='" . get_lang('mysql_databases') . "'/>\n<br />" . get_lang('mysql_databases') . "\n</td></tr></table></a>\n";
                }
            }
            $mod_result = $db->getHomeMods($server_home['home_id']);
            if ($mod_result === FALSE) {
                print_failure(get_lang('fail_no_mods'));
                if ($isAdmin) {
                    $manager .= "<a href='?m=user_games&amp;p=edit&amp;home_id=" . $server_home['home_id'] . "'>" . get_lang('configure_mods') . "</a>";
                }
                continue;
            }
            $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $server_home['home_cfg_file']);
            $master_server_home_id = $db->getMasterServer($server_home['remote_server_id'], $server_home['home_cfg_id']);
            if ($master_server_home_id != FALSE) {
                if (!$db->getGameHomeWithoutMods($master_server_home_id)) {
                    $db->setMasterServer("remove", $master_server_home_id, $server_home['home_cfg_id'], $server_home['remote_server_id']);
                    $master_server_home_id = FALSE;
                }
            }
            if ($server_xml) {
                if (preg_match("/u/", $server_home['access_rights']) > 0) {
                    // In case game is compatible with steam we offer a way to use steam with the updates.
                    if ($server_xml->installer == "steamcmd") {
                        if ($master_server_home_id != FALSE and $master_server_home_id != $server_home['home_id']) {
                            $manager .= "<form name='steam_master_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . "' action='?m=gamemanager&amp;p=update&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update' method='POST' >\n" . "<table align='left' class='monitorbutton' >\n" . "<tr><td align='middle' onclick='document.steam_master_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . ".submit()' ><img style='border:0;height:40px;vertical-align:middle;' src='images/master.png' />" . "<br /><span style='font-weight:bold;'>" . get_lang('update_from_local_master_server') . "</span><input id='master" . $server_home['home_id'] . "' type='hidden' name='master_server_home_id' value='" . $master_server_home_id . "' /></td></tr>\n</table>\n</form>";
                        }
                        $manager .= "<form name='steam_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . "' action='?m=gamemanager&amp;p=update&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update' method='POST' >\n" . "<table align='left' class='monitorbutton' >\n" . "<tr><td align='middle' onclick='document.steam_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . ".submit()' ><img style='border:0;height:40px;vertical-align:middle;' src='images/steam.png' />" . "<br /><span style='font-weight:bold;'>" . get_lang('install_update_steam') . "</span></td></tr>\n</table>\n</form>";
                    } else {
                        $manager .= "<a href='?m=gamemanager&amp;p=update_manual&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/install.png' title='" . get_lang('install_update_manual') . "'/>\n<br>" . get_lang('install_update_manual') . "\n</td></td></table></a>";
                        $sync_name = get_sync_name($server_xml);
                        $sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES);
                        $master_server_home_id = $db->getMasterServer($server_home['remote_server_id'], $server_home['home_cfg_id']);
                        if (in_array($sync_name, $sync_list) or $master_server_home_id != FALSE and $master_server_home_id != $server_home['home_id']) {
                            $manager .= "<a href='?m=gamemanager&amp;p=rsync_install&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/rsync.png' title='" . get_lang('rsync_install') . "'/>\n<br />" . get_lang('rsync_install') . "\n</td></td></table></a>";
                        }
                    }
                }
            }
            if ($isAdmin) {
                if ($server_xml->control_protocol == 'rcon' or $server_xml->control_protocol == 'lcon' or $server_xml->control_protocol == 'rcon2' or @$server_xml->gameq_query_name == 'minecraft') {
                    $manager .= "<form name='rcon_preset" . $server_home['home_id'] . "' action='home.php?m=gamemanager&amp;p=rcon_presets&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "' method='POST'>\n" . "<table align='left' class='monitorbutton' >\n" . "<tr>\n" . "<td align='middle' onclick='document.rcon_preset" . $server_home['home_id'] . ".submit()' ><img style='border:0;height:40px;vertical-align:middle;' src='images/rcon_preset.png' /><br /><span style='font-weight:bold;'>" . get_lang('rcon_presets') . "</span></td>\n" . "</tr>\n" . "</table>\n" . "</form>";
                }
            }
            $xml_installer = $server_xml->installer;
            // If query name does not exist use mod key instead.
            if ($server_xml->protocol == "gameq") {
                $query_name = $server_xml->gameq_query_name;
            } elseif ($server_xml->protocol == "lgsl") {
                $query_name = $server_xml->lgsl_query_name;
            } elseif ($server_xml->mods->mod['key'] == "none" or $server_xml->mods->mod['key'] == "None") {
                $query_name = "none";
            } else {
                $query_name = $server_xml->mods->mod['key'];
            }
            if ($server_xml->mods->mod['key'] == "none" or $server_xml->mods->mod['key'] == "None") {
                $mod = "none";
            } else {
                $mod = $server_xml->mods->mod['key'];
            }
            //----------+ getting the lgsl image icon
            $icon_paths = array("images/icons/{$mod}.png", "images/icons/{$query_name}.png", "protocol/lgsl/other/icon_unknown.gif");
            $icon_path = get_first_existing_file($icon_paths);
            //Properties for all servers
            if (isset($post_home_id) && $post_home_id == $server_home['home_id'] or isset($_GET['home_id']) && $_GET['home_id'] == $server_home['home_id']) {
                $trclass = " expandme";
            }
            $groupusers = $db->getGroupUsersByHomeId($server_home['home_id']);
            if ($groupusers) {
                $groupsus = "<b>" . get_lang('group_users') . "</b><br>";
                foreach ($groupusers as $groupu) {
                    $groupsus .= $groupu['users_login'] . "<br>";
                }
            } else {
                $groupsus = "";
            }
            $view_log = "<a href='?m=gamemanager&amp;p=log&amp;home_id-mod_id-ip-port=" . $server_home['home_id'] . "-" . $server_home['mod_id'] . "-" . $server_home['ip'] . "-" . $server_home['port'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/log.png' title='" . get_lang('view_log') . "'/>\n<br>" . get_lang('view_log') . "\n</td></tr></table></a>";
            $btns = $view_log . @$ftp . @$lite_fm . @$addonsmanager;
            //End
            $remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
            $host_stat = $remote->status_chk();
            if ($host_stat === 1) {
                if ($server_home['use_nat'] == 1) {
                    $query_ip = $server_home['agent_ip'];
                } else {
                    $query_ip = $server_home['ip'];
                }
                $address = $query_ip . ":" . $server_home['port'];
                $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $server_home['home_id']) === 1;
                $update_in_progress = $remote->is_screen_running(OGP_SCREEN_TYPE_UPDATE, $server_home['home_id']) === 1;
                if ($screen_running) {
                    // Check if the screen running the server is running.
                    $status = "online";
                    $order = 1;
                    if ($server_xml->protocol == "lgsl") {
                        $get_q_and_s = lgsl_port_conversion((string) $query_name, $server_home['port'], "", "");
                        //Connection port
                        $c_port = $get_q_and_s['0'];
                        //query port
                        $q_port = $get_q_and_s['1'];
                        //software port
                        $s_port = $get_q_and_s['2'];
                        $address = "<a href='" . lgsl_software_link($query_name, $query_ip, $c_port, $q_port, $s_port) . "'>" . $query_ip . ":" . $server_home['port'] . "</a>";
                    }
                    if ($server_xml->protocol == "teamspeak3") {
                        $address = "<a href='ts3server://" . $query_ip . ":" . $server_home['port'] . "'>" . $query_ip . ":" . $server_home['port'] . "</a>";
                    }
                    if ($server_xml->protocol == "gameq" and $server_xml->installer == 'steamcmd') {
                        $address = "<a href='steam://connect/" . $query_ip . ":" . $server_home['port'] . "'>" . $query_ip . ":" . $server_home['port'] . "</a>";
                    }
                    $pos = $refresh->add("home.php?m=gamemanager&p=ref_servermonitor&type=cleared&server_home=" . $server_home['home_id'] . "&ip=" . $server_home['ip'] . "&port=" . $server_home['port']);
                    if ($server_xml->protocol == "teamspeak3") {
                        require 'protocol/TeamSpeak3/functions.php';
                    }
                    $startup_file_exists = $remote->rfile_exists("startups/" . $server_home['ip'] . "-" . $server_home['port']) === 1;
                    $ctrlChkBoxes .= '<div id="server_icon" class="action-stop' . $server_home['home_id'] . '" >
									 <div>
									 <input id="action-stop" class="action-stop' . $server_home['home_id'] . '" name="action-' . $server_home['home_id'] . '" value="stop-' . $server_home['home_id'] . '-' . $server_home['mod_id'] . '-' . $server_home['ip'] . '-' . $server_home['port'] . '" type="radio"><img style="border:0;height:15px;" src="images/stop.png"/></div><div>&nbsp;' . get_lang('stop_server') . '</div></div>';
                    if ($startup_file_exists) {
                        $ctrlChkBoxes .= '<div id="server_icon" class="action-restart' . $server_home['home_id'] . '" >
										 <div>
										 <input id="action-restart" class="action-restart' . $server_home['home_id'] . '" name="action-' . $server_home['home_id'] . '" value="restart-' . $server_home['home_id'] . '-' . $server_home['mod_id'] . '-' . $server_home['ip'] . '-' . $server_home['port'] . '" type="radio"><img style="border:0;height:15px;" src="images/restart.png"/></div><div>&nbsp;' . get_lang('restart_server') . '</div></div>';
                    }
                    $stats_servers_online++;
                } else {
                    $status = "offline";
                    if ($db->getLastParam($server_home['home_id']) != FALSE) {
                        if ($update_in_progress) {
                            $ctrlChkBoxes .= '<div id="server_icon" class="action-start' . $server_home['home_id'] . '" >&nbsp;' . get_lang('update_in_progress') . '</div>';
                        } else {
                            $ctrlChkBoxes .= '<div id="server_icon" class="action-start' . $server_home['home_id'] . '" >
											 <div>
											 <input id="action-start" class="action-start' . $server_home['home_id'] . '" name="action-' . $server_home['home_id'] . '" value="start-' . $server_home['home_id'] . '-' . $server_home['mod_id'] . '-' . $server_home['ip'] . '-' . $server_home['port'] . '" type="radio"><img style="border:0;height:15px;" src="images/start.png"/></div><div>&nbsp;' . get_lang('start_server') . '</div></div>';
                        }
                    }
                    $order = 3;
                    ob_start();
                    require 'modules/gamemanager/mini_start.php';
                    $ministart = ob_get_contents();
                    ob_end_clean();
                    if ($update_in_progress) {
                        $offlineT = '<div id="server_icon" class="action-start' . $server_home['home_id'] . '" >&nbsp;' . get_lang('update_in_progress') . '</div>';
                    } else {
                        $offlineT = $ministart;
                    }
                }
            } else {
                $status = "offline";
                $order = 3;
                $address = "<span style='color:darkred;font-weight:bold;'>Agent Offline</span>";
            }
            $user = $db->getUserById($server_home['user_id_main']);
            // Template
            @($first = "<tr class='maintr{$trclass}'>");
            $first .= "<td class='collapsible'><span class='hidden'>{$order}</span><a></a>" . "<img src='images/{$status}.png' />" . "</td>";
            $first .= "<td>" . "<span class='hidden'>{$mod}</span><img src='{$icon_path}' />" . "</td>";
            $first .= "<td class='collapsible'><a></a><b>" . $server_home['home_name'] . "</b>{$mod_name}</td>";
            $first .= "<td>" . $address . "</td>";
            $first .= "<td>" . $user['users_login'] . "</td>";
            $first .= "<td style='width:328px;padding:0px;'>{$ctrlChkBoxes}</td>";
            $first .= "</tr>";
            $second = "<tr class='expand-child'>";
            @($second .= "<td colspan='4'>" . $refresh->getdiv($pos, "width:100%;") . "{$offlineT}</td>");
            $second .= "<td width='80'>{$groupsus}</td>";
            @($second .= "<td>{$btns}{$manager}<br>{$mysql}<br>{$get_size}<br>{$ts3opt}</td>");
            $second .= "</tr>";
            //Echo them all
            echo "{$first}{$second}";
        }
    }
    echo "</tbody>";
    echo "<tfoot style='border:1px solid grey;'>\n\t\t\t<tr>\n\t\t\t  <td colspan='6' >\n\t\t\t\t<div class='bloc' >\n\t\t\t\t<img src='images/magnifglass.png' /> " . get_lang('statistics') . ": {$stats_servers_online}/{$stats_servers} " . get_lang('servers') . "\n</div>\n\t\t\t\t<div class='right bloc' >\n\t\t\t\t  <label>" . get_lang('execute_selected_server_operations') . "</label>\n\t\t\t\t  <input id='execute_operations' type='submit' value='" . get_lang('execute_operations') . "' >\n\n\t\t\t\t</div>\n\t\t\t  </td>\n\t\t\t</tr>\n\t\t  </tfoot>";
    echo "</table>";
    ?>
	<script type="text/javascript">
			$(document).ready(function() 
				{ 
					<?php 
    echo $refresh->build("8000");
    ?>
					$('input#search').quicksearch('table#servermonitor tbody tr.maintr');
					$("#servermonitor")
						.collapsible("td.collapsible", {collapse: true})
						.tablesorter({sortList: [[0,0], [1,0]] , widgets: ['zebra','repeatHeaders']})
						; 
				} 
			);
			
			$("div#server_icon").click(function(){
				var id = $(this).attr('class');
				if($("input[type=radio]."+id).attr('checked') == 'checked')
				{
					$("input[type=radio]."+id).prop('checked', false);
				}
				else
				{
					$("input[type=radio]."+id).prop('checked', true);
				}
			});
						
			$('.size').click(function(){
				var $id = $(this).attr('id');
				$.get( "home.php?m=user_games&type=cleared&p=get_size&home_id="+$id, function( data ) {
					$('#'+$id+".size").text( data );
					$('#'+$id+".size").css("font-size", "16pt");
				});
			});
			
			$('#execute_operations').click(function(){
				var addpost = {};
				$('input[type=radio]:checked').each(function( ){
					var name = $(this).attr('name');
					var value = $(this).val();
					addpost[ name ] = value;
				});
				
				$('.right.bloc').html('<img src="images/loading.gif" />');
				
				$.ajax({
				type: "POST",
				url: "home.php?m=gamemanager&p=game_monitor",
				data: addpost,
				complete: function(){ 
					document.location.reload(); 
				}
				});
			});
			
			$('img#action-stop').click(function(){
				$('input[type=radio]#action-stop').each(function( ){
					if( this.checked )
					{
						$(this).attr('checked', false);
					}
					else
					{
						$(this).attr('checked', true);
					}
				});
			});
			
			$('img#action-restart').click(function(){
				$('input[type=radio]#action-restart').each(function( ){
					if( this.checked )
					{
						$(this).attr('checked', false);
					}
					else
					{
						$(this).attr('checked', true);
					}
				});
			});
			
			$('img#action-start').click(function(){
				$('input[type=radio]#action-start').each(function( ){
					if( this.checked )
					{
						$(this).attr('checked', false);
					}
					else
					{
						$(this).attr('checked', true);
					}
				});
			});
		</script>
	<?php 
}
function exec_ogp_module()
{
    global $db;
    global $view;
    $pieces = explode("-", $_GET['home_id-mod_id-ip-port']);
    $home_id = $pieces[0];
    $mod_id = $pieces[1];
    $ip = $pieces[2];
    $port = $pieces[3];
    $user_id = $_SESSION['user_id'];
    $isAdmin = $db->isAdmin($user_id);
    if ($isAdmin) {
        $home_info = $db->getGameHome($home_id);
    } else {
        $home_info = $db->getUserGameHome($user_id, $home_id);
    }
    if ($home_info === FALSE) {
        print_failure(get_lang('no_access_to_home'));
        return;
    }
    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
    if (!$server_xml) {
        echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
        return;
    }
    require_once 'includes/lib_remote.php';
    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
    $home_log = "";
    if (isset($server_xml->console_log)) {
        $log_retval = $remote->remote_readfile($home_info['home_path'] . '/' . $server_xml->console_log, $home_log);
    } else {
        $log_retval = $remote->get_log(OGP_SCREEN_TYPE_HOME, $home_info['home_id'], clean_path($home_info['home_path'] . "/" . $server_xml->exe_location), $home_log);
    }
    if ($log_retval == 0) {
        print_failure(get_lang('agent_offline'));
        echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
    } elseif ($log_retval == 1 || $log_retval == 2) {
        // Using the refreshed class
        if (isset($_GET['refreshed'])) {
            echo "<pre class='log'>" . $home_log . "</pre>";
        } else {
            echo "<h2>" . $home_info['home_name'] . "</h2>";
            require_once "includes/refreshed.php";
            $control = '<form method="POST" >
						<input type="submit" name="';
            if (isset($_POST['full'])) {
                $height = "100%";
                $control .= 'default" value="-';
            } else {
                $height = "500px";
                $control .= 'full" value="+';
            }
            $control .= '" /></form><br />';
            $intervals = array("4s" => "4000", "8s" => "8000", "30s" => "30000", "2m" => "120000", "5m" => "300000");
            $intSel = '<form action="" method="GET" >
					   <input type="hidden" name="m" value="gamemanager" />
					   <input type="hidden" name="p" value="log" />
					   <input type="hidden" name="home_id-mod_id-ip-port" value="' . $_GET['home_id-mod_id-ip-port'] . '" />' . get_lang('refresh_interval') . ':<select name="setInterval" onchange="this.form.submit();">';
            foreach ($intervals as $interval => $value) {
                $selected = "";
                if (isset($_GET['setInterval']) and $_GET['setInterval'] == $value) {
                    $selected = 'selected="selected"';
                }
                $intSel .= '<option value="' . $value . '" ' . $selected . ' >' . $interval . '</option>';
            }
            $intSel .= "</select></form>";
            $setInterval = $_GET['setInterval'] ? $_GET['setInterval'] : 4000;
            $refresh = new refreshed();
            $pos = $refresh->add("home.php?m=gamemanager&p=log&type=cleared&refreshed&home_id-mod_id-ip-port=" . $_GET['home_id-mod_id-ip-port']);
            echo $refresh->getdiv($pos, "height:" . $height . ";overflow:auto;max-width:1600px;");
            ?>
<script type="text/javascript">$(document).ready(function(){ <?php 
            echo $refresh->build("{$setInterval}");
            ?>
} ); </script><?php 
            echo "<table class='center' ><tr><td>{$intSel}</td><td>{$control}</td></tr></table>";
            if ($remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']) != 1) {
                print_failure(get_lang('server_not_running'));
            } else {
                if ($server_xml->control_protocol == 'rcon' or $server_xml->control_protocol == 'rcon2' or @$server_xml->gameq_query_name == "minecraft" or $server_xml->control_protocol == 'lcon' or isset($server_xml->lgsl_query_name) and $server_xml->lgsl_query_name == "7dtd") {
                    require 'modules/gamemanager/rcon.php';
                }
            }
            echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
        }
    } else {
        print_failure(get_lang_f('unable_to_get_log', $log_retval));
        echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
    }
}
function exec_ogp_module()
{
    global $db, $settings;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    $OnlineServers = "";
    $OnlineServersTitle = "";
    if (isset($settings['welcome_title']) && $settings['welcome_title'] == "1") {
        if (isset($settings['welcome_title_message']) && !empty($settings['welcome_title_message'])) {
            echo "<div>" . $settings['welcome_title_message'] . "</div>";
        }
    }
    $OnlineServersTitle .= get_lang('online_servers');
    $player_list = "";
    if ($isAdmin) {
        $server_homes = $db->getIpPorts();
    } else {
        $OnlineServersTitle = "Open Game Panel";
        $OnlineServers .= "<p>" . get_lang("welcome_text") . "</p><br><b>" . get_lang('online_servers') . ":</b><br><br>";
        $server_homes = $db->getIpPortsForUser($_SESSION['user_id']);
    }
    require_once "includes/refreshed.php";
    $refresh = new refreshed();
    if (!$server_homes) {
        $OnlineServers .= "<p class='failure'>" . get_lang('no_games_to_monitor') . "</p>";
        if ($isAdmin) {
            //$OnlineServers .= "<p class='note'>".get_lang('add_games_in').
            //"&nbsp;<a href='?m=user_games&amp;p=add'>".get_lang('game_servers')."</a></p>";
            $OnlineServers .= "<p class='note'>" . get_lang_f("add_games_in", "<a href='?m=user_games&amp;p=add'>" . get_lang('game_servers') . "</a>") . "</p>";
        }
    } else {
        if (isset($settings['old_dashboard_behavior']) and $settings['old_dashboard_behavior'] == 1) {
            $serverslist = $refresh->add("home.php?m=dashboard&p=query_ref&show=servers&type=cleared");
            $playerslist = $refresh->add("home.php?m=dashboard&p=query_ref&show=players&type=cleared");
            $OnlineServers .= $refresh->getdiv($serverslist);
            $player_list .= $refresh->getdiv($playerslist);
        } else {
            $player_list = "";
            $stats_servers = 0;
            $stats_servers_online = 0;
            $stats_players = 0;
            $stats_maxplayers = 0;
            $onlinePlayers = "";
            $OnlineServers .= "<table style='width:100%;' class='online_servers'>";
            require_once "protocol/lgsl/lgsl_protocol.php";
            foreach ($server_homes as $server_home) {
                $remote_server_id = $server_home['remote_server_id'];
                $rserver = $db->getRemoteServerById($remote_server_id);
                // Count the number of servers.
                $stats_servers++;
                // Remember to clear the old value here.
                $message = "";
                $remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key']);
                $host_stat = $remote->status_chk();
                if ($host_stat === 1) {
                    // Check if the screen running the server is running.
                    $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $server_home['home_id']) === 1;
                    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $server_home['home_cfg_file']);
                    if ($screen_running) {
                        // Check if the screen running the server is running.
                        if ($server_home['use_nat'] == 1) {
                            $ip = $server_home['agent_ip'];
                        } else {
                            $ip = $server_home['ip'];
                        }
                        $port = $server_home['port'];
                        $get_q_and_s = lgsl_port_conversion((string) $server_xml->lgsl_query_name, $port, "", "");
                        //Connection port
                        $c_port = $get_q_and_s['0'];
                        //query port
                        $q_port = $get_q_and_s['1'];
                        //software port
                        $s_port = $get_q_and_s['2'];
                        if ($server_xml->protocol == "lgsl") {
                            $address = "<a href='" . lgsl_software_link($server_xml->lgsl_query_name, $ip, $c_port, $q_port, $s_port) . "'>" . $ip . ":" . $port . "</a>";
                        }
                        if ($server_xml->protocol == "teamspeak3") {
                            $address = "<a href='ts3server://{$ip}:{$port}'>{$ip}:{$port}</a>";
                        } elseif ($server_xml->protocol == "gameq" and $server_xml->installer == "steam") {
                            $address = "<a href='steam://connect/{$ip}:{$port}'>{$ip}:{$port}</a>";
                        } elseif ($server_xml->protocol == "gameq" or !isset($server_xml->protocol)) {
                            $address = "{$ip}:{$port}";
                        }
                        $OnlineServers .= "<tr><td><div class='name' ><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=" . $server_home['home_id'] . "-" . $server_home['mod_id'] . "-" . $server_home['ip'] . "-" . $server_home['port'] . "' ><img style='border:0;height:12px;' src='images/magnifglass.png'/>" . $server_home['home_name'] . "</a></div> | ";
                        $OnlineServers .= "<div id='gamelink' >{$address}</div>";
                        $OnlineServers .= "</td></tr>";
                        $stats_servers_online++;
                    }
                }
                unset($map, $player_list, $status, $ip, $port, $players, $playersmax, $name, $map, $mod, $xml_mod, $qport, $address, $maplocation);
            }
            $OnlineServers .= "</table>";
            $OnlineServers .= "<center>" . get_lang('statistics') . ":<br>{$stats_servers_online}/{$stats_servers} " . get_lang('online_servers') . "</center>";
        }
    }
    ?>
	<div style="margin-top:20px;">    
	<?php 
    //$title[$id] = "The Title";
    //$content[$id] = "Content of the Widget";
    $title = array();
    $content = array();
    $href = array();
    // Game Monitor
    $title[1] = get_lang('game_monitor');
    $content[1] = '<img src="themes/' . $settings['theme'] . '/images/icons/game_monitor.png" style="width:48px;float:right;margin:0 0 0 8px" />' . get_lang('dashboard_game_monitor_text');
    $href[1] = 'home.php?m=gamemanager&p=game_monitor';
    // Online Server
    $title[2] = $OnlineServersTitle;
    $content[2] = $OnlineServers;
    $href[2] = null;
    // Currently Online
    $title[3] = get_lang('currently_online');
    $content[3] = $player_list;
    $href[3] = null;
    // FTP
    $title[4] = get_lang('ftp');
    $content[4] = '<img src="themes/' . $settings['theme'] . '/images/icons/folder.png" style="width:48px;float:right;margin:0 0 0 8px" />' . get_lang('dashboard_ftp_text');
    $href[4] = 'home.php?m=ftp';
    // Support
    $title[5] = get_lang('support');
    $content[5] = '<img src="themes/' . $settings['theme'] . '/images/icons/support.png" style="width:48px;float:right;margin:0 0 0 8px" />' . get_lang('dashboard_support_text');
    $href[5] = 'http://www.opengamepanel.org/forum';
    $columns = array();
    $columns[1]['column_id'] = 1;
    $columns[2]['column_id'] = 2;
    $columns[3]['column_id'] = 3;
    foreach ($columns as $column) {
        echo '<div class="column ';
        if ($column['column_id'] == 1) {
            echo 'one_fourth';
        } else {
            if ($column['column_id'] == 2) {
                echo 'one_two';
            } else {
                if ($column['column_id'] == 3) {
                    echo 'one_fourth';
                }
            }
        }
        echo '" id="column' . $column['column_id'] . '" >';
        $items = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXwidgets_users WHERE column_id='" . $column['column_id'] . "' AND user_id='" . $_SESSION['user_id'] . "' ORDER BY sort_no");
        if ($items) {
            foreach ($items as $widget) {
                if ((!isset($settings['old_dashboard_behavior']) or $settings['old_dashboard_behavior'] == 0) and $widget['widget_id'] == "3") {
                    continue;
                }
                echo ' 
				<div class="dragbox bloc rounded" id="item' . $widget['widget_id'] . '"> 
					<h4><span class="configure"></span>';
                if (!is_null($title[$widget['widget_id']])) {
                    echo $title[$widget['widget_id']];
                }
                echo '</h4> 
						<div class="dragbox-content" ';
                if (!is_null($href[$widget['widget_id']])) {
                    echo "onclick=\"location.href='" . $href[$widget['widget_id']] . "'\" style=\"cursor:pointer;";
                    if ($widget['collapsed'] == 1) {
                        echo 'display:none;';
                    }
                    echo '"';
                } elseif ($widget['collapsed'] == 1) {
                    echo 'style="display:none;"';
                }
                echo '>';
                if (!is_null($content[$widget['widget_id']])) {
                    echo $content[$widget['widget_id']];
                }
                echo ' 
					</div> 
				</div>';
                unset($widget);
            }
        }
        echo '</div>';
    }
    if ($isAdmin and $db->isModuleInstalled('status')) {
        echo "<h0>Server Status</h0><br>";
        $servers = $db->getRemoteServers();
        echo "<div style='float:left;width:40%;' >\n\t\t\t   <div class='bloc rounded' >\n\t\t\t   <h4>Select remote server</h4>\n\t\t\t    <div>\n\t\t\t\t<br>\n\t\t\t\t<center>\n\t\t\t    <form action='' method='GET'>\n\t\t\t    <input type='hidden' name='m' value='" . $_GET['m'] . "'/>\n\t\t\t    <input type='hidden' name='p' value='" . $_GET['p'] . "'/>\n\t\t\t    <select name='remote_server_id' onchange=" . '"this.form.submit()"' . ">\n";
        foreach ($servers as $server_row) {
            if (!empty($server_row['remote_server_id']) and !isset($_GET['remote_server_id']) or !empty($server_row['remote_server_id']) and empty($_GET['remote_server_id'])) {
                $_GET['remote_server_id'] = $server_row['remote_server_id'];
            }
            if (isset($_GET['remote_server_id']) and $_GET['remote_server_id'] == $server_row['remote_server_id']) {
                $rhost_id = $_GET['remote_server_id'];
                $remote_server = $db->getRemoteServer($rhost_id);
                $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
                $host_stat = $remote->status_chk();
                if ($host_stat === 1) {
                    $checked = "selected='selected'";
                } else {
                    $checked = '';
                    $_GET['remote_server_id'] = 'webhost';
                }
            } else {
                $checked = '';
            }
            echo "<option value='" . $server_row['remote_server_id'] . "' {$checked} >" . $server_row['remote_server_name'] . "</option>\n";
        }
        if (function_exists('exec')) {
            $checked = (isset($_GET['remote_server_id']) and $_GET['remote_server_id'] == 'webhost') ? "selected='selected'" : "";
            echo "<option value='webhost' {$checked} >Webhost Status</option>";
        }
        echo "\t</select>\n\t\t\t    </form>\n\t\t\t\t</center>\n\t\t\t\t<br><br>\n\t\t\t    </div>\n\t\t\t   </div>\n\t\t\t  </div>\n";
        if (isset($_GET['remote_server_id']) and $_GET['remote_server_id'] == "webhost") {
            unset($_GET['remote_server_id']);
        }
        if (isset($_GET['remote_server_id']) && !empty($_GET['remote_server_id'])) {
            $remote_server = "&remote_server_id=" . $_GET['remote_server_id'];
        } else {
            $remote_server = "";
        }
        if ($isAdmin and $db->isModuleInstalled('status') and (isset($_GET['remote_server_id']) or function_exists('exec'))) {
            $status = $refresh->add("home.php?m=status&type=cleared" . $remote_server);
            echo $refresh->getdiv($status);
        }
    }
    ?>
	
<script type="text/javascript">
var userAgent = navigator.userAgent.toLowerCase(),
	browser   = '',
	version   = 0;

$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());

// Is this a version of IE?
if ($.browser.msie) {
  userAgent = $.browser.version;
  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
  version = userAgent;
  browser = "Internet Explorer";
}

// Is this a version of Chrome?
if ($.browser.chrome) {
  userAgent = userAgent.substring(userAgent.indexOf('chrome/') + 7);
  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
  version = userAgent;
  // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
  $.browser.safari = false;
  browser = "Chrome";
}

// Is this a version of Safari?
if ($.browser.safari) {
  userAgent = userAgent.substring(userAgent.indexOf('safari/') + 7);
  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
  version = userAgent;
  browser = "Safari";
}

// Is this a version of Mozilla?
if ($.browser.mozilla) {
	//Is it Firefox?
	if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
		userAgent = userAgent.substring(userAgent.indexOf('firefox/') + 8);
		userAgent = userAgent.substring(0,userAgent.indexOf('.'));
		version = userAgent;
		browser = "Firefox"
	}
	// If not then it must be another Mozilla
	else {
	  browser = "Mozilla (not Firefox)"
	}
}

// Is this a version of Opera?
if ($.browser.opera) {
	userAgent = userAgent.substring(userAgent.indexOf('version/') + 8);
	userAgent = userAgent.substring(0,userAgent.indexOf('.'));
	version = userAgent;
	browser = "Opera";
}

// Now you have two variables, browser and version
// which have the right info
$(document).ready(
	function(){  
		$('.dragbox')  
		.each(function(){  
			$(this).hover(function(){  
				$(this).find('h4').addClass('collapse'); 
			}, function(){  
			$(this).find('h4').removeClass('collapse');  
			})  
			.find('h4').hover(function(){  
				$(this).find('.configure').css('visibility', 'visible'); 
			}, function(){  
				$(this).find('.configure').css('visibility', 'hidden');  
			})  
			.click(function(){  
				$(this).siblings('.dragbox-content').toggle();  
				//Save state on change of collapse state of panel  
				updateWidgetData();  
			})  
			.end()  
			.find('.configure').css('visibility', 'hidden');  
		});  
	  
		$('.column').sortable({  
			connectWith: '.column',  
			handle: 'h4',  
			cursor: 'move',  
			placeholder: 'placeholder',  
			forcePlaceholderSize: true,  
			opacity: 0.4,   
			start: function(event, ui){
				//Firefox, Safari/Chrome fire click event after drag is complete, fix for that
				if(browser == "Firefox" || browser == "Mozilla (not Firefox)" || browser == "Safari") 
					$(ui.item).find('.dragbox-content').toggle();
			},
			stop: function(){  
				updateWidgetData();  
			}
		})  
		.disableSelection();  
	}  
);
function updateWidgetData(){  
	var items=[];  
	$('.column').each(function(){  
		var columnId=$(this).attr('id');  
		$('.dragbox', this).each(function(i){  
			var collapsed=0;  
			if($(this).find('.dragbox-content').css('display')=="none")  
				collapsed=1;  
			//Create Item object for current panel  
			var item={  
				id: $(this).attr('id'),  
				collapsed: collapsed,  
				order : i,  
				column: columnId  
			};  
			//Push item object into items array  
			items.push(item);  
		});  
	});  
	//Assign items array to sortorder JSON variable  
	var sortorder={ items: items };  
	//Pass sortorder variable to server using ajax to save state  
	$.post('home.php?m=dashboard&p=updateWidgets', 'data='+$.toJSON(sortorder), function(response){ 
		if(response.indexOf("success") < 0){
			$("#console").html('<h0><div class="Failed">Failed to save you\'r operation! Please contact OGP...</div></h0>').hide().fadeIn(1000);  
		}
	});  
}

$(document).ready(function(){ 
	<?php 
    echo $refresh->build("20000");
    ?>
});
</script>
<?php 
}