changeset 397:e9e8b4d40220

Add feature of `frozen state' of the blog board
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 27 Dec 2016 08:41:10 +0859
parents cacd961d3405
children f50d4df067b5
files examples/common/default/default.css examples/sns/form/blog.def s4-blog.sh s4-funcs.sh
diffstat 4 files changed, 97 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/examples/common/default/default.css	Sun Dec 25 11:55:51 2016 +0859
+++ b/examples/common/default/default.css	Tue Dec 27 08:41:10 2016 +0859
@@ -84,6 +84,8 @@
     font-size: 150%; background: yellow; text-align: center;
     white-space: pre-wrap;
 }
+table.bloghead tr.frozen {background: blue; color: white;}
+
 table.bloghead {margin-bottom: 1em;}
 
 table.blog_replies, .blog_replies tr, .blog_replies td {
@@ -185,10 +187,14 @@
 div.lcto td:nth-child(2) {max-width: 8em;}
 table.dumpblogs td:nth-child(5), /* team */
 table.dumpblogs td:nth-child(6), /* title */
+table.dumpblogs td:nth-child(7), /* heading */
 div.lcto td:nth-child(3),	 /* title */
 div.lcto td:nth-child(4)	 /* owner */
 	 {max-width: 14em;}
 
+table.dumpblogs tr.凍結 td:nth-child(n+2) {opacity: 0.5;}
+table.dumpblogs tr.凍結 td:last-child {opacity: 1.0; color: blue;}
+*.frozen, *.凍結 {color: blue;}
 
 /*
 table.dumpblogs td:nth-child(4) {
--- a/examples/sns/form/blog.def	Sun Dec 25 11:55:51 2016 +0859
+++ b/examples/sns/form/blog.def	Tue Dec 27 08:41:10 2016 +0859
@@ -2,6 +2,7 @@
 用途:mode:s:select:普通の掲示板=normal レポート提出用(相互に参照可能)=report-open レポート提出用(管理者のみ参照可能)=report-closed
 タイトル:title:s:text:maxlength="200"
 コメント書込通知:notify:s:select:管理者のみに通知(グループの場合のみ)=admin 所有者全員に通知=all しない=no
+稼動状態:state:s:select:稼動=active 凍結(新規書込停止)=frozen
 所有者:owner:s:owner:
 筆者:author:s:author:
 時刻:ctime:s:stamp:
--- a/s4-blog.sh	Sun Dec 25 11:55:51 2016 +0859
+++ b/s4-blog.sh	Tue Dec 27 08:41:10 2016 +0859
@@ -1,6 +1,10 @@
 #
 type cgiinit >/dev/null 2>&1 || . ./s4-funcs.sh
 
+# Global error flags
+BLOG_NOTMEM=1
+BLOG_FROZEN=2
+
 blog_genform() {
   #
   t=$1 
@@ -8,8 +12,15 @@
 
 blog_writable() (
   # $1=articleid $2=user
+  # Return: $?=0 - Writable
+  # 	      =1 - NOT Writable because user is not a member
+  # 	      =2 - NOT Writable because blog is frozen
   blogowner=`getvalbyid blog owner "$1"`
-  [ x"$blogowner" = x"$2" ] || isuser "$blogowner" || ismember "$2" "$blogowner"
+  state=`getvalbyid blog state "$1"`
+  rc=0
+  [ x"$blogowner" = x"$2" ] || isuser "$blogowner" || ismember "$2" "$blogowner" || rc=$((rc+$BLOG_NOTMEM))
+  [ "$state" = "frozen" ] && rc=$((rc+$BLOG_FROZEN))
+  return $rc
 )
 blog_readable() {
   # $1=articleid $2=user
@@ -74,7 +85,19 @@
   ts=${tbl}_s tm=${tbl}_m
   at=article as=article_s am=article_m
   serial=$(($(date +%s)-1420038000))s$$
-  blog_writable $rowid $user && iswritable=true || iswritable=false
+  blog_writable $rowid $user
+  rc=$?
+  if [ $rc = 0 ]; then
+    iswritable=true
+    ismem=true
+  else
+    iswritable=false
+    if [ $((rc & $BLOG_NOTMEM)) -gt 0 ]; then
+      ismem=false
+    else
+      ismem=true
+    fi
+  fi
   # This function grasps blog entry definiton directly.
   # blog:   id
   # blog_s: title,ctime,heading
@@ -88,7 +111,8 @@
       regmode=`getgroupattr $blogowner regmode`
       # err regmode=$regmode
       if [ x"$regmode" = x"moderated" ]; then
-	if ! ismember $user $blogowner; then
+	# if ! ismember $user $blogowner; then
+	if ! $ismem; then
 	  echo "加入してからどうぞ" | html p
 	  return
 	fi
@@ -113,7 +137,7 @@
 EOF
 
   href="<a href=\"?editheading+$rowid\" accesskey=\"e\" title=\"E\"> 編集 </a>"
-  if $iswritable; then
+  if $ismem; then
     case `getvalbyid blog mode $rowid` in
       *report*)
 	href2="<a href=\"?lshandout+$rowid\" accesskey=\"l\" title=\"L\"> 提出状況 </a>"
@@ -139,7 +163,7 @@
   { IFS='|' read edit ctime hexhead blogtype
     cat<<-EOF
 	<tr><td>${edit:+$href }$ctime $blogtype $href2$href3 $href4</td></tr>
-	<tr class="preface">
+	<tr class="preface${frozen_class:+ }$frozen_class">
 	 <td>`echo "$hexhead"|unhexize|hreflink|minitbl`</td></tr>
 	</table>
 
@@ -772,6 +796,21 @@
   fi
   title=`getvalbyid blog title $rowid`
   owner=`getvalbyid blog owner $rowid`
+  if [ -z "$title" ]; then
+    echo "日記番号指定が無効です。" | html p
+    return
+  fi
+  blog_writable $rowid $user; rc=$?
+  if [ $rc = 0 ]; then
+    iswritable=true
+  else
+    iswritable=false
+    if [ $((rc & $BLOG_FROZEN)) -gt 0 ]; then
+      isfrozen=true
+      frozen_class='frozen"'
+      frozen_flag="<span class=\"$frozen_class\">[凍結]</span>"
+    fi
+  fi
   if isuser "$owner"; then
     subtitle="`gecos $owner` さんの話題"
   else
@@ -785,14 +824,10 @@
 	 \"|htmlescape`"
     memclass=`grp_getbodyclass "$owner"`
   fi
