コード例 #1
0
ファイル: email.php プロジェクト: Raniratna/new_elearning
 function edit($id = '')
 {
     $retrieve = get_pengaturan($id);
     if (empty($retrieve)) {
         redirect('email');
     }
     if (!empty($_POST) and !is_demo_app()) {
         $value = array('subject' => $_POST['subject'], 'body' => $_POST['body']);
         $this->config_model->update($id, $retrieve['nama'], json_encode($value));
         redirect('email/edit/' . $id);
     }
     $retrieve_value = json_decode($retrieve['value'], 1);
     $data['template'] = array('id' => $retrieve['id'], 'nama' => $retrieve['nama'], 'subject' => $retrieve_value['subject'], 'body' => $retrieve_value['body']);
     $data['comp_js'] = get_tinymce('body', 'simple');
     $this->twig->display('edit-email-template.html', $data);
 }
コード例 #2
0
ファイル: welcome.php プロジェクト: unregister/new_elearning
 function pengaturan()
 {
     must_login();
     if (!is_admin()) {
         redirect('welcome');
     }
     $data['comp_js'] = get_tinymce('tinymce, textarea.tinymce');
     if ($this->form_validation->run('pengaturan') == true) {
         foreach ($_POST as $key => $val) {
             # cek ada tidak, kalo ada update
             $retrieve = $this->config_model->retrieve($key);
             if (!empty($retrieve)) {
                 $this->config_model->update($key, $retrieve['nama'], $val);
             }
         }
         $this->session->set_flashdata('pengaturan', get_alert('success', 'Pengaturan berhasil diperbaharui.'));
         redirect('welcome/pengaturan');
     }
     $this->twig->display('pengaturan.html', $data);
 }
コード例 #3
0
ファイル: message.php プロジェクト: unregister/new_elearning
 function detail($segment_3 = '')
 {
     $msg_id = (int) $segment_3;
     $retrieve = $this->msg_model->retrieve(get_sess_data('login', 'id'), $msg_id);
     if (empty($retrieve['retrieve'])) {
         $this->session->set_flashdata('msg', get_alert('success', 'Pesan tidak ditemukan.'));
         redirect('message');
     }
     # format data
     $retrieve['retrieve'] = $this->format_msg($retrieve['retrieve']);
     foreach ($retrieve['old_related_msg'] as $key => &$val) {
         $retrieve['old_related_msg'][$key] = $this->format_msg($val);
     }
     foreach ($retrieve['new_related_msg'] as $key => &$val) {
         $retrieve['new_related_msg'][$key] = $this->format_msg($val);
     }
     // pr($retrieve);die;
     $data['r'] = $retrieve['retrieve'];
     $data['old_related_msg'] = $retrieve['old_related_msg'];
     $data['new_related_msg'] = $retrieve['new_related_msg'];
     if ($data['r']['sender_receiver_id'] != get_sess_data('login', 'id')) {
         $login_receiver = $this->login_model->retrieve($data['r']['sender_receiver_id']);
         if (!empty($login_receiver['siswa_id'])) {
             $user_receiver = $this->siswa_model->retrieve($login_receiver['siswa_id']);
         } elseif (!empty($login_receiver['pengajar_id'])) {
             $user_receiver = $this->pengajar_model->retrieve($login_receiver['pengajar_id']);
         }
         $data['receiver_name'] = $user_receiver['nama'] . " <{$login_receiver['username']}>";
     } else {
         $data['receiver_name'] = $data['r']['profil']['nama'] . " <{$data['r']}[login][username]>";
     }
     $html_js = get_tinymce('content');
     $html_js .= load_comp_js(array(base_url('assets/comp/autocomplete/jquery.autocomplete.min.js'), base_url('assets/comp/autocomplete/script.js'), base_url('assets/comp/jquery/get-new-msg.js')));
     $data['comp_js'] = $html_js;
     $data['comp_css'] = load_comp_css(array(base_url('assets/comp/autocomplete/autocomplete.css')));
     # update read
     $this->msg_model->update_read($msg_id);
     foreach ($data['old_related_msg'] as $old_msg) {
         $this->msg_model->update_read($old_msg['id']);
     }
     foreach ($data['new_related_msg'] as $new_msg) {
         $this->msg_model->update_read($new_msg['id']);
     }
     if (!empty($_GET['confirm']) and $_GET['confirm'] == 1) {
         $data['confirm_del_all'] = true;
     }
     $this->twig->display('detail-pesan.html', $data);
 }
