function komentar($segment_3 = '', $segment_4 = '') { # panggil datatables dan combobox $data['comp_js'] = load_comp_js(array(base_url('assets/comp/datatables/jquery.dataTables.js'), base_url('assets/comp/datatables/datatable-bootstrap2.js'), base_url('assets/comp/datatables/script.js'))); $data['comp_css'] = load_comp_css(array(base_url('assets/comp/datatables/datatable-bootstrap2.css'))); switch ($segment_3) { case 'laporan': if (!is_admin()) { redirect('materi/komentar'); } $field_id = 'laporkan-komentar'; $retrieve_field = retrieve_field($field_id); if (isset($retrieve_field['value'])) { $field_value = json_decode($retrieve_field['value'], 1); } else { $field_value = array(); } # aksi $get_act = !empty($_GET['act']) ? $_GET['act'] : ''; if (!empty($get_act) and in_array($get_act, array(1, 2))) { $id = (string) $_GET['id']; if (empty($id)) { redirect('materi/komentar/laporan'); } # hapus komentar dan laporan if (!empty($field_value[$id])) { $laporan = $field_value[$id]; if ($get_act == 1) { # hapus komentar $this->komentar_model->delete($laporan['komentar_id']); } # hapus laporan unset($field_value[$id]); update_field($field_id, 'Laporan Komentar', json_encode($field_value)); $this->session->set_flashdata('komentar', get_alert('success', 'Komentar ' . ($get_act == 1 ? 'dan laporan ' : '') . 'berhasil dihapus.')); redirect('materi/komentar/laporan'); } else { redirect('materi/komentar/laporan'); } } # format data $results = array(); foreach ($field_value as $id => $val) { $val['id'] = $id; # cari materi $materi = $this->materi_model->retrieve($val['materi_id']); if (empty($materi)) { # hapus laporan unset($field_value[$id]); update_field($field_id, 'Laporan Komentar', json_encode($field_value)); continue; } $val['materi'] = $materi; $login = $this->get_user_data($val['login_id']); $val['login'] = $login; $komentar = $this->komentar_model->retrieve($val['komentar_id']); if (empty($komentar)) { # hapus laporan unset($field_value[$id]); update_field($field_id, 'Laporan Komentar', json_encode($field_value)); continue; } $val['komentar'] = $komentar; $val['komentar']['login'] = $this->get_user_data($komentar['login_id']); $results[] = $val; } $data['laporan'] = $results; $this->twig->display('list-komentar-laporan.html', $data); break; case 'delete': if (!is_admin()) { redirect('materi/komentar'); } $komentar = $this->komentar_model->retrieve((int) $segment_4); if (empty($komentar)) { show_error('Komentar tidak ditemukan'); } # hapus komentar $this->komentar_model->delete($komentar['id']); $this->session->set_flashdata('komentar', get_alert('success', 'Komentar berhasil dihapus.')); redirect('materi/komentar'); break; default: $login_id = null; if (!is_admin()) { $login_id = get_sess_data('login', 'id'); } $retrieve_all = $this->komentar_model->retrieve_all($no_of_records = "all", $page_no = 1, $login_id, $materi_id = null, $tampil = 1); foreach ($retrieve_all as $key => $val) { $val['materi'] = $this->materi_model->retrieve($val['materi_id']); $retrieve_all[$key] = $this->format_komentar($val); } $data['komentar'] = $retrieve_all; if (is_admin()) { # hitung jumlah laporan $field_id = 'laporkan-komentar'; $retrieve_field = retrieve_field($field_id); if (isset($retrieve_field['value'])) { $field_value = json_decode($retrieve_field['value'], 1); } else { $field_value = array(); } $data['jml_laporan'] = count($field_value); } $this->twig->display('list-komentar.html', $data); break; } }
function sudah_ngerjakan($tugas_id, $siswa_id) { # cek sudah mengerjakan belum $nilai = get_row_data('tugas_model', 'retrieve_nilai', array(null, $tugas_id, $siswa_id)); if (!empty($nilai)) { return true; } # cek history untuk tugas essay, karna harus dikoreksi dl $check_history = retrieve_field('history-mengerjakan-' . $siswa_id . '-' . $tugas_id); if (!empty($check_history)) { return true; } return false; }
function detail_jawaban($siswa_id = '', $tugas_id = '') { $siswa_id = (int) $siswa_id; $siswa = $this->siswa_model->retrieve($siswa_id); if (empty($siswa)) { exit('Siswa tidak ditemukan'); } # cek jika siswa, punya dia tidak if (is_siswa() and $siswa['id'] != get_sess_data('user', 'id')) { exit('Akses ditolak'); } $tugas_id = (int) $tugas_id; $tugas = $this->tugas_model->retrieve($tugas_id); if (empty($tugas)) { exit('Tugas tidak ditemukan'); } $data['tugas'] = $this->formatData($tugas); $data['siswa'] = $siswa; # cari history $history_id = 'history-mengerjakan-' . $siswa['id'] . '-' . $tugas['id']; $history = retrieve_field($history_id); if (empty($history)) { exit('Tugas belum dikerjakan'); } $history_value = json_decode($history['value'], 1); $data['history'] = $history_value; if ($tugas['type_id'] == 3) { $this->twig->display('detail-jawaban-ganda.html', $data); } elseif ($tugas['type_id'] == 2) { # jika ada post nilai if (!empty($_POST['nilai'])) { $total_nilai = 0; foreach ($_POST['nilai'] as $p_id => $p_nilai) { $total_nilai = $total_nilai + $p_nilai; } # update history $history_value['nilai'] = $_POST['nilai']; update_field($history_id, $history['nama'], json_encode($history_value)); # simpan atau update nilai $check = $this->tugas_model->retrieve_nilai(null, $tugas['id'], $siswa['id']); if (empty($check)) { $this->tugas_model->create_nilai($total_nilai, $tugas['id'], $siswa['id']); } else { $this->tugas_model->update_nilai($check['id'], $total_nilai, $tugas['id'], $siswa['id']); } redirect('tugas/detail_jawaban/' . $siswa['id'] . '/' . $tugas['id']); } # cek sudah koreksi belum, dengan cara cek nilainya sudah ada belum $nilai = $this->tugas_model->retrieve_nilai(null, $tugas['id'], $siswa['id']); $data['sudah_dikoreksi'] = !empty($nilai) ? true : false; $data['nilai'] = $nilai; $this->twig->display('detail-jawaban-essay.html', $data); } elseif ($tugas['type_id'] == 1) { if (!empty($_POST['nilai'])) { $nilai = $this->input->post('nilai', true); # update history $history_value['nilai'] = $nilai; update_field($history_id, $history['nama'], json_encode($history_value)); # simpan atau update nilai $check = $this->tugas_model->retrieve_nilai(null, $tugas['id'], $siswa['id']); if (empty($check)) { $this->tugas_model->create_nilai($nilai, $tugas['id'], $siswa['id']); } else { $this->tugas_model->update_nilai($check['id'], $nilai, $tugas['id'], $siswa['id']); } redirect('tugas/detail_jawaban/' . $siswa['id'] . '/' . $tugas['id']); } # cek sudah koreksi belum, dengan cara cek nilainya sudah ada belum $nilai = $this->tugas_model->retrieve_nilai(null, $tugas['id'], $siswa['id']); $data['sudah_dikoreksi'] = !empty($nilai) ? true : false; $data['nilai'] = $nilai; $data['file_info'] = get_file_info(get_path_file($history_value['file_name'])); $data['file_info']['mime'] = get_mime_by_extension(get_path_file($history_value['file_name'])); $this->twig->display('detail-jawaban-upload.html', $data); } }
function reset_jawaban($tugas_id, $siswa_id) { # jika pengajar atau admin if (is_pengajar() or is_admin()) { $tugas_id = (int) $tugas_id; $tugas = $this->tugas_model->retrieve($tugas_id); if (empty($tugas)) { redirect('tugas'); } $siswa = $this->siswa_model->retrieve($siswa_id); if (empty($siswa)) { redirect('tugas'); } # hapus history $history_id = 'history-mengerjakan-' . $siswa['id'] . '-' . $tugas['id']; $history = retrieve_field($history_id); $history_value = json_decode($history['value'], 1); delete_field($history_id); # hapus nilai $retrieve_nilai = $this->tugas_model->retrieve_nilai(null, $tugas['id'], $siswa['id']); $this->tugas_model->delete_nilai($retrieve_nilai['id']); $this->session->set_flashdata('tugas', get_alert('success', 'Siswa berhasil dianggap belum mengerjakan.')); if ($tugas['type_id'] == 3) { redirect('tugas/nilai/' . $tugas['id']); } else { # jika tugas upload, dihapus juga file uploadnya biar g menuh-menuhin space if ($tugas['type_id'] == 1 && is_file(get_path_file($history_value['file_name']))) { @unlink(get_path_file($history_value['file_name'])); } redirect('tugas/koreksi/' . $tugas['id']); } } else { $this->session->set_flashdata('tugas', get_alert('warning', 'Akses ditolak.')); redirect('tugas'); } }
/** * Method untuk ngecek apakah siswa sudah mengerjakan tugas tertentu * * @param integer $tugas_id * @param integer $siswa_id * @return boolean */ function sudah_ngerjakan($tugas_id, $siswa_id) { $sudah = false; # cek sudah mengerjakan belum $nilai = get_row_data('tugas_model', 'retrieve_nilai', array(null, $tugas_id, $siswa_id)); if (!empty($nilai)) { $sudah = true; } # cek history, kalo sudah ada berarti sudah mengerjakan $check_history = retrieve_field('history-mengerjakan-' . $siswa_id . '-' . $tugas_id); if (!empty($check_history)) { $sudah = true; } # kalo true coba cek sekali lagi if ($sudah == true) { $check_history = retrieve_field('history-mengerjakan-' . $siswa_id . '-' . $tugas_id); if (empty($check_history)) { $sudah = false; } } return $sudah; }
function post_data($page) { switch ($page) { case 'hirarki_kelas': $o = 1; foreach ((array) $_POST['list'] as $id => $parent_id) { if (!is_numeric($parent_id)) { $parent_id = null; } $retrieve = $this->kelas_model->retrieve($id, true); # update $this->kelas_model->update($id, $retrieve['nama'], $parent_id, $o, $retrieve['aktif']); $o++; } break; case 'get_subkelas': $parent_id = $this->input->post('parent_kelas_id', true); if (!empty($parent_id)) { echo '<option value="">--pilih--</option>'; $subkelas = $this->kelas_model->retrieve_all($parent_id, array('aktif' => 1)); foreach ($subkelas as $sub) { echo '<option value="' . $sub['id'] . '">' . $sub['nama'] . '</option>'; } } break; case 'mapel_kelas': $kelas_id = $this->input->post('kelas_id', TRUE); echo '<option value="">Pilih Matapelajaran</option>'; $retrieve_all = $this->mapel_model->retrieve_all_kelas(null, $kelas_id, 1); foreach ($retrieve_all as $v) { $m = $this->mapel_model->retrieve($v['mapel_id']); if (empty($m)) { continue; } echo '<option value="' . $v['id'] . '">' . $m['nama'] . '</option>'; } break; case 'update_jawaban_ganda': if (!is_siswa()) { exit('Akses ditolak'); } $tugas_id = (int) $this->input->post('tugas_id', true); $pertanyaan_id = (int) $this->input->post('pertanyaan_id', true); $pilihan_id = (int) $this->input->post('pilihan_id', true); $tugas = $this->tugas_model->retrieve($tugas_id); if (empty($tugas)) { exit('Akses ditolak'); } $pertanyaan = $this->tugas_model->retrieve_pertanyaan($pertanyaan_id); if (empty($pertanyaan)) { exit('Akses ditolak'); } if ($pertanyaan['tugas_id'] != $tugas['id']) { exit('Akses ditolak'); } $pilihan = $this->tugas_model->retrieve_pilihan($pilihan_id, $pertanyaan['id']); if (empty($pilihan)) { exit('Akses ditolak'); } $table_name = 'field_tambahan'; $field_id = 'mengerjakan-' . get_sess_data('user', 'id') . '-' . $tugas['id']; $field_name = 'Mengerjakan Tugas'; $check_field = retrieve_field($field_id); if (empty($check_field)) { exit('Akses ditolak'); } # update index jawaban $field_value = json_decode($check_field['value'], 1); $field_value['jawaban'][$pertanyaan['id']] = $pilihan['id']; update_field($field_id, $field_name, json_encode($field_value)); break; case 'update_jawaban_essay': if (!is_siswa()) { exit('Akses ditolak'); } $tugas_id = (int) $this->input->post('tugas_id', true); $pertanyaan_id = (int) $this->input->post('pertanyaan_id', true); $jawaban = $this->input->post('jawaban', true); $tugas = $this->tugas_model->retrieve($tugas_id); if (empty($tugas)) { exit('Akses ditolak'); } $pertanyaan = $this->tugas_model->retrieve_pertanyaan($pertanyaan_id); if (empty($pertanyaan)) { exit('Akses ditolak'); } if ($pertanyaan['tugas_id'] != $tugas['id']) { exit('Akses ditolak'); } $table_name = 'field_tambahan'; $field_id = 'mengerjakan-' . get_sess_data('user', 'id') . '-' . $tugas['id']; $field_name = 'Mengerjakan Tugas'; $check_field = retrieve_field($field_id); if (empty($check_field)) { exit('Akses ditolak'); } # update index jawaban $field_value = json_decode($check_field['value'], 1); $field_value['jawaban'][$pertanyaan['id']] = $jawaban; update_field($field_id, $field_name, json_encode($field_value)); break; case 'new_msg': $active_msg_id = $this->input->post('active_msg_id', true); $active_msg_id = (int) $active_msg_id; if (empty($active_msg_id)) { echo ''; } $msg = $this->msg_model->retrieve(get_sess_data('login', 'id'), $active_msg_id, false, false); if (empty($msg)) { echo ''; } $msg = $msg['retrieve']; $this->db->where('owner_id', get_sess_data('login', 'id')); $this->db->where('opened', '0'); $this->db->where_in('sender_receiver_id', array(get_sess_data('login', 'id'), $msg['sender_receiver_id'])); $this->db->order_by('id', 'ASC'); $results = $this->db->get('messages'); foreach ($results->result_array() as $retrieve) { $this->msg_model->update_read($retrieve['id']); # jika inbox yang dicari pengirimnya if ($retrieve['type_id'] == 1) { $get_user = $retrieve['sender_receiver_id']; } elseif ($retrieve['type_id'] == 2) { $get_user = $retrieve['owner_id']; } # cari sender/receiver $login = $this->login_model->retrieve($get_user); if (!empty($login['siswa_id'])) { $user = $this->siswa_model->retrieve($login['siswa_id']); if (is_admin()) { $user['link_profil'] = site_url('siswa/detail/' . $user['status_id'] . '/' . $user['id']); } else { $user['link_profil'] = site_url('siswa/detail/' . $user['id']); } $user['link_image'] = get_url_image_siswa($user['foto'], 'medium', $user['jenis_kelamin']); } elseif (!empty($login['pengajar_id'])) { $user = $this->pengajar_model->retrieve($login['pengajar_id']); if (is_admin()) { $user['link_profil'] = site_url('pengajar/detail/' . $user['status_id'] . '/' . $user['id']); } else { $user['link_profil'] = site_url('pengajar/detail/' . $user['id']); } $user['link_image'] = get_url_image_pengajar($user['foto'], 'medium', $user['jenis_kelamin']); } # format tanggal, jika hari ini if (date('Y-m-d') == date('Y-m-d', strtotime($retrieve['date']))) { $retrieve['date'] = date('H:i', strtotime($retrieve['date'])); } elseif (date('Y-m-d', strtotime('-1 day', strtotime(date('Y-m-d')))) == date('Y-m-d', strtotime($retrieve['date']))) { $retrieve['date'] = date('H:i', strtotime($retrieve['date'])) . ' kemarin'; } elseif (date('Y-m-d', strtotime('-2 day', strtotime(date('Y-m-d')))) == date('Y-m-d', strtotime($retrieve['date']))) { $retrieve['date'] = date('H:i', strtotime($retrieve['date'])) . ' lusa'; } else { $retrieve['date'] = tgl_jam_indo($retrieve['date']); } ?> <tr id="msg-<?php echo $val['id']; ?> "> <td class="user flag-new"> <img class="img-user img-polaroid img-circle pull-left" src="<?php echo $user['link_image']; ?> "> <a href="{{ n.profil.link_profil }}"><?php echo character_limiter($user['nama'], 23, '...'); ?> </a> <br><small><?php echo $retrieve['date']; ?> </small> </td> <td class="msg-content"> <a class="pull-right" style="margin-left:10px;" href="<?php echo site_url('message/del/' . $retrieve['id'] . '/' . $msg['id']); ?> " onclick="return confirm('Anda yakin ingin menghapus?')"><i class="icon-trash"></i></a> <?php echo html_entity_decode($retrieve['content']); ?> </td> </tr> <?php } break; } }