s4

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/y4-cgi.sh	Sun Jul 19 13:51:41 2015 +0900
     1.3 @@ -0,0 +1,108 @@
     1.4 +#
     1.5 +# cgi functions
     1.6 +#
     1.7 +cgi_form() {
     1.8 +  # $1=stage
     1.9 +  : ${myname:?'Sure to set $myname to this script name'}
    1.10 +  cont=`cat`
    1.11 +  cat<<EOF
    1.12 +<form action="$myname" method="POST" enctype="multipart/form-data">
    1.13 +$cont
    1.14 +<input type="hidden" name="stage" value="$1">
    1.15 +<input type="submit" value="送信">
    1.16 +<input type="reset" value="リセット">
    1.17 +</form>
    1.18 +EOF
    1.19 +}
    1.20 +cgi_submit() {
    1.21 +  cat<<EOF
    1.22 +<input type="submit" value="$1">
    1.23 +EOF
    1.24 +}
    1.25 +cgi_radio() {
    1.26 +  echo "<input type=\"radio\" name=\"$1\" ${2:+value=\"$2\"} $3>"
    1.27 +}
    1.28 +cgi_hidden() {
    1.29 +  echo "<input type=\"hidden\" name=\"$1\" value=\"$2\" $3>"
    1.30 +}
    1.31 +cgi_passwd() {
    1.32 +  cat<<EOF
    1.33 +<table class="pswd">
    1.34 + <tr><td>現パスワード</td><td><input type="password" name="pswd"></td></tr>
    1.35 + <tr><td>新パスワード</td><td><input type="password" name="pswd1"></td></tr>
    1.36 + <tr><td>新パスワード(確認)</td><td><input type="password" name="pswd2"></td></tr>
    1.37 +</table>
    1.38 +EOF
    1.39 +}
    1.40 +cgi_text() {
    1.41 +  echo "<input type=\"text\" name=\"$1\" value=\"$2\" $3>"
    1.42 +}
    1.43 +cgi_textarea() {
    1.44 +  cat<<EOF
    1.45 +<textarea name="$1" $3>$2</textarea>
    1.46 +EOF
    1.47 +}
    1.48 +cgi_file() (			# In a subshell
    1.49 +  # $1=name $2=val(as filename) $3=args(if any)
    1.50 +  # Using global variable $dir
    1.51 +  if [ -s $dir/$2 -a -s $dir/$2.content-type ]; then
    1.52 +    file=$dir/$2
    1.53 +    bn=${file##*/}
    1.54 +    ct=`cat $dir/$2.content-type`
    1.55 +    data=`percenthex $file`
    1.56 +    icon="<img src=\"data:$ct,$data\">"
    1.57 +  fi
    1.58 +  cat<<EOF
    1.59 + ${icon}
    1.60 +<input type="file" name="$1" value="$bn" $3>
    1.61 +EOF
    1.62 +)
    1.63 +cgi_multi() (
    1.64 +  # $1=name $2=dir $3=func $4=args...
    1.65 +  # `dir' should contain $name.count and $name.N where N is 1 upto N
    1.66 +  i=1 name=$1 dir=$2 func=$3
    1.67 +  n=`cat $dir/$name.count`
    1.68 +  echo '<table class="text">'
    1.69 +  while [ $i -le $n ]; do
    1.70 +    file=$name.$i	ctf=$dir/$name.content-type
    1.71 +    vname=$file.`cat $dir/$file.rowid`
    1.72 +    if [ -s $ctf ]; then
    1.73 +      case `cat $ctf` in
    1.74 +	*:[Ii]mage:*)
    1.75 +	  
    1.76 +	;;
    1.77 +	
    1.78 +      esac
    1.79 +    fi
    1.80 +    val="`cat $dir/$file`"
    1.81 +    cat<<EOF
    1.82 + <tr><td>($i)</td><td>
    1.83 +<input class="action" type="radio" name="action.$vname" id="keep.$vname"
    1.84 + value="keep"><label for="keep.$vname">温存</label>
    1.85 +<input class="action" type="radio" name="action.$vname" id="edit.$vname"
    1.86 + value="edit"><label for="edit.$vname">編集</label>
    1.87 +<input class="action" type="radio" name="action.$vname" id="rm.$vname"
    1.88 + value="rm"><label for="rm.$vname">削除</label>
    1.89 +<label class="confirm">本当に消します<input class="confirm" type="checkbox"
    1.90 + name="confirm.$vname" value="yes">はい</label><br>
    1.91 +`$func $vname "$val" "$4"`<span>$val</span>
    1.92 +</td></tr>
    1.93 +EOF
    1.94 +    i=$((i+1))
    1.95 +  done
    1.96 +  cat<<EOF
    1.97 + <tr><td>(新規)</td><td>`$func $name "" "$4"`</td></tr>
    1.98 +</table>
    1.99 +EOF
   1.100 +)
   1.101 +# In these functions, $2 should be quoted because it can be null
   1.102 +cgi_multi_text() {
   1.103 +  cgi_multi $1 "$2" cgi_text "$3"
   1.104 +}
   1.105 +cgi_multi_textarea() {
   1.106 +  cgi_multi $1 "$2" cgi_textarea "$3"
   1.107 +}
   1.108 +cgi_multi_file() {
   1.109 +  # $1=name $2=val(filename)
   1.110 +  cgi_multi $1 "$2" cgi_file "$3"
   1.111 +}