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

$nome = $_POST['nome'];
$link = $_POST['link'];
// $categoria = $_POST['categoria'];
// $serv = $_POST['servicos'];



$img = $_FILES['imagem'];



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

$uploadDir  = $uploadDir;
$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(300, 300, 'crop');
		$resizeObj -> saveImage($uploadDir.$name, 80);


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


	}
}





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


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