<?php

$query=$db->prepare("SELECT * FROM app_radio");
$query->execute();
$row=$query->fetch(PDO::FETCH_ASSOC);

$theme = $settings["theme"];

if (isset($_POST['editapp'])) {
	$duzenle=$db->prepare("UPDATE app_radio SET  
		radio_name=:radio_name,
		radio_url=:radio_url,
		privacy_policy=:privacy_policy 
		WHERE id=1");
	$update=$duzenle->execute(array(  
		'radio_name' => $_POST['radio_name'],
		'radio_url' => $_POST['radio_url'],
		'privacy_policy' => $_POST['privacy_policy']
	));
	if ($update) {
		$success = 'İşlem başarıyla gerçekleşti.';
	} else {
		$error = 'Ayarlar güncellenirken bir hata oluştu.';
	}

	if($_FILES['radio_image']["size"] > 0)  {
		$image = new Upload( $_FILES['radio_image']);
		$upload= PATH . "/public/{$theme}/images/upload/";
		$s1=rand(1000,3200);
		$s2=rand(1000,3200);
		$s3=rand(1000,3200);
		$s4=rand(1000,3200);
		$names=$s1.$s2.$s3.$s4;
		$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/*');
		$radio_image="images/upload/".$name.".".$uzanti;

		$duzenle=$db->prepare("UPDATE app_radio SET  
			radio_name=:radio_name,
			radio_image=:radio_image,
			radio_url=:radio_url,
			privacy_policy=:privacy_policy 
			WHERE id=1");
		$update=$duzenle->execute(array(
			'radio_name' => $_POST['radio_name'],
			'radio_image' => $radio_image,
			'radio_url' => $_POST['radio_url'],
			'privacy_policy' => $_POST['privacy_policy'] 
		));
		if ($update) {
			$sil= PATH . "/public/{$theme}/{$row['radio_image']}";
			@unlink("$sil");
			$success = 'İşlem başarıyla gerçekleşti.';
		} else {
			$error = 'Ayarlar güncellenirken bir hata oluştu.';
		}
	}

}


require admin_view('app-radio');