<?php

function delMask( $str ) {
    return (int)implode('',explode('.',$str));
}
function hakAkses( array $a){
    $akses = $_SESSION['userweb'];
    if(!in_array($akses,$a)){
        // header('Location:?');
        echo '<script>window.location = "?#";</script>';
    }
}
function bulan($bln){
    $bulan = [
        1 =>   'Januari',
            'Februari',
            'Maret',
            'April',
            'Mei',
            'Juni',
            'Juli',
            'Agustus',
            'September',
            'Oktober',
            'November',
            'Desember'
        ];

    return $bulan[$bln];
}
function tahun(){
    return [
        '2020','2021','2022','2023','2024','2025'
    ];
}

function list_merek(){
    include ('conn.php');
    $query = mysqli_query($con,"SELECT * FROM `merek` ORDER BY nama_merek ASC");
    $opt = "";
    while($row = mysqli_fetch_array($query)){
        $opt .= "<option value=\"".$row['idmerek']."\">".$row['nama_merek']."</option>";
    }  
    return $opt; 
}

function list_satuan(){
    include ('conn.php');
    $query = mysqli_query($con,"SELECT * FROM `satuan` ORDER BY nama_satuan ASC");
    $opt = "";
    while($row = mysqli_fetch_array($query)){
        $opt .= "<option value=\"".$row['id_satuan']."\">".$row['nama_satuan']."</option>";
    }  
    return $opt; 
}

function list_kategori(){
    include ('conn.php');
    $query = mysqli_query($con,"SELECT * FROM kategori ORDER BY nama_kategori ASC");
    $opt = "";
    while($row = mysqli_fetch_array($query)){
        $opt .= "<option value=\"".$row['idkategori']."\">".$row['nama_kategori']."</option>";
    }  
    return $opt; 
}
function list_divisi(){
    include ('conn.php');
    $query = mysqli_query($con,"SELECT * FROM divisi ORDER BY nama_divisi ASC");
    $opt = "";
    while($row = mysqli_fetch_array($query)){
        $opt .= "<option value=\"".$row['id_divisi']."\">".$row['nama_divisi']."</option>";
    }  
    return $opt; 
}
function list_konsumen(){
    include ('conn.php');
    $query = mysqli_query($con,"SELECT * FROM konsumen ORDER BY nama_konsumen ASC");
    $opt = "";
    while($row = mysqli_fetch_array($query)){
        $opt .= "<option value=\"".$row['id_konsumen']."\">".$row['nama_konsumen']."</option>";
    }  
    return $opt; 
}
function list_barang(){
    include ('conn.php');
    $barang = mysqli_query($con,"SELECT x.*,x1.nama_merek
        FROM barang x JOIN merek x1 ON x1.idmerek=x.merek_id 
        ORDER BY x.idbarang DESC");
    $opt = "";
    while($row2 = mysqli_fetch_array($barang)){
        $opt .= "<option value=\"".$row2['idbarang']."\">".$row2['nama_barang']." - ".$row2['nama_merek']." - ".$row2['tipe']."</option>";
    }
    return $opt; 
}

function encrypt($str) {
return base64_encode($str);
}
function decrypt($str) {
return base64_decode($str);
}

function base_url(){
    $base_url= ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
    $base_url.= "://".$_SERVER['HTTP_HOST'];
    $base_url.= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
    return $base_url;
}
?>