select("SELECT UUID_SHORT()");
}
function isValidEmail($email)
{
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
function isPostMethod($request)
{
if ($request != "POST") {
return false;
}
return true;
}
function isJson($string)
{
json_decode($string);
return json_last_error() === JSON_ERROR_NONE;
}
function getGenderID($gender)
{
$gender = strtolower($gender);
$gender_id = "0";
if ($this->isNotEmpty($gender)) {
if (substr($gender, 0, 1) == "m") {
$gender_id = "1";
} else if (substr($gender, 0, 1) == "f") {
$gender_id = "2";
}
}
return $gender_id;
}
function isGetMethod($request)
{
if ($request != "GET") {
return false;
}
return true;
}
function implodeQoutation(array $data)
{
if (count($data) <= 0) {
return '';
}
return implode(",", array_map(array($this, 'quoteString'), $data));
}
function quoteString($string)
{
return sprintf("'%s'", $string);
}
function isNotEmpty($data)
{
return preg_match('/\S/', $data);
}
function convert_sql_date($data, $current_format)
{
if ($current_format == 'mm/dd/yyyy') {
$parts = explode('/', $data);
$yyyy_mm_dd = $parts[2] . '-' . $parts[0] . '-' . $parts[1];
return $yyyy_mm_dd;
} else if ($current_format == 'dd/mm/yyyy') {
$date = str_replace('/', '-', $data);
return date('Y-m-d', strtotime($date));
} else {
return "";
}
}
function alphaNumericOnly($s)
{
return preg_replace("/[^a-zA-Z0-9]+/", "", $s);
}
function fix_date($data, $format, $utility)
{
if ($utility->isNotEmpty($data)) {
$fix_date = "";
if (count(explode("/", $data)) == 3) {
$fix_date = $data;
} else {
if ($utility->isNotEmpty(strtotime($data))) {
$fix_date = date("m/d/Y", strtotime($data)); //aha word date
}
}
if ($utility->isNotEmpty($fix_date)) {
// format
// 01/23/2020 false
// 23/01/2020 true
$array_date = explode("/", explode(" ", $fix_date)[0]);
if ($format) { //if format == true swap index 0 and 1
$return_date = $array_date[2] . '-' . $array_date[1] . '-' . $array_date[0];
} else {
$return_date = $array_date[2] . '-' . $array_date[0] . '-' . $array_date[1];
}
$return_date = date("Y-m-d", strtotime($return_date));
if ($this->validateDate($return_date)) {
return $return_date;
}
}
}
return "";
}
function fix_date_v2($date, $format = "Y-m-d")
{
$fix_date = date($format, strtotime($date));
if (date($format, strtotime("1970-01-01")) == $fix_date) {
//invalid date
return "";
}
return $fix_date;
}
function upperCaseNestedArray($value)
{
if (is_array($value)) {
return array_map(array($this, 'upperCaseNestedArray'), $value);
}
return trim(mb_strtoupper($value));
}
// function removeEmptyValueArray($value) {
// if (is_array($value)) {
// return array_map(array($this, 'removeEmptyValueArray'), $value);
// }
// if($this->isNotEmpty()){
// }
// return trim(strtoupper($value));
// }
function lowerCaseNestedArray($value)
{
if (is_array($value)) {
return array_map(array($this, 'lowerCaseNestedArray'), $value);
}
return trim(strtolower($value));
}
function convert_sql_date_to_date_picker($value)
{
if (trim($value) == '') {
return '';
}
return date("m/d/Y", strtotime($value));
}
function fix_mobile_format($data)
{
if (strlen($data) < 5) {
return "";
}
$final_data = "";
//if area code equal to 639xx it will change to 09xxxxxxxxx
if (substr($data, 0, 2) === "09") {
$final_data = "+639" . substr($data, 2, strlen($data));
} else if (substr($data, 0, 3) === "639") {
$final_data = "+639" . substr($data, 3, strlen($data));
} else if (substr($data, 0, 1) === "9" && strlen($data) == 10) {
$final_data = "+639" . substr($data, 1, strlen($data));
} else {
$final_data = $data;
}
//if number start with 09xxx, check the length, if length is not 11 return blank, if not 09xxx return it
if (substr($final_data, 0, 4) === "+639") {
if (strlen($final_data) == 13) {
return $final_data;
} else {
return (strlen($final_data) > 13) ? substr($final_data, 0, 13) : $final_data;
}
}
return $final_data;
}
function fix_mobile_format_v2($data)
{
if (strlen($data) < 5) {
return "";
}
$final_data = "";
//if area code equal to 639xx it will change to 09xxxxxxxxx
if (substr($data, 0, 2) === "09") {
$final_data = "9" . substr($data, 2, strlen($data));
} else if (substr($data, 0, 3) === "639") {
$final_data = "9" . substr($data, 3, strlen($data));
} else if (substr($data, 0, 1) === "9" && strlen($data) == 10) {
$final_data = "9" . substr($data, 1, strlen($data));
} else {
$final_data = $data;
}
//if number start with 09xxx, check the length, if length is not 11 return blank, if not 09xxx return it
if (substr($final_data, 0, 1) === "9") {
if (strlen($final_data) == 10) {
return $final_data;
}/*else{
return (strlen($final_data) > 10) ? substr($final_data,0,10) : $final_data ;
}*/
}
return '';
}
function remove_non_numeric($data)
{
return preg_replace("/[^0-9]/", "", $data);
}
function cleanStr($string)
{
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
function mask($str, $first, $last)
{
$str = $this->cleanStr($str);
$len = strlen($str);
$toShow = $first + $last;
return substr($str, 0, $len <= $toShow ? 0 : $first) . str_repeat("*", $len - ($len <= $toShow ? 0 : $toShow)) . substr($str, $len - $last, $len <= $toShow ? 0 : $last);
}
function mask_email($email)
{
if (!$this->isNotEmpty($email)) {
return "";
}
$mail_parts = explode("@", $email);
$domain_parts = explode('.', $mail_parts[1]);
$mail_parts[0] = $this->mask($mail_parts[0], 2, 1); // show first 2 letters and last 1 letter
$mail_parts[1] = implode('.', $domain_parts);
return implode("@", $mail_parts);
}
function make_thumb($src, $dest, $desired_width)
{
if (!is_file($src) || !file_exists($src)) {
return false;
}
/* read the source image */
$imgInfo = getimagesize($src);
$mime = $imgInfo['mime'];
// Create a new image from file
switch ($mime) {
case 'image/jpeg':
$source_image = imagecreatefromjpeg($src);
break;
case 'image/png':
$source_image = imagecreatefrompng($src);
break;
case 'image/gif':
$source_image = imagecreatefromgif($src);
break;
default:
$source_image = imagecreatefromjpeg($src);
}
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
switch ($mime) {
case 'image/jpeg':
imagejpeg($virtual_image, $dest);
break;
case 'image/png':
imagepng($virtual_image, $dest);
break;
case 'image/gif':
imagegif($virtual_image, $dest);
break;
default:
imagejpeg($virtual_image, $dest);
}
}
function curl_me($url, $params, $method)
{
$method = strtoupper($method);
$ch = curl_init();
switch ($method) {
case 'POST':
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
break;
case 'GET':
break;
default:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
// curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
return $server_output;
}
function arrayNullToBlank($array)
{
foreach ($array as $key => $value) {
if (is_null($value)) {
$array[$key] = "";
}
}
return $array;
}
function separateName($name)
{
$name = trim($name);
$results = array();
preg_match('#^(\w+\.)?\s*([\'\’\w]+)\s+([\'\’\w]+)\s*(\w+\.?)?$#', $name, $results);
if (count($results) > 0) {
$fname_p1 = isset($results[1]) ? $results[1] : "";
$fname_p2 = isset($results[2]) ? $results[2] : "";
$firstname = trim($fname_p1 . ' ' . $fname_p2);
$lastname = "";
for ($i = 3; $i < count($results); $i++) {
$lastname = $lastname . ' ' . $results[$i];
}
$lastname = trim($lastname);
return array($firstname, $lastname);
} else {
return array();
}
}
function validateDate($date, $format = 'Y-m-d')
{
$d = DateTime::createFromFormat($format, $date);
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
return $d && $d->format($format) === $date;
}
function user()
{
return $_SESSION['user'];
}
function str_encrypt($param)
{
$serialized_data = serialize($param);
$key = 'nr5hlcci9v';
$secret_iv = 'xxxxxxxxxxxxxxxx';
$encrypted_data = openssl_encrypt($serialized_data, 'aes-256-cbc', $key, 0, $secret_iv);
$encoded_data = base64_encode($encrypted_data);
return $encoded_data;
}
function str_decrypt($param)
{
$key = 'nr5hlcci9v';
$secret_iv = 'xxxxxxxxxxxxxxxx';
$decoded_data = base64_decode($param);
$decrypted_data = openssl_decrypt($decoded_data, 'aes-256-cbc', $key, 0, $secret_iv);
// Unserialize the decrypted data to retrieve the original array
$decoded_data = unserialize($decrypted_data);
return $decoded_data;
}
function getDateDiff($startDate) {
$start = new DateTime($startDate);
$end = new DateTime(date('Y-m-d'));
$interval = $start->diff($end);
if ($interval->y > 0) {
return "" .$interval->y . " year" . ($interval->y > 1 ? "s" : "") . " ago";
} elseif ($interval->m > 0) {
return "".$interval->m . " month" . ($interval->m > 1 ? "s" : "") . " ago";
} elseif ($interval->d > 6) {
$weeks = floor($interval->d / 7);
return "".$weeks . " week" . ($weeks > 1 ? "s" : "") . " ago";
} elseif ($interval->d > 0) {
return "".$interval->d . " day" . ($interval->d > 1 ? "s" : "") . " ago";
} else {
return "Today";
}
}
}