s4

annotate s4-cgi.sh @ 826:f2d69fb3e038

Link to group list in other world with kwd
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 21 Jun 2020 10:08:12 +0900
parents 9c54908814be
children b3516ee2bb4d
rev   line source
yuuji@0 1 #
yuuji@0 2 # cgi functions
yuuji@0 3 #
yuuji@0 4 cgi_form() {
yuuji@0 5 # $1=stage
yuuji@606 6 # $METHOD := method, defaults to "POST"
yuuji@0 7 : ${myname:?'Sure to set $myname to this script name'}
yuuji@0 8 cont=`cat`
yuuji@0 9 cat<<EOF
yuuji@606 10 <form action="$myname" method="${METHOD:-POST}" enctype="multipart/form-data">
yuuji@0 11 $cont
yuuji@0 12 <input type="hidden" name="stage" value="$1">
yuuji@702 13 <input type="submit" value="送信" title="COMMIT">
yuuji@702 14 <input type="reset" value="リセット" title="Reset">
yuuji@0 15 </form>
yuuji@0 16 EOF
yuuji@0 17 }
yuuji@0 18 cgi_submit() {
yuuji@0 19 cat<<EOF
yuuji@0 20 <input type="submit" value="$1">
yuuji@0 21 EOF
yuuji@0 22 }
yuuji@29 23 cgi_reset() {
yuuji@29 24 cat<<EOF
yuuji@29 25 <input type="reset" value="$1">
yuuji@29 26 EOF
yuuji@29 27 }
yuuji@0 28 cgi_radio() {
yuuji@0 29 echo "<input type=\"radio\" name=\"$1\" ${2:+value=\"$2\"} $3>"
yuuji@0 30 }
yuuji@29 31 cgi_checkbox() {
yuuji@29 32 echo "<input type=\"checkbox\" name=\"$1\" ${2:+value=\"$2\"} $3>"
yuuji@29 33 }
yuuji@0 34 cgi_hidden() {
yuuji@0 35 echo "<input type=\"hidden\" name=\"$1\" value=\"$2\" $3>"
yuuji@0 36 }
yuuji@0 37 cgi_passwd() {
yuuji@0 38 cat<<EOF
yuuji@0 39 <table class="pswd">
yuuji@0 40 <tr><td>現パスワード</td><td><input type="password" name="pswd"></td></tr>
yuuji@0 41 <tr><td>新パスワード</td><td><input type="password" name="pswd1"></td></tr>
yuuji@0 42 <tr><td>新パスワード(確認)</td><td><input type="password" name="pswd2"></td></tr>
yuuji@0 43 </table>
yuuji@0 44 EOF
yuuji@0 45 }
yuuji@0 46 cgi_text() {
yuuji@326 47 _v=`echo "$2"|htmlescape`
yuuji@326 48 echo "<input type=\"text\" name=\"$1\" value=\"$_v\" $3>"
yuuji@0 49 }
yuuji@0 50 cgi_textarea() {
yuuji@326 51 _v=`echo "$2"|htmlescape`
yuuji@0 52 cat<<EOF
yuuji@326 53 <textarea name="$1" $3>$_v</textarea>
yuuji@0 54 EOF
yuuji@0 55 }
yuuji@0 56 cgi_file() ( # In a subshell
yuuji@0 57 # $1=name $2=val(as filename) $3=args(if any)
yuuji@326 58 ## err cgi_file: \$1=$1 \$2=$2 \$3="[$3]"
yuuji@0 59 # Using global variable $dir
yuuji@326 60 if [ -n "$2" -a -s "$dir/$2" ]; then
yuuji@0 61 file=$dir/$2
yuuji@0 62 bn=${file##*/}
yuuji@326 63 ct=`file --mime-type - < "$dir/$2" | cut -d' ' -f2`
yuuji@326 64 data=`percenthex "$file"`
yuuji@0 65 icon="<img src=\"data:$ct,$data\">"
yuuji@0 66 fi
yuuji@0 67 cat<<EOF
yuuji@0 68 ${icon}
yuuji@0 69 <input type="file" name="$1" value="$bn" $3>
yuuji@0 70 EOF
yuuji@0 71 )
yuuji@0 72 cgi_multi() (
yuuji@0 73 # $1=name $2=dir $3=func $4=args...
yuuji@0 74 # `dir' should contain $name.count and $name.N where N is 1 upto N
yuuji@0 75 i=1 name=$1 dir=$2 func=$3
yuuji@0 76 n=`cat $dir/$name.count`
yuuji@0 77 echo '<table class="text">'
yuuji@0 78 while [ $i -le $n ]; do
yuuji@326 79 file=$name.$i
yuuji@326 80 vname=$file.`cat "$dir/$file.rowid"`
yuuji@326 81 val="`cat $dir/$file`"
yuuji@0 82 cat<<EOF
yuuji@0 83 <tr><td>($i)</td><td>
yuuji@0 84 <input class="action" type="radio" name="action.$vname" id="keep.$vname"
yuuji@702 85 value="keep"><label for="keep.$vname" title="Keep">温存</label>
yuuji@0 86 <input class="action" type="radio" name="action.$vname" id="edit.$vname"
yuuji@702 87 value="edit"><label for="edit.$vname" title="Replace">修正</label>
yuuji@0 88 <input class="action" type="radio" name="action.$vname" id="rm.$vname"
yuuji@702 89 value="rm"><label for="rm.$vname" title="Remove">削除</label>
yuuji@702 90 <label class="confirm" title="OK?">本当に消します<input class="confirm" type="checkbox"
yuuji@0 91 name="confirm.$vname" value="yes">はい</label><br>
yuuji@0 92 `$func $vname "$val" "$4"`<span>$val</span>
yuuji@0 93 </td></tr>
yuuji@0 94 EOF
yuuji@0 95 i=$((i+1))
yuuji@0 96 done
yuuji@0 97 cat<<EOF
yuuji@0 98 <tr><td>(新規)</td><td>`$func $name "" "$4"`</td></tr>
yuuji@0 99 </table>
yuuji@0 100 EOF
yuuji@0 101 )
yuuji@0 102 # In these functions, $2 should be quoted because it can be null
yuuji@0 103 cgi_multi_text() {
yuuji@0 104 cgi_multi $1 "$2" cgi_text "$3"
yuuji@0 105 }
yuuji@0 106 cgi_multi_textarea() {
yuuji@0 107 cgi_multi $1 "$2" cgi_textarea "$3"
yuuji@0 108 }
yuuji@0 109 cgi_multi_file() {
yuuji@0 110 # $1=name $2=val(filename)
yuuji@0 111 cgi_multi $1 "$2" cgi_file "$3"
yuuji@0 112 }
yuuji@222 113 cgi_datalist_h() {
yuuji@222 114 # $1=id $2...=hexed-args
yuuji@222 115 echo "<datalist id=\"$1\">"
yuuji@222 116 shift
yuuji@222 117 for i; do
yuuji@326 118 echo "<option value=\"`echo "$i"|unhexize|htmlescape`\"></option>"
yuuji@222 119 done
yuuji@222 120 echo "</datalist>"
yuuji@222 121 }
yuuji@222 122 cgi_select_h() {
yuuji@222 123 # $1=name $2...=hexed-args
yuuji@675 124 echo "<select name=\"$1\"${CGI_SELECT_MULTI:+ multiple} id=\"$1\">"
yuuji@222 125 shift
yuuji@222 126 for i; do
yuuji@222 127 echo "<option>`echo \"$i\"|unhexize|htmlescape`</option>"
yuuji@222 128 done
yuuji@222 129 echo "</select>"
yuuji@222 130 }
yuuji@59 131
yuuji@59 132 html() {
yuuji@59 133 echo "<$*>"
yuuji@59 134 cat
yuuji@59 135 echo "</$1>"
yuuji@59 136 }