<?php
session_start();
include "../phpconfig/config.php";
include "../phpconfig/valida_login.php";
include "../phpconfig/funcoes.php";
include "../phpconfig/slugfy.php";
include '../phpconfig/resize.php';    //Classe de resige GD2
include '../phpconfig/genpass.php';   //Geração de senhas




$id        =       $_POST['id'];


$imgtop       =    $_FILES['top'];
$imglat       =    $_FILES['lat'];
$imginf       =    $_FILES['inf'];
$link       =    $_POST['link'];

$uploadDir = sti('doc_root').sti('up').'banners/';

$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions

if (!empty($imgtop)) {
	$tempFile   = $imgtop['tmp_name'];
	$arch = slugfyUp($imgtop['name']);
	$name = simplesPass(array(1,0,1,0),4)."-".$arch;
	$targetFile = $uploadDir . $name ;


	// Validate the filetype
	$fileParts = pathinfo($imgtop['name']);
	if (in_array(strtolower($fileParts['extension']), $fileTypes)) {

		move_uploaded_file($tempFile, $targetFile);

		$resizeObj = new resize($targetFile);
		$resizeObj -> resizeImage(727, 90, 'crop');
		$resizeObj -> saveImage($uploadDir.$name);



		mysql_query("UPDATE campanhas SET top='$name' WHERE id='$id'") or die(mysql_error());


	}
}


if (!empty($imglat)) {
	$tempFile   = $imglat['tmp_name'];
	$arch = slugfyUp($imglat['name']);
	$name = simplesPass(array(1,0,1,0),4)."-".$arch;
	$targetFile = $uploadDir . $name ;


	// Validate the filetype
	$fileParts = pathinfo($imglat['name']);
	if (in_array(strtolower($fileParts['extension']), $fileTypes)) {

		move_uploaded_file($tempFile, $targetFile);

		$resizeObj = new resize($targetFile);
		$resizeObj -> resizeImage(300, 600, 'crop');
		$resizeObj -> saveImage($uploadDir.$name);




		mysql_query("UPDATE campanhas SET lat='$name' WHERE id='$id'") or die(mysql_error());


	}
}

if (!empty($imginf)) {
	$tempFile   = $imginf['tmp_name'];
	$arch = slugfyUp($imginf['name']);
	$name = simplesPass(array(1,0,1,0),4)."-".$arch;
	$targetFile = $uploadDir . $name ;


	// Validate the filetype
	$fileParts = pathinfo($imginf['name']);
	if (in_array(strtolower($fileParts['extension']), $fileTypes)) {

		move_uploaded_file($tempFile, $targetFile);

		$resizeObj = new resize($targetFile);
		$resizeObj -> resizeImage(755, 300, 'crop');
		$resizeObj -> saveImage($uploadDir.$name);




		mysql_query("UPDATE campanhas SET inf='$name' WHERE id='$id'") or die(mysql_error());


	}
}


mysql_query("UPDATE campanhas SET  
	link='$link'
	WHERE id='$id'", $con) or die(mysql_error());



  
header("location:banners.php?id=$id");


