--- loncom/interface/londocs.pm 2002/07/31 13:50:38 1.3 +++ loncom/interface/londocs.pm 2002/07/31 14:56:36 1.4 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.3 2002/07/31 13:50:38 www Exp $ +# $Id: londocs.pm,v 1.4 2002/07/31 14:56:36 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,6 +30,8 @@ package Apache::londocs; use strict; use Apache::Constants qw(:common); +use Apache::lonnet; +use Apache::loncommon; sub handler { my $r = shift; @@ -37,11 +39,44 @@ sub handler { $r->send_http_header; return OK if $r->header_only; - my $url; +# does this user have privileges to post, etc? + my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}); - if ($ENV{'form.uploaddoc.filename'}) { - $url=&Apache::lonnet::userfileupload('uploaddoc'); + if ($allowed) { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['remove']) } + +# get course data + my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; + my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; + + +# upload a file + if (($ENV{'form.uploaddoc.filename'}) && ($allowed)) { + my $id=time.'_'.$ENV{'user.name'}.'_'.$ENV{'user.domain'}; + my $url=&Apache::lonnet::userfileupload('uploaddoc'); + if ($url=~/^error\:/) { + } else { + my $comment=$ENV{'form.comment'}; + $comment=~s/\/\>\;/g; + &Apache::lonnet::put('coursedocs', + { $id.'.url' => $url, + $id.'.comment' => $comment }, + $coursedom,$coursenum); + } + } + +# delete a file + if ($ENV{'form.remove'}=~/$ENV{'user.name'}\_$ENV{'user.domain'}$/) { + my $id=$ENV{'form.remove'}; + &Apache::lonnet::del('coursedocs', + [$id.'.url',$id.'.comment'], + $coursedom,$coursenum); + } + +# print screen $r->print(< @@ -49,14 +84,31 @@ sub handler {

Course Documents

+ENDDOCUMENT +# ------------------------------------------------------- Print headers to docs + my %currentdocs=&Apache::lonnet::dump('coursedocs',$coursedom,$coursenum); + foreach (sort keys (%currentdocs)) { + if ($_=~/(\d+)\_(\w+)\_(\w+)\.url/) { + $r->print('
'.localtime($1).' '.$2.' '.$3.'
'. + $currentdocs{$1.'_'.$2.'_'.$3.'.comment'}. + '
View'); + } + } +# ----------------------------------------------------------------- Upload form + if ($allowed) { + $r->print(< +

Post a new course document

- + +
Comment:
+
-$url - - -ENDDOCUMENT +ENDFORM + } + $r->print(''); return OK; }