Просмотр файла groupcp.php

Размер файла: 21.98Kb
<?php
/***************************************************************************
 *                            groupcp.php
 *                            -------------------
 *      Разработка модуля: [email protected] 2011 год.
 ***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

$userdata = session_pagestart($user_ip, PAGE_GROUPCP);
init_userprefs($userdata);

if ( isset($HTTP_GET_VARS[POST_GROUPS_URL]) || isset($HTTP_POST_VARS[POST_GROUPS_URL]) )
{
	$group_id = ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) ) ? intval($HTTP_POST_VARS[POST_GROUPS_URL]) : intval($HTTP_GET_VARS[POST_GROUPS_URL]);
}
else
{
	$group_id = '';
}
if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
{
	$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
}
else
{
	$mode = '';
}
if ( isset($HTTP_POST_VARS[POST_POST_URL]) || isset($HTTP_GET_VARS[POST_POST_URL]))
{
	$shout_id = ( intval($HTTP_POST_VARS[POST_POST_URL]) ) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]);
}
else
{
        $shout_id = '';
}

$sid = ( isset($HTTP_POST_VARS['sid']) ) ? $HTTP_POST_VARS['sid'] : '';
$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
$start = ($start < 0) ? 0 : $start;

$cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? TRUE : FALSE;
$confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? TRUE : FALSE;

$group_sql = ($group_id == '') ? "ORDER BY g.group_id DESC LIMIT " . $start . ", 10" : "AND g.group_id = $group_id";
$sql = "SELECT g.*, u.user_id, u.username 
        FROM " . GROUPS_TABLE . " g, " . USERS_TABLE . " u	
	WHERE g.group_moderator = u.user_id
	AND g.group_single_user <> " . TRUE . "	
	$group_sql";
	
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
}             
$group_list = array();
while ($row = $db->sql_fetchrow($result))
{
	$group_list[] = $row;
}
$db->sql_freeresult($result);
$group_list_count = count($group_list);

if ($group_id != '')
{   
        $sql = "SELECT g.group_id, g.group_moderator, g.group_logo, ug.user_id
                FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
		WHERE g.group_id = " . $group_id . "
		AND g.group_id = ug.group_id";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Error groups information', '', __LINE__, __FILE__, $sql);
	}
	$group_info = $db->sql_fetchrow($result);	                             
        $db->sql_freeresult($result); 
                
        if ( $group_info['group_id'] == '' )
        {
	         message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
        }     
        
        $sql = "SELECT ug.group_id, ug.user_pending, u.user_id, u.username, u.user_posts, u.user_regdate, u.user_avatar, u.user_avatar_type, u.user_allowavatar  
	        FROM " . USER_GROUP_TABLE . " ug, " . USERS_TABLE . " u
	        WHERE ug.user_id = u.user_id
	        AND ug.group_id = '" . $group_info['group_id'] . "'
	        ORDER BY u.user_regdate LIMIT 4";
        if ( !($result = $db->sql_query($sql)) )
        {
	        message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
        }             
        $user_group = array();
        while ($row = $db->sql_fetchrow($result))
        {
	        $user_group[] = $row;
        }
        $db->sql_freeresult($result);       
        $user_group_count = count($user_group);  
                
        $sql = "SELECT s.*, u.username, u.user_posts, u.user_nic_color 
                FROM " . GROUP_SHOUTBOX_TABLE . " s, " . USERS_TABLE . " u
		WHERE s.shout_user_id = u.user_id 
		AND s.group_id = '" . $group_info['group_id'] . "'
		ORDER BY s.shout_session_time DESC 
		LIMIT $start, 4";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get shoutbox information', '', __LINE__, __FILE__, $sql);
	}
	$shout_group = array();
        while ($row = $db->sql_fetchrow($result))
        {
	        $shout_group[] = $row;
        }       
        $db->sql_freeresult($result);
	$count_shout_group = count($shout_group);
        
	$sql = "SELECT COUNT(shout_id) as total 
		FROM " . GROUP_SHOUTBOX_TABLE . "
		WHERE group_id = " . $group_info['group_id'];			
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get shoutbox stat information', '', __LINE__, __FILE__, $sql);
	}
	$totals = $db->sql_fetchrow($result);
	$totals = $totals['total'];	
	$pagination = ($totals > 4) ? generate_pagination("groupcp.$phpEx?g=" . $group_info['group_id'] . "&", $totals, 4, $start) : '';
	
        require_once($phpbb_root_path . 'includes/bbcode.'.$phpEx);
        $template->assign_block_vars('shout', array());    
           
        if ( $userdata['session_logged_in'] ) 
        {               
                 $submit = (isset($HTTP_POST_VARS['submit']) && isset($HTTP_POST_VARS['message'])) ? 1 : 0;
                 $message = (isset($HTTP_POST_VARS['message'])) ? trim($HTTP_POST_VARS['message']) : '';

                 if ($shout_id != '') 
                 {
                          $sql = "SELECT shout_id, shout_user_id, shout_username, shout_text 
                                  FROM " . GROUP_SHOUTBOX_TABLE . "
		                  WHERE shout_id = " . $shout_id;			
	                  if ( !($result = $db->sql_query($sql)) )
	                  {
		                  message_die(GENERAL_ERROR, 'Could not get shoutbox stat information', '', __LINE__, __FILE__, $sql);
	                  }
	                  $shout_info = $db->sql_fetchrow($result);             	        
       	         }
                 if ($shout_info['shout_user_id'] == $userdata['user_id'] || $userdata['user_id'] == $group_info['group_moderator']  || $userdata['user_level'] == ADMIN)
		 {
		          $create_level = '1'; 
		 }                        
                 if ((isset($HTTP_POST_VARS['submit']) && isset($HTTP_POST_VARS['message'])) && !empty($message))
                 {
	                  if (isset($HTTP_POST_VARS['submit']) && !empty($message))
	                  {
		                  require_once($phpbb_root_path . 'includes/functions_post.'.$phpEx);
		                  $bbcode_uid = make_bbcode_uid();
		                  $message = prepare_message(trim($message), $html_on, $bbcode_on, $smilies_on, $bbcode_uid);		                  		                  
		               		                        	                  
		                  if ( $shout_info['shout_id'] != '' && $create_level != '' && $mode == 'edit')
		                  {
		                          $sql = "UPDATE " . GROUP_SHOUTBOX_TABLE . " SET 
		                                         group_id = " . $group_info['group_id'] . ", 
		                                         shout_username = '" . $shout_info['shout_username'] . "', 
		                                         shout_user_id = " . $shout_info['shout_user_id'] . ", 		                                        
		                                         shout_text = '" . str_replace("\'", "''", $message) . "', 
		                                         shout_bbcode_uid = '$bbcode_uid' 
			                          WHERE shout_id = " . $shout_info['shout_id'] . " LIMIT 1";
		                  }        
		                  else
		                  {
		                          $sql = "INSERT INTO " . GROUP_SHOUTBOX_TABLE . " (group_id, shout_username, shout_user_id, shout_session_time, shout_ip, shout_text, enable_bbcode, enable_html, enable_smilies, shout_bbcode_uid ) 
				                  VALUES (" . $group_info['group_id'] . ", '" . $userdata['username'] . "', '" . $userdata['user_id'] . "', '" . time() . "', '$user_ip', '$message', 1, 0, 1, '" . $bbcode_uid . "')";
		                  }
		                  if (!$result = $db->sql_query($sql)) 
		                  {
			                  message_die(GENERAL_ERROR, 'Error inserting shout.', '', __LINE__, __FILE__, $sql);
		                  }
		                  else
		                  {
			                  $template->assign_vars(array(
			                         'META' => '<meta http-equiv="refresh" content="2;url=' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $group_id) . '">')
		                          );
		                          $error_message = '<br />Сообщение успешно добавлено/изменено<br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $group_id) . '">', '</a>');		                          			                
		                  }
		                  message_die(GENERAL_MESSAGE, $error_message);
	                  }
                 } 
                 else if ( $shout_info['shout_id'] != '' && $mode == 'delete' )
                 {
	                  if ($userdata['user_id'] != $group_info['group_moderator'] || $userdata['user_level'] != ADMIN ) 
	                  {
	                           message_die(GENERAL_MESSAGE, $lang['Reached_on_error']);
	                  }
	                  if ( !$confirm )
	                  {
		                  $s_hidden_fields = '<input type="hidden" name="confirm" value="true" />';
		                  $s_hidden_fields .= '<input type="hidden" name="mode" value="delete" />';
		                  $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $shout_info['shout_id'] . '" />';
		                 
		                  include($phpbb_root_path . 'includes/page_header.'.$phpEx);
		                  $template->set_filenames(array(
			                 'confirm_body' => 'confirm_body.tpl')
		                  );
		
		                  $template->assign_vars(array(
			                  'MESSAGE_TITLE' => $lang['Information'],
			                  'MESSAGE_TEXT' => $lang['Guest_delete_coment'],
			                  'L_YES' => $lang['Yes'],
			                  'L_NO' => $lang['Yes'],
			                  'S_CONFIRM_ACTION' => append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $group_info['group_id']),
			                  'S_HIDDEN_FIELDS' => $s_hidden_fields)
		                  );

		                 $template->pparse('confirm_body');
		                 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

	                  } 
	                  else
	                  { 	
		                 $sql = "DELETE FROM " . GROUP_SHOUTBOX_TABLE . " 
			                 WHERE shout_id = '" . $shout_info['shout_id'] . "'
			                 AND group_id = " . $group_info['group_id'];
		                 if (!$result = $db->sql_query($sql)) 
		                 {
			                 message_die(GENERAL_ERROR, 'Error removing shout.', '', __LINE__, __FILE__, $sql);
		                 }
		                 else
		                 {			         
			                 message_die(GENERAL_MESSAGE, 'Пост успешно удален!<br/>' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $group_id) . '">', '</a>'));
		                 }
		          } 
                 }
                 else if ( $shout_info['shout_id'] != '' && $mode=='quote' )
	         {
		         if(!empty($shout_info['shout_username']))
		         {
			          $message = $shout_info['shout_username'] . ',';
		         }
		         else
		         {
			          $message = '';
		         }
	         } 
	         else if ( $shout_info['shout_id'] != '' && $create_level != '' && $mode == 'edit' )
	         {
		         if(!empty($shout_info['shout_text']))
		         {
			          $message = $shout_info['shout_text'];
		         }
		         else
		         {
			          $message = '';
		         }
	         }
	         $ermessage = $lang['No_post_mode'];		                  	
                 $template->assign_block_vars('shout.quick', array(
                        'MESSAGE' => $message)
                 ); 
        }	
                    
}
else
{
        $sql =  "SELECT COUNT(*) as total FROM " . GROUPS_TABLE . " WHERE group_single_user <> " . TRUE . "";
        $result = $db->sql_query($sql);
        if( $result )
        { 
               $row = $db->sql_fetchrow($result);
	       $num = $row['total'];	       
        }
        $db->sql_freeresult($result); 
        
        $template->assign_block_vars('groups', array());
        $pagination = generate_pagination("groupcp.$phpEx?mode=start", $num, 10, $start). '';
}
define('SHOW_ONLINE', true);
       
$page_title = $lang['Group_Control_Panel'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$template->set_filenames(array(
	'body' => 'community/community_index_body.tpl')
);

$create_link = ($userdata['session_logged_in'] == 1 && $userdata['user_posts'] >= 500) ? '<a href="group_config.'.$phpEx.'" class="buttom">' . $lang['New_group'] . '</a>' : '';

if($group_id != '' && $mode == 'edit')
{
         $s_groupcp_action =  append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $group_id . "&" . POST_POST_URL . "=" . $shout_id . "&mode=edit");
}
else
{
         $s_groupcp_action = append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $group_id);
}   
      
$template->assign_vars(array(
        'L_GROUP_TYPE' => $lang['Group_type'],
        'L_GROUPS' => $lang['Non_logged_in_groups'],
	'L_ALL_GROUPS' => $lang['Group_Information'],
        'L_GROUP_MODERATOR' => $lang['Group_moderator'],
        'L_JOINED' => $lang['Joined'], 
        'CREATE_LINK' => $create_link,
	'GROUP_MEMBERSHIP_DETAILS' => $lang['Group_member_details'],
	'GROUP_LOGO' => ($group_info['group_logo'] != '') ? '<div><img src="images/group_logo/' . $group_info['group_logo'] . '" alt="" /></div>' : '',
	'S_GROUPCP_CHAT_ACTION' => $s_groupcp_action,
	'TOTAL' => $num,
	'PAGINATION' => $pagination)
);

for($i = 0; $i < $group_list_count; $i++)
{
         if ( $group_list[$i]['group_id'] != '' )
         {		            		    
		  $group_id = $group_list[$i]['group_id'];		  
		  if  ( $group_list[$i]['group_type'] != GROUP_HIDDEN || $userdata['user_id'] == $group_list[$i]['group_moderator'] || $userdata['user_level'] == ADMIN )
		  {				                  
			  $group_type = ($group_list[$i]['group_type'] == GROUP_OPEN) ? $lang['Group_open'] : $lang['Group_closed'];
			  $group_edit = ($userdata['user_id'] == $group_info['group_moderator'] || $userdata['user_level'] == ADMIN ) ? append_sid("group_config.$phpEx?" . POST_GROUPS_URL . "=" . $group_id . "&amp;sid=" . $userdata['session_id']) : '';
			  $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';			  
			  $template->assign_block_vars('switch_groups_remaining', array(
			           'ROW_CLASS' => $row_class,
			           'GROUP_TYPE' => $group_type,
			           'GROUP_URL' => append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $group_id . "&amp;sid=" . $userdata['session_id']),
			           'GROUP_NAME' => $group_list[$i]['group_name'],
			           'GROUP_DESC' => $group_list[$i]['group_description'],
			           'GROUP_MOD' => $group_list[$i]['username'],
			           'GROUP_EDIT' => ($group_edit != '' ) ? '<a href="' . $group_edit . '" class="buttom">Редактировать</a>' : '', 
			           'GROUP_LOGO' => ($group_list[$i]['group_logo'] != '') ? '<img src="images/group_logo/' . $group_list[$i]['group_logo'] . '" alt="" />' : 'no logo') 
			  );						
		          if ( $userdata['session_logged_in'] ) 
                          {	                  
	                           $memberships = $lang['Non_member_groups'] . '<br/><a href=' . append_sid("group_user.$phpEx?" . POST_GROUPS_URL . "=" . $group_id . "&amp;sid=" . $userdata['session_id']) . '>' . $lang['Group_member_join'] . '</a>';
	                           $sql = "SELECT user_pending 
	                                   FROM " . USER_GROUP_TABLE . "
		                           WHERE group_id = " . $group_id . "
		                           AND user_id = " . $userdata['user_id'];
	                           if ( !($result = $db->sql_query($sql)) )
	                           {
		                           message_die(GENERAL_ERROR, 'Error pending user information', '', __LINE__, __FILE__, $sql);
	                           }	                  
                                   while ($row = $db->sql_fetchrow($result))
                                   {
	                                   $memberships = ( $row['user_pending'] ) ? $lang['Memberships_pending'] : $lang['Current_memberships'];	                      	                                	                       	                  
                                   }
                                   $template->assign_block_vars('switch_groups_remaining.joined', array(
	                                   'GROUP_PENDING' => $memberships)
	                           );
                          }
                 } 
         }
         else
         {
                  $template->assign_block_vars('switch_no_groups', array(
                          'NO_GROUPS' => $lang['No_groups_exist'])
                  );
         }                 
}

if ($group_info['group_id'] != '')
{                	     
        $template->assign_block_vars('group', array(
               'L_GROUP_MEMBERS' => $lang['Group_Members'],
               'U_GROUP_MEMBERS' => append_sid("group_user.$phpEx?" . POST_GROUPS_URL . "=" . $group_id . "&amp;sid=" . $userdata['session_id']))
	);     	
        for ($i = 0; $i < $user_group_count; $i++)
        {
                $user_avatar = '';
	        if ( $user_group[$i]['user_avatar_type'] && $user_group[$i]['user_id'] != ANONYMOUS && $user_group[$i]['user_allowavatar'] )
	        {
		        switch( $user_group[$i]['user_avatar_type'] )
		        {
			   case USER_AVATAR_UPLOAD:
				$user_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $user_group[$i]['user_avatar'] . '" alt="" width="70" height="70"/>' : '';
				break;
			   case USER_AVATAR_REMOTE:
				$user_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $user_group[$i]['user_avatar'] . '" alt="" width="70" height="70"/>' : '';
				break;
			   case USER_AVATAR_GALLERY:
				$user_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $user_group[$i]['user_avatar'] . '" alt="" width="70" height="70"/>' : '';
				break;
		        }
	        }
	        $user_posts = $user_group[$i]['user_posts'];
	        $user_regdate = create_date($board_config['default_dateformat'], $user_group[$i]['user_regdate'], $board_config['board_timezone']);
	        $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $user_group[$i]['user_id']);
	        $users = '<a href="' . $temp_url . '">' . $user_group[$i]['username'] . '</a>';          		                   
                $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';
                $template->assign_block_vars('group.user', array(
                         'ROW_CLASS' => $row_class,
	                 'USER' => $users,
	                 'USER_POSTS' => $user_posts,	                                 
	                 'USER_AVATAR' => $user_avatar,
	                 'USER_REGDATE' => $user_regdate)
	        );
        }        
	for ($i = 0; $i < $count_shout_group; $i++)
	{
		$poster = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $shout_group[$i]['shout_user_id']) . '" style="color: ' . $shout_group[$i]['user_nic_color'] . '">' . $shout_group[$i]['username'] . '</a>';		
		$quote = ( $userdata['session_logged_in'] ) ? '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . '=' . $shout_group[$i]['group_id'] . '&' . POST_POST_URL . '=' . $shout_group[$i]['shout_id']) . '&mode=quote">Отв</a>' : '';
		
		if ( $userdata['user_id'] == $group_info['group_moderator']  ||  $userdata['user_level'] == ADMIN )
	        {
		        $delete = '|<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . '=' . $shout_group[$i]['group_id'] . '&' . POST_POST_URL . '=' . $shout_group[$i]['shout_id']) . '&mode=delete">' . $lang['Delete_post'] . '</a>';
		}
		else
	        {
	                $delete = '';
	        }   
	        if ( $userdata['user_id'] == $shout_group[$i]['shout_user_id'] || $userdata['user_id'] == $group_info['group_moderator']  ||  $userdata['user_level'] == ADMIN )
	        {
		        $edit = '|<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . '=' . $shout_group[$i]['group_id'] . '&' . POST_POST_URL . '=' . $shout_group[$i]['shout_id']) . '&mode=edit">' . $lang['Edit_delete_post'] . '</a>';
		}
		else
	        {
	                $edit = '';
	        }      
		
		$bbcode_uid = $shout_group[$i]['shout_bbcode_uid'];		
		$shout_text = $shout_group[$i]['shout_text'];
		$shout_text = make_clickable($shout_text);
		$shout_text = smilies_pass($shout_text);
		$shout_text = ($bbcode_uid != '') ? bbencode_second_pass($shout_text, $bbcode_uid) : '';
		       
		$shout_text = str_replace("\n", "\n<br />\n", $shout_text);
                $nomer_posta = $i + $start + 1;
                $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';             
		
		$template->assign_block_vars('shout.shoutrow', array(
			 'ROW_CLASS' => $row_class,
			 'NUMBER' => $nomer_posta,
			 'SHOUT_TEXT' => $shout_text,
			 'TIME' => create_date($board_config['default_dateformat'], $shout_group[$i]['shout_session_time'], $board_config['board_timezone']),
			 'POSTER' => $poster,
			 'USER_POSTS' => $shout_group[$i]['user_posts'],
                         'QUOTE' => $quote,
                         'EDIT' => $edit,
			 'DELETE' => $delete)
		);	                         	                           
	}                 
}
 
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>