-  if [ -z "$title" ]; then
-    echo "日記番号指定が無効です。" | html p
-    return
-  fi
 
   text=`getpar text`
   if [ -n "$text" ]; then
-    if blog_writable $rowid $user; then
+    if $iswritable; then
       par2table $formdir/article.def
       st=$?
       case $st in
@@ -806,12 +841,16 @@
 	;;
       esac
     else
-      title="$title(加入してないので書き込み不可)"
+      if $isfrozen; then
+	title="$title(凍結板につき書き込み不可)"
+      else
+	title="$title(加入してないので書き込み不可)"
+      fi
     fi
   fi
   def=$formdir/article.def
   echo "$title" > $tmpd/title.$$
-  echo "$subtitle" > $tmpd/subtitle.$$
+  echo "$subtitle$frozen_flag" > $tmpd/subtitle.$$
   ${BLOG_SHOW:-blog_showentry} blog $rowid \
       | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
 	    -D_BODYCLASS_=general"${memclass:+ $memclass}" \
--- a/s4-funcs.sh	Sun Dec 25 11:55:51 2016 +0859
+++ b/s4-funcs.sh	Tue Dec 27 08:41:10 2016 +0859
@@ -2198,9 +2198,10 @@
 `cgi_hidden owner $grp`
 EOF
   cond="where a.id in (select id from blog_s where key='owner' and val=$qgrp) order by ctime desc"
