s4

annotate s4-cgi.sh @ 206:c761ce8ff963

Quoting changed
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 25 Apr 2016 19:46:25 +0859
parents 3590c50e0cbd
children 36b6354de5cb
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@0 6 : ${myname:?'Sure to set $myname to this script name'}
yuuji@0 7 cont=`cat`
yuuji@0 8 cat<<EOF
yuuji@0 9 <form action="$myname" method="POST" enctype="multipart/form-data">
yuuji@0 10 $cont
yuuji@0 11 <input type="hidden" name="stage" value="$1">
yuuji@0 12 <input type="submit" value="送信">
yuuji@0 13 <input type="reset" value="リセット">
yuuji@0 14 </form>
yuuji@0 15 EOF
yuuji@0 16 }
yuuji@0 17 cgi_submit() {
yuuji@0 18 cat<<EOF
yuuji@0 19 <input type="submit" value="$1">
yuuji@0 20 EOF
yuuji@0 21 }
yuuji@29 22 cgi_reset() {
yuuji@29 23 cat<<EOF
yuuji@29 24 <input type="reset" value="$1">
yuuji@29 25 EOF
yuuji@29 26 }
yuuji@0 27 cgi_radio() {
yuuji@0 28 echo "<input type=\"radio\" name=\"$1\" ${2:+value=\"$2\"} $3>"
yuuji@0 29 }
yuuji@29 30 cgi_checkbox() {
yuuji@29 31 echo "<input type=\"checkbox\" name=\"$1\" ${2:+value=\"$2\"} $3>"
yuuji@29 32 }
yuuji@0 33 cgi_hidden() {
yuuji@0 34 echo "<input type=\"hidden\" name=\"$1\" value=\"$2\" $3>"
yuuji@0 35 }
yuuji@0 36 cgi_passwd() {
yuuji@0 37 cat<<EOF
yuuji@0 38 <table class="pswd">
yuuji@0 39 <tr><td>現パスワード</td><td><input type="password" name="pswd"></td></tr>
yuuji@0 40 <tr><td>新パスワード</td><td><input type="password" name="pswd1"></td></tr>
yuuji@0 41 <tr><td>新パスワード(確認)</td><td><input type="password" name="pswd2"></td></tr>
yuuji@0 42 </table>
yuuji@0 43 EOF
yuuji@0 44 }
yuuji@0 45 cgi_text() {
yuuji@0 46 echo "<input type=\"text\" name=\"$1\" value=\"$2\" $3>"
yuuji@0 47 }
yuuji@0 48 cgi_textarea() {
yuuji@0 49 cat<<EOF
yuuji@0 50 <textarea name="$1" $3>$2</textarea>
yuuji@0 51 EOF
yuuji@0 52 }
yuuji@0 53 cgi_file() ( # In a subshell
yuuji@0 54 # $1=name $2=val(as filename) $3=args(if any)
yuuji@0 55 # Using global variable $dir
yuuji@0 56 if [ -s $dir/$2 -a -s $dir/$2.content-type ]; then
yuuji@0 57 file=$dir/$2
yuuji@0 58 bn=${file##*/}
yuuji@0 59 ct=`cat $dir/$2.content-type`
yuuji@0 60 data=`percenthex $file`
yuuji@0 61 icon="<img src=\"data:$ct,$data\">"
yuuji@0 62 fi
yuuji@0 63 cat<<EOF
yuuji@0 64 ${icon}
yuuji@0 65 <input type="file" name="$1" value="$bn" $3>
yuuji@0 66 EOF
yuuji@0 67 )
yuuji@0 68 cgi_multi() (
yuuji@0 69 # $1=name $2=dir $3=func $4=args...
yuuji@0 70 # `dir' should contain $name.count and $name.N where N is 1 upto N
yuuji@0 71 i=1 name=$1 dir=$2 func=$3
yuuji@0 72 n=`cat $dir/$name.count`
yuuji@0 73 echo '<table class="text">'
yuuji@0 74 while [ $i -le $n ]; do
yuuji@0 75 file=$name.$i ctf=$dir/$name.content-type
yuuji@0 76 vname=$file.`cat $dir/$file.rowid`
yuuji@0 77 if [ -s $ctf ]; then
yuuji@0 78 case `cat $ctf` in
yuuji@0 79 *:[Ii]mage:*)
yuuji@0 80
yuuji@0 81 ;;
yuuji@0 82
yuuji@0 83 esac
yuuji@0 84 fi
yuuji@0 85 val="`cat $dir/$file`"
yuuji@0 86 cat<<EOF
yuuji@0 87 <tr><td>($i)</td><td>
yuuji@0 88 <input class="action" type="radio" name="action.$vname" id="keep.$vname"
yuuji@0 89 value="keep"><label for="keep.$vname">温存</label>
yuuji@0 90 <input class="action" type="radio" name="action.$vname" id="edit.$vname"
yuuji@140 91 value="edit"><label for="edit.$vname">修正</label>
yuuji@0 92 <input class="action" type="radio" name="action.$vname" id="rm.$vname"
yuuji@0 93 value="rm"><label for="rm.$vname">削除</label>
yuuji@0 94 <label class="confirm">本当に消します<input class="confirm" type="checkbox"
yuuji@0 95 name="confirm.$vname" value="yes">はい</label><br>
yuuji@0 96 `$func $vname "$val" "$4"`<span>$val</span>
yuuji@0 97 </td></tr>
yuuji@0 98 EOF
yuuji@0 99 i=$((i+1))
yuuji@0 100 done
yuuji@0 101 cat<<EOF
yuuji@0 102 <tr><td>(新規)</td><td>`$func $name "" "$4"`</td></tr>
yuuji@0 103 </table>
yuuji@0 104 EOF
yuuji@0 105 )
yuuji@0 106 # In these functions, $2 should be quoted because it can be null
yuuji@0 107 cgi_multi_text() {
yuuji@0 108 cgi_multi $1 "$2" cgi_text "$3"
yuuji@0 109 }
yuuji@0 110 cgi_multi_textarea() {
yuuji@0 111 cgi_multi $1 "$2" cgi_textarea "$3"
yuuji@0 112 }
yuuji@0 113 cgi_multi_file() {
yuuji@0 114 # $1=name $2=val(filename)
yuuji@0 115 cgi_multi $1 "$2" cgi_file "$3"
yuuji@0 116 }
yuuji@59 117
yuuji@59 118 html() {
yuuji@59 119 echo "<$*>"
yuuji@59 120 cat
yuuji@59 121 echo "</$1>"
yuuji@59 122 }