addons_manager.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <script type="text/javascript" src="js/modules/addonsmanager.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) 2008 - 2018 The OGP Development Team
  7. *
  8. * http://www.opengamepanel.org/
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. *
  24. */
  25. function exec_ogp_module() {
  26. global $db;
  27. if (isset($_POST['create_addon']) AND isset($_POST['name']) AND $_POST['url']=="")
  28. {
  29. print_failure(get_lang("fill_the_url_address_to_a_compressed_file"));
  30. }
  31. elseif(isset($_POST['create_addon']) AND isset($_POST['url']) AND $_POST['name']=="")
  32. {
  33. print_failure(get_lang("fill_the_addon_name"));
  34. }
  35. elseif(isset($_POST['create_addon']) AND isset($_POST['name']) and isset($_POST['url']) and empty($_POST['addon_type']) )
  36. {
  37. print_failure(get_lang("select_an_addon_type"));
  38. }
  39. elseif(isset($_POST['create_addon']) AND isset($_POST['name']) and isset($_POST['url']) and isset($_POST['addon_type']) and empty($_POST['home_cfg_id']) )
  40. {
  41. print_failure(get_lang("select_a_game_type"));
  42. }
  43. elseif (isset($_POST['create_addon']) AND isset($_POST['name']) AND isset($_POST['url']) AND isset($_POST['addon_type']) and isset($_POST['home_cfg_id']) )
  44. {
  45. $fields['name'] = $_POST['name'];
  46. $fields['url'] = $_POST['url'];
  47. $fields['path'] = $_POST['path'];
  48. $fields['addon_type'] = $_POST['addon_type'];
  49. $fields['home_cfg_id'] = $_POST['home_cfg_id'];
  50. $fields['post_script'] = $_POST['post_script'];
  51. $fields['group_id'] = $_POST['group_id'];
  52. if( is_numeric($db->resultInsertId( 'addons', $fields )) )
  53. {
  54. print_success(get_lang_f("addon_has_been_created",$_POST['name']));
  55. if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['edit']))
  56. $db->query("DELETE FROM OGP_DB_PREFIXaddons WHERE addon_id=" . (int)$_POST['addon_id']);
  57. }
  58. }
  59. echo "<h2>".get_lang('addons_manager')."</h2>";
  60. $name = isset($_POST['name']) ? $_POST['name'] : "";
  61. $url = isset($_POST['url']) ? $_POST['url'] : "";
  62. $path = isset($_POST['path']) ? $_POST['path'] : "";
  63. $post_script = isset($_POST['post_script']) ? $_POST['post_script'] : "";
  64. $home_cfg_id = isset($_POST['home_cfg_id']) ? $_POST['home_cfg_id'] : "";
  65. $addon_type = isset($_POST['addon_type']) ? $_POST['addon_type'] : "";
  66. $group_id = isset($_POST['group_id']) ? $_POST['group_id'] : "";
  67. $addon_types = array('plugin', 'mappack', 'config');
  68. if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['edit']))
  69. {
  70. $addons_rows = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXaddons WHERE addon_id=".(int)$_POST['addon_id']);
  71. $addon_info = $addons_rows ? $addons_rows[0] : array();
  72. $name = isset($addon_info['name']) ? $addon_info['name'] : "";
  73. $url = isset($addon_info['url']) ? $addon_info['url'] : "";
  74. $path = isset($addon_info['path']) ? $addon_info['path'] : "";
  75. $post_script = isset($addon_info['post_script']) ? $addon_info['post_script'] : "";
  76. $home_cfg_id = isset($addon_info['home_cfg_id']) ? $addon_info['home_cfg_id'] : "";
  77. $addon_type = isset($addon_info['addon_type']) ? $addon_info['addon_type'] : "";
  78. $group_id = isset($addon_info['group_id']) ? $addon_info['group_id'] : "";
  79. }
  80. ?>
  81. <form action="" method="post">
  82. <table class="center">
  83. <tr>
  84. <td align="right">
  85. <b><?php print_lang('addon_name'); ?></b>
  86. </td>
  87. <td align="left">
  88. <input type="text" value="<?php echo $name; ?>" name="name" size="85" title="<?php print_lang('addon_name_info'); ?>" />
  89. </td>
  90. </tr>
  91. <tr>
  92. <td align="right">
  93. <b><?php print_lang('url'); ?></b>
  94. </td>
  95. <td align="left">
  96. <input type="text" value="<?php echo $url; ?>" name="url" size="85" title="<?php print_lang('url_info'); ?>" />
  97. </td>
  98. </tr>
  99. <!-- If any, you can set the destination path, should be a relative path to the main game server folder. -->
  100. <tr>
  101. <td align="right">
  102. <b><?php print_lang('path'); ?></b>
  103. </td>
  104. <td align="left">
  105. <input type="text" value="<?php echo $path; ?>" name="path" size="85" title="<?php print_lang('path_info'); ?>" />
  106. </td>
  107. </tr>
  108. <tr>
  109. <td align="right">
  110. <b><?php print_lang('post-script'); ?></b><br>
  111. <u><?php print_lang('replacements'); ?></u><br>
  112. %home_path%<br>
  113. %home_name%<br>
  114. %control_password%<br>
  115. %max_players%<br>
  116. %ip%<br>
  117. %port%<br>
  118. %query_port%<br>
  119. %incremental%<br>
  120. </td>
  121. <td align="left">
  122. <textarea name="post_script" style="width:99%;height:175px;" title="<?php print_lang('post-script_info'); ?>" ><?php echo strip_real_escape_string($post_script); ?></textarea>
  123. </td>
  124. </tr>
  125. <tr>
  126. <td align="right">
  127. <b><?php print_lang('select_game_type'); ?></b>
  128. </td>
  129. <td align="left">
  130. <select name='home_cfg_id'>
  131. <?php
  132. $game_cfgs = $db->getGameCfgs();
  133. echo "<option style='background:black;color:white;' value=''>".get_lang('linux_games')."</option>\n";
  134. foreach ( $game_cfgs as $row )
  135. {
  136. if ( preg_match("/linux/", $row['game_key']) )
  137. {
  138. $selected = (isset($home_cfg_id) AND $row['home_cfg_id'] == $home_cfg_id) ? 'selected="selected"' : '';
  139. echo "<option $selected value='".$row['home_cfg_id']."'>".$row['game_name'];
  140. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  141. echo "</option>\n";
  142. }
  143. }
  144. echo "<option style='background:black;color:white;' value=''>".get_lang('windows_games')."</option>\n";
  145. foreach ( $game_cfgs as $row )
  146. {
  147. if ( preg_match("/win/", $row['game_key']) )
  148. {
  149. $selected = (isset($home_cfg_id) AND $row['home_cfg_id'] == $home_cfg_id) ? 'selected=selected' : '';
  150. echo "<option $selected value='".$row['home_cfg_id']."'>".$row['game_name'];
  151. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  152. echo "</option>\n";
  153. }
  154. }
  155. ?>
  156. </select>
  157. </td>
  158. </tr>
  159. <tr>
  160. <td align="right">
  161. <b><?php print_lang('type'); ?></b>
  162. </td>
  163. <td align="left">
  164. <?php
  165. $types = array( 'plugin', 'mappack', 'config' );
  166. foreach($types as $type)
  167. {
  168. $checked = ( isset($addon_type) AND $type == $addon_type) ? 'checked' : '';
  169. echo '<input type="radio" name="addon_type" value="'.$type.'" '.$checked.'>'.get_lang($type);
  170. }
  171. ?>
  172. </td>
  173. </tr>
  174. <tr>
  175. <td align="right">
  176. <b><?php print_lang('show_to_group'); ?></b>
  177. </td>
  178. <td align="left">
  179. <select name='group_id'>
  180. <option value="0"><?php print_lang('all_groups'); ?></option>
  181. <?php
  182. $groups = $db->getGroupList();
  183. foreach($groups as $group)
  184. {
  185. $selected = (isset($group_id) AND $group['group_id'] == $group_id) ? 'selected=selected' : '';
  186. echo "<option value='".$group['group_id']."' $selected>".$group['group_name']."</option>\n";
  187. }
  188. ?>
  189. </select>
  190. </td>
  191. </tr>
  192. <tr>
  193. <td colspan="2" align="center">
  194. <?php
  195. if (isset($_POST['addon_id']) && isset($_POST['edit']))
  196. {
  197. echo '<input type="hidden" name="addon_id" value="'.$_POST['addon_id'].'" >';
  198. echo '<input type="hidden" name="edit" value="'.$_POST['edit'].'" >';
  199. ?>
  200. <button name="create_addon" type="submit">
  201. <?php print_lang('edit_addon'); ?>
  202. </button>
  203. <?php
  204. }
  205. else
  206. {
  207. ?>
  208. <button name="create_addon" type="submit">
  209. <?php print_lang('create_addon'); ?>
  210. </button>
  211. <?php
  212. }
  213. ?>
  214. </td>
  215. </tr>
  216. </table>
  217. </form>
  218. <br>
  219. <h2><?php print_lang('addons_db'); ?></h2>
  220. <table class="center">
  221. <tr>
  222. <td align="center">
  223. <form name="remove" action="" method="get">
  224. <input name="m" type="hidden" value="addonsmanager"/>
  225. <input name="p" type="hidden" value="addons_manager"/>
  226. <b><?php print_lang('game'); ?></b> <select name='home_cfg_id'>
  227. <?php
  228. echo "<option style='background:black;color:white;' value=''>".get_lang('linux_games')."</option>\n";
  229. foreach ( $game_cfgs as $row )
  230. {
  231. if ( preg_match("/linux/", $row['game_key']) )
  232. {
  233. if(isset($_GET['home_cfg_id']) AND $row['home_cfg_id'] == $_GET['home_cfg_id'])
  234. $selected = "selected='selected'";
  235. else
  236. $selected = "";
  237. echo "<option value='".$row['home_cfg_id']."' $selected >".$row['game_name'];
  238. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  239. echo "</option>\n";
  240. }
  241. }
  242. echo "<option style='background:black;color:white;' value=''>".get_lang('windows_games')."</option>\n";
  243. foreach ( $game_cfgs as $row )
  244. {
  245. if(isset($_GET['home_cfg_id']) AND $row['home_cfg_id'] == $_GET['home_cfg_id'])
  246. $selected = "selected='selected'";
  247. else
  248. $selected = "";
  249. if ( preg_match("/win/", $row['game_key']) )
  250. {
  251. echo "<option value='".$row['home_cfg_id']."' $selected >".$row['game_name'];
  252. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  253. echo "</option>\n";
  254. }
  255. }
  256. ?>
  257. </select>
  258. <b><?php print_lang('type'); ?></b>
  259. <select name="addon_type">
  260. <?php
  261. $option = '';
  262. foreach ($addon_types as $k) {
  263. $option .= '<option';
  264. if (isset($_GET['addon_type']) && $_GET['addon_type'] == $k) {
  265. $option .= ' selected';
  266. }
  267. $option .= ' value="'. $k .'">'.get_lang($k).'</option>';
  268. }
  269. echo $option;
  270. ?>
  271. </select>
  272. <b><?php print_lang('group'); ?></b>
  273. <select name='group_id'>
  274. <option value="0"><?php print_lang('all_groups'); ?></option>
  275. <?php
  276. foreach($groups as $group)
  277. {
  278. $selected = (isset($_GET['group_id']) AND $group['group_id'] == $_GET['group_id']) ? 'selected=selected' : '';
  279. echo "<option value='".$group['group_id']."' $selected>".$group['group_name']."</option>\n";
  280. }
  281. ?>
  282. </select>
  283. <button name="show" type="submit">
  284. <?php print_lang('show'); ?>
  285. </button>
  286. </td>
  287. </tr>
  288. <tr>
  289. <td>
  290. <input name="show_game" type="submit" value="<?php print_lang('show_addons_for_selected_game'); ?>"/>
  291. <input name="show_type" type="submit" value="<?php print_lang('show_addons_for_selected_type'); ?>"/>
  292. <input name="show_group" type="submit" value="<?php print_lang('show_addons_for_selected_group'); ?>"/>
  293. <input name="show_all" type="submit" value="<?php print_lang('show_all_addons'); ?>"/>
  294. </td>
  295. </tr>
  296. </form>
  297. </table>
  298. <?php
  299. if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['remove']))
  300. {
  301. if (!$db->query("DELETE FROM OGP_DB_PREFIXaddons WHERE addon_id=" . (int)$_POST['addon_id']))
  302. print_lang('can_not_remove_addon');
  303. }
  304. $home_cfg_id = !empty($_GET['home_cfg_id']) && (int)$_GET['home_cfg_id'] > 0 ? (int)$_GET['home_cfg_id'] : 0;
  305. $addon_type = !empty($_GET['addon_type']) && in_array($_GET['addon_type'], $addon_types) ? $_GET['addon_type'] : "";
  306. $group_id = isset($_GET['group_id']) && is_numeric($_GET['group_id']) ? (int)$_GET['group_id'] : 0;
  307. if ( isset($_GET['show']) )
  308. {
  309. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path, group_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE addon_type='".$addon_type."' AND home_cfg_id=".$home_cfg_id);
  310. }
  311. elseif ( isset($_GET['show_all']) )
  312. {
  313. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path, group_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes");
  314. }
  315. elseif ( isset($_GET['show_type']))
  316. {
  317. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path, group_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE addon_type='".$addon_type."'");
  318. }
  319. elseif ( isset($_GET['show_game']))
  320. {
  321. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path, group_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE home_cfg_id=".$home_cfg_id);
  322. }
  323. elseif ( isset($_GET['show_group']))
  324. {
  325. $group_id = $group_id == '0' ? $group_id." OR group_id IS NULL" : $group_id;
  326. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path, group_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE group_id=".$group_id);
  327. }
  328. ?>
  329. <table class="center">
  330. <?php
  331. $group_names = array();
  332. if(is_array($groups))
  333. {
  334. foreach($groups as $group)
  335. $group_names[$group['group_id']] = $group['group_name'];
  336. }
  337. if (isset($result) && $result && count($result) > 0)
  338. {
  339. foreach($result as $row)
  340. {
  341. ?>
  342. <tr>
  343. <form action="" method="post">
  344. <td class='left'>
  345. <b><?php echo $row['game_name']; ?></b>
  346. </td>
  347. <td>
  348. <?php echo $row['name'];?>
  349. </td>
  350. <td>
  351. <?php echo "[".get_lang('group').": ". (isset($group_names[$row['group_id']])?$group_names[$row['group_id']]:get_lang('all_groups')) ."]";?>
  352. </td>
  353. <td>
  354. <input name="addon_id" type="hidden" value="<?php echo $row['addon_id'];?>"/>
  355. <input name="edit" type="submit" value="<?php print_lang('edit_addon'); ?>"/>
  356. <input name="remove" type="submit" value="<?php print_lang('remove_addon'); ?>"/>
  357. </td>
  358. </form>
  359. </tr>
  360. <?php
  361. }
  362. }
  363. ?>
  364. </table>
  365. <?php
  366. }
  367. ?>