diff -r 000000000000 -r 902822492a68 plugins/SpecialGroups.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/SpecialGroups.php Wed Jun 13 16:03:00 2007 -0400
@@ -0,0 +1,540 @@
+attachHook('base_classes_initted', '
+ global $paths;
+ $paths->add_page(Array(
+ \'name\'=>\'Group Membership\',
+ \'urlname\'=>\'Usergroups\',
+ \'namespace\'=>\'Special\',
+ \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
+ ));
+ ');
+
+function page_Special_Usergroups()
+{
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $email; // Import e-mail encryption functions
+
+ if ( !$session->user_logged_in )
+ {
+ header('Location: ' . makeUrlComplete('Special', 'Login/' . $paths->page));
+ $db->close();
+ exit;
+ }
+
+ $template->header();
+ if ( isset($_POST['do_view']) || isset($_POST['do_view_n']) || ( isset($_GET['act']) && isset($_POST['group_id']) ) )
+ {
+ $gid = ( isset ( $_POST['do_view_n'] ) ) ? intval($_POST['group_id_n']) : intval($_POST['group_id']);
+ if ( empty($gid) || $gid < 1 )
+ {
+ die_friendly('Error', '
Hacking attempt
');
+ }
+ $q = $db->sql_query('SELECT group_name,group_type FROM '.table_prefix.'groups WHERE group_id=' . $gid . ';');
+ if ( !$q )
+ {
+ $db->_die();
+ }
+ $row = $db->fetchrow();
+ $db->free_result();
+ $members = array();
+ $pending = array();
+ $q = $db->sql_query('SELECT u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod,m.pending,COUNT(c.comment_id)
+ FROM '.table_prefix.'users AS u
+ LEFT JOIN '.table_prefix.'group_members AS m
+ ON ( m.user_id = u.user_id )
+ LEFT JOIN '.table_prefix.'comments AS c
+ ON ( c.name = u.username )
+ WHERE m.group_id=' . $gid . '
+ GROUP BY u.user_id
+ ORDER BY m.is_mod DESC,u.username ASC;');
+ if ( !$q )
+ {
+ $db->_die();
+ }
+
+ $is_member = false;
+ $is_mod = false;
+ $is_pending = false;
+
+ while ( $mr = $db->fetchrow() )
+ {
+ if ( $mr['pending'] == 1 )
+ {
+ $pending[] = $mr;
+ if ( $mr['user_id'] == $session->user_id )
+ {
+ $is_pending = true;
+ }
+ }
+ else
+ {
+ $members[] = $mr;
+ if ( $mr['user_id'] == $session->user_id )
+ {
+ $is_member = true;
+ if ( $mr['is_mod'] == 1 )
+ {
+ $is_mod = true;
+ }
+ }
+ }
+ }
+
+ $status = ( $is_member && $is_mod )
+ ? 'You are a moderator of this group.'
+ : ( ( $is_member && !$is_mod )
+ ? 'You are a member of this group.'
+ : 'You are not a member of this group.'
+ );
+
+ $can_do_admin_stuff = ( $is_mod || $session->user_level >= USER_LEVEL_ADMIN );
+
+ switch ( $row['group_type'] )
+ {
+ case GROUP_HIDDEN: $g_state = 'Hidden group'; break;
+ case GROUP_CLOSED: $g_state = 'Closed group'; break;
+ case GROUP_REQUEST: $g_state = 'Members can request to join'; break;
+ case GROUP_OPEN: $g_state = 'Anyone can join'; break;
+ }
+
+ if ( isset($_GET['act']) && $can_do_admin_stuff )
+ {
+ switch($_GET['act'])
+ {
+ case 'update':
+ if(!in_array(intval($_POST['group_state']), Array(GROUP_CLOSED, GROUP_OPEN, GROUP_HIDDEN, GROUP_REQUEST)))
+ {
+ die_friendly('ERROR', 'Hacking attempt
');
+ }
+ $q = $db->sql_query('UPDATE '.table_prefix.'groups SET group_type=' . intval($_POST['group_state']) . ' WHERE group_id=' . intval( $_POST['group_id']) . ';');
+ if (!$q)
+ $db->_die();
+ $row['group_type'] = $_POST['group_state'];
+ echo 'The group state was updated.
';
+ break;
+ case 'adduser':
+ $username = $_POST['add_username'];
+ $mod = ( isset($_POST['add_mod']) ) ? '1' : '0';
+
+ $q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE username=\'' . $db->escape($username) . '\';');
+ if (!$q)
+ $db->_die();
+ if ($db->numrows() < 1)
+ {
+ echo 'The username you entered could not be found.
';
+ break;
+ }
+ $r = $db->fetchrow();
+ $db->free_result();
+ $uid = intval($r['user_id']);
+
+ // Check if the user is already in the group, and if so, only update modship
+ $q = $db->sql_query('SELECT member_id,is_mod FROM '.table_prefix.'group_members WHERE user_id=' . $uid . ' AND group_id=' . intval($_POST['group_id']) . ';');
+ if ( !$q )
+ $db->_die();
+ if ( $db->numrows() > 0 )
+ {
+ $r = $db->fetchrow();
+ if ( (string) $r['is_mod'] != $mod )
+ {
+ $q = $db->sql_query('UPDATE '.table_prefix.'group_members SET is_mod=' . $mod . ' WHERE member_id=' . $r['member_id'] . ';');
+ if ( !$q )
+ $db->_die();
+ foreach ( $members as $i => $member )
+ {
+ if ( $member['member_id'] == $r['member_id'] )
+ $members[$i]['is_mod'] = (int)$mod;
+ }
+ echo 'The user "' . $username . '" is already in this group, so their moderator status was updated.
';
+ }
+ else
+ {
+ echo 'The user "' . $username . '" is already in this group.
';
+ }
+ break;
+ }
+
+ $db->free_result();
+
+ $q = $db->sql_query('INSERT INTO '.table_prefix.'group_members(group_id,user_id,is_mod) VALUES(' . intval($_POST['group_id']) . ', ' . $uid . ', ' . $mod . ');');
+ if (!$q)
+ $db->_die();
+ echo 'The user "' . $username . '" has been added to this usergroup.
';
+
+ $q = $db->sql_query('SELECT u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod,COUNT(c.comment_id)
+ FROM '.table_prefix.'users AS u
+ LEFT JOIN '.table_prefix.'group_members AS m
+ ON ( m.user_id = u.user_id )
+ LEFT JOIN '.table_prefix.'comments AS c
+ ON ( c.name = u.username )
+ WHERE m.group_id=' . $gid . '
+ AND m.pending!=1
+ AND u.user_id=' . $uid . '
+ GROUP BY u.user_id
+ ORDER BY m.is_mod DESC,u.username ASC
+ LIMIT 1;');
+ if ( !$q )
+ $db->_die();
+
+ $r = $db->fetchrow();
+ $members[] = $r;
+ $db->free_result();
+
+ break;
+ case 'del_users':
+ foreach ( $members as $i => $member )
+ {
+ if ( isset($_POST['del_user'][$member['member_id']]) )
+ {
+ $q = $db->sql_query('DELETE FROM '.table_prefix.'group_members WHERE member_id=' . $member['member_id'] . ';');
+ if (!$q)
+ $db->_die();
+ unset($members[$i]);
+ }
+ }
+ break;
+ case 'pending':
+ foreach ( $pending as $i => $member )
+ {
+ if ( isset( $_POST['with_user'][$member['member_id']]) )
+ {
+ if ( isset ( $_POST['do_appr_pending'] ) )
+ {
+ $q = $db->sql_query('UPDATE '.table_prefix.'group_members SET pending=0 WHERE member_id=' . $member['member_id'] . ';');
+ if (!$q)
+ $db->_die();
+ $members[] = $member;
+ unset($pending[$i]);
+ continue;
+ }
+ elseif ( isset ( $_POST['do_reject_pending'] ) )
+ {
+ $q = $db->sql_query('DELETE FROM '.table_prefix.'group_members WHERE member_id=' . $member['member_id'] . ';');
+ if (!$q)
+ $db->_die();
+ unset($pending[$i]);
+ }
+ }
+ }
+ echo 'Pending members status updated successfully.
';
+ break;
+ }
+ }
+
+ if ( isset($_GET['act']) && $_GET['act'] == 'update' && !$is_member && $row['group_type'] == GROUP_OPEN )
+ {
+ $q = $db->sql_query('INSERT INTO '.table_prefix.'group_members(group_id,user_id) VALUES(' . $gid . ', ' . $session->user_id . ');');
+ if (!$q)
+ $db->_die();
+ echo 'You have been added to this group.
';
+
+ $q = $db->sql_query('SELECT u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod,COUNT(c.comment_id)
+ FROM '.table_prefix.'users AS u
+ LEFT JOIN '.table_prefix.'group_members AS m
+ ON ( m.user_id = u.user_id )
+ LEFT JOIN '.table_prefix.'comments AS c
+ ON ( c.name = u.username )
+ WHERE m.group_id=' . $gid . '
+ AND m.pending!=1
+ AND u.user_id=' . $session->user_id . '
+ GROUP BY u.user_id
+ ORDER BY m.is_mod DESC,u.username ASC
+ LIMIT 1;');
+ if ( !$q )
+ $db->_die();
+
+ $r = $db->fetchrow();
+ $members[] = $r;
+ $db->free_result();
+
+ }
+
+ if ( isset($_GET['act']) && $_GET['act'] == 'update' && !$is_member && $row['group_type'] == GROUP_REQUEST && !$is_pending )
+ {
+ $q = $db->sql_query('INSERT INTO '.table_prefix.'group_members(group_id,user_id,pending) VALUES(' . $gid . ', ' . $session->user_id . ', 1);');
+ if (!$q)
+ $db->_die();
+ echo 'A request has been sent to the moderator(s) of this group to add you.
';
+ }
+
+ $state_btns = ( $can_do_admin_stuff ) ?
+ '
+
+
+ '
+ : $g_state;
+ if ( !$can_do_admin_stuff && $row['group_type'] == GROUP_REQUEST && !$is_member )
+ {
+ if ( $is_pending )
+ $state_btns .= ' (Your request to join is awaiting approval)';
+ else
+ $state_btns .= ' ';
+ }
+
+ if ( !$can_do_admin_stuff && $row['group_type'] == GROUP_OPEN && !$is_member )
+ {
+ $state_btns .= ' ';
+ }
+
+ echo '';
+ if ( sizeof ( $pending ) > 0 && $can_do_admin_stuff )
+ {
+ echo '';
+ }
+ echo '';
+ if ( $can_do_admin_stuff )
+ {
+ echo '';
+ }
+ }
+ else
+ {
+ echo '';
+ }
+ $template->footer();
+}
+
+?>