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

Размер файла: 4.18Kb
<?php
require_once './element_options/element_options.php';
if (!$user) { header('Location: /'); exit; }
	
	
if (!$id) {
	$title = 'Город не найден';
	$error1 = '<span class="small">Выбранный Вами город не существует, либо был удален</span>';
	require_once 'element_error_page.php';
	exit;
}
	
if ($id != $user['lost_town'] AND $user['lost_privilege'] != 3) {
	$title = 'Доступ закрыт';
	$error1 = '<span class="small">Администрация ограничила доступ к этой странице</span>';
	require_once 'element_error_page.php';
	exit;
}
	
	$cache_town = cache_town($id);
	
if (!$cache_town) {
	$title = 'Город не найден';
	$error1 = '<span class="small">Выбранный Вами город не существует, либо был удален</span>';
	require_once 'element_error_page.php';
	exit;
}
	
	$element_chat = readcache('element_chat_town_id'.$id);	
	if (!is_array($element_chat)) $element_chat = array();
	$posts = count($element_chat);
	
	if (isset($_GET['delete'])) {
		if ($user['lost_privilege'] > 0) {
			$delete = ($_GET['delete']) ? (int)$_GET['delete'] : 0;
			unset($element_chat[$delete]); 
			writecache('element_chat_town_id'.$id,$element_chat); 
		}
	}
	
	$title = 'Чат "'.$cache_town['lost_name'].'"';
	require_once './element_include/element_head.php';
	require_once './element_include/element_header_user_true.php';
	
	if ($go == 'add') {
		$error = '';
		$text = trim($_POST['text']);
		if (empty($text)) $error = 'Поле \'text\' обязательно для ввода';
			if (empty($error)) {
			$text = addslashes(htmlspecialchars($text));
			$send = array('user_id' => $user['lost_id'], 'text' => $text, 'time' => time());
			array_push($element_chat, $send);
			if (count($element_chat) > element_settings_game('lost_chat_max_count')) array_shift($element_chat);
			writecache('element_chat_town_id'.$id, $element_chat);
			header('Location: /town/chat?id='.$id);
			exit;
		} else echo '<div class="nfl p5 mb5 mt5 small cntr mlra"><span class="red">'.$error.'</span></div>'; 
	}	
	
	echo '<div class="nfl p5 mb5 mt5 small mlra">';
	
	echo '<form method="post" action="/town/chat?id='.$id.'&go=add">
			<input class="fdark w98 mb10" type="text" name="text" value="" size="20" maxlength="255">
				<span class="button w30 mt5"><input type="submit" class="ttl" name="submit" value="Отправить"/></span>
			<a class="small ccc" href="/town/chat?id='.$id.'">Обновить</a>
		  </form>';
	
	if (empty($element_chat)) 
	{
	echo '<div class="p5 cntr"><span class="small ccc">В чате нету сообщений</span></div>';
	echo '</div>';
	} else {
		krsort($element_chat);
		require_once './element_function/element_function_pagination.php';
		$page = (isset($_GET['page']) AND is_numeric($_GET['page'])) ? (int)$_GET['page'] : 1;
		$pagination = pagination(10, $page, count($element_chat));
		
		foreach(array_slice($element_chat, $pagination['start'], $pagination['num'], true) as $k => $massiv) {
			$chat_user = cache_user($massiv['user_id']);
			$on_off = (!empty($online[$massiv['user_id']])) ? 'online' : 'offline';
			$text = Color_Privilege($chat_user['lost_privilege'], ReplaceText($user['lost_login'], $massiv['text']));
			$text = Smiles($text, true);
			
			echo '
			<div class="mt5">
			<a class="yellow1 sndr bl" href="/user?id='.$massiv['user_id'].'">
				<span class="small fr pt2 lngreen">'.Timer($massiv['time']).'</span>
				'.ikonka_user($chat_user['lost_race'], $on_off).' <span class="small">'.$chat_user['lost_login'].'</span>
			</a>';
			echo '<span class="small">'.$text.'</span>';
			echo '<br/><a class="ccc small" href="/town/chat?id='.$id.'&to='.$chat_user['lost_login'].'">[Ответить]</a>';
			echo ($user['lost_privilege'] > 0) ? ' <a class="red small" href="/town/chat?id='.$id.'&delete='.$k.'">[X]</a> <a class="red small" href="/chat#">[Бан]</a>' : '';
			echo '<br/> </div>';
		}
		echo '</div>';
		echo pagination_echo($pagination['page'],$pagination['total'],'/town/chat?id='.$id.'&page=');
	}
	
require_once './element_include/element_foot_user_true.php';
?>