<?php
function cekLama($date) {
$inputDate = strtotime($date);
$currentDate = strtotime(date('Y-m-d'));
$yesterday = strtotime('-1 day', $currentDate);
$status=0;
if ($inputDate < $yesterday) {
$status=0;
//return "Tanggal tersebut adalah tanggal lampau.";
} elseif ($inputDate == $yesterday) {
//return "Tanggal tersebut adalah tanggal kemarin.";
$status=0;
} else {
$status=1;
//return "Tanggal tersebut belum tiba atau adalah hari ini.";
}
return $status;
}
function is24HoursPassed($bookingDate) {
// Convert the booking date to a timestamp
$bookingTimestamp = strtotime($bookingDate);
// Get the current timestamp
$currentTimestamp = time();
// Calculate the difference in seconds
$differenceInSeconds = $currentTimestamp - $bookingTimestamp;
// Check if the difference is greater than or equal to 24 hours (86400 seconds)
if ($differenceInSeconds >= 86400) {
return 1;
} else {
return 0;
}
}
function cekLink($img,$id_konfirmasi){
$link="<a href='$img' target='_blank'>
<img src='ypathfile/pg.png' width='40' height='40' title='Payment Gateway'>
</a>";
if(strlen($img)<50){
$link="<a href='#' onclick='buka(\"konfirmasi/zoom.php?id=$id_konfirmasi\")'>
<img src='ypathfile/$img' width='40' height='40' /></a>";
}
return $link;
}
+++++++++++++++++++++
function kirimWA($HP,$PESAN){
echo "$HP,$PESAN";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.fonnte.com/send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array(
'target' => $HP,
'message' => $PESAN,
'countryCode' => '62', //optional
),
CURLOPT_HTTPHEADER => array(
'Authorization: NzTx3456788Hi'
),
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
}
curl_close($curl);
if (isset($error_msg)) {
echo $error_msg;
}
echo $response;
}
function sentWA($conn, $id_pinjam, $id_anggota, $telepon, $pesan, $keterangan){
date_default_timezone_set("Asia/Jakarta");
$tanggal = date("Y-m-d");
$jam = date("H:i:s");
$sql = "INSERT INTO `tb_wa` (`idw`, `tanggal`, `jam`, `id_pinjam`,`id_anggota`, `telepon`, `pesan`, `keterangan`) VALUES ('', '$tanggal', '$jam', '$id_pinjam','$id_anggota', '$telepon', '$pesan', '$keterangan')";
$s = false;
$conn->autocommit(FALSE);
try {
$rs = $conn->query($sql);
if ($rs) {
$conn->commit();
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
$s = true;
}
} catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
$conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}
function RP($rupiah){
return number_format($rupiah, "2", ",", ".");
}
function getR($digits) {
$temp = "";
for ($i = 0; $i < $digits; $i++) {
$temp .= rand(0, 9);
}
return (int)$temp;
}
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$gab="";
for ($i = 0; $i < 8; $i++) {//8 karakter
$n = rand(0, count($alphabet)-1);
// $pass[$i] = $alphabet[$n];
$gab.= $alphabet[$n];;
}
return $gab;
}
function saveWA($conn,$id_pinjam,$id_anggota,$telepon,$pesan){
date_default_timezone_set("Asia/Jakarta");
$tanggal=date("Y-m-d");
$jam=date("H:i:s");
$sql="INSERT INTO `tb_wa` ( `tanggal`, `jam`, `id_pinjam`, `id_anggota`, `telepon`, `pesan`, `keterangan`) VALUES ('$tanggal', '$jam', '$id_pinjam', '$id_anggota', '$telepon', '$pesan', '')";
$pro=process($conn,$sql);
$reply = ["message" => "$pesan",];
kirimWA($telepon,$pesan);
return $pro;
}
function terbilang($i){
$huruf = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas");
if ($i < 12) return " " . $huruf[$i];
elseif ($i < 20) return terbilang($i - 10) . " Belas";
elseif ($i < 100) return terbilang($i / 10) . " Puluh" . terbilang($i % 10);
elseif ($i < 200) return " Seratus" . terbilang($i - 100);
elseif ($i < 1000) return terbilang($i / 100) . " Ratus" . terbilang($i % 100);
elseif ($i < 2000) return " Seribu" . terbilang($i - 1000);
elseif ($i < 1000000) return terbilang($i / 1000) . " Ribu" . terbilang($i % 1000);
elseif ($i < 1000000000) return terbilang($i / 1000000) . " Juta" . terbilang($i % 1000000);
}
function BAL($tanggal){
$arr=explode(" ",$tanggal);
if($arr[1]=="Januari"||$arr[1]=="January"){$bul="01";}
else if($arr[1]=="Februari"||$arr[1]=="February"){$bul="02";}
else if($arr[1]=="Maret"||$arr[1]=="March"){$bul="03";}
else if($arr[1]=="April"){$bul="04";}
else if($arr[1]=="Mei"||$arr[1]=="May"){$bul="05";}
else if($arr[1]=="Juni"||$arr[1]=="June"){$bul="06";}
else if($arr[1]=="Juli"||$arr[1]=="July"){$bul="07";}
else if($arr[1]=="Agustus"||$arr[1]=="August"){$bul="08";}
else if($arr[1]=="September"){$bul="09";}
else if($arr[1]=="Oktober"||$arr[1]=="October"){$bul="10";}
else if($arr[1]=="November"){$bul="11";}
else if($arr[1]=="Nopember"){$bul="11";}
else if($arr[1]=="Desember"||$arr[1]=="December"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
function BALP($tanggal){
$arr=explode(" ",$tanggal);
if($arr[1]=="Jan"){$bul="01";}
else if($arr[1]=="Feb"){$bul="02";}
else if($arr[1]=="Mar"){$bul="03";}
else if($arr[1]=="Apr"){$bul="04";}
else if($arr[1]=="Mei"){$bul="05";}
else if($arr[1]=="Jun"){$bul="06";}
else if($arr[1]=="Jul"){$bul="07";}
else if($arr[1]=="Agu"){$bul="08";}
else if($arr[1]=="Sep"){$bul="09";}
else if($arr[1]=="Okt"){$bul="10";}
else if($arr[1]=="Nov"){$bul="11";}
else if($arr[1]=="Nop"){$bul="11";}
else if($arr[1]=="Des"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
function WKT($sekarang)
{
if ($sekarang == "0000-00-00") {
$sekarang = date("Y-m-d");
}
$tanggal = substr($sekarang, 8, 2) + 0;
$bulan = substr($sekarang, 5, 2);
$tahun = substr($sekarang, 0, 4);
$judul_bln = array(1 => "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
$wk = $tanggal . " " . $judul_bln[(int)$bulan] . " " . $tahun;
return $wk;
}
function WKTP($sekarang)
{
$tanggal = substr($sekarang, 8, 2) + 0;
$bulan = substr($sekarang, 5, 2);
$tahun = substr($sekarang, 2, 2);
$judul_bln = array(1 => "Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des");
$wk = $tanggal . " " . $judul_bln[(int)$bulan] . "'" . $tahun;
return $wk;
}
function saveLog($conn,$id_pengunjung,$nama_pengunjung,$level,$catatan){
date_default_timezone_set("Asia/Jakarta");
$jam=date("H:i:s");
$tanggal = date("Y-m-d");
$sql="INSERT INTO `tb_bukutamu` (`id_bukutamu`, `id_pengunjung`, `nama_pengunjung`, `level`, `catatan`, `tanggal`, `jam`)
VALUES ('', '$id_pengunjung', '$nama_pengunjung', '$level', '$catatan', '$tanggal', '$jam')";
process($conn, $sql);
return 1;
}
function process($conn, $sql)
{
$s = false;
$conn->autocommit(FALSE);
try {
$rs = $conn->query($sql);
if ($rs) {
$conn->commit();
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
$s = true;
}
} catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
$conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}
function getJum($conn, $sql)
{
$rs = $conn->query($sql);
$jum = $rs->num_rows;
$rs->free();
return $jum;
}
function getField($conn, $sql)
{
$rs = $conn->query($sql);
$rs->data_seek(0);
$d = $rs->fetch_assoc();
$rs->free();
return $d;
}
function getData($conn, $sql)
{
$rs = $conn->query($sql);
$rs->data_seek(0);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
//foreach($arr as $row) {
// echo $row['nama_kelas'] . '*<br>';
//}
$rs->free();
return $arr;
}
function getBukuZ($conn, $kode)
{
//error_reporting(0);
$field = "judul";
$sql = "SELECT `$field` FROM `tb_buku` where `id_buku`='$kode'";
$rs = $conn->query($sql);
$rs->data_seek(0);
$row = $rs->fetch_assoc();
$rs->free();
return $row[$field];
}
function getAnggota($conn, $kode)
{
//error_reporting(0);
$field = "nama_anggota";
$sql = "SELECT `$field` FROM `tb_anggota` where `id_anggota`='$kode'";
$rs = $conn->query($sql);
$rs->data_seek(0);
$row = $rs->fetch_assoc();
$rs->free();
return $row[$field];
}
function getAdmin($conn, $kode)
{
//error_reporting(0);
$field = "nama_admin";
$sql = "SELECT `$field` FROM `tb_admin` where `id_admin`='$kode'";
$rs = $conn->query($sql);
$rs->data_seek(0);
$row = $rs->fetch_assoc();
$rs->free();
return $row[$field];
}
function getKategori($conn, $kode){
//error_reporting(0);
$field = "kategori";
$sql = "SELECT `$field` FROM `tb_kategori` where `id_kategori`='$kode'";
$rs = $conn->query($sql);
$rs->data_seek(0);
$row = $rs->fetch_assoc();
$rs->free();
return $row[$field];
}
function getBuku($conn, $kode){
//error_reporting(0);
$field = "judul";
$sql = "SELECT `$field` FROM `tb_buku` where `id_buku`='$kode'";
$rs = $conn->query($sql);
$rs->data_seek(0);
$row = $rs->fetch_assoc();
$rs->free();
return $row[$field];
}
function getListB($conn, $kode){
//error_reporting(0);
$sql="select `id_buku` from `tb_detail` where `id_pinjam`='$kode' order by `idd` asc";
$jum=getJum($conn,$sql);
$gab="";
if($jum > 0){
$arr=getData($conn,$sql);
foreach($arr as $d) {
$id_buku=$d["id_buku"];
$buku=getBuku($conn,$id_buku);
$gab.="$buku ($id_buku), ";
}
$gab.=" $jum buku";
}
else{$gab="Belum melakukan peminjaman buku...";}
return $gab;
}
function getListB2($conn, $kode){
// error_reporting(0);
$sql="select `id_buku` from `tb_detail` where `id_pinjam`='$kode' order by `idd` asc";
$jum=getJum($conn,$sql);
$gab="<ol>";
if($jum > 0){
$arr=getData($conn,$sql);
foreach($arr as $d) {
$id_buku=$d["id_buku"];
$buku=getBuku($conn,$id_buku);
$gab.="<li>$buku ($id_buku)</li>";
}
$gab.="</ol>$jum buku";
}
else{$gab="Belum melakukan peminjaman buku...";}
return $gab;
}
function getCek($conn, $id_anggota){
$sql = "SELECT `tb_detail`.`idd` FROM `tb_pinjam`,`tb_detail` where `tb_pinjam`.id_pinjam=`tb_detail`.id_pinjam and tb_pinjam.`id_anggota`='$id_anggota' and (`tb_detail`.status_detail='Pinjam' or `tb_detail`.status_detail='Pesan')";
$jum=getJum($conn,$sql)+0;
return $jum;
}
function upBuku($conn, $id_buku){
$sql="select `stok` from `tb_buku` where `id_buku`='$id_buku'";
$jum=getJum($conn,$sql);
if($jum > 0){
$d=getField($conn,$sql);
$stok=$d["stok"]+0;
if($stok<1){
$sql = "Update `tb_buku` set status='Tidak Tersedia' where id_buku='$id_buku'";
$pro=process($conn,$sql);
}
else{
$sql = "Update `tb_buku` set status='Tersedia' where id_buku='$id_buku'";
$pro=process($conn,$sql);
}
}
return 1;
}
?>