$listid = $_REQUEST['listid'] + 0;
    if ($listid == 0) {
        $cachelist = new cachelist(ID_NEW, $login->userid);
        $name_error = $cachelist->setNameAndVisibility($newlist_name, $newlist_public ? 2 : 0);
        if ($name_error) {
            $tpl->assign('name_error', $name_error);
        } else {
            $cachelist->setNode($opt['logic']['node']['id']);
            if ($cachelist->save()) {
                $cachelist->addCacheByID($cacheid);
                if ($newlist_watch) {
                    $cachelist->watch(true);
                }
            }
            $tpl->redirect('viewcache.php?cacheid=' . $cacheid);
        }
    } else {
        $cachelist = new cachelist($listid);
        if ($cachelist->exist()) {
            $cachelist->addCacheByID($cacheid);
        }
        $tpl->redirect('viewcache.php?cacheid=' . $cacheid);
    }
}
$tpl->assign('cachename', sql_value("SELECT `name` FROM `caches` WHERE `cache_id`='&1'", '', $cacheid));
$tpl->assign('cachelists', cachelist::getMyLists());
$tpl->assign('default_list', cachelist::getMyLastAddedToListId());
$tpl->assign('newlist_name', $newlist_name);
$tpl->assign('newlist_public', $newlist_public);
$tpl->assign('newlist_watch', $newlist_watch);
$tpl->display();