コード例 #4
0
ファイル: materi.php プロジェクト: etofia/new_elearning
 function edit($segment_3 = '', $segment_4 = '', $segment_5 = '')
 {
     # versi 1.2 siswa tidak bisa tambah,edit,hapus materi
     if (is_siswa()) {
         redirect('materi');
     }
     $type = (string) strtolower($segment_3);
     $materi_id = (int) $segment_4;
     $uri_back = (string) $segment_5;
     if (empty($uri_back)) {
         $uri_back = site_url('materi');
     } else {
         $uri_back = deurl_redirect($uri_back);
     }
     $data['uri_back'] = $uri_back;
     if (!in_array($type, array('file', 'tertulis'))) {
         redirect($uri_back);
     }
     $materi = $this->materi_model->retrieve($materi_id);
     if (empty($materi)) {
         redirect($uri_back);
     }
     # cek kepemilikan
     if (is_pengajar() and $materi['pengajar_id'] != get_sess_data('user', 'id')) {
         redirect($uri_back);
     }
     if (is_siswa() and $materi['siswa_id'] != get_sess_data('user', 'id')) {
         redirect($uri_back);
     }
     # hanya ambil kelas_idnya
     $materi_kelas = $this->materi_model->retrieve_all_kelas($materi['id']);
     $materi_kelas_id = array();
     foreach ($materi_kelas as $r) {
         $materi_kelas_id[] = $r['kelas_id'];
     }
     $data['type'] = $type;
     $data['materi'] = $materi;
     $data['mapel'] = $this->mapel_model->retrieve_all_mapel();
     $data['kelas'] = $this->kelas_model->retrieve_all(null, array('aktif' => 1));
     $data['materi_kelas'] = $materi_kelas_id;
     $data['comp_js'] = get_tinymce('konten');
     if ($type == 'file') {
         $data['file_info'] = get_file_info(get_path_file($materi['file']));
         $data['file_info']['mime'] = get_mime_by_extension(get_path_file($materi['file']));
     }
     # post action
     $success = false;
     if ($type == 'tertulis') {
         if ($this->form_validation->run('materi/edit/tertulis') == TRUE) {
             $mapel_id = $this->input->post('mapel_id', TRUE);
             $judul = $this->input->post('judul', TRUE);
             $konten = $this->input->post('konten', TRUE);
             $this->materi_model->update($materi['id'], $materi['pengajar_id'], $materi['siswa_id'], $mapel_id, $judul, $konten, null, 1);
             $success = true;
         }
     } elseif ($type == 'file') {
         $upload_success = false;
         $is_new_file = false;
         # jika tidak ada yang diupload, file tetap sama
         if (empty($_FILES['userfile']['tmp_name'])) {
             $update_file = $materi['file'];
             $upload_success = true;
         } else {
             $config['upload_path'] = get_path_file();
             $config['allowed_types'] = 'doc|zip|rar|txt|docx|xls|xlsx|pdf|tar|gz|jpg|jpeg|JPG|JPEG|png|ppt|pptx';
             $config['max_size'] = '0';
             $config['max_width'] = '0';
             $config['max_height'] = '0';
             $config['file_name'] = url_title($this->input->post('judul', TRUE) . '_' . time(), '_', TRUE);
             $this->upload->initialize($config);
             if ($this->upload->do_upload()) {
                 $upload_data = $this->upload->data();
                 $update_file = $upload_data['file_name'];
                 $upload_success = true;
                 $is_new_file = true;
             } else {
                 $data['error_upload'] = '<span class="text-error">' . $this->upload->display_errors() . '</span>';
             }
         }
         if ($this->form_validation->run('materi/edit/file') == TRUE and $upload_success == TRUE) {
             $mapel_id = $this->input->post('mapel_id', TRUE);
             $judul = $this->input->post('judul', TRUE);
             $this->materi_model->update($materi['id'], $materi['pengajar_id'], $materi['siswa_id'], $mapel_id, $judul, null, $update_file, 1);
             if ($is_new_file) {
                 # hapus file sebelumnya
                 if (is_file(get_path_file($materi['file']))) {
                     unlink(get_path_file($materi['file']));
                 }
             }
             $success = true;
         } else {
             if ($is_new_file == TRUE and is_file(get_path_file($update_file))) {
                 unlink(get_path_file($update_file));
             }
         }
     }
     if ($success) {
         # cari kelas materi mana yang harus ditambah / dihapus
         $kelas_id = $this->input->post('kelas_id', TRUE);
         $kelas_post_id = array();
         foreach ($kelas_id as $post_kelas_id) {
             $post_kelas_id = (int) $post_kelas_id;
             if (!empty($post_kelas_id)) {
                 $check = $this->materi_model->retrieve_kelas(null, $materi['id'], $post_kelas_id);
                 if (empty($check)) {
                     # tambahkan
                     $this->materi_model->create_kelas($materi['id'], $post_kelas_id);
                 }
                 $kelas_post_id[] = $post_kelas_id;
             }
         }
         if (count($materi_kelas_id) > count($kelas_post_id)) {
             $diff_kelas = array_diff($materi_kelas_id, $kelas_post_id);
             foreach ($diff_kelas as $diff_kelas_id) {
                 $retrieve = $this->materi_model->retrieve_kelas(null, $materi['id'], $diff_kelas_id);
                 # hapus
                 if (!empty($retrieve)) {
                     $this->materi_model->delete_kelas($retrieve['id']);
                 }
             }
         }
         $this->session->set_flashdata('materi', get_alert('success', 'Materi berhasil diperbaharui.'));
         redirect($uri_back);
     }
     $this->twig->display('edit-materi.html', $data);
 }
コード例 #5
0
ファイル: tugas.php プロジェクト: nicefirework/new_elearning
 function edit_pilihan($segment_3 = '', $segment_4 = '', $segment_5 = '')
 {
     $tugas_id = (int) $segment_3;
     $pertanyaan_id = (int) $segment_4;
     $pilihan_id = (int) $segment_5;
     $tugas = $this->tugas_model->retrieve($tugas_id);
     if (empty($tugas) or $tugas['type_id'] != 3) {
         exit("Tugas tidak ditemukan");
     }
     # jika sebagai pengajar, cek kepemilikan
     if (is_pengajar() and $tugas['pengajar_id'] != get_sess_data('user', 'id')) {
         exit("Tugas tidak ditemukan");
     }
     $pertanyaan = $this->tugas_model->retrieve_pertanyaan($pertanyaan_id);
     if (empty($pertanyaan)) {
         exit("Pertanyaan tidak ditemukan");
     }
     $pilihan = $this->tugas_model->retrieve_pilihan($pilihan_id, $pertanyaan['id']);
     if (empty($pilihan)) {
         exit("Pilihan tidak ditemukan");
     }
     $data['pilihan'] = $pilihan;
     $data['pertanyaan'] = $pertanyaan;
     $data['tugas'] = $tugas;
     $data['comp_js'] = get_tinymce('konten', 'advanced', array('autosave'));
     if ($this->form_validation->run('tugas/pilihan') == TRUE) {
         $post_pilihan = $this->input->post('pilihan', true);
         $post_konten = $this->input->post('konten', true);
         $this->tugas_model->update_pilihan($pilihan['id'], $pertanyaan['id'], $post_konten, $pilihan['kunci'], $post_pilihan);
         $this->session->set_flashdata('tugas', get_alert('success', 'Pilihan berhasil diperbaharui.'));
         redirect('tugas/edit_pilihan/' . $tugas['id'] . '/' . $pertanyaan['id'] . '/' . $pilihan_id);
     }
     $this->twig->display('edit-pilihan.html', $data);
 }
