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/companies.js
function createCompany() {
    $("#createCompany").validator("update");
    $("#createCompany")
        .validator("update")
        .on("submit", function(e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();

                var info = {
                    nit: $(" #createCompany input[name='nit']").val(),
                    name: $(" #createCompany input[name='name']").val(),
                    phone: $(" #createCompany input[name='phone']").val(),
                    contact: $("#createCompany input[name='contact']").val()
                };
                console.log(info);

                swal(Lang.get("messagesClient.company_tag1"), {
                    buttons: {
                        cancel: "No",
                        Ok: true
                    }
                }).then(val => {
                    if (val == "Ok") {
                        $("#btn-create-company").prop("disabled", true);
                        $.ajax({
                            url: "/companies/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) {
                                    swal(r.m, {
                                        icon: "success",
                                        buttons: {
                                            Ok: true
                                        }
                                    }).then(val => {
                                        if (val == "Ok") {
                                            console.log("creado");
                                            $(location).attr(
                                                "href",
                                                "/companies"
                                            );
                                        }
                                    });
                                } else {
                                    swal("Error", r.m, "error");
                                    $("#btn-create-company").prop(
                                        "disabled",
                                        false
                                    );
                                }
                            },
                            error: function(e) {
                                swal(
                                    "Error",
                                    Lang.get("messagesClient.company_tag2"),
                                    "error"
                                );
                                $("#btn-create-company").prop(
                                    "disabled",
                                    false
                                );
                            }
                        });
                    }
                });
            }
        });
}

function clickEditCompany(value) {
    _table = $("#example2").DataTable();
    index = _table.page();
    localStorage.setItem("productsTableIndex", index);
    $(location).attr("href", "/companies/edit/" + value);
}

function editCompany(id) {
    $("#editCompany").validator("update");
    $("#editCompany")
        .validator("update")
        .on("submit", function(e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();

                var info = {
                    id: id,
                    nit: $(" #editCompany input[name='nit']").val(),
                    name: $(" #editCompany input[name='name']").val(),
                    phone: $(" #editCompany input[name='phone']").val(),
                    contact: $("#editCompany input[name='contact']").val()
                };
                console.log(info);

                swal(Lang.get("messagesClient.company_tag4"), {
                    buttons: {
                        cancel: "No",
                        Ok: true
                    }
                }).then(val => {
                    if (val == "Ok") {
                        $("#btn-edit-company").prop("disabled", true);
                        $.ajax({
                            url: "/companies/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) {
                                    swal(r.m, {
                                        icon: "success",
                                        buttons: {
                                            Ok: true
                                        }
                                    }).then(val => {
                                        if (val == "Ok") {
                                            console.log("creado");
                                            localStorage.setItem(
                                                "setPageTable",
                                                true
                                            );
                                            $(location).attr(
                                                "href",
                                                "/companies"
                                            );
                                        }
                                    });
                                } else {
                                    swal("Error", r.m, "error");
                                    $("#btn-edit-company").prop(
                                        "disabled",
                                        false
                                    );
                                }
                            },
                            error: function(e) {
                                swal(
                                    "Error",
                                    Lang.get("messagesClient.company_tag3"),
                                    "error"
                                );
                                $("#btn-edit-company").prop("disabled", false);
                            }
                        });
                    }
                });
            }
        });
}

/**Activar/Desactivar empresa usando switch*/
function chkCompany(value) {
    var state;

    if ($("#Checkactive" + value).is(":checked")) {
        state = 1;
    } else {
        state = 0;
    }

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

    $.ajax({
        url: "/companies/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("Ok", r.m);
            } else {
                swal("Error", Lang.get("messagesClient.company_tag3"), "error");
            }
        },
        error: function(e) {
            swal("Error", Lang.get("messagesClient.company_tag3"), "error");
        }
    });
}

/**Método para eliminar empresa desde la tabla de admins y en editar */
function clickDeleteCompany(id) {
    swal(Lang.get("messagesClient.company_tag5"), {
        buttons: {
            cancel: "No",
            Ok: true
        }
    }).then(val => {
        if (val == "Ok") {
            var info = {
                id: id
            };
            console.log(info);

            $.ajax({
                url: "/companies/delete",
                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) {
                    console.log(r);
                    if (r.r) {
                        swal(r.m, {
                            icon: "success",
                            buttons: {
                                Ok: true
                            }
                        }).then(val => {
                            if (val == "Ok") {
                                console.log("creado");
                                $(location).attr("href", "/companies");
                            }
                        });
                    } else {
                        swal(
                            "Error",
                            Lang.get("messagesClient.company_tag6"),
                            "error"
                        );
                    }
                },
                error: function(e) {
                    swal(
                        "Error",
                        Lang.get("messagesClient.company_tag6"),
                        "error"
                    );
                }
            });
        }
    });
}

function setPageTable() {
    localStorage.setItem("setPageTable", true);
    $(location).attr("href", "/companies");
}