changeset 59:916d81b9c4fc

Selection from group member
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 25 Jul 2015 23:00:58 +0900
parents ccd0c6736215
children 9f4e85181d40
files s4-blog.sh s4-cgi.sh s4-funcs.sh s4.cgi templ/default/default.css
diffstat 5 files changed, 151 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/s4-blog.sh	Thu Jul 23 11:35:05 2015 +0900
+++ b/s4-blog.sh	Sat Jul 25 23:00:58 2015 +0900
@@ -139,11 +139,11 @@
   number=0
   hrefhome0="<a href=\"?home"
   for a in $arts; do
-    arid=${a%%|*} aid=`echo "$a"|cut -d'|' -f2` author=${a##*|} imgs=""
+    arid=${a%%\|*} aid=`echo "$a"|cut -d'|' -f2` author=${a##*\|} imgs=""
 err a=$a, aid=$aid, author=$author
     # name=''	# Get gecos??
     td=$(echo $bstmpdir/`echo $a|md5`)
-    val=`getvalbyid article image $arid $td`
+    val=`getvalbyid article image "$arid" "$td"`
 err val="[$val]" and td as follows:
     
     if true; then
@@ -156,12 +156,6 @@
 		       #ct=`cat $td/$fn.content-type`
 		       ri=`cat $td/$fn.rowid`
 err fn=$fn ct=$ct ri=$ri; ls -lF $td/ 1>&3
-		       #case $ct in
-		#	 [Ii]mage*) anch="<img src=\"data:$ct,$data\">$fn" ;;
-		#	 *) anch=$fn ;;
-		#       esac
-		       # Should not contain newlines for sed argument
-		#       echo -n "<a href=\"$hrfb+$ri\">$anch</a>"
 			iconhref $td/$fn "$hrfb+$ri" "$fn" "$fn"
 		     done)
 	imgs=`echo "$imgs"|tr -d '\n'`	# kill newlines for sed
--- a/s4-cgi.sh	Thu Jul 23 11:35:05 2015 +0900
+++ b/s4-cgi.sh	Sat Jul 25 23:00:58 2015 +0900
@@ -114,3 +114,9 @@
   # $1=name $2=val(filename)
   cgi_multi $1 "$2" cgi_file "$3"
 }
+
+html() {
+  echo "<$*>"
+  cat
+  echo "</$1>"
+}
--- a/s4-funcs.sh	Thu Jul 23 11:35:05 2015 +0900
+++ b/s4-funcs.sh	Sat Jul 25 23:00:58 2015 +0900
@@ -535,9 +535,11 @@
 	   ###vcount=`sq $db "select count(val) from $cond"`
 	   # Reset val to store filenames if type is string
 	   val=`query "select val from $cond and type like 'file:%' order by rowid;"`
+err gvb1-sql: "select count(val) from $cond;"
 	   vcount=`query "select count(val) from $cond;"`
 	   echo $vcount > $td/$c.count
 	   i=0
+err gvbid: i=$i vcount=$vcount
 	   while [ $i -lt $vcount ]; do
 	     slice="order by rowid limit 1 offset $i"
 	     i=$((i+1))
@@ -1020,7 +1022,7 @@
   esac
 }
 email4group() {
-  # Get for-$1=group email address(es) for $2=user
+  # Get for-$1=group email address(es) for $2...=users
   qgrp=`sqlquote "$1"`; shift
   users=`for i; do sqlquote "$i"; done`
   users=`echo $users|tr ' ' ','`
@@ -1031,6 +1033,20 @@
   err `echo $sql`
   query "$sql"
 }
