<commit_before>var itemSelected = null;
var itemIds = new Array();
var itemQuantities = new Array();

function reInitializeOrders() {
    console.log("Resetting values...");

    $(".box-body").removeClass("item-focus");
    $("#orders tr").remove();
    itemIds = new Array();
    itemQuantities = new Array();
    itemSelected = null;
    computeTotalCost();
    $("#type-tabs-content .tab-pane .row *").remove();
    fetchItems();
}

function setupTabs() {
    $.ajax({
        url: "cashier-controller/get-types.php",
        dataType: "json",
        success: function(data) {
            for (var i = 0; i < data.types.length; i++) {
                $tablinks = $("<a>", {"href": "#type_" + data.types[i].id, "data-toggle": "tab"}).text(data.types[i].name);
                $tabpanes = $("<div>", {"class": "tab-pane", "id": "type_" + data.types[i].id, "data-type-id": data.types[i].id, "role": "tabpanel"}).append($("<div>", {"class": "row"}));

                $("#type-tabs").append($("<li>").append($tablinks));
                $("#type-tabs-content").append($tabpanes);

            }

            $("a[href='#type_1']").tab("show");
            
        }, 
        error: function(errorThrown) {
            console.log(errorThrown);
        }
    });
}

function insertInsideTab(type, itemToBeInserted) {
    // console.log(itemToBeInserted);

    $("#type-tabs-content .tab-pane").each(function() {
        if (type == $(this).data("type-id")) {
            $("#type-tabs-content #type_"+type+" .row").append(itemToBeInserted);
        }
    });
}

function insertItem(item) {
    var $itemName = $("<h7>", {"class": ""}).text(item.name);
    var $itemHeader = $("<div>", {"class": "box-header with-border"}).append($itemName);
    var $itemDescription = $("<div>", {"class": "box-body"})
    .append($("<small>").text("₱ " + item.price))
    // .append("<br>")
    // .append($("<small>").text(item.pieces_left + " pieces left"));
    
    var $boxTemplate = $("<div>", {"class": "box box-primary box-solid"}).append($itemHeader).append($itemDescription);
    var $columnTemplate = $("<div>", {"class": "col-sm-2 col-md-4 col-lg-4"}).append($boxTemplate);
    
    $boxTemplate.on("click", function() {
        selectItem($itemDescription, item);
    });

    insertInsideTab(item.type, $columnTemplate);
}

function isUnlocked(boolean) {
    if (boolean) {
        $("#orders tr td:last-child").css("display", "block");
        $("#lock, #clear").css("display", "block");
        $("#cancel").css("display", "none");
        $("#add-to-orders").attr("disabled", true);
        $("#confirm-orders").attr("disabled", true);
    } else {
        $("#orders tr td:last-child").css("display", "none");
        $("#lock, #clear").css("display", "none");
        $("#cancel").css("display", "block");
        $("#add-to-orders").attr("disabled", false);
        $("#confirm-orders").attr("disabled", false);
    }
}

function selectItem($selectedItem, itemProperties) {
    $(".box-body").removeClass("item-focus");
    $selectedItem.addClass("item-focus");
    this.itemSelected = itemProperties;
}

function addToOrder(itemSelected) {
    // console.log(itemSelected);
    var $itemOrdered = "";<commit_msg>fixed security issue on unlocking<commit_after>var itemSelected = null;
var itemIds = new Array();
var itemQuantities = new Array();

function reInitializeOrders() {
    console.log("Resetting values...");

    $(".box-body").removeClass("item-focus");
    $("#orders tr").remove();
    itemIds = new Array();
    itemQuantities = new Array();
    itemSelected = null;
    computeTotalCost();
    $("#type-tabs-content .tab-pane .row *").remove();
    fetchItems();
}

function setupTabs() {
    $.ajax({
        url: "cashier-controller/get-types.php",
        dataType: "json",
        success: function(data) {
            for (var i = 0; i < data.types.length; i++) {
                $tablinks = $("<a>", {"href": "#type_" + data.types[i].id, "data-toggle": "tab"}).text(data.types[i].name);
                $tabpanes = $("<div>", {"class": "tab-pane", "id": "type_" + data.types[i].id, "data-type-id": data.types[i].id, "role": "tabpanel"}).append($("<div>", {"class": "row"}));

                $("#type-tabs").append($("<li>").append($tablinks));
                $("#type-tabs-content").append($tabpanes);

            }

            $("a[href='#type_1']").tab("show");
            
        }, 
        error: function(errorThrown) {
            console.log(errorThrown);
        }
    });
}

function insertInsideTab(type, itemToBeInserted) {
    // console.log(itemToBeInserted);

    $("#type-tabs-content .tab-pane").each(function() {
        if (type == $(this).data("type-id")) {
            $("#type-tabs-content #type_"+type+" .row").append(itemToBeInserted);
        }
    });
}

function insertItem(item) {
    var $itemName = $("<h7>", {"class": ""}).text(item.name);
    var $itemHeader = $("<div>", {"class": "box-header with-border"}).append($itemName);
    var $itemDescription = $("<div>", {"class": "box-body"})
    .append($("<small>").text("₱ " + item.price))
    // .append("<br>")
    // .append($("<small>").text(item.pieces_left + " pieces left"));
    
    var $boxTemplate = $("<div>", {"class": "box box-primary box-solid"}).append($itemHeader).append($itemDescription);
    var $columnTemplate = $("<div>", {"class": "col-sm-2 col-md-4 col-lg-4"}).append($boxTemplate);
    
    $boxTemplate.on("click", function() {
        selectItem($itemDescription, item);
    });

    insertInsideTab(item.type, $columnTemplate);
}

function isUnlocked(boolean) {
    if (boolean) {
        $("#orders tr td:last-child").css("display", "block");
        $("#lock, #clear").css("display", "block");
        $("#cancel").css("display", "none");
        $("#add-to-orders").attr("disabled", true);
        $("#confirm-orders").attr("disabled", true);
    } else {
        $("#manager-password").val("");
        $("#orders tr td:last-child").css("display", "none");
        $("#lock, #clear").css("display", "none");
        $("#cancel").css("display", "block");
        $("#add-to-orders").attr("disabled", false);
        $("#confirm-orders").attr("disabled", false);
    }
}

function selectItem($selectedItem, itemProperties) {
    $(".box-body").removeClass("item-focus");
    $selectedItem.addClass("item-focus");
    this.itemSelected = itemProperties;
}

function addToOrder(itemSelected) {
    // console.log(itemSelected);
    var $itemOrdered = "";
{'fraction_non_alphanumeric': 0.2337642351492767, 'fraction_numerical': 0.0018467220683287165, 'mean_word_length': 3.061875, 'pattern_counts': {'":': 24, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3375405', 'n_tokens_mistral': 2037, 'n_tokens_neox': 2036, 'n_words': 351}