changeset 2:7aa52f9874ae

.hgignore added
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 18 Jul 2015 09:54:00 +0900
parents 5bafa0d981e0
children 95cebd686c97
files .hgignore se-blog.sh se-funcs.sh
diffstat 3 files changed, 79 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sat Jul 18 09:54:00 2015 +0900
@@ -0,0 +1,2 @@
+syntax: glob
+*
--- a/se-blog.sh	Thu Jul 16 23:03:51 2015 +0900
+++ b/se-blog.sh	Sat Jul 18 09:54:00 2015 +0900
@@ -47,7 +47,7 @@
   # blog_m: *article
 
   err "SELECT id from $tbl where rowid=$rowid"
-  id=`sq $db "select id from $tbl where rowid=$rowid"`
+  id=`query "select id from $tbl where rowid=$rowid;"`
 err id=$id
 err "select val from $ts where key='title' and id='$id';"
 
@@ -60,11 +60,14 @@
 
   href="<a href=\"?editheading+$rowid\"> 編集 </a>"
   href2="<a href=\"?lshandout+$rowid\"> 提出状況 </a>"
+  href3="(<a href=\"?gethandout+$rowid\">ファイル取得</a>)"
   cat<<EOF | sq -html $db \
       | sed -e "s|\(<TR><TD>\),e,|\1 $href |" \
-	    -e "s|,s,\(</TD>\)|$href2\1|"
+	    -e "s|,s,\(</TD>\)|$href2$href3\1|"
 -- select val from $ts where key="title" and id="$id";
-select ",e,"||val||" "
+select
+ coalesce((select ",e," from blog where rowid=$rowid and author='$user'),'')
+||val||" "
 ||case (select val from $ts where key="mode" and id="$id")
   when 'report-closed' then "レポート提出用(自身のファイルのみ参照可),s,"
   when 'report-open' then "レポート提出用,s,"
@@ -117,11 +120,10 @@
   arts=`query "select rowid,id,author from $at where blogid='$id';"`
 err  arts="[$arts]"
   number=0
+  hrefhome0="<a href=\"?home"
   for a in $arts; do
     arid=${a%%|*} aid=`echo "$a"|cut -d'|' -f2` author=${a##*|} imgs=""
     ### err a=$a, aid=$aid, author=$author
-    getgecos="coalesce((select val from user_s \
-	where name='$author' and key='gecos'), '$author')"
     # name=''	# Get gecos??
     td=$(echo $tmpd/`echo $a|md5`)
     val=`getvalbyid article image $arid $td`
@@ -151,12 +153,17 @@
     ### number=$((number+1))
 #    reply="<input type=\"radio\" name=\"parent\" class=\"replybtn\" \
 # value=\"$number\">"
+    getgecos="(select rowid from user where name='$author')||':'||\
+	coalesce((select val from user_s \
+	where name='$author' and key='gecos'), '$author')||',[/a],'"
     href="$myname?editart+$arid+$rowid"
     link="<a href=\"$href\">編集</a>"
     cat<<EOF | sq -html $db \
-	| sed -e 's/,n,/<br>/g' -e "s|,i,|$imgs|" \
+	| sed -e "s|,n,\([0-9]*\):|,n,$hrefhome0+\1\">|" \
+	      -e 's|,\[/a\],|</a>|' \
+	      -e 's/,n,/<br>/g' -e "s|,i,|$imgs|" \
 	      -e "s|<TR>\(<TD>\)|<TR id=\"$aid\">\1|" \
-	      -e "s|\(<TR.*>\)\(<TD>\),e,|\1\2 $link|"
+	      -e "s|\(<TR.*>\)\(<TD>\),e,|\1\2$link|"
 select
   coalesce((select ",e," from article where id='$aid' and author='$user'),"")
   ||
@@ -191,15 +198,22 @@
   time=`getvalbyid blog ctime $1|colrm 11`
   owner=`getvalbyid blog owner $1`
   title=`getvalbyid blog title $1`
+  ge=`gecos $owner`
   lshandoutsub $owner "$@" \
       |m4 -D_TITLE_="提出状況" \
-	  -D_SUBTITLE_="$time [$title]@$owner" -D_DIARY_="" \
-	  -D_FORM_="include(/dev/stdin)" -D_BLOGS_= -D_DUMPTABLE_= \
+	  -D_SUBTITLE_="$time [$title]@${ge:-$owner}" -D_DIARY_="" \
+	  -D_FORM_="syscmd(cat)" -D_BLOGS_= -D_DUMPTABLE_= \
 	  $layout/html.m4.html $layout/diary.m4.html
 }
 lshandoutsub() {
   # $1=owner $2=rowid of blog
-    sql="with arts as (select id,author from article \
+  if isgroup $1; then
+    sample="(select user from grp_mem where gname='$1')"
+  else
+    sample="(select distinct author as user from arts)"
+    echo "<p>(集計は板への投稿者のみ)</p>"
+  fi
+  sql="with arts as (select id,author from article \
 	    where blogid=(select id from blog where rowid=$2))\
       select (select rowid from user where name=c0.user)||'	'|| \
 	      coalesce((select val from user_s where name=c0.user \
@@ -209,7 +223,7 @@
 		 as 'コメント記入',\
 	     sum(case when c2.key is not null then 1 else 0 end)\
 		 as 'ファイルの提出'\
-	 from (select user from grp_mem where gname='$owner') c0\
+	 from $sample c0 \
 	        left join (select id,author from arts) a\
 		on c0.user=a.author\
 	        left join (select id,key from article_s where key='text') c1\
@@ -222,6 +236,40 @@
 	| sed -e "s,\(<TR><TD>\)\([^	]*\)	\(.*\)</TD>,\1$hrb\2\">\3</TD>," -e 's,<TD>0</TD>,<TD class="warn">0</TD>,'
     echo '</table>'
 }
