tallow voting by selecting items in ranking - gph-poll - a dynamic poll for geomyidae(8)
 (HTM) git clone git://src.adamsgaard.dk/gph-poll
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit afc543e950f5de12d04241690ddcc9e555ce744e
 (DIR) parent f376c25d72b12a1a4db4f0343bd00af1915a5504
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Tue, 30 Mar 2021 13:54:08 +0200
       
       allow voting by selecting items in ranking
       
       Diffstat:
         M index.dcgi                          |      30 +++++++++++++++++++-----------
       
       1 file changed, 19 insertions(+), 11 deletions(-)
       ---
 (DIR) diff --git a/index.dcgi b/index.dcgi
       t@@ -9,12 +9,14 @@ polldb="poll.db"
        polldescription="description.txt"
        polldir="poll"
        
       -# TODO: Lock access for database trimming.
       -if [ -n "${search}" ]; then
       +if [ -n "${search}" -o "${arguments}" ]; then
                tmpdb="$(mktemp)"
       -        tail -n 99 "${polldb}" > "${tmpdb}"
       -        printf "%s\n" "${search}" | expand -t 4 >> "${tmpdb}"
       -        mv "${tmpdb}" "${polldb}"
       +        if [ -r "$polldb" ]; then
       +                tail -n 99 "${polldb}" > "${tmpdb}"
       +        fi
       +        printf "%s%s\n" "${search}" "${arguments}" \
       +                | expand -t 4 >> "${tmpdb}"
       +        cat "${tmpdb}" > "${polldb}"
        fi
        
        printf '\n'
       t@@ -23,11 +25,17 @@ if [ -r "$polldescription" ]; then
                cat "$polldescription"
        fi
        
       -printf '[7|Your choice: _______|/%s|server|port]\n\n' "$polldir"
       -printf 'Ranking:\n\n'
       +if [ -r "$polldb" ]; then
       +        printf '\nRanking:\n\n'
       +        sort "${polldb}" \
       +                | uniq -c \
       +                | sort -nr \
       +                | while read -r count option; do 
       +                printf '[1|(%s) %s|/%s?%s|server|port]\n' \
       +                        "$count" "$option" "$polldir" "$option" 
       +        done
       +fi
        
       -sort "${polldb}" \
       -        | uniq -c \
       -        | sort -nr
       +printf '\n[7|Add new choice: _______|/%s|server|port]\n' "$polldir"
        
       -printf '\n[1|<< back|/|server|port]\r\n'
       +printf '\n[1|<< back|/|server|port]\n'