s4

diff s4-blog.sh @ 592:a50e83239b51

Add "enquete" mode
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 03 Dec 2019 11:41:39 +0900
parents 1e40019d1bb1
children 874e1f59263f
line diff
     1.1 --- a/s4-blog.sh	Fri Aug 16 14:01:43 2019 +0900
     1.2 +++ b/s4-blog.sh	Tue Dec 03 11:41:39 2019 +0900
     1.3 @@ -167,13 +167,14 @@
     1.4    fi
     1.5    blog_notify=`getvalbyid blog notify "$rowid"`
     1.6    blog_team=`blog_getteam "$rowid"`
     1.7 +  blog_mode=`getvalbyid blog mode "$rowid"`
     1.8    case "$blog_notify" in # "all", "admin" or "no" (or NULL)
     1.9      admin)	notifyto=adm ;;
    1.10      *)		notifyto="" ;;
    1.11    esac
    1.12 -  case `getvalbyid blog mode "$rowid"` in
    1.13 -    *quiz*|*close*)	f_exclusive=1 ;;
    1.14 -    *)			f_exclusive='' ;;
    1.15 +  case $blog_mode in
    1.16 +    *quiz*|*close*|*euquete*)	f_exclusive=1 ;;
    1.17 +    *)				f_exclusive='' ;;
    1.18    esac
    1.19  
    1.20    # err "SELECT id from $tbl where rowid=$rowid"
    1.21 @@ -189,12 +190,14 @@
    1.22  
    1.23    href="<a href=\"?editheading+$rowid\" accesskey=\"e\" title=\"E\"> 編集 </a>"
    1.24    if $ismem; then
    1.25 -    case `getvalbyid blog mode $rowid` in
    1.26 -      *report*|*quiz*)
    1.27 +    case $blog_mode in
    1.28 +      *report*|*quiz*|*euquete*)
    1.29  	href2="<a href=\"?lshandout+$rowid\" accesskey=\"l\" title=\"L\"> 提出状況 </a>"
    1.30  	;;
    1.31      esac
    1.32 -    href3="(<a href=\"?gethandout+$rowid\" accesskey=\"f\" title=\"F\">ファイル取得</a>)"
    1.33 +    if $isgrpadmin; then
    1.34 +      href3="(<a href=\"?gethandout+$rowid\" accesskey=\"f\" title=\"F\">ファイル取得</a>)"
    1.35 +    fi
    1.36    fi
    1.37    href4='<a href="#bottom" accesskey="b" title="B"> 末尾へ</a>'
    1.38    $isgrpadmin &&
    1.39 @@ -213,6 +216,7 @@
    1.40  	       WHEN 'report-closed' THEN 'レポート提出用(closed)'
    1.41  	       WHEN 'report-open' THEN 'レポート提出用(open)'
    1.42  	       WHEN 'quiz' THEN 'クイズ'
    1.43 +	       WHEN 'enquete' THEN '集計'
    1.44  	       ELSE ''
    1.45  	       END
    1.46  	FROM $ts WHERE id='$id' GROUP BY id;
    1.47 @@ -225,12 +229,12 @@
    1.48  	</table>
    1.49  	EOF
    1.50      case "$blogtype" in
    1.51 -      "クイズ")
    1.52 -	echo "クイズモードは本人と管理者の書き込みのみが表示されます。"
    1.53 +      "クイズ"|"集計")
    1.54 +	echo "${blogtype}モードは本人と管理者の書き込みのみが表示されます。"
    1.55  	;;
    1.56      esac | html p 'class="warn"'
    1.57      echo '<table class="blog_replies"> <!-- blog:blog_showentry() main table -->'
    1.58 -    if [ x"$blogtype" = x"クイズ" ]; then
    1.59 +    if [ x"$blogtype" = x"クイズ" -o x"$blogtype" = x"集計" ]; then
    1.60        if $isgroup; then
    1.61  	if ! isgrpowner "$user" "$blogowner"; then
    1.62  	  qgrp=`sqlquote "$blogowner"`
    1.63 @@ -574,7 +578,8 @@
    1.64  	/* WHERE owner=$qowner AND mode LIKE '%report%'; */
    1.65  	WHERE owner=$qowner
    1.66  		AND
    1.67 -	      (mode LIKE '%report%' OR mode LIKE '%quiz%');
    1.68 +	      (mode LIKE '%report%' OR mode LIKE '%quiz%'
    1.69 +	       OR mode LIKE '%enquete%');
    1.70  	 /* ↑これでレポート形式の blogid 一覧を得る */
    1.71  	EOF
    1.72    if [ -z "$CATCSV" ]; then
    1.73 @@ -664,40 +669,114 @@
    1.74    blog_writable $rid $user
    1.75    rc=$?		# =0: writable, $BLOG_NOTMEM bit set => not member
    1.76    if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then
    1.77 +    contenttype; echo
    1.78      echo "メンバー以外は利用できません。" | html p; return
    1.79    fi
    1.80 +  # Here, this blog is writable by $user
    1.81 +  owner=`getvalbyid blog owner $1`
    1.82 +  if [ x"$user" = x"$owner" ]; then
    1.83 +    : OK
    1.84 +  elif isgrpowner "$user" "$owner"; then
    1.85 +    : OK
    1.86 +  else
    1.87 +    contenttype; echo
    1.88 +    echo "板の所有者以外は利用できません。" | html p; return
    1.89 +  fi
    1.90 +  mode=`getvalbyid blog mode $1`
    1.91 +  copy2csv=false
    1.92 +  blogid=`getvalbyid blog id $1`
    1.93 +  isgroup "$owner" && isgroup=true || isgroup=false
    1.94 +  isgrpowner "$user" "$owner" && isgrpadmin=true || isgrpadmin=false
    1.95 +  
    1.96    i=0
    1.97    bd=$tmpd/archive.$$
    1.98    mkdir $bd
    1.99 -  query "select m.rowid,author,m.val from article a join article_m m\
   1.100 -	 on a.id=m.id where blogid=(select id from blog where rowid=$rid)\
   1.101 -	 and m.key in ('image', 'document', 'binary');" \
   1.102 -      | while IFS='|' read rowid author filename; do
   1.103 -	  err isfilereadable $user article_m $rowid
   1.104 -	  isfilereadable $user article_m $rowid || continue
   1.105 -	  err ok
   1.106 -	  i=$((i+1))
   1.107 -	  dir=`printf $bd/%03d $i`
   1.108 -	  mkdir $dir
   1.109 -	  query "select quote(bin) from article_m where rowid=$rowid;" \
   1.110 -	      | unhexize > $dir/$filename
   1.111 -	done
   1.112 -  if [ ! -d $bd/001 ]; then
   1.113 +  case "$mode" in
   1.114 +    *enquete*)
   1.115 +      copy2csv=true
   1.116 +      csvline=`getvalbyid blog heading $1 | grep "..*,." | head -1`
   1.117 +      # Create CSV-base table for questionnaire
   1.118 +      # If heading in blog_s has at least 1 CSV line,
   1.119 +      # we take the line as column list.
   1.120 +      # Otherwise we produce two column CSV as below:
   1.121 +      # USER,ANSWER
   1.122 +      if [ -n "$csvline" ]; then
   1.123 +	:
   1.124 +      else
   1.125 +	query <<-EOF
   1.126 +	  DROP TABLE IF EXISTS tmp_q;
   1.127 +	  CREATE TEMPORARY TABLE tmp_q(user text PRIMARY KEY, answer);
   1.128 +	EOF
   1.129 +      fi
   1.130 +  esac
   1.131 +  query <<-EOF |
   1.132 +	SELECT a.rowid, a.id artid, a.author, s.val
   1.133 +	FROM article a JOIN article_s s ON a.id=s.id
   1.134 +	WHERE blogid=(SELECT id FROM blog WHERE rowid=$rid);
   1.135 +	EOF
   1.136 +  while IFS='|' read rowid artid author text; do
   1.137 +    isfilereadable $user article_s $rowid || continue
   1.138 +    dir=`printf $bd/%d/%06d "$rid" "$rowid"`
   1.139 +    mkdir -p $dir
   1.140 +    echo "$author" > $dir/Author
   1.141 +    echo "$text" > $dir/Text
   1.142 +    if $copy2csv; then
   1.143 +      query "REPLACE INTO tmp_q SELECT author, val
   1.144 +	   FROM article a NATURAL JOIN article_s s
   1.145 +	   WHERE blogid='$blogid' AND key='text';"
   1.146 +    fi
   1.147 +    i=0
   1.148 +    query "SELECT m.rowid, m.val FROM article_m m \
   1.149 +	   WHERE id='$artid' AND m.key IN ('image', 'document', 'binary');" \
   1.150 +      | while IFS='|' read mrowid filename; do
   1.151 +          outfile=`printf "%s/%02d-%s" "$dir" $((++i)) "$filename"`
   1.152 +          query "SELECT quote(bin) FROM article_m WHERE rowid=$mrowid;" \
   1.153 +		| unhexize > $outfile
   1.154 +    done
   1.155 +  done
   1.156 +  # query "select m.rowid,a.id,author,m.val from article a join article_m m\
   1.157 +  # 	 on a.id=m.id where blogid=(select id from blog where rowid=$rid)\
   1.158 +  # 	 and m.key in ('image', 'document', 'binary');" \
   1.159 +  #     | while IFS='|' read rowid artid author filename; do
   1.160 +  # 	  err isfilereadable $user article_m $rowid
   1.161 +  # 	  isfilereadable $user article_m $rowid || continue
   1.162 +  # 	  err ok
   1.163 +  # 	  i=$((i+1))
   1.164 +  # 	  dir=`printf $bd/%03d $i`
   1.165 +  # 	  mkdir $dir
   1.166 +  # 	  echo "$author" > $dir/author
   1.167 +  # 	  query "select val from article_s where id=$artid;" > $dir/text
   1.168 +  # 	  query "select quote(bin) from article_m where rowid=$rowid;" \
   1.169 +  # 	      | unhexize > $dir/$filename
   1.170 +  # 	done
   1.171 +  if [ ! -d $bd/$rid ]; then
   1.172      contenttype; echo
   1.173      echo "取得できるファイルがありませんでした。" | html p
   1.174      return
   1.175    fi
   1.176 +
   1.177 +  if $copy2csv; then
   1.178 +    query <<-EOF > $bd/$rid/all-text-$rid.csv
   1.179 +	.mode csv
   1.180 +	.head 1
   1.181 +	SELECT * FROM tmp_q;
   1.182 +	.mode list
   1.183 +	.head 0
   1.184 +	EOF
   1.185 +  fi
   1.186 +  err "BDLIST: `ls -l $bd`"
   1.187 +  arcname=archive-$rid.tar.gz
   1.188    (cd $bd
   1.189 -   ## err cdto$bd; (pwd; ls -lFa) 1>&3
   1.190 -   tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
   1.191 -   err Creating tar archive "`ls -l archive.tar.gz`"
   1.192 +   # query() CANNOT BE used in this subshell
   1.193 +   tar zcf .archive.tar.gz $rid && mv .archive.tar.gz "$arcname"
   1.194 +   err Creating tar archive "`ls -l "$arcname"`"
   1.195    )
   1.196 -  arc=$bd/archive.tar.gz
   1.197 +  arcfile=$bd/$arcname
   1.198    echo "Content-type: application/x-gzip"
   1.199 -  echo "Content-Length: `cat $arc|wc -c`"
   1.200 -  echo "Content-Disposition: filename=\"archive.tar.gz\""
   1.201 +  echo "Content-Length: `cat $arcfile|wc -c`"
   1.202 +  echo "Content-Disposition: filename=\"$arcname\""
   1.203    echo
   1.204 -  cat $arc
   1.205 +  cat $arcfile
   1.206  }
   1.207  blogseen() {	# $1 = blogid
   1.208    blogid=${1%%[!0-9]*}