<?php 
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED ^ E_STRICT); 
$rootPath = is_file("../../../../library/document.php") ? "../../../../" : "../../";
define("CMS", "korCMS");
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";
include($rootPath."config/odyssey.ini.php");
include($rootPath."library/db.php");
include($rootPath."library/system.php");
include($rootPath."library/messages.php");
include($rootPath."library/variables.php");
include($rootPath."library/language.php");
include($rootPath."library/parameters.php");
include($rootPath."library/content.php");
include($rootPath."library/fileSystem.php");
include($rootPath."library/document.php");
include($rootPath."library/sef.php");
$sef = new sef();
$db = new db();
$db->query("SET NAMES 'utf8mb4'");
$system = new system();
$messages = new messages();
$variables = new variables();
$language = new language();
$parameters = new parameters();
$content = new content();
$fileSystem = new fileSystem();
$document = new document("", "", true);


function getFPath(){
	$parts = explode("/", $_SERVER["PHP_SELF"]);
	array_shift($parts); // the first element will be empty to we get rid of it
	array_pop($parts); // get rid of script name
	$fPath =implode("/", $parts);
	if(substr($fPath, -1) != "/") $fPath.="/";
	$fPath = ($fPath == "/") ? null : $fPath;	
	return $fPath;	
}

$langID = ($_GET['langID']) ? (int)$_GET['langID'] : $language->getDefaultLanguage();
$Lsufix = ((int)$langID > 1) ? "_translated" : NULL;
$variables->getSafeVars(array_keys($_REQUEST));

$token1 = "38629649";
$token2 = "73972658";
list($stage1, $token2b) = explode($token2, $_REQUEST['u']);
list($token1b, $userID) = explode($token1, $stage1);
if(empty($userID)) die("Access denied");

// lets check if the section's record belongs to this user
$section = $system->getTableSectionName($sectionID);
$uid = $db->getRecord("select userID from $section where id='$linkID'")->userID;
if($uid <> $userID) die("Access denied");


$parameters->importParameters();

$id = (int)$_REQUEST['id'];
if($action=="delete" && $linkID && $sectionID && $id){ // procceed to delete youtube video record from db
$db->query("DELETE FROM youtube WHERE id='$id' and linkID='$linkID' and '$sectionID'");
$db->query("DELETE FROM content_youtube WHERE mainID='$id' ");
}

function t($key, $langID=NULL, $context=NULL){ // shortcut of $language->getText($key, $langID=NULL, $context=NULL)
	global $language;
	global $langID;
	return $language->getText($key, $langID, $context);
}

function getBase(){
	global $domain_name;
	if($_SERVER['SERVER_NAME'] == "localhost") return str_replace("localhost", NULL, $domain_name)."/";	
	global $domainPath;
	$www = preg_match('/^www/', $_SERVER['SERVER_NAME']) ? 'www.' : null;
	$parts = explode("/", $_SERVER["PHP_SELF"]);
	array_shift($parts); // the first element will be empty to we get rid of it
	array_pop($parts); // get rid of script name
	$fPath =implode("/", $parts);
	$newPath = $domainPath.$fPath;
	if(substr($newPath, -1) != "/") $newPath.="/";
	return $newPath; // for sef urls, must be a base tag in html HEAD with this value
}

$mn = "odyssey_users";
$mp = ($system->isSystemProtected("extension", $system->getExtensionID($mn), false)) ? $document->modulesPath.$mn."/" : $document->getTemplatePath().$document->modulesPath.$mn."/"; // $mp stands for module path
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<?php echo $rootPath;?>admin/css/admin.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="<?php echo $rootPath;?>js/fancybox2/fancybox.css">
<script type="text/javascript" src="<?php echo $rootPath;?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo $rootPath;?>admin/js/admin.js"></script>
<script type="text/javascript" src="<?php echo $rootPath;?>js/fancybox2/fancybox.js"></script>
<style  type="text/css">
<!--
body {
	margin:0;
	overflow-y: auto;
	overflow-x: hidden;
	background: #ffffff;
	font-family: Verdana, sans-serif, Arial;
	font-size:11px;	
}
-->
</style>
</head>
<body>
<div style="text-align:center;">
<?php 
$query = "SELECT distinct youtube.*, content_youtube.title FROM youtube, content_youtube WHERE youtube.linkID='$linkID' and youtube.sectionID='$sectionID' and content_youtube.mainID=youtube.id and content_youtube.langID='$langID' order by youtube.sort";
$rows=$db->getNumRows($query);
$records=$db->getRecords($query);
if(!count($records)){
	?>
	<script>
	parent.$('#youtube_instructions').css('display','none');
	</script>
	<div style="height:50px">&nbsp;</div>
	<?php
	$messages->addMessage(t("Δεν έχετε επισυνάψει κάποιο YouTube video σε αυτή την εγγραφή")."!");
	$messages->printSystemMessages();
}else{
	?>
	<script>
	$(function(){
		$('a[data-rel="videoGallery"]').fancybox({
			onClosed			: function() {},
			'overlayOpacity'		: 0,
			'overlayColor'		:'#000',			
			'width'			: '100%',
			'height'			: '900',
			'autoScale'			: true,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'				: 'iframe',
			'showNavArrows'		: false,
			'titleShow'			: false
		});
	});
	</script>
    <?php
	if(count($records) > 1){
	?>    
	<div id="preview_video_btn">	
	<a href="preview_gallery_youtube.php?linkID=<?php echo $linkID;?>&sectionID=<?php echo $sectionID;?>" data-rel="videoGallery">
		<img src="images/preview_video_gallery.png" width="205" height="60" alt="preview video gallery">
	</a>
	</div>
	<?php	
	}
}
$w = count($records)*200;
$w = (($w > 700) || empty($w)) ? 'auto' : $w."px";
?>
<div id="attachments_results" style="display:inline-block; 	padding:0px; width:<?php echo $w;?>;">
<?php	
foreach($records as $row){
 ?>
 <table style="padding:0; display:inline-block; width:200px; height:230px; max-height:230px; overflow:hidden;" cellspacing="5">
<tr>
<td style="padding:0; margin:0; height:131px; width:170px; text-align:center; vertical-align:middle">
<object width="156" height="129"><param name="movie" value="https://www.youtube-nocookie.com/v/<?php echo $row->youtubeCode;?>&hl=en_GB&fs=1&rel=0"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube-nocookie.com/v/<?php echo $row->youtubeCode;?>&hl=en_GB&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="transparent" allowfullscreen="true" width="156" height="129"></embed></object>
</td>
</tr>
<tr>
<td style="text-align:center; font-size:.8em;vertical-align:top"><?php echo $row->title;?></td>
</tr>
<tr>
<td style="text-align:center; font-size:.8em; border-bottom:1px solid grey; height:40px !important">
<input type="submit" name="button" value="<?php echo t("Διαγραφή");?>" class="btn btn-danger" onclick="if(confirm('<?php echo t("Είστε βέβαιοι πως θέλετε να καταργήσετε αυτό το youtube video;");?>')){document.location.href='?action=delete&id=<?php echo $row->id;?>&u=<?php echo $u;?>&linkID=<?php echo $linkID;?>&sectionID=<?php echo $sectionID;?>';}">
</td>
</tr>
</table>
<?php 
}
 ?>
</div>
</div>
</body>
</html>
