<?php
defined('BASEPATH') or exit('No direct script access allowed');
// created by : KuduSinau_Hendrik_081275532220 (TERIMAKASIH UNTUK MENDAPATKAN KEBERKAHAN, DENGAN TIDAK MERUBAH NAMA HAK CIPTA, PLAGIAT, DAN TIDAK MEMPERJUALBELIKAN APLIKASI INI, SEMOGA KITA SEMUA MENDAPAT MANFAAT DAN KEBERKAHAN DARI APLIKASI INI)
// created by : KuduSinau_Hendrik_081275532220 (UNTUK MASUKAN DAN SARAN SERTA PENGEMBANGAN BISA MENGHUBUNGI NOMOR)
class Walas extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        kudu_sinau();
        $kd_level = $this->session->userdata('kd_level');
        $Level = $this->uri->segment(1);
        if ($Level == 'walas') {
            $newLevel = 'wali kelas';
        }
        $queryLevel = $this->db->get_where('t_level', ['nm_level' => $newLevel])->row_array();
        $idLevel = $queryLevel['id_level'];
        if (!(($kd_level == 3) and ($idLevel == 3))) {
            if ($kd_level == 1) {
                redirect('admin/block');
            } elseif ($kd_level == 4) {
                redirect('guru/block');
            } elseif ($kd_level == 5) {
                redirect('siswa/block');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function index()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $this->db->from('t_students');;
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->where('status_lulus', 0);
        $jumlahsiswa = $this->db->count_all_results();
        $this->db->from('t_students');;
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->where('status_lulus', 3);
        $jumlahlulus = $this->db->count_all_results();
        $this->db->from('t_teachers');;
        $this->db->where('kd_lembaga', $newKdlembaga);
        $jumlahguru = $this->db->count_all_results();
        $this->db->from('t_kelas');;
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->where('kd_tapel', $kdTapel);
        $jumlahrombel = $this->db->count_all_results();
        $this->db->from('t_user');;
        $this->db->where('kd_user', $newKdlembaga);
        $jumlahuser = $this->db->count_all_results();
        $this->db->from('t_eskul');;
        $this->db->where('kd_lembaga', $newKdlembaga);
        $jumlaheskul = $this->db->count_all_results();
        $data['jumlahSiswa'] = $jumlahsiswa;
        $data['jumlahLulus'] = $jumlahlulus;
        $data['jumlahGuru'] = $jumlahguru;
        $data['jumlahRombel'] = $jumlahrombel;
        $data['jumlahUser'] = $jumlahuser;
        $data['jumlahEskul'] = $jumlaheskul;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Dashboard';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        $this->load->view('walas/dashboard', $data);
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function nilai_sso()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['kkm'] = $this->db->get('t_kkm')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['sso'] = $this->db->order_by('kd_kdsso', SORT_ASC)->get('t_sso')->result_array();
        $data['nilaisso'] = $this->db->get('t_nilaisso')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataWalasSiswa();
        $cekNilaiSso = $this->db->get_where('t_sso', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $kdTapel))->num_rows();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $kdTapel))->num_rows();
        $data['cekNso'] = $cekNilaiSso;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Sikap Sosial';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekNilaiSso < 5) {
            $this->session->set_flashdata('messageInfo2', 'Indikator sikap sosial minimal 5 indikator !');
            $this->load->view('walas/nilai_sso', $data);
        } else {
            if ($cekRombelSiswa > 0) {
                $this->load->view('walas/nilai_sso', $data);
            } else {
                $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
                $this->load->view('walas/nilai_sso', $data);
            }
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function nilai_eskul()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $newKdTapel = $dataTapel['id_tapel'];
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['predikat'] = $this->db->get('t_predikat')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataWalasSiswa();
        $data['dtNilaiEskul'] = $this->m_walas->viewDataEskulSiswa();
        $cekNilaiEskul = $this->db->get_where('t_eskul', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $newKdTapel))->num_rows();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $newKdTapel))->num_rows();
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Ekstrakurikuler';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekNilaiEskul > 0) {
            if ($cekRombelSiswa > 0) {
                $this->load->view('walas/nilai_eskul', $data);
            } else {
                $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
                $this->load->view('walas/nilai_eskul', $data);
            }
        } else {
            $this->session->set_flashdata('messageInfo2', 'Data ekstrakurikuler belum ada !');
            $this->load->view('walas/nilai_eskul', $data);
        }
        $this->load->view('template/footer', $data);
    }
    public function cetak_legger()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdGuru = $data['nmUser']['kd_teachers'];
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $dtTapel = $dataTapel['id_tapel'];
        $data['newTapel'] = $dataTapel;
        $kdGuru = $data['nmUser']['kd_teachers'];
        $this->db->select('*');
        $this->db->from('t_walas');
        $this->db->where('kd_teachers', $newKdGuru);
        $this->db->where('kd_tapel', $kdTapel);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $dataKelas = $this->db->get()->row_array();
        $data['kdKelas'] = $dataKelas;
        $this->db->select(' t_kelas.nm_kelas as tingkat, 
                            t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            
        ');
        $this->db->from('t_walas');
        $this->db->join('t_kelas', 't_walas.kd_kelas = t_kelas.id_kelas');
        $this->db->where('t_walas.kd_tapel', $dtTapel);
        $this->db->where('t_walas.kd_teachers', $kdGuru);
        $this->db->where('t_walas.kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_kelas.nm_rombel', SORT_ASC);
        $kelasSiswa = $this->db->get()->result_array();
        $cekCatatan = $this->db->get_where('t_catatan', array('kd_lembaga' => $newKdlembaga, 'kd_kelas' => $data['kdKelas']['kd_kelas'], 'kd_tapel' => $dtTapel))->num_rows();
        $data['cekCatatan'] = $cekCatatan;
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $kdTapel))->num_rows();
        $data['klsSiswa'] = $kelasSiswa;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Print Rapor';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekCatatan > 0) {
            if ($cekRombelSiswa > 0) {
                $this->load->view('walas/cetak_legger', $data);
            } else {
                $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
                $this->load->view('walas/cetak_legger', $data);
            }
        } else {
            $this->session->set_flashdata('messageInfo', 'Pengisian rapor semester ini oleh wali kelas belum selesai !');
            $this->load->view('walas/cetak_legger', $data);
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputNilaiEskul()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('id_eskul', 'Kode Eskul', 'required|trim');
        $this->form_validation->set_rules('predikat_eskul', 'Predikat Eskul', 'required|trim');
        $this->form_validation->set_rules('deskripsi_eskul', 'Deskripsi Eskul', 'required|trim');
        $newKdstudents =  $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newIdKdEskul = $this->input->post('id_eskul');
        $newNilaiEskul = $this->input->post('predikat_eskul');
        $newDeskEskul = $this->input->post('deskripsi_eskul');
        $this->db->select('*');
        $this->db->from('t_eskul');
        $this->db->where('id_eskul', $newIdKdEskul);
        $this->db->where('kd_tapel', $newTapel);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $query = $this->db->get()->row_array();
        $kdEskul = $query['kd_eskul'];
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_eskul');
        } else {
            $cekKdEskul = $this->db->get_where('t_nilaieskul', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_eskul' => $newIdKdEskul, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
            if ($cekKdEskul > 0) {
                $this->session->set_flashdata('messageError', 'Data ekstrakurikuler sudah ada !');
                redirect('walas/nilai_eskul');
            } else {
                $data = [
                    'kd_students'       => $newKdstudents,
                    'kd_kelas'          => $newKdkelas,
                    'kd_eskul'          => $newIdKdEskul,
                    'tipe_n'            => $kdEskul,
                    'kd_tapel'          => $newTapel,
                    'kd_lembaga'        => $newKdlembaga,
                    'predikat_eskul'    =>  $newNilaiEskul,
                    'deskripsi_eskul'   => $newDeskEskul
                ];
                $this->m_walas->inputDataNilaiEskul($data);
                $this->session->set_flashdata('messageSave', 'Data ekstrakurikuler berhasil ditambahkan !');
                redirect('walas/nilai_eskul');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function hapusNilaiEskul($ideskul)
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $query = $this->db->query("SELECT nm_eskul FROM t_eskul JOIN t_nilaieskul WHERE id_eskul = t_nilaieskul.kd_eskul AND id_nilaieskul = '$ideskul' AND t_nilaieskul.kd_lembaga = '$newKdlembaga' AND t_nilaieskul.kd_tapel = '$newTapel'")->row_array();
        $nmEskul = $query['nm_eskul'];
        $where = array('id_nilaieskul' => $ideskul);
        $this->m_walas->deleteDataEskul($where, 't_nilaieskul');
        $this->session->set_flashdata('messageSuccess', 'Data ekstrakurikuler ' . $nmEskul . ' berhasil dihapus !');
        redirect('walas/nilai_eskul');
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function nilai_catatan()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['catatan'] = $this->db->get('t_catatan')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataCatatanSiswa();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Catatan Wali Kelas';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekRombelSiswa > 0) {
            $this->load->view('walas/nilai_catatan', $data);
        } else {
            $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
            $this->load->view('walas/nilai_catatan', $data);
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputNilaiCatatan()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('nm_catatan', 'Catatan Wali Kelas', 'required|trim');
        $newKdstudents = $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newCatatan = htmlspecialchars($this->input->post('nm_catatan'));
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_catatan');
        } else {
            $cekIdCatatan = $this->db->get_where('t_catatan', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
            if ($cekIdCatatan > 0) {
                $data = [
                    'kd_kelas' => $newKdkelas,
                    'kd_students' => $newKdstudents,
                    'nm_catatan' => $newCatatan,
                    'kd_tapel' => $newTapel,
                    'kd_lembaga' => $newKdlembaga
                ];
                $this->db->where('kd_kelas', $newKdkelas);
                $this->db->where('kd_students', $newKdstudents);
                $this->db->where('kd_tapel', $kdTapel);
                $this->db->where('kd_lembaga', $newKdlembaga);
                $this->db->update('t_catatan', $data);
                $this->session->set_flashdata('messageSave', 'Data catatan wali kelas berhasil diupdate !');
                redirect('walas/nilai_catatan');
            } else {
                $data = [
                    'kd_kelas' => $newKdkelas,
                    'kd_students' => $newKdstudents,
                    'nm_catatan' => $newCatatan,
                    'kd_tapel' => $newTapel,
                    'kd_lembaga' => $newKdlembaga
                ];
                $this->m_walas->inputDataNilaiCatatan($data);
                $this->session->set_flashdata('messageSave', 'Data catatan wali kelas berhasil ditambahkan !');
                redirect('walas/nilai_catatan');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function nilai_absensi()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['catatan'] = $this->db->get('t_catatan')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataAbsensiSiswa();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Absensi';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekRombelSiswa > 0) {
            $this->load->view('walas/nilai_absensi', $data);
        } else {
            $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
            $this->load->view('walas/nilai_absensi', $data);
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputNilaiAbsensi()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('s_absensi', 'Sakit', 'required|numeric|trim');
        $this->form_validation->set_rules('i_absensi', 'Izin', 'required|numeric|trim');
        $this->form_validation->set_rules('a_absensi', 'Alpa', 'required|numeric|trim');
        $newKdstudents = $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newS = htmlspecialchars($this->input->post('s_absensi'));
        $newI = htmlspecialchars($this->input->post('i_absensi'));
        $newA = htmlspecialchars($this->input->post('a_absensi'));
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_absensi');
        } else {
            $cekIdAbsensi = $this->db->get_where('t_absensi', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
            if ($cekIdAbsensi > 0) {
                $data = [
                    'kd_kelas' => $newKdkelas,
                    'kd_students' => $newKdstudents,
                    's_absensi' => $newS,
                    'i_absensi' => $newI,
                    'a_absensi' => $newA,
                    'kd_tapel' => $newTapel,
                    'kd_lembaga' => $newKdlembaga
                ];
                $this->db->where('kd_kelas', $newKdkelas);
                $this->db->where('kd_students', $newKdstudents);
                $this->db->where('kd_tapel', $kdTapel);
                $this->db->where('kd_lembaga', $newKdlembaga);
                $this->db->update('t_absensi', $data);
                $this->session->set_flashdata('messageSave', 'Data absensi siswa berhasil diupdate !');
                redirect('walas/nilai_absensi');
            } else {
                $data = [
                    'kd_kelas' => $newKdkelas,
                    'kd_students' => $newKdstudents,
                    's_absensi' => $newS,
                    'i_absensi' => $newI,
                    'a_absensi' => $newA,
                    'kd_tapel' => $newTapel,
                    'kd_lembaga' => $newKdlembaga
                ];
                $this->m_walas->inputDataNilaiAbsensi($data);
                $this->session->set_flashdata('messageSave', 'Data absensi siswa berhasil ditambahkan !');
                redirect('walas/nilai_absensi');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function naik_kelas()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['naik'] = $this->db->get('t_naik')->result_array();
        $data['lulus'] = $this->db->get('t_lulus')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataNaikSiswa();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Naik Kelas';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekRombelSiswa > 0) {
            $this->load->view('walas/naik_kelas', $data);
        } else {
            $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
            $this->load->view('walas/naik_kelas', $data);
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function print_rapor_4_7($kdsiswa)
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $NmLembaga = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $newNmlembaga = $NmLembaga['id_lembaga'];
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['kkm'] = $this->db->get('t_kkm')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['kdp'] = $this->db->get('t_nokdp')->result_array();
        $data['nilaip'] = $this->db->get('t_nilaip')->result_array();
        $data['akhirp'] = $this->db->get('t_akhirp')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['rSiswap'] = $this->m_guru->viewDataRsiswa();
        $data['nSiswap'] = $this->m_guru->nilaiSiswap();
        $data['tgl'] = $this->m_guru->viewDataTgl();
        $data['kdsiswa'] = $kdsiswa;
        $this->db->select(' t_tapel.kd_smstr as semester,
                            t_teachers.nm_teachers as kamad,
                            t_teachers.gelar_depan as gelardepan, 
                            t_teachers.gelar_belakang as gelarbelakang, 
                            t_teachers.nip_teachers as nip_kamad,
                            t_tapel.kd_tahun as tahun,
                            t_tgl.tmpt_tgl as tempat,
                            t_tapel.id_tapel as tapel,
                            t_tgl.nm_tgl1 as tanggal,
                            t_tgl.nm_tgl3 as tanggal3
        ');
        $this->db->from('t_tapel');
        $this->db->join('t_tgl', 't_tapel.id_tapel = t_tgl.kd_tapel');
        $this->db->join('t_teachers', 't_tgl.kd_teachers = t_teachers.id_teachers');
        $this->db->where('t_tapel.sts_tapel', 1);
        $this->db->where('t_tapel.kd_lembaga', $newNmlembaga);
        $wakturapor = $this->db->get()->row_array();
        $this->db->select(' t_students.nm_students as nama_siswa, 
                            t_students.nislokal_students as nism_siswa, 
                            t_students.nisn_students as nisn_siswa,
                            t_kelas.nm_rombel as kelas,
                            t_kelas.nm_kelas as tingkat,
                            t_walas.id_walas as kode_walas,
                            t_kelas.id_kelas as kode_kelas
        ');
        $this->db->from('t_walas');
        $this->db->join('t_kelas', 't_walas.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_students', 't_rombelsiswa.kd_students = t_students.id_students');
        $this->db->where('t_students.id_students', $kdsiswa);
        $this->db->where('t_rombelsiswa.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_rombelsiswa.kd_lembaga', $newNmlembaga);
        $siswa = $this->db->get()->row_array();
        $this->db->select(' t_teachers.nm_teachers as nama_guru, 
                            t_teachers.gelar_depan as gelardepan, 
                            t_teachers.gelar_belakang as gelarbelakang, 
                            t_teachers.nip_teachers as nip_guru, 
                            t_teachers.nuptk_teachers as nuptk_guru,
                            t_teachers.id_teachers as id_guru,
        ');
        $this->db->from('t_walas');
        $this->db->join('t_kelas', 't_walas.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_teachers', 't_walas.kd_teachers = t_teachers.id_teachers');
        $this->db->where('t_walas.id_walas', $siswa['kode_walas']);
        $this->db->where('t_walas.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_teachers.Kd_lembaga',  $newNmlembaga);
        $guru = $this->db->get()->row_array();
        $this->db->select(' t_kkm.n_kkmkls as kkm,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_kkm.d as d,
                            t_kkm.c as c,
                            t_kkm.b as b,
                            t_kkm.a as a,
        ');
        $this->db->from('t_tapel');
        $this->db->join('t_kelas', 't_kelas.kd_tapel = t_tapel.id_tapel');
        $this->db->join('t_gmapel', 't_gmapel.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_teachers', 't_gmapel.kd_teachers = t_teachers.id_teachers');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_kkm', 't_gmapel.id_gmapel = t_kkm.kd_gmapel');
        $this->db->where('t_kelas.nm_kelas', $siswa['tingkat']);
        $this->db->where('t_tapel.sts_tapel', 1);
        $this->db->where('t_kkm.kd_lembaga', $newNmlembaga);
        $kkm1 = $this->db->get()->row_array();
        if (!is_null($kkm1)) {
            $kkm = $kkm1['kkm'];
        } else {
            $kkm = 0;
        }
        if (!is_null($kkm1)) {
            $a = $kkm1['a'];
        } else {
            $a = 0;
        }
        if (!is_null($kkm1)) {
            $b = $kkm1['b'];
        } else {
            $b = 0;
        }
        if (!is_null($kkm1)) {
            $c = $kkm1['c'];
        } else {
            $c = 0;
        }
        if (!is_null($kkm1)) {
            $d = $kkm1['d'];
        } else {
            $d = 0;
        }
        $this->db->select(' t_akhirsp.predikat_sp as predikat_spiritual,
                            t_akhirsp.deskripsi_sp as deskripsi_spiritual,
                            t_akhirso.predikat_so as predikat_sosial,
                            t_akhirso.deskripsi_so as deskripsi_sosial,
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirso', 't_akhirso.kd_students = t_students.id_students');
        $this->db->join('t_akhirsp', 't_akhirsp.kd_students = t_students.id_students');
        $this->db->where('t_akhirso.kd_students', $kdsiswa);
        $this->db->where('t_akhirsp.kd_students', $kdsiswa);
        $this->db->where('t_akhirso.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirsp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirso.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirsp.kd_lembaga', $newNmlembaga);
        $sikap = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.ARB');
        $this->db->where('t_gmapel.kd_kelas', $siswa['kode_kelas']);
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $b_arab = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.ING');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $b_inggris = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.MTK');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $mtk = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.IPA');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $ipa = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.IPS');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $ips = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.SBD');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $senbud = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PJK');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $pjok = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.INF');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $informatika = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PRK');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $pra = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.INA');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $b_indonesia = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.PKN');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $pkn = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.SKI');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $ski = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.FKH');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $fikih = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.AKA');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $akidah = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.AQH');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $quran = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.SBP');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $sbp = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.SJI');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $sejindo = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PDK');
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $pradkwr = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_bidstudy.nm_kategori as kategori_mapel,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kategori', 'Muatan Lokal (B)');
        $this->db->where('t_gmapel.kd_kelas', $siswa['kode_kelas']);
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $mulok = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_bidstudy.nm_kategori as kategori_mapel,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kategori', 'Peminatan (C)');
        $this->db->where('t_gmapel.kd_kelas', $siswa['kode_kelas']);
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $cpeminatan = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_bidstudy.nm_kategori as kategori_mapel,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kategori', 'Mata Pelajaran Pilihan (C)');
        $this->db->where('t_gmapel.kd_kelas', $siswa['kode_kelas']);
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $clintasminat = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_bidstudy.nm_kategori as kategori_mapel,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Bidang Keahlian (C1)');
        $this->db->where('t_gmapel.kd_kelas', $siswa['kode_kelas']);
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $cdbk = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_bidstudy.nm_kategori as kategori_mapel,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Program Keahlian (C2)');
        $this->db->where('t_gmapel.kd_kelas', $siswa['kode_kelas']);
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $cdpk = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
                            t_bidstudy.nm_kelompok as kelompok_mapel,
                            t_bidstudy.nm_kategori as kategori_mapel,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_akhirk.n_akhirk as nilaik_mapel,
                            t_akhirk.predikat_k as predikatk_mapel,
                            t_akhirk.deskripsi_k as deskripsik_mapel,
                            t_akhirp.n_akhirp as nilaip_mapel,
                            t_akhirp.predikat_p as predikatp_mapel,
                            t_akhirp.deskripsi_p as deskripsip_mapel,
                            
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_akhirp', 't_akhirp.kd_gmapel = t_akhirk.kd_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kategori', 'Paket Keahlian (C3)');
        $this->db->where('t_gmapel.kd_kelas', $siswa['kode_kelas']);
        $this->db->where('t_akhirp.kd_students', $kdsiswa);
        $this->db->where('t_akhirk.kd_students', $kdsiswa);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $cpk = $this->db->get()->result_array();
        $this->db->select(' t_absensi.s_absensi as s,
                            t_absensi.i_absensi as i,
                            t_absensi.a_absensi as a
        ');
        $this->db->from('t_absensi');
        $this->db->join('t_kelas', 't_kelas.id_kelas = t_absensi.kd_kelas');
        $this->db->join('t_students', 't_absensi.kd_students = t_students.id_students');
        $this->db->where('t_absensi.kd_students', $kdsiswa);
        $this->db->where('t_absensi.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_absensi.kd_lembaga', $newNmlembaga);
        $absen = $this->db->get()->row_array();
        $this->db->select(' t_catatan.nm_catatan as catat
        ');
        $this->db->from('t_catatan');
        $this->db->join('t_kelas', 't_kelas.id_kelas = t_catatan.kd_kelas');
        $this->db->join('t_students', 't_catatan.kd_students = t_students.id_students');
        $this->db->where('t_catatan.kd_students', $kdsiswa);
        $this->db->where('t_catatan.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_catatan.kd_lembaga', $newNmlembaga);
        $catatan = $this->db->get()->row_array();
        $this->db->select(' t_naik.ket_naik as naik_lulus,
                            t_naik.kelas_naik as ke_kelas
        ');
        $this->db->from('t_naik');
        $this->db->join('t_kelas', 't_kelas.id_kelas = t_naik.kd_kelas');
        $this->db->join('t_students', 't_naik.kd_students = t_students.id_students');
        $this->db->where('t_naik.kd_students', $kdsiswa);
        $this->db->where('t_naik.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_naik.kd_lembaga', $newNmlembaga);
        $naik = $this->db->get()->row_array();
        $this->db->select(' t_eskul.nm_eskul as eskul,
                            t_nilaieskul.predikat_eskul as predikat,
                            t_nilaieskul.deskripsi_eskul as deskripsi
        ');
        $this->db->from('t_nilaieskul');
        $this->db->join('t_eskul', 't_eskul.kd_eskul = t_nilaieskul.tipe_n');
        $this->db->join('t_kelas', 't_kelas.id_kelas = t_nilaieskul.kd_kelas');
        $this->db->join('t_students', 't_nilaieskul.kd_students = t_students.id_students');
        $this->db->where('t_nilaieskul.kd_students', $kdsiswa);
        $this->db->where('t_nilaieskul.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_nilaieskul.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_nilaieskul.id_nilaieskul', SORT_ASC);
        $eskul = $this->db->get()->result_array();
        $cekNilaiEskul = $this->db->get_where('t_nilaieskul', array('kd_students' => $kdsiswa, 'kd_tapel' => $wakturapor['tapel'], 'kd_lembaga' => $newNmlembaga))->num_rows();
        $this->db->select(' t_prestasi.nm_prestasi as prestasi,
                            t_prestasi.ket_prestasi as keterangan
        ');
        $this->db->from('t_prestasi');
        $this->db->join('t_kelas', 't_kelas.id_kelas = t_prestasi.kd_kelas');
        $this->db->join('t_students', 't_prestasi.kd_students = t_students.id_students');
        $this->db->where('t_prestasi.kd_students', $kdsiswa);
        $this->db->where('t_prestasi.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_prestasi.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_prestasi.id_prestasi', SORT_ASC);
        $prestasi = $this->db->get()->result_array();
        $cekPrestasi = $this->db->get_where('t_prestasi', array('kd_students' => $kdsiswa, 'kd_tapel' => $wakturapor['tapel'], 'kd_lembaga' => $newNmlembaga))->num_rows();
        $data['nilaip'] = $this->db->get('t_akhirp')->result_array();
        $this->db->select_sum('n_akhirp', 'jumlah');
        $this->db->where('kd_students', $kdsiswa);
        $this->db->where('aktif_p', 1);
        $this->db->where('kd_tapel', $wakturapor['tapel']);
        $this->db->where('kd_lembaga', $newNmlembaga);
        $jlhnilaip = $this->db->get('t_akhirp')->row_array();
        if (is_null($jlhnilaip)) {
            $jumlahnilaip = 0;
        } else {
            $jumlahnilaip =  round($jlhnilaip['jumlah']);
        }
        $this->db->select_sum('n_akhirk', 'jumlah');
        $this->db->where('kd_students', $kdsiswa);
        $this->db->where('aktif_k', 1);
        $this->db->where('kd_tapel', $wakturapor['tapel']);
        $this->db->where('kd_lembaga', $newNmlembaga);
        $jlhnilaik = $this->db->get('t_akhirk')->row_array();
        if (is_null($jlhnilaik)) {
            $jumlahnilaik = 0;
        } else {
            $jumlahnilaik =  round($jlhnilaik['jumlah']);
        }
        $data['waktu'] = $wakturapor;
        $data['students'] = $siswa;
        $data['teachers'] = $guru;
        $data['sikap'] = $sikap;
        $data['kkm'] = $kkm;
        $data['a'] = $a;
        $data['b'] = $b;
        $data['c'] = $c;
        $data['d'] = $d;
        $data['b_arab'] = $b_arab;
        $data['b_inggris'] = $b_inggris;
        $data['mtk'] = $mtk;
        $data['ipa'] = $ipa;
        $data['ips'] = $ips;
        $data['senbud'] = $senbud;
        $data['pjok'] = $pjok;
        $data['informatika'] = $informatika;
        $data['pra'] = $pra;
        $data['b_indonesia'] = $b_indonesia;
        $data['pkn'] = $pkn;
        $data['ski'] = $ski;
        $data['fikih'] = $fikih;
        $data['akidah'] = $akidah;
        $data['quran'] = $quran;
        $data['mulok'] = $mulok;
        $data['jumlahnilaip'] = $jumlahnilaip;
        $data['jumlahnilaik'] = $jumlahnilaik;
        $data['absen'] = $absen;
        $data['catatan'] = $catatan;
        $data['naik'] = $naik;
        $data['eskul'] = $eskul;
        $data['cekNilaiEskul'] = $cekNilaiEskul;
        $data['prestasi'] = $prestasi;
        $data['cekPrestasi'] = $cekPrestasi;
        $data['sbp'] = $sbp;
        $data['sejindo'] = $sejindo;
        $data['pradkwr'] = $pradkwr;
        $data['cpeminatan'] = $cpeminatan;
        $data['clintasminat'] = $clintasminat;
        $data['cdbk'] = $cdbk;
        $data['cdpk'] = $cdpk;
        $data['cpk'] = $cpk;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Print Rapor';
        $this->load->view('template/header', $data);
        $this->load->view('walas/print_rapor_4_7', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNoUm()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('no_um', 'Nomor Ujian Madrasah', 'required|trim');
        $newKdstudents = $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newNoUm = htmlspecialchars($this->input->post('no_um'));
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nomor_um');
        } else {
            $cekLulus = $this->db->get_where('t_students', array('id_students' => $newKdstudents, 'kd_lembaga' => $newKdlembaga))->row_array();
            if ($cekLulus['no_um'] == '') {
                $this->db->set('no_um', $newNoUm);
                $this->db->where('id_students', $newKdstudents);
                $this->db->where('kd_lembaga', $newKdlembaga);
                $this->db->update('t_students');
                $this->session->set_flashdata('messageSave', 'Data nomor ujian madrasah berhasil ditambahkan !');
                redirect('walas/nomor_um');
            } else {
                $this->db->set('no_um', $newNoUm);
                $this->db->where('id_students', $newKdstudents);
                $this->db->where('kd_lembaga', $newKdlembaga);
                $this->db->update('t_students');
                $this->session->set_flashdata('messageSave', 'Data nomor ujian madrasah berhasil diupdate !');
                redirect('walas/nomor_um');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function inputDataNoIjazah()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('no_ijazah', 'Nomor Ujian Madrasah', 'required|trim');
        $newKdstudents = $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newNoIjazah = htmlspecialchars($this->input->post('no_ijazah'));
        $newTglTerimaIjazah = htmlspecialchars($this->input->post('tgl_terima_ijazah'));
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nomor_ijazah');
        } else {
            $cekIjazah = $this->db->get_where('t_alumni', array('kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->row_array();
            if ($cekIjazah['no_ijazah'] == '') {
                $data = [
                    'no_ijazah' => $newNoIjazah,
                    'tgl_terima_ijazah' => $newTglTerimaIjazah
                ];
                $this->db->where('kd_students', $newKdstudents);
                $this->db->where('kd_tapel', $kdTapel);
                $this->db->where('kd_lembaga', $newKdlembaga);
                $this->db->update('t_alumni', $data);
                $this->session->set_flashdata('messageSave', 'Data nomor ijazah berhasil ditambahkan !');
                redirect('walas/nomor_ijazah');
            } else {
                $data = [
                    'no_ijazah' => $newNoIjazah,
                    'tgl_terima_ijazah' => $newTglTerimaIjazah
                ];
                $this->db->where('kd_students', $newKdstudents);
                $this->db->where('kd_tapel', $kdTapel);
                $this->db->where('kd_lembaga', $newKdlembaga);
                $this->db->update('t_alumni', $data);
                $this->session->set_flashdata('messageSave', 'Data nomor ijazah berhasil diupdate !');
                redirect('walas/nomor_ijazah');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function inputNilaiSo()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('kd_sso[]', 'Kode Sosial', 'required|trim');
        $this->form_validation->set_rules('n_so[]', 'Nilai Sosial', 'required|numeric|trim');
        $this->form_validation->set_rules('desk_so[]', 'Deskripsi Sosial', 'required|trim');
        $this->form_validation->set_rules('tipe_n[]', 'Deskripsi Sosial', 'required|trim');
        $newKdstudents =  $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newKdsso = $this->input->post('kd_sso');
        $newNilaiso = $this->input->post('n_so');
        $newDeskso = $this->input->post('desk_so');
        $newTipe = $this->input->post('tipe_n');
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_sso');
        } else {
            $data = array();
            foreach ($newKdsso as $nrs => $kso) {
                $data[$nrs]['kd_sso'] = $kso;
            }
            $cekKdso = $this->db->get_where('t_nilaisso', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_sso' => $kso, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
            if ($cekKdso > 0) {
                $data =  $this->input->post();
                for ($i = 0; $i < count($data['id_nilaisso']); $i++) {
                    $update[] = array(
                        'id_nilaisso'   => $data['id_nilaisso'][$i],
                        'kd_kelas'      => $newKdkelas,
                        'kd_students'   => $newKdstudents,
                        'kd_sso'        => $data['kd_sso'][$i],
                        'tipe_n'        => $data['tipe_n'][$i],
                        'n_so'          => $data['n_so'][$i],
                        'kd_tapel'      => $newTapel,
                        'kd_lembaga'    => $newKdlembaga,
                    );
                }
                $this->m_walas->updateDataNilaiSo($update, 'id_nilaisso');
                $cekIdAkhirSo = $this->db->get_where('t_akhirso', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
                if ($cekIdAkhirSo > 0) {
                    $this->db->select_avg('n_so', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaisso')->row_array();
                    $newNakhirSo =  round($query['rata']);
                    $predikat =  $newNakhirSo;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so1' AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_so'] . ', ';
                    }
                    $queryQ = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ)) {
                        $deskQ = '';
                    } else {
                        $deskQ = 'sangat ' . $queryQ['desk_so'];
                    }
                    $queryQ2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ2)) {
                        $deskQ2 = '';
                    } else {
                        $deskQ2 = $queryQ2['desk_so'];
                    }
                    $queryQ3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ3)) {
                        $deskQ3 = '';
                    } else {
                        $deskQ3 = 'cukup ' . $queryQ3['desk_so'];
                    }
                    $queryQ4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ4)) {
                        $deskQ4 = '';
                    } else {
                        $deskQ4 = 'kurang ' . $queryQ4['desk_so'];
                    }
                    $newDeskQ = $deskQ . $deskQ2 . $deskQ3 . $deskQ4;
                    $queryR = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR)) {
                        $deskR = '';
                    } else {
                        $deskR = ', sangat ' . $queryR['desk_so'];
                    }
                    $queryR2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR2)) {
                        $deskR2 = '';
                    } else {
                        $deskR2 = ', ' . $queryR2['desk_so'];
                    }
                    $queryR3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR3)) {
                        $deskR3 = '';
                    } else {
                        $deskR3 = ', cukup ' . $queryR3['desk_so'];
                    }
                    $queryR4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR4)) {
                        $deskR4 = '';
                    } else {
                        $deskR4 = ', kurang ' . $queryR4['desk_so'];
                    }
                    $newDeskR = $deskR . $deskR2 . $deskR3 . $deskR4;
                    $queryS = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS)) {
                        $deskS = '';
                    } else {
                        $deskS = ' dan sikap ' . $queryS['desk_so'] . ' yang sangat baik';
                    }
                    $queryS2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS2)) {
                        $deskS2 = '';
                    } else {
                        $deskS2 = ' dan sikap ' . $queryS2['desk_so'] . ' yang baik';
                    }
                    $queryS3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS3)) {
                        $deskS3 = '';
                    } else {
                        $deskS3 = ' dan sikap ' . $queryS3['desk_so'] . ' yang cukup baik';
                    }
                    $queryS4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS4)) {
                        $deskS4 = '';
                    } else {
                        $deskS4 = ' dan sikap ' . $queryS4['desk_so'] . ' yang kurang baik';
                    }
                    $newDeskS = $deskS . $deskS2 . $deskS3 . $deskS4;
                    $queryT = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT)) {
                        $deskT = '';
                    } else {
                        $deskT = ', serta memiliki sikap ' . $queryT['desk_so'] . ' sangat baik';
                    }
                    $queryT2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT2)) {
                        $deskT2 = '';
                    } else {
                        $deskT2 = ', serta memiliki sikap ' . $queryT2['desk_so'] . ' yang baik';
                    }
                    $queryT3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT3)) {
                        $deskT3 = '';
                    } else {
                        $deskT3 = ', serta memiliki sikap ' . $queryT3['desk_so'] . ' cukup baik';
                    }
                    $queryT4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT4)) {
                        $deskT4 = '';
                    } else {
                        $deskT4 = ', serta memiliki sikap ' . $queryT4['desk_so'] . ' kurang baik';
                    }
                    $newDeskT = $deskT . $deskT2 . $deskT3 . $deskT4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap sangat ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan diamalkan secara istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda memiliki sikap cukup ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda memiliki sikap kurang ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirso' =>  $newNakhirSo,
                        'predikat_so' =>  $grade,
                        'deskripsi_so' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->db->where('kd_kelas', $newKdkelas);
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $this->db->update('t_akhirso', $dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap sosial berhasil diupdate !');
                    redirect('walas/nilai_sso');
                } else {
                    $this->db->select_avg('n_so', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaisso')->row_array();
                    $newNakhirSo =  round($query['rata']);
                    $predikat =  $newNakhirSo;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so1' AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_so'] . ', ';
                    }
                    $queryQ = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ)) {
                        $deskQ = '';
                    } else {
                        $deskQ = 'sangat ' . $queryQ['desk_so'];
                    }
                    $queryQ2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ2)) {
                        $deskQ2 = '';
                    } else {
                        $deskQ2 = $queryQ2['desk_so'];
                    }
                    $queryQ3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ3)) {
                        $deskQ3 = '';
                    } else {
                        $deskQ3 = 'cukup ' . $queryQ3['desk_so'];
                    }
                    $queryQ4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ4)) {
                        $deskQ4 = '';
                    } else {
                        $deskQ4 = 'kurang ' . $queryQ4['desk_so'];
                    }
                    $newDeskQ = $deskQ . $deskQ2 . $deskQ3 . $deskQ4;
                    $queryR = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR)) {
                        $deskR = '';
                    } else {
                        $deskR = ', sangat ' . $queryR['desk_so'];
                    }
                    $queryR2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR2)) {
                        $deskR2 = '';
                    } else {
                        $deskR2 = ', ' . $queryR2['desk_so'];
                    }
                    $queryR3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR3)) {
                        $deskR3 = '';
                    } else {
                        $deskR3 = ', cukup ' . $queryR3['desk_so'];
                    }
                    $queryR4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR4)) {
                        $deskR4 = '';
                    } else {
                        $deskR4 = ', kurang ' . $queryR4['desk_so'];
                    }
                    $newDeskR = $deskR . $deskR2 . $deskR3 . $deskR4;
                    $queryS = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS)) {
                        $deskS = '';
                    } else {
                        $deskS = ' dan sikap ' . $queryS['desk_so'] . ' yang sangat baik';
                    }
                    $queryS2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS2)) {
                        $deskS2 = '';
                    } else {
                        $deskS2 = ' dan sikap ' . $queryS2['desk_so'] . ' yang baik';
                    }
                    $queryS3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS3)) {
                        $deskS3 = '';
                    } else {
                        $deskS3 = ' dan sikap ' . $queryS3['desk_so'] . ' yang cukup baik';
                    }
                    $queryS4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS4)) {
                        $deskS4 = '';
                    } else {
                        $deskS4 = ' dan sikap ' . $queryS4['desk_so'] . ' yang kurang baik';
                    }
                    $newDeskS = $deskS . $deskS2 . $deskS3 . $deskS4;
                    $queryT = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT)) {
                        $deskT = '';
                    } else {
                        $deskT = ', serta memiliki sikap ' . $queryT['desk_so'] . ' sangat baik';
                    }
                    $queryT2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT2)) {
                        $deskT2 = '';
                    } else {
                        $deskT2 = ', serta memiliki sikap ' . $queryT2['desk_so'] . ' yang baik';
                    }
                    $queryT3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT3)) {
                        $deskT3 = '';
                    } else {
                        $deskT3 = ', serta memiliki sikap ' . $queryT3['desk_so'] . ' cukup baik';
                    }
                    $queryT4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT4)) {
                        $deskT4 = '';
                    } else {
                        $deskT4 = ', serta memiliki sikap ' . $queryT4['desk_so'] . ' kurang baik';
                    }
                    $newDeskT = $deskT . $deskT2 . $deskT3 . $deskT4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap sangat ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan diamalkan secara istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda memiliki sikap cukup ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda memiliki sikap kurang ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirso' =>  $newNakhirSo,
                        'predikat_so' =>  $grade,
                        'deskripsi_so' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->m_walas->inputDataNilaiAkhirSo($dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap sosial berhasil diupdate !');
                    redirect('walas/nilai_sso');
                }
            } else {
                $data = array();
                foreach ($newKdsso as $nrs => $rs) {
                    $data[$nrs]['kd_students'] = $newKdstudents;
                    $data[$nrs]['kd_kelas'] =  $newKdkelas;
                    $data[$nrs]['kd_sso'] = $rs;
                    $data[$nrs]['kd_tapel'] = $newTapel;
                    $data[$nrs]['kd_lembaga'] = $newKdlembaga;
                }
                foreach ($newNilaiso as $nrs => $rs) {
                    $data[$nrs]['n_so'] = $rs;
                }
                foreach ($newDeskso as $nrs => $rs) {
                    $data[$nrs]['desk_so'] = $rs;
                }
                foreach ($newTipe as $nrs => $rs) {
                    $data[$nrs]['tipe_n'] = $rs;
                }
                $this->m_walas->inputDataNilaiSo($data);
                $cekIdAkhirSo = $this->db->get_where('t_akhirso', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
                if ($cekIdAkhirSo > 0) {
                    $this->db->select_avg('n_so', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaisso')->row_array();
                    $newNakhirSo =  round($query['rata']);
                    $predikat =  $newNakhirSo;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so1' AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_so'] . ', ';
                    }
                    $queryQ = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ)) {
                        $deskQ = '';
                    } else {
                        $deskQ = 'sangat ' . $queryQ['desk_so'];
                    }
                    $queryQ2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ2)) {
                        $deskQ2 = '';
                    } else {
                        $deskQ2 = $queryQ2['desk_so'];
                    }
                    $queryQ3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ3)) {
                        $deskQ3 = '';
                    } else {
                        $deskQ3 = 'cukup ' . $queryQ3['desk_so'];
                    }
                    $queryQ4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ4)) {
                        $deskQ4 = '';
                    } else {
                        $deskQ4 = 'kurang ' . $queryQ4['desk_so'];
                    }
                    $newDeskQ = $deskQ . $deskQ2 . $deskQ3 . $deskQ4;
                    $queryR = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR)) {
                        $deskR = '';
                    } else {
                        $deskR = ', sangat ' . $queryR['desk_so'];
                    }
                    $queryR2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR2)) {
                        $deskR2 = '';
                    } else {
                        $deskR2 = ', ' . $queryR2['desk_so'];
                    }
                    $queryR3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR3)) {
                        $deskR3 = '';
                    } else {
                        $deskR3 = ', cukup ' . $queryR3['desk_so'];
                    }
                    $queryR4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR4)) {
                        $deskR4 = '';
                    } else {
                        $deskR4 = ', kurang ' . $queryR4['desk_so'];
                    }
                    $newDeskR = $deskR . $deskR2 . $deskR3 . $deskR4;
                    $queryS = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS)) {
                        $deskS = '';
                    } else {
                        $deskS = ' dan sikap ' . $queryS['desk_so'] . ' yang sangat baik';
                    }
                    $queryS2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS2)) {
                        $deskS2 = '';
                    } else {
                        $deskS2 = ' dan sikap ' . $queryS2['desk_so'] . ' yang baik';
                    }
                    $queryS3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS3)) {
                        $deskS3 = '';
                    } else {
                        $deskS3 = ' dan sikap ' . $queryS3['desk_so'] . ' yang cukup baik';
                    }
                    $queryS4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS4)) {
                        $deskS4 = '';
                    } else {
                        $deskS4 = ' dan sikap ' . $queryS4['desk_so'] . ' yang kurang baik';
                    }
                    $newDeskS = $deskS . $deskS2 . $deskS3 . $deskS4;
                    $queryT = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT)) {
                        $deskT = '';
                    } else {
                        $deskT = ', serta memiliki sikap ' . $queryT['desk_so'] . ' sangat baik';
                    }
                    $queryT2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT2)) {
                        $deskT2 = '';
                    } else {
                        $deskT2 = ', serta memiliki sikap ' . $queryT2['desk_so'] . ' yang baik';
                    }
                    $queryT3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT3)) {
                        $deskT3 = '';
                    } else {
                        $deskT3 = ', serta memiliki sikap ' . $queryT3['desk_so'] . ' cukup baik';
                    }
                    $queryT4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT4)) {
                        $deskT4 = '';
                    } else {
                        $deskT4 = ', serta memiliki sikap ' . $queryT4['desk_so'] . ' kurang baik';
                    }
                    $newDeskT = $deskT . $deskT2 . $deskT3 . $deskT4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap sangat ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan diamalkan secara istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda memiliki sikap cukup ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda memiliki sikap kurang ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirso' =>  $newNakhirSo,
                        'predikat_so' =>  $grade,
                        'deskripsi_so' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->db->where('kd_kelas', $newKdkelas);
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $this->db->update('t_akhirso', $dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap sosial berhasil diupdate !');
                    redirect('walas/nilai_sso');
                } else {
                    $this->db->select_avg('n_so', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaisso')->row_array();
                    $newNakhirSo =  round($query['rata']);
                    $predikat =  $newNakhirSo;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so1' AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_so'] . ', ';
                    }
                    $queryQ = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ)) {
                        $deskQ = '';
                    } else {
                        $deskQ = 'sangat ' . $queryQ['desk_so'];
                    }
                    $queryQ2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ2)) {
                        $deskQ2 = '';
                    } else {
                        $deskQ2 = $queryQ2['desk_so'];
                    }
                    $queryQ3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ3)) {
                        $deskQ3 = '';
                    } else {
                        $deskQ3 = 'cukup ' . $queryQ3['desk_so'];
                    }
                    $queryQ4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so2' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryQ4)) {
                        $deskQ4 = '';
                    } else {
                        $deskQ4 = 'kurang ' . $queryQ4['desk_so'];
                    }
                    $newDeskQ = $deskQ . $deskQ2 . $deskQ3 . $deskQ4;
                    $queryR = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR)) {
                        $deskR = '';
                    } else {
                        $deskR = ', sangat ' . $queryR['desk_so'];
                    }
                    $queryR2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR2)) {
                        $deskR2 = '';
                    } else {
                        $deskR2 = ', ' . $queryR2['desk_so'];
                    }
                    $queryR3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR3)) {
                        $deskR3 = '';
                    } else {
                        $deskR3 = ', cukup ' . $queryR3['desk_so'];
                    }
                    $queryR4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so3' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryR4)) {
                        $deskR4 = '';
                    } else {
                        $deskR4 = ', kurang ' . $queryR4['desk_so'];
                    }
                    $newDeskR = $deskR . $deskR2 . $deskR3 . $deskR4;
                    $queryS = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS)) {
                        $deskS = '';
                    } else {
                        $deskS = ' dan sikap ' . $queryS['desk_so'] . ' yang sangat baik';
                    }
                    $queryS2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS2)) {
                        $deskS2 = '';
                    } else {
                        $deskS2 = ' dan sikap ' . $queryS2['desk_so'] . ' yang baik';
                    }
                    $queryS3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS3)) {
                        $deskS3 = '';
                    } else {
                        $deskS3 = ' dan sikap ' . $queryS3['desk_so'] . ' yang cukup baik';
                    }
                    $queryS4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so4' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryS4)) {
                        $deskS4 = '';
                    } else {
                        $deskS4 = ' dan sikap ' . $queryS4['desk_so'] . ' yang kurang baik';
                    }
                    $newDeskS = $deskS . $deskS2 . $deskS3 . $deskS4;
                    $queryT = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 4 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT)) {
                        $deskT = '';
                    } else {
                        $deskT = ', serta memiliki sikap ' . $queryT['desk_so'] . ' sangat baik';
                    }
                    $queryT2 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 3 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT2)) {
                        $deskT2 = '';
                    } else {
                        $deskT2 = ', serta memiliki sikap ' . $queryT2['desk_so'] . ' yang baik';
                    }
                    $queryT3 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 2 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT3)) {
                        $deskT3 = '';
                    } else {
                        $deskT3 = ', serta memiliki sikap ' . $queryT3['desk_so'] . ' cukup baik';
                    }
                    $queryT4 = $this->db->query("SELECT desk_so FROM t_nilaisso WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'so5' AND n_so = 1 AND kd_lembaga = '$newKdlembaga' AND kd_tapel = '$kdTapel'")->row_array();
                    if (is_null($queryT4)) {
                        $deskT4 = '';
                    } else {
                        $deskT4 = ', serta memiliki sikap ' . $queryT4['desk_so'] . ' kurang baik';
                    }
                    $newDeskT = $deskT . $deskT2 . $deskT3 . $deskT4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap sangat ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan diamalkan secara istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda memiliki sikap ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda memiliki sikap cukup ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda memiliki sikap kurang ' . $deskP . $newDeskQ . $newDeskR . $newDeskS . $newDeskT . ', sehingga perlu pendampingan dan pembinaan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirso' =>  $newNakhirSo,
                        'predikat_so' =>  $grade,
                        'deskripsi_so' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->m_walas->inputDataNilaiAkhirSo($dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap sosial berhasil diupdate !');
                    redirect('walas/nilai_sso');
                    // created by : KuduSinau_Hendrik_081275532220
                }
            }
        }
    }
    public function inputNilaiNaik()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->db->select('*');
        $this->db->from('t_tgl');
        $this->db->where('kd_tapel', $kdTapel);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $dataTgl = $this->db->get()->row_array();
        $newTgl = $dataTgl['nm_tgl3'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('ket_naik', 'Status', 'required|trim');
        $newKdstudents = $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newNaik = htmlspecialchars($this->input->post('ket_naik'));
        $nmNaikKelas = $this->db->query("SELECT * FROM  t_kelas WHERE id_kelas = '$newKdkelas' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
        $nmAngka = $this->db->query("SELECT angka_kls FROM  t_kls WHERE nm_kls = '$nmNaikKelas[nm_kelas]'")->row_array();
        $newKelas = $nmAngka['angka_kls'] + 1;
        $nmHuruf = $this->db->query("SELECT huruf_kls FROM  t_kls WHERE angka_kls = '$newKelas'")->row_array();
        $nmRomawi = $this->db->query("SELECT nm_kls FROM  t_kls WHERE angka_kls = '$newKelas'")->row_array();
        $kelasFinal = $nmRomawi['nm_kls'] . ' (' . $nmHuruf['huruf_kls'] . ')';
        if ($newNaik == 'Lulus' or $newNaik == 'Tidak Lulus') {
            $newkelasFinal = '';
        } else {
            $newkelasFinal = $kelasFinal;
        }
        if ($newNaik == 'Naik') {
            $newAngkaKelas = $nmAngka['angka_kls'] + 1;
        } elseif ($newNaik == 'Tidak Naik') {
            $newAngkaKelas =  $nmAngka['angka_kls'];
        } elseif ($newNaik == 'Lulus') {
            $newAngkaKelas  =  0;
            $rombelAktif    = 3;
            $lulus          = 3;
        } elseif ($newNaik == 'Tidak Lulus') {
            $newAngkaKelas =  $nmAngka['angka_kls'];
            $rombelAktif    = 1;
            $lulus          = 0;
        }
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/naik_kelas');
        } else {
            $cekKelasNaik = $this->db->get_where('t_naik', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
            if ($cekKelasNaik > 0) {
                $data = [
                    'kd_kelas' => $newKdkelas,
                    'kd_students' => $newKdstudents,
                    'ket_naik' => $newNaik,
                    'kelas_naik' => $newkelasFinal,
                    'kd_tapel' => $newTapel,
                    'kd_lembaga' => $newKdlembaga
                ];
                $this->db->where('kd_kelas', $newKdkelas);
                $this->db->where('kd_students', $newKdstudents);
                $this->db->where('kd_tapel', $kdTapel);
                $this->db->where('kd_lembaga', $newKdlembaga);
                $this->db->update('t_naik', $data);
                if ($newNaik == 'Lulus') {
                    $cekAlumni = $this->db->get_where('t_alumni', array('kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
                    if ($cekAlumni > 0) {
                        $dataAlumni = [
                            'kd_students' => $newKdstudents,
                            'lulus_status' => $newNaik,
                            'tgl_lulus' => $newTgl,
                            'kd_tapel' => $newTapel,
                            'kd_lembaga' => $newKdlembaga
                        ];
                        $this->db->where('kd_students', $newKdstudents);
                        $this->db->where('kd_tapel', $kdTapel);
                        $this->db->where('kd_lembaga', $newKdlembaga);
                        $this->db->update('t_alumni', $dataAlumni);
                    } else {
                        if ($newNaik == 'Lulus') {
                            $dataAlumni = [
                                'kd_students' => $newKdstudents,
                                'lulus_status' => $newNaik,
                                'tgl_lulus' => $newTgl,
                                'kd_tapel' => $newTapel,
                                'kd_lembaga' => $newKdlembaga
                            ];
                        }
                        $this->m_walas->inputDataAlumni($dataAlumni);
                    }
                } elseif ($newNaik == 'Tidak Lulus') {
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_tapel', $kdTapel);
                    $this->db->where('kd_lembaga', $newKdlembaga);
                    $this->db->delete('t_alumni');
                }
                if ($newNaik == 'Naik' || $newNaik == 'Tidak Naik') {
                    $this->db->query("UPDATE t_students SET tingkat_kelas = '$newAngkaKelas' WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                } elseif ($newNaik == 'Lulus' || $newNaik == 'Tidak Lulus') {
                    $this->db->query("UPDATE t_students SET tingkat_kelas = $newAngkaKelas WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                    $this->db->query("UPDATE t_students SET rombel_aktif = $rombelAktif WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                    $this->db->query("UPDATE t_students SET status_lulus = $lulus WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                }
                if ($newNaik == 'Naik' || $newNaik == 'Tidak Naik') {
                    $this->session->set_flashdata('messageSave', 'Data kenaikan kelas berhasil diupdate !');
                } elseif ($newNaik == 'Lulus' || $newNaik == 'Tidak Lulus') {
                    $this->session->set_flashdata('messageSave', 'Data kelulusan berhasil diupdate !');
                }
                redirect('walas/naik_kelas');
            } else {
                $data = [
                    'kd_kelas' => $newKdkelas,
                    'kd_students' => $newKdstudents,
                    'ket_naik' => $newNaik,
                    'kelas_naik' => $newkelasFinal,
                    'kd_tapel' => $newTapel,
                    'kd_lembaga' => $newKdlembaga
                ];
                $this->m_walas->inputDataNilaiNaik($data);
                if ($newNaik == 'Lulus') {
                    $dataAlumni = [
                        'kd_students' => $newKdstudents,
                        'lulus_status' => $newNaik,
                        'tgl_lulus' => $newTgl,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->m_walas->inputDataAlumni($dataAlumni);
                }
                if ($newNaik == 'Naik' || $newNaik == 'Tidak Naik') {
                    $this->db->query("UPDATE t_students SET tingkat_kelas = '$newAngkaKelas' WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                } elseif ($newNaik == 'Lulus' || $newNaik == 'Tidak Lulus') {
                    $this->db->query("UPDATE t_students SET tingkat_kelas = $newAngkaKelas WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                    $this->db->query("UPDATE t_students SET rombel_aktif = $rombelAktif WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                    $this->db->query("UPDATE t_students SET status_lulus = $lulus WHERE id_students = '$newKdstudents' AND kd_lembaga = '$newKdlembaga'");
                }
                if ($newNaik == 'Naik' || $newNaik == 'Tidak Naik') {
                    $this->session->set_flashdata('messageSave', 'Data kenaikan kelas berhasil ditambahkan !');
                } elseif ($newNaik == 'Lulus' || $newNaik == 'Tidak Lulus') {
                    $this->session->set_flashdata('messageSave', 'Data kelulusan berhasil ditambahkan !');
                }
                redirect('walas/naik_kelas');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function nilai_prestasi()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['prestasi'] = $this->db->order_by('nm_prestasi', SORT_ASC)->get('t_prestasi')->result_array();
        $data['lulus'] = $this->db->get('t_lulus')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataPrestasiSiswa();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Prestasi';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekRombelSiswa > 0) {
            $this->load->view('walas/nilai_prestasi', $data);
        } else {
            $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
            $this->load->view('walas/nilai_prestasi', $data);
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function nilai_ssp()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['kkm'] = $this->db->get('t_kkm')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['ssp'] = $this->db->order_by('kd_kdssp', SORT_ASC)->get('t_ssp')->result_array();
        $data['nilaissp'] = $this->db->get('t_nilaissp')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataWalasSiswa();
        $cekNilaiSsp = $this->db->get_where('t_ssp', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['cekNsp'] = $cekNilaiSsp;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Sikap Spiritual';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekNilaiSsp < 5) {
            $this->session->set_flashdata('messageInfo2', 'Indikator sikap spiritual minimal 5 indikator !');
            $this->load->view('walas/nilai_ssp', $data);
        } else {
            if ($cekRombelSiswa > 0) {
                $this->load->view('walas/nilai_ssp', $data);
            } else {
                $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
                $this->load->view('walas/nilai_ssp', $data);
            }
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputNilaiPrestasi()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('nm_prestasi', 'Nama Prestasi', 'required|trim');
        $this->form_validation->set_rules('ket_prestasi', 'Keterangan Prestasi', 'required|trim');
        $newKdstudents = $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newPrestasi = htmlspecialchars($this->input->post('nm_prestasi'));
        $newKetPrestasi = htmlspecialchars($this->input->post('ket_prestasi'));
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_prestasi');
        } else {
            $cekIdPrestasi = $this->db->get_where('t_prestasi', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'nm_prestasi' => $newPrestasi, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
            if ($cekIdPrestasi > 0) {
                $this->session->set_flashdata('messageError', 'Data prestasi ' . $newPrestasi . ' sudah ada !');
                redirect('walas/nilai_prestasi');
            } else {
                $data = [
                    'kd_kelas' => $newKdkelas,
                    'kd_students' => $newKdstudents,
                    'nm_prestasi' => $newPrestasi,
                    'ket_prestasi' => $newKetPrestasi,
                    'kd_tapel' => $newTapel,
                    'kd_lembaga' => $newKdlembaga
                ];
                $this->m_walas->inputDataNilaiPrestasi($data);
                $this->session->set_flashdata('messageSave', 'Data prestasi ' . $newPrestasi . ' berhasil ditambahkan !');
                redirect('walas/nilai_prestasi');
                // created by : KuduSinau_Hendrik_081275532220
            }
        }
    }
    public function updateDataNilaiPrestasi()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $idPrestasi['id_prestasi'] = $this->input->post("id_prestasi");
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('nm_prestasi', 'Nama Prestasi', 'required|trim');
        $this->form_validation->set_rules('ket_prestasi', 'Keterangan Prestasi', 'required|trim');
        $newKdstudents = $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newPrestasi = htmlspecialchars($this->input->post('nm_prestasi'));
        $newKetPrestasi = htmlspecialchars($this->input->post('ket_prestasi'));
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_prestasi');
        } else {
            $data = [
                'kd_kelas' => $newKdkelas,
                'kd_students' => $newKdstudents,
                'nm_prestasi' => $newPrestasi,
                'ket_prestasi' => $newKetPrestasi,
                'kd_tapel' => $newTapel,
                'kd_lembaga' => $newKdlembaga
            ];
            $this->db->where('id_prestasi', $idPrestasi['id_prestasi']);
            $this->db->where('kd_tapel', $kdTapel);
            $this->db->where('kd_lembaga', $newKdlembaga);
            $this->db->update('t_prestasi', $data);
            $this->session->set_flashdata('messageSave', 'Data prestasi ' . $newPrestasi . ' berhasil diupdate !');
            redirect('walas/nilai_prestasi');
            // created by : KuduSinau_Hendrik_081275532220
        }
    }
    public function inputNilaiSp()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('kd_ssp[]', 'Kode Spiritual', 'required|trim');
        $this->form_validation->set_rules('n_sp[]', 'Nilai Spiritual', 'required|numeric|trim');
        $this->form_validation->set_rules('desk_sp[]', 'Deskripsi Spiritual', 'required|trim');
        $this->form_validation->set_rules('tipe_n[]', 'Deskripsi Spiritual', 'required|trim');
        $newKdstudents =  $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newKdssp = $this->input->post('kd_ssp');
        $newNilaisp = $this->input->post('n_sp');
        $newDesksp = $this->input->post('desk_sp');
        $newTipe = $this->input->post('tipe_n');
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_ssp');
        } else {
            $data = array();
            foreach ($newKdssp as $nrs => $sp) {
                $data[$nrs]['kd_ssp'] = $sp;
            }
            $cekKdsp = $this->db->get_where('t_nilaissp', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_ssp' => $sp, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
            if ($cekKdsp > 0) {
                $data =  $this->input->post();
                for ($i = 0; $i < count($data['id_nilaissp']); $i++) {
                    $update[] = array(
                        'id_nilaissp'   => $data['id_nilaissp'][$i],
                        'kd_kelas'      => $newKdkelas,
                        'kd_students'   => $newKdstudents,
                        'kd_ssp'        => $data['kd_ssp'][$i],
                        'tipe_n'        => $data['tipe_n'][$i],
                        'n_sp'          => $data['n_sp'][$i],
                        'kd_tapel'      => $newTapel,
                        'kd_lembaga'    => $newKdlembaga,
                    );
                }
                $this->m_walas->updateDataNilaiSp($update, 'id_nilaissp');
                $cekKdsp = $this->db->get_where('t_akhirsp', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
                if ($cekKdsp > 0) {
                    $this->db->select_avg('n_sp', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaissp')->row_array();
                    $newNakhirSp =  round($query['rata']);
                    $predikat =  $newNakhirSp;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp1' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_sp'] . ', ';
                    }
                    $queryP1 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp2' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP1)) {
                        $deskP1 = '';
                    } else {
                        $deskP1 = $queryP1['desk_sp'] . ', ';
                    }
                    $queryP2 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp3' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP2)) {
                        $deskP2 = '';
                    } else {
                        $deskP2 = $queryP2['desk_sp'] . ', ';
                    }
                    $queryP3 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp4' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP3)) {
                        $deskP3 = '';
                    } else {
                        $deskP3 = $queryP3['desk_sp'] . ', ';
                    }
                    $queryP4 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp5' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP4)) {
                        $deskP4 = '';
                    } else {
                        $deskP4 = $queryP4['desk_sp'] . ', ';
                    }
                    $newAkhirDeskripsiSp = $deskP . $deskP1 . $deskP2 . $deskP3 . $deskP4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda sangat baik dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan tetap istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda mulai berkembang dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda mulai terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda belum terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirsp' =>  $newNakhirSp,
                        'predikat_sp' =>  $grade,
                        'deskripsi_sp' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->db->where('kd_kelas', $newKdkelas);
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $this->db->update('t_akhirsp', $dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap spiritual berhasil diupdate !');
                    redirect('walas/nilai_ssp');
                } else {
                    $this->db->select_avg('n_sp', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaissp')->row_array();
                    $newNakhirSp =  round($query['rata']);
                    $predikat =  $newNakhirSp;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp1' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_sp'] . ', ';
                    }
                    $queryP1 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp2' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP1)) {
                        $deskP1 = '';
                    } else {
                        $deskP1 = $queryP1['desk_sp'] . ', ';
                    }
                    $queryP2 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp3' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP2)) {
                        $deskP2 = '';
                    } else {
                        $deskP2 = $queryP2['desk_sp'] . ', ';
                    }
                    $queryP3 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp4' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP3)) {
                        $deskP3 = '';
                    } else {
                        $deskP3 = $queryP3['desk_sp'] . ', ';
                    }
                    $queryP4 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp5' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP4)) {
                        $deskP4 = '';
                    } else {
                        $deskP4 = $queryP4['desk_sp'] . ', ';
                    }
                    $newAkhirDeskripsiSp = $deskP . $deskP1 . $deskP2 . $deskP3 . $deskP4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda sangat baik dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan tetap istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda mulai berkembang dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda mulai terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda belum terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirsp' =>  $newNakhirSp,
                        'predikat_sp' =>  $grade,
                        'deskripsi_sp' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->m_walas->inputDataNilaiAkhirSp($dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap spiritual berhasil diupdate !');
                    redirect('walas/nilai_ssp');
                }
            } else {
                $data = array();
                foreach ($newKdssp as $nrs => $rs) {
                    $data[$nrs]['kd_students'] = $newKdstudents;
                    $data[$nrs]['kd_kelas'] =  $newKdkelas;
                    $data[$nrs]['kd_ssp'] = $rs;
                    $data[$nrs]['kd_tapel'] = $newTapel;
                    $data[$nrs]['kd_lembaga'] = $newKdlembaga;
                }
                foreach ($newNilaisp as $nrs => $rs) {
                    $data[$nrs]['n_sp'] = $rs;
                }
                foreach ($newDesksp as $nrs => $rs) {
                    $data[$nrs]['desk_sp'] = $rs;
                }
                foreach ($newTipe as $nrs => $rs) {
                    $data[$nrs]['tipe_n'] = $rs;
                }
                $this->m_walas->inputDataNilaiSp($data);
                $cekKdsp = $this->db->get_where('t_akhirsp', array('kd_kelas' => $newKdkelas, 'kd_students' => $newKdstudents, 'kd_tapel' => $kdTapel, 'kd_lembaga' => $newKdlembaga))->num_rows();
                if ($cekKdsp > 0) {
                    $this->db->select_avg('n_sp', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaissp')->row_array();
                    $newNakhirSp =  round($query['rata']);
                    $predikat =  $newNakhirSp;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp1' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_sp'] . ', ';
                    }
                    $queryP1 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp2' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP1)) {
                        $deskP1 = '';
                    } else {
                        $deskP1 = $queryP1['desk_sp'] . ', ';
                    }
                    $queryP2 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp3' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP2)) {
                        $deskP2 = '';
                    } else {
                        $deskP2 = $queryP2['desk_sp'] . ', ';
                    }
                    $queryP3 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp4' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP3)) {
                        $deskP3 = '';
                    } else {
                        $deskP3 = $queryP3['desk_sp'] . ', ';
                    }
                    $queryP4 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp5' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP4)) {
                        $deskP4 = '';
                    } else {
                        $deskP4 = $queryP4['desk_sp'] . ', ';
                    }
                    $newAkhirDeskripsiSp = $deskP . $deskP1 . $deskP2 . $deskP3 . $deskP4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda sangat baik dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan tetap istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda mulai berkembang dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda mulai terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda belum terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirsp' =>  $newNakhirSp,
                        'predikat_sp' =>  $grade,
                        'deskripsi_sp' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->db->where('kd_kelas', $newKdkelas);
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $this->db->update('t_akhirsp', $dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap spiritual berhasil diupdate !');
                    redirect('walas/nilai_ssp');
                } else {
                    $this->db->select_avg('n_sp', 'rata');
                    $this->db->where('kd_students', $newKdstudents);
                    $this->db->where('kd_kelas',  $newKdkelas);
                    $this->db->where('kd_tapel',  $kdTapel);
                    $this->db->where('kd_lembaga',  $newKdlembaga);
                    $query = $this->db->get('t_nilaissp')->row_array();
                    $newNakhirSp =  round($query['rata']);
                    $predikat =  $newNakhirSp;
                    if ($predikat == 4) {
                        $grade = "Sangat Baik";
                    } elseif ($predikat == 3) {
                        $grade = "Baik";
                    } elseif ($predikat == 2) {
                        $grade = "Cukup";
                    } else {
                        $grade = "Kurang";
                    }
                    $queryP = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp1' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP)) {
                        $deskP = '';
                    } else {
                        $deskP = $queryP['desk_sp'] . ', ';
                    }
                    $queryP1 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp2' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP1)) {
                        $deskP1 = '';
                    } else {
                        $deskP1 = $queryP1['desk_sp'] . ', ';
                    }
                    $queryP2 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp3' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP2)) {
                        $deskP2 = '';
                    } else {
                        $deskP2 = $queryP2['desk_sp'] . ', ';
                    }
                    $queryP3 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp4' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP3)) {
                        $deskP3 = '';
                    } else {
                        $deskP3 = $queryP3['desk_sp'] . ', ';
                    }
                    $queryP4 = $this->db->query("SELECT desk_sp FROM t_nilaissp WHERE kd_kelas = '$newKdkelas' AND kd_students = '$newKdstudents' AND tipe_n = 'sp5' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
                    if (is_null($queryP4)) {
                        $deskP4 = '';
                    } else {
                        $deskP4 = $queryP4['desk_sp'] . ', ';
                    }
                    $newAkhirDeskripsiSp = $deskP . $deskP1 . $deskP2 . $deskP3 . $deskP4;
                    $predikat = $grade;
                    if ($predikat == 'Sangat Baik') {
                        $deskripsiAkhir = 'Ananda sangat baik dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan tetap istiqomah.';
                    } elseif ($predikat == 'Baik') {
                        $deskripsiAkhir = 'Ananda mulai berkembang dan konsisten menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu dipertahankan dan ditingkatkan lagi.';
                    } elseif ($predikat == 'Cukup') {
                        $deskripsiAkhir = 'Ananda mulai terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    } else {
                        $deskripsiAkhir = 'Ananda belum terlihat menerapkan ' . $newAkhirDeskripsiSp . 'sehingga perlu pembinaan dan pendampingan secara intensif.';
                    }
                    $dt = [
                        'kd_students' =>  $newKdstudents,
                        'kd_kelas' =>  $newKdkelas,
                        'n_akhirsp' =>  $newNakhirSp,
                        'predikat_sp' =>  $grade,
                        'deskripsi_sp' =>  $deskripsiAkhir,
                        'kd_tapel' => $newTapel,
                        'kd_lembaga' => $newKdlembaga
                    ];
                    $this->m_walas->inputDataNilaiAkhirSp($dt);
                    $this->session->set_flashdata('messageSave', 'Data nilai sikap spiritual berhasil diupdate !');
                    redirect('walas/nilai_ssp');
                    // created by : KuduSinau_Hendrik_081275532220
                }
            }
        }
    }
    public function hapusNilaiPrestasi($idPrestasi)
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $query = $this->db->query("SELECT nm_prestasi FROM t_prestasi WHERE id_prestasi = '$idPrestasi' AND kd_tapel = '$kdTapel' AND kd_lembaga = '$newKdlembaga'")->row_array();
        $nmPrestasi = $query['nm_prestasi'];
        $where = array('id_prestasi' => $idPrestasi);
        $this->m_walas->deleteDataPrestasi($where, 't_prestasi');
        $this->session->set_flashdata('messageSuccess', 'Data prestasi ' . $nmPrestasi . ' berhasil dihapus !');
        redirect('walas/nilai_prestasi');
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function print_rapor_1_3($kdsiswa)
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $kdLembaga =  $data['nmLembaga']['id_lembaga'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['kkm'] = $this->db->get('t_kkm')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['kdp'] = $this->db->get('t_nokdp')->result_array();
        $data['nilaip'] = $this->db->get('t_nilaip')->result_array();
        $data['akhirp'] = $this->db->get('t_akhirp')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['rSiswap'] = $this->m_guru->viewDataRsiswa();
        $data['nSiswap'] = $this->m_guru->nilaiSiswap();
        $data['tgl'] = $this->m_guru->viewDataTgl();
        $data['Siswa'] = $this->m_walas->viewDataWalasSiswa();
        $data['kdsiswa'] = $kdsiswa;
        $this->db->select('*');
        $this->db->from('t_students');
        $this->db->join('t_teachers', 't_students.nm_kamad = t_teachers.id_teachers');
        $this->db->where('t_students.id_students', $kdsiswa);
        $this->db->where('t_students.kd_lembaga',  $newKdlembaga);
        $dtsiswa = $this->db->get()->row_array();
        if (!is_null($dtsiswa)) {
            $dtsiswa1 = $dtsiswa;
        }
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->where('t_lembaga.id_lembaga', $kdLembaga);
        $dtlembaga = $this->db->get()->row_array();
        if (!is_null($dtlembaga)) {
            $dtlembaga1 = $dtlembaga;
        }
        $this->db->select('image_user');
        $this->db->from('t_user');
        $this->db->where('t_user.kd_students', $kdsiswa);
        $this->db->where('t_user.kd_user', $newKdlembaga);
        $dtuser = $this->db->get()->row_array();
        if (!is_null($dtuser)) {
            $dtuser1 = $dtuser;
        }
        $data['students'] = $dtsiswa1;
        $data['lembaga'] = $dtlembaga1;
        $data['user'] = $dtuser1;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Print Rapor';
        $this->load->view('template/header', $data);
        $this->load->view('walas/print_rapor_1_3', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function cetak_rapor()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $newKdGuru = $data['nmUser']['kd_teachers'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $data['newTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_walas');
        $this->db->where('kd_teachers', $newKdGuru);
        $this->db->where('kd_tapel', $kdTapel);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $dataKelas = $this->db->get()->row_array();
        $data['kdKelas'] = $dataKelas;
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['naik'] = $this->db->get('t_naik')->result_array();
        $data['lulus'] = $this->db->get('t_lulus')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataNaikSiswa();
        $cekCatatan = $this->db->get_where('t_catatan', array('kd_lembaga' => $newKdlembaga, 'kd_kelas' => $data['kdKelas']['kd_kelas'], 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['cekCatatan'] = $cekCatatan;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Print Rapor';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekCatatan > 0) {
            if ($cekRombelSiswa > 0) {
                $this->load->view('walas/cetak_rapor', $data);
            } else {
                $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
                $this->load->view('walas/cetak_rapor', $data);
            }
        } else {
            $this->session->set_flashdata('messageInfo', 'Pengisian rapor semester ini oleh wali kelas belum selesai !');
            $this->load->view('walas/cetak_rapor', $data);
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function print_legger($kdKelas)
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $NmLembaga = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $newNmlembaga = $NmLembaga['id_lembaga'];
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        if (!is_null($dataTapel)) {
            $kdTapel = $dataTapel['id_tapel'];
        } else {
            $kdTapel = 'null';
        }
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['kkm'] = $this->db->get('t_kkm')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['kdp'] = $this->db->get('t_nokdp')->result_array();
        $data['nilaip'] = $this->db->get('t_nilaip')->result_array();
        $data['akhirp'] = $this->db->get('t_akhirp')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['rSiswap'] = $this->m_guru->viewDataRsiswa();
        $data['nSiswap'] = $this->m_guru->nilaiSiswap();
        $data['tgl'] = $this->m_guru->viewDataTgl();
        $data['kdKelas'] = $kdKelas;
        $this->db->select('nm_rombel as rombel, nm_kelas as tingkat');
        $this->db->from('t_kelas');
        $this->db->where('kd_tapel',  $kdTapel);
        $this->db->where('kd_lembaga',  $newKdlembaga);
        $this->db->where('id_kelas', $kdKelas);
        $data['nmKelas'] = $this->db->get()->row_array();
        $this->db->select(' t_tapel.kd_smstr as semester,
                            t_teachers.nm_teachers as kamad,
                            t_teachers.gelar_depan as gelardepan, 
                            t_teachers.gelar_belakang as gelarbelakang, 
                            t_teachers.nip_teachers as nip_kamad,
                            t_tapel.kd_tahun as tahun,
                            t_tgl.tmpt_tgl as tempat,
                            t_tapel.id_tapel as tapel,
                            t_tgl.nm_tgl1 as tanggal,
                            t_tgl.nm_tgl3 as tanggal3
        ');
        $this->db->from('t_tapel');
        $this->db->join('t_tgl', 't_tapel.id_tapel = t_tgl.kd_tapel');
        $this->db->join('t_teachers', 't_tgl.kd_teachers = t_teachers.id_teachers');
        $this->db->where('t_tapel.sts_tapel', 1);
        $this->db->where('t_tapel.kd_lembaga', $newNmlembaga);
        $wakturapor = $this->db->get()->row_array();
        $this->db->select(' t_students.nm_students as nama_siswa, 
                            t_students.nislokal_students as nism_siswa, 
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as id_siswa,
                            t_kelas.nm_rombel as kelas,
                            t_kelas.nm_kelas as tingkat,
                            t_walas.id_walas as kode_walas,
                            t_kelas.id_kelas as kode_kelas
        ');
        $this->db->from('t_walas');
        $this->db->join('t_kelas', 't_walas.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_students', 't_rombelsiswa.kd_students = t_students.id_students');
        $this->db->where('t_walas.kd_kelas', $kdKelas);
        $this->db->where('t_rombelsiswa.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_rombelsiswa.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        $siswa = $this->db->get()->result_array();
        $this->db->select(' t_teachers.nm_teachers as nama_guru, 
                            t_teachers.gelar_depan as gelardepan, 
                            t_teachers.gelar_belakang as gelarbelakang, 
                            t_teachers.nip_teachers as nip_guru, 
                            t_teachers.nuptk_teachers as nuptk_guru,
                            t_teachers.id_teachers as id_guru,
        ');
        $this->db->from('t_walas');
        $this->db->join('t_kelas', 't_walas.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_teachers', 't_walas.kd_teachers = t_teachers.id_teachers');
        $this->db->where('t_walas.kd_kelas', $kdKelas);
        $this->db->where('t_walas.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_teachers.Kd_lembaga',  $newNmlembaga);
        $guru = $this->db->get()->row_array();
        $this->db->select(' t_kkm.n_kkmkls as kkm,
                            t_gmapel.id_gmapel as idg_mapel,
                            t_kkm.d as d,
                            t_kkm.c as c,
                            t_kkm.b as b,
                            t_kkm.a as a,
        ');
        $this->db->from('t_tapel');
        $this->db->join('t_kelas', 't_kelas.kd_tapel = t_tapel.id_tapel');
        $this->db->join('t_gmapel', 't_gmapel.kd_kelas = t_kelas.id_kelas');
        $this->db->join('t_teachers', 't_gmapel.kd_teachers = t_teachers.id_teachers');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_kkm', 't_gmapel.id_gmapel = t_kkm.kd_gmapel');
        $this->db->where('t_kelas.id_kelas', $kdKelas);
        $this->db->where('t_tapel.sts_tapel', 1);
        $this->db->where('t_kkm.kd_lembaga', $newNmlembaga);
        $kkm1 = $this->db->get()->row_array();
        if (!is_null($kkm1)) {
            $kkm = $kkm1['kkm'];
        } else {
            $kkm = 0;
        }
        if (!is_null($kkm1)) {
            $a = $kkm1['a'];
        } else {
            $a = 0;
        }
        if (!is_null($kkm1)) {
            $b = $kkm1['b'];
        } else {
            $b = 0;
        }
        if (!is_null($kkm1)) {
            $c = $kkm1['c'];
        } else {
            $c = 0;
        }
        if (!is_null($kkm1)) {
            $d = $kkm1['d'];
        } else {
            $d = 0;
        }
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.ARB');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['b_arabk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.ARB');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['b_arabp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.INA');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['b_indok'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.INA');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['b_indop'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.PKN');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['pknk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.PKN');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['pknp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.SKI');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['skik'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.SKI');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['skip'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.FKH');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['fikihk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.FKH');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['fikihp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.AKA');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['akidah_ak'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.AKA');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['akidah_ap'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.AQH');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['quran_hk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.AQH');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['quran_hp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.MTK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['mtkk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.MTK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['mtkp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.IPA');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['ipak'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.IPA');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['ipap'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.IPS');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['ipsk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.IPS');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['ipsp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.ING');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['b_ingk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.ING');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['b_ingp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.SJI');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['sej_indok'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'A.SJI');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['sej_indop'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa,
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.SBP');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['sb_prak'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.SBP');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['sb_prap'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PJK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['penjasorkesk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PJK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['penjasorkesp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.SBD');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['sen_budk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.SBD');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['sen_budp'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PRK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['prakaryak'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa,
                            t_bidstudy.nm_nmbidstudy as nama_mapel
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PRK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['prakaryap'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.INF');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['informatikak'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa,
                            t_bidstudy.nm_nmbidstudy as nama_mapel
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.INF');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['informatikap'] = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kd_mapel
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.INF');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['nmInf'] = $this->db->get()->row_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kd_mapel
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PRK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['nmPra'] = $this->db->get()->row_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kdk_siswa
        ');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PDK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirk.kd_lembaga', $newNmlembaga);
        $data['pra_kwhk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.nm_students as nama_siswa,
                            t_students.nisn_students as nisn_siswa,
                            t_students.id_students as kdp_siswa
        ');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_gmapel.kd_bidstudy = t_bidstudy.id_bidstudy');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_bidstudy.nm_kdbidstudy', 'B.PDK');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_akhirp.kd_lembaga', $newNmlembaga);
        $data['pra_kwhp'] = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
        ');
        $this->db->from('t_bidstudy');
        $this->db->join('t_gmapel', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Muatan Lokal (B)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $data['nmMulok'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirp', 't_akhirp.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Muatan Lokal (B)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['npMulok'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
                        
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirk', 't_akhirk.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Muatan Lokal (B)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['nkMulok'] = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
        ');
        $this->db->from('t_bidstudy');
        $this->db->join('t_gmapel', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Peminatan (C)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $data['nmPeminatan'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirp', 't_akhirp.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Peminatan (C)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['npPeminatan'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
                        
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirk', 't_akhirk.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Peminatan (C)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['nkPeminatan'] = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
        ');
        $this->db->from('t_bidstudy');
        $this->db->join('t_gmapel', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Mata Pelajaran Pilihan (C)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $data['nmPilihan'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirp', 't_akhirp.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Mata Pelajaran Pilihan (C)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['npPilihan'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
                        
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirk', 't_akhirk.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Mata Pelajaran Pilihan (C)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['nkPilihan'] = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
        ');
        $this->db->from('t_bidstudy');
        $this->db->join('t_gmapel', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Bidang Keahlian (C1)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $data['nmDbk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirp', 't_akhirp.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Bidang Keahlian (C1)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['npDbk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
                        
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirk', 't_akhirk.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Bidang Keahlian (C1)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['nkDbk'] = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
        ');
        $this->db->from('t_bidstudy');
        $this->db->join('t_gmapel', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Program Keahlian (C2)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $data['nmDpk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirp', 't_akhirp.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Program Keahlian (C2)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['npDpk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
                        
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirk', 't_akhirk.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Dasar Program Keahlian (C2)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['nkDpk'] = $this->db->get()->result_array();
        $this->db->select(' t_bidstudy.nm_kdbidstudy as kode_mapel,
                            t_bidstudy.nm_nmbidstudy as nama_mapel,
        ');
        $this->db->from('t_bidstudy');
        $this->db->join('t_gmapel', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Paket Keahlian (C3)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_bidstudy.nm_nmbidstudy', SORT_ASC);
        $data['nmPk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirp.n_akhirp as nilaip_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirp', 't_akhirp.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Paket Keahlian (C3)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['npPk'] = $this->db->get()->result_array();
        $this->db->select(' t_akhirk.n_akhirk as nilaik_mapel,
                            t_students.id_students as kode_siswa,
                            t_bidstudy.nm_kdbidstudy as kode_mapel
                        
        ');
        $this->db->from('t_students');
        $this->db->join('t_akhirk', 't_akhirk.kd_students = t_students.id_students');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_bidstudy', 't_bidstudy.id_bidstudy = t_gmapel.kd_bidstudy');
        $this->db->where('t_bidstudy.nm_kategori', 'Paket Keahlian (C3)');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $data['nkPk'] = $this->db->get()->result_array();
        $data['nilaip'] = $this->db->get('t_akhirp')->result_array();
        $this->db->select_sum('n_akhirp', 'jlhp');
        $this->db->from('t_akhirp');
        $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirp.aktif_p', 1);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        $jlhnilaip = $this->db->get()->result_array();
        if (is_null($jlhnilaip)) {
            $data['jumlahp'] = 0;
        } else {
            $data['jumlahp'] = $jlhnilaip;
        }
        $data['nilaik'] = $this->db->get('t_akhirk')->result_array();
        $this->db->select_sum('n_akhirk', 'jlhk');
        $this->db->from('t_akhirk');
        $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
        $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
        $this->db->where('t_gmapel.kd_kelas', $kdKelas);
        $this->db->where('t_akhirk.aktif_k', 1);
        $this->db->where('t_gmapel.kd_tapel', $wakturapor['tapel']);
        $this->db->where('t_gmapel.kd_lembaga', $newNmlembaga);
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        $jlhnilaik = $this->db->get()->result_array();
        if (is_null($jlhnilaik)) {
            $data['jumlahk'] = 0;
        } else {
            $data['jumlahk'] = $jlhnilaik;
        }
        $data['waktu'] = $wakturapor;
        $data['students'] = $siswa;
        $data['teachers'] = $guru;
        $data['kkm'] = $kkm;
        $data['a'] = $a;
        $data['b'] = $b;
        $data['c'] = $c;
        $data['d'] = $d;
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Print Rapor';
        $this->load->view('template/header', $data);
        $this->load->view('walas/print_legger', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function nomor_um()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['naik'] = $this->db->get('t_naik')->result_array();
        $data['lulus'] = $this->db->get('t_lulus')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataNomorUm();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Nomor UM';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekRombelSiswa > 0) {
            $this->load->view('walas/nomor_um', $data);
        } else {
            $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
            $this->load->view('walas/nomor_um', $data);
        }
        $this->load->view('template/footer', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function block()
    {
        $data['title'] = 'D-Rapor | Blocked';
        $this->load->view('walas/block', $data);
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataNilaiEskul()
    {
        $dataUser = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $idNilaiEskul['id_nilaieskul'] = $this->input->post("id_nilaieskul");
        $newKdlembaga = $dataUser['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $newTapel = $dataTapel['id_tapel'];
        $this->form_validation->set_rules('kd_students', 'Kode Siswa', 'required|trim');
        $this->form_validation->set_rules('kd_kelas', 'Kode Kelas', 'required|trim');
        $this->form_validation->set_rules('kd_eskul', 'Kode Eskul', 'required|trim');
        $this->form_validation->set_rules('predikat_eskul', 'Predikat Eskul', 'required|trim');
        $this->form_validation->set_rules('deskripsi_eskul', 'Deskripsi Eskul', 'required|trim');
        $newKdstudents =  $this->input->post('kd_students');
        $newKdkelas = $this->input->post('kd_kelas');
        $newnmKdEskul = $this->input->post('kd_eskul');
        $newNilaiEskul = $this->input->post('predikat_eskul');
        $newDeskEskul = $this->input->post('deskripsi_eskul');
        $this->db->select('*');
        $this->db->from('t_eskul');
        $this->db->where('nm_eskul', $newnmKdEskul);
        $this->db->where('kd_tapel', $newTapel);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $query = $this->db->get()->row_array();
        $kdEskul = $query['kd_eskul'];
        $idEskul = $query['id_eskul'];
        if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('messageWarning', 'Data tidak boleh kosong !');
            redirect('walas/nilai_eskul');
        } else {
            $data = [
                'kd_students' => $newKdstudents,
                'kd_kelas' =>  $newKdkelas,
                'kd_eskul' =>  $idEskul,
                'tipe_n' =>  $kdEskul,
                'predikat_eskul' => $newNilaiEskul,
                'deskripsi_eskul' => $newDeskEskul,
                'kd_tapel' => $newTapel,
                'kd_lembaga' => $newKdlembaga
            ];
            $this->m_walas->updateDataEskul($data, $idNilaiEskul);
            $query = $this->db->query("SELECT nm_eskul FROM t_eskul JOIN t_nilaieskul WHERE t_eskul.kd_eskul = '$kdEskul' AND id_eskul = ' $idEskul' AND t_nilaieskul.kd_tapel = '$newTapel' AND t_nilaieskul.kd_lembaga = '$newKdlembaga'")->row_array();
            $nmEskul = $query['nm_eskul'];
            $this->session->set_flashdata('messageSave', 'Data ekstrakurikuler ' . $nmEskul . ' berhasil diupdate !');
            redirect('walas/nilai_eskul');
            // created by : KuduSinau_Hendrik_081275532220
        }
    }
    public function nomor_ijazah()
    {
        $data['nmUser'] = $this->db->get_where('t_user', ['username' => $this->session->userdata('username')])->row_array();
        $data['nmJenjang'] = $this->db->get_where('t_jenjang', ['id_jenjang' => $this->session->userdata('kd_jenjang')])->row_array();
        $data['nmLevel'] = $this->db->get_where('t_level', ['id_level' => $this->session->userdata('kd_level')])->row_array();
        $data['nmStatus'] = $this->db->get_where('t_status', ['id_status' => $this->session->userdata('status_lembaga')])->row_array();
        $data['nmLembaga'] = $this->db->get_where('t_lembaga', ['id_lembaga' => $this->session->userdata('kd_user')])->row_array();
        $data['nmTapel'] = $this->db->get_where('t_tapel', ['kd_lembaga' => $this->session->userdata('kd_user')])->result_array();
        $newKdlembaga = $data['nmUser']['kd_user'];
        $this->db->select('*');
        $this->db->from('t_tapel');
        $this->db->where('sts_tapel', 1);
        $this->db->where('kd_lembaga', $newKdlembaga);
        $this->db->order_by('t_tapel.kd_tahun', SORT_ASC);
        $dataTapel = $this->db->get()->row_array();
        $data['kdTapel'] = $dataTapel;
        $this->db->select('*');
        $this->db->from('t_lembaga');
        $this->db->join('t_jenjang', 't_lembaga.kd_jenjang = t_jenjang.id_jenjang');
        $this->db->join('t_status', 't_lembaga.kd_status = t_status.id_status');
        $this->db->where('t_lembaga.id_lembaga', $newKdlembaga);
        $data['Lembaga'] = $this->db->get()->row_array();
        $data['gMapel'] = $this->db->get('t_gmapel')->result_array();
        $data['naik'] = $this->db->get('t_naik')->result_array();
        $data['lulus'] = $this->db->get('t_lulus')->result_array();
        $data['dtKdp'] = $this->db->get('t_kdp')->result_array();
        $data['eskul'] = $this->db->get('t_eskul')->result_array();
        $data['nilaieskul'] = $this->db->get('t_nilaieskul')->result_array();
        $data['walas'] = $this->db->get('t_walas')->result_array();
        $data['dtKkm'] = $this->m_guru->viewDataKkm();
        $data['dtNilaip'] = $this->m_guru->viewDataNilaip();
        $data['dtWalasGuru'] = $this->m_walas->viewDataWalasGuru();
        $data['dtWalasSiswa'] = $this->m_walas->viewDataNomorIjazah();
        $cekRombelSiswa = $this->db->get_where('t_rombelsiswa', array('kd_lembaga' => $newKdlembaga, 'kd_tapel' => $data['kdTapel']['id_tapel']))->num_rows();
        $data['nama'] = 'Digital Rapor';
        $data['footer'] = 'KuduSinau';
        $data['title'] = 'D-Rapor | Nomor Ijazah';
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar', $data);
        $this->load->view('template/headertop', $data);
        $this->load->view('template/mobile', $data);
        if ($cekRombelSiswa > 0) {
            $this->load->view('walas/nomor_ijazah', $data);
        } else {
            $this->session->set_flashdata('messageInfo2', 'Belum ada siswa di kelas - rombel ini !');
            $this->load->view('walas/nomor_ijazah', $data);
        }
        $this->load->view('template/footer', $data);
    }
}
// created by : KuduSinau_Hendrik_081275532220 (TERIMAKASIH UNTUK MENDAPATKAN KEBERKAHAN, DENGAN TIDAK MERUBAH NAMA HAK CIPTA, PLAGIAT, DAN TIDAK MEMPERJUALBELIKAN APLIKASI INI, SEMOGA KITA SEMUA MENDAPAT MANFAAT DAN KEBERKAHAN DARI APLIKASI INI)
