s4

annotate s4-cgi.sh @ 893:c1a5d137740d

Display momentary information of frozen state change
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 26 Dec 2020 15:17:56 +0900
parents b3516ee2bb4d
children 5d70fa029f8d
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@837 60 case "$3" in
yuuji@837 61 *multiple*)
yuuji@837 62 onemore='<button type="button" id="morefile" title="More attachment file">添付追加</button>'
yuuji@837 63 multiple="$nl$onemore"
yuuji@837 64 ;;
yuuji@837 65 esac
yuuji@326 66 if [ -n "$2" -a -s "$dir/$2" ]; then
yuuji@0 67 file=$dir/$2
yuuji@0 68 bn=${file##*/}
yuuji@326 69 ct=`file --mime-type - < "$dir/$2" | cut -d' ' -f2`
yuuji@326 70 data=`percenthex "$file"`
yuuji@0 71 icon="<img src=\"data:$ct,$data\">"
yuuji@0 72 fi
yuuji@0 73 cat<<EOF
yuuji@0 74 ${icon}
yuuji@837 75 <input type="file" name="$1" value="$bn" $3>$multiple
yuuji@0 76 EOF
yuuji@0 77 )
yuuji@0 78 cgi_multi() (
yuuji@0 79 # $1=name $2=dir $3=func $4=args...
yuuji@0 80 # `dir' should contain $name.count and $name.N where N is 1 upto N
yuuji@0 81 i=1 name=$1 dir=$2 func=$3
yuuji@837 82 argnomulti=`echo "$4"|sed 's/multiple//'` # No multiple for Replaced entres
yuuji@0 83 n=`cat $dir/$name.count`
yuuji@836 84 case "$func" in
yuuji@836 85 *file) addrename=yes ;;
yuuji@836 86 esac
yuuji@0 87 echo '<table class="text">'
yuuji@0 88 while [ $i -le $n ]; do
yuuji@326 89 file=$name.$i
yuuji@326 90 vname=$file.`cat "$dir/$file.rowid"`
yuuji@326 91 val="`cat $dir/$file`"
yuuji@837 92 if [ -n "$addrename" ]; then
yuuji@837 93 # ${var:+..} cannot be used for inside-quotes incompatibility of shells
yuuji@837 94 ren1="<input class=\"action\" type=\"radio\" name=\"action.$vname\"
yuuji@837 95 id=\"mv.$vname\" value=\"mv\"><label for=\"mv.$vname\"
yuuji@837 96 title=\"Rename\">名前変更</label>"
yuuji@837 97 ren2="<input class=\"mv\" type=\"text\" name=\"mv.$vname\" value=\"$val\">"
yuuji@837 98 fi
yuuji@0 99 cat<<EOF
yuuji@0 100 <tr><td>($i)</td><td>
yuuji@0 101 <input class="action" type="radio" name="action.$vname" id="keep.$vname"
yuuji@702 102 value="keep"><label for="keep.$vname" title="Keep">温存</label>
yuuji@0 103 <input class="action" type="radio" name="action.$vname" id="edit.$vname"
yuuji@702 104 value="edit"><label for="edit.$vname" title="Replace">修正</label>
yuuji@837 105 $ren1
yuuji@0 106 <input class="action" type="radio" name="action.$vname" id="rm.$vname"
yuuji@702 107 value="rm"><label for="rm.$vname" title="Remove">削除</label>
yuuji@702 108 <label class="confirm" title="OK?">本当に消します<input class="confirm" type="checkbox"
yuuji@0 109 name="confirm.$vname" value="yes">はい</label><br>
yuuji@837 110 `$func $vname "$val" "$argnomulti"`<span>$val</span>
yuuji@837 111 $ren2
yuuji@0 112 </td></tr>
yuuji@0 113 EOF
yuuji@0 114 i=$((i+1))
yuuji@0 115 done
yuuji@0 116 cat<<EOF
yuuji@0 117 <tr><td>(新規)</td><td>`$func $name "" "$4"`</td></tr>
yuuji@0 118 </table>
yuuji@0 119 EOF
yuuji@0 120 )
yuuji@0 121 # In these functions, $2 should be quoted because it can be null
yuuji@0 122 cgi_multi_text() {
yuuji@836 123 cgi_multi $1 "$2" cgi_text "$3 class=\"edit\""
yuuji@0 124 }
yuuji@0 125 cgi_multi_textarea() {
yuuji@836 126 cgi_multi $1 "$2" cgi_textarea "$3 class=\"edit\""
yuuji@0 127 }
yuuji@0 128 cgi_multi_file() {
yuuji@0 129 # $1=name $2=val(filename)
yuuji@836 130 cgi_multi $1 "$2" cgi_file "$3 class=\"edit\""
yuuji@0 131 }
yuuji@222 132 cgi_datalist_h() {
yuuji@222 133 # $1=id $2...=hexed-args
yuuji@222 134 echo "<datalist id=\"$1\">"
yuuji@222 135 shift
yuuji@222 136 for i; do
yuuji@326 137 echo "<option value=\"`echo "$i"|unhexize|htmlescape`\"></option>"
yuuji@222 138 done
yuuji@222 139 echo "</datalist>"
yuuji@222 140 }
yuuji@222 141 cgi_select_h() {
yuuji@222 142 # $1=name $2...=hexed-args
yuuji@675 143 echo "<select name=\"$1\"${CGI_SELECT_MULTI:+ multiple} id=\"$1\">"
yuuji@222 144 shift
yuuji@222 145 for i; do
yuuji@222 146 echo "<option>`echo \"$i\"|unhexize|htmlescape`</option>"
yuuji@222 147 done
yuuji@222 148 echo "</select>"
yuuji@222 149 }
yuuji@59 150
yuuji@59 151 html() {
yuuji@59 152 echo "<$*>"
yuuji@59 153 cat
yuuji@59 154 echo "</$1>"
yuuji@59 155 }