alert("Sorry You Don\'t Have The Permission.")'; header('Location: index.php') ; exit ; } $active_sub_menu = 'hr-attendance' ; $active_menu = 'hr-staff-attendance' ; $staff_all = [] ; $mysqli_staff = $mysqli->query("SELECT staff_idno, staff_id FROM staff WHERE deleted_at IS NULL") ; if ( $mysqli_staff->num_rows > 0 ){ while($row_staff = $mysqli_staff->fetch_array(MYSQLI_ASSOC)){ $staff_all[$row_staff['staff_idno']] = $row_staff['staff_id'] ; } } if(isset($_FILES['import-excel']['name'])){ include 'PhpExcel/PHPExcel.php' ; $file_name = $_FILES['import-excel']['name']; $ext = pathinfo($file_name, PATHINFO_EXTENSION); //Checking the file extension if($ext == "xlsx"){ $file_name = $_FILES['import-excel']['tmp_name']; $inputFileName = $file_name; /**********************PHPExcel Script to Read Excel File**********************/ // Read your Excel workbook try { $inputFileType = PHPExcel_IOFactory::identify($inputFileName); //Identify the file $objReader = PHPExcel_IOFactory::createReader($inputFileType); //Creating the reader $objPHPExcel = $objReader->load($inputFileName); //Loading the file } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); header("location: hr-staff.php?page_mode=staff-attendance&result=error&msg=".urlencode($e->getMessage())); exit; } // ################################################################################## // Setting excel // ################################################################################## $sheet1 = $objPHPExcel->getSheet(0); //Selecting sheet 0 $highestRow1 = $sheet1->getHighestRow(); //Getting number of rows $highestColumn1 = $sheet1->getHighestColumn(); //Getting number of columns // Loop through each row of the worksheet in turn -> $row is for starting point for ( $row = 2; $row <= $highestRow1; $row++ ) { // Read a row of data into an array $rowData = $sheet1->rangeToArray('A' . $row . ':' . $highestColumn1 . $row, NULL, TRUE, FALSE); $rowData2[] = $rowData[0] ; } if( isset($rowData2) ){ $setting_point = $mysqli->query( "SELECT point_id, point_type FROM setting_point WHERE deleted_at IS NULL AND point_from = 'adjustment' AND point_type IN ( 'plus', 'minus' ) AND difficulty = 'normal'" ) ; if ( $setting_point->num_rows > 0 ){ $setting_point_list = [] ; while ( $row_setting_point = $setting_point->fetch_assoc() ){ $setting_point_list[$row_setting_point['point_type']] = $row_setting_point['point_id'] ; } foreach ( $rowData2 as $rowData2data ){ $staff_idno = $rowData2data['0'] ; $staff_id = $staff_all[$staff_idno] ; $point_amount = $rowData2data['1'] ; $point_type = ( $point_amount > 0 ? 'plus' : ( $point_amount < 0 ? 'minus' : '' ) ) ; $remark = $rowData2data['2'] ; if ( $staff_idno != '' && $staff_id != '' && ( $point_type == 'plus' || $point_type == 'minus' ) && ( $point_amount < 0 || $point_amount > 0 ) ){ pointMovement( 'adjustment', $setting_point_list[$point_type], $point_type, 'normal', $staff_id, $point_amount, $remark ) ; pushToUserCron( 'staff_adjustment', $setting_point_list[$point_type], $staff_id, 'Point Adjustment', $remark ) ; } } } }else{ header( "Location: ?result=error&msg=Failed to Import" ) ; exit; } header( "Location: ?result=success&msg=Import Successful" ) ; exit; } } $result = $_GET['result']; $msg = $_GET['msg']; if ($result == 'error') { $display_error = '