Diff for /loncom/imspackages/imsimportdocs.pm between versions 1.1 and 1.27

version 1.1, 2004/03/02 15:45:06 version 1.27, 2009/11/20 16:20:17
Line 1 Line 1
   # The LearningOnline Network with CAPA
   #
   # $Id$
   #
   # Copyright Michigan State University Board of Trustees
   #
   # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   #
   # LON-CAPA is free software; you can redistribute it and/or modify
   # it under the terms of the GNU General Public License as published by
   # the Free Software Foundation; either version 2 of the License, or
   # (at your option) any later version.
   #
   # LON-CAPA is distributed in the hope that it will be useful,
   # but WITHOUT ANY WARRANTY; without even the implied warranty of
   # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   # GNU General Public License for more details.
   #
   # You should have received a copy of the GNU General Public License
   # along with LON-CAPA; if not, write to the Free Software
   # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   #
   # /home/httpd/html/adm/gpl.txt
   #
   # http://www.lon-capa.org/
   #
   
 package Apache::imsimportdocs;  package Apache::imsimportdocs;
   
   use Apache::Constants qw(:common :http :methods);
 use Apache::lonnet;  use Apache::lonnet;
   use Apache::londocs;
 use Apache::loncommon;  use Apache::loncommon;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::imsprocessor;  use Apache::imsprocessor;
 use LONCAPA::Configuration;  use LONCAPA::Configuration;
   use LONCAPA::map();
   use lib '/home/httpd/lib/perl/';
   use LONCAPA;
    
   use strict;
   
 sub jscript_one {  sub jscript_one {
     my $javascript = shift;      my $javascript = shift;
Line 41  function setOptions(caller,itemnum) { Line 75  function setOptions(caller,itemnum) {
     if (caller == "board") {      if (caller == "board") {
       opForm.elements[menu].options[0] = new Option("Select","-1",true,true)        opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
       opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)        opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
       opForm.elements[menu].options[2] = new Option("Import topics & posts (with author)","allpost",true,true)        opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true)
       opForm.elements[menu].options[3] = new Option("Import topics & posts (no author)","allanon",true,true)        opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true)
     }      }
     else {       else { 
       if (caller == "users") {        if (caller == "users") {
Line 94  function nextPage(caller) { Line 128  function nextPage(caller) {
 #;  #;
 }  }
   
   sub jscript_three {
       my $javascript = shift;
       $$javascript = qq|
   function init(tf) {
       setTimeout("self.close()",3000)
       tf.submit();   
   }
       |;
   }
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     my $javascript = '';      my $javascript = '';
Line 101  sub handler { Line 145  sub handler {
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
   
     my @areas = ("doc","extlink","announce","staff","board","quiz","survey","pool","users");      my @areas = ();
     my %cmsmap = ();      my %cmsmap = ();
     %{$cmsmap{bb5}} = (      my %areaname = ();
                 announce => 'resource/x-bb-announcement',      &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname);
                 board => 'resource/x-bb-discussionboard',  
                 doc => 'resource/x-bb-document',  
                 extlink => 'resource/x-bb-externallink',  
                 pool => 'assessment/x-bb-pool',  
                 quiz => 'assessment/x-bb-quiz',  
                 staff => 'resource/x-bb-staffinfo',  
                 survey => 'assessment/x-bb-survey',  
                 users => 'course/x-bb-user',  
                 );  
    
     %{$cmsmap{angel}} =  (  
                 board => 'BOARD',  
                 extlink => 'LINK',  
                 msg => 'MESSAGE',  
                 quiz => 'QUIZ',  
                 survey => 'FORM',  
                 );  
   
     @{$cmsmap{angel}{doc}} = ('FILE','PAGE');  
   
 # get course data  # get course data
     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};      my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};      my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
     my $coursehome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'};  
   
 # get personal data  # get personal data
     
     my $uname=$ENV{'user.name'};      my $uname=$env{'user.name'};
     my $udom=$ENV{'user.domain'};      my $udom=$env{'user.domain'};
     my $plainname=&Apache::lonnet::escape(      my $plainname=&escape(
                      &Apache::loncommon::plainname($uname,$udom));                       &Apache::loncommon::plainname($uname,$udom));
   
 # does this user have privileges to post, etc?  # does this user have privileges to post, etc?
     my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});      my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
     unless ($allowed) {      unless ($allowed) {
         $r->print("<html><head><title>The LearningOnline Network with CAPA</title></head>");          $r->print(&Apache::loncommon::start_page('Import IMS package',undef,
         $r->print(&Apache::loncommon::bodytag('Import IMS package'));                                                     {'only_body' => 1,}));  
         $r->print('<h3>'.&mt('Modification of Course Contents Disallowed').'</h3>'.&mt('Your current role does not grant you the right to modify course content in this course.').'</body></html>');          $r->print(
               '<p class="LC_error">'
              .&mt('Modification of Course Contents Disallowed')
              .'</p><p>'
              .&mt('Your current role does not grant you the right to modify course content in this course.')
              .'</p>'
              .&Apache::loncommon::end_page()
           );
         return OK;          return OK;
     }      }
   
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
        ['phase']);         ['phase']);
   
     if ($ENV{'form.phase'} eq 'one') {          if ($env{'form.phase'} eq 'one') {    
         &jscript_one(\$javascript);          &jscript_one(\$javascript);
     } elsif ($ENV{'form.phase'} eq 'two') {      } elsif ($env{'form.phase'} eq 'two') {
         &jscript_two(\$javascript);          &jscript_two(\$javascript);
       } elsif ($env{'form.phase'} eq 'three') {
           &jscript_three(\$javascript);
     }      }
   
       $javascript = 
           "<script type=\"text/javascript\">\n".
           "//<!--\n$javascript\n// --></script>\n";
       my $headline = 'Import IMS package';
       my $start_page = &Apache::loncommon::start_page($headline,
                                                       $javascript,
                                                       {'only_body' => 1,})
                       .'<h1>'.&mt($headline).'</h1>';
 # print screen  # print screen
     $r->print(<<ENDHEAD);      $r->print($start_page);
 <html>  
 <head>      if ($env{'form.phase'} eq 'one') {
 <title>The LearningOnline Network with CAPA</title>  
 <script type="text/javascript">  
 <!--  
 $javascript  
 -->  
 </script>  
 </head>  
 ENDHEAD  
 # -------------------------------------------------------------------- Body tag  
     $r->print(&Apache::loncommon::bodytag('Import IMS package'));  
     if ($ENV{'form.phase'} eq 'one') {  
         &display_one($r);                 &display_one($r);       
     } elsif ($ENV{'form.phase'} eq 'two') {      } elsif ($env{'form.phase'} eq 'two') {
         &display_two($r,$coursenum,\@areas,%cmsmap);          &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap);
     } elsif ($ENV{'form.phase'} eq 'three') {      } elsif ($env{'form.phase'} eq 'three') {
         &display_three($r,$coursenum,$coursedom,$coursehome,\@areas,%cmsmap);          &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
     }         }   
     $r->print("</body><html>");      $r->print(&Apache::loncommon::end_page());
       return OK;
 }   } 
   
 sub uploadzip {  
     my $tempdir = shift;  
     my $fname=$ENV{'form.uploadname.filename'};  
 # Replace Windows backslashes by forward slashes  
     $fname=~s/\\/\//g;  
 # Get rid of everything but the actual filename  
     $fname=~s/^.*\/([^\/]+)$/$1/;  
 # Replace spaces by underscores  
     $fname=~s/\s+/\_/g;  
 # Replace all other weird characters by nothing  
     $fname=~s/[^\w\.\-]//g;  
 # See if there is anything left  
     unless ($fname) { return 'error: no uploaded file'; }  
   
 # Save the file  
     chomp($ENV{'form.uploadname'});  
     open(my $fh,'>'.$tempdir.'/'.$fname);  
     print $fh $ENV{'form.uploadname'};  
     close($fh);  
     return $fname;     
 }  
   
 sub display_one {  sub display_one {
     my $r = shift;      my ($r) = @_;
     my $timestamp = time;  
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
   
     $r->print(<<ENDBLOCK);      $r->print(
 <form action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" name="pickcms">          '<form action="/adm/imsimportdocs" method="post"'
   <table border='0' bgcolor='#F6F6F6' cellspacing='0' cellpadding ='0' width='100%'>         .' enctype="multipart/form-data" name="pickcms">'
    <tr>         .&Apache::lonhtmlcommon::topic_bar(
     <td colspan='2'>              1,&mt('Specify the Course Management system used to create the package'))
      <table border='0' cellspacing='0' cellpadding='0'>         .&mt('Please choose the CMS used to create your IMS content package:').' '
       <tr>         .'<select name="source">'
         <td colspan='2'  align='left'>&nbsp;         .'<option value="-1" selected="selected">'.&mt('Please select').'</option>'
         </td>         .'<option value="bb5">Blackboard 5</option>'
        </tr>         .'<option value="bb6">Blackboard 6</option>'
        <tr bgcolor='#CCCCFF'>         .'<option value="angel5">ANGEL 5.5</option>'
         <td valign='middle'><img src='/res/adm/pages/bl_step1.gif'>&nbsp;         .'<option value="webctce4">WebCT 4 Campus Edition</option>'
         </td>         .'</select>'
         <td width='100%' align='left'>&nbsp;&nbsp;      );
          <font face='arial,helvetica,sans-serif'><b>Specify the Course Management system used to create the package.</b>&nbsp;&nbsp;      $r->print(
          </font>         &Apache::lonhtmlcommon::topic_bar(
        </td>             2,&mt('Locate the IMS content package you wish to upload'))
       </tr>        .'<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
       <tr>        .'<input type="hidden" name="phase" value="two" />'
        <td colspan='2'>&nbsp;</td>        .&mt('File:')
       </tr>        .' <input type="file" name="uploadname" size="40" />'
       <tr>      );
        <td>&nbsp;</td>      $r->print(
        <td>         '<hr />'
         <font face='Arial,Helvetica,sans-serif'>        .'<p>'
 Please choose the CMS used to create your IMS content package.&nbsp;&nbsp;        .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
         <select name="source">        .' onclick="javascript:self.close()" />'
          <option value='-1' selected="true">Please select        .' '
          <option value='bb5'>Blackboard 5        .'<input type="button" name="nextpage" value="'.&mt('Upload IMS package').'"'
          <option value='angel'>ANGEL        .' onclick="javascript:nextPage()" />'
         </select>        .'</p>'
         </font>      );
        </td>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;</td>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;</td>  
       </tr>  
       <tr bgcolor='#CCCCFF'>  
         <td valign='middle'><img src='/res/adm/pages/bl_step2.gif'>&nbsp;  
         </td>  
         <td width='100%' align='left'>&nbsp;&nbsp;  
          <font face='arial,helvetica,sans-serif'><b>Locate the IMS content package you wish to upload.</b>&nbsp;&nbsp;  
          </font>  
        </td>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;</td>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;  
         <input type="hidden" name="folder" value="$ENV{'form.folder'}" />  
         <input type="hidden" name="phase" value="two" />  
         <input type="file" name="uploadname" size="40" />  
        </td>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;</td>  
       </tr>  
       <tr>  
        <td>&nbsp;</td>  
        <td><font face='arial,helvetica,sans-serif'>If you have selected the CMS, and located the IMS package, you should click the 'Upload IMS package' button to upload the file to the server.</font></td>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;</td>  
       </tr>  
       <tr  
        <td colspan='2'>  
         <table border='0' cellspacing='0' cellpadding='0' width="100%">  
          <tr>  
           <td align='left'>  
            <input type="button" name="exitpage" value="Exit now" onClick="javascript:self.close()">  
           </td>  
           <td align='right'>  
            <input type="button" name="nextpage" value="Upload IMS package" onClick="javascript:nextPage()">  
           </td>  
          </tr>  
         </table>  
        </td>  
       </tr>  
      </table>  
     </td>  
    </tr>  
   </table>  
 </form>  
 ENDBLOCK  
 }  }
   
   
 sub display_two {  sub display_two {
     my ($r,$crs,$areasref,%cmsmap) = @_;      my ($r,$crs,$areasref,$areaname,%cmsmap) = @_;
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
     my $cms = $ENV{'form.source'};      my $cms = $env{'form.source'};
     my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs);      my $timenow = time;
     my $fname = &uploadzip($tempdir);      my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
       my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir);
     my $unzip_result = '';      my $unzip_result = '';
     my $manifest_result = '';      my $manifest_result = '';
     unless ($tempdir eq '') {      unless ($tempdir eq '') {
         $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);          $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
     }      }
     my %resources = ();      my %resources = ();
       my %includedres = ();
       my %includeditems = ();
     my %items = ();      my %items = ();
     my %hrefs = ();      my %hrefs = ();
       my %resinfo = ();
     my %count = ();      my %count = ();
     my @bgcolors = ("#eeeeee","#dddddd");  
   
     my $counter = 0;      my $counter = 0;
     my $iter = 0;  
     my %count = (      my %count = (
                 announce => 0,                  announce => 0,
                 board => 0,                  board => 0,
Line 329  sub display_two { Line 283  sub display_two {
                 users => 0,                  users => 0,
                 );                  );
   
     my %areaname = (      if ($unzip_result ne 'ok') {
                 announce => 'Announcements',          $r->print(
                 board => 'Discussion Boards',              '<p class="LC_warning">'
                 doc => 'Documents, pages &amp; folders',             .&mt('Processing of your IMS package failed because the file you'
                 extlink => 'Links to external sites',                 .' uploaded could not be unzipped.')
                 pool => 'Question pools',             .'</p>'
                 quiz => 'Quizzes',          );
                 staff => 'Staff information',          return();
                 survey => 'Surveys',      }
                 users => 'Enrollment',  
                 );      # Get manifest file from package
                $manifest_result = &Apache::imsprocessor::process_manifest(
     if ($unzip_result eq 'ok') {                             $cms,$tempdir,\%resources,\%items,\%hrefs,
         $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs);                             \%resinfo,'choose',\%includedres,\%includeditems);
         if ($manifest_result eq 'ok') {      if ($manifest_result ne 'ok') {
             foreach my $res (sort keys %resources) {          $r->print(
                 if ($cms eq 'bb5') {             '<p class="LC_warning">'
                     foreach my $area (keys %{$cmsmap{$cms}}) {            .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.')
                         if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {            .'</p>'
                             $count{$area} ++;          );
                         }          return();
                     }      }
                 } elsif ($cms eq 'angel') {  
                     foreach my $area (keys %{$cmsmap{$cms}}) {      # Count areas depending on cms version
                         if ($area eq 'doc') {      foreach my $res (sort keys %resources) {
                             if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {          if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') {
                                 $count{$area} ++;              foreach my $area (keys %{$cmsmap{$cms}}) {
                             }                  if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
                         } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {                      $count{$area} ++;
                             $count{$area} ++;                  }
                         }              }
           } elsif ($cms eq 'angel5') {
               foreach my $area (keys %{$cmsmap{$cms}}) {
                   if ($area eq 'doc') {
                       if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
                           $count{$area} ++;
                     }                      }
                   } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
                       $count{$area} ++;
                 }                  }
             }              }
             $r->print(<<ENDBLOCK);          } else { # Unknown cms format
 <form name="pickoptions" method="post">              $r->print(
                   '<span class="LC_warning">'
                  .&mt('Unsupported IMS format: [_1]',$cms)
                  .'</span><br />'
               );
               # return();
           }
       }
   
   
       # Start output: Step 3 and step 4
   
       $r->print(
           '<form name="pickoptions" method="post">'
          .&Apache::lonhtmlcommon::topic_bar(
               3,&mt('Choose which content types you wish to import'))
          .'<p>'
          .&mt('Check the checkboxes for all areas you wish to import from the IMS package:')
          .'</p>'
       );
   
       $r->print(
           &Apache::loncommon::start_data_table()
          .&Apache::loncommon::start_data_table_header_row()
          .'<th>'.&mt('Import?').'</th>'
          .'<th>'.&mt('Content type').'</th>'
          .'<th>'.&mt('Additional options').'</th>'
          .&Apache::loncommon::end_data_table_header_row()
       );
   
       # Display import row for each area/content type
       foreach my $area (@{$areasref}) {
           unless ($count{$area} > 0) { next };
   
           my $count_tag = 'flag_'.$counter;
   
           # Checkbox: Import?
           $r->print(
               &Apache::loncommon::start_data_table_row()
              .'<td><input name="'.$area.'" type="checkbox"'
           );
           if ($area eq 'board' || $area eq 'users') {
               $r->print(qq| onclick='javascript:setOptions("$area","$counter")'|);
           }
   
           $r->print(' /></td>');
   
           # Content Type
           $r->print(
               '<td>'
              .$$areaname{$area}.'&nbsp;&nbsp; - '
              .&mt('[quant,_1,item]',$count{$area})
              .'</td>'
           );
   
           # Additional Options
           $r->print('<td>');
           if ($area eq 'board') {
               $r->print(
                   '<select name="db_handling">'
                  .'<option value="-2">&lt;-- '.&mt('Check Import first').'</option>'
                  .'</select>'
               );
           } elsif ($area eq 'users') {
               $r->print(
                   '<select name="user_handling">'
                  .'<option value="-2">&lt;-- '.&mt('Check Import first').'</option>'
                  .'</select>'
               );
           } else {
               $r->print(
                   &mt('None')
                  .'<input type="hidden" name="'.$count_tag.'" />'
               );
           }
           $r->print('</td>');
   
           $r->print(&Apache::loncommon::end_data_table_row());
           $counter ++;
       }
   
       $r->print(&Apache::loncommon::end_data_table());
   
       $r->print(
           &Apache::lonhtmlcommon::topic_bar(
               4,&mt('Choose display options for listing of contents of top level of package'))
          .'<p>'
          .&mt('Select a display option for the package content:')
          .'</p>'
       );
       $r->print(
           '<label>'
          .'<input type="radio" name="toplevel" value="newfolder" />'
          .&mt('Display listing of contents in a new folder, with folder name:')
          .'</label>'
          .' <input type="text" name="foldername" size="15" value="'.&mt('Type Name Here').'" />'
          .'<br />'
          .'<label>'
          .'<input type="radio" name="toplevel" value="oldfolder" checked="checked" />'
          .&mt('Append listing of contents of top level of package to contents list for the current folder.')
          .'</label>'
       );
   
       # Buttons
       $r->print(
           '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
          .'<input type="hidden" name="source" value="'.$cms.'" />'
          .'<input type="hidden" name="tempdir" value="'.$tempdir.'" />'
          .'<input type="hidden" name="phase" value="three" />'
       );
       $r->print(
           '<hr />'
          .'<p>'
          .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
          .' onclick="javascript:self.close()" />'
          .' '
          .'<input type="button" name="nextpage" value="'.&mt('Finish Import').'"'
          .' onclick="javascript:nextPage('.$counter.')" />'
          .'</p>'
       );
   
      $r->print('</form>');
   }
   
   
   sub display_three {
       my ($r,$crs,$cdom,$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 %importareas = ();
       my %includedres = ();
       my %includeditems = ();
       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 $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"}) && ($env{'form.'.$area} ne '')) {
               if ($cms eq 'angel5' && $area eq 'doc') {
                   foreach (@{$cmsmap{$cms}{$area}}) {
                       $importareas{$_} = 1;
                   }
               } else {
                   $importareas{$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,\%resinfo,'prepare',\%includedres,\%includeditems);
       if ($manifest_result eq 'ok') {
           foreach my $res (sort keys %resources) {
               if ($importareas{$resources{$res}{type}}) {
                   $includedres{$res} = 1;
               }
           }
           foreach my $itm (sort keys %items) {
               &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
           }
       }
       foreach my $itm (sort keys %includeditems) {
           &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
       }
   
       $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
       if ($manifest_result eq 'ok') {
   
           my @path = ($cdom,$crs,$timenow);
           my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
           foreach my $item (@path) {
               $fullpath .= '/'.$item;
               if (!-e "$fullpath") {
                   mkdir("$fullpath",0770);
               }
           }
           my @namedirs = ("resfiles","sequences","pages","problems");
           foreach my $name (@namedirs) {
               if (!-e "$fullpath/$name") {
                   mkdir("$fullpath/$name",0770);
               }
           }
           &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
   
           my @boards = ();
           my @announcements = ();
           my @quizzes = ();
           my @surveys = ();
           my @pools = ();
           my @groups = ();
           my %messages = ();
           my @timestamp = ();
           my %boardnum = ();
           my @topurls = ();
           my @topnames = ();
           my @packages = ();
   
           &Apache::imsprocessor::process_resinfo($cms,'DOCS',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
   
           my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
   
           &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems);
   
           foreach my $item (@pages) {
               my $filename = $timenow.'/pages/'.$item;
               my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
           }
           foreach my $item (@sequences) {
               unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
                   my $filename = $timenow.'/sequences/'.$item;
                   my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
               }
           }
           foreach my $item (@resrcfiles) {
               my $filename = $timenow.'/resfiles/'.$item;
               my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
           }
   
           my @imports = ();
           if ($toplevel eq 'oldfolder') {
               for (my $i=0; $i<@topurls; $i++) {
                   my $url = &unescape($topurls[$i]);
                   my $name = &unescape($topnames[$i]);
                   push(@imports, [$name, $url]);
               }
           } elsif ($toplevel eq 'newfolder') {
               my $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
               my $name = &unescape("$env{'form.foldername'}");
               push(@imports, [$name, $url]);
           }
           my $errtext='';
           my $fatal=0;
           ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
           if ($#LONCAPA::map::order<1) {
               $LONCAPA::map::order[0]=1;
               $LONCAPA::map::resources[1]='';
           }
           my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
           if ($fatal) {
               &Apache::lonnet::logthis("Fatal error during group_import.");
           }
       }
       if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
           system("rm -r -f $tempdir");
       }
       $r->print(<<ENDBLOCK);
   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>    <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
    <tr>     <tr>
     <td colspan='2'>      <td colspan='2'>
Line 374  sub display_two { Line 619  sub display_two {
        </td>         </td>
       </tr>        </tr>
       <tr bgcolor='#CCCCFF'>        <tr bgcolor='#CCCCFF'>
        <td valign='middle'><img src='/res/adm/pages/bl_step3.gif'>         <td valign="middle"><img src="/res/adm/pages/bl_step5.gif" alt="5" />
        </td>         </td>
        <td width='100%' align='left'>&nbsp;&nbsp;         <td width='100%' align='left'>&nbsp;&nbsp;
         <font face='arial,helvetica,sans-serif'><b>Choose which content types you wish to import</b></font>          <font face='arial,helvetica,sans-serif'><b>Your import is complete</b></font>
        </td>         </td>
       </tr>        </tr>
       <tr>        <tr>
Line 386  sub display_two { Line 631  sub display_two {
       <tr>        <tr>
        <td>&nbsp;</td>         <td>&nbsp;</td>
        <td>         <td>
         <table border='0' cellspacing='0' cellpadding='1' bgcolor='#000000'>  
          <tr>  
           <td>  
            <table border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' width='100%'>  
             <tr>  
              <td>  
               <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width='100%'>  
                <tr bgcolor='#CCCCFF'>  
                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Import?</b></font></td>             
                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Content type</b></font></td>  
                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Additional options</b></font></td>  
                </tr>  
 ENDBLOCK  ENDBLOCK
             foreach my $area (@{$areasref}) {      my $initblock = qq|  
                 if ($count{$area} > 0) {           <form method="post" action="/adm/roles" target="loncapaclient" name="importDone">
                     my $count_tag = 'flag_'.$counter;             <input type="hidden" name="orgurl" value="/adm/coursedocs" />
                     $r->print("               <tr bgcolor='@bgcolors[$iter]'>             <input type="hidden" name="selectrole" value="1" />
                 <td align='left'><font face='arial,helvetica,sans-serif'><input name='$area' type='checkbox' ");             <h3><font color="red">Changes will become active for your current session after
                     if ($area eq 'board' || $area eq 'users') {             <input type="hidden" name="$env{'request.role'}" value="1" />
                         $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|);             <input type="button" value="|;
                     }      $initblock .= &mt('re-initializing course');
                     $r->print("/></font></td>      $initblock .= qq|" onClick="javascript:init(this.form)" />|;
                 <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;$areaname{$area}&nbsp;&nbsp; - $count{$area} item(s)</font></td>");      $initblock .= ', '.&mt('or the next time you log in.');
                     if ($area eq 'board') {      $initblock .= qq|</font></h3></form>|;  
                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;      $r->print($initblock);
                  <select name='bb_handling'>      $r->print(<<ENDBLOCKTWO);
                   <option value='-2'>&lt;-- Check Import first  
                  </select></font>  
                 </td>");  
                     } elsif ($area eq 'users') {  
                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;  
                  <select name='user_handling'>  
                   <option value='-2'>&lt;-- Check Import first  
                  </select>  
                  </font>          
                 </td>");  
                     } else {  
                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;None<input type='hidden' name='$count_tag' /></font></td>");  
                     }  
                     $counter ++;  
                     $iter = $counter%2;  
                 }  
             }  
             $r->print(<<ENDDOCUMENT);  
                </tr>  
               </table>  
              </td>  
             </tr>  
            </table>  
           </td>  
          </tr>  
         </table>  
        </td>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;<br /><br /></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>  
       </tr>  
       <tr>  
        <td colspan='2'>&nbsp;  
           <input type="hidden" name="folder" value="$ENV{'form.folder'}" />  
           <input type="hidden" name="source" value="$cms" />  
           <input type="hidden" name="tempdir" value="$tempdir" />  
           <input type="hidden" name="phase" value="three" />  
        </td>  
       </tr>  
       <tr>  
        <td colspan='2'>  
         <table border='0' cellspacing='0' cellpadding='0' width="100%">  
          <tr>  
           <td align='left'>  
            <input type='button' name='exitpage' value='Exit now' onClick="javascript:self.close()">  
           </td>  
           <td align='right'>  
            <input type="button" name="nextpage" value="Complete Import" onClick="javascript:nextPage($counter)">  
           </td>  
          </tr>  
         </table>  
        </td>  
       </tr>  
      </table>       </table>
     </td>      </td>
    </tr>     </tr>
   </table>    </table>
 ENDDOCUMENT  ENDBLOCKTWO
         } else {  
             $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n");  
         }  
     } else {  
         $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n");  
     }  
 }  
   
   
 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 $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);   
    }  
 }  }
   
 1;  1;

Removed from v.1.1  
changed lines
  Added in v.1.27


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>