# HG changeset patch # User HIROSE Yuuji # Date 1575340899 -32400 # Node ID a50e83239b512adc5073e67aa6e2367812c16276 # Parent 3bfd1ac6fbf343ebdf5bf884b4d86542a6e94278 Add "enquete" mode diff -r 3bfd1ac6fbf3 -r a50e83239b51 examples/sns/form/blog.def --- a/examples/sns/form/blog.def Sat Sep 07 07:41:52 2019 +0900 +++ b/examples/sns/form/blog.def Tue Dec 03 11:41:39 2019 +0900 @@ -1,5 +1,5 @@ シリアル:id:p:serial: -用途:mode:s:select:普通の掲示板=normal レポート提出用(相互に参照可能)=report-open レポート提出用(添付ファイルは管理者のみ参照可能)=report-closed クイズ(管理者以外は本人の記事のみ見える)=quiz +用途:mode:s:select:普通の掲示板=normal レポート提出用(相互に参照可能)=report-open レポート提出用(添付ファイルは管理者のみ参照可能)=report-closed クイズ(管理者以外は本人の記事のみ見える)=quiz 集計=enquete タイトル:title:s:text:maxlength="200" コメント書込通知:notify:s:select:管理者のみに通知(グループの場合のみ)=admin 所有者全員に通知=all しない=no 稼動状態:state:s:select:稼動=active 凍結(新規書込停止)=frozen diff -r 3bfd1ac6fbf3 -r a50e83239b51 s4-blog.sh --- a/s4-blog.sh Sat Sep 07 07:41:52 2019 +0900 +++ b/s4-blog.sh Tue Dec 03 11:41:39 2019 +0900 @@ -167,13 +167,14 @@ fi blog_notify=`getvalbyid blog notify "$rowid"` blog_team=`blog_getteam "$rowid"` + blog_mode=`getvalbyid blog mode "$rowid"` case "$blog_notify" in # "all", "admin" or "no" (or NULL) admin) notifyto=adm ;; *) notifyto="" ;; esac - case `getvalbyid blog mode "$rowid"` in - *quiz*|*close*) f_exclusive=1 ;; - *) f_exclusive='' ;; + case $blog_mode in + *quiz*|*close*|*euquete*) f_exclusive=1 ;; + *) f_exclusive='' ;; esac # err "SELECT id from $tbl where rowid=$rowid" @@ -189,12 +190,14 @@ href=" 編集 " if $ismem; then - case `getvalbyid blog mode $rowid` in - *report*|*quiz*) + case $blog_mode in + *report*|*quiz*|*euquete*) href2=" 提出状況 " ;; esac - href3="(ファイル取得)" + if $isgrpadmin; then + href3="(ファイル取得)" + fi fi href4=' 末尾へ' $isgrpadmin && @@ -213,6 +216,7 @@ WHEN 'report-closed' THEN 'レポート提出用(closed)' WHEN 'report-open' THEN 'レポート提出用(open)' WHEN 'quiz' THEN 'クイズ' + WHEN 'enquete' THEN '集計' ELSE '' END FROM $ts WHERE id='$id' GROUP BY id; @@ -225,12 +229,12 @@ EOF case "$blogtype" in - "クイズ") - echo "クイズモードは本人と管理者の書き込みのみが表示されます。" + "クイズ"|"集計") + echo "${blogtype}モードは本人と管理者の書き込みのみが表示されます。" ;; esac | html p 'class="warn"' echo '' - if [ x"$blogtype" = x"クイズ" ]; then + if [ x"$blogtype" = x"クイズ" -o x"$blogtype" = x"集計" ]; then if $isgroup; then if ! isgrpowner "$user" "$blogowner"; then qgrp=`sqlquote "$blogowner"` @@ -574,7 +578,8 @@ /* WHERE owner=$qowner AND mode LIKE '%report%'; */ WHERE owner=$qowner AND - (mode LIKE '%report%' OR mode LIKE '%quiz%'); + (mode LIKE '%report%' OR mode LIKE '%quiz%' + OR mode LIKE '%enquete%'); /* ↑これでレポート形式の blogid 一覧を得る */ EOF if [ -z "$CATCSV" ]; then @@ -664,40 +669,114 @@ blog_writable $rid $user rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then + contenttype; echo echo "メンバー以外は利用できません。" | html p; return fi + # Here, this blog is writable by $user + owner=`getvalbyid blog owner $1` + if [ x"$user" = x"$owner" ]; then + : OK + elif isgrpowner "$user" "$owner"; then + : OK + else + contenttype; echo + echo "板の所有者以外は利用できません。" | html p; return + fi + mode=`getvalbyid blog mode $1` + copy2csv=false + blogid=`getvalbyid blog id $1` + isgroup "$owner" && isgroup=true || isgroup=false + isgrpowner "$user" "$owner" && isgrpadmin=true || isgrpadmin=false + i=0 bd=$tmpd/archive.$$ mkdir $bd - query "select m.rowid,author,m.val from article a join article_m m\ - on a.id=m.id where blogid=(select id from blog where rowid=$rid)\ - and m.key in ('image', 'document', 'binary');" \ - | while IFS='|' read rowid author filename; do - err isfilereadable $user article_m $rowid - isfilereadable $user article_m $rowid || continue - err ok - i=$((i+1)) - dir=`printf $bd/%03d $i` - mkdir $dir - query "select quote(bin) from article_m where rowid=$rowid;" \ - | unhexize > $dir/$filename - done - if [ ! -d $bd/001 ]; then + case "$mode" in + *enquete*) + copy2csv=true + csvline=`getvalbyid blog heading $1 | grep "..*,." | head -1` + # Create CSV-base table for questionnaire + # If heading in blog_s has at least 1 CSV line, + # we take the line as column list. + # Otherwise we produce two column CSV as below: + # USER,ANSWER + if [ -n "$csvline" ]; then + : + else + query <<-EOF + DROP TABLE IF EXISTS tmp_q; + CREATE TEMPORARY TABLE tmp_q(user text PRIMARY KEY, answer); + EOF + fi + esac + query <<-EOF | + SELECT a.rowid, a.id artid, a.author, s.val + FROM article a JOIN article_s s ON a.id=s.id + WHERE blogid=(SELECT id FROM blog WHERE rowid=$rid); + EOF + while IFS='|' read rowid artid author text; do + isfilereadable $user article_s $rowid || continue + dir=`printf $bd/%d/%06d "$rid" "$rowid"` + mkdir -p $dir + echo "$author" > $dir/Author + echo "$text" > $dir/Text + if $copy2csv; then + query "REPLACE INTO tmp_q SELECT author, val + FROM article a NATURAL JOIN article_s s + WHERE blogid='$blogid' AND key='text';" + fi + i=0 + query "SELECT m.rowid, m.val FROM article_m m \ + WHERE id='$artid' AND m.key IN ('image', 'document', 'binary');" \ + | while IFS='|' read mrowid filename; do + outfile=`printf "%s/%02d-%s" "$dir" $((++i)) "$filename"` + query "SELECT quote(bin) FROM article_m WHERE rowid=$mrowid;" \ + | unhexize > $outfile + done + done + # query "select m.rowid,a.id,author,m.val from article a join article_m m\ + # on a.id=m.id where blogid=(select id from blog where rowid=$rid)\ + # and m.key in ('image', 'document', 'binary');" \ + # | while IFS='|' read rowid artid author filename; do + # err isfilereadable $user article_m $rowid + # isfilereadable $user article_m $rowid || continue + # err ok + # i=$((i+1)) + # dir=`printf $bd/%03d $i` + # mkdir $dir + # echo "$author" > $dir/author + # query "select val from article_s where id=$artid;" > $dir/text + # query "select quote(bin) from article_m where rowid=$rowid;" \ + # | unhexize > $dir/$filename + # done + if [ ! -d $bd/$rid ]; then contenttype; echo echo "取得できるファイルがありませんでした。" | html p return fi + + if $copy2csv; then + query <<-EOF > $bd/$rid/all-text-$rid.csv + .mode csv + .head 1 + SELECT * FROM tmp_q; + .mode list + .head 0 + EOF + fi + err "BDLIST: `ls -l $bd`" + arcname=archive-$rid.tar.gz (cd $bd - ## err cdto$bd; (pwd; ls -lFa) 1>&3 - tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz - err Creating tar archive "`ls -l archive.tar.gz`" + # query() CANNOT BE used in this subshell + tar zcf .archive.tar.gz $rid && mv .archive.tar.gz "$arcname" + err Creating tar archive "`ls -l "$arcname"`" ) - arc=$bd/archive.tar.gz + arcfile=$bd/$arcname echo "Content-type: application/x-gzip" - echo "Content-Length: `cat $arc|wc -c`" - echo "Content-Disposition: filename=\"archive.tar.gz\"" + echo "Content-Length: `cat $arcfile|wc -c`" + echo "Content-Disposition: filename=\"$arcname\"" echo - cat $arc + cat $arcfile } blogseen() { # $1 = blogid blogid=${1%%[!0-9]*} diff -r 3bfd1ac6fbf3 -r a50e83239b51 s4-funcs.sh --- a/s4-funcs.sh Sat Sep 07 07:41:52 2019 +0900 +++ b/s4-funcs.sh Tue Dec 03 11:41:39 2019 +0900 @@ -2726,7 +2726,7 @@ (SELECT user FROM grp_mem WHERE gname=bs.owner AND user='$user') IS NULL THEN 0 - WHEN mode = 'quiz' + WHEN mode IN ('quiz', 'enquete') THEN 0 -- "quiz" mode blog cannot be searched ELSE 1 END;