コード例 #6
0
ファイル: materi.php プロジェクト: Raniratna/new_elearning
 function detail($segment_3 = '', $segment_4 = '', $segment_5 = '')
 {
     $materi_id = (int) $segment_3;
     if (empty($materi_id)) {
         show_error("Materi tidak ditemukan.");
     }
     $materi = $this->materi_model->retrieve($materi_id);
     if (empty($materi) or empty($materi['publish'])) {
         show_error("Materi tidak ditemukan.");
     }
     # tambah views jika materi terfulis
     if (empty($materi['file'])) {
         $plus_views = false;
         # buat session kalo sudah baca materi yan ini
         $session_read = $this->session->userdata('read_materi');
         if (empty($session_read)) {
             $this->session->set_userdata(array('read_materi' => array($materi['id'])));
             $plus_views = true;
         } else {
             if (!in_array($materi['id'], $session_read)) {
                 $plus_views = true;
             }
         }
         if ($plus_views) {
             $this->materi_model->plus_views($materi['id']);
         }
     }
     $data['materi'] = $materi;
     switch ($segment_4) {
         case 'laporkan':
             $komentar = $this->komentar_model->retrieve((int) $segment_5);
             if (empty($komentar) or $komentar['tampil'] == 0 or $komentar['materi_id'] != $materi['id']) {
                 show_error('Komentar tidak ditemukan');
             }
             $data['komentar'] = $komentar;
             $this->form_validation->set_rules('alasan', 'Alasan', 'required|trim|xss_clean');
             if (!empty($_POST['alasan']) and $_POST['alasan'] == 'tulis') {
                 $this->form_validation->set_rules('alasan_lain', 'Tulis alasan', 'required|trim|xss_clean');
             }
             if ($this->form_validation->run() == true) {
                 $alasan = $this->input->post('alasan', true);
                 if ($alasan == 'tulis') {
                     $alasan = $this->input->post('alasan_lain', true);
                 }
                 $unix_id = uniqid() . time();
                 $field_id = 'laporkan-komentar';
                 $retrieve_field = retrieve_field($field_id);
                 if (empty($retrieve_field)) {
                     create_field($field_id, 'Laporkan Komentar', json_encode(array($unix_id => array('materi_id' => $materi['id'], 'komentar_id' => $komentar['id'], 'alasan' => $alasan, 'login_id' => get_sess_data('login', 'id'), 'tgl_lapor' => date('Y-m-d H:i:s')))));
                 } else {
                     $value_field = json_decode($retrieve_field['value'], 1);
                     # cek sudah ada belum datanya
                     $exist = false;
                     foreach ($value_field as $val) {
                         if ($val['materi_id'] == $materi['id'] and $val['login_id'] == get_sess_data('login', 'id') and $val['komentar_id'] == $komentar['id']) {
                             $exist = true;
                         }
                     }
                     if (!$exist) {
                         $value_field[$unix_id] = array('materi_id' => $materi['id'], 'komentar_id' => $komentar['id'], 'alasan' => $alasan, 'login_id' => get_sess_data('login', 'id'), 'tgl_lapor' => date('Y-m-d H:i:s'));
                         update_field($field_id, 'Laporkan Komentar', json_encode($value_field));
                     }
                 }
                 $this->session->set_flashdata('laporkan', get_alert('success', 'Laporan berhasil dikirim.'));
                 redirect('materi/detail/' . $materi['id'] . '/laporkan/' . $komentar['id']);
             }
             $this->twig->display('laporkan-komentar.html', $data);
             break;
         default:
         case 'download':
             # jika request download
             if ($segment_4 == 'download' and !empty($materi['file'])) {
                 $data_file = file_get_contents(get_path_file($materi['file']));
                 // Read the file's contents
                 $name_file = $materi['file'];
                 $this->materi_model->plus_views($materi['id']);
                 force_download($name_file, $data_file);
             }
             # post komentar
             $this->form_validation->set_rules('komentar', 'Komentar', 'required|trim|xss_clean');
             if ($this->form_validation->run() == true) {
                 $komentar_id = $this->komentar_model->create(get_sess_data('login', 'id'), $materi['id'], $tampil = 1, $this->input->post('komentar', true));
                 redirect('materi/detail/' . $materi['id'] . '/#komentar-' . $komentar_id);
             }
             $data['materi']['download_link'] = site_url('materi/detail/' . $materi['id'] . '/download');
             # ambil komentar
             $retrieve_all_komentar = $this->komentar_model->retrieve_all(20, (int) $segment_4, null, $materi['id'], 1);
             # format komentar
             foreach ($retrieve_all_komentar['results'] as $key => $val) {
                 $retrieve_all_komentar['results'][$key] = $this->format_komentar($val);
             }
             $data['materi']['komentar'] = $retrieve_all_komentar['results'];
             $data['materi']['jml_komentar'] = $retrieve_all_komentar['total_record'];
             $data['materi']['komentar_pagination'] = $this->pager->view($retrieve_all_komentar, 'materi/detail/' . $materi['id'] . '/');
             # cari tipenya
             if (empty($materi['file'])) {
                 $type = 'tertulis';
             } else {
                 $type = 'file';
                 $data['materi']['file_info'] = get_file_info(get_path_file($materi['file']));
                 $data['materi']['file_info']['mime'] = get_mime_by_extension(get_path_file($materi['file']));
             }
             $data['type'] = $type;
             $data['materi']['mapel'] = $this->mapel_model->retrieve($materi['mapel_id']);
             # cari materi kelas
             $arr_materi_kelas_id = array();
             $materi_kelas = $this->materi_model->retrieve_all_kelas($materi['id']);
             foreach ($materi_kelas as $mk) {
                 $arr_materi_kelas_id[] = $mk['kelas_id'];
                 $kelas = $this->kelas_model->retrieve($mk['kelas_id']);
                 $data['materi']['materi_kelas'][] = $kelas;
             }
             # cari pembuatnya
             if (!empty($materi['pengajar_id'])) {
                 $pengajar = $this->pengajar_model->retrieve($materi['pengajar_id']);
                 $data['materi']['pembuat'] = array('nama' => $pengajar['nama'], 'link_foto' => get_url_image_pengajar($pengajar['foto'], 'medium', $pengajar['jenis_kelamin']));
                 if (is_admin()) {
                     $data['materi']['pembuat']['link_profil'] = site_url('pengajar/detail/' . $pengajar['status_id'] . '/' . $pengajar['id']);
                 } else {
                     $data['materi']['pembuat']['link_profil'] = site_url('pengajar/detail/' . $pengajar['id']);
                 }
             }
             if (!empty($materi['siswa_id'])) {
                 $siswa = $this->siswa_model->retrieve($materi['siswa_id']);
                 $data['materi']['pembuat'] = array('nama' => $siswa['nama'], 'link_foto' => get_url_image_siswa($siswa['foto'], 'medium', $siswa['jenis_kelamin']));
                 if (is_admin()) {
                     $data['materi']['pembuat']['link_profil'] = site_url('siswa/detail/' . $siswa['status_id'] . '/' . $siswa['id']);
                 } else {
                     $data['materi']['pembuat']['link_profil'] = site_url('siswa/detail/' . $siswa['id']);
                 }
             }
             # cari materi terkait
             $retrieve_terkait_mapel = $this->materi_model->retrieve_all($no_of_records = 10, $page_no = 1, $pengajar_id = array(), $siswa_id = array(), $mapel_id = array($materi['mapel_id']), $judul = null, $konten = null, $tgl_posting = null, $publish = 1, $kelas_id = array(), $type = array(), $pagination = false);
             $data_terkait = array();
             foreach ($retrieve_terkait_mapel as $row) {
                 if (empty($data_terkait[$row['id']]) and $row['id'] != $materi['id'] and count($data_terkait) <= 20) {
                     $data_terkait[$row['id']] = $row;
                 }
             }
             $retrieve_terkait_kelas = $this->materi_model->retrieve_all($no_of_records = 10, $page_no = 1, $pengajar_id = array(), $siswa_id = array(), $mapel_id = array(), $judul = null, $konten = null, $tgl_posting = null, $publish = 1, $kelas_id = $arr_materi_kelas_id, $type = array(), $pagination = false);
             foreach ($retrieve_terkait_kelas as $row) {
                 if (empty($data_terkait[$row['id']]) and $row['id'] != $materi['id'] and count($data_terkait) <= 20) {
                     $data_terkait[$row['id']] = $row;
                 }
             }
             $data['terkait'] = $data_terkait;
             # setup componen SyntaxHighlighter
             $html_js = load_comp_js(array(base_url('assets/comp/SyntaxHighlighter/scripts/shCore.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushAppleScript.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushAS3.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushBash.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushColdFusion.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushCpp.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushCSharp.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushCss.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushDelphi.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushDiff.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushErlang.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushGroovy.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushJava.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushJavaFX.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushJScript.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushPerl.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushPhp.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushPlain.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushPowerShell.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushPython.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushRuby.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushSass.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushScala.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushSql.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushVb.js'), base_url('assets/comp/SyntaxHighlighter/scripts/shBrushXml.js'), base_url('assets/comp/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML')));
             $html_js .= '<script type="text/javascript">SyntaxHighlighter.all();</script>';
             # setup tinymce komentar
             $tiny_option = 'theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,bullist,numlist,|,link,unlink,|,sub,sup,charmap,tiny_mce_wiris_formulaEditor,|,emotions,image,media,youtubeIframe,syntaxhl,code",
             theme_advanced_buttons2 : "",
             theme_advanced_buttons3 : "",
             theme_advanced_toolbar_location : "top",
             theme_advanced_toolbar_align : "left",
             theme_advanced_statusbar_location : "bottom",
             file_browser_callback : "openKCFinder",
             theme_advanced_resizing : false,
             content_css : "' . base_url('assets/comp/tinymce/com/content.css') . '",
             convert_urls: false,
             force_br_newlines : false,
             force_p_newlines : false,';
             $html_js .= get_tinymce('komentar', 'advanced', array('pdw'), $tiny_option);
             # setup colorbox
             $html_js .= load_comp_js(array(base_url('assets/comp/colorbox/jquery.colorbox-min.js'), base_url('assets/comp/colorbox/act-materi.js')));
             $data['comp_js'] = $html_js;
             $data['comp_css'] = load_comp_css(array(base_url('assets/comp/SyntaxHighlighter/styles/shCoreEclipse.css'), base_url('assets/comp/colorbox/colorbox.css')));
             $this->twig->display('detail-materi.html', $data);
             break;
     }
 }
