<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:../../404.php');
}else{
include_once '../../../po-library/po-database.php';
include_once '../../../po-library/po-function.php';

$val = new Povalidasi;
$mod=$_POST[mod];
$act=$_POST[act];

// Delete Banner
if ($mod=='banner' AND $act=='delete'){
	$id = $val->validasi($_POST['id'],'sql');
	$tabledel = new PoTable('banner');
	$currentDel = $tabledel->findBy(id_banner, $id);
	$currentDel = $currentDel->current();
	$picture = $currentDel->picture;
		unlink("../../../po-content/po-upload/banner/$picture");
		$tabledel->deleteBy('id_banner', $id);
}

// Input Banner
elseif ($mod=='banner' AND $act=='input'){
$title = $val->validasi($_POST['title'],'xss');
$url = $val->validasi($_POST['url'],'xss');
$size = $val->validasi($_POST['size'],'xss');
$extensionList = array("jpg", "jpeg");
$fileName = $_FILES['fupload']['name'];
$tmpName  = $_FILES['fupload']['tmp_name'];
$fileType = $_FILES['fupload']['type'];
$fileSize = $_FILES['fupload']['size'];
$pecah = explode(".", $fileName);
$ekstensi = $pecah[1];
$seotitle = seo_title($title);
$acak = rand(000000,999999);
$nama_file = "-pobanner.";
$nama_file_unik = $seotitle.'-'.$acak.$nama_file.$ekstensi;
$picture = 'ban-'.$nama_file_unik;

if (!empty($tmpName)){
	if (in_array($ekstensi, $extensionList)){
		UploadBanner($nama_file_unik, $size);
		$table = new PoTable('banner');
		$table->save(array(
			'title' => $title,
			'url' => $url,
			'size' => $size,
			'date' => $tgl_sekarang,
			'picture' => $picture
		));
		header('location:../../admin.php?mod='.$mod);
	}else{
		header('location:../../404.php');
	}
}else{
	header('location:../../404.php');
}
}

// Update Banner
elseif ($mod=='banner' AND $act=='update'){
$id = $val->validasi($_POST['id'],'sql');
$title = $val->validasi($_POST['title'],'xss');
$url = $val->validasi($_POST['url'],'xss');

 	$data = array(
			'title' => $title,
			'url' => $url
	);
	$table = new PoTable('banner');
	$table->updateBy('id_banner', $id, $data);
	header('location:../../admin.php?mod='.$mod);
}
}
?>