+if [ -z "$QRYID" -a -z "$COKID" ]; then
+ printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
+
+ cat <<-EOF
+ <!DOCTYPE HTML>
+ <HTML><head>
+ <title>Bookman - New Collection</title>
+ </head><body id="newcollection">
+ <h1>You have not yet set up a collection on this server.</h1>
+ Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
+ </body></HTML>
+ EOF
+ exit 0
+elif ! [ -d "users/${QRYID}" ]; then
+ printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL"
+ printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
+
+ cat <<-EOF
+ <!DOCTYPE HTML>
+ <HTML><head>
+ <title>Bookman - 404</title>
+ </head><body id="missingcollection">
+ <h1>The collection you requested does not exist on this server.</h1>
+ Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
+ </body></HTML>
+ EOF
+ exit 0
+fi
+
+list_bookmarks(){
+ fid="$1"
+ bmodify="$(GET bmodify |checkid)"
+
+ tail -n+2 "${BDB}/${fid}.bm" \
+ | while read bid name url; do
+ if [ "${bid}" = "$bmodify" ]; then
+ cat <<-EOF
+ <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modbookmark">
+ <input type="hidden" name="bid" value="${bid}" />
+ <input type="text" name="name" value="${name}")" placeholder="Name" />
+ <input type="text" name="url" value="${url}")" placeholder="URL" />
+ <button type="submit">Modify</button>
+ </form>
+ EOF
+ else
+ cat <<-EOF
+ <div class="bookmark">
+ <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&bmodify=${bid}">Modify</a>
+ <a class="link" href="${url}")"><img src="${BDB}/favicons/${bid}.ico"/>${name}</a>
+ </div>
+ EOF
+ fi
+ done
+}
+
+foldermod(){
+ fmodify="$(GET fmodify |checkid )"
+ fdelete="$(GET fdelete |checkid )"
+ fmove="$(GET fmove |checkid )"
+
+ if [ -n "$fmodify" ]; then
+ read fid fname order <"${BDB}/${fmodify}.bm"
+ cat <<-EOF
+ <form class="modfolder rename" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
+ <h1>Rename Folder: ${fname}</h1>
+ <input type="hidden" name="fid" value="${fid}" />
+ <label class="tab">Rename</label>
+ <a class="tab"
+ href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a>
+ <a class="tab"
+ href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
+ <input type="text" name="name" value="${fname}" />
+ <button type="submit" name="control" value="confirm">OK</button>
+ <button type="submit" name="control" value="cancel">Cancel</button>
+ </form>
+ EOF
+ elif [ -n "$fdelete" ]; then
+ read fid fname order <"${BDB}/${fdelete}.bm"
+ cat <<-EOF
+ <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=delfolder">
+ <h1>Delete Folder: ${fname}</h1>
+ <input type="hidden" name="fid" value="${fid}" />
+ <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a>
+ <label class="tab">Delete</label>
+ <a class="tab"
+ href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
+ <label>Pass Bookmarks on to:</label>
+ <select name="target">
+ $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
+ <option value="____________">(none)</option>
+ </select>
+ <button type="submit" name="control" value="confirm">OK</button>
+ <button type="submit" name="control" value="cancel">Cancel</button>
+ </form>
+ EOF
+ elif [ -n "$fmove" ]; then
+ read fid fname order <"${BDB}/${fmove}.bm"
+ cat <<-EOF
+ <form class="modfolder move" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
+ <h1>Move Folder: ${fname}</h1>
+ <input type="hidden" name="fid" value="${fid}" />
+ <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a>
+ <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a>
+ <label class="tab">Move</label>
+ <label>Move before folder:</label>
+ <select name="target">
+ $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
+ <option value="____________">(last)</option>
+ </select>
+ <button type="submit" name="control" value="confirm">OK</button>
+ <button type="submit" name="control" value="cancel">Cancel</button>
+ </form>
+ EOF
+ fi
+}
+
+show_folders(){
+ list_folders \
+ | while read fid fname order; do
+ cat <<-EOF
+ <section class="folder" id="${fid}">
+ <h1>${fname}</h1>
+ <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Modify</a>
+ $(list_bookmarks "$fid")
+ <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=newbookmark">
+ <input type="hidden" name="fid" value="${fid}" />
+ <input type="text" name="name" value="" placeholder="Name" />
+ <input type="text" name="url" value="" placeholder="URL" />
+ <button type="submit">New Bookmark</button>
+ </form>
+ </section>
+ EOF
+ done
+}
+
+printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
+cat <<EOF
+<!DOCTYPE HTML>
+<HTML><head>
+ <title>Bookman - Your Collection</title>
+ <link rel="stylesheet" type="text/css" href="bookmarks.css" />
+</head><body id="collection">
+ $(foldermod)
+ $(show_folders)
+ <form class="newfolder" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=newfolder">
+ <input type="text" name="name" value="" placeholder="New Folder" />
+ <button type="submit">New</button>
+ </form>
+</body></HTML>
+EOF
+
+#set filetype=sh