1
0

home.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 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. // Load languages.
  39. include_once("includes/lang.php");
  40. if (!$db instanceof OGPDatabase) {
  41. ogpLang();
  42. die(get_lang('no_db_connection'));
  43. }
  44. // Logged in user settings - access this global variable where needed
  45. if(hasValue($_SESSION['user_id'])){
  46. $loggedInUserInfo = $db->getUserById($_SESSION['user_id']);
  47. }
  48. $settings = $db->getSettings();
  49. @$GLOBALS['panel_language'] = $settings['panel_language'];
  50. ogpLang();
  51. require_once("includes/view.php");
  52. $view = new OGPView();
  53. $view->setCharset(get_lang('lang_charset'));
  54. $view->setTimeZone($settings['time_zone']);
  55. if(isset($_GET['type']) && $_GET['type'] == 'cleared')
  56. {
  57. if(isset($_GET['data_type'])){
  58. heading(true);
  59. $view->printView(true, $_GET['data_type']);
  60. }else{
  61. heading(true);
  62. $view->printView(true);
  63. }
  64. }
  65. else
  66. {
  67. ogpHome();
  68. $view->printView();
  69. }
  70. function heading()
  71. {
  72. global $db,$view,$settings;
  73. if ( !file_exists(CONFIG_FILE) )
  74. {
  75. print_failure(get_lang('failed_to_read_config'));
  76. $view->refresh("index.php");
  77. return;
  78. }
  79. // Start Output Buffering
  80. if (!isset($_SESSION['users_login']))
  81. {
  82. print_failure(get_lang('invalid_login_information'));
  83. echo "<p class='note' style='color:red;'>".get_lang('invalid_redirect')."...</p>";
  84. $view->refresh("index.php", 2);
  85. return;
  86. }
  87. else
  88. {
  89. $info = $db->getUserById($_SESSION['user_id']);
  90. if($info['user_expires'] != "X")
  91. {
  92. list($days,$strd,$hours,$strh,$minutes,$strm) = explode(" ", read_expire($info['user_expires']));
  93. $minutes2expire = $minutes + intval( $hours * 60 ) + intval( $days * 24 * 60 );
  94. if($minutes2expire <= 0)
  95. {
  96. echo "<h1>".get_lang('account_expired')."</h1>";
  97. echo "<p class='note'>".get_lang('contact_admin_to_enable_account')."</p>";
  98. session_destroy();
  99. return;
  100. }
  101. }
  102. if( isset($settings['maintenance_mode']) && $settings['maintenance_mode'] == "1" )
  103. {
  104. if ($_SESSION['users_group'] == "user")
  105. {
  106. echo "<h2>".$settings['maintenance_title']."</h2>";
  107. echo "<p>".$settings['maintenance_message']."</p>";
  108. $view->setTitle("OGP: Maintenance.");
  109. echo "<p class='failure'>".get_lang('logging_out_10')."...</p>";
  110. $view->refresh("index.php", 10);
  111. session_destroy();
  112. return;
  113. }
  114. }
  115. if ( isset($_REQUEST['logout']) )
  116. {
  117. session_destroy();
  118. print_success(get_lang('logout_message'));
  119. $view->refresh("index.php");
  120. return;
  121. }
  122. include "includes/navig.php";
  123. }
  124. if(isset($maintenance))echo $maintenance;
  125. }
  126. function ogpHome()
  127. {
  128. global $db,$view,$settings;
  129. ?>
  130. %top%
  131. <?php
  132. if(isset($_SESSION['user_id']))
  133. {
  134. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  135. if ( $isAdmin )
  136. $server_homes = $db->getHomesFor('admin', $_SESSION['user_id']);
  137. else
  138. $server_homes = $db->getHomesFor('user_and_group', $_SESSION['user_id']);
  139. if(!empty($server_homes))
  140. {
  141. $servers_by_game_name = array();
  142. foreach( $server_homes as $server_home )
  143. {
  144. if(isset($settings['check_expiry_by']) and $settings['check_expiry_by'] == "once_logged_in")
  145. {
  146. if($db->check_expire_date($_SESSION['user_id'], $server_home['home_id']))
  147. continue;
  148. }
  149. $servers_by_game_name["$server_home[game_name]"][] = $server_home;
  150. }
  151. ksort($servers_by_game_name);
  152. $game_homes_list = "<ul id='submenu_0' >\n";
  153. require_once("modules/config_games/server_config_parser.php");
  154. foreach( $servers_by_game_name as $game_name => $server_homes )
  155. {
  156. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$server_homes[0]['home_cfg_file']);
  157. $mod = $server_homes[0]['mod_key'];
  158. // If query name does not exist use mod key instead.
  159. if ($server_xml->protocol == "gameq")
  160. $query_name = $server_xml->gameq_query_name;
  161. elseif ($server_xml->protocol == "lgsl")
  162. $query_name = $server_xml->lgsl_query_name;
  163. elseif ($server_xml->protocol == "teamspeak3")
  164. $query_name = 'ts3';
  165. else
  166. $query_name = $mod;
  167. //----------+ getting the lgsl image icon
  168. $icon_paths = array("images/icons/$mod.png",
  169. "images/icons/$query_name.png",
  170. "protocol/lgsl/other/icon_unknown.gif");
  171. $icon_path = get_first_existing_file($icon_paths);
  172. $game_homes_list .= "<li>\n<a href='?m=gamemanager&p=game_monitor&home_cfg_id=".$server_homes[0]['home_cfg_id'].
  173. "'><span data-icon_path='$icon_path'>$game_name</span></a>\n<ul id='submenu_1' >\n";
  174. foreach($server_homes as $server_home)
  175. {
  176. $button_name = htmlentities($server_home['home_name']);
  177. if( ! preg_match("/none/i", $server_home['mod_name']) )
  178. $button_name .= " - ".$server_home['mod_name'];
  179. $game_homes_list .= "<li><a title='".$server_home['ip'].':'.$server_home['port'].
  180. "' class='user_menu_link' href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=".
  181. $server_home['home_id'].'-'.$server_home['mod_id'].'-'.$server_home['ip'].'-'.
  182. $server_home['port']."'>".$button_name."</a></li>\n";
  183. }
  184. $game_homes_list .= "</ul>\n</li>\n";
  185. }
  186. $game_homes_list .= "</ul>\n";
  187. }
  188. else
  189. $game_homes_list = "";
  190. ?>
  191. <div class="menu-bg">
  192. <div class="menu">
  193. <ul>
  194. <?php
  195. $menus = $db->getMenusForGroup('user');
  196. foreach ( $menus as $menu )
  197. {
  198. $module = $menu['module'];
  199. if ( !empty( $menu['subpage'] ) )
  200. {
  201. $subpage = "&amp;p=".$menu['subpage'];
  202. $button = $menu['subpage'];
  203. if (isset($_GET['p']) AND $_GET['p'] == $menu['subpage'] ) $menu_link_class = 'user_menu_link_selected'; else $menu_link_class = 'user_menu_link';
  204. }
  205. else
  206. {
  207. $subpage = "";
  208. $button = $menu['module'];
  209. if (isset($_GET['m']) AND $_GET['m'] == $menu['module'] ) $menu_link_class = 'user_menu_link_selected'; else $menu_link_class = 'user_menu_link';
  210. }
  211. $button_url = "?m=".$module.$subpage;
  212. if ( preg_match( '/\\_?\\_/', get_lang("$button") ) )
  213. {
  214. $button_name = $menu['menu_name'];
  215. }
  216. else
  217. {
  218. $button_name = get_lang("$button");
  219. }
  220. echo "<li><a class='".$menu_link_class."' href='".$button_url."'><span class='$button'>".$button_name."</span></a>";
  221. if( $menu['subpage'] == "game_monitor" )
  222. echo $game_homes_list;
  223. echo "</li>\n";
  224. }
  225. if($isAdmin)
  226. {
  227. $data = "";
  228. $TotalSelected = false;
  229. $menus = $db->getMenusForGroup('admin');
  230. foreach ($menus as $key => $row) {
  231. if ( !empty( $row['subpage'] ) )
  232. $name[$key] = $row['subpage'];
  233. else
  234. $name[$key] = $row['module'];
  235. $translation[$key] = get_lang($name[$key]);
  236. }
  237. array_multisort($translation, $name, SORT_DESC, $menus);
  238. foreach ( $menus as $menu )
  239. {
  240. $module = $menu['module'];
  241. if ( !empty( $menu['subpage'] ) )
  242. {
  243. $subpage = "&amp;p=".$menu['subpage'];
  244. $button = $menu['subpage'];
  245. if (isset($_GET['p']) AND $_GET['p'] == $menu['subpage'] ) $menu_link_class = 'admin_menu_link_selected'; else $menu_link_class = 'admin_menu_link';
  246. }
  247. else
  248. {
  249. $subpage = "";
  250. $button = $menu['module'];
  251. if (isset($_GET['m']) AND $_GET['m'] == $menu['module'] ) $menu_link_class = 'admin_menu_link_selected'; else $menu_link_class = 'admin_menu_link';
  252. }
  253. if($menu_link_class == 'admin_menu_link_selected' && isset($_GET['m']) && $_GET['m'] != 'user_admin')
  254. $TotalSelected = true;
  255. else if (isset($_GET['m']) && $_GET['m'] == 'user_admin')
  256. if(!isset($_GET['p']))
  257. $TotalSelected = true;
  258. else if($_GET['p'] != 'edit_user')
  259. $TotalSelected = true;
  260. $button_url = "?m=".$module.$subpage;
  261. if ( preg_match( '/\\_?\\_/', get_lang("$button") ) )
  262. {
  263. $button_name = $menu['menu_name'];
  264. }
  265. else
  266. {
  267. $button_name = get_lang("$button");
  268. }
  269. $data .= "<li><a class='".$menu_link_class."' href='".$button_url."'><span class='$button'>".$button_name."</span></a></li>\n";
  270. }
  271. ?>
  272. <li><a href="?m=administration&amp;p=main"
  273. <?php
  274. if ((isset($_GET['m']) AND $_GET['m'] == "administration") || $TotalSelected )
  275. echo 'class="admin_menu_link_selected"'; else echo 'class="admin_menu_link"';
  276. ?> target="_self" ><span class="administration" ><?php echo get_lang('administration'); ?></span></a>
  277. <ul id="administration" >
  278. <?php echo $data ?>
  279. </ul>
  280. </li>
  281. <?php
  282. }
  283. else
  284. $isSubUser = $db->isSubUser($_SESSION['user_id']);
  285. ?>
  286. <li>
  287. <a href="?m=user_admin&amp;p=edit_user&amp;user_id=<?php echo $_SESSION['user_id'] ?>"
  288. <?php if (isset($_GET['p']) AND $_GET['p'] == "edit_user" ) echo 'class="user_menu_link_selected"'; else echo 'class="user_menu_link"';
  289. ?> target="_self" ><span class="username" ><?php echo $_SESSION['users_login']; ?></span></a>
  290. <ul>
  291. <?php
  292. // Normal users only!
  293. if(!$isAdmin && !$isSubUser)
  294. {
  295. if($db->isModuleInstalled("subusers")){
  296. ?>
  297. <li><a href="?m=subusers&p=submanage"><span class="subusers"><?php print_lang('sub_users'); ?></span></a></li>
  298. <?php
  299. }
  300. ?>
  301. <li><a href="?m=user_admin&p=show_groups"><span class="groups"><?php print_lang('show_groups'); ?></span></a></li>
  302. <?php
  303. }
  304. ?>
  305. <li><a href="?logout"><span class="logout">[<?php print_lang('logout'); ?>]</span></a></li>
  306. </ul>
  307. </li>
  308. <?php
  309. // Custom Tabs
  310. if( isset($settings['custom_tab']) && $settings['custom_tab'] == "1" && isset($settings['custom_tab_name']) && $settings['custom_tab_name'] != "" )
  311. {
  312. echo "<li><a href='$settings[custom_tab_link]' target='$settings[custom_tab_target_blank]'><span class='customtab'>$settings[custom_tab_name]</span></a>";
  313. if( isset($settings['custom_tab_sub']) && $settings['custom_tab_sub'] == "1" )
  314. {
  315. echo '<ul>';
  316. for($i = 1; $i <= 4; $i++)
  317. {
  318. $num = $i == 1 ? "" : $i;
  319. if( isset($settings["custom_tab_sub_name$num"]) && $settings["custom_tab_sub_name$num"] != "" )
  320. {
  321. echo '<li><a href="'.$settings["custom_tab_sub_link$num"].'" target="'.
  322. $settings["custom_tab_target_blank"].'" ><span class="customtab">'.$settings["custom_tab_sub_name$num"].'</span></a></li>';
  323. }
  324. }
  325. echo '</ul>';
  326. }
  327. echo '</li>';
  328. }
  329. ?>
  330. </ul>
  331. </div>
  332. </div>
  333. <?php
  334. }
  335. ?>
  336. %topbody%
  337. <?php
  338. heading();
  339. ?>
  340. <div class="clear"></div>
  341. %botbody%
  342. %bottom%
  343. <?php
  344. }
  345. ?>