コード例 #7
0
ファイル: add_tour_view.php プロジェクト: vskrip/abclass
<div id="wrapper">
    <div id="content">

	<p>
		<h4>Добавление тура</h4>
	</p>

<?php 
echo get_tinymce();
?>

<form action = "<?php 
echo base_url();
?>
materials/add_tour" method="post">

	<p>Название тура
		<br>
<input type="text" name="title" value="<?php 
echo set_value('title');
?>
"><br>
<strong><?php 
echo form_error('title');
?>
</strong>
</p>

<p>Мета-описание тура<br>
<input type="text" name="description" value="<?php 
echo set_value('description');
コード例 #8
0
ファイル: admin.php プロジェクト: nicefirework/new_elearning
 function materi($act = 'list', $segment_4 = '', $segment_5 = '', $segment_6 = '', $segment_7 = '', $segment_8 = '')
 {
     $this->must_login();
     $data['web_title'] = 'Materi | Administrator';
     switch ($act) {
         case 'detail':
             $content_file = 'admin_materi/detail.html';
             $materi_id = (int) $segment_4;
             if (empty($materi_id)) {
                 $data['error'] = "Materi tidak ditemukan";
             }
             $materi = $this->materi_model->retrieve($materi_id);
             if (empty($materi) or empty($materi['publish'])) {
                 $data['error'] = "Materi tidak ditemukan";
             }
             switch ($segment_5) {
                 default:
                 case 'download':
                     # jika request download
                     if ($segment_5 == 'download' and !empty($materi['file'])) {
                         $data_file = file_get_contents(get_path_file($materi['file']));
                         // Read the file's contents
                         $name_file = $materi['file'];
                         force_download($name_file, $data_file);
                     }
                     if (!isset($data['error'])) {
                         $data['materi'] = $materi;
                         $data['materi']['download_link'] = site_url('admin/materi/detail/' . $materi['id'] . '/download');
                         # cari tipenya
                         if (empty($materi['file'])) {
                             $type = 'tertulis';
                         } else {
                             $type = 'file';
                             $data['materi']['file_info'] = get_file_info(get_path_file($materi['file']));
                             $data['materi']['file_info']['mime'] = get_mime_by_extension(get_path_file($materi['file']));
                         }
                         $data['type'] = $type;
                         $data['materi']['mapel'] = $this->mapel_model->retrieve($materi['mapel_id']);
                         # cari materi kelas
                         $materi_kelas = $this->materi_model->retrieve_all_kelas($materi['id']);
                         foreach ($materi_kelas as $mk) {
                             $kelas = $this->kelas_model->retrieve($mk['kelas_id']);
                             $data['materi']['materi_kelas'][] = $kelas;
                         }
                         # cari pembuatnya
                         if (!empty($materi['pengajar_id'])) {
                             $pengajar = $this->pengajar_model->retrieve($materi['pengajar_id']);
                             $data['materi']['pembuat'] = array('nama' => $pengajar['nama'], 'link_profil' => site_url('admin/pengajar/detail/' . $pengajar['status_id'] . '/' . $pengajar['id']), 'link_foto' => get_url_image_pengajar($pengajar['foto'], 'medium', $pengajar['jenis_kelamin']));
                         }
                         if (!empty($materi['siswa_id'])) {
                             $siswa = $this->siswa_model->retrieve($materi['siswa_id']);
                             $data['materi']['pembuat'] = array('nama' => $siswa['nama'], 'link_profil' => site_url('admin/siswa/' . $siswa['status_id'] . '/' . $siswa['id']), 'link_foto' => get_url_image_siswa($siswa['foto'], 'medium', $siswa['jenis_kelamin']));
                         }
                     } else {
                         $data['materi'] = array();
                     }
                     break;
             }
             break;
         case 'delete':
             $materi_id = (int) $segment_4;
             $uri_back = (string) $segment_5;
             if (empty($uri_back)) {
                 $uri_back = site_url('admin/materi');
             } else {
                 $uri_back = deurl_redirect($uri_back);
             }
             $materi = $this->materi_model->retrieve($materi_id);
             if (empty($materi)) {
                 redirect($uri_back);
             }
             # jika file
             if (!empty($materi['file']) and is_file(get_path_file($materi['file']))) {
                 unlink(get_path_file($materi['file']));
             }
             $this->materi_model->delete($materi['id']);
             $this->session->set_flashdata('materi', get_alert('success', 'Materi berhasil dihapus'));
             redirect($uri_back);
             break;
         case 'edit':
             $type = (string) strtolower($segment_4);
             $materi_id = (int) $segment_5;
             $uri_back = (string) $segment_6;
             if (empty($uri_back)) {
                 $uri_back = redirect('admin/materi');
             } else {
                 $uri_back = deurl_redirect($uri_back);
             }
             $data['uri_back'] = $uri_back;
             if (!in_array($type, array('file', 'tertulis'))) {
                 redirect($uri_back);
             }
             $materi = $this->materi_model->retrieve($materi_id);
             if (empty($materi)) {
                 redirect($uri_back);
             }
             # hanya ambil kelas_idnya
             $materi_kelas = $this->materi_model->retrieve_all_kelas($materi['id']);
             $materi_kelas_id = array();
             foreach ($materi_kelas as $r) {
                 $materi_kelas_id[] = $r['kelas_id'];
             }
             $content_file = 'admin_materi/edit.html';
             $data['module_title'] = anchor($uri_back, 'Materi') . ' / Edit Materi ' . $type;
             $data['type'] = $type;
             $data['materi'] = $materi;
             $data['mapel'] = $this->mapel_model->retrieve_all_mapel();
             $data['kelas'] = $this->kelas_model->retrieve_all(null, array('aktif' => 1));
             $data['materi_kelas'] = $materi_kelas_id;
             $data['comp_js'] = get_tinymce('konten');
             if ($type == 'file') {
                 $data['file_info'] = get_file_info(get_path_file($materi['file']));
                 $data['file_info']['mime'] = get_mime_by_extension(get_path_file($materi['file']));
             }
             # post action
             $success = false;
             if ($type == 'tertulis') {
                 if ($this->form_validation->run('admin/materi/edit/tertulis') == TRUE) {
                     $mapel_id = $this->input->post('mapel_id', TRUE);
                     $judul = $this->input->post('judul', TRUE);
                     $konten = $this->input->post('konten', TRUE);
                     $this->materi_model->update($materi['id'], get_sess_data('admin', 'pengajar', 'id'), null, $mapel_id, $judul, $konten, null, 1);
                     $success = true;
                 }
             } elseif ($type == 'file') {
                 $upload_success = false;
                 $is_new_file = false;
                 # jika tidak ada yang diupload, file tetap sama
                 if (empty($_FILES['userfile']['tmp_name'])) {
                     $update_file = $materi['file'];
                     $upload_success = true;
                 } else {
                     $config['upload_path'] = get_path_file();
                     $config['allowed_types'] = 'doc|zip|rar|txt|docx|xls|xlsx|pdf|tar|gz|jpg|jpeg|JPG|JPEG|png|ppt|pptx';
                     $config['max_size'] = '0';
                     $config['max_width'] = '0';
                     $config['max_height'] = '0';
                     $config['file_name'] = url_title($this->input->post('judul', TRUE) . '_' . time(), '_', TRUE);
                     $this->upload->initialize($config);
                     if ($this->upload->do_upload()) {
                         $upload_data = $this->upload->data();
                         $update_file = $upload_data['file_name'];
                         $upload_success = true;
                         $is_new_file = true;
                     } else {
                         $data['error_upload'] = '<span class="text-error">' . $this->upload->display_errors() . '</span>';
                     }
                 }
                 if ($this->form_validation->run('admin/materi/edit/file') == TRUE and $upload_success == TRUE) {
                     $mapel_id = $this->input->post('mapel_id', TRUE);
                     $judul = $this->input->post('judul', TRUE);
                     $this->materi_model->update($materi['id'], get_sess_data('admin', 'pengajar', 'id'), null, $mapel_id, $judul, null, $update_file, 1);
                     if ($is_new_file) {
                         # hapus file sebelumnya
                         if (is_file(get_path_file($materi['file']))) {
                             unlink(get_path_file($materi['file']));
                         }
                     }
                     $success = true;
                 } else {
                     if ($is_new_file == TRUE and is_file(get_path_file($update_file))) {
                         unlink(get_path_file($update_file));
                     }
                 }
             }
             if ($success) {
                 # cari kelas materi mana yang harus ditambah / dihapus
                 $kelas_id = $this->input->post('kelas_id', TRUE);
                 $kelas_post_id = array();
                 foreach ($kelas_id as $post_kelas_id) {
                     $post_kelas_id = (int) $post_kelas_id;
                     if (!empty($post_kelas_id)) {
                         $check = $this->materi_model->retrieve_kelas(null, $materi['id'], $post_kelas_id);
                         if (empty($check)) {
                             # tambahkan
                             $this->materi_model->create_kelas($materi['id'], $post_kelas_id);
                         }
                         $kelas_post_id[] = $post_kelas_id;
                     }
                 }
                 if (count($materi_kelas_id) > count($kelas_post_id)) {
                     $diff_kelas = array_diff($materi_kelas_id, $kelas_post_id);
                     foreach ($diff_kelas as $diff_kelas_id) {
                         $retrieve = $this->materi_model->retrieve_kelas(null, $materi['id'], $diff_kelas_id);
                         # hapus
                         if (!empty($retrieve)) {
                             $this->materi_model->delete_kelas($retrieve['id']);
                         }
                     }
                 }
                 $this->session->set_flashdata('materi', get_alert('success', 'Materi berhasil diperbaharui'));
                 redirect($uri_back);
             }
             break;
         case 'add':
             $type = (string) strtolower($segment_4);
             if (!in_array($type, array('file', 'tertulis'))) {
                 redirect('admin/materi');
             }
             $content_file = 'admin_materi/add.html';
             $data['module_title'] = anchor('admin/materi', 'Materi') . ' / Tambah Materi ' . $type;
             $data['type'] = $type;
             $data['mapel'] = $this->mapel_model->retrieve_all_mapel();
             $data['kelas'] = $this->kelas_model->retrieve_all(null, array('aktif' => 1));
             $data['comp_js'] = get_tinymce('konten');
             $success = false;
             if ($type == 'tertulis') {
                 if ($this->form_validation->run('admin/materi/add/tertulis') == TRUE) {
                     $mapel_id = $this->input->post('mapel_id', TRUE);
                     $judul = $this->input->post('judul', TRUE);
                     $konten = $this->input->post('konten', TRUE);
                     $materi_id = $this->materi_model->create(get_sess_data('admin', 'pengajar', 'id'), null, $mapel_id, $judul, $konten, null, 1);
                     $success = true;
                 }
             } elseif ($type == 'file') {
                 $config['upload_path'] = get_path_file();
                 $config['allowed_types'] = 'doc|zip|rar|txt|docx|xls|xlsx|pdf|tar|gz|jpg|jpeg|JPG|JPEG|png|ppt|pptx';
                 $config['max_size'] = '0';
                 $config['max_width'] = '0';
                 $config['max_height'] = '0';
                 $config['file_name'] = url_title($this->input->post('judul', TRUE) . '_' . time(), '_', TRUE);
                 $this->upload->initialize($config);
                 if ($this->form_validation->run('admin/materi/add/file') == TRUE and $this->upload->do_upload()) {
                     $mapel_id = $this->input->post('mapel_id', TRUE);
                     $judul = $this->input->post('judul', TRUE);
                     $upload_data = $this->upload->data();
                     $file = $upload_data['file_name'];
                     $materi_id = $this->materi_model->create(get_sess_data('admin', 'pengajar', 'id'), null, $mapel_id, $judul, null, $file, 1);
                     $success = true;
                 } else {
                     $upload_data = $this->upload->data();
                     if (!empty($upload_data) and is_file(get_path_file($upload_data['file_name']))) {
                         unlink(get_path_file($upload_data['file_name']));
                     }
                     $data['error_upload'] = '<span class="text-error">' . $this->upload->display_errors() . '</span>';
                 }
             }
             if ($success) {
                 # simpan kelas materi
                 $kelas_id = $this->input->post('kelas_id', TRUE);
                 foreach ($kelas_id as $materi_kelas_id) {
                     $this->materi_model->create_kelas($materi_id, $materi_kelas_id);
                 }
                 $this->session->set_flashdata('materi', get_alert('success', 'Materi berhasil ditambah'));
                 if (!empty($materi_id)) {
                     redirect('admin/materi/edit/' . $type . '/' . $materi_id);
                 } else {
                     redirect('admin/materi');
                 }
             }
             break;
         default:
         case 'list':
             $content_file = 'admin_materi/list.html';
             $data['module_title'] = 'Materi';
             $page_no = (int) $segment_4;
             if (empty($page_no)) {
                 $page_no = 1;
             }
             # jika ada post filter
             if ($this->form_validation->run('admin/materi/filter') == true) {
                 $pengajar = $this->input->post('pengajar', TRUE);
                 $siswa = $this->input->post('siswa', TRUE);
                 # cari id pengajar
                 $pengajar_id = array();
                 if (!empty($pengajar)) {
                     foreach ($this->pengajar_model->retrieve_all_by_name($pengajar) as $val) {
                         $pengajar_id[] = $val['id'];
                     }
                 }
                 # cari id siswa
                 $siswa_id = array();
                 if (!empty($siswa)) {
                     foreach ($this->siswa_model->retrieve_all_by_name($siswa) as $val) {
                         $siswa_id[] = $val['id'];
                     }
                 }
                 $filter = array('judul' => $this->input->post('judul', true), 'konten' => $this->input->post('konten', true), 'pengajar_id' => $pengajar_id, 'pengajar' => $pengajar, 'siswa_id' => $siswa_id, 'siswa' => $siswa, 'mapel_id' => $this->input->post('mapel_id', true), 'kelas_id' => $this->input->post('kelas_id', true), 'type' => $this->input->post('type', true));
                 $this->session->set_userdata('filter_materi', $filter);
             }
             $filter = $this->session->userdata('filter_materi');
             if (empty($filter)) {
                 $filter = array('judul' => '', 'konten' => '', 'pengajar_id' => array(), 'pengajar' => '', 'siswa_id' => array(), 'siswa' => '', 'mapel_id' => array(), 'kelas_id' => array(), 'type' => array());
             }
             $data['filter'] = $filter;
             # ambil semua data materi
             $retrieve_all_materi = $this->materi_model->retrieve_all(50, $page_no, $filter['pengajar_id'], $filter['siswa_id'], $filter['mapel_id'], $filter['judul'], $filter['konten'], $tgl_posting = null, $publish = 1, $filter['kelas_id'], $filter['type']);
             # format array data
             $results = array();
             foreach ($retrieve_all_materi['results'] as $key => $val) {
                 # cari pembuatnya
                 if (!empty($val['pengajar_id'])) {
                     $pengajar = $this->pengajar_model->retrieve($val['pengajar_id']);
                     $val['pembuat'] = $pengajar;
                     $val['pembuat']['link_profil'] = site_url('admin/pengajar/detail/' . $pengajar['status_id'] . '/' . $pengajar['id']);
                 }
                 if (!empty($val['siswa_id'])) {
                     $siswa = $this->siswa_model->retrieve($val['siswa_id']);
                     $val['pembuat'] = $siswa;
                     $val['pembuat']['link_profil'] = site_url('admin/siswa/detail/' . $siswa['status_id'] . '/' . $siswa['id']);
                 }
                 # cari materi kelas
                 $materi_kelas = $this->materi_model->retrieve_all_kelas($val['id']);
                 foreach ($materi_kelas as $mk) {
                     $kelas = $this->kelas_model->retrieve($mk['kelas_id']);
                     $val['materi_kelas'][] = $kelas;
                 }
                 # cari matapelajarannya
                 $val['mapel'] = $this->mapel_model->retrieve($val['mapel_id']);
                 $results[$key] = $val;
             }
             $data['materi'] = $results;
             $data['pagination'] = $this->pager->view($retrieve_all_materi, 'admin/materi/list/' . $page_no . '/');
             $data['kelas'] = $this->kelas_model->retrieve_all(null, array('aktif' => 1));
             $data['mapel'] = $this->mapel_model->retrieve_all_mapel();
             break;
     }
     $data = array_merge(default_parser_item(), $data);
     $this->twig->display($content_file, $data);
 }
