File:  [LON-CAPA] / loncom / imspackages / imsimportdocs.pm
Revision 1.29: download - view: text, annotated - select for diffs
Fri Nov 20 18:25:34 2009 UTC (14 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_9_99_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
XHTML, balanced tags:
- Close form in phase 1
- Added dummy action to form in phase 2
- Lower case attributes in phase 3

- Added some comments and line breaks to phase 1 code

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: imsimportdocs.pm,v 1.29 2009/11/20 18:25:34 bisitz Exp $
    4: #
    5: # Copyright Michigan State University Board of Trustees
    6: #
    7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    8: #
    9: # LON-CAPA is free software; you can redistribute it and/or modify
   10: # it under the terms of the GNU General Public License as published by
   11: # the Free Software Foundation; either version 2 of the License, or
   12: # (at your option) any later version.
   13: #
   14: # LON-CAPA is distributed in the hope that it will be useful,
   15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17: # GNU General Public License for more details.
   18: #
   19: # You should have received a copy of the GNU General Public License
   20: # along with LON-CAPA; if not, write to the Free Software
   21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22: #
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: 
   28: package Apache::imsimportdocs;
   29: 
   30: use Apache::Constants qw(:common :http :methods);
   31: use Apache::lonnet;
   32: use Apache::londocs;
   33: use Apache::loncommon;
   34: use Apache::lonlocal;
   35: use Apache::imsprocessor;
   36: use LONCAPA::Configuration;
   37: use LONCAPA::map();
   38: use lib '/home/httpd/lib/perl/';
   39: use LONCAPA;
   40:  
   41: use strict;
   42: 
   43: sub jscript_one {
   44:     my $javascript = shift;
   45:     $$javascript = qq#
   46: function verify() {
   47:  if ((document.forms.pickcms.uploadname.value == '')  || (!document.forms.pickcms.uploadname.value)) {
   48:    alert("You must provide the name of the IMS package to be imported")
   49:    return false
   50:  }
   51:  if (document.forms.pickcms.source.selectedIndex == 0) {
   52:    alert("You must choose the Course Management System from which the IMS package was exported");
   53:    return false
   54:  }
   55:  return true
   56: }
   57: 
   58: function nextPage() {
   59:  if (verify()) {
   60:    document.forms.pickcms.submit()
   61:  }
   62: }
   63: #;
   64:  
   65: }
   66: 
   67: sub jscript_two {
   68:     my $javascript = shift;
   69:     $$javascript = qq#
   70: function setOptions(caller,itemnum) {
   71:   var opForm = document.forms.pickoptions
   72:   var menu = 1 + itemnum*2
   73:   opForm.elements[menu].length = 0
   74:   if (opForm.elements[itemnum*2].checked == true) {
   75:     if (caller == "board") {
   76:       opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
   77:       opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
   78:       opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true)
   79:       opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true)
   80:     }
   81:     else { 
   82:       if (caller == "users") {
   83:         opForm.elements[menu].length = 0
   84:         opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
   85:         opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true)
   86:         opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true)
   87:       }
   88:     }
   89:   }
   90:   else {
   91:     opForm.elements[menu].options[0] = new Option("Not required","0",true,true)
   92:   }
   93:   opForm.elements[menu].selectedIndex = 0
   94: }
   95: 
   96: function verify(caller) { 
   97:   var opForm = document.forms.pickoptions
   98:   var totcheck = 0;
   99:   for (var i=0; i<caller; i++) {
  100:     if (opForm.elements[2*i].checked == true) {
  101:       totcheck ++
  102:       if (opForm.elements[2*i].name == "board") { 
  103:         if (opForm.elements[2*i+1].selectedIndex == 0) {     
  104:           alert("You must select one of the additional options when importing Discussion Boards ")
  105:           return false
  106:         }
  107:       }
  108:       if (opForm.elements[2*i].name == "users") {
  109:         if (opForm.elements[2*i+1].selectedIndex == 0) {     
  110:           alert("You must select one of the additional options when importing Enrollment")
  111:           return false
  112:         }
  113:       }
  114:     }
  115:   }
  116:   if (totcheck == 0) {
  117:     alert("You must check the Checkbox for at least one Content Type");
  118:     return false
  119:   }
  120:   return true
  121: }
  122: 
  123: function nextPage(caller) {
  124:  if (verify(caller)) {
  125:    document.forms.pickoptions.submit()
  126:  }
  127: }
  128: #;
  129: }
  130: 
  131: sub jscript_three {
  132:     my $javascript = shift;
  133:     $$javascript = qq|
  134: function init(tf) {
  135:     setTimeout("self.close()",3000)
  136:     tf.submit();   
  137: }
  138:     |;
  139: }
  140: 
  141: sub handler {
  142:     my $r = shift;
  143:     my $javascript = '';
  144:     &Apache::loncommon::content_type($r,'text/html');
  145:     $r->send_http_header;
  146:     return OK if $r->header_only;
  147: 
  148:     my @areas = ();
  149:     my %cmsmap = ();
  150:     my %areaname = ();
  151:     &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname);
  152: 
  153: # get course data
  154:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  155:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  156: 
  157: # get personal data
  158:  
  159:     my $uname=$env{'user.name'};
  160:     my $udom=$env{'user.domain'};
  161:     my $plainname=&escape(
  162:                      &Apache::loncommon::plainname($uname,$udom));
  163: 
  164: # does this user have privileges to post, etc?
  165:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  166:     unless ($allowed) {
  167:         $r->print(&Apache::loncommon::start_page('Import IMS package',undef,
  168:                                                  {'only_body' => 1,}));  
  169:         $r->print(
  170:             '<p class="LC_error">'
  171:            .&mt('Modification of Course Contents Disallowed')
  172:            .'</p><p>'
  173:            .&mt('Your current role does not grant you the right to modify course content in this course.')
  174:            .'</p>'
  175:            .&Apache::loncommon::end_page()
  176:         );
  177:         return OK;
  178:     }
  179: 
  180:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  181:        ['phase']);
  182: 
  183:     if ($env{'form.phase'} eq 'one') {    
  184:         &jscript_one(\$javascript);
  185:     } elsif ($env{'form.phase'} eq 'two') {
  186:         &jscript_two(\$javascript);
  187:     } elsif ($env{'form.phase'} eq 'three') {
  188:         &jscript_three(\$javascript);
  189:     }
  190: 
  191:     $javascript = 
  192:         "<script type=\"text/javascript\">\n".
  193:         "//<!--\n$javascript\n// --></script>\n";
  194:     my $headline = 'Import IMS package';
  195:     my $start_page = &Apache::loncommon::start_page($headline,
  196:                                                     $javascript,
  197:                                                     {'only_body' => 1,})
  198:                     .'<h1>'.&mt($headline).'</h1>';
  199: # print screen
  200:     $r->print($start_page);
  201: 
  202:     if ($env{'form.phase'} eq 'one') {
  203:         &display_one($r);       
  204:     } elsif ($env{'form.phase'} eq 'two') {
  205:         &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap);
  206:     } elsif ($env{'form.phase'} eq 'three') {
  207:         &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
  208:     }   
  209:     $r->print(&Apache::loncommon::end_page());
  210:     return OK;
  211: } 
  212: 
  213: 
  214: sub display_one {
  215:     my ($r) = @_;
  216:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
  217: 
  218:     $r->print(
  219:         '<form action="/adm/imsimportdocs" method="post"'
  220:        .' enctype="multipart/form-data" name="pickcms">'
  221:     );
  222: 
  223:     # Step 1
  224:     $r->print(
  225:        &Apache::lonhtmlcommon::topic_bar(
  226:             1,&mt('Specify the Course Management system used to create the package'))
  227:        .&mt('Please choose the CMS used to create your IMS content package:').' '
  228:        .'<select name="source">'
  229:        .'<option value="-1" selected="selected">'.&mt('Please select').'</option>'
  230:        .'<option value="bb5">Blackboard 5</option>'
  231:        .'<option value="bb6">Blackboard 6</option>'
  232:        .'<option value="angel5">ANGEL 5.5</option>'
  233:        .'<option value="webctce4">WebCT 4 Campus Edition</option>'
  234:        .'</select>'
  235:     );
  236: 
  237:     # Step 2
  238:     $r->print(
  239:        &Apache::lonhtmlcommon::topic_bar(
  240:            2,&mt('Locate the IMS content package you wish to upload'))
  241:       .'<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
  242:       .'<input type="hidden" name="phase" value="two" />'
  243:       .&mt('File:')
  244:       .' <input type="file" name="uploadname" size="40" />'
  245:     );
  246: 
  247:     # Buttons
  248:     $r->print(
  249:        '<hr />'
  250:       .'<p>'
  251:       .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
  252:       .' onclick="javascript:self.close()" />'
  253:       .' '
  254:       .'<input type="button" name="nextpage" value="'.&mt('Upload IMS package').'"'
  255:       .' onclick="javascript:nextPage()" />'
  256:       .'</p>'
  257:     );
  258: 
  259:     $r->print('</form>');
  260: }
  261: 
  262: 
  263: sub display_two {
  264:     my ($r,$crs,$areasref,$areaname,%cmsmap) = @_;
  265:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
  266:     my $cms = $env{'form.source'};
  267:     my $timenow = time;
  268:     my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
  269:     my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir);
  270:     my $unzip_result = '';
  271:     my $manifest_result = '';
  272:     unless ($tempdir eq '') {
  273:         $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
  274:     }
  275:     my %resources = ();
  276:     my %includedres = ();
  277:     my %includeditems = ();
  278:     my %items = ();
  279:     my %hrefs = ();
  280:     my %resinfo = ();
  281:     my %count = ();
  282:     my $counter = 0;
  283:     my %count = (
  284:                 announce => 0,
  285:                 board => 0,
  286:                 doc => 0,
  287:                 extlink => 0,
  288:                 msg => 0,
  289:                 pool => 0,
  290:                 quiz => 0,
  291:                 staff => 0,
  292:                 survey => 0,
  293:                 users => 0,
  294:                 );
  295: 
  296:     if ($unzip_result ne 'ok') {
  297:         $r->print(
  298:             '<p class="LC_warning">'
  299:            .&mt('Processing of your IMS package failed because the file you'
  300:                .' uploaded could not be unzipped.')
  301:            .'</p>'
  302:         );
  303:         return();
  304:     }
  305: 
  306:     # Get manifest file from package
  307:     $manifest_result = &Apache::imsprocessor::process_manifest(
  308:                            $cms,$tempdir,\%resources,\%items,\%hrefs,
  309:                            \%resinfo,'choose',\%includedres,\%includeditems);
  310:     if ($manifest_result ne 'ok') {
  311:         $r->print(
  312:            '<p class="LC_warning">'
  313:           .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.')
  314:           .'</p>'
  315:         );
  316:         return();
  317:     }
  318: 
  319:     # Count areas depending on cms version
  320:     foreach my $res (sort keys %resources) {
  321:         if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') {
  322:             foreach my $area (keys %{$cmsmap{$cms}}) {
  323:                 if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
  324:                     $count{$area} ++;
  325:                 }
  326:             }
  327:         } elsif ($cms eq 'angel5') {
  328:             foreach my $area (keys %{$cmsmap{$cms}}) {
  329:                 if ($area eq 'doc') {
  330:                     if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
  331:                         $count{$area} ++;
  332:                     }
  333:                 } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
  334:                     $count{$area} ++;
  335:                 }
  336:             }
  337:         } else { # Unknown cms format
  338:             $r->print(
  339:                 '<span class="LC_warning">'
  340:                .&mt('Unsupported IMS format: [_1]',$cms)
  341:                .'</span><br />'
  342:             );
  343:             # return();
  344:         }
  345:     }
  346: 
  347: 
  348:     # Start output: Step 3 and step 4
  349: 
  350:     $r->print(
  351:         '<form name="pickoptions" method="post" action="">'
  352:        .&Apache::lonhtmlcommon::topic_bar(
  353:             3,&mt('Choose which content types you wish to import'))
  354:        .'<p>'
  355:        .&mt('Check the checkboxes for all areas you wish to import from the IMS package:')
  356:        .'</p>'
  357:     );
  358: 
  359:     $r->print(
  360:         &Apache::loncommon::start_data_table()
  361:        .&Apache::loncommon::start_data_table_header_row()
  362:        .'<th>'.&mt('Import?').'</th>'
  363:        .'<th>'.&mt('Content type').'</th>'
  364:        .'<th>'.&mt('Additional options').'</th>'
  365:        .&Apache::loncommon::end_data_table_header_row()
  366:     );
  367: 
  368:     # Display import row for each area/content type
  369:     foreach my $area (@{$areasref}) {
  370:         unless ($count{$area} > 0) { next };
  371: 
  372:         my $count_tag = 'flag_'.$counter;
  373: 
  374:         # Checkbox: Import?
  375:         $r->print(
  376:             &Apache::loncommon::start_data_table_row()
  377:            .'<td><input name="'.$area.'" type="checkbox"'
  378:         );
  379:         if ($area eq 'board' || $area eq 'users') {
  380:             $r->print(qq| onclick='javascript:setOptions("$area","$counter")'|);
  381:         }
  382: 
  383:         $r->print(' /></td>');
  384: 
  385:         # Content Type
  386:         $r->print(
  387:             '<td>'
  388:            .$$areaname{$area}.'&nbsp;&nbsp; - '
  389:            .&mt('[quant,_1,item]',$count{$area})
  390:            .'</td>'
  391:         );
  392: 
  393:         # Additional Options
  394:         $r->print('<td>');
  395:         if ($area eq 'board') {
  396:             $r->print(
  397:                 '<select name="db_handling">'
  398:                .'<option value="-2">&lt;-- '.&mt('Check Import first').'</option>'
  399:                .'</select>'
  400:             );
  401:         } elsif ($area eq 'users') {
  402:             $r->print(
  403:                 '<select name="user_handling">'
  404:                .'<option value="-2">&lt;-- '.&mt('Check Import first').'</option>'
  405:                .'</select>'
  406:             );
  407:         } else {
  408:             $r->print(
  409:                 &mt('None')
  410:                .'<input type="hidden" name="'.$count_tag.'" />'
  411:             );
  412:         }
  413:         $r->print('</td>');
  414: 
  415:         $r->print(&Apache::loncommon::end_data_table_row());
  416:         $counter ++;
  417:     }
  418: 
  419:     $r->print(&Apache::loncommon::end_data_table());
  420: 
  421:     $r->print(
  422:         &Apache::lonhtmlcommon::topic_bar(
  423:             4,&mt('Choose display options for listing of contents of top level of package'))
  424:        .'<p>'
  425:        .&mt('Select a display option for the package content:')
  426:        .'</p>'
  427:     );
  428:     $r->print(
  429:         '<label>'
  430:        .'<input type="radio" name="toplevel" value="newfolder" />'
  431:        .&mt('Display listing of contents in a new folder, with folder name:')
  432:        .'</label>'
  433:        .' <input type="text" name="foldername" size="15" value="'.&mt('Type Name Here').'" />'
  434:        .'<br />'
  435:        .'<label>'
  436:        .'<input type="radio" name="toplevel" value="oldfolder" checked="checked" />'
  437:        .&mt('Append listing of contents of top level of package to contents list for the current folder.')
  438:        .'</label>'
  439:     );
  440: 
  441:     # Buttons
  442:     $r->print(
  443:         '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
  444:        .'<input type="hidden" name="source" value="'.$cms.'" />'
  445:        .'<input type="hidden" name="tempdir" value="'.$tempdir.'" />'
  446:        .'<input type="hidden" name="phase" value="three" />'
  447:     );
  448:     $r->print(
  449:         '<hr />'
  450:        .'<p>'
  451:        .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
  452:        .' onclick="javascript:self.close()" />'
  453:        .' '
  454:        .'<input type="button" name="nextpage" value="'.&mt('Finish Import').'"'
  455:        .' onclick="javascript:nextPage('.$counter.')" />'
  456:        .'</p>'
  457:     );
  458: 
  459:    $r->print('</form>');
  460: }
  461: 
  462: 
  463: sub display_three {
  464:     my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_;
  465:     my $folder = $env{'form.folder'};
  466:     my $cms = $env{'form.source'};
  467:     my $tempdir = $env{'form.tempdir'};
  468:     my $longcrs = '';
  469:     if ($crs =~ m/^(\d)(\d)(\d)/) {
  470:         $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
  471:     }
  472:     my %importareas = ();
  473:     my %includedres = ();
  474:     my %includeditems = ();
  475:     my @targets = ();
  476:     my %resources = ();
  477:     my %items = ();
  478:     my %hrefs = ();
  479:     my %urls = ();
  480:     my %resinfo = ();
  481:     my %total = (
  482:                  page => 0,
  483:                  prob => 0,
  484:                  seq => 0,
  485:                  board => 0,         
  486:                  quiz => 0,
  487:                  surv => 0,
  488:                 );
  489:     my @pages = ();
  490:     my @sequences = ();
  491:     my @resrcfiles = ();
  492: 
  493:     my $timenow = time;
  494: 
  495:     my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow;
  496:     my $seqstem = "/uploaded/$cdom/$crs/$timenow";
  497:     my $db_handling = '';
  498:     my $user_handling = '';
  499: 
  500:     my $toplevel = '';
  501:     my $foldername = '';
  502:     my %topitems = ();
  503:     if (defined($env{'form.toplevel'}) ) {
  504:         $toplevel = $env{'form.toplevel'};     
  505:     }
  506:     if (defined($env{'form.foldername'}) ) {
  507:         $foldername = $env{'form.foldername'}; 
  508:     }
  509: 
  510:     foreach my $area (@{$areas}) {
  511:         if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) {
  512:             if ($cms eq 'angel5' && $area eq 'doc') {
  513:                 foreach (@{$cmsmap{$cms}{$area}}) {
  514:                     $importareas{$_} = 1;
  515:                 }
  516:             } else {
  517:                 $importareas{$cmsmap{$cms}{$area}} = 1;
  518:             }
  519:             if ($area eq 'board') {
  520:                 $db_handling = $env{'form.db_handling'};
  521:             } elsif ($area eq 'users') {
  522:                 $user_handling = $env{'form.user_handling'};
  523:             }
  524:         }
  525:     }
  526: 
  527:     my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems);
  528:     if ($manifest_result eq 'ok') {
  529:         foreach my $res (sort keys %resources) {
  530:             if ($importareas{$resources{$res}{type}}) {
  531:                 $includedres{$res} = 1;
  532:             }
  533:         }
  534:         foreach my $itm (sort keys %items) {
  535:             &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
  536:         }
  537:     }
  538:     foreach my $itm (sort keys %includeditems) {
  539:         &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
  540:     }
  541: 
  542:     $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
  543:     if ($manifest_result eq 'ok') {
  544: 
  545:         my @path = ($cdom,$crs,$timenow);
  546:         my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
  547:         foreach my $item (@path) {
  548:             $fullpath .= '/'.$item;
  549:             if (!-e "$fullpath") {
  550:                 mkdir("$fullpath",0770);
  551:             }
  552:         }
  553:         my @namedirs = ("resfiles","sequences","pages","problems");
  554:         foreach my $name (@namedirs) {
  555:             if (!-e "$fullpath/$name") {
  556:                 mkdir("$fullpath/$name",0770);
  557:             }
  558:         }
  559:         &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
  560: 
  561:         my @boards = ();
  562:         my @announcements = ();
  563:         my @quizzes = ();
  564:         my @surveys = ();
  565:         my @pools = ();
  566:         my @groups = ();
  567:         my %messages = ();
  568:         my @timestamp = ();
  569:         my %boardnum = ();
  570:         my @topurls = ();
  571:         my @topnames = ();
  572:         my @packages = ();
  573: 
  574:         &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);
  575: 
  576:         my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
  577: 
  578:         &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);
  579: 
  580:         foreach my $item (@pages) {
  581:             my $filename = $timenow.'/pages/'.$item;
  582:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  583:         }
  584:         foreach my $item (@sequences) {
  585:             unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
  586:                 my $filename = $timenow.'/sequences/'.$item;
  587:                 my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  588:             }
  589:         }
  590:         foreach my $item (@resrcfiles) {
  591:             my $filename = $timenow.'/resfiles/'.$item;
  592:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  593:         }
  594: 
  595:         my @imports = ();
  596:         if ($toplevel eq 'oldfolder') {
  597:             for (my $i=0; $i<@topurls; $i++) {
  598:                 my $url = &unescape($topurls[$i]);
  599:                 my $name = &unescape($topnames[$i]);
  600:                 push(@imports, [$name, $url]);
  601:             }
  602:         } elsif ($toplevel eq 'newfolder') {
  603:             my $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
  604:             my $name = &unescape("$env{'form.foldername'}");
  605:             push(@imports, [$name, $url]);
  606:         }
  607:         my $errtext='';
  608:         my $fatal=0;
  609:         ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
  610:         if ($#LONCAPA::map::order<1) {
  611:             $LONCAPA::map::order[0]=1;
  612:             $LONCAPA::map::resources[1]='';
  613:         }
  614:         my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
  615:         if ($fatal) {
  616:             &Apache::lonnet::logthis("Fatal error during group_import.");
  617:         }
  618:     }
  619:     if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
  620:         system("rm -r -f $tempdir");
  621:     }
  622: 
  623:     # All done, display success message
  624:     $r->print(
  625:         '<p class="LC_success">'
  626:        .&mt('Your import is complete.')
  627:        .'</p>'
  628:     );
  629:     # Re-initialize Button
  630:     my $initbutton =
  631:            '<input type="button" value="'
  632:           .&mt('re-initializing course')
  633:           .'" onclick="javascript:init(this.form)" />';
  634:     $r->print(
  635:         '<form method="post" action="/adm/roles" target="loncapaclient" name="importDone">'
  636:        .'<input type="hidden" name="orgurl" value="/adm/coursedocs" />'
  637:        .'<input type="hidden" name="selectrole" value="1" />'
  638:        .'<input type="hidden" name="'.$env{'request.role'}.'" value="1" />'
  639:        .'<p class="LC_warning">'
  640:        .&mt('Changes will become active for your current session after [_1]'
  641:            .', or the next time you log in.'
  642:             ,$initbutton)
  643:        .'</p>'
  644:        .'</form>'
  645:     );
  646: }
  647: 
  648: 1;
  649: __END__

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