HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/qas.sports-crowd.com/public/js/flash_ticket.js
function create() {
    $("#form_create").validator("update");
    $("#form_create")
        .validator("update")
        .on("submit", function (e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();
                let match_event_id = $("select[name=match_event_id]").val();
                if (match_event_id == '0') {
                    match_event_id = null;
                }
                let zone_id = $("select[name=zone_id]").val();
                let price = $("input[name=price]").val();
                let web_price = $("input[name=web_price]").val();
                let special_price = $("input[name=special_price]").val();
                let courtesy_price = $("input[name=courtesy_price]").val();
                let salable_capacity = $("input[name=salable_capacity]").val();
                let maximum_number_ballots = $("input[name=maximum_number_ballots]").val();
                let maximum_user_ticket_sales_box_office = $("input[name=maximum_user_ticket_sales_box_office]").val();
                let description = $("textarea[name=description]").val();
                let tags = $("select[name='generalMultiselect']").val();
                let show_in = $("select[name='show_in']").val();
                let show_image = $("select[name='show_image']").val();
                let apply_coupon_type = $("select[name='typesAplicationCupon']").val();
                let coupon = $("textarea[name='coupon']").val();

                if (!zone_id || zone_id == '0' || !price || !salable_capacity || !maximum_number_ballots || !maximum_user_ticket_sales_box_office) {
                    swal(Lang.get("messagesClient.global.fields_requireds"), {
                        icon: "error",
                    });
                    return;
                }

                var info = {
                    _method: $("input[name=_method]").val(),
                    match_event_id,
                    zone_id,
                    price,
                    salable_capacity,
                    maximum_number_ballots,
                    maximum_user_ticket_sales_box_office,
                    web_price,
                    special_price,
                    courtesy_price,
                    description,
                    tags,
                    show_in,
                    show_image,
                    apply_coupon_type,
                    coupon
                };

                $("#btn-create").addClass("displayNone");
                $("#spinnerButton").removeClass("displayNone");

                swal(Lang.get("messagesClient.global.create_record"), {
                    buttons: {
                        cancel: "No",
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $.ajax({
                            url: `/flash_ticket/create`,
                            type: "POST",
                            contentType: "application/json",
                            headers: {
                                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                                "Content-Type": "application/json",
                            },
                            data: JSON.stringify(info),
                            success: function (r) {
                                if (r.r) {
                                    var id = r.data;
                                    var img = document.getElementById("image");
                                    var img = img.files[0];
                                    if (img != null) {
                                        saveImage(id);
                                    } else {
                                        swal(r.m, {
                                            icon: "success",
                                            buttons: {
                                                Ok: true,
                                            },
                                        }).then((val) => {
                                            if (val == "Ok") {
                                                $(location).attr("href", `/flash_ticket`);
                                            }
                                        });
                                    }
                                } else {
                                    swal("Error", r.m, "error");
                                    $("#btn-create").removeClass("displayNone");
                                    $("#spinnerButton").addClass("displayNone");
                                }
                            },
                            error: function (e) {
                                swal("Error", "¡Hubo un Error al crear!", "error");
                                $("#btn-create").removeClass("displayNone");
                                $("#spinnerButton").addClass("displayNone");
                            },
                        });
                    } else {
                        $("#btn-create").removeClass("displayNone");
                        $("#spinnerButton").addClass("displayNone");
                    }
                });
            }
        });
}

function clickEdit(event_id) {
    $(location).attr("href", `/flash_ticket/${event_id}/edit`);
}

