load->model('m_data'); $this->load->model('Export_model','export'); $this->load->helper(array('url','html','form')); $data['export_list'] = $this->export->exportList(); // cek session yang login, jika session status tidak sama dengan session admin_login,maka halaman akan di alihkan kembali ke halaman login. if($_SESSION['status'] == "dosen_login"){ $this->db_ = $this->load->database('skpv',TRUE); }else { $this->session->set_flashdata('flash_error', 'Silahkan Login Terlebih dahulu.'); redirect('landing','refresh'); } } //menampilkan view header, index dan footer function index(){ // $data['user'] = $this->m_data->get_data('user')->num_rows(); $data['user'] = '-'; $nidu = $_SESSION['username']; $this->db_->where('nidu', $nidu); $data['dt'] = $this->db_->get('dosen')->row_array(); $data['dosen'] = '-'; $data['matkul'] = '-'; $data['mhs'] = '-'; $data['dhmd'] = '-'; $this->load->view('dosen/v_dashboard',$data); } public function edit_profile() { if ($this->input->post()) { $uname = $this->input->post('username', true); $pw = MD5($this->input->post('old_pw')); $npw = MD5($this->input->post('new_pw')); $cpw = MD5($this->input->post('conf')); if ($npw != $cpw) { $this->session->set_flashdata('flash_error','Konfirmasi Password Salah.'); redirect('dosen/edit_profile'); } else { $where = array( 'username' => $uname, 'password' => $pw ); $this->load->model('m_login'); $cek = $this->m_login->cek_login('user', $where); if ($cek > 0) { $value = array( 'password' => $npw ); $this->db->where('id', $_SESSION['id']); $this->db->update('user', $value); $this->session->set_flashdata('flash_success','Password berhasil diperbaharui.'); redirect('dosen/edit_profile'); } else { $this->session->set_flashdata('flash_error','Password Salah.'); redirect('dosen/edit_profile'); } } } else { $this->load->view('v_profile'); } } function logout(){ $this->session->sess_destroy(); redirect(base_url().'landing'); } // ======================================== Start Fungsi Manage Nilai ================================================ function nilai(){ if($this->input->post()){ $this->load->helper('date'); $waktu = time(); $time = mdate('%Y-%m-%d %H:%i:%s', $waktu); $data = array( 'nidu_dosen' => $_SESSION['username'], 'kdmk' => $this->input->post('bobot_kdmk',true), 'bbt_kehadiran' => $this->input->post('bobot_kehadiran',true), 'bbt_tugas' => $this->input->post('bobot_tugas',true), 'bbt_quiz' => $this->input->post('bobot_quiz',true), 'bbt_uts' => $this->input->post('bobot_uts',true), 'bbt_uas' => $this->input->post('bobot_uas',true), 'created_at' => $time, 'created_by' => $_SESSION['username'] ); // cek bobot sudah masuk atau belum $where = array( 'nidu_dosen' => $_SESSION['username'], 'kdmk' => $this->input->post('bobot_kdmk',true) ); $hsl = $this->m_data->cek_where('nilai_bobot',$where); if($hsl->num_rows() == 0){ // data belum ada $this->m_data->insert_data('nilai_bobot', $data); $this->session->set_flashdata('flash_success','ditambahkan.'); }else{ // data sudah ada $this->m_data->update_data($where, $data, 'nilai_bobot'); $this->session->set_flashdata('flash_success','diperbaharui.'); } redirect('dosen/nilai'); } $this->load->view('dosen/v_nilai'); } function get_mbkm_byNidu($nidu = null){ // $univ=$this->input->get('universitas'); $nidu_=urldecode($nidu); $this->db->where('nidu', $nidu_); $this->db->order_by('nmmkind', 'asc'); $data = $this->db->get('mk_mbkm'); echo json_encode($data->result()); } function get_mhsmbkm_byKdmk($kdmk = null){ // $univ=$this->input->get('universitas'); $kdmk_=urldecode($kdmk); $this->db->where('kdmk', $kdmk_); $this->db->where('status', 'acc'); $this->db->order_by('idmhs', 'asc'); $data = $this->db->get('pengajuan_mbkm'); echo json_encode($data->result()); } function get_nilaimbkm_byKdmk($kdmk = null){ // $univ=$this->input->get('universitas'); $kdmk_=urldecode($kdmk); $this->db->where('kdmk', $kdmk_); $this->db->order_by('nama_mhs', 'asc'); $data = $this->db->get('nilai_mbkm'); echo json_encode($data->result()); } // function get_nilaimbkm_byNimKdmk($kdmk = null){ // // $univ=$this->input->get('universitas'); // $kdmk_=urldecode($kdmk); // $this->db->where('kdmk', $kdmk_); // $this->db->order_by('nama_mhs', 'asc'); // $data = $this->db->get('nilai_mbkm'); // echo json_encode($data->result()); // } function get_nilaimbkm_byNimKdmk() { $id=$this->input->get('id'); $kdmk=$this->input->get('kdmk'); $where = array( 'id' => $id, 'kdmk' => $kdmk ); $hsl=$this->m_data->cek_where('nilai_mbkm',$where); if($hsl->num_rows()>0){ foreach ($hsl->result() as $i) { $data = array( 'id' => $i->id, 'nim' => $i->nim_mhs, 'nama' => $i->nama_mhs, 'kdmk' => $i->kdmk, 'stsemester' => $i->stsemester, 'nilai_kehadiran' => $i->nilai_kehadiran, 'tugas' => $i->tugas, 'quiz' => $i->quiz, 'uts' => $i->uts, 'uas' => $i->uas, 'total_nilai' => $i->total_nilai, 'nilai_huruf' => $i->nilai_huruf, 'status' => $i->status ); } } echo json_encode($data); } function get_nilaibobot_byKdmk($kdmk = null){ // $univ=$this->input->get('universitas'); $kdmk_=urldecode($kdmk); $this->db->where('kdmk', $kdmk_); $data = $this->db->get('nilai_bobot'); echo json_encode($data->result()); } function edit_nilai($id = NULL) { $this->load->helper('date'); $waktu = time(); $time = mdate('%Y-%m-%d %H:%i:%s', $waktu); $update = array( 'nilai_kehadiran' => $this->input->post('kehadiran', true), 'tugas' => $this->input->post('tugas', true), 'quiz' => $this->input->post('quiz', true), 'uts' => $this->input->post('uts', true), 'uas' => $this->input->post('uas', true), 'total_nilai' => $this->input->post('total', true), 'nilai_huruf' => $this->input->post('nilai_huruf', true), 'updated_at' => $time ); $where = array( 'id' => $id ); // $this->db->insert('user', $insert); $this->m_data->update_data($where,$update,'nilai_mbkm'); $this->session->set_flashdata('flash_success', 'Input Nilai Sukses.'); redirect('Dosen/nilai'); } function delete_nilai($id = NULL) { $this->db->where('id', $id); $this->db->delete('nilai_mbkm'); $this->session->set_flashdata('flash_success','Data Nilai Telah.'); redirect('Dosen/nilai'); } // ======================================== End Fungsi Manage Nilai ================================================ function importFile(){ if ($this->input->post('submit')) { $path = './uploads/'; include APPPATH."/third_party/PHPExcel.php"; $config['upload_path'] = $path; $config['allowed_types'] = 'xlsx|xls|csv'; $config['remove_spaces'] = TRUE; $this->load->library('upload', $config); $this->upload->initialize($config); if (!$this->upload->do_upload('uploadFile')) { $error = array('error' => $this->upload->display_errors()); } else { $data = array('upload_data' => $this->upload->data()); } if(empty($error)){ if (!empty($data['upload_data']['file_name'])) { $import_xls_file = $data['upload_data']['file_name']; } else { $import_xls_file = 0; } $inputFileName = $path . $import_xls_file; try { $inputFileType = PHPExcel_IOFactory::identify($inputFileName); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); $flag = true; $i=0; foreach ($allDataInSheet as $value) { if($flag){ $flag =false; continue; } $this->load->helper('date'); $waktu = time(); $time = mdate('%Y-%m-%d %H:%i:%s', $waktu); $inserdata = $value['B']; $inserdata2 = $value['D']; // $inserdata[$i]['nama_mhs'] = $value['B']; // $inserdata[$i]['kdmk'] = $value['C']; // $inserdata[$i]['stsemester'] = $value['D']; // $inserdata[$i]['nilai_kehadiran'] = $value['E']; // $inserdata[$i]['tugas'] = $value['F']; // $inserdata[$i]['quiz'] = $value['G']; // $inserdata[$i]['uts'] = $value['H']; // $inserdata[$i]['uas'] = $value['I']; // $inserdata[$i]['total_nilai'] = $value['J']; // $inserdata[$i]['nilai_huruf'] = $value['K']; // $inserdata[$i]['created_at'] = $time; $value = array( 'nilai_kehadiran' => $value['F'], 'tugas' => $value['G'], 'quiz' => $value['H'], 'uts' => $value['I'], 'uas' => $value['J'], 'total_nilai' => $value['K'], 'nilai_huruf' => $value['L'], 'updated_at' => $time ); $this->db->where('nim_mhs', $inserdata); $this->db->where('kdmk', $inserdata2); $this->db->update('nilai_mbkm', $value); $i++; } $this->session->set_flashdata('flash_success','Data Nilai Telah Diupload.'); redirect('Dosen/nilai'); } catch (Exception $e) { $this->session->set_flashdata('flash_success','Data Nilai Telah Diupload.'); redirect('Dosen/nilai'); die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' .$e->getMessage()); } }else{ $this->session->set_flashdata('flash_error','Upload data gagal.'); redirect('Dosen/nilai'); } } redirect('Dosen/nilai'); } public function generateXls($kdmk = null) { include APPPATH.'third_party/PHPExcel.php'; $excel = new PHPExcel(); $excel->getProperties()->setCreator('P3TI') ->setLastModifiedBy('') ->setTitle("Data Mahasiswa") ->setSubject("Mahasiswa") ->setDescription("Laporan Semua Data Mahasiswa") ->setKeywords("Data Mahasiswa"); $style_col = array( 'font' => array('bold' => true), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER ), 'borders' => array( 'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'right' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN) ) ); $style_row = array( 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT, 'vertical' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER ), 'borders' => array( 'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'right' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN) ) ); $style_row2 = array( 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER ), 'borders' => array( 'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'right' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN) ) ); $excel->setActiveSheetIndex(0)->setCellValue('A1', "DATA MAHASISWA"); $excel->getActiveSheet()->mergeCells('A1:L1'); $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(TRUE); $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(15); $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $excel->setActiveSheetIndex(0)->setCellValue('A3', "NO"); $excel->setActiveSheetIndex(0)->setCellValue('B3', "NIM MAHASISWA"); $excel->setActiveSheetIndex(0)->setCellValue('C3', "NAMA MAHASISWA"); $excel->setActiveSheetIndex(0)->setCellValue('D3', "KODE MATAKULIAH"); $excel->setActiveSheetIndex(0)->setCellValue('E3', "STATUS SEMESTER"); $excel->setActiveSheetIndex(0)->setCellValue('F3', "NILAI KEHADIRAN"); $excel->setActiveSheetIndex(0)->setCellValue('G3', "TUGAS"); $excel->setActiveSheetIndex(0)->setCellValue('H3', "QUIZ"); $excel->setActiveSheetIndex(0)->setCellValue('I3', "UTS"); $excel->setActiveSheetIndex(0)->setCellValue('J3', "UAS"); $excel->setActiveSheetIndex(0)->setCellValue('K3', "TOTAL NILAI"); $excel->setActiveSheetIndex(0)->setCellValue('L3', "NILAI HURUF"); $excel->getActiveSheet()->getStyle('A3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('B3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('C3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('D3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('E3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('F3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('G3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('H3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('I3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('J3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('K3')->applyFromArray($style_col); $excel->getActiveSheet()->getStyle('L3')->applyFromArray($style_col); $this->db->where('kdmk', $kdmk); $siswa = $this->db->get('nilai_mbkm')->result(); ; $no = 1; $numrow = 4; foreach($siswa as $data){ $excel->setActiveSheetIndex(0)->setCellValue('A'.$numrow, $no); $excel->setActiveSheetIndex(0)->setCellValue('B'.$numrow, $data->nim_mhs); $excel->setActiveSheetIndex(0)->setCellValue('C'.$numrow, $data->nama_mhs); $excel->setActiveSheetIndex(0)->setCellValue('D'.$numrow, $data->kdmk); $excel->setActiveSheetIndex(0)->setCellValue('E'.$numrow, $data->stsemester); $excel->setActiveSheetIndex(0)->setCellValue('F'.$numrow, $data->nilai_kehadiran); $excel->setActiveSheetIndex(0)->setCellValue('G'.$numrow, $data->tugas); $excel->setActiveSheetIndex(0)->setCellValue('H'.$numrow, $data->quiz); $excel->setActiveSheetIndex(0)->setCellValue('I'.$numrow, $data->uts); $excel->setActiveSheetIndex(0)->setCellValue('J'.$numrow, $data->uas); $excel->setActiveSheetIndex(0)->setCellValue('K'.$numrow, $data->total_nilai); $excel->setActiveSheetIndex(0)->setCellValue('L'.$numrow, $data->nilai_huruf); $excel->getActiveSheet()->getStyle('A'.$numrow)->applyFromArray($style_row); $excel->getActiveSheet()->getStyle('B'.$numrow)->applyFromArray($style_row); $excel->getActiveSheet()->getStyle('C'.$numrow)->applyFromArray($style_row); $excel->getActiveSheet()->getStyle('D'.$numrow)->applyFromArray($style_row); $excel->getActiveSheet()->getStyle('E'.$numrow)->applyFromArray($style_row2); $excel->getActiveSheet()->getStyle('F'.$numrow)->applyFromArray($style_row2); $excel->getActiveSheet()->getStyle('G'.$numrow)->applyFromArray($style_row2); $excel->getActiveSheet()->getStyle('H'.$numrow)->applyFromArray($style_row2); $excel->getActiveSheet()->getStyle('I'.$numrow)->applyFromArray($style_row2); $excel->getActiveSheet()->getStyle('J'.$numrow)->applyFromArray($style_row2); $excel->getActiveSheet()->getStyle('K'.$numrow)->applyFromArray($style_row2); $excel->getActiveSheet()->getStyle('L'.$numrow)->applyFromArray($style_row2); $no++; $numrow++; } $excel->getActiveSheet()->getColumnDimension('A')->setWidth(5); $excel->getActiveSheet()->getColumnDimension('B')->setWidth(15); $excel->getActiveSheet()->getColumnDimension('C')->setWidth(25); $excel->getActiveSheet()->getColumnDimension('D')->setWidth(20); $excel->getActiveSheet()->getColumnDimension('E')->setWidth(30); $excel->getActiveSheet()->getColumnDimension('F')->setWidth(30); $excel->getActiveSheet()->getColumnDimension('G')->setWidth(30); $excel->getActiveSheet()->getColumnDimension('H')->setWidth(30); $excel->getActiveSheet()->getColumnDimension('I')->setWidth(30); $excel->getActiveSheet()->getColumnDimension('J')->setWidth(30); $excel->getActiveSheet()->getColumnDimension('K')->setWidth(30); $excel->getActiveSheet()->getColumnDimension('L')->setWidth(30); $excel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1); $excel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); $excel->getActiveSheet(0)->setTitle("Laporan Data Mahasiswa"); $excel->setActiveSheetIndex(0); $filename="datamahasiswa.xls"; $objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5'); ob_end_clean(); header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename='.$filename); $objWriter->save('php://output'); } }