Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $importType=$_POST['importType'];
- $schoolYear = $_POST['schoolYear'];
- $arrSchoolYear = explode('/',$schoolYear);
- if(((substr($_FILES[userfile][name],-3)=="csv")||(substr($_FILES[userfile][name],-3)=="xls")||(substr($_FILES[userfile][name],-4)=="xlsx"))){
- if($_FILES[userfile][tmp_name]&&$importType!=0&&$schoolYear!=""){
- //exit;
- echo "<br />";
- $objPHPExcel = PHPExcel_IOFactory::load($_FILES[userfile][tmp_name]);
- $objPHPExcel->setActiveSheetIndex(0);
- echo date('H:i:s') . " Load from Excel file\n";
- echo "<br/>Reading sheet <br />";
- echo "<br />";
- $objWorksheet = $objPHPExcel->getActiveSheet();
- $i=1;
- $no=$i-1;
- $countError=0;
- $dataSchedule = array();
- //looping bwt nampilin
- function xls2Date($date) {
- return date('Y-m-d',(((++$date > 25568) ? $date : 25569) * 86400) - ((70 * 365 + 19) * 86400));
- }
- function xls2Time($date) {
- return date('H:I:S',(((++$date > 25568) ? $date : 25569) * 86400) - ((70 * 365 + 19) * 86400));
- }
- foreach ($objWorksheet->getRowIterator() as $row) {
- $cellIterator = $row->getCellIterator();
- $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
- // even if it is not set.
- // By default, only cells
- // that are set will be
- // iterated.
- $v=$objPHPExcel->getActiveSheet()->getCell('A'.$i)->getValue();
- if($i>1){
- $id=$objPHPExcel->getActiveSheet()->getCell('A'.$i)->getValue();
- $room=$objPHPExcel->getActiveSheet()->getCell('H'.$i)->getValue();
- $day=$objPHPExcel->getActiveSheet()->getCell('B'.$i)->getValue();
- $hour=$objPHPExcel->getActiveSheet()->getCell('C'.$i)->getValue();
- $class=$objPHPExcel->getActiveSheet()->getCell('D'.$i)->getValue();
- $subject=$objPHPExcel->getActiveSheet()->getCell('E'.$i)->getValue();
- $lecturer=$objPHPExcel->getActiveSheet()->getCell('F'.$i)->getValue();
- $roomPecah = explode('-',$room);
- if(count($roomPecah)>2 && is_int($roompecah[0])){
- $roomId = str_replace(' ','',$roomPecah[0]);
- }else{
- $room = strtolower($room);
- $byRoomName = $schedule->GetRoombyRoomName($room);
- $roomId = $byRoomName[0]['ROOMID'];
- }
- // $subjectPecah = explode('-',$subject);
- // $countSP = count($subjectPecah);
- // echo $id;
- // echo "<br/>";
- // if($countSP>2){
- // $subjectId = str_replace(' ','',$subjectPecah[1]);
- // $subjectCode = str_replace(' ','',$subjectPecah[1]);
- // $subjectName = str_replace(' ','',$subjectPecah[2]);
- // $courseData = $course->GetCourseIdOutStudyProgram('',$subjectCode,$class,'1415');
- // }else{
- // $subjectCode = $subjectPecah[0];
- // $subjectName = $subjectPecah[1];
- // $courseData = $course->GetCourseIdOutStudyProgram('',$subjectCode,$class,'1415');
- // echo "haha";
- // }
- // print_r($courseData);
- // $courseData = $course->GetCourseIdOutStudyProgram('',$subject,$class,'1415');
- $subjectCode=$subject;
- $courseData = $course->GetCourseIdOutStudyProgram('',$subjectCode,$class,$arrSchoolYear[0],$arrSchoolYear[1]);
- $courseId = $courseData[0]['COURSEID'];
- $courseData[0]['SEMESTER'];
- if(($roomId=="")||($courseId=="")||($day=="")||($hour=="")||strlen($day)==1){
- echo "<div class='navailable'>";
- echo $no." ".$courseId." ".$subjectCode." ".$class." ".$studyProgram." ".$lecturer." ".$day." ".$hour." ".$room;
- echo "</div> ";
- $countError++;
- }
- else if(($roomId!="")||($hour!="")||($day!="")){
- echo "<div>";
- echo $no." ".$courseId." ".$subjectCode." ".$class." ".$studyProgram." ".$lecturer." ".$day." ".$hour." ".$room;
- echo "</div> ";
- }
- if(strlen($hour)==7 || strlen($hour)==4){
- $hour = '0'.$hour;
- }
- IF(strlen($hour)==5){
- $hour = $hour.":00";
- $hour = str_replace(".", ":", $hour);
- }
- $dataSchedule[$no]=array($courseId,$roomId,strtoupper($day),$hour,$id);
- // echo strlen($hour);
- echo "<br>";
- }
- $i++;
- $no++;
- // break;
- }
- $totalData=$no-1;
- echo "There are <font color='red'>".$countError."</font> errors in ".$totalData." data.";
- // print_r($dataCourse);
- // bwt insert/ga ($countError==0)
- if($countError==0){
- $newid = $schedule->GetNextNewScheduleId();
- if($importType==1){
- // $newid=0;
- // echo $totalData;
- for($j=1;$j<=$totalData;$j++){
- $courseIdData=$dataSchedule[$j][0];
- $roomIdData=$dataSchedule[$j][1];
- $dayData=strtoupper(trim($dataSchedule[$j][2],' '));
- $hour=$dataSchedule[$j][3];
- $schid=$dataSchedule[$j][4];
- // echo $dayData;
- // echo $hour;
- $dayHourId = $schedule->getDayHourId($dayData,$hour);
- // print_r($dayHourId);
- $dataDayHourId = $dayHourId[0]['DAYHOURID'];
- $INDONESIADAYNAME = $dayHourId[0]['INDONESIADAYNAME'];
- $userid = $_SESSION['userid'];
- $scheduleId = $courseIdData."".$schid;
- $data = array(
- 'SCHEDULESID' => $scheduleId,
- 'DAYHOURID' => $dataDayHourId,
- 'ROOMID' => $roomIdData,
- 'COURSEID' => $courseIdData,
- 'DAY' => "'".@StrToDb($INDONESIADAYNAME,'upper')."'",
- 'USERID' => "'".$userid."'",
- );
- if($courseIdData!=""){
- echo "<br>".$j.". ".$courseIdData;
- $schedule->InsertNewSchedule($data);
- }
- $rowsAff = $schedule->GetAffectedRows();
- if($rowsAff>0){
- $msg = @GetMessage(@GetLang('new_schedule_successfully_added','ucfirst'),"success");
- }
- else{
- $msg = @GetMessage(@GetLang('new_schedule_successfully_to_be_added','ucfirst'),"failed");
- }
- // break;
- }
- echo $msg;
- }else if($importType==2){
- for($j=1;$j<=$totalData;$j++){
- $courseIdData=$dataSchedule[$j][0];
- $roomIdData=$dataSchedule[$j][1];
- $dayData=strtoupper(trim($dataSchedule[$j][2],' '));
- $hour=$dataSchedule[$j][3];
- $schid=$dataSchedule[$j][4];
- $dayHourId = $schedule->getDayHourId($dayData,$hour);
- $dataDayHourId = $dayHourId[0]['DAYHOURID'];
- $INDONESIADAYNAME = $dayHourId[0]['INDONESIADAYNAME'];
- // echo $courseIdData."<br/>";
- $schedule->DeleteNewScheduleByImport($courseIdData);
- $userid = $_SESSION['userid'];
- $data = array(
- 'SCHEDULESID' => $courseIdData."".$schid,
- 'DAYHOURID' => $dataDayHourId,
- 'ROOMID' => $roomIdData,
- 'COURSEID' => $courseIdData,
- 'DAY' => "'".@StrToDb($INDONESIADAYNAME,'upper')."'",
- 'USERID' => "'".$userid."'",
- );
- $schedule->InsertNewSchedule($data);
- $rowsAff = $schedule->GetAffectedRows();
- if($rowsAff>0){
- $msg = @GetMessage(@GetLang('new_schedule_successfully_added','ucfirst'),"success");
- }
- else{
- $msg = @GetMessage(@GetLang('new_schedule_successfully_to_be_added','ucfirst'),"failed");
- }
- }
- }
- }
- else{
- $msg = @GetMessage(@GetLang('new_schedule_failed_to_be_added','ucfirst'),"failed");
- }
- } else {
- $msg=@GetMessage(@GetLang('please_choose_import_type','ucfirst'),"failed");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement