diff s4-blog.sh @ 443:f1744a954888

New blog mode "quiz" introduced, which allows normal users to view only administrators' or each one's own article. But administrators can always see all articles.
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 01 Jul 2017 20:13:34 +0859
parents 14764da097ec
children 39823dfee44f
line wrap: on
line diff
--- a/s4-blog.sh	Sat Jul 01 12:05:07 2017 +0859
+++ b/s4-blog.sh	Sat Jul 01 20:13:34 2017 +0859
@@ -129,11 +129,13 @@
   # blog_s: title,ctime,heading
   # blog_m: *article
 
+  blogowner=`getvalbyid blog owner "$2"`
+  isgroup "$blogowner" && isgroup=true || isgroup=false
+
   # 2015-10-05 check readable
   if ! $iswritable; then
-    blogowner=`getvalbyid blog owner "$2"`
     # err blogowner=$blogowner
-    if isgroup "$blogowner"; then
+    if $isgroup; then
       regmode=`getgroupattr $blogowner regmode`
       # err regmode=$regmode
       if [ x"$regmode" = x"moderated" ]; then
@@ -172,6 +174,7 @@
     href3="(<a href=\"?gethandout+$rowid\" accesskey=\"f\" title=\"F\">ファイル取得</a>)"
   fi
   href4='<a href="#bottom" accesskey="b" title="B"> 末尾へ</a>'
+  quizmodefile=$td/quiz; rm -f "$quizmodefile"	# XXX: Global state
 
   query<<-EOF |
 	SELECT coalesce((SELECT "yes" FROM blog
@@ -196,6 +199,18 @@
 
 	<table class="blog_replies">
 	EOF
+    if [ x"$blogtype" = x"クイズ" ]; then
+      if $isgroup; then
+	if ! isgrpowner "$user" "$blogowner"; then
+	  qgrp=`sqlquote "$blogowner"`
+	  cat<<-EOF > $quizmodefile
+		AND  (author IN (SELECT user FROM grp_adm WHERE gname=$qgrp)
+		      OR
+		      author='$user')
+		EOF
+	fi
+      fi
+    fi
   }
   lkhome="<a href=\"$myname?home" lke='">'
   lkedit="<a href=\"$myname?editart"
@@ -206,6 +221,7 @@
   atime=`query "SELECT time FROM acclog
 		WHERE tbl='blog' AND tblrowid=$rowid AND user='$user';"`
   iconcleaner=$tmpd/iconcleaner.$$
+  [ -s $quizmodefile ] && cond_qz=`cat $quizmodefile`
   # *** DO NOT USE query(), use "sq $db" instead here ***
   # because the next block in pipe line uses query() repeatedly.
   sq $db<<EOF |
@@ -239,8 +255,10 @@
 	(SELECT group_concat(rowid||':'||length(bin)||':'||hex(val), ' ')
 	 FROM article_m
 	 WHERE id=a.id AND key='image') imxgids
-FROM (select rowid,id,author from article where blogid in
-     (select id from blog where rowid=$rowid)) a
+FROM (select rowid,id,author from article
+      where blogid in
+      (select id from blog where rowid=$rowid)
+      $cond_qz) a
   LEFT JOIN
      a_s s
   ON a.id=s.id;

yatex.org