コード例 #9
0
ファイル: tugas.php プロジェクト: unregister/new_elearning
 function kerjakan($tugas_id = '')
 {
     if (!is_siswa()) {
         redirect('tugas');
     }
     $tugas_id = (int) $tugas_id;
     $tugas = $this->tugas_model->retrieve($tugas_id);
     if (empty($tugas)) {
         redirect('tugas');
     }
     # cek aktif tidak dan tampil siswa tidak
     if (empty($tugas['aktif'])) {
         $this->session->set_flashdata('tugas', get_alert('warning', 'Tugas belum aktif.'));
         redirect('tugas');
     }
     if (empty($tugas['tampil_siswa'])) {
         $this->session->set_flashdata('tugas', get_alert('warning', 'Tugas belum aktif.'));
         redirect('tugas');
     }
     # cek sudah mengerjakan belum
     if (sudah_ngerjakan($tugas['id'], get_sess_data('user', 'id'))) {
         $this->session->set_flashdata('tugas', get_alert('warning', 'Anda sudah mengerjakan tugas ini.'));
         redirect('tugas');
     }
     $field_id = 'mengerjakan-' . get_sess_data('user', 'id') . '-' . $tugas['id'];
     $field_name = 'Mengerjakan Tugas';
     $mulai = date('Y-m-d H:i:s');
     $selesai = date('Y-m-d H:i:s', strtotime("+ {$tugas['durasi']} minutes", strtotime($mulai)));
     $field_value = array('mulai' => $mulai, 'selesai' => $selesai);
     # cek sudah pernah mengerjakan belum, untuk keamanan.
     # karna bisa saja dibuka 2 kali dikomputer yang berbeda
     $check_field = retrieve_field($field_id);
     if (!empty($check_field)) {
         $check_field_value = json_decode($check_field['value'], 1);
         # cek upload tidak dan sudah selesai belum dari segi waktunya
         if ($tugas['type_id'] != 1 and strtotime(date('Y-m-d H:i:s')) >= strtotime($check_field_value['selesai'])) {
             redirect('tugas/finish/' . $tugas['id'] . '/' . $check_field_value['unix_id']);
         }
     } else {
         $pertanyaan = array();
         if ($tugas['type_id'] != 1) {
             # ambil pertanyaan ditugas ini
             $pertanyaan = $this->tugas_model->retrieve_all_pertanyaan('all', 1, $tugas['id'], 'ASC');
             # jika pilihan ganda, ambil pilihannya
             if ($tugas['type_id'] == 3) {
                 foreach ($pertanyaan as $key => $val) {
                     $val['pilihan'] = $this->tugas_model->retrieve_all_pilihan($val['id']);
                     $pertanyaan[$key] = $val;
                 }
             }
             $field_value['pertanyaan'] = $pertanyaan;
             $field_value['tugas'] = $tugas;
             $field_value['unix_id'] = md5($field_id) . rand(9, 999999);
             create_field($field_id, $field_name, json_encode($field_value));
         } else {
             create_field($field_id, $field_name, json_encode(array('mulai' => $mulai, 'tugas' => $tugas, 'unix_id' => md5($field_id) . rand(9, 999999))));
         }
     }
     $check_field = retrieve_field($field_id);
     $check_field_value = json_decode($check_field['value'], 1);
     $data['data'] = $check_field_value;
     $html_js = '';
     if ($tugas['type_id'] != 1) {
         $html_js = load_comp_js(array(base_url('assets/comp/jquery.countdown/jquery.countdown.min.js'), base_url('assets/comp/jquery.countdown/script.js')));
     }
     if ($tugas['type_id'] == 2) {
         # cari id pertanyaan, untuk keperluan auto save
         $arr_pertanyaan_id = array();
         foreach ($check_field_value['pertanyaan'] as $p) {
             $arr_pertanyaan_id[] = $p['id'];
         }
         $html_js .= get_tinymce('jawaban, textarea#jawaban-' . implode(', textarea#jawaban-', $arr_pertanyaan_id), 'advanced', array('autosave'));
         $html_js .= load_comp_js(array(base_url('assets/comp/jquery/tinymce.autosave.js')));
         $data['data']['str_id'] = implode(',', $arr_pertanyaan_id);
     }
     $data['comp_js'] = $html_js;
     $this->twig->display('ujian-online.html', $data);
 }