+email4groupbyuid() {
+  # Get for-$1=group email address(es) for $2...=user-ids
+  qgrp=`sqlquote "$1"`; shift
+err em4gbid-IN: "\$1=$1 qgrp=$qgrp"
+  uids=`echo "$@"`
+  uids=`echo $uids|tr ' ' ','`
+  sql="select coalesce(s.val, g.user) from grp_mem g
+	left join grp_mem_s s on g.gname=s.gname and g.user=s.user
+	and s.key='email'
+	where g.gname=$qgrp and g.user in
+	 (select name from user where rowid in ($uids));"
+  err email4gByid `echo $sql`
+  query "$sql"
+}
 collectemail() (
   # Collect email addresses for group $1
   for e; do
@@ -1374,7 +1390,8 @@
     iamowner=$rowid
   fi
   if ismember "$user" "$grp"; then
-    echo "${iamowner:+ / }<a href=\"?blog+$rowid\">グループの新規話題作成</a></p>"
+    echo "${iamowner:+ / }<a href=\"?blog+$rowid\">グループの新規話題作成</a>"
+    echo "/ <a href=\"?grpaction+$rowid\">メンバーを個別選択しての操作</a></p>"
 # div.fold input[type="checkbox"]:checked ~ div {display: block;}
     cat<<EOF
 <form action="?send2mem" method="POST" enctype="multipart/form-data">
@@ -1434,6 +1451,115 @@
   thumbxy=50x50 listmember "" "$c" \
       |sed -e "s|\(<br>\),not=\(.*\)|\1<a href=\"$cm+\2\">管理者委託</a>|"
 }
