0, 'message' => $msg)); exit(); } } function getHari($date) { $timestamp = strtotime($date); $day = date('D', $timestamp); $hari = '-'; switch ($day) { case 0: $hari = 'Minggu'; break; case 1: $hari = 'Senin'; break; case 2: $hari = 'Selasa'; break; case 3: $hari = 'Rabu'; break; case 4: $hari = 'Kamis'; break; case 5: $hari = 'Jumat'; break; case 6: $hari = 'Sabtu'; break; } return $hari; } function convertHaritoInt($hari) { $intHari = 0; switch ($hari) { case 'Senin': $intHari = 1; break; case 'Selasa': $intHari = 2; break; case 'Rabu': $intHari = 3; break; case 'Kamis': $intHari = 4; break; case 'Jumat': $intHari = 5; break; case 'Sabtu': $intHari = 6; break; case 'Minggu': $intHari = 0; break; } return $intHari; } function createToken($id) { $x = base64_encode($id); $time = base64_encode(time()); //php7 keatas $token = $x.bin2hex(random_bytes(64)).$time; //dibawah php 7 //$token = $x.bin2hex(openssl_random_pseudo_bytes(64)).$time; return $token; } function getUnauthorizedMessage() { return json_encode( array( 'status' => '0', 'msg' => 'Unauthorized', ) ); } function jsonResponse($payload, $statusCode = 200) { http_response_code($statusCode); echo json_encode($payload); exit(); } function getRequestJson() { static $decoded = null; static $loaded = false; if ($loaded) { return $decoded; } $loaded = true; $raw = file_get_contents('php://input'); if ($raw === false || trim($raw) === '') { $decoded = []; return $decoded; } $decoded = json_decode($raw, true); if (!is_array($decoded)) { $decoded = []; } return $decoded; } function getRequestValue($key, $default = null) { if (isset($_POST[$key])) { return $_POST[$key]; } if (isset($_GET[$key])) { return $_GET[$key]; } $json = getRequestJson(); if (isset($json[$key])) { return $json[$key]; } return $default; } function requireRobotSecret() { $server = new Server(); $expectedSecret = $server->getSecretKeyRobot(); $providedSecret = getRequestValue('secret'); if ($providedSecret === null || $providedSecret === '') { $headerKey = isset($_SERVER['HTTP_X_API_KEY']) ? trim((string) $_SERVER['HTTP_X_API_KEY']) : ''; if ($headerKey !== '') { $providedSecret = $headerKey; } } if (!is_string($providedSecret) || trim($providedSecret) !== $expectedSecret) { jsonResponse([ 'status' => 0, 'msg' => 'Unauthorized', ], 401); } } function requireSessionRole($role) { if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); } $key = 'login-'.$role; if (!isset($_SESSION[$key]) || !is_array($_SESSION[$key])) { jsonResponse([ 'status' => false, 'msg' => 'Forbidden', ], 403); } return $_SESSION[$key]; } function getDataNotFoundMessage() { return json_encode( array( 'status' => '0', 'msg' => 'Data Not Found', ) ); } function getDataEmptyMessage() { return json_encode( array( 'status' => '0', 'msg' => 'Data cannot be empty', ) ); } function getHariText($hari) { $hariText = '-'; switch ($hari) { case '0': $hariText = 'Minggu'; break; case '1': $hariText = 'Senin'; break; case '2': $hariText = 'Selasa'; break; case '3': $hariText = 'Rabu'; break; case '4': $hariText = 'Kamis'; break; case '5': $hariText = 'Jumat'; break; case '6': $hariText = 'Sabtu'; break; } return $hariText; } function cwUpload($field_name = '', $target_folder = '', $file_name = '', $thumb = false, $thumb_folder = '', $thumb_width = '', $thumb_height = '') { //folder path setup $target_path = $target_folder; $thumb_path = $thumb_folder; //file name setup $filename_err = explode('.', $_FILES[$field_name]['name']); $filename_err_count = count($filename_err); $file_ext = $filename_err[$filename_err_count - 1]; if ($file_name != '') { $fileName = $file_name.'.'.$file_ext; } else { $fileName = $_FILES[$field_name]['name']; } //upload image path $upload_image = $target_path.basename($fileName); //upload image if (move_uploaded_file($_FILES[$field_name]['tmp_name'], $upload_image)) { //thumbnail creation if ($thumb == true) { $thumbnail = $thumb_path.$fileName; list($width, $height) = getimagesize($upload_image); $thumb_create = imagecreatetruecolor($thumb_width, $thumb_height); switch ($file_ext) { case 'jpg': $source = imagecreatefromjpeg($upload_image); break; case 'jpeg': $source = imagecreatefromjpeg($upload_image); break; case 'png': $source = imagecreatefrompng($upload_image); break; case 'gif': $source = imagecreatefromgif($upload_image); break; default: $source = imagecreatefromjpeg($upload_image); } imagecopyresized($thumb_create, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); switch ($file_ext) { case 'jpg' || 'jpeg': imagejpeg($thumb_create, $thumbnail, 100); break; case 'png': imagepng($thumb_create, $thumbnail, 100); break; case 'gif': imagegif($thumb_create, $thumbnail, 100); break; default: imagejpeg($thumb_create, $thumbnail, 100); } } return $fileName; } else { return false; } } function getPeriode($waktu, $before = false) { $interval = 5 * 60; //10 menit $timeStart = strtotime(date('d-m-Y 00:00:00')); $timeEnd = strtotime(date('d-m-Y 23:59:59')); $inTime = true; $i = 1; $periode = ''; $periodeBefore = ''; while ($inTime) { $time = $timeStart + ($i * $interval); $timeBefore = $time - $interval; $timeNext = $time + $interval; if (($waktu >= $time) && ($waktu < $timeNext)) { $periode = date('H:i:s', $time).' - '.date('H:i:s', $timeNext); $periodeBefore = date('H:i:s', $timeBefore).' - '.date('H:i:s', $time); $inTime = false; } //stop looing kalau belum jam start if ($time < $timeStart) { $inTime = false; } //stop looping kalau udh lewat if ($time > $timeEnd) { $inTime = false; } //echo $time.'
'; //array_push($arrTime,$time); ++$i; } if ($before) { return array( 'now' => $periode, 'before' => $periodeBefore, ); } else { return $periode; } } function utf8ize($d) { if (is_array($d)) { foreach ($d as $k => $v) { $d[$k] = utf8ize($v); } } elseif (is_string($d)) { return utf8_encode($d); } return $d; }