<?php
    require_once('session.php');

    $trxID = $_POST['trxID'];
    $kode = date('YdmHis');
    $tipe_gambar = array('image/jpg','image/jpeg', 'image/x-png', 'image/png');
    $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 = 'konfirmasi_'.$trxID.'_'.$kode.'.'.$extensi;
    $upload_dir = "../bukti/";
    $created_date = date('Y-m-d H:i:s');
    
    if(isset($_POST['submit'])){
        $sql_2 = mysqli_query($conn,"SELECT * FROM `tb_transaksi` WHERE kd_transaksi = '$trxID'") or die(mysqli_error());
        $s2 = mysqli_fetch_array($sql_2);
        if($s2['status'] == 0){
            if(in_array(strtolower($tipe), $tipe_gambar)){
                move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir . $newname);
                $query = mysqli_query($conn,"UPDATE `tb_transaksi` SET `note` = '$newname' WHERE kd_transaksi = '$trxID'") or die(mysqli_error());
                header('Location:../m/history.php/');
                exit();
            }
            else {
                header('Location:../m/payment.php/?trxID='.$trxID.'&notif=1');
                exit();
            } 
            
        }
        else {
            header('Location:../m/history.php/');
            exit();
        }
    }
?>