<?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/admin_pagination.php");
include($rootPath."library/fileSystem.php");
include($rootPath."library/imageResize.php");
include($rootPath."library/authentication.php");
include($rootPath."library/document.php");
include($rootPath."library/sef.php");
$sef = new sef();
$db = new db();
$system = new system();
$messages = new messages();
$variables = new variables();
$language = new language();
$parameters = new parameters();
$content = new content();
$content = new admin_pagination();
$fileSystem = new fileSystem();
$imageResize = new imageResize();
$authentication = new authentication(false, true);
$document = new document("", "", true);
$db->query("SET NAMES 'utf8mb4'");

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();
$isMultilingualSite = $language->isMultilingualSite();

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);
}

?>
<!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 href="<?php echo $rootPath;?>admin/css/sort.css" rel="stylesheet" type="text/css">
<link href="css/odyssey_users.css" rel="stylesheet" type="text/css">
<link type="text/css" href="<?php echo $rootPath;?>admin/css/ui/jquery-ui-odyssey.css" rel="stylesheet">
<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;?>admin/js/jquery-ui-All.min.js"></script>
<script type="text/javascript" src="<?php echo $rootPath;?>admin/js/jquery.ajaxform.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#sort-list-video").sortable({
		handle : '.handle',
		update : function () {
			var order = $('#sort-list-video').sortable('serialize');
			$("#sortInfo").load("<?php echo $rootPath;?>admin/sort.php?frontend=1&"+order+"&table=youtube");
		}
	});	
});

function setDragStyle(elm, typeOfEvent){
	if(typeOfEvent == "startDrag"){
		hideRecords();
		elm.parentNode.style.border="dashed 3px #7b8168";
		elm.parentNode.style.background="#ededed";
	}else{
		elm.parentNode.style.border="dashed 3px transparent";
		elm.parentNode.style.borderBottom="dashed 3px silver";
	}
}

function showFields(id){
	hideRecords();
	$('#button_'+id).hide();
	$('#record_'+id).css('display', 'table');
}

function hideRecords(){
	$('.attachment_record').each(function(){
		$(this).hide();
	});
	$('.attachment_button').each(function(){
		$(this).show('fast');
	});	
}

function saveForm(id){
	$('#submit_'+id).attr('value', '<?php echo t("Αποστολή δεδομένων");?>');
	$("#form_"+id).ajaxSubmit({
		url: '<?php echo $rootPath;?>admin/ajax_youtube.php?frontend=1', 
		type: 'post',
		success: showResponse
		});
}

function showResponse(responseText, statusText, xhr, $form)  { 
	if(statusText != "success"){
		alert("<?php echo t("Υπήρξε κάποιο πρόβλημα κατά την αποθήκευση των δεδομένων");?>");
	}else{
		var data = responseText.split("~~|~~");
		var id= data[0];
		var title = data[1];
		if(parseInt(id) > 0){
			$('#submit_'+id).attr('value', '<?php echo t("Αποθηκεύθηκε");?>');
			if(title) $('#caption_'+id).html(title);
			setTimeout(function(){
				$('#submit_'+id).attr('value', '<?php echo t("Αποθήκευση");?>');
				hideRecords();
			}, 2000);
		}else{
			alert("<?php echo t("Σφάλμα");?>: " + responseText);
		}
	}
} 

</script>


<style type="text/css">
<!--
body {
	margin:0;
	overflow: auto;
	max-width:800px;
	background: #ededed;
	font-family: Verdana, sans-serif, Arial;
	font-size:11px;	
}
-->
</style>
</head>
<body>
<div id="sortInfo"></div>
<?php 
$header=t("ΜΕΤΟΝΟΜΑΣΙΑ ή ΤΑΞΙΝΟΜΗΣΗ ΕΠΙΣΥΝΑΠΤΟΜΕΝΩΝ YOUTUBE ΒΙΝΤΕΟ");
 ?>
<div class="section_title"><?php echo $header;?></div>
<?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 βίντεο σε αυτή την εγγραφή")."!");
	$messages->printSystemMessages();
}
$w = 700;
?>

