show_groups.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 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. function exec_ogp_module() {
  25. global $db, $loggedInUserInfo;
  26. $page_user = (isset($_GET['page']) && (int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1;
  27. $limit_user = (isset($_GET['limit']) && (int)$_GET['limit'] > 0) ? (int)$_GET['limit'] : 10;
  28. $search_field = (isset($_GET['search']) && !empty($_GET['search'])) ? $_GET['search'] : false;
  29. if(hasValue($loggedInUserInfo) && is_array($loggedInUserInfo) && $loggedInUserInfo["users_page_limit"] && !(isset($_GET['limit']) and !empty($_GET['limit']))){
  30. $limit_user = $loggedInUserInfo["users_page_limit"];
  31. }
  32. ?>
  33. <div class="center">
  34. <h2><?php print_lang('add_new_group'); ?></h2>
  35. <p><?php print_lang('info_group'); ?></p>
  36. <?php
  37. require_once('includes/form_table_class.php');
  38. $ft = new FormTable();
  39. $ft->start_form('?m=user_admin&amp;p=add_group');
  40. $ft->start_table();
  41. $ft->add_field('string','group_name','');
  42. $ft->end_table();
  43. $ft->add_button('submit','add_group',get_lang('add_group'));
  44. $ft->end_form();
  45. ?>
  46. </div>
  47. <?php
  48. echo '<h2>'.get_lang('available_groups').'</h2>';
  49. echo '<table style="width: 100%;">
  50. <tr>
  51. <td style="width: 50%; vertical-align: middle; text-align: right;">
  52. <form action="home.php" method="GET" style="float:right;">
  53. <input type ="hidden" name="m" value="user_admin" />
  54. <input type ="hidden" name="p" value="show_groups" />
  55. <input name="search" type="text" id="search" value="' . $search_field . '"/>
  56. <input type="submit" value="'.get_lang('search').'" />
  57. </form>
  58. </td>
  59. </tr>
  60. </table>';
  61. if ($db->isAdmin($_SESSION['user_id']))
  62. $result = $db->getGroupList_limit($page_user,$limit_user,$search_field);
  63. else
  64. $result = $db->getUserGroupList_limit($_SESSION['user_id'],$page_user,$limit_user,$search_field);
  65. if ( $result === FALSE )
  66. {
  67. echo "<p class='note'>".get_lang('no_groups_available')."</p>";
  68. return;
  69. }
  70. $i = 0;
  71. echo "<table class='center'><tr class='tr$i'><td>".
  72. get_lang('actions')."</td><td>".get_lang('group_name')."</td><td>".
  73. get_lang('users')."</td></tr>";
  74. foreach ( $result as $row ) #loop through the groups
  75. {
  76. $i++;
  77. echo "<tr class='tr$i'><td><a href='?m=user_games&amp;p=assign&amp;group_id=".$row['group_id']."'>[".
  78. get_lang('assign_homes')."]</a><br />
  79. <a href='?m=user_admin&amp;p=del_group&amp;group_id=".
  80. $row['group_id']."'>[".get_lang('delete_group').']</a>';
  81. echo "</td><td>".$row['group_name']."</td>";
  82. echo "<td class='left'>";
  83. $subusersEnabled = $db->isModuleInstalled("subusers");
  84. $subEnabled = false;
  85. if(!$subusersEnabled){
  86. $available_users = $db->getAvailableUsersForGroup($row['group_id']);
  87. }else{
  88. if(!$db->isAdmin($_SESSION['user_id'])){
  89. $available_users = $db->getAvailableSubUsersForGroup($row['group_id'], $_SESSION['user_id']);
  90. $subEnabled = true;
  91. }else{
  92. $available_users = $db->getAvailableUsersForGroup($row['group_id']);
  93. }
  94. }
  95. if ( is_array($available_users) )
  96. {
  97. if(count($available_users) > 0){
  98. echo "<form action=\"?m=user_admin&amp;p=add_to_group\" method=\"post\">".
  99. get_lang('add_user_to_group').
  100. ": <select name=\"user_to_add\">";
  101. foreach ($available_users as $user_row )
  102. {
  103. echo "<option value=\"" . $user_row['user_id'] . "\">" . htmlentities($user_row['users_login']) . "</option>";
  104. }
  105. echo "</select>\n";
  106. echo "<input type='hidden' name='group_id' value='" . $row['group_id'] . "' />";
  107. echo "<input type='submit' name='add_user_to_group' value='".get_lang('add_user')."' />";
  108. echo "</form>\n";
  109. }else{
  110. if($subEnabled){
  111. echo "<p>" .get_lang('no_subusers'). "</p>";
  112. }
  113. }
  114. }else{
  115. if($subEnabled){
  116. echo "<p>" .get_lang('no_subusers'). "</p>";
  117. }
  118. }
  119. $group_users = $db->listUsersInGroup($row['group_id']);
  120. if (is_array($group_users))
  121. {
  122. echo "<ul>";
  123. foreach ($group_users as $user_id)
  124. {
  125. $user_info = $db->getUserById($user_id['user_id']);
  126. echo "<li><a href='?m=user_admin&amp;p=del_from_group&amp;group_id=".
  127. $row['group_id']."&amp;user_id=".$user_id['user_id']."'>[".get_lang('remove_from_group').
  128. "]</a> " . $user_info['users_login'] . "</li>";
  129. }
  130. echo "</ul>";
  131. }
  132. echo "</td></tr>";
  133. }
  134. echo "</table>";
  135. if ($db->isAdmin($_SESSION['user_id']))
  136. $count_groups = $db->get_group_count($search_field);
  137. else
  138. $count_groups = $db->getUserGroupList_count($_SESSION['user_id'],$search_field);
  139. if(isset($_GET['search']) && !empty($_GET['search'])){
  140. $uri = '?m=user_admin&p=show_groups&search='.$_GET['search'].'&limit='.$limit_user.'&page=';
  141. }
  142. else{
  143. $uri = '?m=user_admin&p=show_groups&limit='.$limit_user.'&page=';
  144. }
  145. echo paginationPages($count_groups[0]['total'], $page_user, $limit_user, $uri, 3, 'userGroups');
  146. }
  147. ?>