changeset 827:97be0474f268

List belonging groups
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 21 Jun 2020 16:13:52 +0900
parents f2d69fb3e038
children 476a70f667cf
files s4-funcs.sh s4-world.sh
diffstat 2 files changed, 33 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/s4-funcs.sh	Sun Jun 21 10:08:12 2020 +0900
+++ b/s4-funcs.sh	Sun Jun 21 16:13:52 2020 +0900
@@ -2390,7 +2390,7 @@
     echo '</table>'
   done
   if [ -n "$S4WORLDLIST" -a -n "$3" ]; then
-    peekgrpworlds mem="$3"
+    peekgrpworlds mem:"$3"
   fi
   echo '</div>'
 }
@@ -2448,7 +2448,22 @@
   fi
   if [ -n "$2" ]; then
     kwd=`echo $2 | tr -d '";\n' | tr -d "'"`
-    cond1="(nick like '%${kwd}%' or b.name like '%${kwd}%')"
+    case "$kwd" in
+      mem:*)
+	byuser=${kwd#*mem:}
+	cond1="(a.gname IN (SELECT gname FROM grp_mem WHERE user='$byuser'))"
+	err cond1=$cond1
+	;;
+    esac
+    if [ x"$1" = x"group" ]; then
+      if [ -n "$cond1" ]; then
+	enthead="`gecos "$byuser"|htmlescape` さんの所属"
+      else
+	cond1="(b.name like '%${kwd}%')"
+      fi
+    else
+      cond1="(nick like '%${kwd}%' or b.name like '%${kwd}%')"
+    fi
   fi
   tag=`getpar tag` tag2=`getpar tag2`
   if [ x"$tag" = x"NULL" ]; then
@@ -2517,7 +2532,7 @@
   # Note that mtime is stored only in grp_s.
 ## err LE:sql.1="$sql"
   total=`query "with x as ($sql) select count(*) from x;"`
-  echo "${entity} 一覧" "${S4WORLDNAME:+@$S4WORLDNAME}" | html h2
+  echo "$enthead${entity} 一覧" "${S4WORLDNAME:+@$S4WORLDNAME}" | html h2
   echo '<div class="listentry">'		# List-entry div
   # Show owner/member filter button
   METHOD=GET
@@ -2634,7 +2649,7 @@
   echo "</div>"					# End of List-entry div
   echo ${pnbtn:+"<hr>$nextbtn$prevbtn"}
   if [ -n "$kwd" -a x"$tbl" = x"grp" -a -n "$S4WORLDS" ]; then
-    peekgrpworlds kwd="$kwd"
+    peekgrpworlds "$kwd"
   fi
 )
 listmember() {
--- a/s4-world.sh	Sun Jun 21 10:08:12 2020 +0900
+++ b/s4-world.sh	Sun Jun 21 16:13:52 2020 +0900
@@ -183,11 +183,21 @@
 }
 
 grepgrpworld() (
-  world=$1; wname=$2; kwd=$3; db=$4 cond=$5
+  world=$1; wname=$2; exp=$3; db=$4
   case $world in
-    Base)	cgi=`basename ${S4MASTERURL:-$URL}` ;;
+    Base)	cgi=${S4MASTERURL:-$URL} ;;
     *)		cgi=s4-world-$world$cgiext ;;
   esac
+  arg=${3#*:}
+  case $exp in
+    kwd:*) cond="gname LIKE '%$arg%'"
+	   guide="`echo $arg|htmlescape` を含むグループは別世界にもあります"
+	   s="(<a href=\"$cgi?stage=grps&kwd=$arg\">絞込</a>)" ;;
+    mem:*) cond="user = '$arg'"
+	   guide="別世界の所属グループ"
+	   s="(<a href=\"$cgi?stage=grps&kwd=mem:$arg\">所属絞</a>)" ;;
+  esac
+  err "arg=[$arg] cond=[$cond] s=[$s]"
   query <<-EOF |
 	ATTACH DATABASE "$db" AS td;
 	SELECT DISTINCT td.grp.rowid,hex(gname)
@@ -204,7 +214,6 @@
     if [ -n "$ans" ]; then
       w=`echo $wname|htmlescape`
       u="<a href=\"$cgi?grps\"><span class=\"pre\">$w</span></a>"
-      s="(<a href=\"$cgi?stage=grps&kwd=$kwd\">絞込</a>)"
       cat<<-EOF
 	<tr>
 	 <tr><td>$u $s</td>
@@ -216,20 +225,13 @@
 )
 
 peekgrpworlds() (
-  # $1=(kwd=Pattern|mem=User)
-  arg=${1#*=}
-  case $1 in
-    kwd=*) cond="gname LIKE '%$arg%'"
-	   guide="`echo $arg|htmlescape` を含むグループは別世界にもあります" ;;
-    mem=*) cond="user = '$arg'"
-	   guide="別世界の所属グループ";;
-  esac
+  # $1=(kwd:Pattern|mem:User)
   for wd in `worldnameDBlist`; do
     world=${wd%%:*}; wd=${wd#*:}
     worldname=${wd%:*}
     d=${wd#*:}
     if [ ! $db -ef $d -a -s $d ]; then
-      grepgrpworld "$world" "$worldname" "$arg" "$d" "$cond"
+      grepgrpworld "$world" "$worldname" "$1" "$d"
     fi
   done | {
     result=`cat`

yatex.org