<div id="attachments_results" style="display:block; padding:0px; max-width:100%;">
<div style="text-align:right; margin: 5px">
<input type="button" class="btn btn-warning" value="Επιστροφή" onclick="parent.$.fancybox.close()">
</div>
<div style="font-size: 10px; text-align:right; margin: 5px"><?php echo t("Για νέα ταξινόμηση σύρτε τα βίντεο από το σχετικό εικονίδιο στην επιθυμητή θέση");?></div>
<ul id="sort-list-video" style="list-style-type:none; margin: 20px auto;">
<?php	
foreach($records as $row){
	$fileID = $row->id;
	$ext = $fileSystem->getExtensionByFileTypeID($fileSystem->getFileTypeID($row->bankID));
	 ?>
            <li id="listItem_<?php echo $row->id;?>" style="border-bottom: dashed 3px silver; padding-bottom:5px; margin-top:50px;">            
                <div class="video_thumb_wrapper" style="background: url(<?php echo $protocol;?>://img.youtube.com/vi/<?php echo $row->youtubeCode;?>/2.jpg) no-repeat center center;">
                    <object width="220" height="150">
                        <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="220" height="150"></embed>
                    </object>
                </div>
                <div class="handle" onmousedown="setDragStyle(this, 'startDrag');" onmouseup="setDragStyle(this, 'stopDrag');" style="display:table; margin: -50px auto 0 auto;"> <img src="images/sort_icon.png" alt="move" width="78" height="70" align="absmiddle" style="position:relative; z-index:100; cursor:move"> </div>
                
                <a id="button_<?php echo $row->id;?>" class="btn btn-info attachment_button" href="javascript:void(0)" style="display:block" onclick="showFields('<?php echo $row->id;?>');"><?php echo t("Εμφάνιση στοιχείων προς επεξεργασία");?></a>
                <form id="form_<?php echo $row->id;?>">
                <div id="record_<?php echo $row->id;?>" class="normal attachment_record" style="margin: 7px auto 0 auto; min-width: 280px; margin-top:7px; display:none;">
	<?php
	$Lresult =$db->query("SELECT * FROM languages WHERE active=1 ");
	$LRecords = $db->getRows($Lresult);
	
	foreach($LRecords as $Lrow) {
		$languageID = $Lrow->id;
		$title = $db->getRecord("select title from content_youtube where mainID='$fileID' and langID='$languageID'")->title;
		$extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
		?>
		<div>
        <?php
		if($isMultilingualSite){ 
		?>
		<img class="admin_label_flag" src="<?php echo $rootPath;?>mediabank/flags/flag<?php  echo $extension;?>.png">
		<?php 
		} 
		?>        
		<div class="admin_label"><?php echo t("Τίτλος");?> <?php  if($Lrow->extension && $isMultilingualSite){echo(' '.t("στα").' '.$Lrow->{title.$Lsufix});}?>: 
		</div>
		<div style="clear:both">
		<input name="title<?php  echo $extension;?>" type="text" class="listbox" id="title<?php  echo $extension;?>" value="<?php echo $title;?>" style="width:100%">
        </div>
        </div>

		<?php 
}

?>
	<input name="writedata" type="hidden" id="writedata" value="1">
	<input name="linkID" type="hidden" id="linkID" value="<?php  echo $linkID;?>">
	<input name="fileID" type="hidden" id="fileID" value="<?php  echo $row->id;?>">
	<input name="sectionID" type="hidden" id="sectionID" value="<?php  echo $sectionID;?>">
	<div class="admin_label"><input id="submit_<?php echo $row->id;?>" type="button" class="btn btn-success" value="<?php echo t("Αποθήκευση");?>" onclick="saveForm('<?php echo $row->id;?>');"></div>
				</div>
				</form>
			<div style="clear:both;"></div>
            </li>     
	<?php 
}
?>
</ul>






</div>
<div style="height:40px;"></div>
</body>
</html>
