<?php
define('_IN_JOHNCMS', 1);
require('incfiles/core.php'); ?>
<?php require('incfiles/head.php');?>
<style>
	input[type=text] {
		width: 89.5%;
		padding: 12px 20px;
		margin: 8px 0;
		display: inline-block;
		border: 1px solid #ccc;
		box-sizing: border-box;
	}
	.ajaxchat{width:100%;position:relative;}
	.ajaxchat .height-chat{height: 600px;}
	.ajaxchat .message{overflow-y:auto;height: 600px;position: absolute;top:0;left:0;right:0;}
</style>
<?php 
// tekshirib olamiz
if ((!$user_id == true) && !(!$user_id ==false))  {
	echo '<div class="rmenu"><p>Chatimiz ga faqat saytimiz foydalanuvchilari kirishga huquqli, shu sababdan avvalo ro\'yxatdan o\'tishingizni so\'raymiz!</p></div>';
	require_once ("../incfiles/end.php");
	exit;
} ?>
<?php 
if ($id)
	$us = mysql_fetch_assoc(mysql_query('select * from `chats` where `id` = ' . $id . ';'));
switch ($akb) {
	// Hamma habarni o`chrish
	case 'tozalash':
	if ($rights >= 7) {
		if (isset($_POST['submit'])) {
			mysql_query('truncate `chats`');
			header('location: ?');
		} else {
			echo '<div class="menu"><form action="?akb=tozalash" method="post">Chatdagi hamma habarni tozalavorasizmi?<br />

			<input type="submit" name="submit" value="Tozalash" /><br /><a href="?">Orqaga</a></form></div>';	
		}
	}
	break; 
// Habarni o'chrish
	case 'del':
	if ($us['user_id'] == $user_id || $rights >= 9) {
		if (isset($_POST['submit'])) {
			mysql_query('delete from `chats` where `id` = ' . $id . ';');
			header('location: ?');
		} else {
			echo '<form action="?akb=del&amp;id=' . $id . '" method="post">Ushbu xabarni o`chirmoqchimisiz?<br />

			<input type="submit" name="submit" value="O`chirish" />  <a href="?">Qaytish</a>      
			<a href="?akb=taxrir&amp;id='.$id.'">   Taxrirlash</a></form>';
		} 
	}	else {
		echo 'Meni kechring nimadir siz yoki menda xato ketdi, men sizni nima qilayotganingizni tushunmadim';
echo '<a href="?"> Qaytish</a> ';
		 }
	break;
// Postni taxrirlash
	case 'taxrir':
	if ($us['user_id'] == $user_id || $rights >= 7) {
		$post = mysql_fetch_assoc(mysql_query('select * from `chats` where `id` = ' . $id . ';'));
		if (isset($_POST['submit'])) {
			$message = isset($_POST['message']) ? functions::checkin(mb_substr(trim($_POST['message']), 0, 150)) : '';
			if (empty($message))
				$error[] = 'Пустое сообщение!';
			if ($ban['1'] || $ban['13'])
				$error[] = 'Вы забанены!';
			if (!$error) {
				mysql_query('update `chats` set `message` = "' . mysql_real_escape_string($message) . '" where `id` = ' . $id . ';');
				header('location: ?');
			} else {
				echo functions::display_error($error, '<a href="index.'.$akb_for.'">Orqaga</a>');
			}
		} else {
			echo '<div class="phdr"><b>Редактируем пост</b></div>';
			echo '<div class="menu"><form action="?akb=taxrir&amp;id=' . $id . '" name="edit" method="post">';

			echo 'Сообщение (max 500):<br />';
			echo bbcode::auto_bb('taxrir', 'message');
			echo '<textarea rows="' . $set_user['field_h'] . '" name="message">' . $post['message'] . '</textarea><br />' .
			'<input type="submit" name="submit" value="Сохранить" /></form></div>';
			echo '<div class="menu"><a href="?">Назад</a></div>';
		} 
	} else {
		echo 'Meni kechring nimadir siz yoki menda xato ketdi, men sizni nima qilayotganingizni tushunmadim';
echo '<a href="?"> Qaytish</a> ';
		 }
	break;
// Umumiy ko`rinish
	default:
	?>
	<section>
		<div class="w3-container w3-theme-d3"><p><b>O`zimizning Chat</b></p></div> 
		<div class="ajaxchat">
			<div class="height-chat">
				<div class="message">
					<div class="msgs">
						<?php functions::get_chat(10);?>
					</div> 
				</div>
			</div>
		</div>
		<div class="gmenu">
				<?php echo bbcode::auto_bb('form', 'msg'); ?>
			<form id="chatform" name="form">
				<textarea type="text" class="form-control" name="msg"></textarea>
				<button class="w3-button w3-white w3-border w3-round-large">Yuborish</button> <select class="select-radio" name="select-radio"><option value="https://listen2.myradio24.com/8000">HipHop BY</option>
      <option value="https://zaycevfm.cdnvideo.ru/ZaycevFM_pop_256.mp3">Зайцев.FM Pop Music</option>
     <option value="https://zaycevfm.cdnvideo.ru/ZaycevFM_disco_256.mp3">Зайцев.FM DISCO</option>
     <option value="https://zaycevfm.cdnvideo.ru/ZaycevFM_electronic_256.mp3">Зайцев.FM Club</option>
	 <option value="https://listen2.myradio24.com/8144">Шансон</option>
    </select>  <audio id="radio-chat" controls="" src="https://zaycevfm.cdnvideo.ru/ZaycevFM_pop_256.mp3"> </audio>
    </form>
				    <script>
     $('.select-radio').unbind().change(function(){
       var url = $(this).val();
       var radio_sound = $('#radio-chat')[0];
       radio_sound.pause();
       $('#radio-chat').attr('src', url);
       radio_sound.play();
       });
    </script>
			</div>
		</section>
		<?php 
		if ($rights >= 7) {
			echo '<div class="phdr"><a href="?akb=tozalash">Xabarlarni Tozalash</a></div>';
		}?> 
		<script src="<?php echo $home;?>/ajax/chat.js"></script>
		<?php 		require('incfiles/end.php');
		break; }
		?>