[LON-CAPA-cvs] cvs: modules /raeburn imsimportdocs.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 09 Mar 2004 16:34:35 -0000


This is a MIME encoded message

--raeburn1078850075
Content-Type: text/plain

raeburn		Tue Mar  9 11:34:35 2004 EDT

  Modified files:              
    /modules/raeburn	imsimportdocs.pm 
  Log:
  Now allows specification of destination of top level sequence from IMS package (group import into current folder, or creation of a new folder). Propagation of files and folders added to /userfiles area on current server back to /userfiles area in lonUsers directory for course on home server.
  
  
--raeburn1078850075
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20040309113435.txt"

Index: modules/raeburn/imsimportdocs.pm
diff -u modules/raeburn/imsimportdocs.pm:1.1 modules/raeburn/imsimportdocs.pm:1.2
--- modules/raeburn/imsimportdocs.pm:1.1	Tue Mar  2 10:45:06 2004
+++ modules/raeburn/imsimportdocs.pm	Tue Mar  9 11:34:34 2004
@@ -1,10 +1,13 @@
 package Apache::imsimportdocs;
 
+use Apache::Constants qw(:common :http :methods);
 use Apache::lonnet;
+use Apache::londocs;
 use Apache::loncommon;
 use Apache::lonlocal;
 use Apache::imsprocessor;
 use LONCAPA::Configuration;
+use strict;
 
 sub jscript_one {
     my $javascript = shift;
@@ -94,6 +97,16 @@
 #;
 }
 
+sub jscript_three {
+    my $javascript = shift;
+    $$javascript = qq|
+function init(tf) {
+    setTimeout("self.close()",3000)
+    tf.submit();   
+}
+    |;
+}
+
 sub handler {
     my $r = shift;
     my $javascript = '';
@@ -153,6 +166,8 @@
         &jscript_one(\$javascript);
     } elsif ($ENV{'form.phase'} eq 'two') {
         &jscript_two(\$javascript);
+    } elsif ($ENV{'form.phase'} eq 'three') {
+        &jscript_three(\$javascript);
     }
 
 # print screen
@@ -174,9 +189,10 @@
     } elsif ($ENV{'form.phase'} eq 'two') {
         &display_two($r,$coursenum,\@areas,%cmsmap);
     } elsif ($ENV{'form.phase'} eq 'three') {
-        &display_three($r,$coursenum,$coursedom,$coursehome,\@areas,%cmsmap);
+        &display_three($r,$coursenum,$coursedom,$coursehome,$uname,$udom,\@areas,%cmsmap);
     }   
     $r->print("</body><html>");
+    return OK;
 } 
 
 sub uploadzip {
@@ -202,8 +218,7 @@
 }
 
 sub display_one {
-    my $r = shift;
-    my $timestamp = time;
+    my ($r) = @_;
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
 
     $r->print(<<ENDBLOCK);
@@ -301,7 +316,8 @@
     my ($r,$crs,$areasref,%cmsmap) = @_;
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
     my $cms = $ENV{'form.source'};
-    my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs);
+    my $timenow = time;
+    my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
     my $fname = &uploadzip($tempdir);
     my $unzip_result = '';
     my $manifest_result = '';
@@ -311,6 +327,7 @@
     my %resources = ();
     my %items = ();
     my %hrefs = ();
+    my %resinfo = ();
     my %count = ();
     my @bgcolors = ("#eeeeee","#dddddd");
 
