s4
changeset 592:a50e83239b51
Add "enquete" mode
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 03 Dec 2019 11:41:39 +0900 |
parents | 3bfd1ac6fbf3 |
children | 874e1f59263f |
files | examples/sns/form/blog.def s4-blog.sh s4-funcs.sh |
diffstat | 3 files changed, 112 insertions(+), 33 deletions(-) [+] |
line diff
1.1 --- a/examples/sns/form/blog.def Sat Sep 07 07:41:52 2019 +0900 1.2 +++ b/examples/sns/form/blog.def Tue Dec 03 11:41:39 2019 +0900 1.3 @@ -1,5 +1,5 @@ 1.4 シリアル:id:p:serial: 1.5 -用途:mode:s:select:普通の掲示板=normal レポート提出用(相互に参照可能)=report-open レポート提出用(添付ファイルは管理者のみ参照可能)=report-closed クイズ(管理者以外は本人の記事のみ見える)=quiz 1.6 +用途:mode:s:select:普通の掲示板=normal レポート提出用(相互に参照可能)=report-open レポート提出用(添付ファイルは管理者のみ参照可能)=report-closed クイズ(管理者以外は本人の記事のみ見える)=quiz 集計=enquete 1.7 タイトル:title:s:text:maxlength="200" 1.8 コメント書込通知:notify:s:select:管理者のみに通知(グループの場合のみ)=admin 所有者全員に通知=all しない=no 1.9 稼動状態:state:s:select:稼動=active 凍結(新規書込停止)=frozen
2.1 --- a/s4-blog.sh Sat Sep 07 07:41:52 2019 +0900 2.2 +++ b/s4-blog.sh Tue Dec 03 11:41:39 2019 +0900 2.3 @@ -167,13 +167,14 @@ 2.4 fi 2.5 blog_notify=`getvalbyid blog notify "$rowid"` 2.6 blog_team=`blog_getteam "$rowid"` 2.7 + blog_mode=`getvalbyid blog mode "$rowid"` 2.8 case "$blog_notify" in # "all", "admin" or "no" (or NULL) 2.9 admin) notifyto=adm ;; 2.10 *) notifyto="" ;; 2.11 esac 2.12 - case `getvalbyid blog mode "$rowid"` in 2.13 - *quiz*|*close*) f_exclusive=1 ;; 2.14 - *) f_exclusive='' ;; 2.15 + case $blog_mode in 2.16 + *quiz*|*close*|*euquete*) f_exclusive=1 ;; 2.17 + *) f_exclusive='' ;; 2.18 esac 2.19 2.20 # err "SELECT id from $tbl where rowid=$rowid" 2.21 @@ -189,12 +190,14 @@ 2.22 2.23 href="<a href=\"?editheading+$rowid\" accesskey=\"e\" title=\"E\"> 編集 </a>" 2.24 if $ismem; then 2.25 - case `getvalbyid blog mode $rowid` in 2.26 - *report*|*quiz*) 2.27 + case $blog_mode in 2.28 + *report*|*quiz*|*euquete*) 2.29 href2="<a href=\"?lshandout+$rowid\" accesskey=\"l\" title=\"L\"> 提出状況 </a>" 2.30 ;; 2.31 esac 2.32 - href3="(<a href=\"?gethandout+$rowid\" accesskey=\"f\" title=\"F\">ファイル取得</a>)" 2.33 + if $isgrpadmin; then 2.34 + href3="(<a href=\"?gethandout+$rowid\" accesskey=\"f\" title=\"F\">ファイル取得</a>)" 2.35 + fi 2.36 fi 2.37 href4='<a href="#bottom" accesskey="b" title="B"> 末尾へ</a>' 2.38 $isgrpadmin && 2.39 @@ -213,6 +216,7 @@ 2.40 WHEN 'report-closed' THEN 'レポート提出用(closed)' 2.41 WHEN 'report-open' THEN 'レポート提出用(open)' 2.42 WHEN 'quiz' THEN 'クイズ' 2.43 + WHEN 'enquete' THEN '集計' 2.44 ELSE '' 2.45 END 2.46 FROM $ts WHERE id='$id' GROUP BY id; 2.47 @@ -225,12 +229,12 @@ 2.48 </table> 2.49 EOF 2.50 case "$blogtype" in 2.51 - "クイズ") 2.52 - echo "クイズモードは本人と管理者の書き込みのみが表示されます。" 2.53 + "クイズ"|"集計") 2.54 + echo "${blogtype}モードは本人と管理者の書き込みのみが表示されます。" 2.55 ;; 2.56 esac | html p 'class="warn"' 2.57 echo '<table class="blog_replies"> <!-- blog:blog_showentry() main table -->' 2.58 - if [ x"$blogtype" = x"クイズ" ]; then 2.59 + if [ x"$blogtype" = x"クイズ" -o x"$blogtype" = x"集計" ]; then 2.60 if $isgroup; then 2.61 if ! isgrpowner "$user" "$blogowner"; then 2.62 qgrp=`sqlquote "$blogowner"` 2.63 @@ -574,7 +578,8 @@ 2.64 /* WHERE owner=$qowner AND mode LIKE '%report%'; */ 2.65 WHERE owner=$qowner 2.66 AND 2.67 - (mode LIKE '%report%' OR mode LIKE '%quiz%'); 2.68 + (mode LIKE '%report%' OR mode LIKE '%quiz%' 2.69 + OR mode LIKE '%enquete%'); 2.70 /* ↑これでレポート形式の blogid 一覧を得る */ 2.71 EOF 2.72 if [ -z "$CATCSV" ]; then 2.73 @@ -664,40 +669,114 @@ 2.74 blog_writable $rid $user 2.75 rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member 2.76 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then 2.77 + contenttype; echo 2.78 echo "メンバー以外は利用できません。" | html p; return 2.79 fi 2.80 + # Here, this blog is writable by $user 2.81 + owner=`getvalbyid blog owner $1` 2.82 + if [ x"$user" = x"$owner" ]; then 2.83 + : OK 2.84 + elif isgrpowner "$user" "$owner"; then 2.85 + : OK 2.86 + else 2.87 + contenttype; echo 2.88 + echo "板の所有者以外は利用できません。" | html p; return 2.89 + fi 2.90 + mode=`getvalbyid blog mode $1` 2.91 + copy2csv=false 2.92 + blogid=`getvalbyid blog id $1` 2.93 + isgroup "$owner" && isgroup=true || isgroup=false 2.94 + isgrpowner "$user" "$owner" && isgrpadmin=true || isgrpadmin=false 2.95 + 2.96 i=0 2.97 bd=$tmpd/archive.$$ 2.98 mkdir $bd 2.99 - query "select m.rowid,author,m.val from article a join article_m m\ 2.100 - on a.id=m.id where blogid=(select id from blog where rowid=$rid)\ 2.101 - and m.key in ('image', 'document', 'binary');" \ 2.102 - | while IFS='|' read rowid author filename; do 2.103 - err isfilereadable $user article_m $rowid 2.104 - isfilereadable $user article_m $rowid || continue 2.105 - err ok 2.106 - i=$((i+1)) 2.107 - dir=`printf $bd/%03d $i` 2.108 - mkdir $dir 2.109 - query "select quote(bin) from article_m where rowid=$rowid;" \ 2.110 - | unhexize > $dir/$filename 2.111 - done 2.112 - if [ ! -d $bd/001 ]; then 2.113 + case "$mode" in 2.114 + *enquete*) 2.115 + copy2csv=true 2.116 + csvline=`getvalbyid blog heading $1 | grep "..*,." | head -1` 2.117 + # Create CSV-base table for questionnaire 2.118 + # If heading in blog_s has at least 1 CSV line, 2.119 + # we take the line as column list. 2.120 + # Otherwise we produce two column CSV as below: 2.121 + # USER,ANSWER 2.122 + if [ -n "$csvline" ]; then 2.123 + : 2.124 + else 2.125 + query <<-EOF 2.126 + DROP TABLE IF EXISTS tmp_q; 2.127 + CREATE TEMPORARY TABLE tmp_q(user text PRIMARY KEY, answer); 2.128 + EOF 2.129 + fi 2.130 + esac 2.131 + query <<-EOF | 2.132 + SELECT a.rowid, a.id artid, a.author, s.val 2.133 + FROM article a JOIN article_s s ON a.id=s.id 2.134 + WHERE blogid=(SELECT id FROM blog WHERE rowid=$rid); 2.135 + EOF 2.136 + while IFS='|' read rowid artid author text; do 2.137 + isfilereadable $user article_s $rowid || continue 2.138 + dir=`printf $bd/%d/%06d "$rid" "$rowid"` 2.139 + mkdir -p $dir 2.140 + echo "$author" > $dir/Author 2.141 + echo "$text" > $dir/Text 2.142 + if $copy2csv; then 2.143 + query "REPLACE INTO tmp_q SELECT author, val 2.144 + FROM article a NATURAL JOIN article_s s 2.145 + WHERE blogid='$blogid' AND key='text';" 2.146 + fi 2.147 + i=0 2.148 + query "SELECT m.rowid, m.val FROM article_m m \ 2.149 + WHERE id='$artid' AND m.key IN ('image', 'document', 'binary');" \ 2.150 + | while IFS='|' read mrowid filename; do 2.151 + outfile=`printf "%s/%02d-%s" "$dir" $((++i)) "$filename"` 2.152 + query "SELECT quote(bin) FROM article_m WHERE rowid=$mrowid;" \ 2.153 + | unhexize > $outfile 2.154 + done 2.155 + done 2.156 + # query "select m.rowid,a.id,author,m.val from article a join article_m m\ 2.157 + # on a.id=m.id where blogid=(select id from blog where rowid=$rid)\ 2.158 + # and m.key in ('image', 'document', 'binary');" \ 2.159 + # | while IFS='|' read rowid artid author filename; do 2.160 + # err isfilereadable $user article_m $rowid 2.161 + # isfilereadable $user article_m $rowid || continue 2.162 + # err ok 2.163 + # i=$((i+1)) 2.164 + # dir=`printf $bd/%03d $i` 2.165 + # mkdir $dir 2.166 + # echo "$author" > $dir/author 2.167 + # query "select val from article_s where id=$artid;" > $dir/text 2.168 + # query "select quote(bin) from article_m where rowid=$rowid;" \ 2.169 + # | unhexize > $dir/$filename 2.170 + # done 2.171 + if [ ! -d $bd/$rid ]; then 2.172 contenttype; echo 2.173 echo "取得できるファイルがありませんでした。" | html p 2.174 return 2.175 fi 2.176 + 2.177 + if $copy2csv; then 2.178 + query <<-EOF > $bd/$rid/all-text-$rid.csv 2.179 + .mode csv 2.180 + .head 1 2.181 + SELECT * FROM tmp_q; 2.182 + .mode list 2.183 + .head 0 2.184 + EOF 2.185 + fi 2.186 + err "BDLIST: `ls -l $bd`" 2.187 + arcname=archive-$rid.tar.gz 2.188 (cd $bd 2.189 - ## err cdto$bd; (pwd; ls -lFa) 1>&3 2.190 - tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz 2.191 - err Creating tar archive "`ls -l archive.tar.gz`" 2.192 + # query() CANNOT BE used in this subshell 2.193 + tar zcf .archive.tar.gz $rid && mv .archive.tar.gz "$arcname" 2.194 + err Creating tar archive "`ls -l "$arcname"`" 2.195 ) 2.196 - arc=$bd/archive.tar.gz 2.197 + arcfile=$bd/$arcname 2.198 echo "Content-type: application/x-gzip" 2.199 - echo "Content-Length: `cat $arc|wc -c`" 2.200 - echo "Content-Disposition: filename=\"archive.tar.gz\"" 2.201 + echo "Content-Length: `cat $arcfile|wc -c`" 2.202 + echo "Content-Disposition: filename=\"$arcname\"" 2.203 echo 2.204 - cat $arc 2.205 + cat $arcfile 2.206 } 2.207 blogseen() { # $1 = blogid 2.208 blogid=${1%%[!0-9]*}
3.1 --- a/s4-funcs.sh Sat Sep 07 07:41:52 2019 +0900 3.2 +++ b/s4-funcs.sh Tue Dec 03 11:41:39 2019 +0900 3.3 @@ -2726,7 +2726,7 @@ 3.4 (SELECT user FROM grp_mem 3.5 WHERE gname=bs.owner AND user='$user') IS NULL 3.6 THEN 0 3.7 - WHEN mode = 'quiz' 3.8 + WHEN mode IN ('quiz', 'enquete') 3.9 THEN 0 -- "quiz" mode blog cannot be searched 3.10 ELSE 1 3.11 END;