[LON-CAPA-cvs] cvs: loncom /interface londocs.pm

www lon-capa-cvs@mail.lon-capa.org
Wed, 31 Jul 2002 14:56:36 -0000


www		Wed Jul 31 10:56:36 2002 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  Raw functionality there, no LaTeX, no token-security, no remove
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.3 loncom/interface/londocs.pm:1.4
--- loncom/interface/londocs.pm:1.3	Wed Jul 31 09:50:38 2002
+++ loncom/interface/londocs.pm	Wed Jul 31 10:56:36 2002
@@ -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 @@
 
 use strict;
 use Apache::Constants qw(:common);
+use Apache::lonnet;
+use Apache::loncommon;
 
 sub handler {
     my $r = shift;
@@ -37,11 +39,44 @@
     $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/\</\&lt\;/g;
+           $comment=~s/\>/\&gt\;/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(<<ENDDOCUMENT);
 <html>
 <head>
@@ -49,14 +84,31 @@
 </head>
 <body bgcolor="#FFFFFF">
 <h1>Course Documents</h1>
+ENDDOCUMENT
+# ------------------------------------------------------- Print headers to docs
+   my %currentdocs=&Apache::lonnet::dump('coursedocs',$coursedom,$coursenum);
+   foreach (sort keys (%currentdocs)) {
+       if ($_=~/(\d+)\_(\w+)\_(\w+)\.url/) {
+	   $r->print('<hr>'.localtime($1).' '.$2.' '.$3.'<blockquote>'.
+		     $currentdocs{$1.'_'.$2.'_'.$3.'.comment'}.
+                     '</blockquote><a href="'.$currentdocs{$_}.'">View</a>');
+       }
+   }
+# ----------------------------------------------------------------- Upload form
+   if ($allowed) {
+       $r->print(<<ENDFORM);
+<hr />
+<h3>Post a new course document</h3>
 <form method="post" enctype="multipart/form-data">
-<input type="file" name="uploaddoc" size="20">
+<input type="file" name="uploaddoc" size="50">
+<br />Comment:<br />
+<textarea cols=50 rows=4 name='comment'>
+</textarea>
 <input type="submit" value="Upload Document">
 </form>
-$url
-</body>
-</html>
-ENDDOCUMENT
+ENDFORM
+    }
+    $r->print('</body></html>');
     return OK;
 }