s4

view y4-cgi.sh @ 4:6822f4362bf9

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