<?php

require_once '../incfiles/core.php';
require_once '../incfiles/func.php';
require_once '../incfiles/auth.php';
require_once '../incfiles/user.php';

$req = mysql_query("SELECT * FROM `video` WHERE `id` = '".intval($_GET['id_video'])."'");
$file = mysql_fetch_array($req);
$file['name'] = str_replace('.mp4', '', $file['name']);
$file['name'] = str_replace('.flv', '', $file['name']);
$file['name'] = str_replace('.3gp', '', $file['name']);
$fil = 'http://'.$_SERVER['HTTP_HOST'].'/files/video/'.$file['dir'].'/'.$file['file'];
$screen = 'http://'.$_SERVER['HTTP_HOST'].'/files/screen/'.$file['dir'].'/'.$file['file'].'.jpg';

$title = $file['name'];
	require_once '../incfiles/head.php';

	echo '<div class="title">'.lang('Просмотр видео', 'Перегляд відео').' '.$file['name'].'</div>';

	?>
	
	<video controls="controls" style="width:97%;"><source src="<?=$fil?>"></video>
	
	<?
	echo '<div class="post_panel">';
			echo''.lang('Мне нравится','Мені подобається').'';
			echo  like('video',$file['id'],$file['ulike'],$file['clike'],$file['user_id']);
			echo '</div>
			</div>';
			
	$name = mysql_fetch_array(mysql_query("SELECT `name` FROM `users` WHERE `id` = '".$file['dir']."'"));
	echo'<div class="block">Автор: <a href="'.URL.'/?id='.$file['dir'].'" onclick="Page.Go(this.href); return false;">'.$name['name'].'</a><br/>'.lang('Добавлено','Додана').': '.vtime($file['time']).'</div>';
			if (!empty($user_id) && $user_id == $file['dir'])
			{ 
				echo '<div class="title">';
				
				echo '<a href="'.URL.'/video/?id='.$user_id.'&del='.$file['id'].'" onclick="Page.Go(this.href); return false">'.lang('Удалить','Видалити').'</a></div>';
			}
			if (!empty($user_id) && $user_id != $id) echo '<div class="title"><a href="'.URL.'/video/add.php?id=track_'.$file['id'].'" onclick="Page.Go(this.href); return false"><img src="'.URL.'/design/img/adds.png"/>'.lang('Добавить в свои видеозаписи','Додати у свої відеозаписи').'</a></div>';

			
if (!empty($user_id))
			{
			?>
<script type="text/javascript">
$(function(){
	$('#form').on('submit', function(e){
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			$('#content_comm').load($that.attr('action')+ '#content_comm .comm');
			$('#textarea').val('');
       }
     }
    });
  });
});

$(function(){
	$('#form_re_comm').on('submit', function(e){
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			Page.Go($that.attr('action'));
       }
     }
    });
  });
});
</script>

<?
			
			require_once 'handler/del_comm.php';
			require_once 'handler/comm.php';
			
			echo '<div class="block2">
				<form id="form" method="post" action="'.URL.'/video/view.php?id_video='.$file['id'].'">
				<textarea id="textarea" class="input" name="comm" rows="4"></textarea>
				<input class="button2" type="submit" value="'.lang('Написать','Написати').'"/>
				<a class="button3" href="'.URL.'/ajax/smiles.php" onclick="FormContent.Smiles(this.href); return false"><img src="'.URL.'/design/img/smile.png"/></a>
				</form>
				</div>
				<div id="form_content"></div>';
			}

			echo '<div id="content_comm"><div class="comm">
			<div class="title">'.lang('Комментарии','Коментарі').' <div class="right">'.$file['comm'].'</div></div>';
		
			$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `video_comm` WHERE `fid` = '".$file['id']."' LIMIT 1"),0);
			if ($all == true)
			{
				$cp = ceil($all/10);
				$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
				$start = $p*10-10;

				$arr_comm = mysql_query("SELECT * FROM `video_comm` WHERE `fid` = '".$file['id']."' ORDER by `time` DESC LIMIT $start,10");
				while ($arr = mysql_fetch_array($arr_comm))
				{
					echo '<div class="block">';
					if (!empty($user_id) && $user_id == $file['dir'] or !empty($user_id) && $user_id == $arr['user_id']) echo '<div class="right"><a href="'.URL.'/video/view.php?id_video='.$file['id'].'&p='.$p.'&del_comm='.$arr['id'].'" onclick="Form.delPost(this.href); return false"><img src="'.URL.'/design/img/closed.png"/></a></div>';
					echo user_name($arr['user_id']).'<br/>'.vtime($arr['time']).'<ul>';
					if (!empty($arr['quote_id'])) echo '<div class="quote">'.user_name($arr['quote_id']).' '.lang('пишет','пише').':<ul>'.smiles(text($arr['quote'])).'</ul></div>';
					echo smiles(text($arr['text'])).'</ul>';
					if (!empty($user_id) && $user_id != $arr['user_id'])
					{
						echo '<ul><a class="link_re_comm" id="link_re_comm_'.$arr['id'].'" href="" onclick="Form.reComm('.$arr['id'].'); return false">'.lang('Ответить','Відповісти').'</a></ul>
						<div class="re_comm" id="re_comm_'.$arr['id'].'">
						<form id="form_re_comm" method="post" action="'.URL.'/video/view.php?id_video='.$file['id'].'">
						<textarea class="input" name="re_comm" rows="4"></textarea>
						<input type="hidden" name="re_id" value="'.$arr['id'].'"/>
						<input class="button2" type="submit" value="'.lang('Написать','Написати').'"/>
						</form>
						</div>';
					}
					echo '</div>';
				}
			}
			navi($p,$cp,''.URL.'/video/view.php?id='.$arr_user['id'].'&n='.$n.'&');
			echo '</div></div>';
			
require_once '../incfiles/foot.php';


?>