<?php
 $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 $extra="../../index";
 $host=$_SERVER['HTTP_HOST'];
 $uri=rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
 $go_to = '<script type="text/javascript"> window.location.href="http://'.$host.''.$uri.'/'.$extra.'";</script>';
if($actual_link == "http://$_SERVER[HTTP_HOST]/appTruck/php/functions/function_main"){
  echo $go_to;
};
function validate_jsnj_data($data_jsnj){
  global $_app_conn_db;
  $data_jsnj = mysqli_real_escape_string($_app_conn_db,$data_jsnj);
  $data_jsnj = trim($data_jsnj);
  $data_jsnj = addslashes($data_jsnj);
  $data_jsnj = strip_tags($data_jsnj);
  $data_jsnj = htmlspecialchars($data_jsnj, ENT_QUOTES);
  $data_jsnj = filter_var($data_jsnj, FILTER_SANITIZE_STRING);
  return $data_jsnj;    
 };
function validate_jsnj_varchar_html($data_jsnj){
  global $_app_conn_db;
  $data_jsnj = mysqli_real_escape_string($_app_conn_db,$data_jsnj);
  $data_jsnj = trim($data_jsnj);
  return $data_jsnj;
 };
function validate_jsnj_number($data_jsnj){
  global $_app_conn_db;
  $data_jsnj = mysqli_real_escape_string($_app_conn_db,$data_jsnj);
  $data_jsnj = addslashes($data_jsnj);
  $data_jsnj = strip_tags($data_jsnj);
  $data_jsnj = htmlspecialchars($data_jsnj, ENT_QUOTES);
  $data_jsnj = filter_var($data_jsnj, FILTER_SANITIZE_STRING);
    $data_jsnj = trim($data_jsnj);
    if(empty($data_jsnj)){
        $data_jsnj = '0.00';
    };
  $data_jsnj = number_format($data_jsnj, 2, '.', '');
  return $data_jsnj;
 };
function show_jsnj_longtext($data_jsnj){
  $data_jsnj =	str_replace(array('\r\n', '\r', '\n', '\t'), '&#60;br&#62;', $data_jsnj);
  $data_jsnj = nl2br($data_jsnj);
  $data_jsnj = stripslashes($data_jsnj);
  $data_jsnj = trim($data_jsnj);
  $data_jsnj = strip_tags($data_jsnj);
  $data_jsnj = ucfirst($data_jsnj);
    $data_jsnj =  html_entity_decode(htmlentities($data_jsnj, ENT_QUOTES, 'UTF-8'), ENT_QUOTES , 'ISO-8859-15');
  $data_jsnj = htmlspecialchars_decode($data_jsnj, ENT_QUOTES);

  if(empty($data_jsnj)){
	$data_jsnj = '';
  };
  return $data_jsnj;    
 };
function show_jsnj_longtext_edit($data_jsnj){
    $data_jsnj = str_replace(array('\r\n', '\r', '\n', '\t'), PHP_EOL, $data_jsnj);
    $data_jsnj = stripslashes($data_jsnj);
    $data_jsnj = trim($data_jsnj);
    $data_jsnj = strip_tags($data_jsnj);
    $data_jsnj =  html_entity_decode(htmlentities($data_jsnj, ENT_QUOTES, 'UTF-8'), ENT_QUOTES , 'ISO-8859-15');
    $data_jsnj = htmlspecialchars_decode($data_jsnj, ENT_QUOTES);
    if(empty($data_jsnj)){
        $data_jsnj = '';
    };
    return $data_jsnj;
};
function show_jsnj_number($data_jsnj){
  $data_jsnj = nl2br($data_jsnj);
  $data_jsnj = stripslashes($data_jsnj);
  $data_jsnj = trim($data_jsnj);
  $data_jsnj = strip_tags($data_jsnj);
  $data_jsnj = htmlspecialchars_decode($data_jsnj, ENT_QUOTES);
  
  if(empty($data_jsnj)){
	$data_jsnj = '0.00';
  };
  $data_jsnj = number_format($data_jsnj, 2, '.', '');
  return $data_jsnj;    
 };
