
<?php
  
$video = DB::GET_STRING("SELECT * FROM `VIDEOS` WHERE `ID` = '".INTVAL(GET('video_id'))."' LIMIT 1");
$account = DB::GET_STRING("SELECT * FROM `USERS` WHERE `ID` = '".$video['USER_ID']."' LIMIT 1");

IF (!$video['ID']){
  
  ERROR('Неверная директива', 'session');
  REDIRECT('/modules/?path=videos');

}

IF (DB::GET_COLUMN("SELECT COUNT(*) FROM `VIDEOS_DIR` WHERE `ID` = '".$video['ID_DIR']."' AND `USER_ID` = '".$account['ID']."' LIMIT 1") == 1){
  
  $dir = DB::GET_STRING("SELECT * FROM `VIDEOS_DIR` WHERE `USER_ID` = '".$account['ID']."' AND `ID` = '".$video['ID_DIR']."' LIMIT 1");
  
  $id_dir = $dir['ID'];
  $nav = "<a href='/modules/?path=videos&section=users&id=".$account['ID']."'>".LG('Видео')."</a>".ICONS('angle-right', 20, 'fa-fw')."<a href='/modules/?path=videos&section=users&id=".$account['ID']."&dir=".$dir['ID']."'>".TEXT_ABSOLUTE($dir['NAME'])."</a>".ICONS('angle-right', 20, 'fa-fw')."".TEXT_ABSOLUTE($video['NAME'])."";

}ELSE{
  
  $id_dir = 0;
  $nav = "<a href='/modules/?path=videos&section=users&id=".$account['ID']."'>".LG('Видео')."</a>".ICONS('angle-right', 20, 'fa-fw')."".TEXT_ABSOLUTE($video['NAME'])."";
  
}

/*
-------------
Список лайков
-------------
*/

IF (GET('get') == "like_list"){
  
  REQUIRE (ROOT.'/modules/videos/plugins/like_list.php');
  
}

/*
--------------------
Редактирование видео
--------------------
*/

IF (GET('get') == "video_edit"){  
  
  IF (ACCESS('video_edit', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
    
    REQUIRE (ROOT.'/modules/videos/plugins/edit_video.php');
    
  }
  
}

/*
--------------
Удаление видео
--------------
*/

IF (GET('get') == "video_delete_ok"){ 
  
  IF (ACCESS('videos_delete', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
    
    REQUIRE (ROOT.'/modules/videos/plugins/delete_video.php');
    
  }
  
}

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO $nav;
ECHO "</div>";

//Редактировать комментарий
IF ($video['USER_ID'] == $user['ID'] || MANAGEMENT == 1 || ACCESS('videos_comments_edit_and_delete', NULL, 1)){
  
  REQUIRE (ROOT.'/modules/videos/plugins/comments_edit_get.php');
  
}

IF (GET('get') == "video_delete"){ 
  
  IF ($account['ID'] == $user['ID'] || ACCESS('videos_delete', NULL, 1) || MANAGEMENT == 1){
    
    ECHO "<div class='list'>";
    ECHO "".LG('Вы действительно хотите удалить видео')." <b>".TEXT_ABSOLUTE($video['NAME'])."</b>?<br /><br />";
    
    ECHO "<a href='/modules/?path=videos&section=show&video_id=".$video['ID']."&get=video_delete_ok' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";
    ECHO "<a href='/modules/?path=videos&section=show&video_id=".$video['ID']."' class='btn-o'>".LG('Отменить')."</a>";
    
    ECHO "</div>";
  
  }
  
}

IF ($id_dir > 0){
  
  IF (MANAGEMENT == 0){
    
    IF (ACCESS('videos_private_show', NULL, 1) == FALSE){
      
      REQUIRE (ROOT.'/modules/videos/plugins/private_dir.php');
      
    }
  
  }
  
}

ECHO "<div class='list'>";

//Информация о видео
REQUIRE (ROOT.'/modules/videos/plugins/video_info.php');

IF (ACCESS('videos_edit', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
  
  ECHO "<a href='/modules/?path=videos&section=show&video_id=".$video['ID']."&get=video_edit' class='btn'>".ICONS('pencil', 15, 'fa-fw')."".LG('Редактировать')."</a>";
  
}

IF (ACCESS('videos_delete', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
  
  ECHO "<a href='/modules/?path=videos&section=show&video_id=".$video['ID']."&get=video_delete' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";

}

ECHO "</div>";

ECHO "<div class='list-body' style='position: relative; z-index: 0;'>";

$result = SCANDIR(ROOT.'/modules/videos/plugins/video/', SCANDIR_SORT_ASCENDING);

FOR ($i = 0; $i < COUNT($result); $i++){
  
  IF (PREG_MATCH('#\.php$#i',$result[$i])){       
    
    REQUIRE (ROOT.'/modules/videos/plugins/video/'.$result[$i]);
  
  }

}

ECHO "</div>";

//Комментарии
REQUIRE (ROOT.'/modules/videos/plugins/comments.php');

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO $nav;
ECHO "</div>";
  
?>