+  colstate="state:稼動状態:frozen=rowclass=凍結"
   DT_CHLD=article:blogid \
 	 DT_VIEW=replyblog dumptable html blog \
-	 "ctime team title heading$colmd" "$cond"
+	 "ctime team title heading$colmd $colstate" "$cond"
 
   getgname="(select gname from grp where rowid=$rowid)"
   c="group by a.name having a.name in (select user from grp_mem where gname=$getgname)"
@@ -2895,6 +2896,26 @@
     showgroup $grid
   done
 }
+dt_rowhack() {
+  # From: <TR>
+  #        ....
+  #        <TD>rowclass=foo</TD>
+  #        </TR>
+  # To:   <TR class="foo">....<TD>foo</TD></TR>
+  sed -e '
+	/^<TR>/ {
+	  :loop
+	  s/\n//
+	  N
+	  /<\/TR>/ {
+	    s/\n//
+	    s,^<TR>\(.*\)<TD>rowclass=\(.*\)\(</TD></TR>\),<TR class="\2">\1<TD>\2\3,
+	    n
+	  }
+	  $p
+	  b loop
+	}'
+}
 dumptable() {
   # $1=mode $2=Table $3=column-list-of-*_s(defaults to *) $4=conditions(if any)
   # textのフィールドだけ全てダンプにしたほうがいいか
@@ -2923,16 +2944,28 @@
   # Construct join expression
   eav="" scols=""
   pk=`gettblpkey $2`
-  substr=${dumpcollen:+"substr(val, 0, $dumpcollen)"}
-  substr=${substr:-val}
+  substr=${dumpcollen:+"substr(%s, 0, $dumpcollen)"}
+  substr=${substr:-%s}
   for col in ${3:-`gettbl_s_cols $2`}; do
+    valvar=val
     case $col in
       gecos)	scols="$scols${scols:+, }${col#}"
 		continue ;;	# built-in column name
-      *:*)	col=${col%:*} as=${col#*:} ;;
+      *:*)	as=${col#*:}	# as can be 稼動状態:frozen=凍結中
+		col=${col%%:*}	# stage:稼動状態:frozen=凍結中 -> stage
+		case "$as" in
+		  *:*=*) cnd=${as#*:}
+			 h=${cnd%%=*} v=${cnd#*=}
+			 h=`sqlquotestr "$h"`
+			 v=`sqlquotestr "$v"`
+			 valvar="CASE val WHEN $h THEN $v END"
+			 as=${as%%:*} ;;
+		esac
+		;;
       *)	as=${col} ;;
     esac
-    eav=$eav${eav:+,}" max(case key when '$col' then $substr end) as $as"
+    ss=`printf "$substr" "$valvar"`
+    eav=$eav${eav:+,}" max(case key when '$col' then $ss end) as $as"
     scols="$scols${scols:+, }b.$as"
   done
 #case author when '$user' then a.rowid else '---' end as ID,
@@ -2945,7 +2978,7 @@
 	 then (SELECT gecos FROM gecoses WHERE name=val) END) as gecos
  from ${2}_s c group by $pk) b on a.$pk=b.$pk $4;"}
   ## err dt:SQL="`echo \"$presql$sql\"|tr -d '\n'`"
-  cat<<EOF | sed "s,\(<TR><TD>\)\([1-9][0-9]*\)\(#[0-9a-fxs]*\)*</TD>,\1$elink$dvlink</TD>,"
+  cat<<EOF | sed "s,\(<TR><TD>\)\([1-9][0-9]*\)\(#[0-9a-fxs]*\)*</TD>,\1$elink$dvlink</TD>," | dt_rowhack
 <div> <!-- for folding by check button (s4-funcs.sh:dumptable()) -->
 <div class="dumptable">
 <table class="b$dt_class">

yatex.org