1
0

assign_home.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <script type="text/javascript" src="js/modules/user_games-assign.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 create_selection($selection,$flag,$access_rights)
  26. {
  27. $right = "<tr><td align='right'><label for='".clean_id_string($selection)."'>".get_lang($selection).":</label></td>
  28. <td align='left'><input id='".clean_id_string($selection)."' type='checkbox' name='".$selection."' value='1' checked='checked' /></td></tr>
  29. <tr><td colspan='2' class='info'>".get_lang($selection.'_info')."</td></tr>";
  30. if (preg_match("/$flag/",$access_rights))
  31. return $right;
  32. }
  33. function exec_ogp_module()
  34. {
  35. global $db;
  36. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  37. if(isset($_REQUEST['user_id'])){
  38. if(empty($_REQUEST['user_id']) || $db->getUserById($_REQUEST['user_id']) == null)
  39. {
  40. print_failure(get_lang("valid_user"));
  41. return;
  42. }
  43. }else if(isset($_REQUEST['group_id'])){
  44. if(empty($_REQUEST['group_id']) || $db->getGroupById($_REQUEST['group_id']) == null)
  45. {
  46. print_failure(get_lang("valid_group"));
  47. return;
  48. }
  49. }else{
  50. print_failure(get_lang("invalid_url"));
  51. return;
  52. }
  53. if ( isset( $_REQUEST['user_id'] ) && !$isAdmin )
  54. {
  55. echo "<p class='note'>".get_lang("not_available")."</p>";
  56. return;
  57. }
  58. if ( isset( $_REQUEST['group_id'] ) && !$isAdmin )
  59. {
  60. $result = $db->getUserGroupList($_SESSION['user_id']);
  61. foreach ( $result as $row ) #loop through the groups
  62. {
  63. if ( $row['group_id'] == $_REQUEST['group_id'] )
  64. {
  65. $own_group = TRUE;
  66. }
  67. }
  68. }
  69. if( !$isAdmin && !isset($own_group) )
  70. {
  71. echo "<p class='note'>".get_lang("not_available")."</p>";
  72. return;
  73. }
  74. $selections = array();
  75. $full_access = '';
  76. foreach($db->getModulesAccessRights() as $ar)
  77. {
  78. $selections[$ar['description']] = $ar['flag'];
  79. $full_access .= $ar['flag'];
  80. }
  81. if(isset($_POST['change_access_rights']))
  82. {
  83. if(is_array($_POST['home_ids']))
  84. {
  85. if($isAdmin)
  86. $access_right_flags = implode('',$_POST['flags']);
  87. foreach($_POST['home_ids'] as $i => $home_id)
  88. {
  89. if(!$isAdmin)
  90. {
  91. $home_info = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  92. $access_rights = $home_info['access_rights'];
  93. $flags = $_POST['flags'];
  94. foreach($flags as $i => $flag)
  95. {
  96. if(!strstr($access_rights, $flag))
  97. unset($flags[$i]);
  98. }
  99. $access_right_flags = implode('',$flags);
  100. }
  101. if(!$db->updateAccessRightsFor($_POST['id_type'],$_POST['assign_id'],$home_id,$access_right_flags))
  102. print_failure(get_lang_f("failed_to_assign_game_for_",$id_type,$db->getError()));
  103. }
  104. }
  105. return;
  106. }
  107. if ( isset($_REQUEST['user_id']) )
  108. {
  109. $assign_id = $_REQUEST['user_id'];
  110. $id_type = "user";
  111. $user = $db->getUserById($assign_id);
  112. $assign_name = $user['users_login'];
  113. }
  114. else if ( isset($_REQUEST['group_id']) )
  115. {
  116. $assign_id = $_REQUEST['group_id'];
  117. $id_type = "group";
  118. $group = $db->getGroupById($assign_id);
  119. $assign_name = $group['group_name'];
  120. }
  121. $submit = isset($_POST['submit']) ? $_POST['submit'] : "";
  122. if( isset($_REQUEST['assign']) )
  123. {
  124. $access_rights = "";
  125. foreach ($selections as $selection => $flag)
  126. {
  127. if (isset($_REQUEST[$selection]))
  128. $access_rights .= $flag;
  129. }
  130. $hacker = FALSE;
  131. if( !$isAdmin )
  132. {
  133. $home_info = $db->getUserGameHome($_SESSION['user_id'],$_REQUEST['home_id']);
  134. if(!$home_info)
  135. {
  136. print_failure(get_lang_f("failed_to_assign_game_for",$id_type,"(Hacking attempt)"));
  137. $hacker = TRUE;
  138. }
  139. else
  140. {
  141. foreach ($selections as $selection => $flag)
  142. {
  143. if (isset($_REQUEST[$selection]))
  144. {
  145. if( !preg_match("/$flag/",$home_info['access_rights']) )
  146. {
  147. print_failure(get_lang_f("failed_to_assign_game_for",$id_type,"(Hacking attempt)"));
  148. $hacker = TRUE;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. if (!$hacker)
  155. {
  156. if ( $db->assignHomeTo($id_type,$assign_id,$_REQUEST['home_id'], $access_rights) === TRUE )
  157. {
  158. $db->updateExpirationDate($_REQUEST['home_id'], $_POST['expiration_date'], $id_type, $assign_id);
  159. print_success(get_lang_f("assigned_home_to_".$id_type,$_REQUEST['home_id'],$assign_name));
  160. $db->logger(get_lang_f("assigned_home_to_".$id_type,$_REQUEST['home_id'],$assign_name));
  161. }
  162. else
  163. {
  164. print_failure(get_lang_f("failed_to_assign_game_for_",$id_type,$db->getError()));
  165. }
  166. }
  167. unset($_POST['home_id']);
  168. }
  169. else if ( isset($_REQUEST['unassign']) )
  170. {
  171. if ( $db->unassignHomeFrom($id_type,$assign_id,$_REQUEST['home_id']) === TRUE )
  172. {
  173. print_success(get_lang_f("unassigned_home_from_".$id_type,$_REQUEST['home_id'],$assign_name));
  174. $db->logger(get_lang_f("unassigned_home_from_".$id_type,$_REQUEST['home_id'],$assign_name));
  175. }
  176. else
  177. {
  178. print_failure(get_lang_f("failed_to_assign_game_from_",$id_type));
  179. }
  180. }
  181. $remote_servers = $db->getRemoteServers();
  182. if ( empty($remote_servers) )
  183. {
  184. print_failure(get_lang("no_remote_servers_available_please_add_at_least_one"));
  185. echo "<p><a href='?m=server'>".get_lang("add_remote_server")."</a></p>";
  186. return;
  187. }
  188. if ( $isAdmin )
  189. $available_homes = $db->getAvailableHomesFor($id_type,$assign_id);
  190. else
  191. $available_homes = $db->getAvailableUserHomesFor($id_type,$assign_id,$_SESSION['user_id']);
  192. if ( !empty($available_homes) )
  193. {
  194. echo "<h2>".get_lang_f('assign_new_home_to_'.$id_type,$assign_name)."</h2>";
  195. echo "<form action='?m=user_games&amp;p=assign' method='post'>";
  196. echo "<input name='".$id_type."_id' value='".$assign_id."' type='hidden' />\n";
  197. echo "<table class='center'><tr><td align='right'><label for='home_id'>".get_lang("select_home").":</label></td>";
  198. echo '<td align="left"><select id="home_id" name="home_id" onchange="this.form.submit();">';
  199. echo "<option></option>\n";
  200. foreach ( $available_homes as $home )
  201. {
  202. if( isset($_POST['home_id']) && $_POST['home_id'] == $home['home_id'])
  203. $selected="selected='selected'";
  204. else
  205. $selected="";
  206. echo "<option value='".$home['home_id']."' $selected >".htmlentities($home['home_name'])."</option>\n";
  207. }
  208. echo "</select></td>\n";
  209. if( isset($_POST['home_id']) and !empty($_POST['home_id']) )
  210. {
  211. ?>
  212. <link rel="stylesheet" type="text/css" href="js/datetimepicker/jquery.datetimepicker.min.css">
  213. <script src="js/datetimepicker/jquery.datetimepicker.full.min.js"></script>
  214. <script type="text/javascript" src="js/modules/user_games.js"></script>
  215. <?php
  216. if( $isAdmin )
  217. {
  218. $access_rights = $full_access;
  219. }
  220. else
  221. {
  222. $home_info = $db->getUserGameHome($_SESSION['user_id'],$_POST['home_id']);
  223. $access_rights = $home_info['access_rights'];
  224. }
  225. foreach ( $selections as $selection => $flag)
  226. {
  227. echo create_selection($selection,$flag,$access_rights);
  228. }
  229. echo "<tr><td class='right'>".get_lang("assign_expiration_date").":</td>\n".
  230. "<td class='left'>\n".
  231. "<tr><td class='right'>".get_lang("server_expiration_date").":</td>\n".
  232. "<td class='left'>".
  233. "<div id='datetimepicker' class='input-append date'>".
  234. "<input name='expiration_date' placeholder='dd/MM/yyyy hh:mm:ss' type='text' value='X' data-today='".date('d/m/Y H:i:s')."' >\n".
  235. "</div></td></tr>\n".
  236. "<tr><td colspan='2' class='info'>". get_lang("assign_expiration_date_info") ."</td></tr>\n";
  237. echo "<tr><td colspan='2'><input type='submit' name='assign' value='".get_lang("assign")."' /></td></tr>\n";
  238. }
  239. echo "</table></form>\n";
  240. }
  241. else
  242. {
  243. echo "<h2>".get_lang("no_more_homes_available_that_can_be_assigned_for_this_$id_type")."</h2>";
  244. if( $isAdmin )
  245. echo get_lang_f("you_can_add_a_new_game_server_from","<a href='?m=user_games'>".get_lang("game_servers")."</a>")."</p>";
  246. }
  247. // View servers for use if there are any.
  248. $game_homes = $db->getHomesFor($id_type,$assign_id);
  249. if( empty($game_homes) )
  250. {
  251. echo "<h3>".get_lang_f("no_homes_assigned_to_".$id_type,$assign_name)."</h3>";
  252. }
  253. else
  254. {
  255. echo "<h2>".get_lang("assigned_homes")."</h2>";
  256. echo '<table class="center">';
  257. echo "<tr><th>".get_lang("home_id")."</th><th>".get_lang("game_server")."</th>
  258. <th>".get_lang("game_type")."</th>
  259. <th align='center'>".get_lang("game_home")."</th>
  260. <th>".get_lang("game_home_name")."</th><th>".get_lang("access_rights")."</th>
  261. <th>".get_lang("assign_expiration_date")."</th>
  262. <th>".get_lang("actions")."</th></tr>";
  263. foreach( $game_homes as $row )
  264. {
  265. $access_rights = empty($row['access_rights']) ? "-" : $row['access_rights'];
  266. $type = $id_type == "group" ? "user_group_expiration_date" : "user_expiration_date";
  267. $expiration = $row[$type] == "X" ? "X" : date('d/m/Y H:i:s', $row[$type]);
  268. echo "<tr><td><input type=checkbox class='change_access_rights' data-home_id='" . $row['home_id'] . "' >" . $row['home_id'] . "</td>
  269. <td>".$row['agent_ip']." (Agent)</td>
  270. <td>" . $row['game_name'] . "</td>
  271. <td>" . $row['home_path'] . "</td>
  272. <td>" . htmlentities($row["home_name"]) . "</td>
  273. <td>$access_rights</td>
  274. <td>$expiration</td>
  275. <td>
  276. <form action='?m=user_games&amp;p=assign' method='post'>
  277. <input name='".$id_type."_id' value='$assign_id' type='hidden' />
  278. <input name='home_id' value='".$row['home_id']."' type='hidden' />
  279. <input type='submit' name='unassign' value='".get_lang("unassign")."' /></form></td>
  280. </tr>";
  281. }
  282. echo "</table>";
  283. echo "<button id=\"change_access_rights_submit\" onclick=\"change_access_rights('".trim($id_type)."', '".trim($assign_id),"')\">".get_lang('change_access_rights_for_selected_servers')."</button>\n".
  284. "<div id='dialog' ";
  285. foreach ( $selections as $selection => $flag)
  286. {
  287. echo "data-$flag=\"$selection\" ";
  288. }
  289. echo "></div>";
  290. }
  291. if ( $id_type === "group" )
  292. echo create_back_button('user_admin','show_groups');
  293. else
  294. echo create_back_button('user_admin');
  295. }
  296. ?>