function show_jsnj_data($data_jsnj){
    $data_jsnj =	str_replace(array('\r\n', '\r', '\n', '\t'), ' ', $data_jsnj);
    $data_jsnj = nl2br($data_jsnj);
    $data_jsnj = stripslashes($data_jsnj);
    $data_jsnj = trim($data_jsnj);
    $data_jsnj = strip_tags($data_jsnj);
    $data_jsnj =  html_entity_decode(htmlentities($data_jsnj, ENT_QUOTES, 'UTF-8'), ENT_QUOTES , 'ISO-8859-15');
    $data_jsnj = htmlspecialchars_decode($data_jsnj, ENT_QUOTES);
    
    if(empty($data_jsnj)){
        $data_jsnj = '';
    };
    return $data_jsnj;
};
function show_jsnj_longtext_space($data_jsnj){
    $data_jsnj =	str_replace(array('\r\n', '\r', '\n', '\t'), ' ', $data_jsnj);
    $data_jsnj = nl2br($data_jsnj);
    $data_jsnj = stripslashes($data_jsnj);
    $data_jsnj = trim($data_jsnj);
    $data_jsnj = strip_tags($data_jsnj);
    $data_jsnj = ucfirst($data_jsnj);
    $data_jsnj =  html_entity_decode(htmlentities($data_jsnj, ENT_QUOTES, 'UTF-8'), ENT_QUOTES , 'ISO-8859-15');
    $data_jsnj = htmlspecialchars_decode($data_jsnj, ENT_QUOTES);
    
    if(empty($data_jsnj)){
        $data_jsnj = '';
    };
    return $data_jsnj;
};
function jsnj_otp($data_jsnj){
    global $_app_conn_db;
    $data_jsnj = mysqli_real_escape_string($_app_conn_db,$data_jsnj);
    $data_jsnj = nl2br($data_jsnj);
    $data_jsnj = stripslashes($data_jsnj);
    $data_jsnj = trim($data_jsnj);
    $data_jsnj = strip_tags($data_jsnj);
    if(empty($data_jsnj)){
        $data_jsnj = '0';
    };
    return $data_jsnj;
};
function jsnj_date_dmy($data_jsnj){
    $data_jsnj = date('d-m-Y',strtotime($data_jsnj));
    return $data_jsnj;
};
function jsnj_date_dM($data_jsnj){
    $data_jsnj = date('d-M',strtotime($data_jsnj));
    return $data_jsnj;
};
function jsnj_date_ymd($data_jsnj){
    $data_jsnj = date('Y-m-d',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_time_seconds($data_jsnj){
    $data_jsnj = date('h:i:s',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_time_24($data_jsnj){
    $data_jsnj = date('H:i',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_datetime_show($data_jsnj){
    $data_jsnj = date('d-m-Y | h:i A',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_datemonth_show($data_jsnj){
    $data_jsnj = date('d-M',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_date_show($data_jsnj){
    $data_jsnj = date('d',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_time_show($data_jsnj){
    $data_jsnj = date('h:i A',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_month_show($data_jsnj){
    $data_jsnj = date('M',strtotime($data_jsnj));
    return $data_jsnj;
}
function jsnj_date_by_time($data_jsnj){
    $data_jsnj = date("d-m-Y | h:i A", $data_jsnj);
    return $data_jsnj;
}
function jsnj_date_by_time_dmy($data_jsnj){
    $data_jsnj = date("d-m-Y", $data_jsnj);
    return $data_jsnj;
}
function jsnj_by_time($data_jsnj){
    $data_jsnj = date("h:i A", $data_jsnj);
    return $data_jsnj;
}

function imageResize($imageSrc,$imageWidth,$imageHeight) {

    $newImageWidth =200;
    $newImageHeight =200;

    $newImageLayer=imagecreatetruecolor($newImageWidth,$newImageHeight);
    imagecopyresampled($newImageLayer,$imageSrc,0,0,0,0,$newImageWidth,$newImageHeight,$imageWidth,$imageHeight);

    return $newImageLayer;
}

function compressImage($type,$source, $destination,$imgsize) {

    $size = getimagesize( $source );

// Set the new width of the image
    $thumb_width = "800";
// Calculate the height of the new image to keep the aspect ratio
    $thumb_height = ( int )(( $thumb_width/$size[0] )*$size[1] );
// Create a new true color image in the memory
    $thumbnail = imagecreatetruecolor( $thumb_width, $thumb_height );
    if ($type == 'image/jpeg' || $type == 'image/jpg' ) {
        $src_img = imagecreatefromjpeg($source);
    }elseif ($type == 'image/png') {
        $src_img = imagecreatefrompng($source);
        imagealphablending($src_img, false);
        imagesavealpha($src_img, true);
        imagealphablending($thumbnail, false);
        imagesavealpha($thumbnail,true);
        $transparent = imagecolorallocatealpha($thumbnail, 255, 255, 255, 0);
        imagefilledrectangle($thumbnail, 0, 0, $thumb_width, $thumb_height, $transparent);
    }elseif ($type == 'image/gif') {
        $src_img = imagecreatefromgif($source);
    }



// Create the resized image
    imagecopyresampled( $thumbnail, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1] );
// Save the image as $source
    $maxSize4m = 4000 * 1024; //4mb
    $maxSize3m = 3000 * 1024; //3mb
    $maxSize2m = 2000 * 1024; //2mb
    $maxSize1m = 1000 * 1024; //1mb
    $maxSize05m = 500 * 1024; //500kb
    if ($imgsize > $maxSize4m) {
        $imgQuality= '60';
        $imgQualityPng = '6';
    }else if ($imgsize >= $maxSize3m && $imgsize < $maxSize4m) {
        $imgQuality= '60';
        $imgQualityPng = '6';
    } else if ($imgsize >= $maxSize2m && $imgsize < $maxSize3m) {
        $imgQuality= '65';
        $imgQualityPng = '7';
    } else if ($imgsize >= $maxSize1m && $imgsize < $maxSize2m) {
        $imgQuality= '70';
        $imgQualityPng = '7';
    } else if ($imgsize >= $maxSize05m && $imgsize < $maxSize1m) {
        $imgQuality= '75';
        $imgQualityPng = '8';
    } else if ($imgsize < $maxSize05m) {
        $imgQuality= '90';
        $imgQualityPng = '9';
    } else {
        $imgQualityPng = '9';
    }
    if ($type == 'image/jpeg' || $type == 'image/jpg' ) {
        $saveImg =  imagejpeg($thumbnail, $destination, $imgQuality);
    }elseif ($type == 'image/png') {
        $saveImg = imagepng($thumbnail, $destination, $imgQualityPng);
    }elseif ($type == 'image/gif') {
        $saveImg = imagegif($thumbnail, $destination);
    }else {
        $saveImg = imagejpeg($thumbnail, $destination, $imgQuality);
    }


}
//need img/view.php file
function loadImage($url, $width, $height,$quality){
    echo '../img/view?url=', urlencode($url) ,
    '&w=',$width,
    '&h=',$height,
    '&q=',$quality;
}
$numPage = $tcountNum ='';
?>