/
home
/
efamember
/
domains
/
efa-member.com
/
public_html
/
config
/
up file
home
<?php @session_start(); function connectDB($secure) { if ($secure == "cAh3DrJACzw4RbU") { $dbhost = "localhost"; $dbuser = "efamember_j9ckhwosk"; $dbpass = "ISA4ZSvtx"; $dbname = "efamember_k8hk2odkl"; $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); mysqli_set_charset($connection, "utf8"); if (!$connection) { die("Connection failed: " . mysqli_connect_error()); } else { return $connection; } } else { return false; } } function url() { if (isset($_SERVER['HTTPS'])) { $protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http"; } else { $protocol = 'http'; } return $protocol . "://" . $_SERVER['HTTP_HOST'] . "/demo"; } function checkAdmin($admin_id) { $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); if ($connection) { $sql = "SELECT active_status FROM tbl_admin WHERE admin_id = '$admin_id';"; $rs = mysqli_query($connection, $sql); $row = mysqli_fetch_array($rs); $sql2 = "SELECT count(*) as count_check FROM tbl_admin WHERE active_status = '" . $row['active_status'] . "';"; $rs2 = mysqli_query($connection, $sql2); $row2 = mysqli_fetch_array($rs2); if ($row2['count_check'] > 0) { return 1; } else { return 0; } } else { return 0; } } function recheck_query($r) { $search_array = array(";", "'", chr(34)); $new_string = str_replace($search_array, "", $r); $new_string = str_ireplace("SELECT", "", $new_string); $new_string = str_ireplace("INSERT", "", $new_string); $new_string = str_ireplace("UPDATE", "", $new_string); $new_string = str_ireplace("DELETE", "", $new_string); $new_string = str_ireplace("DROP", "", $new_string); $new_string = str_ireplace("CREATE", "", $new_string); $new_string = str_ireplace("TRUNCATE", "", $new_string); $new_string = str_ireplace("TABLE", "", $new_string); return $new_string; } function check_access($user_id, $access_id) { $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); $sql = "SELECT access_level FROM tbl_user WHERE user_id = '$user_id';"; $rs = mysqli_query($connection, $sql) or die(mysqli_error()); $row = mysqli_fetch_array($rs); $page_id = $access_id; $level = $row['access_level']; $access_code = strrev(decbin($level)); $accessible = substr($access_code, $page_id - 1, 1); if ($accessible) { return 1; } else { return 0; } mysqli_close($connection); } function getRandomID($size, $table, $column_name) { $check_status = 0; $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); while ($check_status == 0) { $random_id = randomCode($size); $sql = "SELECT count(*) as count FROM $table WHERE $column_name = '$random_id';"; $rs_check = mysqli_query($connection, $sql) or die(mysqli_error()); $row_check = mysqli_fetch_assoc($rs_check); $check_repeat = $row_check['count']; if ($check_repeat == 0) { $check_status = 1; } } return $random_id; } function getRandomID2($size, $table, $column_name) { $check_status = 0; $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); while ($check_status == 0) { $random_id = randomCode2($size); $sql = "SELECT count(*) as count FROM $table WHERE $column_name = '$random_id';"; $rs_check = mysqli_query($connection, $sql) or die(mysqli_error()); $row_check = mysqli_fetch_assoc($rs_check); $check_repeat = $row_check['count']; if ($check_repeat == 0) { $check_status = 1; } } return $random_id; } function randomCode($length) { $possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghigklmnopqrstuvwxyz"; //ตัวอักษรที่ต้องการสุ่ม $str = ""; while (strlen($str) < $length) { $str .= substr($possible, (rand() % strlen($possible)), 1); } return $str; } function randomCode2($length) { $possible = "0123456789"; //ตัวอักษรที่ต้องการสุ่ม $str = ""; while (strlen($str) < $length) { $str .= substr($possible, (rand() % strlen($possible)), 1); } return $str; } function getBaseUrl() { if (isset($_SERVER['HTTPS'])) { $protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http"; } else { $protocol = 'http'; } return $protocol . "://" . $_SERVER['HTTP_HOST']; } function dateShow($date) { return date('d/m/', strtotime($date)) . date('Y', strtotime($date + 543)); } function dateThai($date) { $strYear = date("Y", strtotime($date)) + 543; $strMonth = date("m", strtotime($date)); $strDay = date("d", strtotime($date)); $strHour = date("H", strtotime($date)); $strMinute = date("i", strtotime($date)); $strSeconds = date("s", strtotime($date)); $thaimonth = array("มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"); $strthaimounth = $thaimonth[$strMonth - 1]; return $strDay . " " . $strthaimounth . " " . $strYear; } function dateThai2($date) { $strYear = date("Y", strtotime($date)) + 543; $strMonth = date("m", strtotime($date)); $strDay = date("d", strtotime($date)); $strHour = date("H", strtotime($date)); $strMinute = date("i", strtotime($date)); $strSeconds = date("s", strtotime($date)); $thaimonth = array("ม.ค.", "ก.พ.", "มี.ค.", "เม.ย", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."); $strthaimounth = $thaimonth[$strMonth - 1]; return $strDay . " " . $strthaimounth . " " . $strYear; } function dateEng($date) { $strYear = date("Y", strtotime($date)); $strMonth = date("m", strtotime($date)); $strDay = date("d", strtotime($date)); $strHour = date("H", strtotime($date)); $strMinute = date("i", strtotime($date)); $strSeconds = date("s", strtotime($date)); $thaimonth = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $strthaimounth = $thaimonth[$strMonth - 1]; return $strDay . " " . $strthaimounth . " " . $strYear; } function dateEng2($date) { $strYear = date("Y", strtotime($date)) + 543; $strMonth = date("m", strtotime($date)); $strDay = date("d", strtotime($date)); $strHour = date("H", strtotime($date)); $strMinute = date("i", strtotime($date)); $strSeconds = date("s", strtotime($date)); $thaimonth = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); $strthaimounth = $thaimonth[$strMonth - 1]; return $strDay . " " . $strthaimounth . " " . $strYear; } function getData($tbl, $field, $id) { $conn = connectDB('-%eA|y).m0%%1A7'); $sql = "SELECT * FROM $tbl WHERE $field = '$id'"; $rs = $conn->query($sql); $row = $rs->fetch_assoc(); return $row; } function stringInsert($str, $insertstr, $pos) { $str = substr($str, 0, $pos) . $insertstr . substr($str, $pos); return $str; } function bigsara_encode($name, $secure_text, $secure_pointer) { $encode = base64_encode($name); $encode = stringInsert($encode, $secure_text, $secure_pointer); $encode = base64_encode($encode); return $encode; } function bigsara_decode($name, $secure_text) { $decode = base64_decode($name); $decode = str_replace($secure_text, "", $decode); $decode = base64_decode($decode); return $decode; } function getRegisterNO($size = 4, $text = '', $table, $column, $ct_code) // เอาไว้กำหนดเลขรันหัวบิล (ชื่อตาราง,คอลั่มน์,ใส่อักษรนำหน้า,จำนวนตัวเลขตามท้ายกี่ตัว Default 4) เช่น XX0001 { $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); $number = sprintf('%0' . $size . 'd', 1); $sql = "SELECT (CASE WHEN (SELECT COUNT($column) AS count_this_month FROM $table WHERE race = '$ct_code' AND $column LIKE '$text%') > 0 THEN LPAD((MAX(substring($column , -$size))+1),$size,0) ELSE '$number' END) AS NextCode FROM $table WHERE $column LIKE '$text%'"; $rs = mysqli_query($connection, $sql); $row = mysqli_fetch_assoc($rs); return $text . $row['NextCode']; } function getRunNO($size = 4, $text = '', $table, $column) // เอาไว้กำหนดเลขรันหัวบิล (ชื่อตาราง,คอลั่มน์,ใส่อักษรนำหน้า,จำนวนตัวเลขตามท้ายกี่ตัว Default 4) เช่น XX0001 { $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); $number = sprintf('%0' . $size . 'd', 1); $sql = "SELECT (CASE WHEN (SELECT COUNT($column) AS count_this_month FROM $table WHERE $column LIKE '$text%') > 0 THEN LPAD((MAX(substring($column , -$size))+1),$size,0) ELSE '$number' END) AS NextCode FROM $table WHERE $column LIKE '$text%'"; $rs = mysqli_query($connection, $sql); $row = mysqli_fetch_assoc($rs); return $text . $row['NextCode']; } function registerType_title($type) { if ($type == 1) { $register_type = 'นายจ้าง'; } elseif ($type == 2) { $register_type = 'บนจ.'; } elseif ($type == 3) { $register_type = 'Agency'; } elseif ($type == 4) { $register_type = 'แรงงาน'; } return $register_type; } function registerLevel_title($level) { if ($level == 'g9k1s') { $register_level = 'ทั่วไป'; } elseif ($level == 'kki22') { $register_level = 'วิสามัญ'; } elseif ($level == 'x9fkq') { $register_level = 'สามัญ.'; } return $register_level; } function getTitle_name($title) { if ($title == '1') { $title_name = 'นาย ( Mr. )'; } elseif ($title == '2') { $title_name = 'นางสาว ( Miss )'; } elseif ($title == '3') { $title_name = 'นาง ( Mrs. ).'; } // elseif ($title == '4') { // $title_name = 'อื่นๆ.'; // } return $title_name; } function date_picker($date) { list($d, $m, $y) = explode('/', $date); return date('Y-m-d', strtotime("$y-$m-$d")); } function convertToMoney($amount_number) { $amount_number = number_format($amount_number, 2, ".", ""); $pt = strpos($amount_number, "."); $number = $fraction = ""; if ($pt === false) { $number = $amount_number; } else { $number = substr($amount_number, 0, $pt); $fraction = substr($amount_number, $pt + 1); } $ret = ""; $baht = ReadNumber($number); if ($baht != "") { $ret .= $baht . "บาท"; } $satang = ReadNumber($fraction); if ($satang != "") { $ret .= $satang . "สตางค์"; } else { $ret .= "ถ้วน"; } return $ret; } function ReadNumber($number) { $position_call = array("แสน", "หมื่น", "พัน", "ร้อย", "สิบ", ""); $number_call = array("", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า"); $number = $number + 0; $ret = ""; if ($number == 0) return $ret; if ($number > 1000000) { $ret .= ReadNumber(intval($number / 1000000)) . "ล้าน"; $number = intval(fmod($number, 1000000)); } $divider = 100000; $pos = 0; while ($number > 0) { $d = intval($number / $divider); $ret .= (($divider == 10) && ($d == 2)) ? "ยี่" : ((($divider == 10) && ($d == 1)) ? "" : ((($divider == 1) && ($d == 1) && ($ret != "")) ? "เอ็ด" : $number_call[$d])); $ret .= ($d ? $position_call[$pos] : ""); $number = $number % $divider; $divider = $divider / 10; $pos++; } return $ret; } function list_order($table, $column, $where = "") { $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); $sql = "SELECT MAX($column) AS NextList FROM $table $where"; $rs = mysqli_query($connection, $sql); $row = mysqli_fetch_assoc($rs); return $row['NextList'] + 1; } // ฟังก์ชันสร้างคีย์จากรหัสผ่านด้วย PBKDF2 function createKey($password, $salt, $length = 32) { return hash_pbkdf2("sha512", $password, $salt, 100000, $length, true); } // ฟังก์ชันเข้ารหัสข้อความด้วย AES-256-CBC function encryptMessage($message, $password) { $salt = openssl_random_pseudo_bytes(16); $key = createKey($password, $salt); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); $encryptedMessage = openssl_encrypt($message, 'aes-256-cbc', $key, 0, $iv); $encryptedMessage = base64_encode($encryptedMessage . '::' . $iv . '::' . $salt); $_SESSION['encryptedMessage'] = $encryptedMessage; return $encryptedMessage; } // ฟังก์ชันถอดรหัสข้อความด้วย AES-256-CBC function decryptMessage($encryptedMessage, $password) { list($encryptedData, $iv, $salt) = explode('::', base64_decode($encryptedMessage), 3); $key = createKey($password, $salt); $originalMessage = openssl_decrypt($encryptedData, 'aes-256-cbc', $key, 0, $iv); return $originalMessage; }