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

class Pesertadidik extends MY_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/pesertadidik
	 *	- or -
	 * 		http://example.com/index.php/pesertadidik/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/pesertadidik/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public $_fieldname;
	public function __construct()
	{
		parent::__construct();
		$this->load->model(array('pesertadidik_m','master/master_m'));
		$this->lang->load('pesertadidik');
		$this->_fieldname = 'peserta_didik_id,nama,jenis_kelamin,nisn,nik,tempat_lahir,tanggal_lahir,agama_id,kebutuhan_khusus_id,alamat_jalan,rt,rw,nama_dusun,desa_kelurahan,kode_wilayah,kode_pos,lintang,bujur,jenis_tinggal_id,alat_transportasi_id,nik_ayah,nik_ibu,anak_keberapa,nik_wali,nomor_telepon_rumah,nomor_telepon_seluler,email,penerima_kps,no_kps,layak_pip,penerima_kip,no_kip,nm_kip,no_kks,reg_akta_lahir,id_layak_pip,id_bank,rekening_bank,nama_kcp,rekening_atas_nama,status_data,nama_ayah,tahun_lahir_ayah,jenjang_pendidikan_ayah,pekerjaan_id_ayah,penghasilan_id_ayah,kebutuhan_khusus_id_ayah,nama_ibu_kandung,tahun_lahir_ibu,jenjang_pendidikan_ibu,penghasilan_id_ibu,pekerjaan_id_ibu,kebutuhan_khusus_id_ibu,nama_wali,tahun_lahir_wali,jenjang_pendidikan_wali,pekerjaan_id_wali,penghasilan_id_wali,kewarganegaraan,create_date,last_update,soft_delete,last_sync,updater_id';
		$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
	}

	public function index()
	{

		$this->data['subtitle'] = $this->lang->line('pesertadidik_heading');
		// $this->data['pesertadidik']  = $this->pesertadidik_m->get_data();
		// dump($this->data['pesertadidik']); 
		$this->parser->parse('pesertadidik_list',$this->data);
	}

	public function pesertadidik_ajax()
	{
		if (!$this->input->is_ajax_request()) {
		   exit('No direct script access allowed');
		}
		$pesertadidik = $this->pesertadidik_m->get_datatables();
		$data = array();

		foreach ($pesertadidik as $item) {
            $row   = array();
            $row[] = '<input type="checkbox" name="pesertadidik-id[]" class="styled" value="' . $item->peserta_didik_id . '">';
            $row[] = '<a href="'. site_url('pesertadidik/view/' . $item->peserta_didik_id) .'">'. title($item->nama) . '</a>';
            $row[] = $item->jenis_kelamin;
            $row[] =  $item->nisn ;
            $row[] =  $item->tempat_lahir ;
            $row[] =  $item->tanggal_lahir ;
            
            $row[] = '<a href="'. site_url('pesertadidik/edit/' . $item->peserta_didik_id) . '" class="btn btn-primary" >' . lang('app_edit_btn') . '</a>&nbsp;<a href="'. site_url('pesertadidik/view/' . $item->peserta_didik_id) . '" class="btn btn-warning">' . lang('app_view_btn') . '</a>';

            $data[] = $row;
        }

		$output = array(
                        "draw"            => $_POST['draw'],
                        "recordsTotal"    => $this->pesertadidik_m->count_all(),
                        "recordsFiltered" => $this->pesertadidik_m->count_filtered(),
                        "data"            => $data,
                );

		return $this->output
	        ->set_content_type('application/json')
	        ->set_status_header(200)
	        ->set_output(json_encode($output));

	}

	public function view($id = NULL)
	{

		$this->data['subtitle'] = $this->lang->line('pesertadidik_heading');
		$this->data['pesertadidik']  = $this->pesertadidik_m->get_data($id);

		$this->parser->parse('pesertadidik_detail',$this->data);
	}

	public function edit($id = NULL)
	{
		if ($id == NULL)
	{
		$this->data['subtitle'] = $this->lang->line('pesertadidik_create_heading');
		$pesertadidik           = $this->pesertadidik_m->_new();
	}
	else
	{
		$this->data['subtitle'] = $this->lang->line('pesertadidik_edit_heading');
		$pesertadidik = $this->pesertadidik_m->get($id);
	}


	$rules = $this->pesertadidik_m->_rules;

	$this->form_validation->set_rules($rules);

	if ($this->form_validation->run($this) == TRUE)
	{
		$data  = $this->pesertadidik_m->array_form_post(array('nama','jenis_kelamin','nisn','nik','tempat_lahir','tanggal_lahir','agama_id','kebutuhan_khusus_id','alamat_jalan','rt','rw','nama_dusun','desa_kelurahan','kode_wilayah','kode_pos','lintang','bujur','jenis_tinggal_id','alat_transportasi_id','nik_ayah','nik_ibu','anak_keberapa','nik_wali','nomor_telepon_rumah','nomor_telepon_seluler','email','penerima_kps','no_kps','layak_pip','penerima_kip','no_kip','nm_kip','no_kks','reg_akta_lahir','id_layak_pip','id_bank','rekening_bank','nama_kcp','rekening_atas_nama','status_data','nama_ayah','tahun_lahir_ayah','jenjang_pendidikan_ayah','pekerjaan_id_ayah','penghasilan_id_ayah','kebutuhan_khusus_id_ayah','nama_ibu_kandung','tahun_lahir_ibu','jenjang_pendidikan_ibu','penghasilan_id_ibu','pekerjaan_id_ibu','kebutuhan_khusus_id_ibu','nama_wali','tahun_lahir_wali','jenjang_pendidikan_wali','pekerjaan_id_wali','penghasilan_id_wali','kewarganegaraan','create_date','last_update','soft_delete','last_sync','updater_id'));

		if($this->pesertadidik_m->save($data, $id))
		{
			redirect('pesertadidik');
		}
	}

	// Data Pribadi

	$this->data['nama'] = array(
		'name'  => 'nama',
		'id'    => 'nama',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nama_placeholder'),
		'value' => $this->form_validation->set_value('nama', $pesertadidik->nama)
	); 

	// pass the user to the view
	$genders = array('l'=>'Laki-laki', 'p'=>'Perempuan');
	$this->data['gender_item']    = '';

	foreach ($genders as $key => $value) {
		$checked = null;
		$item = null;
		
		if ($key  == strtolower($pesertadidik->jenis_kelamin)) {
			$checked= ' checked="checked"';
		}
		
		$this->data['gender_item'] .= '<label class="radio-inline">' . htmlspecialchars($value,ENT_QUOTES,'UTF-8') . '<input type="radio" class="styled" name="jenis_kelamin" value="'.$key.'" '.$checked.'></label>';
	}


	$this->data['nisn'] = array(
		'name'  => 'nisn',
		'id'    => 'nisn',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nisn_placeholder'),
		'value' => $this->form_validation->set_value('nisn', $pesertadidik->nisn)
	); 
 

	$this->data['kewarganegaraan'] = array(
		'name'        => 'kewarganegaraan',
		'id'          => 'select-kewarganegaraan',
		'required'    => 'required',
		'data-master'    => 'negara',
		'class'       => 'select2-master',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_kewarganegaraan')
	);

	$this->data['kewarganegaraan_option'] = $this->master_m->get_master('negara','negara_id','nama', $pesertadidik->kewarganegaraan);
	$this->data['kewarganegaraan_selected'] = $pesertadidik->kewarganegaraan;

	$this->data['nik'] = array(
		'name'  => 'nik',
		'id'    => 'nik',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nik_placeholder'),
		'value' => $this->form_validation->set_value('nik', $pesertadidik->nik)
	); 

	$this->data['tempat_lahir'] = array(
		'name'  => 'tempat_lahir',
		'id'    => 'tempat_lahir',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_tempat_lahir_placeholder'),
		'value' => $this->form_validation->set_value('tempat_lahir', $pesertadidik->tempat_lahir)
	); 

	$this->data['tanggal_lahir'] = array(
		'name'  => 'tanggal_lahir',
		'id'    => 'tanggal_lahir',
		'type'  => 'date',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_tanggal_lahir_placeholder'),
		'value' => $this->form_validation->set_value('tanggal_lahir', $pesertadidik->tanggal_lahir)
	); 

	$this->data['agama'] = array(
		'name'        => 'agama_id',
		'id'          => 'select-agama',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_agama_id')
	);

	$this->data['agama_option'] = $this->master_m->get_master('agama','agama_id','nama');
	$this->data['agama_selected'] = $pesertadidik->agama_id;

	$this->data['kebutuhan_khusus'] = array(
		'name'        => 'kebutuhan_khusus_id',
		'id'          => 'select-kebutuhan_khusus',
		'data-master'    => 'kebutuhan_khusus',
		'class'       => 'select2-master',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_kebutuhan_khusus_id')
	);

	$this->data['kebutuhan_khusus_option'] = $this->master_m->get_master('kebutuhan_khusus','kebutuhan_khusus_id','kebutuhan_khusus', $pesertadidik->kebutuhan_khusus_id);
	$this->data['kebutuhan_khusus_selected'] = $pesertadidik->kebutuhan_khusus_id;


	$this->data['alamat_jalan'] = array(
		'name'  => 'alamat_jalan',
		'id'    => 'alamat_jalan',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_alamat_jalan_placeholder'),
		'value' => $this->form_validation->set_value('alamat_jalan', $pesertadidik->alamat_jalan)
	); 

	$this->data['rt'] = array(
		'name'  => 'rt',
		'id'    => 'rt',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_rt_placeholder'),
		'value' => $this->form_validation->set_value('rt', $pesertadidik->rt)
	); 

	$this->data['rw'] = array(
		'name'  => 'rw',
		'id'    => 'rw',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_rw_placeholder'),
		'value' => $this->form_validation->set_value('rw', $pesertadidik->rw)
	); 

	$this->data['nama_dusun'] = array(
		'name'  => 'nama_dusun',
		'id'    => 'nama_dusun',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nama_dusun_placeholder'),
		'value' => $this->form_validation->set_value('nama_dusun', $pesertadidik->nama_dusun)
	); 

	$this->data['desa_kelurahan'] = array(
		'name'  => 'desa_kelurahan',
		'id'    => 'desa_kelurahan',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_desa_kelurahan_placeholder'),
		'value' => $this->form_validation->set_value('desa_kelurahan', $pesertadidik->desa_kelurahan)
	); 
	
	$this->data['kode_wilayah'] = array(
		'name'        => 'kode_wilayah',
		'id'          => 'select-kode_wilayah',
		'required'    => 'required',
		'data-master'    => 'mst_wilayah',
		'class'       => 'select2-master',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_kode_wilayah')
	);

	$this->data['kode_wilayah_option'] = $this->master_m->get_master('mst_wilayah','kode_wilayah','nama', $pesertadidik->kode_wilayah);
	$this->data['kode_wilayah_selected'] = trim($pesertadidik->kode_wilayah);

	$this->data['kode_pos'] = array(
		'name'  => 'kode_pos',
		'id'    => 'kode_pos',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_kode_pos_placeholder'),
		'value' => $this->form_validation->set_value('kode_pos', $pesertadidik->kode_pos)
	); 

	$this->data['lintang'] = array(
		'name'  => 'lintang',
		'id'    => 'lintang',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_lintang_placeholder'),
		'value' => $this->form_validation->set_value('lintang', $pesertadidik->lintang)
	); 

	$this->data['bujur'] = array(
		'name'  => 'bujur',
		'id'    => 'bujur',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_bujur_placeholder'),
		'value' => $this->form_validation->set_value('bujur', $pesertadidik->bujur)
	); 

	$this->data['jenis_tinggal_id'] = array(
		'name'        => 'jenis_tinggal_id',
		'id'          => 'select-jenis_tinggal_id',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_jenis_tinggal_id')
	);

	$this->data['jenis_tinggal_id_option'] = $this->master_m->get_master('jenis_tinggal','jenis_tinggal_id','nama');
	$this->data['jenis_tinggal_id_selected'] = $pesertadidik->jenis_tinggal_id;


	$this->data['alat_transportasi_id'] = array(
		'name'        => 'alat_transportasi_id',
		'id'          => 'select-alat_transportasi_id',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_alat_transportasi_id')
	);

	$this->data['alat_transportasi_id_option'] = $this->master_m->get_master('alat_transportasi','alat_transportasi_id','nama');
	$this->data['alat_transportasi_id_selected'] = $pesertadidik->alat_transportasi_id;
	
	
	$this->data['anak_keberapa'] = array(
		'name'  => 'anak_keberapa',
		'id'    => 'anak_keberapa',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_anak_keberapa_placeholder'),
		'value' => $this->form_validation->set_value('anak_keberapa', $pesertadidik->anak_keberapa)
	); 

	// pass the user to the view
	$kps = array('1'=>'Ya', '0'=>'Tidak');
	$this->data['penerima_kps_item']    = '';

	foreach ($kps as $key => $value) {
		$checked = null;
		$item = null;
		
		if ($key  == strtolower($pesertadidik->penerima_kps)) {
			$checked= ' checked="checked"';
		}
		
		$this->data['penerima_kps_item'] .= '<label class="radio-inline">' . htmlspecialchars($value,ENT_QUOTES,'UTF-8') . '<input type="radio" class="styled" name="penerima_kps" value="'.$key.'" '.$checked.'></label>';
	}

	$this->data['no_kps'] = array(
		'name'  => 'no_kps',
		'id'    => 'no_kps',
		'type'  => 'text',
		'disabled'  => 'disabled',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_no_kps_placeholder'),
		'value' => $this->form_validation->set_value('no_kps', $pesertadidik->no_kps)
	); 

	// pass the user to the view
	$layak_pip = array('1'=>'Ya', '0'=>'Tidak');
	$this->data['layak_pip_item']    = '';

	foreach ($layak_pip as $key => $value) {
		$checked = null;
		$item = null;
		
		if ($key  == strtolower($pesertadidik->layak_pip)) {
			$checked= ' checked="checked"';
		}
		
		$this->data['layak_pip_item'] .= '<label class="radio-inline">' . htmlspecialchars($value,ENT_QUOTES,'UTF-8') . '<input type="radio" class="styled" name="layak_pip" value="'.$key.'" '.$checked.'></label>';
	}


	$kip = array('1'=>'Ya', '0'=>'Tidak');
	$this->data['penerima_kip_item']    = '';

	foreach ($kip as $key => $value) {
		$checked = null;
		$item = null;
		
		if ($key  == strtolower($pesertadidik->penerima_kip)) {
			$checked= ' checked="checked"';
		}
		
		$this->data['penerima_kip_item'] .= '<label class="radio-inline">' . htmlspecialchars($value,ENT_QUOTES,'UTF-8') . '<input type="radio" class="styled" name="penerima_kip" value="'.$key.'" '.$checked.'></label>';
	}


	$this->data['no_kip'] = array(
		'name'  => 'no_kip',
		'id'    => 'no_kip',
		'type'  => 'text',
		'disabled'  => 'disabled',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_no_kip_placeholder'),
		'value' => $this->form_validation->set_value('no_kip', $pesertadidik->no_kip)
	); 

	$this->data['nm_kip'] = array(
		'name'  => 'nm_kip',
		'id'    => 'nm_kip',
		'type'  => 'text',
		'disabled'  => 'disabled',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nm_kip_placeholder'),
		'value' => $this->form_validation->set_value('nm_kip', $pesertadidik->nm_kip)
	); 

	$this->data['no_kks'] = array(
		'name'  => 'no_kks',
		'id'    => 'no_kks',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_no_kks_placeholder'),
		'value' => $this->form_validation->set_value('no_kks', $pesertadidik->no_kks)
	); 

	$this->data['reg_akta_lahir'] = array(
		'name'  => 'reg_akta_lahir',
		'id'    => 'reg_akta_lahir',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_reg_akta_lahir_placeholder'),
		'value' => $this->form_validation->set_value('reg_akta_lahir', $pesertadidik->reg_akta_lahir)
	); 

	$this->data['id_layak_pip'] = array(
		'name'  => 'id_layak_pip',
		'id'    => 'id_layak_pip',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_id_layak_pip_placeholder'),
		'value' => $this->form_validation->set_value('id_layak_pip', $pesertadidik->id_layak_pip)
	); 

	$this->data['id_layak_pip'] = array(
		'name'        => 'id_layak_pip',
		'id'          => 'select-id_layak_pip',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_id_layak_pip')
	);

	$this->data['id_layak_pip_option'] = $this->master_m->get_master('alasan_layak_pip','id_layak_pip','alasan_layak_pip');
	$this->data['id_layak_pip_selected'] = $pesertadidik->id_layak_pip;


	// Info Rekening


	$this->data['bank'] = array(
		'name'        => 'id_bank',
		'id'          => 'select-bank',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_id_bank')
	);

	$this->data['bank_option'] = $this->master_m->get_master('bank','id_bank','nm_bank');
	$this->data['bank_selected'] = $pesertadidik->id_bank;

	$this->data['rekening_bank'] = array(
		'name'  => 'rekening_bank',
		'id'    => 'rekening_bank',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_rekening_bank_placeholder'),
		'value' => $this->form_validation->set_value('rekening_bank', $pesertadidik->rekening_bank)
	); 

	$this->data['nama_kcp'] = array(
		'name'  => 'nama_kcp',
		'id'    => 'nama_kcp',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nama_kcp_placeholder'),
		'value' => $this->form_validation->set_value('nama_kcp', $pesertadidik->nama_kcp)
	); 

	$this->data['rekening_atas_nama'] = array(
		'name'  => 'rekening_atas_nama',
		'id'    => 'rekening_atas_nama',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_rekening_atas_nama_placeholder'),
		'value' => $this->form_validation->set_value('rekening_atas_nama', $pesertadidik->rekening_atas_nama)
	); 

	// Data Ayah

	$this->data['nama_ayah'] = array(
		'name'  => 'nama_ayah',
		'id'    => 'nama_ayah',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nama_ayah_placeholder'),
		'value' => $this->form_validation->set_value('nama_ayah', $pesertadidik->nama_ayah)
	); 
	$this->data['nik_ayah'] = array(
		'name'  => 'nik_ayah',
		'id'    => 'nik_ayah',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nik_ayah_placeholder'),
		'value' => $this->form_validation->set_value('nik_ayah', $pesertadidik->nik_ayah)
	);  

	$this->data['tahun_lahir_ayah'] = array(
		'name'  => 'tahun_lahir_ayah',
		'id'    => 'tahun_lahir_ayah',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_tahun_lahir_ayah_placeholder'),
		'value' => $this->form_validation->set_value('tahun_lahir_ayah', $pesertadidik->tahun_lahir_ayah)
	); 

	$this->data['jenjang_pendidikan_ayah'] = array(
		'name'        => 'jenjang_pendidikan_ayah',
		'id'          => 'select-jenjang_pendidikan_ayah',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_jenjang_pendidikan_ayah')
	);

	$this->data['jenjang_pendidikan_ayah_option'] = $this->master_m->get_master('jenjang_pendidikan','jenjang_pendidikan_id','nama');
	$this->data['jenjang_pendidikan_ayah_selected'] = $pesertadidik->jenjang_pendidikan_ayah;

	$this->data['pekerjaan_id_ayah'] = array(
		'name'        => 'pekerjaan_id_ayah',
		'id'          => 'select-pekerjaan_id_ayah',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_pekerjaan_id_ayah')
	);

	$this->data['pekerjaan_id_ayah_option'] = $this->master_m->get_master('pekerjaan','pekerjaan_id','nama');
	$this->data['pekerjaan_id_ayah_selected'] = $pesertadidik->pekerjaan_id_ayah;

	$this->data['penghasilan_id_ayah'] = array(
		'name'        => 'penghasilan_id_ayah',
		'id'          => 'select-penghasilan_id_ayah',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_penghasilan_id_ayah')
	);

	$this->data['penghasilan_id_ayah_option'] = $this->master_m->get_master('penghasilan_orangtua_wali','penghasilan_orangtua_wali_id','nama');
	$this->data['penghasilan_id_ayah_selected'] = $pesertadidik->penghasilan_id_ayah;

	$this->data['kebutuhan_khusus_id_ayah'] = array(
		'name'        => 'kebutuhan_khusus_id_ayah',
		'id'          => 'select-kebutuhan_khusus_id_ayah',
		'required'    => 'required',
		'data-master'    => 'kebutuhan_khusus',
		'class'       => 'select2-master',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_kebutuhan_khusus_id_ayah')
	);

	$this->data['kebutuhan_khusus_id_ayah_option'] = $this->master_m->get_master('kebutuhan_khusus','kebutuhan_khusus_id','kebutuhan_khusus', $pesertadidik->kebutuhan_khusus_id_ayah);
	$this->data['kebutuhan_khusus_id_ayah_selected'] = $pesertadidik->kebutuhan_khusus_id_ayah;


	// Data Ibu kandung
	$this->data['nama_ibu_kandung'] = array(
		'name'  => 'nama_ibu_kandung',
		'id'    => 'nama_ibu_kandung',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nama_ibu_kandung_placeholder'),
		'value' => $this->form_validation->set_value('nama_ibu_kandung', $pesertadidik->nama_ibu_kandung)
	); 

	$this->data['nik_ibu'] = array(
		'name'  => 'nik_ibu',
		'id'    => 'nik_ibu',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nik_ibu_placeholder'),
		'value' => $this->form_validation->set_value('nik_ibu', $pesertadidik->nik_ibu)
	); 

	$this->data['tahun_lahir_ibu'] = array(
		'name'  => 'tahun_lahir_ibu',
		'id'    => 'tahun_lahir_ibu',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_tahun_lahir_ibu_placeholder'),
		'value' => $this->form_validation->set_value('tahun_lahir_ibu', $pesertadidik->tahun_lahir_ibu)
	); 

	$this->data['jenjang_pendidikan_ibu'] = array(
		'name'        => 'jenjang_pendidikan_ibu',
		'id'          => 'select-jenjang_pendidikan_ibu',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_jenjang_pendidikan_ibu')
	);

	$this->data['jenjang_pendidikan_ibu_option'] = $this->master_m->get_master('jenjang_pendidikan','jenjang_pendidikan_id','nama');
	$this->data['jenjang_pendidikan_ibu_selected'] = $pesertadidik->jenjang_pendidikan_ibu;

	$this->data['pekerjaan_id_ibu'] = array(
		'name'        => 'pekerjaan_id_ibu',
		'id'          => 'select-pekerjaan_id_ibu',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_pekerjaan_id_ibu')
	);

	$this->data['pekerjaan_id_ibu_option'] = $this->master_m->get_master('pekerjaan','pekerjaan_id','nama');
	$this->data['pekerjaan_id_ibu_selected'] = $pesertadidik->pekerjaan_id_ibu;

	$this->data['penghasilan_id_ibu'] = array(
		'name'        => 'penghasilan_id_ibu',
		'id'          => 'select-penghasilan_id_ibu',
		'required'    => 'required',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_penghasilan_id_ibu')
	);

	$this->data['penghasilan_id_ibu_option'] = $this->master_m->get_master('penghasilan_orangtua_wali','penghasilan_orangtua_wali_id','nama');
	$this->data['penghasilan_id_ibu_selected'] = $pesertadidik->penghasilan_id_ibu;

	$this->data['kebutuhan_khusus_id_ibu'] = array(
		'name'        => 'kebutuhan_khusus_id_ibu',
		'id'          => 'select-kebutuhan_khusus_id_ibu',
		'required'    => 'required',
		'data-master'    => 'kebutuhan_khusus',
		'class'       => 'select2-master',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_kebutuhan_khusus_id_ibu')
	);

	$this->data['kebutuhan_khusus_id_ibu_option'] = $this->master_m->get_master('kebutuhan_khusus','kebutuhan_khusus_id','kebutuhan_khusus', $pesertadidik->kebutuhan_khusus_id_ibu);
	$this->data['kebutuhan_khusus_id_ibu_selected'] = $pesertadidik->kebutuhan_khusus_id_ibu;

	
	// Data Wali

	$this->data['nama_wali'] = array(
		'name'  => 'nama_wali',
		'id'    => 'nama_wali',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nama_wali_placeholder'),
		'value' => $this->form_validation->set_value('nama_wali', $pesertadidik->nama_wali)
	); 
	
	$this->data['nik_wali'] = array(
		'name'  => 'nik_wali',
		'id'    => 'nik_wali',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nik_wali_placeholder'),
		'value' => $this->form_validation->set_value('nik_wali', $pesertadidik->nik_wali)
	);

	$this->data['tahun_lahir_wali'] = array(
		'name'  => 'tahun_lahir_wali',
		'id'    => 'tahun_lahir_wali',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_tahun_lahir_wali_placeholder'),
		'value' => $this->form_validation->set_value('tahun_lahir_wali', $pesertadidik->tahun_lahir_wali)
	); 

	$this->data['jenjang_pendidikan_wali'] = array(
		'name'        => 'jenjang_pendidikan_wali',
		'id'          => 'select-jenjang_pendidikan_wali',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_jenjang_pendidikan_wali')
	);

	$this->data['jenjang_pendidikan_wali_option'] = $this->master_m->get_master('jenjang_pendidikan','jenjang_pendidikan_id','nama');
	$this->data['jenjang_pendidikan_wali_selected'] = $pesertadidik->jenjang_pendidikan_wali;

	$this->data['pekerjaan_id_wali'] = array(
		'name'        => 'pekerjaan_id_wali',
		'id'          => 'select-pekerjaan_id_wali',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_pekerjaan_id_wali')
	);

	$this->data['pekerjaan_id_wali_option'] = $this->master_m->get_master('pekerjaan','pekerjaan_id','nama');
	$this->data['pekerjaan_id_wali_selected'] = $pesertadidik->pekerjaan_id_wali;

	$this->data['penghasilan_id_wali'] = array(
		'name'        => 'penghasilan_id_wali',
		'id'          => 'select-penghasilan_id_wali',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_penghasilan_id_wali')
	);

	$this->data['penghasilan_id_wali_option'] = $this->master_m->get_master('penghasilan_orangtua_wali','penghasilan_orangtua_wali_id','nama');
	$this->data['penghasilan_id_wali_selected'] = $pesertadidik->penghasilan_id_wali;

	// Informasi Orangtua / Wali

	$this->data['ayah_id'] = array(
		'name'        => 'ayah_id',
		'id'          => 'select-ayah_id',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_ayah_id')
	);

	$this->data['ayah_id_option'] = $this->master_m->get_master('orang_tua','orang_tua_id','nama');
	$this->data['ayah_id_selected'] = $pesertadidik->ayah_id;

	$this->data['ibu_id'] = array(
		'name'        => 'ibu_id',
		'id'          => 'select-ibu_id',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_ibu_id')
	);

	$this->data['ibu_id_option'] = $this->master_m->get_master('orang_tua','orang_tua_id','nama');
	$this->data['ibu_id_selected'] = $pesertadidik->ibu_id;


	$this->data['wali_id'] = array(
		'name'        => 'wali_id',
		'id'          => 'select-wali_id',
		'class'       => 'select2-search',
		'data-placeholder'=> "Pilih " . $this->lang->line('pesertadidik_wali_id')
	);

	$this->data['wali_id_option'] = $this->master_m->get_master('orang_tua','orang_tua_id','nama');
	$this->data['wali_id_selected'] = $pesertadidik->wali_id;
	// Kontak

	$this->data['nomor_telepon_rumah'] = array(
		'name'  => 'nomor_telepon_rumah',
		'id'    => 'nomor_telepon_rumah',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nomor_telepon_rumah_placeholder'),
		'value' => $this->form_validation->set_value('nomor_telepon_rumah', $pesertadidik->nomor_telepon_rumah)
	); 

	$this->data['nomor_telepon_seluler'] = array(
		'name'  => 'nomor_telepon_seluler',
		'id'    => 'nomor_telepon_seluler',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_nomor_telepon_seluler_placeholder'),
		'value' => $this->form_validation->set_value('nomor_telepon_seluler', $pesertadidik->nomor_telepon_seluler)
	); 

	$this->data['email'] = array(
		'name'  => 'email',
		'id'    => 'email',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_email_placeholder'),
		'value' => $this->form_validation->set_value('email', $pesertadidik->email)
	); 


	$this->data['create_date'] = array(
		'name'  => 'create_date',
		'id'    => 'create_date',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_create_date_placeholder'),
		'value' => $this->form_validation->set_value('create_date', $pesertadidik->create_date)
	); 

	$this->data['last_update'] = array(
		'name'  => 'last_update',
		'id'    => 'last_update',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_last_update_placeholder'),
		'value' => $this->form_validation->set_value('last_update', $pesertadidik->last_update)
	); 

	$this->data['updater_id'] = array(
		'name'  => 'updater_id',
		'id'    => 'updater_id',
		'type'  => 'text',
		'class' => 'form-control',
		'placeholder'=> $this->lang->line('pesertadidik_updater_id_placeholder'),
		'value' => $this->form_validation->set_value('updater_id', $pesertadidik->updater_id)
	); 


	$this->data['pesertadidik_meta'] = array(
		'create_date'    => ((!empty($pesertadidik->create_date)) ? $pesertadidik->create_date : now()),
		'last_update'   => ((!empty($pesertadidik->create_date)) ?  now() : $pesertadidik->last_update),
		'updater_id' => ((!empty($pesertadidik->updater_id)) ? $this->data['app_session']->id : $pesertadidik->updater_id),
	);

	$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
	$this->parser->parse('pesertadidik_edit', $this->data);
	}

	public function generate_form() 
	{
		$fieldname = explode(',', $this->_fieldname);

		$controller = '';
		$view = '';
		$model = '';
		$lang = '';

		$module_name = strtolower(get_class($this));

		$controller .= "\t" .'if ($id == NULL)
	{
		$this->data[\'subtitle\'] = $this->lang->line(\''.$module_name.'_create_heading\');
		$'.$module_name.'           = $this->'.$module_name.'_m->_new();
	}
	else
	{
		$this->data[\'subtitle\'] = $this->lang->line(\''.$module_name.'_edit_heading\');
		$'.$module_name.' = $this->'.$module_name.'_m->get($id);
	}<br><br>' . PHP_EOL;



		$controller .="\t" . '$rules = $this->'.$module_name.'_m->_rules;
		$this->form_validation->set_rules($rules);

		if ($this->form_validation->run($this) == TRUE)
		{
			$data  = $this->'.$module_name.'->array_form_post(array('. $this->arr_to_text($fieldname).'));

			if($this->'.$module_name.'->save($data, $id))
			{
				redirect(\''.$module_name.'\');
			}
		}<br><br>' . PHP_EOL;

	$view .='{extends file="default.tpl"}

	{block name="js_files"}
		{js(\'pages/'.$module_name.'.js\')}
	{/block}
	
	{block name="content"}
	<div class="panel panel-default">
	<div class="panel-heading">
		<h5 class="panel-title">{lang(\''.$module_name.'_create_heading\')}</h5>
		<div class="heading-elements">
			<ul class="icons-list">
				<li><a data-action="collapse"></a></li>
			</ul>
		</div>
	</div>

	<div class="panel-body">
	{form_open(uri_string(),\'class="form-horizontal"\')}
	<fieldset class="content-group">
		{if isset($message)}
			{alert($message)}
		{/if}' . PHP_EOL;


	$model .= '$' .  $module_name . ' = new stdClass();' . PHP_EOL;


	foreach ($fieldname as $key => $value) {
		$controller .= "\t&#x24;this->data['". $value ."'] = array(
		'name'  => '". $value ."',
		'id'    => '". $value ."',
		'type'  => 'text',
		'required' => 'required',
		'class' => 'form-control',
		'placeholder'=> &#x24;this->lang->line('". $module_name ."_". $value ."_placeholder'),
		'value' => &#x24;this->form_validation->set_value('". $value ."', &#x24;". $module_name ."->". $value .")
	); <br><br>";

	$view .="\t" .'<div class="form-group">
		<label class="control-label col-lg-2">{lang(\''.$module_name.'_'.$value.'\')}</label>
		<div class="col-lg-10">{form_input($'.$value.')}</div>
	</div>' . PHP_EOL ;


	$model .='$'. $module_name . '->' . $value . ' = &apos;&apos;' . PHP_EOL ;

	$lang  .='$lang[\''. $module_name . '_' . $value . '\'] = \'' . $value . '\';'. PHP_EOL;
	}


	$controller .= '$this->parser->parse(\''.$module_name.'_edit\', $this->data);';

	$view .="\t" .'</fieldset>
	<div class="text-right">
		<button type="submit" class="btn btn-primary">{lang(\''.$module_name.'_save\')} <i class="icon-arrow-right14 position-right"></i></button>
	</div>
{form_close()}
	</div>
</div>
{/block}';

	$model .='return $' . $module_name . ';' . PHP_EOL;

		$data['controller'] = $controller;
		$data['view'] = $view;
		$data['model'] = $model;
		$data['lang'] = $lang;

		$this->parser->parse('generate', $data);
	}

	public function arr_to_text($text)
	{
		$res = '';
		$i = 0;
		foreach ($text as $key => $value) {
			$i++;
			$res .= "'".$value."'";

			if (count($text) !== $i)
			{
				$res .= ',';
			}
		}

		return $res;
	}

}
