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

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

include "../../../../model/viewlist.php";
include "../../../../model/viewkatlist.php";
include "../../../../controller/upload.php";

$aksi = $_GET[aksi];
if($aksi=='tambah'){
    $katlist = new viewkatlist();

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

    $katlist->addkatlist($_POST[nama],$tag);

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

    $katlist->id = $_POST[id];
    $katlist->editkatlist($_POST[nama]);

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

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

    if (empty($nama_file)) {
      $nama_unik = 'default_user.png';
    }else{
      $nama_unik = $acak.$nama_file;
      $upload->lists($nama_unik,$db->linkupload());
    }

    $list->addlist($_POST[id],$_POST[nama],$_POST[keterangan],$nama_unik);

    header("location:../../../../index.php?module=list&act=edit&id=$_POST[id]");
}
elseif($aksi=='delete'){
    $list = new viewlist();
    $katlist = new viewkatlist();

    $katlist->id = $_GET[id];
    $katlist->deletekatlist();

    $list->deletelistkat($_GET[id]);

    header("location:../../../../index.php?module=list");
}
elseif ($aksi=='deletelist') {
    $list = new viewlist();

    $list->id = $_GET[idk];
    $list->deletelist();

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