<?php

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

$theme = $settings["theme"];

if (isset($_POST['proedit'])) {
	$seourl = seo($_POST['programci']);
	$duzenle = $db->prepare("UPDATE programci SET
	    email=:email,
		sifre=:sifre,
		programci=:programci,
		program=:program, 
		facebook=:facebook,
		twitter=:twitter,
		instagram=:instagram,
		durum=:durum,
		seourl=:seourl, 
		edit_date=:edit_date
		WHERE id={$_GET['id']}");
	$update = $duzenle->execute(array(
		'email' => $_POST['email'],
		'sifre' => (md5($_POST['sifre'])),
		'programci' => $_POST['programci'],
		'program' => $_POST['program'],
		'facebook' => $_POST['facebook'],
		'twitter' => $_POST['twitter'],
		'instagram' => $_POST['instagram'],
		'durum' => $_POST['durum'],
		'seourl' => $seourl, 
		'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 programci 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/programci/";
		$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 = 400;
		$image->image_y = 400;
		$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/programci/" . $name . "." . $uzanti;
		$duzenle = $db->prepare("UPDATE programci SET
		    email=:email,
			sifre=:sifre,
			programci=:programci,
			program=:program,
			image=:image,
			facebook=:facebook,
			twitter=:twitter,
			instagram=:instagram,
			durum=:durum,
			seourl=:seourl, 
			edit_date=:edit_date
			WHERE id={$_GET['id']}");
		$update = $duzenle->execute(array(
			'email' => $_POST['email'],
			'sifre' => $_POST['sifre'],
			'programci' => $_POST['programci'],
			'program' => $_POST['program'],
			'image' => $image,
			'facebook' => $_POST['facebook'],
			'twitter' => $_POST['twitter'],
			'instagram' => $_POST['instagram'],
			'durum' => $_POST['durum'],
			'seourl' => $seourl, 
			'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('programci-edit');
