View file element_support_ticket.php

File size: 7.48Kb
<?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;
	}
	$ticket = mysql_fetch_array(mysql_query("SELECT * FROM `element_support` WHERE `lost_id` = '$id' LIMIT 1"));

	if (!$ticket) {
		$title = 'Запрос не найден';
		$error1 = '<span class="small">Выбранный Вами запрос не существует, либо был удален</span>';
		require_once 'element_error_page.php';
		exit;	
	}

	if ($ticket['lost_user'] != $user['lost_id'] AND $user['lost_privilege'] != 3) {
		$title = 'Доступ закрыт';
		$error1 = '<span class="small">Вы не можете просматривать эту страницу, так как администрации ограничила к ней доступ</span>';
		require_once 'element_error_page.php';
		exit;
	}
	$name_ticket = array('', 'Общие вопросы','Предложение по игре','Вопросы по оплате','Технические вопросы');
	$ticket_user = cache_user($ticket['lost_user']);
	
	$ticket_comm = readcache('element_count_ticket_comment'.$id);
		if (empty($ticket_comm)) {
		$ticket_comm = mysql_result(mysql_query("SELECT COUNT(lost_id) FROM `element_support_comment` WHERE `lost_ticket` = '$id'"), 0);
		writecache('element_count_ticket_comment'.$id, $ticket_comm);
		}
	