コード例 #10
0
ファイル: welcome.php プロジェクト: pancamedia/Marlina-Sabil
 function pengaturan()
 {
     must_login();
     if (!is_admin()) {
         redirect('welcome');
     }
     if (!is_demo_app()) {
         # bagian hapus gambar
         if (!empty($_GET['delete-img'])) {
             $img_id = (int) $_GET['delete-img'];
             if ($img_id > 0 and $img_id <= 4) {
                 $key = 'img-slide-' . $img_id;
                 $retrieve = $this->config_model->retrieve($key);
                 if (!empty($retrieve) and !empty($retrieve['value'])) {
                     # hapus file
                     if (is_file(get_path_image($retrieve['value']))) {
                         unlink(get_path_image($retrieve['value']));
                     }
                     $this->config_model->update($key, $key, '');
                 }
             }
             redirect('welcome/pengaturan');
         }
         if ($this->form_validation->run('pengaturan') == true) {
             foreach ($_POST as $key => $val) {
                 # cek ada tidak, kalo ada update
                 $retrieve = $this->config_model->retrieve($key);
                 if (!empty($retrieve)) {
                     $this->config_model->update($key, $retrieve['nama'], $val);
                 } else {
                     $this->config_model->create($key, $key, $val);
                 }
             }
             # untuk upload gambar
             foreach ($_FILES as $key => $val) {
                 if (!empty($val['tmp_name'])) {
                     $config = array();
                     $config['upload_path'] = get_path_image();
                     $config['allowed_types'] = 'jpg|jpeg|png';
                     $config['max_size'] = '0';
                     $config['max_width'] = '0';
                     $config['max_height'] = '0';
                     $config['file_name'] = $key;
                     $this->upload->initialize($config);
                     if ($this->upload->do_upload($key)) {
                         # hapus file sebelumnya
                         $old_file = get_pengaturan($key, 'value');
                         if (is_file(get_path_image($old_file))) {
                             unlink(get_path_image($old_file));
                         }
                         $upload_data = $this->upload->data();
                         $retrieve = $this->config_model->retrieve($key);
                         if (!empty($retrieve)) {
                             $this->config_model->update($key, $key, $upload_data['file_name']);
                         } else {
                             $this->config_model->create($key, $key, $upload_data['file_name']);
                         }
                     }
                 }
             }
             $this->session->set_flashdata('pengaturan', get_alert('success', 'Pengaturan berhasil diperbaharui.'));
             redirect('welcome/pengaturan');
         }
     }
     $data['comp_js'] = get_tinymce('tinymce, textarea.tinymce');
     $this->twig->display('pengaturan.html', $data);
 }
