<?php
use Intervention\Image\ImageManagerStatic as Image;

$slidesDao = new \Dao\Slides();
$slidesDao->getSlidePorId($conecta, filter_input(INPUT_POST, 'id'));
$slidesDao->titulo = $conecta->real_escape_string(filter_input(INPUT_POST, 'titulo'));
$slidesDao->subtitulo = $conecta->real_escape_string(filter_input(INPUT_POST, 'subtitulo'));
$slidesDao->link = $conecta->real_escape_string(filter_input(INPUT_POST, 'link'));
$slidesDao->ordem = \Dao\Funcoes::getUltimoId($conecta, 'slides', 'ordem');
if (!empty($_FILES['image']['name'])) {
    if ($slidesDao->image != '')
        if (file_exists($pasta . $slidesDao->image))
            unlink($pasta . $slidesDao->image);
    
        $slidesDao->image = \Dao\Funcoes::randFileName($_FILES['image']['name']);
        $image = Image::make($_FILES['image']['tmp_name'])->resize(2500, null, function ($constraint) {
            $constraint->aspectRatio();
        });

        $image->save($pasta . $slidesDao->image, 85);
}
$res = json_decode($slidesDao->salvar($conecta));
if ($res->data == 'Success') 
    \Dao\Funcoes::displayMessage('Confirmação', $res->message, 'slides.php');
else 
    \Dao\Funcoes::displayMessage('Erro', $res->message, 'slides.php', 'red');