load->library('session');
$this->load->library('rhlib');
$this->load->helper(array("form","url"));
$this->load->database();
set_time_limit(0);
ini_set('memory_limit', '2000M');
}
function index(){
$this->load->view("import/import.php");
}
public function doImport(){
if (isset($_REQUEST["cmdimport"])){
if ($_FILES["file"]){
//require 'phpexcel_1.7.8/Classes/PHPExcel.php';
require_once 'phpexcel/Classes/PHPExcel/IOFactory.php';
//$data->read($_FILES['file']['tmp_name']);
$FILE_NAME= $_FILES['file']['tmp_name'];
$FILE_TYPE= $_FILES['file']['type'];
$inputFileName=$FILE_NAME;
$inputFileType=$FILE_TYPE;
try
{
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch (Exception $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME)
. '": ' . $e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
// Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++) {
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL, TRUE, FALSE);
foreach($rowData[0] as $k=>$v){
//echo "Row: ".$row."- Col: ".($k+1)." = ".$v."
";
if ($row==1)
{
switch (strtoupper(trim($v)))
{
case "SEMESTER": $COL_INDEX_1=($k+1);break;
case "KODE PRODI":$COL_INDEX_2=($k+1);break;
case "NPM":$COL_INDEX_3=($k+1);break;
case "KODE MATA KULIAH":$COL_INDEX_4=($k+1);break;
case "NIDU":$COL_INDEX_5=($k+1);break;
case "NILAI HURUF":$COL_INDEX_6=($k+1);break;
case "BOBOT NILAI":$COL_INDEX_7=($k+1);break;
case "KELAS":$COL_INDEX_8=($k+1);break;
default:break;
}
}else{
switch ($k+1)
{
case $COL_INDEX_1:$SEMESTER=$v;break;
case $COL_INDEX_2:$KDPRODI=$v;break;
case $COL_INDEX_3:$NPM=$v;break;
case $COL_INDEX_4:$KDMK=$v;break;
case $COL_INDEX_5:$NIDU=$v;break;
case $COL_INDEX_6:$NILAIHURUF=$v;break;
case $COL_INDEX_7:$BOBOTNILAI=$v;break;
case $COL_INDEX_8:$KELAS=$v;break;
}
}
}
//Insert Data;
if ($row>1)
{
switch (strtoupper(trim($NILAIHURUF))) {
case 'A':$BOBOTNILAI=4;break;
case 'B':$BOBOTNILAI=3;break;
case 'C':$BOBOTNILAI=2;break;
case 'D':$BOBOTNILAI=1;break;
default:$BOBOTNILAI=0; break;
}
$NIDU=trim($NIDU)==""?"NULL":"'$NIDU'";
if (trim($NPM)!=""){
$query="SELECT * FROM nilai ";
$query.=" WHERE ltrim(rtrim(nim))='".($NPM)."'";
$query.=" AND ltrim(rtrim(kdprodi))='".($KDPRODI)."'";
$query.=" AND ltrim(rtrim(KDSTSEMESTER))='".($SEMESTER)."'";
$query.=" AND ltrim(rtrim(KDMK))='".($KDMK)."'";
$rs_peg=$this->db->query($query);
if ($rs_peg->num_rows()==0){
$query="INSERT INTO NILAI(kdstsemester,kdprodi,nim,kdmk,nidu,nilaihuruf,bobotnilai)";
$query.=" VALUES('".$SEMESTER."','".$KDPRODI."','".$NPM."','".$KDMK."',".$NIDU.",'".$NILAIHURUF."','".$BOBOTNILAI."')";
$this->db->query($query) or die("Err : ".$query);
}
}
echo $query."
";
}
}
redirect('akademik/import','refresh');
//Cari Data di Pegawai
/*$query="SELECT * FROM nilai ";
$query.=" WHERE ltrim(rtrim(nim))='".($NPM)."'";
$query.=" AND ltrim(rtrim(kdprodi))='".($KODE_PRODI)."'";
$query.=" AND ltrim(rtrim(KDSTSEMESTER))='".($SEMESTER)."'";
$query.=" AND ltrim(rtrim(KDMK))='".($KDMK)."'";
$rs_peg=$this->db->query($query);
if ($rs_peg->num_rows()==0)
{
//masukan ke log import data tidak diketemukan dilocal
{
$query="INSERT INTO NILAI(kdstsemester,kdprodi,nim,kdmk,nidu,klsparalel,nilaihuruf,bobotnilai)";
$query=" VALUES('".$SEMESTER."','".$KODE_PRODI."'".$NPM."'"
/*$id=$FILE_NAME."#".date("d-m-Y h:m:s");
$query="DELETE FROM tlog_import ";
$query.=" WHERE id_log='".$id."'";
$conn->Execute($query) or die($query);
$desc="NIP : ".$NIP_BARU. " tidak diketemukan di local database!\n";
$desc.=" import nip tersebut gagal update database local!";
$query="INSERT INTO tlog_import(id_log,file_name,description,created_date) ";
$query.=" VALUES('".$id."','".$FILE_NAME."','".InsertText($desc)."','".date("Y-m-d h:m:s")."')";
$conn->Execute($query) or die($query);*/
}
}
//else
/*{
$query="";
$msg="imported done!";
echo $msg;
}*/
//echo $first .",". $middle.",". $last.",". $email."
";
//redirect('akademik/import','refresh');
}
}