コード例 #11
0
ファイル: tugas.php プロジェクト: pancamedia/Marlina-Sabil
 function kerjakan($tugas_id = '')
 {
     if (!is_siswa()) {
         redirect('tugas');
     }
     $tugas_id = (int) $tugas_id;
     $tugas = $this->tugas_model->retrieve($tugas_id);
     if (empty($tugas)) {
         redirect('tugas');
     }
     # cek aktif tidak dan tampil siswa tidak
     if (empty($tugas['aktif'])) {
         $this->session->set_flashdata('tugas', get_alert('warning', 'Tugas belum aktif.'));
         redirect('tugas');
     }
     if (empty($tugas['tampil_siswa'])) {
         $this->session->set_flashdata('tugas', get_alert('warning', 'Tugas belum aktif.'));
         redirect('tugas');
     }
     # dibuat variabel baru untuk php versi < 5.5
     $sudah_mengerjakan = sudah_ngerjakan($tugas['id'], get_sess_data('user', 'id'));
     # cek sudah mengerjakan belum
     if ($sudah_mengerjakan == true) {
         $this->session->set_flashdata('tugas', get_alert('warning', 'Anda sudah mengerjakan tugas ini.'));
         redirect('tugas');
     }
     $field_id = 'mengerjakan-' . get_sess_data('user', 'id') . '-' . $tugas['id'];
     $field_name = 'Mengerjakan Tugas';
     $mulai = date('Y-m-d H:i:s');
     $durasi = $tugas['durasi'];
     $selesai = date('Y-m-d H:i:s', strtotime("+{$durasi} minutes", strtotime($mulai)));
     $field_value = array('mulai' => $mulai, 'selesai' => $selesai, 'uri_string' => uri_string());
     # untuk keperluan check sedang ujian
     $field_value['valid_route'] = array('/tugas/kerjakan', '/tugas/finish', '/tugas/submit_essay', '/tugas/submit_upload');
     # simpan tugas dan unix_id nya
     $field_value['tugas'] = $tugas;
     $field_value['unix_id'] = md5($field_id) . rand(9, 999999);
     # cek sudah pernah mengerjakan belum, untuk keamanan.
     # karna bisa saja dibuka 2 kali dikomputer yang berbeda
     $check_field = retrieve_field($field_id);
     if (!empty($check_field)) {
         $check_field_value = json_decode($check_field['value'], 1);
         # cek upload tidak dan sudah selesai belum dari segi waktunya
         if ($tugas['type_id'] != 1 and strtotime($mulai) >= strtotime($check_field_value['selesai'])) {
             redirect('tugas/finish/' . $tugas['id'] . '/' . $check_field_value['unix_id']);
         }
     } else {
         $pertanyaan = array();
         if ($tugas['type_id'] != 1) {
             # ambil pertanyaan ditugas ini
             $pertanyaan = $this->tugas_model->retrieve_all_pertanyaan('all', 1, $tugas['id'], 'random');
             $pertanyaan_id = array();
             foreach ($pertanyaan as $key => $val) {
                 $pertanyaan_id[$key] = $val['id'];
             }
             # jika pertanyaan masih kosong
             if (empty($pertanyaan_id)) {
                 $this->session->set_flashdata('tugas', get_alert('warning', 'Pertanyaan tugas masih kosong.'));
                 redirect('tugas');
             }
             $field_value['pertanyaan_id'] = $pertanyaan_id;
         } else {
             unset($field_value['selesai']);
         }
         # simpan
         create_field($field_id, $field_name, json_encode($field_value));
     }
     $check_field = retrieve_field($field_id);
     $check_field_value = json_decode($check_field['value'], 1);
     # kondisi untuk versi tugas yang terlanjur dibuat di versi < 1.5
     if (!isset($check_field_value['pertanyaan_id']) and isset($check_field_value['pertanyaan'])) {
         $check_field_value['pertanyaan_id'] = array();
         foreach ($check_field_value['pertanyaan'] as $key => $p) {
             $check_field_value[$key] = $p['id'];
         }
         # update
         unset($check_field_value['pertanyaan']);
         update_field($field_id, $check_field['nama'], json_encode($check_field_value));
     }
     # ini untuk mendapatkan data soal lengkapnya
     if (!empty($check_field_value['pertanyaan_id'])) {
         $soal = array();
         foreach ($check_field_value['pertanyaan_id'] as $key => $p_id) {
             $pertanyaan = $this->tugas_model->retrieve_pertanyaan($p_id);
             # jika pilihan ganda ambil pilihannya
             if ($check_field_value['tugas']['type_id'] == 3) {
                 $pertanyaan['pilihan'] = $this->tugas_model->retrieve_all_pilihan($pertanyaan['id']);
             }
             $soal[$key] = $pertanyaan;
         }
         $check_field_value['pertanyaan'] = $soal;
     }
     if ($tugas['type_id'] != 1) {
         # cari sisa waktu dalam menit
         $sisa_menit = strtotime($check_field_value['selesai']) - strtotime($mulai);
         $check_field_value['sisa_menit'] = ceil($sisa_menit);
     }
     # save data
     $data['data'] = $check_field_value;
     $html_js = '';
     $html_css = '';
     if ($tugas['type_id'] != 1) {
         $html_js = load_comp_js(array(base_url('assets/comp/jcounter/js/jquery.jCounter-0.1.4.js'), base_url('assets/comp/jquery/ujian.js')));
         $html_css .= load_comp_css(array(base_url('assets/comp/jcounter/css/jquery.jCounter-iosl.css')));
     }
     if ($tugas['type_id'] == 2) {
         $html_js .= get_tinymce('jawaban, textarea#jawaban-' . implode(', textarea#jawaban-', $check_field_value['pertanyaan_id']), 'advanced', array('autosave'));
         $html_js .= load_comp_js(array(base_url('assets/comp/jquery/tinymce.autosave.js')));
         $data['data']['str_id'] = implode(',', $check_field_value['pertanyaan_id']);
     }
     $data['comp_js'] = $html_js;
     $data['comp_css'] = $html_css;
     $this->twig->display('ujian-online.html', $data);
 }