+gethandout() {
+  # $1=rowid of blog
+  i=0
+  bd=$tmpd/archive.$$
+  mkdir $bd
+  query "select m.rowid,author,m.val from article a join article_m m\
+	 on a.id=m.id where blogid=(select id from blog where rowid=$1)\
+	 and m.key in ('image', 'document', 'binary');" \
+      | while IFS='|' read rowid author filename; do
+	  # err isfilereadable $user article_m $1
+	  isfilereadable $user article_m $1 || continue
+	  err ok
+	  i=$((i+1))
+	  dir=`printf $bd/%03d $i`
+	  mkdir $dir
+	  query "select quote(bin) from article_m where rowid=$rowid;" \
+	      | xxd -r -p > $dir/$filename
+	done
+  if [ ! -d $bd/001 ]; then
+    contenttype; echo
+    echo "<p>取得できるファイルがありませんでした。</p>"
+    return
+  fi
+  (cd $bd
+   err cdto$bd; (pwd; ls -lFa) 1>&3
+   tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
+  )
+  arc=$bd/archive.tar.gz
+  echo "Content-type: application/x-gzip"
+  echo "Content-Length: `cat $arc|wc -c`"
+  echo "Content-Disposition: filename=\"archive.tar.gz\""
+  echo
+  cat $arc
+}
 
 listblog() (
   # $1=user
--- a/se-funcs.sh	Thu Jul 16 23:03:51 2015 +0900
+++ b/se-funcs.sh	Sat Jul 18 09:54:00 2015 +0900
@@ -7,8 +7,9 @@
 bindir=`(cd $mydir/bin; pwd)`
 PATH=/usr/local/sqlite3/bin:$PATH:$bindir
 tmpdir=${TMPDIR:-tmp}
+dbdir=${DBDIR:-db}
 tmpfiles=""
-db=${DB:-$tmpdir/cgi.sq3}
+db=${DB:-$dbdir/cgi.sq3}
 admin=wwwadmin@gentei.org
 layout=templ/default
 formdir=templ/form
@@ -36,10 +37,12 @@
 グループへの一斉送信機能は付いたが表に出てない(7/6)
 ひとつのarticleをheadingにして新規ツリーを作成、あるといいかも。
 
-7/17	個人blogに「レポート提出用」がついたとき
+7/18	○書込著者からホームへのリンク
+	締切設定
 	一斉送信
-	添付ファイル回収
-	imgcacheは別ディレクトリにしないと + .htaccess
+7/17	○個人blogに「レポート提出用」がついたときの挙動
+	○添付ファイル回収
+	○imgcacheは別ディレクトリにしないと + .htaccess
 7/15	○レポート提出モードの表示を付ける
 	管理者権限での削除? → まだいいか
 
@@ -372,8 +375,14 @@
 }
 gecos() (
   u=${1:-$user}
-  gecos=`query "select val from user_s where name='$u' and key='gecos';"`
-  echo "${gecos:-$u}"
+  #gecos=`query "select val from user_s where name='$u' and key='gecos';"`
+  sql="select case when (select name from user where name='$u') is not null
+		then (select val from user_s where name='$u' and key='gecos')
+		when (select gname from grp where gname='$u') is not null
+		then (select val from grp_s where gname='$u' and key='gecos')
+		else '$u'
+		end;"
+  query "$sql"
 )
 getpar() {
 err getpar: "select val from par where var='$1' and sessid='$session' $2;"
@@ -545,7 +554,7 @@
 			 query "select quote(bin) from $cond and val=\"$fn\";" \
 			     | xxd -r -p > $file
 			 echo ${type#file:} > $file.content-type
-err TTTTTTTTTTTTTTTT: $type
+# err TTTTTTTTTTTTTTTT: $type
 			 case $type in
 			   *:[Ii]mage*) mogrify -geometry $thumbxy $file ;;
 			   *:[Aa]pplication*)
@@ -932,7 +941,7 @@
 	    type='file'; k=${k%:filename}
 	    case `file --mime-type $tmpdir/$v|cut -d' ' -f2` in
 	      [Ii]mage/*)
-		mogrify -resize $maximagexy $tmpdir/$v
+		mogrify -resize $maximagexy'>' $tmpdir/$v
 		;;
 	    esac
 	    ;;
@@ -1391,7 +1400,7 @@
   fi
   tbl=${1%.def}
   tbl=${tbl##*/}
-  if [ -n "$rowid" ]; then
+  if [ -n "$rowid" ]; then	# Modify existing entry
     if [ x"$tbl" = x"user" ]; then
       rowowner=`query "select name from $tbl where rowid=$rowid;"`
     elif [ x"$tbl" = x"grp" ]; then

yatex.org