<?php
       require_once 'common/database.php';
       if(!isset($_SESSION['logged_in'])){
           header('location: index.php');
       }
            date_default_timezone_set('Asia/Jakarta'); 
       
           $nama = $_POST['nama'];
           $deskripsi = $_POST['deskripsi'];  
           $tanggal = $_POST['tanggal'];
           $harga = $_POST['harga'];
           $gambar = $_FILES['gambar']['name'];
           $kuota = $_POST['kuota'];

           $tmp_file = $_FILES['gambar']['tmp_name'];
           $path  = "uploads/".$gambar;

                    if(move_uploaded_file($tmp_file,$path)){
                        $do = CreatePaket($nama,$deskripsi,$tanggal,$gambar,$harga,$kuota);
                        if($do < 0){
                            echo "<script>alert('Paket $nama telah dibuat');
                                window.location = 'paket.php'</script>";
                        }
                        else{
                            echo "<script>alert('Paket $nama gagal dibuat');
                                window.location = 'paket#addnew.php'</script>";
                        }
                    }
                    else{
                        echo "<script>alert('Database is in trouble!');
                                window.location = 'paket.php'</script>";
                    }
           
            if($tanggal < date_default_timezone_set('Asia/Jakarta')){
                echo "<script>alert('Tanggal tidak boleh yang sudah lewat');
                        window.location = 'paket#addnew.php'</script>";
            }

       



?>