Просмотр файла admin/admin_groups.php

Размер файла: 12.35Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', 1);
  7.  
  8. if ( !empty($setmodules) )
  9. {
  10. $filename = basename(__FILE__);
  11. $module['Groups']['Управление группами'] = $filename;
  12.  
  13. return;
  14. }
  15.  
  16. $phpbb_root_path = './../';
  17. require($phpbb_root_path . 'extension.inc');
  18. require('./pagestart.' . $phpEx);
  19.  
  20. if ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) || isset($HTTP_GET_VARS[POST_GROUPS_URL]) )
  21. {
  22. $group_id = ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) ) ? intval($HTTP_POST_VARS[POST_GROUPS_URL]) : intval($HTTP_GET_VARS[POST_GROUPS_URL]);
  23. }
  24. else
  25. {
  26. $group_id = 0;
  27. }
  28.  
  29. if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
  30. {
  31. $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  32. $mode = htmlspecialchars($mode);
  33. }
  34. else
  35. {
  36. $mode = '';
  37. }
  38.  
  39. if ( isset($HTTP_POST_VARS['edit']) || isset($HTTP_POST_VARS['new']) )
  40. {
  41.  
  42. $template->set_filenames(array(
  43. 'body' => 'admin/group_edit_body.tpl')
  44. );
  45.  
  46. if ( isset($HTTP_POST_VARS['edit']) )
  47. {
  48.  
  49. $sql = "SELECT *
  50. FROM " . GROUPS_TABLE . "
  51. WHERE group_single_user <> " . TRUE . "
  52. AND group_id = $group_id";
  53. if ( !($result = $db->sql_query($sql)) )
  54. {
  55. message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
  56. }
  57.  
  58. if ( !($group_info = $db->sql_fetchrow($result)) )
  59. {
  60. message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
  61. }
  62.  
  63. $mode = 'editgroup';
  64. $template->assign_block_vars('group_edit', array());
  65.  
  66. }
  67. else if ( isset($HTTP_POST_VARS['new']) )
  68. {
  69. $group_info = array (
  70. 'group_name' => '',
  71. 'group_description' => '',
  72. 'group_moderator' => '',
  73. 'group_type' => GROUP_OPEN);
  74. $group_open = ' checked="checked"';
  75.  
  76. $mode = 'newgroup';
  77.  
  78. }
  79.  
  80. if ($group_info['group_moderator'] != '')
  81. {
  82. $sql = "SELECT user_id, username
  83. FROM " . USERS_TABLE . "
  84. WHERE user_id = " . $group_info['group_moderator'];
  85. if ( !($result = $db->sql_query($sql)) )
  86. {
  87. message_die(GENERAL_ERROR, 'Could not obtain user info for moderator list', '', __LINE__, __FILE__, $sql);
  88. }
  89.  
  90. if ( !($row = $db->sql_fetchrow($result)) )
  91. {
  92. message_die(GENERAL_ERROR, 'Could not obtain user info for moderator list', '', __LINE__, __FILE__, $sql);
  93. }
  94.  
  95. $group_moderator = $row['username'];
  96. }
  97. else
  98. {
  99. $group_moderator = '';
  100. }
  101.  
  102. $group_open = ( $group_info['group_type'] == GROUP_OPEN ) ? ' checked="checked"' : '';
  103. $group_closed = ( $group_info['group_type'] == GROUP_CLOSED ) ? ' checked="checked"' : '';
  104. $group_hidden = ( $group_info['group_type'] == GROUP_HIDDEN ) ? ' checked="checked"' : '';
  105.  
  106. $s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_GROUPS_URL . '" value="' . $group_id . '" />';
  107.  
  108. $template->assign_vars(array(
  109. 'GROUP_NAME' => $group_info['group_name'],
  110. 'GROUP_DESCRIPTION' => $group_info['group_description'],
  111. 'GROUP_MODERATOR' => $group_moderator,
  112.  
  113. 'L_GROUP_TITLE' => $lang['Group_administration'],
  114. 'L_GROUP_EDIT_DELETE' => ( isset($HTTP_POST_VARS['new']) ) ? $lang['New_group'] : $lang['Edit_group'],
  115. 'L_GROUP_NAME' => $lang['group_name'],
  116. 'L_GROUP_DESCRIPTION' => $lang['group_description'],
  117. 'L_GROUP_MODERATOR' => $lang['group_moderator'],
  118. 'L_FIND_USERNAME' => $lang['Find_username'],
  119. 'L_GROUP_STATUS' => $lang['group_status'],
  120. 'L_GROUP_OPEN' => $lang['group_open'],
  121. 'L_GROUP_CLOSED' => $lang['group_closed'],
  122. 'L_GROUP_HIDDEN' => $lang['group_hidden'],
  123. 'L_GROUP_DELETE' => $lang['group_delete'],
  124. 'L_GROUP_DELETE_CHECK' => $lang['group_delete_check'],
  125. 'L_SUBMIT' => $lang['Submit'],
  126. 'L_RESET' => $lang['Reset'],
  127. 'L_DELETE_MODERATOR' => $lang['delete_group_moderator'],
  128. 'L_DELETE_MODERATOR_EXPLAIN' => $lang['delete_moderator_explain'],
  129. 'L_YES' => $lang['Yes'],
  130.  
  131. 'U_SEARCH_USER' => append_sid("../search.$phpEx?mode=searchuser"),
  132.  
  133. 'S_GROUP_OPEN_TYPE' => GROUP_OPEN,
  134. 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED,
  135. 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN,
  136. 'S_GROUP_OPEN_CHECKED' => $group_open,
  137. 'S_GROUP_CLOSED_CHECKED' => $group_closed,
  138. 'S_GROUP_HIDDEN_CHECKED' => $group_hidden,
  139. 'S_GROUP_ACTION' => append_sid("admin_groups.$phpEx"),
  140. 'S_HIDDEN_FIELDS' => $s_hidden_fields)
  141. );
  142.  
  143. $template->pparse('body');
  144.  
  145. }
  146. else if ( isset($HTTP_POST_VARS['group_update']) )
  147. {
  148.  
  149. if ( isset($HTTP_POST_VARS['group_delete']) )
  150. {
  151.  
  152. $sql = "SELECT auth_mod FROM " . AUTH_ACCESS_TABLE . "
  153. WHERE group_id = " . $group_id;
  154. if ( !($result = $db->sql_query($sql)) )
  155. {
  156. message_die(GENERAL_ERROR, 'Could not select auth_access', '', __LINE__, __FILE__, $sql);
  157. }
  158.  
  159. $row = $db->sql_fetchrow($result);
  160. if (intval($row['auth_mod']) == 1)
  161. {
  162. $sql = "SELECT user_id FROM " . USER_GROUP_TABLE . "
  163. WHERE group_id = " . $group_id;
  164. if ( !($result = $db->sql_query($sql)) )
  165. {
  166. message_die(GENERAL_ERROR, 'Could not select user_group', '', __LINE__, __FILE__, $sql);
  167. }
  168.  
  169. $rows = $db->sql_fetchrowset($result);
  170. for ($i = 0; $i < count($rows); $i++)
  171. {
  172. $sql = "SELECT g.group_id FROM " . AUTH_ACCESS_TABLE . " a, " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
  173. WHERE (a.auth_mod = 1) AND (g.group_id = a.group_id) AND (a.group_id = ug.group_id) AND (g.group_id = ug.group_id)
  174. AND (ug.user_id = " . intval($rows[$i]['user_id']) . ") AND (ug.group_id <> " . $group_id . ")";
  175. if ( !($result = $db->sql_query($sql)) )
  176. {
  177. message_die(GENERAL_ERROR, 'Could not obtain moderator permissions', '', __LINE__, __FILE__, $sql);
  178. }
  179.  
  180. if ($db->sql_numrows($result) == 0)
  181. {
  182. $sql = "UPDATE " . USERS_TABLE . " SET user_level = " . USER . "
  183. WHERE user_level = " . MOD . " AND user_id = " . intval($rows[$i]['user_id']);
  184. if ( !$db->sql_query($sql) )
  185. {
  186. message_die(GENERAL_ERROR, 'Could not update moderator permissions', '', __LINE__, __FILE__, $sql);
  187. }
  188. }
  189. }
  190. }
  191.  
  192. $sql = "DELETE FROM " . GROUPS_TABLE . "
  193. WHERE group_id = " . $group_id;
  194. if ( !$db->sql_query($sql) )
  195. {
  196. message_die(GENERAL_ERROR, 'Could not update group', '', __LINE__, __FILE__, $sql);
  197. }
  198.  
  199. $sql = "DELETE FROM " . USER_GROUP_TABLE . "
  200. WHERE group_id = " . $group_id;
  201. if ( !$db->sql_query($sql) )
  202. {
  203. message_die(GENERAL_ERROR, 'Could not update user_group', '', __LINE__, __FILE__, $sql);
  204. }
  205.  
  206. $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
  207. WHERE group_id = " . $group_id;
  208. if ( !$db->sql_query($sql) )
  209. {
  210. message_die(GENERAL_ERROR, 'Could not update auth_access', '', __LINE__, __FILE__, $sql);
  211. }
  212.  
  213. $message = $lang['Deleted_group'] . '<br /><br />' . sprintf($lang['Click_return_groupsadmin'], '<a href="' . append_sid("admin_groups.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
  214.  
  215. message_die(GENERAL_MESSAGE, $message);
  216. }
  217. else
  218. {
  219. $group_type = isset($HTTP_POST_VARS['group_type']) ? intval($HTTP_POST_VARS['group_type']) : GROUP_OPEN;
  220. $group_name = isset($HTTP_POST_VARS['group_name']) ? htmlspecialchars(trim($HTTP_POST_VARS['group_name'])) : '';
  221. $group_description = isset($HTTP_POST_VARS['group_description']) ? trim($HTTP_POST_VARS['group_description']) : '';
  222. $group_moderator = isset($HTTP_POST_VARS['username']) ? $HTTP_POST_VARS['username'] : '';
  223. $delete_old_moderator = isset($HTTP_POST_VARS['delete_old_moderator']) ? true : false;
  224.  
  225. if ( $group_name == '' )
  226. {
  227. message_die(GENERAL_MESSAGE, $lang['No_group_name']);
  228. }
  229. else if ( $group_moderator == '' )
  230. {
  231. message_die(GENERAL_MESSAGE, $lang['No_group_moderator']);
  232. }
  233. $this_userdata = get_userdata($group_moderator, true);
  234. $group_moderator = $this_userdata['user_id'];
  235.  
  236. if ( !$group_moderator )
  237. {
  238. message_die(GENERAL_MESSAGE, $lang['No_group_moderator']);
  239. }
  240. if( $mode == "editgroup" )
  241. {
  242. $sql = "SELECT *
  243. FROM " . GROUPS_TABLE . "
  244. WHERE group_single_user <> " . TRUE . "
  245. AND group_id = " . $group_id;
  246. if ( !($result = $db->sql_query($sql)) )
  247. {
  248. message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
  249. }
  250.  
  251. if( !($group_info = $db->sql_fetchrow($result)) )
  252. {
  253. message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
  254. }
  255. if ( $group_info['group_moderator'] != $group_moderator )
  256. {
  257. if ( $delete_old_moderator )
  258. {
  259. $sql = "DELETE FROM " . USER_GROUP_TABLE . "
  260. WHERE user_id = " . $group_info['group_moderator'] . "
  261. AND group_id = " . $group_id;
  262. if ( !$db->sql_query($sql) )
  263. {
  264. message_die(GENERAL_ERROR, 'Could not update group moderator', '', __LINE__, __FILE__, $sql);
  265. }
  266. }
  267.  
  268. $sql = "SELECT user_id
  269. FROM " . USER_GROUP_TABLE . "
  270. WHERE user_id = $group_moderator
  271. AND group_id = $group_id";
  272. if ( !($result = $db->sql_query($sql)) )
  273. {
  274. message_die(GENERAL_ERROR, 'Failed to obtain current group moderator info', '', __LINE__, __FILE__, $sql);
  275. }
  276.  
  277. if ( !($row = $db->sql_fetchrow($result)) )
  278. {
  279. $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
  280. VALUES (" . $group_id . ", " . $group_moderator . ", 0)";
  281. if ( !$db->sql_query($sql) )
  282. {
  283. message_die(GENERAL_ERROR, 'Could not update group moderator', '', __LINE__, __FILE__, $sql);
  284. }
  285. }
  286. }
  287.  
  288. $sql = "UPDATE " . GROUPS_TABLE . "
  289. SET group_type = $group_type, group_name = '" . str_replace("\'", "''", $group_name) . "', group_description = '" . str_replace("\'", "''", $group_description) . "', group_moderator = $group_moderator
  290. WHERE group_id = $group_id";
  291. if ( !$db->sql_query($sql) )
  292. {
  293. message_die(GENERAL_ERROR, 'Could not update group', '', __LINE__, __FILE__, $sql);
  294. }
  295. $message = $lang['Updated_group'] . '<br /><br />' . sprintf($lang['Click_return_groupsadmin'], '<a href="' . append_sid("admin_groups.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');;
  296.  
  297. message_die(GENERAL_MESSAGE, $message);
  298. }
  299. else if( $mode == 'newgroup' )
  300. {
  301. $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user)
  302. VALUES ($group_type, '" . str_replace("\'", "''", $group_name) . "', '" . str_replace("\'", "''", $group_description) . "', $group_moderator, '0')";
  303. if ( !$db->sql_query($sql) )
  304. {
  305. message_die(GENERAL_ERROR, 'Could not insert new group', '', __LINE__, __FILE__, $sql);
  306. }
  307. $new_group_id = $db->sql_nextid();
  308.  
  309. $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
  310. VALUES ($new_group_id, $group_moderator, 0)";
  311. if ( !$db->sql_query($sql) )
  312. {
  313. message_die(GENERAL_ERROR, 'Could not insert new user-group info', '', __LINE__, __FILE__, $sql);
  314. }
  315. $message = $lang['Added_new_group'] . '<br /><br />' . sprintf($lang['Click_return_groupsadmin'], '<a href="' . append_sid("admin_groups.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');;
  316.  
  317. message_die(GENERAL_MESSAGE, $message);
  318.  
  319. }
  320. else
  321. {
  322. message_die(GENERAL_MESSAGE, $lang['No_group_action']);
  323. }
  324. }
  325. }
  326. else
  327. {
  328. $sql = "SELECT group_id, group_name
  329. FROM " . GROUPS_TABLE . "
  330. WHERE group_single_user <> " . TRUE . "
  331. ORDER BY group_name";
  332. if ( !($result = $db->sql_query($sql)) )
  333. {
  334. message_die(GENERAL_ERROR, 'Could not obtain group list', '', __LINE__, __FILE__, $sql);
  335. }
  336.  
  337. $select_list = '';
  338. if ( $row = $db->sql_fetchrow($result) )
  339. {
  340. $select_list .= '<select name="' . POST_GROUPS_URL . '">';
  341. do
  342. {
  343. $select_list .= '<option value="' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
  344. }
  345. while ( $row = $db->sql_fetchrow($result) );
  346. $select_list .= '</select>';
  347. }
  348.  
  349. $template->set_filenames(array(
  350. 'body' => 'admin/group_select_body.tpl')
  351. );
  352.  
  353. $template->assign_vars(array(
  354. 'L_GROUP_TITLE' => $lang['Group_administration'],
  355. 'L_GROUP_EXPLAIN' => $lang['Group_admin_explain'],
  356. 'L_GROUP_SELECT' => $lang['Select_group'],
  357. 'L_LOOK_UP' => $lang['Look_up_group'],
  358. 'L_CREATE_NEW_GROUP' => $lang['New_group'],
  359.  
  360. 'S_GROUP_ACTION' => append_sid("admin_groups.$phpEx"),
  361. 'S_GROUP_SELECT' => $select_list)
  362. );
  363.  
  364. if ( $select_list != '' )
  365. {
  366. $template->assign_block_vars('select_box', array());
  367. }
  368.  
  369. $template->pparse('body');
  370. }
  371.  
  372. include('./page_footer_admin.'.$phpEx);
  373.  
  374. ?>