<?php ini_set('date.timezone', 'Asia/Jakarta');
	
	if (!function_exists('acak')) {
		function acak($panjang)
		{
			//tentukan karakter random acak
			$karakter = 'ABCDEFGHIJKL1234567890^()';
			// buat variable kosong sebagai nilai
			//kembalikan (return)
			$string = '';
			
			for ($i = 0; $i < $panjang; $i++) {
				//lakukan random data dengan nilai awal 0
				//dan nilai akhir sebanyak value "$karatker"
				$pos = rand(0, strlen($karakter) - 1);
				//melakukan penggabungan antara nilai di kiri dengan nilai kanan
				$string .= $karakter[$pos];
			}
			
			return $string;
		}
	}

	function tujuan_dukcapil($selected, $name, $pk, $instansi_id)
	{
		$ci = get_instance();
		$cmb = "<select name='$name' class='form-control select2' required>";
		$data = $ci->db->query("SELECT * FROM user WHERE instansi_id = '$instansi_id' ")->row();
			$cmb .= "<option value='" . $d->$pk . "'";
			$cmb .= $selected == $d->$pk ? " selected='selected'" : '';
			$cmb .= ">" .  strtoupper($d->nama) . "</option>";
		$cmb .= "</select>";
		return $cmb;
	}

	function pt($selected, $name, $pk)
	{
		$ci = get_instance();
		$cmb = "<select name='$name' class='form-control select2' required>";
		$data = $ci->db->query("SELECT A.* FROM instansi A WHERE  A.akses = '1' AND A.status = '1' ORDER BY A.id ASC")->result();
		foreach ($data as $d) {
			$cmb .= "<option value='" . $d->$pk . "'";
			$cmb .= $selected == $d->$pk ? " selected='selected'" : '';
			$cmb .= ">" .  strtoupper($d->nama) . "</option>";
		}
		$cmb .= "</select>";
		return $cmb;
	}
	
	function pengadilan($selected, $name, $pk)
	{
		$ci = get_instance();
		$cmb = "<select name='$name' class='form-control select2' required>";
		$cmb .= "<option value=''>PILIH PENGADILAN</option>";
		$data = $ci->db->query("SELECT A.* FROM instansi A WHERE  A.akses = '2' AND A.status = '1' ORDER BY A.id ASC")->result();
		foreach ($data as $d) {
			$cmb .= "<option value='" . $d->$pk . "'";
			$cmb .= $selected == $d->$pk ? " selected='selected'" : '';
			$cmb .= ">" .  strtoupper($d->nama) . "</option>";
		}
		$cmb .= "</select>";
		return $cmb;
	}
	
	function dukcapil_prov($selected, $name, $pk)
	{
		$ci = get_instance();
		$cmb = "<select name='$name' class='form-control select2' required>";
		$data = $ci->db->query("SELECT * FROM instansi WHERE  akses = '3' AND status = '1' ORDER BY id ASC")->result();
		foreach ($data as $d) {
			$cmb .= "<option value='" . $d->$pk . "'";
			$cmb .= $selected == $d->$pk ? " selected='selected'" : '';
			$cmb .= ">" .  strtoupper($d->nama) . "</option>";
		}
		$cmb .= "</select>";
		return $cmb;
	}
	
	function dukcapil($selected, $name, $pk)
	{
		$ci = get_instance();
		$cmb = "<select name='$name' class='form-control select2' required>";
		$cmb .= "<option value=''>PILIH DISDUKCAPIL</option>";
		$data = $ci->db->query("SELECT * FROM instansi WHERE  akses = '4' AND status = '1' ORDER BY id ASC")->result();
		foreach ($data as $d) {
			$cmb .= "<option value='" . $d->$pk . "'";
			$cmb .= $selected == $d->$pk ? " selected='selected'" : '';
			$cmb .= ">" .  strtoupper($d->nama) . "</option>";
		}
		$cmb .= "</select>";
		return $cmb;
	}
	
	function dukcapil2($selected, $name, $pk)
	{
		$ci = get_instance();
		$cmb = "<select name='$name' class='form-control select2'>";
		$cmb .= "<option value=''>PILIH DISDUKCAPIL KE-2</option>";
		$data = $ci->db->query("SELECT * FROM instansi WHERE akses = '4' AND status = '1' ORDER BY id ASC")->result();
		foreach ($data as $d) {
			$cmb .= "<option value='" . $d->$pk . "'";
			$cmb .= $selected == $d->$pk ? " selected='selected'" : '';
			$cmb .= ">" .  strtoupper($d->nama) . "</option>";
		}
		$cmb .= "</select>";
		return $cmb;
	}
	
	if (!function_exists('bulan')) {
		function bulan($bulan)
		{
			switch ($bulan) {
				case '01':
                $bulan = "JANUARI";
                break;
				case '02':
                $bulan = "FEBRUARI";
                break;
				case '03':
                $bulan = "MARET";
                break;
				case '04':
                $bulan = "APRIL";
                break;
				case '05':
                $bulan = "MEI";
                break;
				case '06':
                $bulan = "JUNI";
                break;
				case '07':
                $bulan = "JULI";
                break;
				case '08':
                $bulan = "AGUSTUS";
                break;
				case '09':
                $bulan = "SEPTEMBER";
                break;
				case '10':
                $bulan = "OKTOBER";
                break;
				case '11':
                $bulan = "NOVEMBER";
                break;
				case '12':
                $bulan = "DESEMBER";
                break;
			}
			return $bulan;
		}
	}
	
	// fungsi tanggal statis indonesia
	if (!function_exists('tgl_indo')) {
		function tgl_indo($date)
		{
			//bi = bulan_indonesia
			$bi = explode('-', $date);
			$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',
			);
			return $bi['2'] . " " . $bulan[$bi['1']] . " " . $bi['0'];
		}
	}
	
	//function hari indonesia
	if (!function_exists('hari_indo')) {
		function hari_ini($hari)
		{
			//$hari = date ("D");
			switch ($hari) {
				case 'Sun':
                $hari_ini = "Minggu";
                break;
				case 'Mon':
                $hari_ini = "Senin";
                break;
				case 'Tue':
                $hari_ini = "Selasa";
                break;
				case 'Wed':
                $hari_ini = "Rabu";
                break;
				case 'Thu':
                $hari_ini = "Kamis";
                break;
				case 'Fri':
                $hari_ini = "Jumat";
                break;
				case 'Sat':
                $hari_ini = "Sabtu";
                break;
				default:
                $hari_ini = "Tidak di ketahui";
                break;
			}
			return  $hari_ini;
		}
	}
	
	if (!function_exists('number_to_words')) {
		function number_to_words($number)
		{
			$before_comma = trim(to_word($number));
			//$after_comma = trim(comma($number));
			return ucwords($results = $before_comma); /*.' koma '.$after_comma)*/
		}
		
		function to_word($number)
		{
			$words = "";
			$arr_number = array(
            "",
            "satu",
            "dua",
            "tiga",
            "empat",
            "lima",
            "enam",
            "tujuh",
            "delapan",
            "sembilan",
            "sepuluh",
            "sebelas"
			);
			
			if ($number < 12) {
				$words = " " . $arr_number[$number];
				} else if ($number < 20) {
				$words = to_word($number - 10) . " belas";
				} else if ($number < 100) {
				$words = to_word($number / 10) . " puluh " . to_word($number % 10);
				} else if ($number < 200) {
				$words = "seratus " . to_word($number - 100);
				} else if ($number < 1000) {
				$words = to_word($number / 100) . " ratus " . to_word($number % 100);
				} else if ($number < 2000) {
				$words = "seribu " . to_word($number - 1000);
				} else if ($number < 1000000) {
				$words = to_word($number / 1000) . " ribu " . to_word($number % 1000);
				} else if ($number < 1000000000) {
				$words = to_word($number / 1000000) . " juta " . to_word($number % 1000000);
				} else {
				$words = "undefined";
			}
			return $words;
		}
	}		