<?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
include '../phpscripts/genfolder.php'; //Geração de folders automaticamente


$titulo = $_POST['titulo'];
$conteudo = addslashes($_POST['conteudo']);

$slug       = slugfyURL($_POST['slug']); 
// $seo_titulo = $titulo;
// $description = $_POST['description'];
// $keywords = $_POST['keywords'];
// $data_cad = date('Y-m-d');
// $altimg = $_POST['altimg'];
$img = $_FILES['imagem'];

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


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

// $selpro = mysql_query("SELECT slug FROM servicos WHERE slug='$slug'");
// $i=1;

// while(mysql_num_rows(mysql_query("SELECT slug FROM servicos WHERE slug='$slug'"))==1){

//     $slug = $slug.'-'.$i;
//     $i++;
// }



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

	


	}
}

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





mysql_query("INSERT INTO servicos(

	titulo,
	
	conteudo, 
	slug,
	imagem
	
	
	
	
) VALUES (
	
	'$titulo',
	
	'$conteudo',
	'$slug',
	'$name'
	
	

)", $con) or die(mysql_error());




}


  
header("location:index.php");