<?php
 


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

$theme = $settings["theme"];

if (isset($_POST['editsayfa'])) {
	$seourl=seo($_POST['page']);
	$duzenle=$db->prepare("UPDATE sayfalar SET
		page=:page,
		detail=:detail, 
		seo_title=:seo_title,
		seo_keywords=:seo_keywords,
		seo_description=:seo_description, 
		seourl=:seourl, 
		edit_date=:edit_date
		WHERE id={$_GET['id']}");
	$update=$duzenle->execute(array(
		'page' => $_POST['page'],
		'detail' => $_POST['detail'], 
		'seo_title' => $_POST['seo_title'],
		'seo_keywords' => $_POST['seo_keywords'],
		'seo_description' => $_POST['seo_description'], 
		'seourl' => $seourl, 
		'edit_date' => $date
	));
	if ($update) {
		$success = 'Haberi başarıyla güncellediniz.';
	} else {
		$error = 'Bir hata oluştu.';
	}
	if($_FILES['image']["size"] > 0)  {
		$sor=$db->prepare("SELECT * FROM sayfalar where id=:id");
		$sor->execute(array(
			'id' => $_GET['id']
		));
		$cek=$sor->fetch(PDO::FETCH_ASSOC);
		$sil=$cek['image'];
		$image = new Upload( $_FILES['image']);
		$upload= PATH . "/public/{$theme}/images/sayfalar/";
		$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 = 500;
		$image->image_y = 500;
		$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/sayfalar/".$name.".".$uzanti;
		$duzenle=$db->prepare("UPDATE sayfalar SET
			page=:page,
			detail=:detail,
			image=:image,
			seo_title=:seo_title,
			seo_keywords=:seo_keywords,
			seo_description=:seo_description, 
			seourl=:seourl, 
			edit_date=:edit_date
			WHERE id={$_GET['id']}");
		$update=$duzenle->execute(array(
			'page' => $_POST['page'],
			'detail' => $_POST['detail'],
			'image' => $image,
			'seo_title' => $_POST['seo_title'],
			'seo_keywords' => $_POST['seo_keywords'],
			'seo_description' => $_POST['seo_description'], 
			'seourl' => $seourl, 
			'edit_date' => $date
		));
		if ($update) {
			$sil= PATH . "/public/{$theme}/{$sil}";
			@unlink("$sil");
			$success = 'Sayfayı başarıyla güncellediniz.';
		} else {
			$error = 'Bir hata oluştu.';
		}
	}
}

require admin_view('sayfa-edit');