$qs = "SELECT category_id, category_name FROM phph_categories ";
    if (!empty($ccid)) {
        $qs .= "WHERE category_parent = {$ccid} ";
    } else {
        $qs .= "WHERE category_parent IS NULL ";
    }
    $qs .= "ORDER BY category_order";
    $q = $db->prepare($qs);
    $res = $db->execute($q);
    if (PEAR::isError($res)) {
        die($res->getMessage());
    }
    while ($res->fetchInto($row)) {
        $name = "";
        if ($level > 0) {
            for ($i = 0; $i < $level; $i++) {
                $name .= "---";
            }
            $name .= " ";
        }
        $name .= $row['category_name'];
        $categories[$row['category_id']] = $name;
        fill_category_tree(&$categories, $row['category_id'], $level + 1);
    }
}
$categories = array();
fill_category_tree(&$categories, "", 0);
$smarty->assign('categories', $categories);
$smarty->display('upload-form.tpl');
HTML::endBODY();
HTML::endHTML();
if ($action == 'view') {
    action_view();
} elseif ($action == "categories") {
    action_categories();
} elseif ($action == "category") {
    action_category();
} elseif ($action == "user") {
    action_user();
} elseif ($action == "register") {
    action_register();
} elseif ($action == "activate") {
    action_activate();
} elseif ($action == "login") {
    action_login();
} elseif ($action == "postcomment") {
    action_postcomment();
} elseif ($action == "subscribe") {
    action_subscribe();
} elseif ($action == "unsubscribe") {
    action_unsubscribe();
} else {
    $action = "index";
    $template = $action;
    action_index();
}
HTML::startHTML();
HTML::head($smarty->get_template_vars('page_title'));
HTML::startBODY();
$smarty->display($templates[$template]);
HTML::endBODY();
HTML::endHTML();