@@ -342,7 +359,7 @@
                 );
          
     if ($unzip_result eq 'ok') {
-        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs);
+        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
         if ($manifest_result eq 'ok') {
             foreach my $res (sort keys %resources) {
                 if ($cms eq 'bb5') {
@@ -411,7 +428,7 @@
                 <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;$areaname{$area}&nbsp;&nbsp; - $count{$area} item(s)</font></td>");
                     if ($area eq 'board') {
                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;
-                 <select name='bb_handling'>
+                 <select name='db_handling'>
                   <option value='-2'>&lt;-- Check Import first
                  </select></font>
                 </td>");
@@ -443,9 +460,35 @@
       <tr>
        <td colspan='2'>&nbsp;<br /><br /></td>
       </tr>
+      <tr bgcolor='#CCCCFF'>
+       <td valign='middle'><img src='/res/adm/pages/bl_step4.gif'>
+       </td>
+       <td width='100%' align='left'>&nbsp;&nbsp;
+        <font face='arial,helvetica,sans-serif'><b>Choose display options for listing of contents of top level of package.</b></font>
+       </td>
+      </tr>
+      <tr>
+       <td colspan='2'>&nbsp;</td>
+      </tr>
       <tr>
        <td>&nbsp;</td>
-       <td><font face='arial,helvetica,sans-serif'>Once you have checked the checkboxes for all areas you wish to import from the IMS package, and selected options (if available) you should click the 'Complete Import' button.</font></td>
+       <td>
+        <table border='0'>
+         <tr>
+          <td><font face='arial,helvetica,sans-serif'><input type="radio" name="toplevel" value="newfolder" />Display listing of contents in a new folder, with folder name:&nbsp;&nbsp;&nbsp;<input type="text" name="foldername" size="15" value="Type Name Here" /></font></td>
+         </tr>
+         <tr>
+          <td><font face='arial,helvetica,sans-serif'><input type="radio" name="toplevel" value="oldfolder" />Append listing of contents of top level of package to contents list for the current folder.</font></td>
+         </tr>
+        </table>
+       </td>
+      </tr>
+      <tr>
+       <td colspan='2'>&nbsp;</td>
+      </tr>
+      <tr>
+       <td>&nbsp;</td>
+       <td><font face='arial,helvetica,sans-serif'>Once you have checked the checkboxes for all areas you wish to import from the IMS package, selected options (if available), and selected a display option for the package contents you should click the 'Complete Import' button.</font></td>
       </tr>
       <tr>
        <td colspan='2'>&nbsp;
@@ -484,38 +527,173 @@
 
 
 sub display_three {
-   my ($r,$crs,$cdom,$chome,$areas,%cmsmap) = @_;
-   $r->print("You reached phase three");
-   my $cms = $ENV{'form.source'};
-   my $tempdir = $ENV{'form.tempdir'};
-   my $longcrs = '';
-   if ($crs =~ m/^(\d)(\d)(\d)/) {
-       $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
-   }
-   my $destdir = '';
-   my %imports = ();
-   my @targets = ();
-   my %resources = ();
-   my %items = ();
-   my %hrefs = ();
-   my %urls = ();
-   foreach my $area (@{$areas}) {
-       if (defined($ENV{"form.$area"}) ) {          
-           if ($cms eq 'angel' && $area eq 'doc') {
-               foreach (@{$cmsmap{$cms}{$area}}) {
-                   $imports{$_} = 1;
-               }
-           } else {
-               $imports{$cmsmap{$cms}{$area}} = 1;
-           }
-       }
-   }
+    my ($r,$crs,$cdom,$chome,$uname,$udom,$areas,%cmsmap) = @_;
+    my $folder = $ENV{'form.folder'};
+    my $cms = $ENV{'form.source'};
+    my $tempdir = $ENV{'form.tempdir'};
+    my $longcrs = '';
+    if ($crs =~ m/^(\d)(\d)(\d)/) {
+        $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
+    }
+    my %imports = ();
+    my @targets = ();
+    my %resources = ();
+    my %items = ();
+    my %hrefs = ();
+    my %urls = ();
+    my %resinfo = ();
+    my %total = (
+                 page => 0,
+                 prob => 0,
+                 seq => 0,
+                 board => 0,         
+                 quiz => 0,
+                 surv => 0,
+                );
+    my @pages = ();
+    my @sequences = ();
+    my @resrcfiles = ();
+
+    my $timenow = time;
+
+    my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow;
+    my $dirname = $cdom.'/'.$crs.'/'.$timenow;
+    my $seqstem = "/uploaded/$cdom/$crs/$timenow";
+    my $db_handling = '';
+    my $user_handling = '';
+
+    my $toplevel = '';
+    my $foldername = '';
+    my %topitems = ();
+    if (defined($ENV{'form.toplevel'}) ) {
+        $toplevel = $ENV{'form.toplevel'};     
+    }
+    if (defined($ENV{'form.foldername'}) ) {
+        $foldername = $ENV{'form.foldername'}; 
+    }
+ 
+    foreach my $area (@{$areas}) {
+        if (defined($ENV{"form.$area"}) ) {          
+            if ($cms eq 'angel' && $area eq 'doc') {
+                foreach (@{$cmsmap{$cms}{$area}}) {
+                    $imports{$_} = 1;
+                }
+            } else {
+                $imports{$cmsmap{$cms}{$area}} = 1;
+            }
+            if ($area eq 'board') {
+                $db_handling = $ENV{'form.db_handling'};
+            } elsif ($area eq 'users') {
+                $user_handling = $ENV{'form.user_handling'};
+            }
+        }
+    }
    
-   my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs);
-   if ($manifest_result eq 'ok') {
-       &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets);
-       $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir); 
-   }
+    my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
+    if ($manifest_result eq 'ok') {
+        &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets);
+        my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow);
+
+        my @boards = ();
+        my @announcements = ();
+        my @quizzes = ();
+        my @surveys = ();
+        my @groups = ();
+        my %messages = ();
+        my @timestamp = ();
+        my %boardnum = ();
+        my @topurls = ();
+        my @topnames = ();
+
+        &Apache::imsprocessor::process_resinfo($cms,$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$dirname,$seqstem,\@resrcfiles);
+
+        &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%resinfo,\%items,\%resources,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames);
+ 
+        foreach my $item (@pages) {
+            my $path = $timenow.'/pages/';
+            &copy_items($item,$path,$cdom,$chome,$crs);
+        }
+        foreach my $item (@sequences) {
+            unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
+                my $path = $timenow.'/sequences/';
+                &copy_items($item,$path,$cdom,$chome,$crs);
+            }
+        }
+        foreach my $item (@resrcfiles) {
+            my $path = $timenow.'/resfiles/';
+            &copy_items($item,$path,$cdom,$chome,$crs);
+        }
+
+        my @imports = ();
+        if ($toplevel eq 'oldfolder') {
+            for (my $i=0; $i<@topurls; $i++) {
+                my $url = &Apache::lonnet::unescape($topurls[$i]);
+                my $name = &Apache::lonnet::unescape($topnames[$i]);
+                push @imports, $name, $url;
+            }
+        } elsif ($toplevel eq 'newfolder') {
+            my $url = &Apache::lonnet::unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
+            my $name = &Apache::lonnet::unescape("$ENV{'form.foldername'}");
+            push @imports, $name, $url;
+        }
+        my $errtext='';
+        my $fatal=0;
+        ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
+        if ($#Apache::lonratedt::order<1) {
+            $Apache::lonratedt::order[0]=1;
+            $Apache::lonratedt::resources[1]='';
+        }
+        my ($errtext,$fatal)=&Apache::londocs::group_import($crs, $cdom, $folder,@imports);
+        if ($fatal) {
+            print STDERR "Fatal error during group_import\n";
+        }
+    }
+    $r->print(<<ENDBLOCK);
+  <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
+   <tr>
+    <td colspan='2'>
+     <table border='0' cellspacing='0' cellpadding='0'>
+      <tr>
+       <td colspan='2'  align='left'>&nbsp;
+       </td>
+      </tr>
+      <tr bgcolor='#CCCCFF'>
+       <td valign='middle'><img src='/res/adm/pages/bl_step5.gif'>
+       </td>
+       <td width='100%' align='left'>&nbsp;&nbsp;
+        <font face='arial,helvetica,sans-serif'><b>Your import is complete</b></font>
+       </td>
+      </tr>
+      <tr>
+       <td colspan='2'>&nbsp;</td>
+      </tr>
+      <tr>
+       <td>&nbsp;</td>
+       <td>
+ENDBLOCK
+    my $initblock = qq|  
+         <form method="post" action="/adm/roles" target="loncapaclient" name="importDone">
+           <input type="hidden" name="orgurl" value="/adm/coursedocs" />
+           <input type="hidden" name="selectrole" value="1" />
+           <h3><font color="red">Changes will become active for your current session after
+           <input type="hidden" name="$ENV{'request.role'}" value="1" />
+           <input type="button" value="|;
+    $initblock .= &mt('re-initializing course');
+    $initblock .= qq|" onClick="javascript:init(this.form)"/>|;
+    $initblock .= &mt('or the next time you log in.');
+    $initblock .= qq|</font></h3></form>|;  
+    $r->print($initblock);
+    $r->print(<<ENDBLOCKTWO);
+     </table>
+    </td>
+   </tr>
+  </table>
+ENDBLOCKTWO
+}
+
+sub copy_items {
+    my ($filename,$fpath,$cdom,$chome,$crs) = @_;    
+    my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$filename.':'.$fpath,$chome);
 }
 
 1;

--raeburn1078850075--