<?php
session_start();

include "../phpconfig/config.php";
include "../phpconfig/valida_login.php";
include "../phpconfig/funcoes.php";
include '../phpconfig/slugfy.php';    //Geração de slugs
include '../phpconfig/resize.php';    //Classe de resige GD2
include '../phpconfig/genpass.php';   //Geração de senhas

$titulo_pt = $_POST['titulop'];
$descricao = $_POST['descricao'];
// $titulo_es = $_POST['tituloe'];
// $titulo_en = $_POST['tituloi'];
//$texto = addslashes($_POST['texto']);
$link = $_POST['link'];
$img = $_FILES['imagem'];

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

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

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

	//echo $targetFile; exit;

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

		move_uploaded_file($tempFile, $targetFile);

		$resizeObj = new resize($targetFile);

		// Resize image (options: exact, portrait (pela lagura), landscape(pela altura), auto, crop)
		$resizeObj -> resizeImage(2600, 480, 'crop');
		$resizeObj -> saveImage($uploadDir.$name, 80);

		mysql_query("INSERT INTO banners SET  titulo_pt='$titulo_pt', descricao = '$descricao',  link='$link', imagem='$name', ordem='0'", $con) or die(mysql_error());


	}
}
  
header("location:index.php");