<?php

$query=$db->prepare("SELECT * FROM video where id=:id");
$query->execute(array(
	'id' => $_GET['id']
));
$row=$query->fetch(PDO::FETCH_ASSOC);

$theme = $settings["theme"];

if (isset($_POST['editvideo'])) {
	$duzenle=$db->prepare("UPDATE video SET
		baslik=:baslik,
		video_url=:video_url,
		aciklama=:aciklama,  
		edit_date=:edit_date
		WHERE id={$_POST['id']}");
	$update=$duzenle->execute(array(
		'baslik' => $_POST['baslik'],
		'video_url' => $_POST['video_url'],
		'aciklama' => $_POST['aciklama'],  
		'edit_date' => $date
	));
	if ($update) {
		$success = 'İşlem başarıyla gerçekleşti.';
	} else {
		$error = 'Bir hata oluştu.';
	}
	if($_FILES['image']["size"] > 0)  {
		$sor=$db->prepare("SELECT * FROM video where id=:id");
		$sor->execute(array(
			'id' => $_POST['id']
		));
		$cek=$sor->fetch(PDO::FETCH_ASSOC);
		$sil=$cek['image'];
		$image = new Upload( $_FILES['image']);
		$upload= PATH . "/public/{$theme}/images/video/";
		$s1=rand(1000,3200);
		$s2=rand(1000,3200);
		$s3=rand(1000,3200);
		$s4=rand(1000,3200);
		$names=$s1.$s2.$s3.$s4;
		$image->image_resize = true;
		$image->image_ratio_crop = true;
		$image->image_x = 380;
		$image->image_y = 200;
		$name=$image->file_new_name_body = $names;
		$uzantiss=$image->file_src_name;
		$uzantis=ext($uzantiss);
		$uzanti=$image->image_convert = $uzantis;
		$image->Process($upload);
		$image->allowed = array ('image/*');
		$image="images/video/".$name.".".$uzanti;
		$duzenle=$db->prepare("UPDATE video SET
			baslik=:baslik,
			video_url=:video_url,
			aciklama=:aciklama,
			image=:image,  
			edit_date=:edit_date
			WHERE id={$_POST['id']}");
		$update=$duzenle->execute(array(
			'baslik' => $_POST['baslik'],
			'video_url' => $_POST['video_url'],
			'aciklama' => $_POST['aciklama'],
			'image' => $image,  
			'edit_date' => $date
		));
		if ($update) {
			$sil= PATH . "/public/{$theme}/{$sil}";
			@unlink("$sil");
			$success = 'İşlem başarıyla gerçekleşti.';
		} else {
			$error = 'Bir hata oluştu.';
		}
	}
}
require admin_view('video-edit');