<?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'];

$titulo = $_POST['titulo'];
$conteudo = addslashes($_POST['conteudo']);
// $slug = $_POST['slug'];
// $seo_titulo = $titulo;
// $description = $_POST['description'];
// $keywords = $_POST['keywords'];
// $altimg = $_POST['altimg'];
// $img = $_FILES['imagem'];

// $slug   = slugfyURL(trim($_POST['slug']));
// if(strlen($slug)==0) { $slug=slugfyURL($titulo); }

$img = $_FILES['imagem'];


$slug = slugfyURL($_POST['slug']);
if(strlen($slug)==0) { $slug=slugfyURL($titulo); }


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




$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 ;


	// 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(430, 314, 'crop');
		// $resizeObj -> saveImage($uploadDir.$name, 80);
		$resizeObj -> resizeImage(200, 200, 'crop');
		$resizeObj -> saveImage($uploadDir.'thumb-'.$name, 80);
		$resizeObj -> resizeImage(430, 314, 'crop');
		$resizeObj -> saveImage($uploadDir.$name);


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


	}
}


if(strlen($titulo)!=0 && strlen($conteudo)!=0){ 

mysql_query("UPDATE servicos SET  
	titulo='$titulo',
	conteudo='$conteudo',
	slug='$slug'
	 WHERE id='$id'", $con) or die(mysql_error());
}


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