PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/includes/datastore/build_moderators.php

http://torrentpier2.googlecode.com/
PHP | 107 lines | 90 code | 11 blank | 6 comment | 2 complexity | 079c6e2e181dcb27587471498d2b05cb MD5 | raw file
  1<?php
  2
  3if (!defined('BB_ROOT')) die(basename(__FILE__));
  4
  5$data = array(
  6	'name_users'  => array(),  // only by personal permissions
  7	'name_groups' => array(),  // only visible to all users
  8	'mod_users'   => array(),  // only by personal permissions
  9	'mod_groups'  => array(),  // only visible to all users
 10	'moderators'  => array(),  // all moderators
 11	'admins'      => array(),  // all admins
 12);
 13
 14// name_users
 15// mod_users
 16$sql = "
 17	SELECT
 18		aa.forum_id, u.user_id, u.username
 19	FROM
 20		". BB_AUTH_ACCESS ." aa,
 21		". BB_USER_GROUP  ." ug,
 22		". BB_GROUPS      ." g,
 23		". BB_USERS       ." u
 24	WHERE
 25				aa.forum_perm & ". BF_AUTH_MOD ."
 26		AND ug.group_id = aa.group_id
 27		AND ug.user_pending = 0
 28		AND g.group_id = ug.group_id
 29		AND g.group_single_user = 1
 30		AND u.user_id = ug.user_id
 31	GROUP BY
 32		aa.forum_id, u.user_id
 33	ORDER BY
 34		u.username
 35";
 36
 37foreach (DB()->fetch_rowset($sql) as $row)
 38{
 39	$data['name_users'][$row['user_id']] = $row['username'];
 40	$data['mod_users'][$row['forum_id']][] = $row['user_id'];
 41}
 42
 43// name_groups
 44// mod_groups
 45$sql = "
 46	SELECT
 47		aa.forum_id, g.group_id, g.group_name
 48	FROM
 49		". BB_AUTH_ACCESS ." aa,
 50		". BB_GROUPS      ." g
 51	WHERE
 52				aa.forum_perm & ". BF_AUTH_MOD ."
 53		AND g.group_id = aa.group_id
 54		AND g.group_single_user = 0
 55		AND g.group_type != ". GROUP_HIDDEN ."
 56	GROUP BY
 57		aa.forum_id, g.group_id
 58	ORDER BY
 59		g.group_name
 60";
 61
 62foreach (DB()->fetch_rowset($sql) as $row)
 63{
 64	$data['name_groups'][$row['group_id']] = $row['group_name'];
 65	$data['mod_groups'][$row['forum_id']][] = $row['group_id'];
 66}
 67
 68// moderators
 69$sql = "
 70	SELECT
 71		u.user_id, u.username
 72	FROM
 73		". BB_AUTH_ACCESS ." aa,
 74		". BB_USER_GROUP  ." ug,
 75		". BB_GROUPS      ." g,
 76		". BB_USERS       ." u
 77	WHERE
 78				aa.forum_perm & ". BF_AUTH_MOD ."
 79		AND ug.group_id = aa.group_id
 80		AND ug.user_pending = 0
 81		AND g.group_id = ug.group_id
 82		AND u.user_id = ug.user_id
 83	GROUP BY
 84		u.user_id
 85	ORDER BY
 86		u.username
 87";
 88
 89foreach (DB()->fetch_rowset($sql) as $row)
 90{
 91	$data['moderators'][$row['user_id']] = $row['username'];
 92}
 93
 94// admins
 95$sql = "
 96	SELECT user_id, username
 97	FROM ". BB_USERS ."
 98	WHERE user_level = ". ADMIN ."
 99	ORDER BY username
100";
101
102foreach (DB()->fetch_rowset($sql) as $row)
103{
104	$data['admins'][$row['user_id']] = $row['username'];
105}
106
107$this->store('moderators', $data);