<?php
defined('BASEPATH') or exit('No direct script access allowed');

class ControllerAlamat extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        //validasi jika user belum login
        check_not_login();
        if ($this->session->userdata('level') != 1) {
            redirect();
        }
        $this->set_timezone();
        $this->load->library('encrypt');
        $this->load->library('form_validation');
        $this->load->library('Mycustom');
        $this->load->library('pdfgenerator');
        $this->load->library('Notifikasi');
        $this->load->model('bagian_owner/insert_model');
        $this->load->model('bagian_owner/select_model');
        $this->load->model('bagian_owner/update_model');
        $this->set_timezone();
    }
    public function set_timezone()
    {
        date_default_timezone_set("Asia/Jakarta");
    }
    public function index()
    {
        redirect('arisan');
    }
    public function Kot_kab()
    {
        $province_id                 = $this->input->post('province_id');
        $kab_kota                    = file_get_contents('https://open-api.my.id/api/wilayah/regencies/' . $province_id);
        $data_kab_kota               = json_decode($kab_kota, true);
        foreach ($data_kab_kota as $Data_kab_kota) :
            echo '<option value="' . $Data_kab_kota['id'] . '">' . $Data_kab_kota['name'] . '</option>';
        endforeach;
    }
    public function kecamatan()
    {
        $kab_kot                     = $this->input->post('kab_kot');
        $kecamatan                   = file_get_contents('https://open-api.my.id/api/wilayah/districts/' . $kab_kot);
        $data_kecamatan              = json_decode($kecamatan, true);
        foreach ($data_kecamatan as $Data_kecamatan) :
            echo '<option value="' . $Data_kecamatan['id'] . '">' . $Data_kecamatan['name'] . '</option>';
        endforeach;
    }
    public function nm_desabaru()
    {
        $kecamatan                     = $this->input->post('kecamatan');
        $nm_desabaru                   = file_get_contents('https://open-api.my.id/api/wilayah/villages/' . $kecamatan);
        $data_desabaru                 = json_decode($nm_desabaru, true);
        foreach ($data_desabaru as $Data_desabaru) :
            echo '<option value="' . $Data_desabaru['id'] . '">' . $Data_desabaru['name'] . '</option>';
        endforeach;
    }
}

/* End of file ControllerAlamat.php and path \application\controllers\arisan\ControllerAlamat.php */