|
Server : Apache System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : matalashes ( 1004) PHP Version : 8.1.29 Disable Function : NONE Directory : /home/matalashes/.trash/app.bak.6/Helpers/ |
Upload File : |
<?php
if (!function_exists('swal_error')) {
/**
* @param string $error Error condition
* @param string $message Messsage
* @return script
*/
function swal_error($error, $message)
{
$script = '<script type="text/javascript">';
if ($error == "true") {
$script .= 'Swal.fire({
icon: "error",
title: "Oops...",
allowEnterKey: true,
allowEscapeKey: true,
focusConfirm: true,
confirmButtonColor: "#3E9CCA",
text: "' . $message . '"
});';
}
$script .= '</script>';
return $script;
}
}
if (!function_exists('deletefilejs')) {
function deletefilejs($url_action_table, $upload_data)
{
$script = '<script type="text/javascript">';
$script .= 'function deletefilejs() {';
$script .= 'var state = $(".close_upload_btn").attr("state");
var path = $(".close_upload_btn").attr("path");
var id = $(".close_upload_btn").attr("_id");
$(".close_upload_btn").hide();
var fd = new FormData();
if (state == "edit") {
fd.append("path", path);
fd.append("id", id);
}
$.ajax({
type: "POST",
url: "' . $url_action_table["deletefile"] . '",
cache: false,
data: fd,
contentType: false,
processData: false,
success: function (data) {
$("#' . $upload_data["upload_field_name"] . '").show();
$("#' . $upload_data["upload_field_name"] . '").attr("required", "required");
$("#' . $upload_data["upload_field_name"] . '").val("");
$(".preview_image").hide();
var preview = $(".preview_image"); //selects the query named img
preview.attr("src", "");
$(".btn").prop("disabled", false);
},
error: function (html) {
alert("Kode Error [" + html.status + "]<br/><br/>Status:" + html.statusText);
}
});';
$script .= '}';
$script .= '</script>';
return $script;
}
}
if (!function_exists('upload_file')) {
function upload_file($url_action_table, $upload_data)
{
$script = '<script type="text/javascript">';
$script .= 'function upload_file() {';
$script .= '// var file = document.querySelector("input[type=file]").files[0]; //sames as here
// alert(document.getElementById("us_file").files[0]["type"]);
$(".preview_image").hide();
$(".close_upload_btn").hide();
var file = $("#' . $upload_data["upload_field_name"] . '").get(0).files[0]; //selects the query named img
var fd = new FormData();
fd.append("' . $upload_data["upload_field_name"] . '", file);
var reader = new FileReader();
reader.onloadend = function () {
$(".preview_image").attr("src", reader.result);
}
$(".preloader").css("display","block");
if (file) {
reader.readAsDataURL(file); //reads the data as a URL
$.ajax({
type: "POST",
url: "' . $url_action_table["upload"] . '",
cache: false,
data: fd,
contentType: false,
processData: false,
success: function (result) {
$(".preloader").css("display","none");
var data = JSON.parse(result);
console.log(data["message"]);
if (data["is_success"]) {
Swal.fire({
icon: "success",
title: "Great!",
text: data["message"]
});
$(".preview_image").show();
$(".close_upload_btn").show();
$(".close_upload_btn").attr("path",data["filename"]);
$("#' . $upload_data["upload_field_name"] . '").hide();
} else {
$(".preloader").css("display","none");
Swal.fire({
icon: "error",
title: "Oops...",
html: data["message"]
});
}
},
error: function (html) {
$(".preloader").css("display","none");
alert("Kode Error [" + html.status + "]<br/><br/>Status:" + html.statusText);
$(".btn").prop("disabled", false);
}
});
}';
$script .= '}';
$script .= '</script>';
return $script;
}
}
//Untuk file, bukan image
if (!function_exists('deletefilejs2')) {
function deletefilejs2($url_action_table, $upload_data, $_id_data, $state)
{
$script = '<script type="text/javascript">';
$script .= 'function deletefilejs2() {';
$script .= 'var state = $(".close_upload_btn2").attr("state");
var path = $(".close_upload_btn2").attr("path");
$(".close_upload_btn2").hide();
var fd = new FormData();
if (state == "edit") {
fd.append("path", path);
}
$.ajax({
type: "POST",
url: "' . $url_action_table["deletefile2"] . '/' . $_id_data . '/' . $state . '",
cache: false,
data: fd,
contentType: false,
processData: false,
success: function (data) {
$("#' . $upload_data["upload_field_name2"] . '").show();
$("#' . $upload_data["upload_field_name2"] . '").attr("required", "required");
$("#' . $upload_data["upload_field_name2"] . '").val("");
$(".preview_image2").hide();
var preview = $(".preview_image2"); //selects the query named img
preview.attr("href", "");
$(".btn").prop("disabled", false);
},
error: function (html) {
alert("Kode Error [" + html.status + "]<br/><br/>Status:" + html.statusText);
$(".btn").prop("disabled", false);
}
});';
$script .= '}';
$script .= '</script>';
return $script;
}
}
//Untuk file, bukan image
if (!function_exists('upload_file2')) {
function upload_file2($url_action_table, $upload_data, $_id_data, $state)
{
$script = '<script type="text/javascript">';
$script .= 'function upload_file2() {';
$script .= '// var file = document.querySelector("input[type=file]").files[0]; //sames as here
// alert(document.getElementById("us_file").files[0]["type"]);
$(".preview_image2").hide();
$(".close_upload_btn2").hide();
var file = $("#' . $upload_data["upload_field_name2"] . '").get(0).files[0]; //selects the query named img
var fd = new FormData();
fd.append("' . $upload_data["upload_field_name2"] . '", file);
var reader = new FileReader();
reader.onloadend = function () {
$(".preview_image2").attr("href", reader.result);
}
$(".preloader").css("display","block");
if (file) {
reader.readAsDataURL(file); //reads the data as a URL
console.log(file);
$.ajax({
type: "POST",
url: "' . $url_action_table["upload2"] . '/' . $_id_data . '/' . $state . '",
cache: false,
data: fd,
contentType: false,
processData: false,
success: function (result) {
$(".preloader").css("display","none");
var data = JSON.parse(result);
if (data["is_success"]) {
Swal.fire({
type: "success",
title: "Great!",
text: data["message"]
});
$(".preview_image2").show();
$(".close_upload_btn2").show();
$("#' . $upload_data["upload_field_name2"] . '").hide();
} else {
$(".preloader").css("display","none");
Swal.fire({
type: "error",
title: "Oops...",
html: data["message"]
});
}
},
error: function (html) {
$(".preloader").css("display","none");
alert("Kode Error [" + html.status + "]<br/><br/>Status:" + html.statusText);
$(".btn").prop("disabled", false);
}
});
}';
$script .= '}';
$script .= '</script>';
return $script;
}
}