コード例 #12
0
 function edit($segment_3 = '')
 {
     # yang bisa edit pengumuman adalah pengajar / admin
     if (!is_pengajar() and !is_admin()) {
         redirect('pengumuman/index');
     }
     $id = (int) $segment_3;
     $pengumuman = $this->pengumuman_model->retrieve(array('id' => $id));
     if (empty($pengumuman)) {
         $this->session->set_flashdata('pengumuman', get_alert('warning', 'Pengumuman tidak ditemukan.'));
         redirect('pengumuman/index/1');
     }
     $allow_action = $this->get_allow_action($pengumuman);
     if (!in_array('edit', $allow_action)) {
         $this->session->set_flashdata('pengumuman', get_alert('warning', 'Akses ditolak.'));
         redirect('pengumuman/index/1');
     }
     $data['p'] = $pengumuman;
     if ($this->form_validation->run('pengumuman') == true) {
         $judul = $this->input->post('judul', true);
         $split = explode(" s/d ", $this->input->post('tgl_tampil', true));
         $tgl_tampil = $split[0];
         $tgl_tutup = $split[1];
         $konten = $this->input->post('konten', true);
         $tampil_siswa = $this->input->post('tampil_siswa', true);
         $tampil_pengajar = $this->input->post('tampil_pengajar', true);
         $this->pengumuman_model->update($pengumuman['id'], $judul, $konten, $tgl_tampil, $tgl_tutup, $tampil_siswa, $tampil_pengajar, $pengumuman['pengajar_id']);
         $this->session->set_flashdata('pengumuman', get_alert('success', 'Pengumuman berhasil diperbaharui.'));
         redirect('pengumuman/edit/' . $pengumuman['id']);
     }
     # load komponen
     $html_js = get_tinymce('konten');
     $html_js .= load_comp_js(array(base_url('assets/comp/jquery/moment.min.js'), base_url('assets/comp/daterangepicker/jquery.daterangepicker.js'), base_url('assets/comp/daterangepicker/setup.js')));
     $data['comp_js'] = $html_js;
     $data['comp_css'] = load_comp_css(array(base_url('assets/comp/daterangepicker/daterangepicker.css')));
     $this->twig->display('edit-pengumuman.html', $data);
 }