<?php
	require_once('session.php');
	if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    header("HTTP/1.1 403 Forbidden");
    echo "Access forbidden. Use HTTPS.";
    exit();
    }
    if($u['cuid'] == 1){ 
    if (isset($_POST['csrf_token']) && $_POST['csrf_token'] === $_SESSION['csrf_token']) {
    $users = $u['user'];
    $content = str_replace(array( "’","'" ),"&apos;",$_POST['deskripsi']);
    $status = $_POST['status'];
    $join_date = date('Y-m-d');
    $kode = date('YmdHis');
    $tipe_gambar = array('image/jpg','image/jpeg', 'image/png', 'image/gif');
    $gbr = $_FILES['image']['name'];
    $ukuran = $_FILES['image']['size'];
    $tipe = $_FILES['image']['type'];
    $error = $_FILES['image']['error'];
    $explode = explode('.',$gbr);
    $extensi  = $explode[count($explode)-1];
    $newname = 'brand_'.$users.'_'.$kode.'.'.$extensi;
    $upload_dir = "../../upload/";
    if($_FILES['image']['size'] <= 2048000){
        if ($gbr != "" && $error == 0) {
            $fileMimeType = mime_content_type($_FILES['image']['tmp_name']);
            $allowedMimeTypes = array('image/jpeg', 'image/png', 'image/gif');

            if (in_array($fileMimeType, $allowedMimeTypes)) {
                move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir . $newname);
                $query = mysqli_query($conn,"UPDATE `tb_banner` SET `image` = '$newname', `content` = '$content', `status` = '$status' WHERE cuid = 1") or die(mysqli_error());
                header('location:../banner/?notif=1');
           }
           else {
                header('location:../banner/?notif=3');
           } 
        }
        else {
            $query = mysqli_query($conn,"UPDATE `tb_banner` SET `content` = '$content', `status` = '$status' WHERE cuid = 1") or die(mysqli_error());
            header('location:../banner/?notif=1');
        }
    }
    else if($_FILES['image']['size'] >= 2048000 || $_FILES['image']['size'] == 0){
        header('location:../banner/?notif=2');
    }
} else {
    // CSRF token is invalid, handle the error
    echo "Ngapain Bang Ngetamper Data Kah?";
    exit();
}
} else { echo 'BOKEP CXFTEAMS'; }
?>