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

Размер файла: 9.8Kb
<?php
/***************************************************************************
 *                            styles.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['style']) || isset($HTTP_POST_VARS['style']) )
{
	$style = ( isset($HTTP_POST_VARS['style']) ) ? intval($HTTP_POST_VARS['style']) : intval($HTTP_GET_VARS['style']);
}
else
{
	$style = '';
}

$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;

$style_sql = ($style == '') ? "ORDER BY s.style_id DESC LIMIT " . $start . ", 10" : "AND s.style_id = $style";
$sql = "SELECT s.*, u.user_id, u.username 
        FROM " . $table_prefix . "css_style s, " . USERS_TABLE . " u	
	WHERE s.user_id = u.user_id
	$style_sql";	
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
}             
$style_list = array();
while ($row = $db->sql_fetchrow($result))
{
	$style_list[] = $row;
}
$db->sql_freeresult($result);
$style_list_count = count($style_list);

if($style_list_count == '' && $style != '')
{
       message_die(GENERAL_MESSAGE, 'УппС.. Нет такого стиля!');
}

$sql =  "SELECT COUNT(style_id) as total FROM " . $table_prefix . "css_style";
$result = $db->sql_query($sql);
if( $result )
{ 
       $row = $db->sql_fetchrow($result);
       $num = $row['total'];	       
}
$db->sql_freeresult($result); 

$pagination = generate_pagination("styles.$phpEx?style=$style", $num, 10, $start);

$gen_simple_header = ($style != '') ? TRUE : FALSE;     
$page_title = 'Стили пользователей';
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$template->set_filenames(array(
	'body' => 'styles_index_body.tpl')
);

$submit = ( $userdata['session_logged_in'] && $style ) ? '<br/><input class="subbutton" type="submit" name="add" value="Экспорт в профиль" />' : '';

$template->assign_vars(array(
        'CREATE_LINK' => ($style == '') ? '<a href="style_edit.'.$phpEx.'" class="buttom">Создать новый</a>' : '',
        'SUBMIT' => $submit,
        'PAGINATION' => $pagination)
);

for($i = 0; $i < $style_list_count; $i++)
{
         if ( $style_list[$i]['style_id'] != '' )
         {		            		    
		if(($userdata['user_id'] == $style_list[$i]['user_id'] || $userdata['user_level'] == ADMIN) && $style)
		{
		        $style_edit = '<a href="' . append_sid("style_edit.$phpEx?style=" . $style_list[$i]['style_id']) . '" class="buttom">Редактировать</a>';
		        $style_delete = '<a href="' . append_sid("style_edit.$phpEx?style=" . $style_list[$i]['style_id']) . '&amp;delete" class="buttom">Удалить</a>';
		}     
		else
		{
		        $style_edit = '';
		        $style_delete = ''; 
		}   
		$temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $style_list[$i]['user_id']);
	        $users = '<a href="' . $temp_url . '">' . $style_list[$i]['username'] . '</a>'; 
		$row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';			  
		$template->assign_block_vars('switch_styles', array(
			'ROW_CLASS' => $row_class,
			'STYLE_URL' => append_sid("styles.$phpEx?style=" . $style_list[$i]['style_id'] . "&amp;sid=" . $userdata['session_id']),
			'STYLE_NAME' => $style_list[$i]['style_name'],
			'USERS' => $users,
			'STYLE_EDIT' => $style_edit,
			'STYLE_DELETE' => $style_delete)

		);
		if($style != '')
		{
		        $width = ($style_list[$i]['body_max']) ? 'max-' : ''; 
		        $template->assign_block_vars('css', array(
		                 'BODY_BACKGROUND' => ($style_list[$i]['body_background']) ? 'background-color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['body_background'])) . ';' : '', 	
                                 'BODY_COLOR' => ($style_list[$i]['body_color']) ? 'color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['body_color'])) . ';' : '', 	
                                 'BODY_BORDER' => ($style_list[$i]['body_border']) ? 'border: 1px solid ' . str_replace('"', '&quot;', strip_tags($style_list[$i]['body_border'])) . ';' : '', 	
                                 'BODY_WIDTH' => ($style_list[$i]['body_width']) ? $width . 'width:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['body_width'])) . ';' : '', 		
                                 'A_LINK' => ($style_list[$i]['a_link']) ? str_replace('"', '&quot;', strip_tags($style_list[$i]['a_link'])) : '', 
                                 'A_HOVER' => ($style_list[$i]['a_hower']) ? str_replace('"', '&quot;', strip_tags($style_list[$i]['a_hower'])) : '', 	
                                 'TOP_BACKGROUND' => ($style_list[$i]['top_background']) ? 'background-color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['top_background'])) . ';' : '', 	
                                 'TOP_COLOR' => ($style_list[$i]['top_color']) ? 'color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['top_color'])) . ';' : '', 	
                                 'TOP_BORDER' => ($style_list[$i]['top_border']) ? 'border: 1px solid ' . str_replace('"', '&quot;', strip_tags($style_list[$i]['top_border'])) . ';' : '', 	
                                 'TAB_BACKGROUND' => ($style_list[$i]['tab_background']) ? 'background-color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['tab_background'])) . ';' : '', 	
                                 'TAB_COLOR' => ($style_list[$i]['tab_color']) ? 'color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['tab_color'])) . ';' : '', 	
                                 'TAB_BORDER' => ($style_list[$i]['tab_border']) ? 'border: 1px solid ' . str_replace('"', '&quot;', strip_tags($style_list[$i]['tab_border'])) . ';' : '', 	          	
                                 'ROW1_BACKGROUND' => ($style_list[$i]['row1_background']) ? 'background-color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row1_background'])) . ';' : '', 	
                                 'ROW1_COLOR' => ($style_list[$i]['row1_color']) ? 'color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row1_color'])) . ';' : '', 	
                                 'ROW1_BORDER' => ($style_list[$i]['row1_border']) ? 'border: 1px solid ' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row1_border'])) . ';' : '', 	         	
                                 'ROW_HARD_BACKGROUND' => ($style_list[$i]['row_hard_background']) ? 'background-color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row_hard_background'])) . ';' : '', 	
                                 'ROW_HARD_COLOR' => ($style_list[$i]['row_hard_color']) ? 'color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row_hard_color'])) . ';' : '', 	
                                 'ROW_HARD_BORDER' => ($style_list[$i]['row_hard_border']) ? 'border: 1px solid ' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row_hard_border'])) . ';' : '', 	
                                 'ROW_EASY_BACKGROUND' => ($style_list[$i]['row_easy_background']) ? 'background-color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row_easy_background'])) . ';' : '', 	
                                 'ROW_EASY_COLOR' => ($style_list[$i]['row_easy_color']) ? 'color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row_easy_color'])) . ';' : '', 	
                                 'ROW_EASY_BORDER' => ($style_list[$i]['row_easy_border']) ? 'border: 1px solid ' . str_replace('"', '&quot;', strip_tags($style_list[$i]['row_easy_border'])) . ';' : '', 	
                                 'BUTTOM_BACKGROUND' => ($style_list[$i]['buttom_background']) ? 'background-color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['buttom_background'])) . ';' : '', 	
                                 'BUTTOM_COLOR' => ($style_list[$i]['buttom_color']) ? 'color:' . str_replace('"', '&quot;', strip_tags($style_list[$i]['buttom_color'])) . ';' : '', 	
                                 'BUTTOM_BORDER' => ($style_list[$i]['buttom_border']) ? 'border: 1px solid ' . str_replace('"', '&quot;', strip_tags($style_list[$i]['buttom_border'])) . ';' : '')
                        );          
		}						
         }
         else
         {
                  $template->assign_block_vars('switch_no_styles', array());
         }                         
}
if ($userdata['session_logged_in'])
{
         if ( !empty($HTTP_POST_VARS['add']) && !empty($HTTP_POST_VARS['style_text']) )
         {
	          $style_text = htmlspecialchars(trim($HTTP_POST_VARS['style_text']));

	          $sql = "UPDATE " . USERS_TABLE . "
		          SET style_text = '" . str_replace("\'", "''", $style_text) . "'
		          WHERE user_id = ".$userdata['user_id'];
	          if ( !($result = $db->sql_query($sql)) )
	          {
		          message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
	          }
	          $message = 'Стиль установлен<br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
	          $template->assign_vars(array(
		         "META" => '<meta http-equiv="refresh" content="2;url=' . append_sid("index.$phpEx") . '">')
	          );
	          message_die(GENERAL_MESSAGE, $message);
	}          
} 

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

?>