Last active
September 17, 2024 16:33
-
-
Save neno-tech/4262ff111044b47b815fe6f5f61b41bb to your computer and use it in GitHub Desktop.
เช็คอินอัพเดตล่าสุด
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ABSENSI GOOGLE SCRIPT | |
* *********************************************************************************** | |
* Code by : fahroni|ganteng | |
* contact me : [email protected] | |
* Date : Mar 2021 | |
* License : MIT | |
* | |
*/ | |
//spreadsheet url | |
var database = "xxx";//แก้1 | |
function doGet(){ | |
return HtmlService | |
.createTemplateFromFile('index') | |
.evaluate() | |
.setSandboxMode(HtmlService.SandboxMode.NATIVE) | |
.addMetaTag('viewport', 'width=device-width, initial-scale=1'); | |
} | |
function submitAbsensi(data){ | |
// Buka Spreadsheet | |
let ss = SpreadsheetApp.openByUrl(database); | |
let ws = ss.getSheetByName('รายชื่อ');//แก้2 | |
let list = ws.getRange(2,1,ws.getRange("A2").getDataRegion().getLastRow() - 1, 5).getValues(); | |
let userId = list.map(function(r){ return r[1].toString(); }); | |
let pass = list.map(function(r){ return r[3].toString(); }); | |
// Verifikasi data yang dikirim | |
data.idPegawai = data['idPegawai'] !== undefined?data.idPegawai.toString():''; | |
data.password = data['password'] !== undefined?data.password.toString():''; | |
data.position = data['position'] !== undefined?data.position:[0,0]; | |
// Verifikasi user dan password | |
let indexData = userId.indexOf(data.idPegawai); | |
if(indexData > -1 && pass[indexData] == data.password){ | |
let nama = list.map(function(r){ return r[2]}); | |
// Get Alamat dari koordinat | |
let koordinat = data.position[0] +', '+ data.position[1]; | |
let response = Maps.newGeocoder().reverseGeocode(data.position[0], data.position[1]); | |
let lokasi = response.results[0].formatted_address; | |
//buka sheet absensi dan simpan data | |
ws = ss.getSheetByName("ข้อมูลการเช็คอิน");//แก้3 | |
ws.appendRow([data.idPegawai, nama[indexData], new Date(),koordinat, lokasi]); | |
return nama[indexData]; | |
} | |
else | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
ABSENSI GOOGLE SCRIPT | |
----------------------------------------------------- | |
Code by : fahroni|ganteng | |
contact me : [email protected] | |
Date : Mar 2021 | |
License : MIT | |
--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | |
</head> | |
<body class="bg-light"> | |
<div class="container"> | |
<div class="py-5 text-center"> | |
<img class="d-block mx-auto mb-4" src="https://drive.google.com/uc?id=[id-gambar]" alt="" width="150" > | |
<h2>ระบบเช็คอิน</h2> | |
</div> | |
<form class="row" onsubmit="submitAbsensi();return false;"> | |
<div class="col-md-12"> | |
<h4 class="mb-3">แบบฟอร์มลงชื่อเช็คอิน</h4> | |
<div class="mb-3"> | |
<label for="idPegawai">เลขประชาชน</label> | |
<input type="text" class="form-control" id="idPegawai" placeholder="เลขประชาชน 13 หลัก" required> | |
</div> | |
<div class="mb-3"> | |
<label for="password">วันเดือนปีเกิด</label> | |
<input type="password" class="form-control" id="password" placeholder="01122560" required> | |
</div> | |
<hr class="mb-4"> | |
<div class="alert alert-success" role="alert" style="display:none"></div> | |
<div class="alert alert-warning" role="alert" style="display:none"> | |
<h5>Perhatian!</h5> | |
<p>Anda harus mengijinkan akses lokasi pada browser agar bisa melakukan absensi</p> | |
</div> | |
<div class="alert alert-danger" role="alert" style="display:none"> | |
<h5>Gagal!</h5> | |
<p>Anda tidak terdaftar</p> | |
</div> | |
<button class="btn btn-primary btn-lg btn-block" type="submit">เช็คอิน</button> | |
</div> | |
</form> | |
<footer class="my-5 pt-5 text-muted text-center text-small"> | |
<p class="mb-1">© 2021 ครูอภิวัฒน์"สอนสร้างสื่อ"</p> | |
</footer> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
<script> | |
function submitAbsensi(){ | |
$('.alert-warning').show(); | |
if (navigator.geolocation) | |
navigator.geolocation.getCurrentPosition(simpanDataAbsensi); | |
} | |
function simpanDataAbsensi(position) { | |
$('.alert').hide(); | |
$('.btn').attr('disabled',true).html('รอสักครู่...'); | |
let data = { | |
idPegawai : $('#idPegawai').val(), | |
password : $('#password').val(), | |
position : [ | |
position.coords.latitude, | |
position.coords.longitude | |
] | |
}; | |
//console.log(data); | |
google.script.run.withSuccessHandler(callbackAbsensi).submitAbsensi(data); | |
} | |
function callbackAbsensi(msg){ | |
if(msg){ | |
$('.alert-success').html('<h5>สวัสดีคุณ '+msg+'!</h5><p>ระบบได้บันทึกการเช็คอินของคุณเรียบร้อยแล้ว</p>').show(); | |
$('.form-control').val(''); | |
} | |
else { | |
$('.alert-danger').show(); | |
$('#password').val(''); | |
} | |
$('.btn').removeAttr('disabled').html('เช็คอิน'); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment