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); }
if (isset($_POST['label'])) { if ($_FILES['image']['tmp_name'] !== "") { $img = file_get_contents($_FILES['image']['tmp_name']); } else { $img = NULL; } $parent_id = NULL; if ($_POST['parentId'] !== "") { $parent_id = $_POST['parentId']; } $dispOrder = 0; if ($_POST['dispOrder'] !== "") { $dispOrder = intval($_POST['dispOrder']); } $cat = new \Pasteque\Category($_POST['reference'], $parent_id, $_POST['label'], $img, $dispOrder); $id = \Pasteque\CategoriesService::createCat($cat, $img); if ($id !== FALSE) { $message = \i18n("Category saved. <a href=\"%s\">Go to the category page</a>.", PLUGIN_NAME, \Pasteque\get_module_url_action(PLUGIN_NAME, 'category_edit', array('id' => $id))); } else { $error = \i18n("Unable to save changes"); } } } $category = NULL; if (isset($_GET['id'])) { $category = \Pasteque\CategoriesService::get($_GET['id']); } ?> <h1><?php \pi18n("Edit a category", PLUGIN_NAME); ?>