function import_csv($csv)
{
    $error_mess = array();
    $update = 0;
    $create = 0;
    $error = 0;
    while ($tab = $csv->readLine()) {
        $parentOk = false;
        if ($tab['Parent'] !== NULL) {
            $parent = \Pasteque\CategoriesService::getByName($tab['Parent']);
            $image = NULL;
            if ($parent) {
                $parentOk = true;
                $tab['Parent'] = $parent->id;
            }
        } else {
            // Category isn't subCategory
            $parentOk = true;
        }
        if ($parentOk) {
            $cat = new \Pasteque\Category($tab['Parent'], $tab['Designation'], $image, $tab['Ordre']);
            $category_exist = \Pasteque\CategoriesService::getByName($cat->label);
            //UPDATE category
            if ($category_exist) {
                $cat->id = $category_exist->id;
                if (\Pasteque\CategoriesService::updateCat($cat)) {
                    $update++;
                } else {
                    $error++;
                    $error_mess[] = \i18n("On line %d: Cannot update category: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['Designation']);
                }
                //CREATE category
            } else {
                $id = \Pasteque\CategoriesService::createCat($cat);
                if ($id) {
                    $create++;
                } else {
                    $error++;
                    $error_mess[] = \i18n("On line %d: Cannot create category: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['Designation']);
                }
            }
        } else {
            $error++;
            $error_mess[] = \i18n("On line %d: Category parent doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber());
        }
    }
    $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $create, $update, $error);
    $csv->close();
    \Pasteque\tpl_msg_box($message, $error_mess);
}
$error = NULL;
if (isset($_POST['delete-comp'])) {
    if (\Pasteque\CompositionsService::delete($_POST['delete-comp'])) {
        $message = \i18n("Changes saved");
    } 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);
Esempio n. 3
0
function show_login_page()
{
    // Pasteque login page ?
    tpl_open();
    global $loginErrorMessage;
    if ($loginErrorMessage != NULL) {
        \Pasteque\tpl_msg_box($message, $loginErrorMessage);
    }
    ?>
<form class="edit" method="POST">
    <label for="login">Login :</label><input name="login" type="text" /><br />
    <label for="password">Password :</label><input name="password" type="password" /><br />
    <input style="margin:10px; width:auto; margin-left: 27%;" type="submit" />
</form>
<?php 
    tpl_close();
}