addons_manager.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <script type="text/javascript" src="js/modules/addonsmanager.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) 2008 - 2017 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. if( is_numeric($db->resultInsertId( 'addons', $fields )) )
  52. {
  53. print_success(get_lang_f("addon_has_been_created",$_POST['name']));
  54. if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['edit']))
  55. $db->query("DELETE FROM OGP_DB_PREFIXaddons WHERE addon_id=" . (int)$_POST['addon_id']);
  56. }
  57. }
  58. echo "<h2>".get_lang('addons_manager')."</h2>";
  59. $name = isset($_POST['name']) ? $_POST['name'] : "";
  60. $url = isset($_POST['url']) ? $_POST['url'] : "";
  61. $path = isset($_POST['path']) ? $_POST['path'] : "";
  62. $post_script = isset($_POST['post_script']) ? $_POST['post_script'] : "";
  63. $home_cfg_id = isset($_POST['home_cfg_id']) ? $_POST['home_cfg_id'] : "";
  64. $addon_type = isset($_POST['addon_type']) ? $_POST['addon_type'] : "";
  65. $addon_types = array('plugin', 'mappack', 'config');
  66. if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['edit']))
  67. {
  68. $addons_rows = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXaddons WHERE addon_id=".(int)$_POST['addon_id']);
  69. $addon_info = $addons_rows[0];
  70. $name = isset($addon_info['name']) ? $addon_info['name'] : "";
  71. $url = isset($addon_info['url']) ? $addon_info['url'] : "";
  72. $path = isset($addon_info['path']) ? $addon_info['path'] : "";
  73. $post_script = isset($addon_info['post_script']) ? $addon_info['post_script'] : "";
  74. $home_cfg_id = isset($addon_info['home_cfg_id']) ? $addon_info['home_cfg_id'] : "";
  75. $addon_type = isset($addon_info['addon_type']) ? $addon_info['addon_type'] : "";
  76. }
  77. ?>
  78. <form action="" method="post">
  79. <table class="center">
  80. <tr>
  81. <td align="right">
  82. <b><?php print_lang('addon_name'); ?></b>
  83. </td>
  84. <td align="left">
  85. <input type="text" value="<?php echo $name; ?>" name="name" size="85" title="<?php print_lang('addon_name_info'); ?>" />
  86. </td>
  87. </tr>
  88. <tr>
  89. <td align="right">
  90. <b><?php print_lang('url'); ?></b>
  91. </td>
  92. <td align="left">
  93. <input type="text" value="<?php echo $url; ?>" name="url" size="85" title="<?php print_lang('url_info'); ?>" />
  94. </td>
  95. </tr>
  96. <!-- If any, you can set the destination path, should be a relative path to the main game server folder. -->
  97. <tr>
  98. <td align="right">
  99. <b><?php print_lang('path'); ?></b>
  100. </td>
  101. <td align="left">
  102. <input type="text" value="<?php echo $path; ?>" name="path" size="85" title="<?php print_lang('path_info'); ?>" />
  103. </td>
  104. </tr>
  105. <tr>
  106. <td align="right">
  107. <b><?php print_lang('post-script'); ?></b><br>
  108. <u><?php print_lang('replacements'); ?></u><br>
  109. %home_path%<br>
  110. %home_name%<br>
  111. %control_password%<br>
  112. %max_players%<br>
  113. %ip%<br>
  114. %port%<br>
  115. %query_port%<br>
  116. %incremental%<br>
  117. </td>
  118. <td align="left">
  119. <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>
  120. </td>
  121. </tr>
  122. <tr>
  123. <td align="right">
  124. <b><?php print_lang('select_game_type'); ?></b>
  125. </td>
  126. <td align="left">
  127. <select name='home_cfg_id'>
  128. <?php
  129. $game_cfgs = $db->getGameCfgs();
  130. echo "<option style='background:black;color:white;' value=''>".get_lang('linux_games')."</option>\n";
  131. foreach ( $game_cfgs as $row )
  132. {
  133. if ( preg_match("/linux/", $row['game_key']) )
  134. {
  135. $selected = (isset($home_cfg_id) AND $row['home_cfg_id'] == $home_cfg_id) ? 'selected="selected"' : '';
  136. echo "<option $selected value='".$row['home_cfg_id']."'>".$row['game_name'];
  137. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  138. echo "</option>\n";
  139. }
  140. }
  141. echo "<option style='background:black;color:white;' value=''>".get_lang('windows_games')."</option>\n";
  142. foreach ( $game_cfgs as $row )
  143. {
  144. if ( preg_match("/win/", $row['game_key']) )
  145. {
  146. $selected = (isset($home_cfg_id) AND $row['home_cfg_id'] == $home_cfg_id) ? 'selected=selected' : '';
  147. echo "<option $selected value='".$row['home_cfg_id']."'>".$row['game_name'];
  148. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  149. echo "</option>\n";
  150. }
  151. }
  152. ?>
  153. </select>
  154. </td>
  155. </tr>
  156. <tr>
  157. <td align="right">
  158. <b><?php print_lang('type'); ?></b>
  159. </td>
  160. <td align="left">
  161. <?php
  162. $types = array( 'plugin', 'mappack', 'config' );
  163. foreach($types as $type)
  164. {
  165. $checked = ( isset($addon_type) AND $type == $addon_type) ? 'checked' : '';
  166. echo '<input type="radio" name="addon_type" value="'.$type.'" '.$checked.'>'.get_lang($type);
  167. }
  168. ?>
  169. </td>
  170. </tr>
  171. <tr>
  172. <td colspan="2" align="center">
  173. <?php
  174. if (isset($_POST['addon_id']) && isset($_POST['edit']))
  175. {
  176. echo '<input type="hidden" name="addon_id" value="'.$_POST['addon_id'].'" >';
  177. echo '<input type="hidden" name="edit" value="'.$_POST['edit'].'" >';
  178. ?>
  179. <button name="create_addon" type="submit">
  180. <?php print_lang('edit_addon'); ?>
  181. </button>
  182. <?php
  183. }
  184. else
  185. {
  186. ?>
  187. <button name="create_addon" type="submit">
  188. <?php print_lang('create_addon'); ?>
  189. </button>
  190. <?php
  191. }
  192. ?>
  193. </td>
  194. </tr>
  195. </table>
  196. </form>
  197. <br>
  198. <h2><?php print_lang('addons_db'); ?></h2>
  199. <table class="center">
  200. <tr>
  201. <td align="center">
  202. <form name="remove" action="" method="get">
  203. <input name="m" type="hidden" value="addonsmanager"/>
  204. <input name="p" type="hidden" value="addons_manager"/>
  205. <b><?php print_lang('game'); ?></b> <select name='home_cfg_id'>
  206. <?php
  207. echo "<option style='background:black;color:white;' value=''>".get_lang('linux_games')."</option>\n";
  208. foreach ( $game_cfgs as $row )
  209. {
  210. if ( preg_match("/linux/", $row['game_key']) )
  211. {
  212. if(isset($_GET['home_cfg_id']) AND $row['home_cfg_id'] == $_GET['home_cfg_id'])
  213. $selected = "selected='selected'";
  214. else
  215. $selected = "";
  216. echo "<option value='".$row['home_cfg_id']."' $selected >".$row['game_name'];
  217. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  218. echo "</option>\n";
  219. }
  220. }
  221. echo "<option style='background:black;color:white;' value=''>".get_lang('windows_games')."</option>\n";
  222. foreach ( $game_cfgs as $row )
  223. {
  224. if(isset($_GET['home_cfg_id']) AND $row['home_cfg_id'] == $_GET['home_cfg_id'])
  225. $selected = "selected='selected'";
  226. else
  227. $selected = "";
  228. if ( preg_match("/win/", $row['game_key']) )
  229. {
  230. echo "<option value='".$row['home_cfg_id']."' $selected >".$row['game_name'];
  231. if ( preg_match("/64/", $row['game_key']) ) echo " (64bit)";
  232. echo "</option>\n";
  233. }
  234. }
  235. ?>
  236. </select>
  237. <b><?php print_lang('type'); ?></b>
  238. <select name="addon_type">
  239. <?php
  240. $option = '';
  241. foreach ($addon_types as $k) {
  242. $option .= '<option';
  243. if (isset($_GET['addon_type']) && $_GET['addon_type'] == $k) {
  244. $option .= ' selected';
  245. }
  246. $option .= ' value="'. $k .'">'.get_lang($k).'</option>';
  247. }
  248. echo $option;
  249. ?>
  250. </select>
  251. <button name="show" type="submit">
  252. <?php print_lang('show'); ?>
  253. </button>
  254. </td>
  255. </tr>
  256. <tr>
  257. <td>
  258. <input name="show_game" type="submit" value="<?php print_lang('show_addons_for_selected_game'); ?>"/>
  259. <input name="show_type" type="submit" value="<?php print_lang('show_addons_for_selected_type'); ?>"/>
  260. <input name="show_all" type="submit" value="<?php print_lang('show_all_addons'); ?>"/>
  261. </td>
  262. </tr>
  263. </form>
  264. </table>
  265. <?php
  266. if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['remove']))
  267. {
  268. if (!$db->query("DELETE FROM OGP_DB_PREFIXaddons WHERE addon_id=" . (int)$_POST['addon_id']))
  269. print_lang('can_not_remove_addon');
  270. }
  271. $home_cfg_id = !empty($_GET['home_cfg_id']) && (int)$_GET['home_cfg_id'] > 0 ? (int)$_GET['home_cfg_id'] : 0;
  272. $addon_type = !empty($_GET['addon_type']) && in_array($_GET['addon_type'], $addon_types) ? $_GET['addon_type'] : "";
  273. if ( isset($_GET['show']) )
  274. {
  275. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE addon_type='".$addon_type."' AND home_cfg_id=".$home_cfg_id);
  276. }
  277. elseif ( isset($_GET['show_all']) )
  278. {
  279. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes");
  280. }
  281. elseif ( isset($_GET['show_type']))
  282. {
  283. unset($_GET['show_all']);
  284. unset($_GET['show_game']);
  285. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE addon_type='".$addon_type."'");
  286. }
  287. elseif ( isset($_GET['show_game']))
  288. {
  289. unset($_GET['show_all']);
  290. unset($_GET['show_type']);
  291. $result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE home_cfg_id=".$home_cfg_id);
  292. }
  293. ?>
  294. <table class="center">
  295. <?php
  296. if (isset($result) and $result > 0)
  297. {
  298. foreach($result as $row)
  299. {
  300. ?>
  301. <tr>
  302. <form action="" method="post">
  303. <td class='left'>
  304. <b><?php echo $row['game_name']; ?></b>
  305. </td>
  306. <td>
  307. <?php echo $row['name'];?>
  308. </td>
  309. <td>
  310. <input name="addon_id" type="hidden" value="<?php echo $row['addon_id'];?>"/>
  311. <input name="edit" type="submit" value="<?php print_lang('edit_addon'); ?>"/>
  312. <input name="remove" type="submit" value="<?php print_lang('remove_addon'); ?>"/>
  313. </td>
  314. </form>
  315. </tr>
  316. <?php
  317. }
  318. }
  319. ?>
  320. </table>
  321. <?php
  322. }
  323. ?>