home.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2015 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. require_once("includes/functions.php");
  25. require_once("includes/helpers.php");
  26. require_once("includes/html_functions.php");
  27. startSession();
  28. // Report all PHP errors
  29. error_reporting(E_ERROR);
  30. // Path definitions
  31. define("IMAGES", "images/");
  32. define("INCLUDES", "includes/");
  33. define("MODULES", "modules/");
  34. define("CONFIG_FILE","includes/config.inc.php");
  35. require_once CONFIG_FILE;
  36. // Connect to the database server and select database.
  37. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  38. // Logged in user settings - access this global variable where needed
  39. if(hasValue($_SESSION['user_id'])){
  40. $loggedInUserInfo = $db->getUserById($_SESSION['user_id']);
  41. }
  42. $settings = $db->getSettings();
  43. @$GLOBALS['panel_language'] = $settings['panel_language'];
  44. // Load languages.
  45. include_once("includes/lang.php");
  46. ogpLang();
  47. require_once("includes/view.php");
  48. $view = new OGPView();
  49. $view->setCharset(get_lang('lang_charset'));
  50. $view->setTimeZone($settings['time_zone']);
  51. if(isset($_GET['type']) && $_GET['type'] == 'cleared')
  52. {
  53. if(isset($_GET['data_type'])){
  54. heading(true);
  55. $view->printView(true, $_GET['data_type']);
  56. }else{
  57. heading(true);
  58. $view->printView(true);
  59. }
  60. }
  61. else
  62. {
  63. ogpHome();
  64. $view->printView();
  65. }
  66. function heading()
  67. {
  68. global $db,$view,$settings;
  69. if ( !file_exists(CONFIG_FILE) )
  70. {
  71. print_failure(get_lang('failed_to_read_config'));
  72. $view->refresh("index.php");
  73. return;
  74. }
  75. // Start Output Buffering
  76. if (!isset($_SESSION['users_login']))
  77. {
  78. print_failure(get_lang('invalid_login_information'));
  79. echo "<p class='note' style='color:red;'>".get_lang('invalid_redirect')."...</p>";
  80. $view->refresh("index.php", 2);
  81. return;
  82. }
  83. else
  84. {
  85. $info = $db->getUserById($_SESSION['user_id']);
  86. if($info['user_expires'] != "X")
  87. {
  88. list($days,$strd,$hours,$strh,$minutes,$strm) = explode(" ", read_expire($info['user_expires']));
  89. $minutes2expire = $minutes + intval( $hours * 60 ) + intval( $days * 24 * 60 );
  90. if($minutes2expire <= 0)
  91. {
  92. echo "<h1>".get_lang('account_expired')."</h1>";
  93. echo "<p class='note'>".get_lang('contact_admin_to_enable_account')."</p>";
  94. session_destroy();
  95. return;
  96. }
  97. }
  98. if( isset($settings['maintenance_mode']) && $settings['maintenance_mode'] == "1" )
  99. {
  100. if ($_SESSION['users_group'] == "user")
  101. {
  102. echo "<h2>".$settings['maintenance_title']."</h2>";
  103. echo "<p>".$settings['maintenance_message']."</p>";
  104. $view->setTitle("OGP: Maintenance.");
  105. echo "<p class='failure'>".get_lang('logging_out_10')."...</p>";
  106. $view->refresh("index.php", 10);
  107. session_destroy();
  108. return;
  109. }
  110. }
  111. if ( isset($_REQUEST['logout']) )
  112. {
  113. session_destroy();
  114. print_success(get_lang('logout_message'));
  115. $view->refresh("index.php");
  116. return;
  117. }
  118. include "includes/navig.php";
  119. }
  120. if(isset($maintenance))echo $maintenance;
  121. }
  122. function ogpHome()
  123. {
  124. global $db,$view,$settings, $loggedInUserInfo;
  125. $page_user = (isset($_GET['page']) && (int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1; // thanks for Adjokip
  126. $limit_user = isset($_GET['limit']) ? $_GET['limit'] : 10;
  127. if(hasValue($loggedInUserInfo) && is_array($loggedInUserInfo) && $loggedInUserInfo["users_page_limit"] && !hasValue($_GET['limit'])){
  128. $limit_user = $loggedInUserInfo["users_page_limit"];
  129. }
  130. ?>
  131. %top%
  132. <?php
  133. if(isset($_SESSION['user_id']))
  134. {
  135. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  136. if ( $isAdmin )
  137. $server_homes = $db->getHomesFor_limit('admin', $_SESSION['user_id'],$page_user,$limit_user);
  138. else
  139. $server_homes = $db->getHomesFor_limit('user_and_group', $_SESSION['user_id'],$page_user,$limit_user);
  140. if(!empty($server_homes))
  141. {
  142. $servers_by_game_name = array();
  143. foreach( $server_homes as $server_home )
  144. {
  145. if(isset($settings['check_expiry_by']) and $settings['check_expiry_by'] == "once_logged_in")
  146. {
  147. if($db->check_expire_date($_SESSION['user_id'], $server_home['home_id']))
  148. continue;
  149. }
  150. $servers_by_game_name["$server_home[game_name]"][] = $server_home;
  151. }
  152. ksort($servers_by_game_name);
  153. $game_homes_list = "<ul id='submenu_0' >\n";
  154. require_once("modules/config_games/server_config_parser.php");
  155. foreach( $servers_by_game_name as $game_name => $server_homes )
  156. {
  157. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$server_homes[0]['home_cfg_file']);
  158. $mod = $server_homes[0]['mod_key'];
  159. // If query name does not exist use mod key instead.
  160. if ($server_xml->protocol == "gameq")
  161. $query_name = $server_xml->gameq_query_name;
  162. elseif ($server_xml->protocol == "lgsl")
  163. $query_name = $server_xml->lgsl_query_name;
  164. else
  165. $query_name = $mod;
  166. //----------+ getting the lgsl image icon
  167. $icon_paths = array("images/icons/$mod.png",
  168. "images/icons/$query_name.png",
  169. "protocol/lgsl/other/icon_unknown.gif");
  170. $icon_path = get_first_existing_file($icon_paths);
  171. $game_homes_list .= "<li>\n<a href='?m=gamemanager&p=game_monitor&home_cfg_id=".$server_homes[0]['home_cfg_id'].
  172. "'><span data-icon_path='$icon_path'>$game_name</span></a>\n<ul id='submenu_1' >\n";
  173. foreach($server_homes as $server_home)
  174. {
  175. $button_name = htmlentities($server_home['home_name']);
  176. if( ! preg_match("/none/i", $server_home['mod_name']) )
  177. $button_name .= " - ".$server_home['mod_name'];
  178. $game_homes_list .= "<li><a title='".$server_home['ip'].':'.$server_home['port'].
  179. "' class='user_menu_link' href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=".
  180. $server_home['home_id'].'-'.$server_home['mod_id'].'-'.$server_home['ip'].'-'.
  181. $server_home['port']."'>".$button_name."</a></li>\n";
  182. }
  183. $game_homes_list .= "</ul>\n</li>\n";
  184. }
  185. $game_homes_list .= "</ul>\n";
  186. }
  187. else
  188. $game_homes_list = "";
  189. ?>
  190. <div class="menu-bg">
  191. <div class="menu">
  192. <ul>
  193. <?php
  194. $menus = $db->getMenusForGroup('user');
  195. foreach ( $menus as $menu )
  196. {
  197. $module = $menu['module'];
  198. if ( !empty( $menu['subpage'] ) )
  199. {
  200. $subpage = "&amp;p=".$menu['subpage'];
  201. $button = $menu['subpage'];
  202. if (isset($_GET['p']) AND $_GET['p'] == $menu['subpage'] ) $menu_link_class = 'user_menu_link_selected'; else $menu_link_class = 'user_menu_link';
  203. }
  204. else
  205. {
  206. $subpage = "";
  207. $button = $menu['module'];
  208. if (isset($_GET['m']) AND $_GET['m'] == $menu['module'] ) $menu_link_class = 'user_menu_link_selected'; else $menu_link_class = 'user_menu_link';
  209. }
  210. $button_url = "?m=".$module.$subpage;
  211. if ( preg_match( '/\\_?\\_/', get_lang("$button") ) )
  212. {
  213. $button_name = $menu['menu_name'];
  214. }
  215. else
  216. {
  217. $button_name = get_lang("$button");
  218. }
  219. echo "<li><a class='".$menu_link_class."' href='".$button_url."'><span class='$button'>".$button_name."</span></a>";
  220. if( $menu['subpage'] == "game_monitor" )
  221. echo $game_homes_list;
  222. echo "</li>\n";
  223. }
  224. if($isAdmin)
  225. {
  226. $data = "";
  227. $TotalSelected = false;
  228. $menus = $db->getMenusForGroup('admin');
  229. foreach ($menus as $key => $row) {
  230. if ( !empty( $row['subpage'] ) )
  231. $name[$key] = $row['subpage'];
  232. else
  233. $name[$key] = $row['module'];
  234. $translation[$key] = get_lang($name[$key]);
  235. }
  236. array_multisort($translation, $name, SORT_DESC, $menus);
  237. foreach ( $menus as $menu )
  238. {
  239. $module = $menu['module'];
  240. if ( !empty( $menu['subpage'] ) )
  241. {
  242. $subpage = "&amp;p=".$menu['subpage'];
  243. $button = $menu['subpage'];
  244. if (isset($_GET['p']) AND $_GET['p'] == $menu['subpage'] ) $menu_link_class = 'admin_menu_link_selected'; else $menu_link_class = 'admin_menu_link';
  245. }
  246. else
  247. {
  248. $subpage = "";
  249. $button = $menu['module'];
  250. if (isset($_GET['m']) AND $_GET['m'] == $menu['module'] ) $menu_link_class = 'admin_menu_link_selected'; else $menu_link_class = 'admin_menu_link';
  251. }
  252. if($menu_link_class == 'admin_menu_link_selected' && isset($_GET['m']) && $_GET['m'] != 'user_admin')
  253. $TotalSelected = true;
  254. else if (isset($_GET['m']) && $_GET['m'] == 'user_admin')
  255. if(!isset($_GET['p']))
  256. $TotalSelected = true;
  257. else if($_GET['p'] != 'edit_user')
  258. $TotalSelected = true;
  259. $button_url = "?m=".$module.$subpage;
  260. if ( preg_match( '/\\_?\\_/', get_lang("$button") ) )
  261. {
  262. $button_name = $menu['menu_name'];
  263. }
  264. else
  265. {
  266. $button_name = get_lang("$button");
  267. }
  268. $data .= "<li><a class='".$menu_link_class."' href='".$button_url."'><span class='$button'>".$button_name."</span></a></li>\n";
  269. }
  270. ?>
  271. <li><a href="?m=administration&amp;p=main"
  272. <?php
  273. if ((isset($_GET['m']) AND $_GET['m'] == "administration") || $TotalSelected )
  274. echo 'class="admin_menu_link_selected"'; else echo 'class="admin_menu_link"';
  275. ?> target="_self" ><span class="administration" ><?php echo get_lang('administration'); ?></span></a>
  276. <ul id="administration" >
  277. <?php echo $data ?>
  278. </ul>
  279. </li>
  280. <?php
  281. }
  282. else
  283. $isSubUser = $db->isSubUser($_SESSION['user_id']);
  284. ?>
  285. <li>
  286. <a href="?m=user_admin&amp;p=edit_user&amp;user_id=<?php echo $_SESSION['user_id'] ?>"
  287. <?php if (isset($_GET['p']) AND $_GET['p'] == "edit_user" ) echo 'class="user_menu_link_selected"'; else echo 'class="user_menu_link"';
  288. ?> target="_self" ><span class="username" ><?php echo $_SESSION['users_login']; ?></span></a>
  289. <ul>
  290. <?php
  291. // Normal users only!
  292. if(!$isAdmin && !$isSubUser)
  293. {
  294. if($db->isModuleInstalled("subusers")){
  295. ?>
  296. <li><a href="?m=subusers&p=submanage"><span class="subusers"><?php print_lang('sub_users'); ?></span></a></li>
  297. <?php
  298. }
  299. ?>
  300. <li><a href="?m=user_admin&p=show_groups"><span class="groups"><?php print_lang('show_groups'); ?></span></a></li>
  301. <?php
  302. }
  303. ?>
  304. <li><a href="?logout"><span class="logout">[<?php print_lang('logout'); ?>]</span></a></li>
  305. </ul>
  306. </li>
  307. <?php
  308. // Custom Tabs
  309. if( isset($settings['custom_tab']) && $settings['custom_tab'] == "1" && isset($settings['custom_tab_name']) && $settings['custom_tab_name'] != "" )
  310. {
  311. echo "<li><a href='$settings[custom_tab_link]' target='$settings[custom_tab_target_blank]'><span class='customtab'>$settings[custom_tab_name]</span></a>";
  312. if( isset($settings['custom_tab_sub']) && $settings['custom_tab_sub'] == "1" )
  313. {
  314. echo '<ul>';
  315. for($i = 1; $i <= 4; $i++)
  316. {
  317. $num = $i == 1 ? "" : $i;
  318. if( isset($settings["custom_tab_sub_name$num"]) && $settings["custom_tab_sub_name$num"] != "" )
  319. {
  320. echo '<li><a href="'.$settings["custom_tab_sub_link$num"].'" target="'.
  321. $settings["custom_tab_target_blank"].'" ><span class="customtab">'.$settings["custom_tab_sub_name$num"].'</span></a></li>';
  322. }
  323. }
  324. echo '</ul>';
  325. }
  326. echo '</li>';
  327. }
  328. ?>
  329. </ul>
  330. </div>
  331. </div>
  332. <?php
  333. }
  334. ?>
  335. %topbody%
  336. <?php
  337. heading();
  338. ?>
  339. <div class="clear"></div>
  340. %botbody%
  341. %bottom%
  342. <?php
  343. }
  344. ?>