+grpaction() {			# $1=group-rowid
+  # $grid=Group-id $grp=gname (got in s4.cgi)
+  usel=`getpar usel`
+  if [ -n "$usel" ]; then
+    uids=$(echo `echo $usel`|tr ' ' ',')
+    #err grpaction-1: grp=$grp, `echo $sql`
+    text=`getpar text`
+    
+    rm=`getpar rm` cfm=`getpar confirm`
+err rm=$rm cfm=$cfm
+    if [ x"$rm" = x"yes" ]; then
+      if isgrpowner "$user" "$grp"; then
+	if [ x"$rm$cfm" = x"yesyes" ]; then
+	  # Eliminate
+	  cond="where gname=(select gname from grp where rowid=$grid) and user in (select name from user where rowid in ($uids))"
+	  for tbl in grp_mem grp_mem_s grp_mem_m; do
+	    sql="delete from $tbl $cond;"
+	    # echo "sql=$sql"
+	    query "$sql"
+	    err rmGRPuser "$sql"
+	  done
+	  num=`query "select count(*) from user where rowid in ($uids);"`
+	  #err num=$num
+	  if [ 0$num -gt 0 ]; then
+	    sql="select coalesce(b.val,a.name) from user a left join \
+	user_s b on a.name=b.name and key='gecos' where a.rowid in ($uids);"
+	    # err `echo "$sql"`
+	    html pre<<EOF
+以下の${num}名のグループ $grp 登録を解除しました。
+`query "$sql"`
+EOF
+	  fi
+	else
+	  echo "<p>確認のチェックがないのでやめておきます。</p>"
+	  return
+	fi
+      else			# not Group Owner
+	echo "<p>グループ管理者でないのでメンバー操作はできません。</p>"
+	return
+      fi
+      cat<<EOF
+
+EOF
+    elif [ -n "$text" ]; then	# if NOT removal mode
+      smail "`email4groupbyuid "$grp" $usel` $user" \
+	    "`gecos $user` さんからのメッセージ" <<EOF
+$url
+のグループ「$grp」のメンバーである `gecos $user` さんから、
+あなた宛へのメッセージです。
+----------------------------------------------------------
+$text
+EOF
+      if [ $? = 0 ]; then
+	echo "<p>Note: 以下のメンバーにメッセージを送信しました。"
+	echo "</p><pre>"
+	sql="select coalesce(b.val, a.name) from
+		(select name from user where rowid in ($uids)) a
+		left join user_s b on a.name=b.name and b.key='gecos';"
+	query $sql
+	err SendDone: `echo $sql`
+	echo "(送信者である `gecos $user` さんも含まれます)</pre>"
+      fi
+    fi
+  fi
+  # New entry
+  sql="select u.rowid||','||j.* from user u
+	 join (select a.user as name,coalesce(b.val,a.user)
+		 from (select gname,user from grp_mem
+		 where gname=(select gname from grp where rowid=$1))
+	 a left join (select gname,user,val from grp_mem_s where key='email')
+	 b using(gname,user))
+	j using(name) order by u.name;"
+  sql="select a.rowid||','||coalesce(val,a.name) as name from
+	 (select rowid,name from user where name in
+		 (select user from grp_mem where
+		 gname=(select gname from grp where rowid=1)))
+	  a left join user_s on a.name=user_s.name and key='gecos'
+	order by name;"
+  err grpaction: `echo $sql`
+  b1='<label> <input type="checkbox" name="usel" value="'
+  b2='"> ' b3='</label>'
+  cgi_form grpaction<<EOF \
+      	| sed  -e "s|^\(<TR><TD>\)\([0-9]*\),\([^<]*\)|\1$b1\2$b2\3$b3|" \
+	| m4 -D_TITLE_="グループ[$grp]参加メンバーに対する操作" \
+	     -D_SUBTITLE_="チェック後操作ボタン" \
+	     -D_FORM_="syscmd(cat)" -D_DUMPTABLE_="" \
+	     $layout/groupman.m4.html
+<div class="fold">
+`cgi_radio rm send id="sendmsg"`<label
+ for="sendmsg">下でチェックした人にメッセージを送信する</label>
+<div>
+`cgi_textarea text "" cols=40`
+</div>
+</div>
+<div class="fold">
+`cgi_radio rm yes ` 下でチェックした人のグループ登録解除
+<div>
+本当に消します! `cgi_checkbox confirm yes` 確認
+<p>この操作による通知は本人に行きません。
+あらかじめ通知するか、登録解除してよい状況かしっかり確認してください。</p>
+</div>
+</div>
+<h4>$grp 参加者一覧</h4>
+<table>
+`sq $db -html "$sql"`
+`cgi_hidden grp $grid`
+</table>
+EOF
+}
 send2grpmember() {
   rowid=`getpar grp`
   if [ -z "$rowid" ]; then
--- a/s4.cgi	Thu Jul 23 11:35:05 2015 +0900
+++ b/s4.cgi	Sat Jul 25 23:00:58 2015 +0900
@@ -137,7 +137,17 @@
     m4 -D_TITLE_="グループ $grp" \
        $layout/html.m4.html
     showgroup "$grid"
-    
+    ;;
+  "grpaction")			# $2=group-rowid
+    contenttype; echo
+    grid=${2:-`getpar grp`}
+    grp=`getgroupbyid "$grid"`
+    if [ -z "$grp" ]; then
+      echo "<p>無効な指定です。</p>"
+      return
+    fi
+    m4 -D_TITLE_="グループ $grp 個別選択操作" $layout/html.m4.html
+    grpaction "$grid"
     ;;
   "commission")
     # $2=grp-rowid $3=user-rowid
@@ -286,8 +296,8 @@
     sql="select quote(bin) from $2 where rowid='$3';"
     sq $db "$sql" | unhexize > $bin
     tv=`query "select type,val from $2 where rowid='$3';"`
-    type=${tv%|*} fn=${tv#*|}
-    err tv=$tv type=$type fn=$fn
+    type=${tv%\|*} fn=${tv#*\|}
+    err tv=$tv type=$type fn=$fn, tp2=${tv%\|*}
     ct=${type#file:}
     case $ct in			# all text/* changed to text/plain
       text/*)
--- a/templ/default/default.css	Thu Jul 23 11:35:05 2015 +0900
+++ b/templ/default/default.css	Sat Jul 25 23:00:58 2015 +0900
@@ -80,7 +80,8 @@
     xxdisplay: none; max-height: 80%; overflow: auto;
     height: 0px; opacity: 0; padding: 0 1ex;
 }
-div.fold input[type="checkbox"]:checked ~ div {
+div.fold input[type="checkbox"]:checked ~ div,
+div.fold input[type="radio"]:checked ~ div {
     display: block; background: #eef;
     height: auto; opacity: 1.0; transition: 1s;
 }

yatex.org