<?php
class klas_air {
    function koneksi() {
        $koneksi = mysqli_connect(
            "localhost",
            "atez4996_sarahtiara",
            "sarahtiara12",
            "atez4996_air_arasarah"
        );
        return $koneksi;

    }


    function dt_user($sesi_user) {
        $q=mysqli_query($this->koneksi(),"SELECT nama,kota,level FROM login WHERE username='$sesi_user'");
        $d=mysqli_fetch_row($q);
        return $d;
    }

    function user_to_idtarif($username) {
        $q=mysqli_query($this->koneksi(),"SELECT t.id_tarif FROM login l JOIN tarif t ON UPPER(TRIM(t.tipe))=UPPER(TRIM(l.tipe)) WHERE l.username='$username' AND t.status='AKTIF' LIMIT 1");
        $d=mysqli_fetch_row($q);
        return $d[0] ?? null;
    }

    function kdtarif_to_tarif($id_tarif) {
        $q=mysqli_query($this->koneksi(),"SELECT tarif FROM tarif WHERE id_tarif='$id_tarif' AND status='AKTIF'");
        $d=mysqli_fetch_row($q);
        return $d[0] ?? null;
    }

    function no_to_user($no) {
        $q=mysqli_query($this->koneksi(),"SELECT username FROM pemakaian WHERE no='$no'");
        $d=mysqli_fetch_row($q);
        return $d[0] ?? null;
    }

    function tgl_walik($tgl) {
        $e=explode("-",$tgl);
        $bulan = array(
            "01" => "Januari",
            "02" => "Februari",
            "03" => "Maret",
            "04" => "April",
            "05" => "Mei",
            "06" => "Juni",
            "07" => "Juli",
            "08" => "Agustus",
            "09" => "September",
            "10" => "Oktober",
            "11" => "November",
            "12" => "Desember"
        );
        $tgl_baru="$e[2] ".$bulan[$e[1]]." $e[0]";
        return $tgl_baru;
    }

    function bln($no)
    {
        if ($no == 1) $bln = "Januari";
        elseif ($no == 2) $bln = "Februari";
        elseif ($no == 3) $bln = "Maret";
        elseif ($no == 4) $bln = "April";
        elseif ($no == 5) $bln = "Mei";
        elseif ($no == 6) $bln = "Juni";
        elseif ($no == 7) $bln = "Juli";
        elseif ($no == 8) $bln = "Agustus";
        elseif ($no == 9) $bln = "September";
        elseif ($no == 10) $bln = "Oktober";
        elseif ($no == 11) $bln = "November";
        else
            $bln = "Desember";
        return $bln;
    }
}
?>
