if (isset($_GET['delete-taxcat'])) {
    if (\Pasteque\TaxesService::deleteCat($_GET['delete-taxcat'])) {
        $message = \i18n("Changes saved");
    } else {
        $error = \i18n("Unable to delete tax. Tax cannot be deleted when in use.", PLUGIN_NAME);
    }
}
$taxes = \Pasteque\TaxesService::getAll();
//Title
echo \Pasteque\row(\Pasteque\mainTitle(\i18n("Taxes", PLUGIN_NAME)));
//Buttons
$buttons = \Pasteque\addButton(\i18n("Add a tax", PLUGIN_NAME), \Pasteque\get_module_url_action(PLUGIN_NAME, 'tax_edit'));
echo \Pasteque\row(\Pasteque\buttonGroup($buttons));
//Informations
\Pasteque\tpl_msg_box($message, $error);
//Counter
echo \Pasteque\row(\Pasteque\counterDiv(\i18n("%d taxes", PLUGIN_NAME, count($taxes))));
if (count($taxes) == 0) {
    echo \Pasteque\errorDiv(\i18n("No tax found", PLUGIN_NAME));
} else {
    $content[0][0] = \i18n("TaxCat.label");
    $i = 1;
    foreach ($taxes as $tax) {
        $btn_group = \Pasteque\editButton(\i18n('Edit', PLUGIN_NAME), \Pasteque\get_module_url_action(PLUGIN_NAME, 'tax_edit', array("id" => $tax->id)));
        $btn_group .= \Pasteque\deleteButton(\i18n('Delete', PLUGIN_NAME), \Pasteque\get_current_url() . "&delete-taxcat=" . $tax->id);
        $content[$i][0] = $tax->label;
        $content[$i][0] .= \Pasteque\buttonGroup($btn_group, "pull-right");
        $i++;
    }
    echo \Pasteque\row(\Pasteque\standardTable($content));
}
    } else {
        $error = \i18n("Unable to save changes");
    }
}
$compositions = \Pasteque\CompositionsService::getAll();
//Title
echo \Pasteque\row(\Pasteque\mainTitle(\i18n("Compositions", PLUGIN_NAME)));
//Buttons
$buttons = \Pasteque\addButton(\i18n("Add composition", PLUGIN_NAME), \Pasteque\get_module_url_action(PLUGIN_NAME, "composition_edit"));
echo \Pasteque\row(\Pasteque\buttonGroup($buttons));
//Information
\Pasteque\tpl_msg_box($message, $error);
//Counter
echo \Pasteque\row(\Pasteque\counterDiv(\i18n("%d compositions", PLUGIN_NAME, count($compositions))));
if (count($compositions) == 0) {
    echo \Pasteque\errorDiv(\i18n("No category found", PLUGIN_NAME));
} else {
    $content[0][0] = \i18n("Composition.label");
    $i = 1;
    foreach ($compositions as $composition) {
        if ($composition->hasImage) {
            $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=product&id=" . $composition->id;
        } else {
            $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=product";
        }
        $btn_group = \Pasteque\editButton(\i18n('Edit', PLUGIN_NAME), \Pasteque\get_module_url_action(PLUGIN_NAME, "composition_edit", array("productId" => $composition->id)));
        $btn_group .= \Pasteque\deleteButton(\i18n('Delete', PLUGIN_NAME), \Pasteque\get_current_url() . "&delete-comp=" . $composition->id);
        $content[$i][0] .= "<img class=\"img img-thumbnail thumbnail pull-left\" src=\"?" . $imgSrc . "\">";
        $content[$i][0] .= $composition->label;
        $content[$i][0] .= \Pasteque\buttonGroup($btn_group, "pull-right");
        $i++;
        $content[0][0] = "";
        $content[0][1] = \i18n("Product.reference");
        $content[0][2] = \i18n("Product.label");
        $i = 1;
        if (isset($archivesCat[$category->id])) {
            foreach ($archivesCat[$category->id] as $product) {
                if (!$product->visible) {
                    if ($product->hasImage) {
                        $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=product&id=" . $product->id;
                    } else {
                        $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=product";
                    }
                    $content[$i][0] = "<img class=\"img img-thumbnail thumbnail\" src=\"?" . $imgSrc . "\">";
                    $content[$i][1] = $product->reference;
                    $content[$i][2] = $product->label;
                    $btn_group = \Pasteque\editButton(\i18n('Edit', PLUGIN_NAME), \Pasteque\get_module_url_action(PLUGIN_NAME, 'product_edit', array("id" => $product->id)));
                    $content[$i][2] .= \Pasteque\buttonGroup($btn_group, "pull-right");
                    $i++;
                }
            }
        }
        if (sizeof($content) > 1) {
            echo \Pasteque\row(\Pasteque\secondaryTitle(\Pasteque\esc_html($category->label) . "&nbsp;-&nbsp;" . \i18n("Archived", PLUGIN_NAME)));
            echo \Pasteque\row(\Pasteque\standardTable($content));
        }
        unset($content);
    }
}
if (count($products) == 0) {
    echo \Pasteque\errorDiv(\i18n("No product found", PLUGIN_NAME));
}