<?php
//error_reporting(0);
session_start();
ob_start();
include "../../../../konfig/dbconnect.php";

$db = new database();
$db->dbsql();   

include "../../../../model/viewgaleri.php";
include "../../../../model/viewkatgaleri.php";
include "../../../../controller/upload.php";

$aksi = $_GET[aksi];
if($aksi=='tambah'){
    $katgaleri = new viewkatgaleri();

    $tag = str_replace(" ", "-", $_POST[nama]);

    $katgaleri->addkatgaleri($_POST[nama],$_POST[keterangan],$tag);

    header("location:../../../../index.php?module=galeri&act=edit&tag=$tag");
}
elseif($aksi=='edit'){
    $katgaleri = new viewkatgaleri();

    $katgaleri->id = $_POST[id];
    $katgaleri->editkatgaleri($_POST[nama],$_POST[keterangan]);

    header("location:../../../../index.php?module=galeri&act=edit&id=$_POST[id]");
}
elseif ($aksi=='tambah_gambar') {
    $galeri = new viewgaleri();
    $upload = new upload();

    $lokasi_file    = $_FILES['gambar']['tmp_name'];
    $tipe_file      = $_FILES['gambar']['type'];
    $nama_file      = $_FILES['gambar']['name'];
    $acak           = rand(1,99);
    $nama_unik      = $acak.$nama_file;

    $upload->galeri($nama_unik,$db->linkupload());

    $galeri->addgaleri($_POST[id],$_POST[nama]);

    header("location:../../../../index.php?module=galeri&act=edit&id=$_POST[id]");
}
elseif($aksi=='delete'){
    $galeri = new viewgaleri();
    $katgaleri = new viewkatgaleri();
    
    $katgaleri->id = $_GET[id];
    $katgaleri->deletekatgaleri();

    $galeri->deletegalerikat($_GET[id]);
    
    header("location:../../../../index.php?module=galeri");
}
elseif ($aksi=='deletegambar') {
    $galeri = new viewgaleri();

    $galeri->id = $_GET[idk];
    $galeri->deletegaleri();

    header("location:../../../../index.php?module=galeri&act=edit&id=$_GET[id]");
}
