View file element_other_chat.php

File size: 4.27Kb
<?php
require_once './element_options/element_options.php';

if (!$user) { header('Location: /'); exit; }
	$title = 'Общий чат';
	if (readcache('element_user_mesto'.$user['lost_id']) != $title) writecache('element_user_mesto'.$user['lost_id'], $title);
	require_once './element_include/element_head.php';
	require_once './element_include/element_header_user_true.php';

$element_chat = readcache('element_chat');	
if (!is_array($element_chat)) $element_chat = array();
$posts = count($element_chat);		
	
	$ban = BanUserCountActive($user['lost_id']);
	$chat_lvl = element_settings_game('lost_chat_min_level');
	
		if ($go == 'add') {
		$error = '';
		$text = trim($_POST['text']);
		if (empty($text)) $error = 'Поле \'text\' обязательно для ввода';
		if ($user['lost_level'] < $chat_lvl) $error = 'Вы не можете комментировать чат';
		if ($ban > 0) $error = 'Вы не можете комментировать чат';
		
			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',$element_chat);
			header('Location: /chat');
			exit;
			} else echo '<div class="nfl p5 mb5 mt5 small cntr mlra"><span class="error1">'.$error.'</span></div>'; 
		}	

		if (isset($_GET['delete'])) {
			if ($user['lost_privilege'] > 0) {
				$delete = ($_GET['delete']) ? (int)$_GET['delete'] : 0;
				unset($element_chat[$delete]); 
				writecache('element_chat',$element_chat); 
			}
		}
		
		
	$chat_to_user = (isset($_GET['to'])) ? $_GET['to'].', ' : '';

	echo '<div class="nfl p5 mt5 mb5 mlra">';

	if ($user['lost_level'] < $chat_lvl) {
		echo '<div class="cntr small mb5 error1">Комментировать чат можно с '.$chat_lvl.' уровня</div>';
	} else if ($ban > 0) {
		echo '<div class="cntr small mb5"><a class="error1" href="/ban/list?id='.$user['lost_id'].'">Вы не можете комментировать чат, так как находитесь в бане</a></div>';
	} else {
		echo '<form method="post" action="/chat?go=add">
				<input class="fdark w98 mb10" type="text" name="text" value="'.$chat_to_user.'" size="20" maxlength="255">
					<span class="button w30 mt5"><input type="submit" class="ttl" name="submit" value="Отправить"/></span>
					<a class="small ccc" href="/chat">Обновить</a>
					<a class="small ccc" href="/smiles.php">Смайлы</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="/chat?to='.$chat_user['lost_login'].'">[Ответить]</a>';
			echo ($user['lost_privilege'] > 0) ? ' <a class="red small" href="/chat?delete='.$k.'">[X]</a> <a class="red small" href="/ban/list?id='.$massiv['user_id'].'&to='.$massiv['text'].'">[Бан]</a>' : '';
			echo '<br/> </div>';
		}
		
		echo '</div>';
		echo pagination_echo($pagination['page'],$pagination['total'],'/chat?page=');
	}
	
	require_once './element_include/element_foot_user_true.php';
?>