$title = 'Запрос №'.$ticket['lost_id'].' '.$name_ticket[$ticket['lost_type']];
require_once './element_include/element_head.php';
require_once './element_include/element_header_user_true.php';
	
	if ($go == 'create') {
		$text = (isset($_POST['text']) AND !empty($_POST['text'])) ? mysql_real_escape_string(htmlspecialchars(addslashes(trim($_POST['text'])))) : false;
		if (!$text) $error = 'Поле \'содержание\' обязательно для ввода';
		if ($ticket['lost_close'] > 0) $error = 'Запрос закрыт';
		
		if (!isset($error)) {
		$support = ($user['lost_privilege'] == 3) ? 1 : 0;
			mysql_query("INSERT INTO `element_support_comment` SET `lost_ticket` = '$id',
																   `lost_user` = '$user[lost_id]',
																   `lost_text` = '$text',
																   `lost_time` = '".time()."',
																   `lost_support` = '$support'");
			if ($user['lost_privilege'] == 3) {	
			$text = '<span class="white">Ответ на Ваш запрос:<br/>'.$text.'</span>';
			$profile_other = explode(' ', $ticket_user['lost_other']);
			$profile_other[2] = $profile_other[2] + 1;
			$ticket_user['lost_other'] = implode(' ', $profile_other);
			writecache('element_users_id_'.$ticket['lost_user'], $ticket_user);
			user_list_update($ticket['lost_user']);
			mysql_query("INSERT INTO `element_mail` SET `lost_out` = '0',
														`lost_in` = '$ticket[lost_user]',
														`lost_sub_text` = 'Ответ на Ваш запрос',
														`lost_text` = '$text',
														`lost_user_out` = '0',
														`lost_user_in` = '$ticket[lost_user]',
														`lost_time` = '".time()."',
														`lost_system` = 'Служба поддержки',
														`lost_new` = '1'");		
			require_once './element_function/element_function_mail.php';											
			$count_in = Cache_Count_Message($ticket['lost_user']);
			if (!empty($count_in['all'])) $count_in['all']++;
			if (!empty($count_in['in'])) $count_in['in']++;
			if (!empty($count_in['new'])) $count_in['new']++;
			writecache('element_count_message'.$ticket['lost_user'], $count_in);											
			}											   
			$ticket_comm++;
			writecache('element_count_ticket_comment'.$id, $ticket_comm);
			header('Location: /support/ticket?id='.$id);
			exit;
		} else echo '<div class="error cntr p5 mb5"><span class="red">'.$error.'</span></div>'; 
	}
	
	if ($go == 'close' AND $user['lost_privilege'] == 3) {
		$op_cl = ($ticket['lost_close'] > 0) ? 0 : 1;
		mysql_query("UPDATE `element_support` SET `lost_close` = '$op_cl' WHERE `lost_id` = '$id' LIMIT 1");
		header('Location: /support/ticket?id='.$id);
		exit;
	}

echo '<div class="nfl p5 mb5 mt5 mlra">';
	echo (($user['lost_privilege'] == 3) ? '<div class="cntr mb5"><a class="yellow1 small" href="/support/ticket?id='.$id.'&go=close">'.(($ticket['lost_close'] == 0) ? 'Закрыть запрос' : 'Открыть запрос').'</a></div>' : '');
	echo '<a class="yellow1 sndr bl" href="/user?id='.$ticket['lost_user'].'">
			<span class="small fr pt2 lngreen">'.rdate("d M H:i", $ticket['lost_time']).'</span>
			'.ikonka_user($ticket_user['lost_race'], ((!empty($online[$ticket['lost_user']])) ? 'online' : 'offline')).' <span class="small">'.$ticket_user['lost_login'].'</span>
		  </a>';
	echo '<span class="small white">'.nl2br($ticket['lost_text']).'</span>';	
	
	echo '<div class="p5 cntr small"><span class="lngreen">Комментариев: '.$ticket_comm.'</span>'.(($ticket['lost_close'] > 0) ? '<br/><span class="red">Запрос закрыт</span>' : '').'</div>';
	
	if ($ticket_comm > 0) {
		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, $ticket_comm);
		
		$query = mysql_query("SELECT * FROM `element_support_comment` WHERE `lost_ticket` = '$id' ORDER BY `lost_time` ASC  LIMIT $pagination[start], $pagination[num]");
	
		while ($myrrow = mysql_fetch_array($query)) {
		$comment_user = cache_user($myrrow['lost_user']);
		$on_off = (!empty($online[$myrrow['lost_user']])) ? 'online' : 'offline';
		echo '<div class="mb5">';
		if ($myrrow['lost_support'] == 0) 
			echo '<a class="yellow1 sndr bl" href="/user?id='.$myrrow['lost_user'].'">
			<span class="small fr pt2 lngreen">'.rdate("d M H:i", $myrrow['lost_time']).'</span>
			'.ikonka_user($comment_user['lost_race'], $on_off).' <span class="small">'.$comment_user['lost_login'].'</span></a>';
		else 
			echo (($user['lost_privilege'] >= 2) ? 
					'<a class="yellow1 sndr bl" href="/user?id='.$myrrow['lost_user'].'">' : 
					'<span class="yellow1 sndr bl">').'
			<span class="small fr pt2 lngreen">'.rdate("d M H:i", $myrrow['lost_time']).'</span>
			<span class="small">Служба поддержки</span> 
			'.(($user['lost_privilege'] >= 2) ? 
			'[ '.ikonka_user($comment_user['lost_race'], $on_off).' <span class="small">'.$comment_user['lost_login'].'</span> ]</a>' : 
			'</span>');
		
		echo '<span class="small white">'.nl2br($myrrow['lost_text']).'</span>';
		echo '</div>';
		}
	
		echo pagination_echo($pagination['page'],$pagination['total'],'/support/read?id='.$id.'&page=');
	}
	
		echo (($ticket['lost_close'] > 0) ? '<div class="cntr p5 red small">Вы не можете комментировать этот запрос, потому что он закрыт</div>' : '<form class="cntr" method="post" action="/support/ticket?id='.$id.'&go=create">
		<span class="small white">Содержание:</span><br/>
		<textarea class="w90 mb5 fdark" rows="5" name="text"></textarea><br/>
		
		<span class="btn w30 green"><span class="el">
		<span class="er"><input class="ttl" type="submit" name="submit" value="Отправить"/>
		</span></span>
		</span>
		</form>');
		
echo '</div>';
require_once './element_include/element_foot_user_true.php';
?>