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

www lon-capa-cvs@mail.lon-capa.org
Mon, 08 Sep 2003 18:56:09 -0000


www		Mon Sep  8 14:56:09 2003 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  Saving my work on "Dump course to author space"
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.73 loncom/interface/londocs.pm:1.74
--- loncom/interface/londocs.pm:1.73	Fri Sep  5 14:11:26 2003
+++ loncom/interface/londocs.pm	Mon Sep  8 14:56:09 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.73 2003/09/05 18:11:26 bowersj2 Exp $
+# $Id: londocs.pm,v 1.74 2003/09/08 18:56:09 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@
 use Apache::lonratedt;
 use Apache::lonratsrv;
 use Apache::lonxml;
+use Apache::loncreatecourse;
 use HTML::Entities;
 use GDBM_File;
 
@@ -72,6 +73,63 @@
                                 $map,1);
 }
 
+# ----------------------------------------- Return hash with valid author names
+
+sub authorhosts {
+    my %outhash=();
+    my $home=0;
+    my $other=0;
+    foreach (keys %ENV) {
+	if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
+	    my $role=$1;
+	    my $realm=$2;
+	    my ($start,$end)=split(/\./,$ENV{$_});
+	    if (($start) && ($start>time)) { next; }
+	    if (($end) && (time>$end)) { next; }
+	    my $ca; my $cd;
+	    if ($1 eq 'au') {
+		$ca=$ENV{'user.name'};
+		$cd=$ENV{'user.domain'};
+	    } else {
+		($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
+	    }
+	    if (&Apache::lonnet::homeserver($ca,$cd) eq 
+		$Apache::lonnet::perlvar{'lonHostID'}) {
+		$home++;
+		$outhash{'home_'.$ca.'@'.$cd}=1;
+	    } else {
+		$outhash{'otherhome_'.$ca.'@'.$cd}=
+		    &Apache::lonnet::homeserver($ca,$cd);
+		$other++;
+	    }
+	}
+    }
+    return ($home,$other,%outhash);
+}
+# ------------------------------------------------------ Generate "dump" button
+
+sub dumpbutton {
+    my ($home,$other,%outhash)=&authorhosts();
+    if ($home+$other==0) { return ''; }
+    my $output='</td><td bgcolor="#DDDDCC">';
+    if ($home) {
+	return '</td><td bgcolor="#DDDDCC">'.
+	    '<input type="submit" name="dumpcourse" value="Dump Course DOCS to Construction Space" />';
+    } else {
+	return'</td><td bgcolor="#DDDDCC">'.
+      'Dump Course DOCS to Construction Space: available on other servers';
+    }
+}
+
+# -------------------------------------------------------- Actually dump course
+
+sub dumpcourse {
+    my ($home,$other,%outhash)=&authorhosts();
+    unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
+    my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
+
+}
+
 # Imports the given (name, url) resources into the course
 # coursenum, coursedom, and folder must precede the list
 sub group_import {
@@ -664,8 +722,7 @@
 					'','',$showdoc));
   unless ($showdoc) {
     if ($allowed) {
-       $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
-		     'Editing the Table of Contents for your Course'));
+       my $dumpbut=&dumpbutton();
        $r->print(<<ENDCOURSEVERIFY);
 <form name="renameform" method="post" action="/adm/coursedocs">
 <input type="hidden" name="title" />
@@ -677,10 +734,17 @@
 <input type="hidden" name="folder" />
 </form>
 <form action="/adm/coursedocs" method="post" name="courseverify">
+<table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
+<tr><td bgcolor="#DDDDCC">
 <input type="submit" name="verify" value="Verify Content" />
+</td><td bgcolor="#DDDDCC">
 <input type="submit" name="versions" value="Check Resource Versions" />
+$dumpbut
+</td></tr></table>
 </form>
 ENDCOURSEVERIFY
+       $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
+		     'Editing the Table of Contents for your Course'));
     }
 # --------------------------------------------------------- Standard documents
     $r->print('<table border=2 cellspacing=4 cellpadding=4>');