hesk_dbConnect();
hesk_isLoggedIn();
/* Check permissions for this feature */
hesk_checkPermission('can_man_cat');
// Possible priorities
$priorities = array(3 => array('value' => 3, 'text' => $hesklang['low'], 'formatted' => $hesklang['low']), 2 => array('value' => 2, 'text' => $hesklang['medium'], 'formatted' => '<font class="medium">' . $hesklang['medium'] . '</font>'), 1 => array('value' => 1, 'text' => $hesklang['high'], 'formatted' => '<font class="important">' . $hesklang['high'] . '</font>'), 0 => array('value' => 0, 'text' => $hesklang['critical'], 'formatted' => '<font class="critical">' . $hesklang['critical'] . '</font>'));
/* What should we do? */
if ($action = hesk_REQUEST('a')) {
    if ($action == 'linkcode') {
        generate_link_code();
    } elseif (defined('HESK_DEMO')) {
        hesk_process_messages($hesklang['ddemo'], 'manage_categories.php', 'NOTICE');
    } elseif ($action == 'new') {
        new_cat();
    } elseif ($action == 'rename') {
        rename_cat();
    } elseif ($action == 'remove') {
        remove();
    } elseif ($action == 'order') {
        order_cat();
    } elseif ($action == 'autoassign') {
        toggle_autoassign();
    } elseif ($action == 'type') {
        toggle_type();
    } elseif ($action == 'priority') {
        change_priority();
    } elseif ($action == 'manager') {
        change_manager();
    }
}
/* Print header */
            reply($_REQUEST["id"], $_REQUEST["corps"]);
            break;
        case "close":
            close($_REQUEST["id"]);
            break;
        case "open":
            open($_REQUEST["id"]);
            break;
        case "main_pref":
            main_pref();
            break;
        case "pref_insert_cat":
            insert_cat($_REQUEST['categorie_insert'], $_REQUEST['ordre_insert']);
            break;
        case "pref_rename_cat":
            rename_cat($_REQUEST['categorie_old'], $_REQUEST['categorie_rename'], $_REQUEST['ordre_rename']);
            break;
        case "pref_delete_cat":
            delete_cat($_REQUEST['categorie_delete']);
            break;
        default:
            main();
            break;
    }
} else {
    if ($level_admin == -1) {
        echo "<div class=\"notification error png_bg\">\n" . "<div>\n" . "<br /><br /><div style=\"text-align: center;\">" . _MODULEOFF . "<br /><br /><a href=\"javascript:history.back()\"><b>" . _BACK . "</b></a></div><br /><br />" . "</div>\n" . "</div>\n";
    } else {
        if ($visiteur > 1) {
            echo "<div class=\"notification error png_bg\">\n" . "<div>\n" . "<br /><br /><div style=\"text-align: center;\">" . _NOENTRANCE . "<br /><br /><a href=\"javascript:history.back()\"><b>" . _BACK . "</b></a></div><br /><br />" . "</div>\n" . "</div>\n";
        } else {