<?php


$query=$db->prepare("SELECT * FROM gallery where type=:type");
$query->execute(array(
	'type' => "photos"
));
 
$theme = $settings["theme"];

if (isset($_POST['newphotos'])) {
	$images = array();
	foreach ($_FILES['image'] as $k => $l) { foreach ($l as $i => $v) {
		if (!array_key_exists($i, $images)) $images[$i] = array(); $images[$i][$k] = $v; }
	}
	foreach ($images as $image){
		$handle = new Upload($image);
		$s1=rand(1000,3200);
		$s2=rand(1000,3200);
		$s3=rand(1000,3200);
		$s4=rand(1000,3200);
		$names=$s1.$s2.$s3.$s4;
		$name=$handle->file_new_name_body = $names;
		$uzantiss=$handle->file_src_name;
		$uzantis=ext($uzantiss);
		$uzanti=$handle->image_convert = $uzantis;
		$handle->allowed = array('image/*');
		$handle->Process(realpath(PATH)."/public/{$theme}/images/photos/");
		$image= "images/photos/".$name.".".$uzanti;
		$handle-> Clean();
		$kaydet=$db->prepare("INSERT INTO gallery SET
			image=:image,
			type=:type");
		$insert=$kaydet->execute(array(
			'image' => $image,
			'type' => "photos"
		));
		if ($insert) {
			$success = 'İşlem başarıyla gerçekleşti.';
		} else {
			$error = 'Bir hata oluştu.';
		}
	}
}

if (isset($_POST['deletephotos'])) {
	$image=$_POST['image'];
	$sil=$db->prepare("DELETE from gallery where gallery_id=:gallery_id");
	$kontrol=$sil->execute(array(
		'gallery_id' => $_POST['gallery_id']
	));
	if ($kontrol) {
		$sil= PATH . "/public/{$theme}/{$image}";
		@unlink("$sil");
		$success = 'İşlem başarıyla gerçekleşti.';
	} else {
		$error = 'Bir hata oluştu.';
	}
}
 

require admin_view('foto-galeri');