diff -r de56132c008d -r bdac73ed481e plugins/SpecialGroups.php --- a/plugins/SpecialGroups.php Sun Mar 28 21:49:26 2010 -0400 +++ b/plugins/SpecialGroups.php Sun Mar 28 23:10:46 2010 -0400 @@ -1,12 +1,12 @@ user_logged_in ) - { - header('Location: ' . makeUrlComplete('Special', 'Login/' . $paths->page)); - $db->close(); - exit; - } - - $template->header(); - userprefs_show_menu(); - 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,system_group FROM '.table_prefix.'groups WHERE group_id=' . $gid . ';'); - if ( !$q ) - { - $db->_die('SpecialGroups.php, line ' . __LINE__); - } - $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) AS num_comments - 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,u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod,m.pending - ORDER BY m.is_mod DESC,u.username ASC;'); - if ( !$q ) - { - $db->_die('SpecialGroups.php, line ' . __LINE__); - } - - $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 ) - ? $lang->get('groupcp_status_mod') - : ( ( $is_member && !$is_mod ) - ? $lang->get('groupcp_status_member') - : $lang->get('groupcp_status_not_member') - ); - - $can_do_admin_stuff = ( $is_mod || $session->user_level >= USER_LEVEL_ADMIN ); - - switch ( $row['group_type'] ) - { - case GROUP_HIDDEN: $g_state = $lang->get('groupcp_type_hidden'); break; - case GROUP_CLOSED: $g_state = $lang->get('groupcp_type_closed'); break; - case GROUP_REQUEST: $g_state = $lang->get('groupcp_type_request'); break; - case GROUP_OPEN: $g_state = $lang->get('groupcp_type_open'); 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('SELECT group_type, system_group FROM '.table_prefix.'groups WHERE group_id=' . intval( $_POST['group_id']) . ';'); - if ( !$q ) - $db->_die('SpecialGroups.php, line ' . __LINE__); - $error = false; - if ( $db->numrows() < 1 ) - { - echo '
The group you selected does not exist.
'; - $error = true; - } - $r = $db->fetchrow(); - if ( $r['system_group'] == 1 && ( intval($_POST['group_state']) == GROUP_OPEN || intval($_POST['group_state']) == GROUP_REQUEST ) ) - { - echo '
' . $lang->get('groupcp_err_state_system_group') . '
'; - $error = true; - } - if ( !$error ) - { - $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('SpecialGroups.php, line ' . __LINE__); - $row['group_type'] = $_POST['group_state']; - echo '
' . $lang->get('groupcp_msg_state_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('SpecialGroups.php, line ' . __LINE__); - if ($db->numrows() < 1) - { - echo '
' . $lang->get('groupcp_err_user_not_found') . '
'; - break; - } - $r = $db->fetchrow(); - $db->free_result(); - $uid = intval($r['user_id']); + global $db, $session, $paths, $template, $plugins; // Common objects + global $email; // Import e-mail encryption functions + global $lang; + + if ( !$session->user_logged_in ) + { + header('Location: ' . makeUrlComplete('Special', 'Login/' . $paths->page)); + $db->close(); + exit; + } + + $template->header(); + userprefs_show_menu(); + 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,system_group FROM '.table_prefix.'groups WHERE group_id=' . $gid . ';'); + if ( !$q ) + { + $db->_die('SpecialGroups.php, line ' . __LINE__); + } + $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) AS num_comments + 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,u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod,m.pending + ORDER BY m.is_mod DESC,u.username ASC;'); + if ( !$q ) + { + $db->_die('SpecialGroups.php, line ' . __LINE__); + } + + $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 ) + ? $lang->get('groupcp_status_mod') + : ( ( $is_member && !$is_mod ) + ? $lang->get('groupcp_status_member') + : $lang->get('groupcp_status_not_member') + ); + + $can_do_admin_stuff = ( $is_mod || $session->user_level >= USER_LEVEL_ADMIN ); + + switch ( $row['group_type'] ) + { + case GROUP_HIDDEN: $g_state = $lang->get('groupcp_type_hidden'); break; + case GROUP_CLOSED: $g_state = $lang->get('groupcp_type_closed'); break; + case GROUP_REQUEST: $g_state = $lang->get('groupcp_type_request'); break; + case GROUP_OPEN: $g_state = $lang->get('groupcp_type_open'); 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('SELECT group_type, system_group FROM '.table_prefix.'groups WHERE group_id=' . intval( $_POST['group_id']) . ';'); + if ( !$q ) + $db->_die('SpecialGroups.php, line ' . __LINE__); + $error = false; + if ( $db->numrows() < 1 ) + { + echo '
The group you selected does not exist.
'; + $error = true; + } + $r = $db->fetchrow(); + if ( $r['system_group'] == 1 && ( intval($_POST['group_state']) == GROUP_OPEN || intval($_POST['group_state']) == GROUP_REQUEST ) ) + { + echo '
' . $lang->get('groupcp_err_state_system_group') . '
'; + $error = true; + } + if ( !$error ) + { + $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('SpecialGroups.php, line ' . __LINE__); + $row['group_type'] = $_POST['group_state']; + echo '
' . $lang->get('groupcp_msg_state_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('SpecialGroups.php, line ' . __LINE__); + if ($db->numrows() < 1) + { + echo '
' . $lang->get('groupcp_err_user_not_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('SpecialGroups.php, line ' . __LINE__); - 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('SpecialGroups.php, line ' . __LINE__); - foreach ( $members as $i => $member ) - { - if ( $member['member_id'] == $r['member_id'] ) - $members[$i]['is_mod'] = (int)$mod; - } - echo '
' . $lang->get('groupcp_msg_user_already_in_mod_updated', array('username' => $username)) . '
'; - } - else - { - echo '
' . $lang->get('groupcp_msg_user_already_in', array('username' => $username)) . '
'; - } - 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('SpecialGroups.php, line ' . __LINE__); - echo '
' . $lang->get('groupcp_msg_user_added', array('username' => $username)) . '
'; - - $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) AS num_comments - 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,u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod - ORDER BY m.is_mod DESC,u.username ASC - LIMIT 1;'); - if ( !$q ) - $db->_die('SpecialGroups.php, line ' . __LINE__); - - $r = $db->fetchrow(); - $members[] = $r; - $db->free_result(); - - // just added a user to the group, so regenerate the ranks cache - generate_cache_userranks(); - - 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('SpecialGroups.php, line ' . __LINE__); - unset($members[$i]); - } - } - // regenerate the ranks cache - generate_cache_userranks(); - - 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('SpecialGroups.php, line ' . __LINE__); - $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('SpecialGroups.php, line ' . __LINE__); - unset($pending[$i]); - } - } - } - // memberships updated/changed, regenerate ranks cache - generate_cache_userranks(); - - echo '
' . $lang->get('groupcp_msg_pending_updated') . '
'; - break; - } - } - - if ( isset($_GET['act']) && $_GET['act'] == 'update' && !$is_member && $row['group_type'] == GROUP_OPEN && !$can_do_admin_stuff ) - { - $q = $db->sql_query('INSERT INTO '.table_prefix.'group_members(group_id,user_id) VALUES(' . $gid . ', ' . $session->user_id . ');'); - if (!$q) - $db->_die('SpecialGroups.php, line ' . __LINE__); - echo '
' . $lang->get('groupcp_msg_self_added') . '
'; - - $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) AS num_comments - 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,u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod - ORDER BY m.is_mod DESC,u.username ASC - LIMIT 1;'); - if ( !$q ) - $db->_die('SpecialGroups.php, line ' . __LINE__); - - $r = $db->fetchrow(); - $members[] = $r; - $db->free_result(); - - } - - if ( isset($_GET['act']) && $_GET['act'] == 'update' && !$is_member && $row['group_type'] == GROUP_REQUEST && !$is_pending && !$can_do_admin_stuff ) - { - $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('SpecialGroups.php, line ' . __LINE__); - echo '
' . $lang->get('groupcp_msg_membership_requested') . '
'; - } - - $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 .= ' ' . $lang->get('groupcp_msg_status_pending'); - else - $state_btns .= ' '; - } - - if ( !$can_do_admin_stuff && $row['group_type'] == GROUP_OPEN && !$is_member ) - { - $state_btns .= ' '; - } - - $g_name_local = 'groupcp_grp_' . strtolower($row['group_name']); - $str = $lang->get($g_name_local); - if ( $str != $g_name_local ) - $row['group_name'] = $str; - - echo '
-
- - - - - - - - - - - - - - - - - ' . ( ( $is_mod || $session->user_level >= USER_LEVEL_ADMIN ) ? ' - - - - ' : '' ) . ' -
' . $lang->get('groupcp_th_group_info') . '
' . $lang->get('groupcp_lbl_group_name') . '' . $row['group_name'] . ( $row['system_group'] == 1 ? ' ' . $lang->get('groupcp_msg_system_group') : '' ) . '
' . $lang->get('groupcp_lbl_status') . '' . $status . '
' . $lang->get('groupcp_lbl_state') . '' . $state_btns . '
- -
-
- -
'; - if ( sizeof ( $pending ) > 0 && $can_do_admin_stuff ) - { - echo '
- -

' . $lang->get('groupcp_th_pending_memberships') . '

-
- - - - - - - - '; - $cls = 'row2'; - foreach ( $pending as $member ) - { - - $date = enano_date(ED_DATE, $member['reg_time']); - $cls = ( $cls == 'row2' ) ? 'row1' : 'row2'; - $addy = $email->encryptEmail($member['email']); - - echo " - - - - - - "; - } - echo '
' . $lang->get('groupcp_th_username') . '' . $lang->get('groupcp_th_email') . '' . $lang->get('groupcp_th_reg_time') . '' . $lang->get('groupcp_th_comments') . '' . $lang->get('groupcp_th_select') . '
{$member['username']}{$addy}{$date}{$member['num_comments']}
-
-
- With selected: - - -
-
'; - } - echo '
-

' . $lang->get('groupcp_th_group_members') . '

-
- - - - - - - ' . ( ( $can_do_admin_stuff ) ? ' - - ' : '' ) . ' - - - - '; - $mod_printed = false; - $mem_printed = false; - $cls = 'row2'; - - foreach ( $members as $member ) - { - if ( $member['is_mod'] != 1 ) - break; - - $date = enano_date(ED_DATE, $member['reg_time']); - $cls = ( $cls == 'row2' ) ? 'row1' : 'row2'; - $addy = $email->encryptEmail($member['email']); - - $mod_printed = true; - - echo " - - - - - " . ( ( $can_do_admin_stuff ) ? " - - " : '' ) . " - "; - } - if (!$mod_printed) - echo ''; - echo ''; - foreach ( $members as $member ) - { - if ( $member['is_mod'] == 1 ) - continue; - - $date = enano_date(ED_DATE, $member['reg_time']); - $cls = ( $cls == 'row2' ) ? 'row1' : 'row2'; - $addy = $email->encryptEmail($member['email']); - - $mem_printed = true; - - echo " - - - - - " . ( ( $can_do_admin_stuff ) ? " - - " : '' ) . " - "; - } - if (!$mem_printed) - echo ''; - echo '
' . $lang->get('groupcp_th_username') . '' . $lang->get('groupcp_th_email') . '' . $lang->get('groupcp_th_reg_time') . '' . $lang->get('groupcp_th_comments') . '' . $lang->get('groupcp_th_remove') . '
' . $lang->get('groupcp_th_group_mods') . '
{$member['username']}{$addy}{$date}{$member['num_comments']}
' . $lang->get('groupcp_msg_no_mods') . '
' . $lang->get('groupcp_th_group_members') . '
{$member['username']}{$addy}{$date}{$member['num_comments']}
' . $lang->get('groupcp_msg_no_members') . '
-
'; - if ( $can_do_admin_stuff ) - { - echo "
get('groupcp_btn_remove_selected') . "\" />
"; - } - echo ' -
'; - if ( $can_do_admin_stuff ) - { - echo '
-
- - - - - - - - - - - - - -
' . $lang->get('groupcp_th_add_member') . '
' . $lang->get('groupcp_lbl_username') . '' . $template->username_field('add_username') . '
' . $lang->get('groupcp_lbl_moderator') . '
- -
-
- -
'; - } - } - else - { - echo '
'; - echo '
- - - - - - - - '; - $taboo = 'WHERE group_name != \'' . implode('\' AND group_name != \'', $taboo) . '\''; - $q = $db->sql_query('SELECT group_id,group_name FROM '.table_prefix.'groups '.$taboo.' AND group_type != ' . GROUP_HIDDEN . ' ORDER BY group_name ASC;'); - if(!$q) - { - echo $db->get_error(); - $template->footer(); - return; - } - if($db->numrows() > 0) - { - echo ' - - - - '; - } - $db->free_result(); - echo '
' . $lang->get('groupcp_th_select_group') . '
- ' . $lang->get('groupcp_lbl_current_memberships') . ' - '; - $taboo = Array('Everyone'); - if ( sizeof ( $session->groups ) > count($taboo) ) - { - echo ' - '; - } - else - { - echo 'None'; - } - - echo '
- ' . $lang->get('groupcp_lbl_non_memberships') . ' - - - -
-
-
'; - } - $template->footer(); + // 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('SpecialGroups.php, line ' . __LINE__); + 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('SpecialGroups.php, line ' . __LINE__); + foreach ( $members as $i => $member ) + { + if ( $member['member_id'] == $r['member_id'] ) + $members[$i]['is_mod'] = (int)$mod; + } + echo '
' . $lang->get('groupcp_msg_user_already_in_mod_updated', array('username' => $username)) . '
'; + } + else + { + echo '
' . $lang->get('groupcp_msg_user_already_in', array('username' => $username)) . '
'; + } + 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('SpecialGroups.php, line ' . __LINE__); + echo '
' . $lang->get('groupcp_msg_user_added', array('username' => $username)) . '
'; + + $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) AS num_comments + 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,u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod + ORDER BY m.is_mod DESC,u.username ASC + LIMIT 1;'); + if ( !$q ) + $db->_die('SpecialGroups.php, line ' . __LINE__); + + $r = $db->fetchrow(); + $members[] = $r; + $db->free_result(); + + // just added a user to the group, so regenerate the ranks cache + generate_cache_userranks(); + + 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('SpecialGroups.php, line ' . __LINE__); + unset($members[$i]); + } + } + // regenerate the ranks cache + generate_cache_userranks(); + + 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('SpecialGroups.php, line ' . __LINE__); + $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('SpecialGroups.php, line ' . __LINE__); + unset($pending[$i]); + } + } + } + // memberships updated/changed, regenerate ranks cache + generate_cache_userranks(); + + echo '
' . $lang->get('groupcp_msg_pending_updated') . '
'; + break; + } + } + + if ( isset($_GET['act']) && $_GET['act'] == 'update' && !$is_member && $row['group_type'] == GROUP_OPEN && !$can_do_admin_stuff ) + { + $q = $db->sql_query('INSERT INTO '.table_prefix.'group_members(group_id,user_id) VALUES(' . $gid . ', ' . $session->user_id . ');'); + if (!$q) + $db->_die('SpecialGroups.php, line ' . __LINE__); + echo '
' . $lang->get('groupcp_msg_self_added') . '
'; + + $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) AS num_comments + 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,u.username,u.email,u.reg_time,m.member_id,m.user_id,m.is_mod + ORDER BY m.is_mod DESC,u.username ASC + LIMIT 1;'); + if ( !$q ) + $db->_die('SpecialGroups.php, line ' . __LINE__); + + $r = $db->fetchrow(); + $members[] = $r; + $db->free_result(); + + } + + if ( isset($_GET['act']) && $_GET['act'] == 'update' && !$is_member && $row['group_type'] == GROUP_REQUEST && !$is_pending && !$can_do_admin_stuff ) + { + $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('SpecialGroups.php, line ' . __LINE__); + echo '
' . $lang->get('groupcp_msg_membership_requested') . '
'; + } + + $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 .= ' ' . $lang->get('groupcp_msg_status_pending'); + else + $state_btns .= ' '; + } + + if ( !$can_do_admin_stuff && $row['group_type'] == GROUP_OPEN && !$is_member ) + { + $state_btns .= ' '; + } + + $g_name_local = 'groupcp_grp_' . strtolower($row['group_name']); + $str = $lang->get($g_name_local); + if ( $str != $g_name_local ) + $row['group_name'] = $str; + + echo '
+
+ + + + + + + + + + + + + + + + + ' . ( ( $is_mod || $session->user_level >= USER_LEVEL_ADMIN ) ? ' + + + + ' : '' ) . ' +
' . $lang->get('groupcp_th_group_info') . '
' . $lang->get('groupcp_lbl_group_name') . '' . $row['group_name'] . ( $row['system_group'] == 1 ? ' ' . $lang->get('groupcp_msg_system_group') : '' ) . '
' . $lang->get('groupcp_lbl_status') . '' . $status . '
' . $lang->get('groupcp_lbl_state') . '' . $state_btns . '
+ +
+
+ +
'; + if ( sizeof ( $pending ) > 0 && $can_do_admin_stuff ) + { + echo '
+ +

' . $lang->get('groupcp_th_pending_memberships') . '

+
+ + + + + + + + '; + $cls = 'row2'; + foreach ( $pending as $member ) + { + + $date = enano_date(ED_DATE, $member['reg_time']); + $cls = ( $cls == 'row2' ) ? 'row1' : 'row2'; + $addy = $email->encryptEmail($member['email']); + + echo " + + + + + + "; + } + echo '
' . $lang->get('groupcp_th_username') . '' . $lang->get('groupcp_th_email') . '' . $lang->get('groupcp_th_reg_time') . '' . $lang->get('groupcp_th_comments') . '' . $lang->get('groupcp_th_select') . '
{$member['username']}{$addy}{$date}{$member['num_comments']}
+
+
+ With selected: + + +
+
'; + } + echo '
+

' . $lang->get('groupcp_th_group_members') . '

+
+ + + + + + + ' . ( ( $can_do_admin_stuff ) ? ' + + ' : '' ) . ' + + + + '; + $mod_printed = false; + $mem_printed = false; + $cls = 'row2'; + + foreach ( $members as $member ) + { + if ( $member['is_mod'] != 1 ) + break; + + $date = enano_date(ED_DATE, $member['reg_time']); + $cls = ( $cls == 'row2' ) ? 'row1' : 'row2'; + $addy = $email->encryptEmail($member['email']); + + $mod_printed = true; + + echo " + + + + + " . ( ( $can_do_admin_stuff ) ? " + + " : '' ) . " + "; + } + if (!$mod_printed) + echo ''; + echo ''; + foreach ( $members as $member ) + { + if ( $member['is_mod'] == 1 ) + continue; + + $date = enano_date(ED_DATE, $member['reg_time']); + $cls = ( $cls == 'row2' ) ? 'row1' : 'row2'; + $addy = $email->encryptEmail($member['email']); + + $mem_printed = true; + + echo " + + + + + " . ( ( $can_do_admin_stuff ) ? " + + " : '' ) . " + "; + } + if (!$mem_printed) + echo ''; + echo '
' . $lang->get('groupcp_th_username') . '' . $lang->get('groupcp_th_email') . '' . $lang->get('groupcp_th_reg_time') . '' . $lang->get('groupcp_th_comments') . '' . $lang->get('groupcp_th_remove') . '
' . $lang->get('groupcp_th_group_mods') . '
{$member['username']}{$addy}{$date}{$member['num_comments']}
' . $lang->get('groupcp_msg_no_mods') . '
' . $lang->get('groupcp_th_group_members') . '
{$member['username']}{$addy}{$date}{$member['num_comments']}
' . $lang->get('groupcp_msg_no_members') . '
+
'; + if ( $can_do_admin_stuff ) + { + echo "
get('groupcp_btn_remove_selected') . "\" />
"; + } + echo ' +
'; + if ( $can_do_admin_stuff ) + { + echo '
+
+ + + + + + + + + + + + + +
' . $lang->get('groupcp_th_add_member') . '
' . $lang->get('groupcp_lbl_username') . '' . $template->username_field('add_username') . '
' . $lang->get('groupcp_lbl_moderator') . '
+ +
+
+ +
'; + } + } + else + { + echo '
'; + echo '
+ + + + + + + + '; + $taboo = 'WHERE group_name != \'' . implode('\' AND group_name != \'', $taboo) . '\''; + $q = $db->sql_query('SELECT group_id,group_name FROM '.table_prefix.'groups '.$taboo.' AND group_type != ' . GROUP_HIDDEN . ' ORDER BY group_name ASC;'); + if(!$q) + { + echo $db->get_error(); + $template->footer(); + return; + } + if($db->numrows() > 0) + { + echo ' + + + + '; + } + $db->free_result(); + echo '
' . $lang->get('groupcp_th_select_group') . '
+ ' . $lang->get('groupcp_lbl_current_memberships') . ' + '; + $taboo = Array('Everyone'); + if ( sizeof ( $session->groups ) > count($taboo) ) + { + echo ' + '; + } + else + { + echo 'None'; + } + + echo '
+ ' . $lang->get('groupcp_lbl_non_memberships') . ' + + + +
+
+
'; + } + $template->footer(); } ?>