<?php

$preload_files = 'modules/products/classes/products.class.php';
require "../../Group-Office.php";
require '../../lib/tkdlib.php';
$GO_SECURITY->authenticate();
$GO_MODULES->authenticate('products');
require $GO_LANGUAGE->get_language_file('products');
require $GO_THEME->theme_path . "header.inc";
$pro = new products();
$choice = new choice_list();
switch ($_REQUEST['task']) {
    case 'update':
        $i = (int) $pro->update_category($_POST['id'], $_POST['category'], $_POST['parent_id'], $_POST['template_id']);
        if ($i == $pro->err_duplicate) {
            alert(sprintf($sc_Duplicate, $sc_category));
        }
        if ($i == $pro->err_child_of_itsself) {
            alert($sc_ChildOfItsself);
        }
        break;
    case 'add':
        if ((int) $pro->add_category($_POST['category'], $_POST['parent_id'], $_POST['template_id']) == $pro->err_duplicate) {
            alert(sprintf($sc_Duplicate, $sc_category));
        }
        break;
    case 'delete':
        if (!$pro->delete_category($_POST['id'])) {
            alert(sprintf($sc_CannotDelete, $_POST['txt_name']));
        }
        break;