PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/admin_groups.php

https://github.com/Dratone/EveBB
PHP | 568 lines | 473 code | 74 blank | 21 comment | 134 complexity | 2dd3c0888408fb949a668d7c5cd6b55b MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2010 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. // Tell header.php to use the admin template
  8. define('PUN_ADMIN_CONSOLE', 1);
  9. define('PUN_ROOT', dirname(__FILE__).'/');
  10. require PUN_ROOT.'include/common.php';
  11. require PUN_ROOT.'include/common_admin.php';
  12. if ($pun_user['g_id'] != PUN_ADMIN)
  13. message($lang_common['No permission']);
  14. // Load the admin_censoring.php language file
  15. require PUN_ROOT.'lang/'.$admin_language.'/admin_groups.php';
  16. // Add/edit a group (stage 1)
  17. if (isset($_POST['add_group']) || isset($_GET['edit_group']))
  18. {
  19. if (isset($_POST['add_group']))
  20. {
  21. $base_group = intval($_POST['base_group']);
  22. $result = $db->query('SELECT * FROM '.$db->prefix.'groups WHERE g_id='.$base_group) or error('Unable to fetch user group info', __FILE__, __LINE__, $db->error());
  23. $group = $db->fetch_assoc($result);
  24. $mode = 'add';
  25. }
  26. else // We are editing a group
  27. {
  28. $group_id = intval($_GET['edit_group']);
  29. if ($group_id < 1)
  30. message($lang_common['Bad request']);
  31. $result = $db->query('SELECT * FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch user group info', __FILE__, __LINE__, $db->error());
  32. if (!$db->num_rows($result))
  33. message($lang_common['Bad request']);
  34. $group = $db->fetch_assoc($result);
  35. $mode = 'edit';
  36. }
  37. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
  38. $required_fields = array('req_title' => $lang_admin_groups['Group title label']);
  39. $focus_element = array('groups2', 'req_title');
  40. define('PUN_ACTIVE_PAGE', 'admin');
  41. require PUN_ROOT.'header.php';
  42. generate_admin_menu('groups');
  43. ?>
  44. <div class="blockform">
  45. <h2><span><?php echo $lang_admin_groups['Group settings head'] ?></span></h2>
  46. <div class="box">
  47. <form id="groups2" method="post" action="admin_groups.php" onsubmit="return process_form(this)">
  48. <p class="submittop"><input type="submit" name="add_edit_group" value="<?php echo $lang_admin_common['Save'] ?>" /></p>
  49. <div class="inform">
  50. <input type="hidden" name="mode" value="<?php echo $mode ?>" />
  51. <?php if ($mode == 'edit'): ?> <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
  52. <?php endif; ?><?php if ($mode == 'add'): ?> <input type="hidden" name="base_group" value="<?php echo $base_group ?>" />
  53. <?php endif; ?> <fieldset>
  54. <legend><?php echo $lang_admin_groups['Group settings subhead'] ?></legend>
  55. <div class="infldset">
  56. <p><?php echo $lang_admin_groups['Group settings info'] ?></p>
  57. <table class="aligntop" cellspacing="0">
  58. <tr>
  59. <th scope="row"><?php echo $lang_admin_groups['Group title label'] ?></th>
  60. <td>
  61. <input type="text" name="req_title" size="25" maxlength="50" value="<?php if ($mode == 'edit') echo pun_htmlspecialchars($group['g_title']); ?>" tabindex="1" />
  62. </td>
  63. </tr>
  64. <tr>
  65. <th scope="row"><?php echo $lang_admin_groups['User title label'] ?></th>
  66. <td>
  67. <input type="text" name="user_title" size="25" maxlength="50" value="<?php echo pun_htmlspecialchars($group['g_user_title']) ?>" tabindex="2" />
  68. <span><?php echo $lang_admin_groups['User title help'] ?></span>
  69. </td>
  70. </tr>
  71. <?php if ($group['g_id'] != PUN_ADMIN): if ($group['g_id'] != PUN_GUEST): if ($mode != 'edit' || $pun_config['o_default_user_group'] != $group['g_id']): ?> <tr>
  72. <th scope="row"> <?php echo $lang_admin_groups['Mod privileges label'] ?></th>
  73. <td>
  74. <input type="radio" name="moderator" value="1"<?php if ($group['g_moderator'] == '1') echo ' checked="checked"' ?> tabindex="3" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="moderator" value="0"<?php if ($group['g_moderator'] == '0') echo ' checked="checked"' ?> tabindex="4" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  75. <span><?php echo $lang_admin_groups['Mod privileges help'] ?></span>
  76. </td>
  77. </tr>
  78. <tr>
  79. <th scope="row"><?php echo $lang_admin_groups['Edit profile label'] ?></th>
  80. <td>
  81. <input type="radio" name="mod_edit_users" value="1"<?php if ($group['g_mod_edit_users'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_edit_users" value="0"<?php if ($group['g_mod_edit_users'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  82. <span><?php echo $lang_admin_groups['Edit profile help'] ?></span>
  83. </td>
  84. </tr>
  85. <tr>
  86. <th scope="row"><?php echo $lang_admin_groups['Rename users label'] ?></th>
  87. <td>
  88. <input type="radio" name="mod_rename_users" value="1"<?php if ($group['g_mod_rename_users'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_rename_users" value="0"<?php if ($group['g_mod_rename_users'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  89. <span><?php echo $lang_admin_groups['Rename users help'] ?></span>
  90. </td>
  91. </tr>
  92. <tr>
  93. <th scope="row"><?php echo $lang_admin_groups['Change passwords label'] ?></th>
  94. <td>
  95. <input type="radio" name="mod_change_passwords" value="1"<?php if ($group['g_mod_change_passwords'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_change_passwords" value="0"<?php if ($group['g_mod_change_passwords'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  96. <span><?php echo $lang_admin_groups['Change passwords help'] ?></span>
  97. </td>
  98. </tr>
  99. <tr>
  100. <th scope="row"><?php echo $lang_admin_groups['Ban users label'] ?></th>
  101. <td>
  102. <input type="radio" name="mod_ban_users" value="1"<?php if ($group['g_mod_ban_users'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_ban_users" value="0"<?php if ($group['g_mod_ban_users'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  103. <span><?php echo $lang_admin_groups['Ban users help'] ?></span>
  104. </td>
  105. </tr>
  106. <?php endif; endif; ?> <tr>
  107. <th scope="row"><?php echo $lang_admin_groups['Read board label'] ?></th>
  108. <td>
  109. <input type="radio" name="read_board" value="1"<?php if ($group['g_read_board'] == '1') echo ' checked="checked"' ?> tabindex="3" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="read_board" value="0"<?php if ($group['g_read_board'] == '0') echo ' checked="checked"' ?> tabindex="4" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  110. <span><?php echo $lang_admin_groups['Read board help'] ?></span>
  111. </td>
  112. </tr>
  113. <tr>
  114. <th scope="row"><?php echo $lang_admin_groups['View user info label'] ?></th>
  115. <td>
  116. <input type="radio" name="view_users" value="1"<?php if ($group['g_view_users'] == '1') echo ' checked="checked"' ?> tabindex="3" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="view_users" value="0"<?php if ($group['g_view_users'] == '0') echo ' checked="checked"' ?> tabindex="4" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  117. <span><?php echo $lang_admin_groups['View user info help'] ?></span>
  118. </td>
  119. </tr>
  120. <tr>
  121. <th scope="row"><?php echo $lang_admin_groups['Post replies label'] ?></th>
  122. <td>
  123. <input type="radio" name="post_replies" value="1"<?php if ($group['g_post_replies'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="post_replies" value="0"<?php if ($group['g_post_replies'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  124. <span><?php echo $lang_admin_groups['Post replies help'] ?></span>
  125. </td>
  126. </tr>
  127. <tr>
  128. <th scope="row"><?php echo $lang_admin_groups['Post topics label'] ?></th>
  129. <td>
  130. <input type="radio" name="post_topics" value="1"<?php if ($group['g_post_topics'] == '1') echo ' checked="checked"' ?> tabindex="7" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="post_topics" value="0"<?php if ($group['g_post_topics'] == '0') echo ' checked="checked"' ?> tabindex="8" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  131. <span><?php echo $lang_admin_groups['Post topics help'] ?></span>
  132. </td>
  133. </tr>
  134. <?php if ($group['g_id'] != PUN_GUEST): ?> <tr>
  135. <th scope="row"><?php echo $lang_admin_groups['Edit posts label'] ?></th>
  136. <td>
  137. <input type="radio" name="edit_posts" value="1"<?php if ($group['g_edit_posts'] == '1') echo ' checked="checked"' ?> tabindex="11" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="edit_posts" value="0"<?php if ($group['g_edit_posts'] == '0') echo ' checked="checked"' ?> tabindex="12" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  138. <span><?php echo $lang_admin_groups['Edit posts help'] ?></span>
  139. </td>
  140. </tr>
  141. <tr>
  142. <th scope="row"><?php echo $lang_admin_groups['Delete posts label'] ?></th>
  143. <td>
  144. <input type="radio" name="delete_posts" value="1"<?php if ($group['g_delete_posts'] == '1') echo ' checked="checked"' ?> tabindex="13" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="delete_posts" value="0"<?php if ($group['g_delete_posts'] == '0') echo ' checked="checked"' ?> tabindex="14" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  145. <span><?php echo $lang_admin_groups['Delete posts help'] ?></span>
  146. </td>
  147. </tr>
  148. <tr>
  149. <th scope="row"><?php echo $lang_admin_groups['Delete topics label'] ?></th>
  150. <td>
  151. <input type="radio" name="delete_topics" value="1"<?php if ($group['g_delete_topics'] == '1') echo ' checked="checked"' ?> tabindex="15" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="delete_topics" value="0"<?php if ($group['g_delete_topics'] == '0') echo ' checked="checked"' ?> tabindex="16" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  152. <span><?php echo $lang_admin_groups['Delete topics help'] ?></span>
  153. </td>
  154. </tr>
  155. <tr>
  156. <th scope="row"><?php echo $lang_admin_groups['Set own title label'] ?></th>
  157. <td>
  158. <input type="radio" name="set_title" value="1"<?php if ($group['g_set_title'] == '1') echo ' checked="checked"' ?> tabindex="17" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="set_title" value="0"<?php if ($group['g_set_title'] == '0') echo ' checked="checked"' ?> tabindex="18" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  159. <span><?php echo $lang_admin_groups['Set own title help'] ?></span>
  160. </td>
  161. </tr>
  162. <?php endif; ?> <tr>
  163. <th scope="row"><?php echo $lang_admin_groups['User search label'] ?></th>
  164. <td>
  165. <input type="radio" name="search" value="1"<?php if ($group['g_search'] == '1') echo ' checked="checked"' ?> tabindex="19" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="search" value="0"<?php if ($group['g_search'] == '0') echo ' checked="checked"' ?> tabindex="20" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  166. <span><?php echo $lang_admin_groups['User search help'] ?></span>
  167. </td>
  168. </tr>
  169. <tr>
  170. <th scope="row"><?php echo $lang_admin_groups['User list search label'] ?></th>
  171. <td>
  172. <input type="radio" name="search_users" value="1"<?php if ($group['g_search_users'] == '1') echo ' checked="checked"' ?> tabindex="21" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="search_users" value="0"<?php if ($group['g_search_users'] == '0') echo ' checked="checked"' ?> tabindex="22" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  173. <span><?php echo $lang_admin_groups['User list search help'] ?></span>
  174. </td>
  175. </tr>
  176. <?php if ($group['g_id'] != PUN_GUEST): ?> <tr>
  177. <th scope="row"><?php echo $lang_admin_groups['Send e-mails label'] ?></th>
  178. <td>
  179. <input type="radio" name="send_email" value="1"<?php if ($group['g_send_email'] == '1') echo ' checked="checked"' ?> tabindex="21" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="send_email" value="0"<?php if ($group['g_send_email'] == '0') echo ' checked="checked"' ?> tabindex="22" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  180. <span><?php echo $lang_admin_groups['Send e-mails help'] ?></span>
  181. </td>
  182. </tr>
  183. <?php endif; ?> <tr>
  184. <th scope="row"><?php echo $lang_admin_groups['Post flood label'] ?></th>
  185. <td>
  186. <input type="text" name="post_flood" size="5" maxlength="4" value="<?php echo $group['g_post_flood'] ?>" tabindex="24" />
  187. <span><?php echo $lang_admin_groups['Post flood help'] ?></span>
  188. </td>
  189. </tr>
  190. <tr>
  191. <th scope="row"><?php echo $lang_admin_groups['Search flood label'] ?></th>
  192. <td>
  193. <input type="text" name="search_flood" size="5" maxlength="4" value="<?php echo $group['g_search_flood'] ?>" tabindex="25" />
  194. <span><?php echo $lang_admin_groups['Search flood help'] ?></span>
  195. </td>
  196. </tr>
  197. <?php if ($group['g_id'] != PUN_GUEST): ?> <tr>
  198. <th scope="row"><?php echo $lang_admin_groups['E-mail flood label'] ?></th>
  199. <td>
  200. <input type="text" name="email_flood" size="5" maxlength="4" value="<?php echo $group['g_email_flood'] ?>" tabindex="26" />
  201. <span><?php echo $lang_admin_groups['E-mail flood help'] ?></span>
  202. </td>
  203. </tr>
  204. <tr>
  205. <th scope="row"><?php echo $lang_admin_groups['group_locked_label'] ?></th>
  206. <td>
  207. <input type="radio" name="group_locked" value="1"<?php if ($group['g_locked'] == '1') echo ' checked="checked"' ?> tabindex="21" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="group_locked" value="0"<?php if ($group['g_locked'] == '0') echo ' checked="checked"' ?> tabindex="26" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  208. <span><?php echo $lang_admin_groups['group_locked_info'] ?></span>
  209. </td>
  210. </tr>
  211. <?php endif; endif; ?> </table>
  212. <?php if ($group['g_moderator'] == '1' ): ?> <p class="warntext"><?php echo $lang_admin_groups['Moderator info'] ?></p>
  213. <?php endif; ?> </div>
  214. </fieldset>
  215. </div>
  216. <p class="submitend"><input type="submit" name="add_edit_group" value="<?php echo $lang_admin_common['Save'] ?>" tabindex="27" /></p>
  217. </form>
  218. </div>
  219. </div>
  220. <div class="clearer"></div>
  221. </div>
  222. <?php
  223. require PUN_ROOT.'footer.php';
  224. }
  225. // Add/edit a group (stage 2)
  226. else if (isset($_POST['add_edit_group']))
  227. {
  228. confirm_referrer('admin_groups.php');
  229. // Is this the admin group? (special rules apply)
  230. $is_admin_group = (isset($_POST['group_id']) && $_POST['group_id'] == PUN_ADMIN) ? true : false;
  231. $title = pun_trim($_POST['req_title']);
  232. $user_title = pun_trim($_POST['user_title']);
  233. $moderator = isset($_POST['moderator']) && $_POST['moderator'] == '1' ? '1' : '0';
  234. $mod_edit_users = $moderator == '1' && isset($_POST['mod_edit_users']) && $_POST['mod_edit_users'] == '1' ? '1' : '0';
  235. $mod_rename_users = $moderator == '1' && isset($_POST['mod_rename_users']) && $_POST['mod_rename_users'] == '1' ? '1' : '0';
  236. $mod_change_passwords = $moderator == '1' && isset($_POST['mod_change_passwords']) && $_POST['mod_change_passwords'] == '1' ? '1' : '0';
  237. $mod_ban_users = $moderator == '1' && isset($_POST['mod_ban_users']) && $_POST['mod_ban_users'] == '1' ? '1' : '0';
  238. $read_board = isset($_POST['read_board']) ? intval($_POST['read_board']) : '1';
  239. $view_users = (isset($_POST['view_users']) && $_POST['view_users'] == '1') || $is_admin_group ? '1' : '0';
  240. $post_replies = isset($_POST['post_replies']) ? intval($_POST['post_replies']) : '1';
  241. $post_topics = isset($_POST['post_topics']) ? intval($_POST['post_topics']) : '1';
  242. $edit_posts = isset($_POST['edit_posts']) ? intval($_POST['edit_posts']) : ($is_admin_group) ? '1' : '0';
  243. $delete_posts = isset($_POST['delete_posts']) ? intval($_POST['delete_posts']) : ($is_admin_group) ? '1' : '0';
  244. $delete_topics = isset($_POST['delete_topics']) ? intval($_POST['delete_topics']) : ($is_admin_group) ? '1' : '0';
  245. $set_title = isset($_POST['set_title']) ? intval($_POST['set_title']) : ($is_admin_group) ? '1' : '0';
  246. $search = isset($_POST['search']) ? intval($_POST['search']) : '1';
  247. $search_users = isset($_POST['search_users']) ? intval($_POST['search_users']) : '1';
  248. $send_email = (isset($_POST['send_email']) && $_POST['send_email'] == '1') || $is_admin_group ? '1' : '0';
  249. $post_flood = isset($_POST['post_flood']) ? intval($_POST['post_flood']) : '0';
  250. $search_flood = isset($_POST['search_flood']) ? intval($_POST['search_flood']) : '0';
  251. $email_flood = isset($_POST['email_flood']) ? intval($_POST['email_flood']) : '0';
  252. $group_locked = (isset($_POST['group_locked']) && $_POST['group_locked'] == '1') ? '1' : '0';
  253. if ($title == '')
  254. message($lang_admin_groups['Must enter title message']);
  255. $user_title = ($user_title != '') ? '\''.$db->escape($user_title).'\'' : 'NULL';
  256. if ($_POST['mode'] == 'add')
  257. {
  258. $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_title=\''.$db->escape($title).'\'') or error('Unable to check group title collision', __FILE__, __LINE__, $db->error());
  259. if ($db->num_rows($result))
  260. message(sprintf($lang_admin_groups['Title already exists message'], pun_htmlspecialchars($title)));
  261. $db->query('INSERT INTO '.$db->prefix.'groups (g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood, g_locked) VALUES(\''.$db->escape($title).'\', '.$user_title.', '.$moderator.', '.$mod_edit_users.', '.$mod_rename_users.', '.$mod_change_passwords.', '.$mod_ban_users.', '.$read_board.', '.$view_users.', '.$post_replies.', '.$post_topics.', '.$edit_posts.', '.$delete_posts.', '.$delete_topics.', '.$set_title.', '.$search.', '.$search_users.', '.$send_email.', '.$post_flood.', '.$search_flood.', '.$email_flood.', '.$group_locked.')') or error('Unable to add group', __FILE__, __LINE__, $db->error());
  262. $new_group_id = $db->insert_id();
  263. // Now lets copy the forum specific permissions from the group which this group is based on
  264. $result = $db->query('SELECT forum_id, read_forum, post_replies, post_topics FROM '.$db->prefix.'forum_perms WHERE group_id='.intval($_POST['base_group'])) or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error());
  265. while ($cur_forum_perm = $db->fetch_assoc($result))
  266. $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$new_group_id.', '.$cur_forum_perm['forum_id'].', '.$cur_forum_perm['read_forum'].', '.$cur_forum_perm['post_replies'].', '.$cur_forum_perm['post_topics'].')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
  267. }
  268. else
  269. {
  270. $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_title=\''.$db->escape($title).'\' AND g_id!='.intval($_POST['group_id'])) or error('Unable to check group title collision', __FILE__, __LINE__, $db->error());
  271. if ($db->num_rows($result))
  272. message(sprintf($lang_admin_groups['Title already exists message'], pun_htmlspecialchars($title)));
  273. $db->query('UPDATE '.$db->prefix.'groups SET g_title=\''.$db->escape($title).'\', g_user_title='.$user_title.', g_moderator='.$moderator.', g_mod_edit_users='.$mod_edit_users.', g_mod_rename_users='.$mod_rename_users.', g_mod_change_passwords='.$mod_change_passwords.', g_mod_ban_users='.$mod_ban_users.', g_read_board='.$read_board.', g_view_users='.$view_users.', g_post_replies='.$post_replies.', g_post_topics='.$post_topics.', g_edit_posts='.$edit_posts.', g_delete_posts='.$delete_posts.', g_delete_topics='.$delete_topics.', g_set_title='.$set_title.', g_search='.$search.', g_search_users='.$search_users.', g_send_email='.$send_email.', g_post_flood='.$post_flood.', g_search_flood='.$search_flood.', g_email_flood='.$email_flood.', g_locked='.$group_locked.' WHERE g_id='.intval($_POST['group_id'])) or error('Unable to update group', __FILE__, __LINE__, $db->error());
  274. }
  275. // Regenerate the quick jump cache
  276. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  277. require PUN_ROOT.'include/cache.php';
  278. $group_id = $_POST['mode'] == 'add' ? $new_group_id : intval($_POST['group_id']);
  279. generate_quickjump_cache($group_id);
  280. if ($_POST['mode'] == 'edit')
  281. redirect('admin_groups.php', $lang_admin_groups['Group edited redirect']);
  282. else
  283. redirect('admin_groups.php', $lang_admin_groups['Group added redirect']);
  284. }
  285. // Set default group
  286. else if (isset($_POST['set_default_group']))
  287. {
  288. confirm_referrer('admin_groups.php');
  289. $group_id = intval($_POST['default_group']);
  290. // Make sure it's not the admin or guest groups
  291. if ($group_id == PUN_ADMIN || $group_id == PUN_GUEST)
  292. message($lang_common['Bad request']);
  293. // Make sure it's not a moderator group
  294. $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_id='.$group_id.' AND g_moderator=0') or error('Unable to check group moderator status', __FILE__, __LINE__, $db->error());
  295. if (!$db->num_rows($result))
  296. message($lang_common['Bad request']);
  297. $db->query('UPDATE '.$db->prefix.'config SET conf_value='.$group_id.' WHERE conf_name=\'o_default_user_group\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
  298. // Regenerate the config cache
  299. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  300. require PUN_ROOT.'include/cache.php';
  301. generate_config_cache();
  302. redirect('admin_groups.php', $lang_admin_groups['Default group redirect']);
  303. }
  304. // Remove a group
  305. else if (isset($_GET['del_group']))
  306. {
  307. confirm_referrer('admin_groups.php');
  308. $group_id = isset($_POST['group_to_delete']) ? intval($_POST['group_to_delete']) : intval($_GET['del_group']);
  309. if ($group_id < 5)
  310. message($lang_common['Bad request']);
  311. // Make sure we don't remove the default group
  312. if ($group_id == $pun_config['o_default_user_group'])
  313. message($lang_admin_groups['Cannot remove default message']);
  314. // Check if this group has any members
  315. $result = $db->query('SELECT g.g_title, COUNT(u.id) FROM '.$db->prefix.'groups AS g INNER JOIN '.$db->prefix.'users AS u ON g.g_id=u.group_id WHERE g.g_id='.$group_id.' GROUP BY g.g_id, g_title') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error());
  316. // If the group doesn't have any members or if we've already selected a group to move the members to
  317. if (!$db->num_rows($result) || isset($_POST['del_group']))
  318. {
  319. if (isset($_POST['del_group_comply']) || isset($_POST['del_group']))
  320. {
  321. if (isset($_POST['del_group']))
  322. {
  323. $move_to_group = intval($_POST['move_to_group']);
  324. $db->query('UPDATE '.$db->prefix.'users SET group_id='.$move_to_group.' WHERE group_id='.$group_id) or error('Unable to move users into group', __FILE__, __LINE__, $db->error());
  325. }
  326. // Delete the group and any forum specific permissions
  327. $db->query('DELETE FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to delete group', __FILE__, __LINE__, $db->error());
  328. $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE group_id='.$group_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
  329. redirect('admin_groups.php', $lang_admin_groups['Group removed redirect']);
  330. }
  331. else
  332. {
  333. $result = $db->query('SELECT g_title FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch group title', __FILE__, __LINE__, $db->error());
  334. $group_title = $db->result($result);
  335. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
  336. define('PUN_ACTIVE_PAGE', 'admin');
  337. require PUN_ROOT.'header.php';
  338. generate_admin_menu('groups');
  339. ?>
  340. <div class="blockform">
  341. <h2><span><?php echo $lang_admin_groups['Group delete head'] ?></span></h2>
  342. <div class="box">
  343. <form method="post" action="admin_groups.php?del_group=<?php echo $group_id ?>">
  344. <div class="inform">
  345. <input type="hidden" name="group_to_delete" value="<?php echo $group_id ?>" />
  346. <fieldset>
  347. <legend><?php echo $lang_admin_groups['Confirm delete subhead'] ?></legend>
  348. <div class="infldset">
  349. <p><?php printf($lang_admin_groups['Confirm delete info'], pun_htmlspecialchars($group_title)) ?></p>
  350. <p class="warntext"><?php echo $lang_admin_groups['Confirm delete warn'] ?></p>
  351. </div>
  352. </fieldset>
  353. </div>
  354. <p class="buttons"><input type="submit" name="del_group_comply" value="<?php echo $lang_admin_common['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
  355. </form>
  356. </div>
  357. </div>
  358. <div class="clearer"></div>
  359. </div>
  360. <?php
  361. require PUN_ROOT.'footer.php';
  362. }
  363. }
  364. list($group_title, $group_members) = $db->fetch_row($result);
  365. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
  366. define('PUN_ACTIVE_PAGE', 'admin');
  367. require PUN_ROOT.'header.php';
  368. generate_admin_menu('groups');
  369. ?>
  370. <div class="blockform">
  371. <h2><span><?php echo $lang_admin_groups['Delete group head'] ?></span></h2>
  372. <div class="box">
  373. <form id="groups" method="post" action="admin_groups.php?del_group=<?php echo $group_id ?>">
  374. <div class="inform">
  375. <fieldset>
  376. <legend><?php echo $lang_admin_groups['Move users subhead'] ?></legend>
  377. <div class="infldset">
  378. <p><?php printf($lang_admin_groups['Move users info'], pun_htmlspecialchars($group_title), forum_number_format($group_members)) ?></p>
  379. <label><?php echo $lang_admin_groups['Move users label'] ?>
  380. <select name="move_to_group">
  381. <?php
  382. $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_GUEST.' AND g_id!='.$group_id.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
  383. while ($cur_group = $db->fetch_assoc($result))
  384. {
  385. if ($cur_group['g_id'] == PUN_MEMBER) // Pre-select the pre-defined Members group
  386. echo "\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
  387. else
  388. echo "\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
  389. }
  390. ?>
  391. </select>
  392. <br /></label>
  393. </div>
  394. </fieldset>
  395. </div>
  396. <p class="buttons"><input type="submit" name="del_group" value="<?php echo $lang_admin_groups['Delete group'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
  397. </form>
  398. </div>
  399. </div>
  400. <div class="clearer"></div>
  401. </div>
  402. <?php
  403. require PUN_ROOT.'footer.php';
  404. }
  405. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
  406. define('PUN_ACTIVE_PAGE', 'admin');
  407. require PUN_ROOT.'header.php';
  408. generate_admin_menu('groups');
  409. ?>
  410. <div class="blockform">
  411. <h2><span><?php echo $lang_admin_groups['Add groups head'] ?></span></h2>
  412. <div class="box">
  413. <form id="groups" method="post" action="admin_groups.php">
  414. <div class="inform">
  415. <fieldset>
  416. <legend><?php echo $lang_admin_groups['Add group subhead'] ?></legend>
  417. <div class="infldset">
  418. <table class="aligntop" cellspacing="0">
  419. <tr>
  420. <th scope="row"><?php echo $lang_admin_groups['New group label'] ?><div><input type="submit" name="add_group" value="<?php echo $lang_admin_common['Add'] ?>" tabindex="2" /></div></th>
  421. <td>
  422. <select id="base_group" name="base_group" tabindex="1">
  423. <?php
  424. $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_ADMIN.' AND g_id!='.PUN_GUEST.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
  425. while ($cur_group = $db->fetch_assoc($result))
  426. {
  427. if ($cur_group['g_id'] == $pun_config['o_default_user_group'])
  428. echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
  429. else
  430. echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
  431. }
  432. ?>
  433. </select>
  434. <span><?php echo $lang_admin_groups['New group help'] ?></span>
  435. </td>
  436. </tr>
  437. </table>
  438. </div>
  439. </fieldset>
  440. </div>
  441. <div class="inform">
  442. <fieldset>
  443. <legend><?php echo $lang_admin_groups['Default group subhead'] ?></legend>
  444. <div class="infldset">
  445. <table class="aligntop" cellspacing="0">
  446. <tr>
  447. <th scope="row"><?php echo $lang_admin_groups['Default group label'] ?><div><input type="submit" name="set_default_group" value="<?php echo $lang_admin_common['Save'] ?>" tabindex="4" /></div></th>
  448. <td>
  449. <select id="default_group" name="default_group" tabindex="3">
  450. <?php
  451. $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id>'.PUN_GUEST.' AND g_moderator=0 ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
  452. while ($cur_group = $db->fetch_assoc($result))
  453. {
  454. if ($cur_group['g_id'] == $pun_config['o_default_user_group'])
  455. echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
  456. else
  457. echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
  458. }
  459. ?>
  460. </select>
  461. <span><?php echo $lang_admin_groups['Default group help'] ?></span>
  462. </td>
  463. </tr>
  464. </table>
  465. </div>
  466. </fieldset>
  467. </div>
  468. </form>
  469. </div>
  470. <h2 class="block2"><span><?php echo $lang_admin_groups['Existing groups head'] ?></span></h2>
  471. <div class="box">
  472. <div class="fakeform">
  473. <div class="inform">
  474. <fieldset>
  475. <legend><?php echo $lang_admin_groups['Edit groups subhead'] ?></legend>
  476. <div class="infldset">
  477. <p><?php echo $lang_admin_groups['Edit groups info'] ?></p>
  478. <table cellspacing="0">
  479. <?php
  480. $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
  481. while ($cur_group = $db->fetch_assoc($result))
  482. echo "\t\t\t\t\t\t\t\t".'<tr><th scope="row"><a href="admin_groups.php?edit_group='.$cur_group['g_id'].'">'.$lang_admin_groups['Edit link'].'</a>'.(($cur_group['g_id'] > PUN_MEMBER) ? ' | <a href="admin_groups.php?del_group='.$cur_group['g_id'].'">'.$lang_admin_groups['Delete link'].'</a>' : '').'</th><td>'.pun_htmlspecialchars($cur_group['g_title']).'</td></tr>'."\n";
  483. ?>
  484. </table>
  485. </div>
  486. </fieldset>
  487. </div>
  488. </div>
  489. </div>
  490. </div>
  491. <div class="clearer"></div>
  492. </div>
  493. <?php
  494. require PUN_ROOT.'footer.php';