function edit() {
    $("#form_edit").validator("update");
    $("#form_edit")
        .validator("update")
        .on("submit", function (e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();
                let match_event_id = $("select[name=match_event_id]").val();
                if (match_event_id == '0') {
                    match_event_id = null;
                }
                let zone_id = $("select[name=zone_id]").val();
                let price = $("input[name=price]").val();
                let salable_capacity = $("input[name=salable_capacity]").val();
                let maximum_number_ballots = $("input[name=maximum_number_ballots]").val();
                let maximum_user_ticket_sales_box_office = $("input[name=maximum_user_ticket_sales_box_office]").val();
                let web_price = $("input[name=web_price]").val();
                let special_price = $("input[name=special_price]").val();
                let courtesy_price = $("input[name=courtesy_price]").val();
                let description = $("textarea[name=description]").val();
                let tags = $("#form_edit select[name='generalMultiselect']").val();
                let show_in = $("#form_edit select[name='show_in']").val();
                let show_image = $("#form_edit select[name='show_image']").val();
                let apply_coupon_type = $("select[name='typesAplicationCupon']").val();
                let coupon = $("textarea[name='coupon']").val();

                if (!zone_id || zone_id == '0' || !price || !salable_capacity || !maximum_number_ballots || !maximum_user_ticket_sales_box_office) {
                    swal(Lang.get("messagesClient.global.fields_requireds"), {
                        icon: "error",
                    });
                    return;
                }

                var info = {
                    _method: $("input[name=_method]").val(),
                    match_event_id,
                    zone_id,
                    price,
                    salable_capacity,
                    maximum_number_ballots,
                    maximum_user_ticket_sales_box_office,
                    web_price,
                    special_price,
                    courtesy_price,
                    description,
                    tags,
                    show_in,
                    show_image,
                    apply_coupon_type,
                    coupon

                };
                var id = $("#form_edit").attr("eventId");

                $("#btn-edit").addClass("displayNone");
                $("#spinnerButton").removeClass("displayNone");

                swal(Lang.get("messagesClient.global.edit_record"), {
                    buttons: {
                        cancel: "No",
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $.ajax({
                            url: `/flash_ticket/${id}/update`,
                            type: "PUT",
                            contentType: "application/json",
                            headers: {
                                "X-CSRF-TOKEN": $(
                                    'meta[name="csrf-token"]'
                                ).attr("content"),
                                "Content-Type": "application/json",
                            },
                            data: JSON.stringify(info),
                            success: function (r) {
                                if (r.r) {
                                    var img = document.getElementById("image");
                                    var img = img.files[0];
                                    if (img != null) {
                                        saveImage(id);
                                    } else {
                                        swal(r.m, {
                                            icon: "success",
                                            buttons: {
                                                Ok: true,
                                            },
                                        }).then((val) => {
                                            if (val == "Ok") {
                                                $(location).attr("href", `/flash_ticket`);
                                            }
                                        });
                                    }
                                } else {
                                    swal("Error", r.m, "error");
                                    $("#btn-edit").removeClass("displayNone");
                                    $("#spinnerButton").addClass("displayNone");
                                }
                            },
                            error: function (e) {
                                swal("Error", "¡Hubo un Error al actualizar!", "error");
                                $("#btn-edit").removeClass("displayNone");
                                $("#spinnerButton").addClass("displayNone");
                            },
                        });
                    } else {
                        $("#btn-edit").removeClass("displayNone");
                        $("#spinnerButton").addClass("displayNone");
                    }
                });
            }
        });
}

/** Método para eliminar **/
function clickDelete(event_id) {
    swal(Lang.get("messagesClient.global.delete_record"), {
        buttons: {
            cancel: "No",
            Ok: true,
        },
    }).then((val) => {
        if (val == "Ok") {
            var info = {
                _method: "DELETE",
            };

            $.ajax({
                url: `/flash_ticket/${event_id}/delete`,
                type: "DELETE",
                contentType: "application/json",
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr(
                        "content"
                    ),
                    "Content-Type": "application/json",
                },
                data: JSON.stringify(info),
                success: function (r) {
                    if (r.r) {
                        swal(r.m, {
                            icon: "success",
                            buttons: {
                                Ok: true,
                            },
                        }).then((val) => {
                            if (val == "Ok") {
                                $(location).attr("href", `/flash_ticket`);
                            }
                        });
                    } else {
                        swal("Error", r.m, "error");
                    }
                },
                error: function (e) {
                    swal("Error", Lang.get("messagesClient.events.error_delete"), "error");
                },
            });
        }
    });
}

/** Activar/Desactivar usando switch */
function chk(value) {
    var state;
    if ($("#Checkactive" + value).is(":checked")) {
        state = 1;
    } else {
        state = 0;
    }

    var info = {
        id: value,
        state: state,
    };

    $.ajax({
        url: "/flash_ticket/active",
        type: "POST",
        contentType: "application/json",
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        data: JSON.stringify(info),
        success: function (r) {
            if (r.r) {
                swal(r.m, {
                    icon: "success",
                    buttons: {
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $(location).attr("href", `/flash_ticket`);
                    }
                });
            } else {
                swal("Error", r.m, "error");
            }
        },
        error: function (e) {
            swal("Error al actualizar registro", {
                icon: "error",
            });
        },
    });
}

function saveImage(id) {
    var fImage = document.getElementById("image");
    fImage = fImage.files[0];
    if (fImage) {
        var formData = new FormData();
        formData.append("id", id);
        formData.append("image", fImage);

        $.ajax({
            type: "POST",
            dataType: "json",
            processData: false,
            contentType: false,
            headers: {
                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            },
            data: formData,
            url: "/flash_ticket/saveImage",
            success: function (r) {
                if (r.r) {
                    swal(r.m, {
                        icon: "success",
                        buttons: {
                            Ok: true,
                        },
                    }).then((val) => {
                        if (val == "Ok") {
                            $(location).attr("href", "/flash_ticket");
                        }
                    });
                } else {
                    swal("Error", "¡Error al cargar imagen del evento!", "error");
                    if ($("#btn-create")) $("#btn-create").removeClass("displayNone");
                    if ($("#btn-edit")) $("#btn-edit").removeClass("displayNone");
                    $("#spinnerButton").addClass("displayNone");
                }
            },
            error: function (e) {
                swal("Error", "¡Error al cargar imagen del evento!", "error");
                if ($("#btn-create")) $("#btn-create").removeClass("displayNone");
                if ($("#btn-edit")) $("#btn-edit").removeClass("displayNone");
                $("#spinnerButton").addClass("displayNone");
            },
        });
    }
}