File:  [LON-CAPA] / loncom / imspackages / imsimportdocs.pm
Revision 1.26: download - view: text, annotated - select for diffs
Fri Nov 20 14:39:32 2009 UTC (14 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Layout, localization and code style for import phase 2 (display_two, step 3 and 4):
- Replaced hardcoded styles by standard styles (topic_bar, data_table)
- Removed unnecessary HTML tables
- Got rid of deprecated tags and outdated/unecessary styles
- Code style: Directly go on with next item in area loop when no content exists for current area
- XHTML: attributes in lower case
- Close <form>, close all data_table rows
- Split message text about what to do at the bottom in two texts and display the approriate part in each step where needed
- Localization: Added missing &mt() calls, use quant for item counter
- Consistent wording: "Finish Import"
- Added some code comments

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: imsimportdocs.pm,v 1.26 2009/11/20 14:39:32 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:        .&Apache::lonhtmlcommon::topic_bar(
  222:             1,&mt('Specify the Course Management system used to create the package'))
  223:        .&mt('Please choose the CMS used to create your IMS content package:').' '
  224:        .'<select name="source">'
  225:        .'<option value="-1" selected="selected">'.&mt('Please select').'</option>'
  226:        .'<option value="bb5">Blackboard 5</option>'
  227:        .'<option value="bb6">Blackboard 6</option>'
  228:        .'<option value="angel5">ANGEL 5.5</option>'
  229:        .'<option value="webctce4">WebCT 4 Campus Edition</option>'
  230:        .'</select>'
  231:     );
  232:     $r->print(
  233:        &Apache::lonhtmlcommon::topic_bar(
  234:            2,&mt('Locate the IMS content package you wish to upload'))
  235:       .'<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
  236:       .'<input type="hidden" name="phase" value="two" />'
  237:       .&mt('File:')
  238:       .' <input type="file" name="uploadname" size="40" />'
  239:     );
  240:     $r->print(
  241:        '<hr />'
  242:       .'<p>'
  243:       .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
  244:       .' onclick="javascript:self.close()" />'
  245:       .' '
  246:       .'<input type="button" name="nextpage" value="'.&mt('Upload IMS package').'"'
  247:       .' onclick="javascript:nextPage()" />'
  248:       .'</p>'
  249:     );
  250: }
  251: 
  252: 
  253: sub display_two {
  254:     my ($r,$crs,$areasref,$areaname,%cmsmap) = @_;
  255:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
  256:     my $cms = $env{'form.source'};
  257:     my $timenow = time;
  258:     my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
  259:     my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir);
  260:     my $unzip_result = '';
  261:     my $manifest_result = '';
  262:     unless ($tempdir eq '') {
  263:         $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
  264:     }
  265:     my %resources = ();
  266:     my %includedres = ();
  267:     my %includeditems = ();
  268:     my %items = ();
  269:     my %hrefs = ();
  270:     my %resinfo = ();
  271:     my %count = ();
  272:     my $counter = 0;
  273:     my %count = (
  274:                 announce => 0,
  275:                 board => 0,
  276:                 doc => 0,
  277:                 extlink => 0,
  278:                 msg => 0,
  279:                 pool => 0,
  280:                 quiz => 0,
  281:                 staff => 0,
  282:                 survey => 0,
  283:                 users => 0,
  284:                 );
  285: 
  286:     if ($unzip_result ne 'ok') {
  287:         $r->print(
  288:             '<p class="LC_warning">'
  289:            .&mt('Processing of your IMS package failed because the file you'
  290:                .' uploaded could not be unzipped.')
  291:            .'</p>'
  292:         );
  293:         return();
  294:     }
  295: 
  296:     # Get manifest file from package
  297:     $manifest_result = &Apache::imsprocessor::process_manifest(
  298:                            $cms,$tempdir,\%resources,\%items,\%hrefs,
  299:                            \%resinfo,'choose',\%includedres,\%includeditems);
  300:     if ($manifest_result ne 'ok') {
  301:         $r->print(
  302:            '<p class="LC_warning">'
  303:           .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.')
  304:           .'</p>'
  305:         );
  306:         return();
  307:     }
  308: 
  309:     # Count areas depending on cms version
  310:     foreach my $res (sort keys %resources) {
  311:         if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') {
  312:             foreach my $area (keys %{$cmsmap{$cms}}) {
  313:                 if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
  314:                     $count{$area} ++;
  315:                 }
  316:             }
  317:         } elsif ($cms eq 'angel5') {
  318:             foreach my $area (keys %{$cmsmap{$cms}}) {
  319:                 if ($area eq 'doc') {
  320:                     if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
  321:                         $count{$area} ++;
  322:                     }
  323:                 } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
  324:                     $count{$area} ++;
  325:                 }
  326:             }
  327:         } else { # Unknown cms format
  328:             $r->print(
  329:                 '<span class="LC_warning">'
  330:                .&mt('Unsupported IMS format: [_1]',$cms)
  331:                .'</span><br />'
  332:             );
  333:             # return();
  334:         }
  335:     }
  336: 
  337: 
  338:     # Start output: Step 3 and step 4
  339: 
  340:     $r->print(
  341:         '<form name="pickoptions" method="post">'
  342:        .&Apache::lonhtmlcommon::topic_bar(
  343:             3,&mt('Choose which content types you wish to import'))
  344:        .'<p>'
  345:        .&mt('Check the checkboxes for all areas you wish to import from the IMS package:')
  346:        .'</p>'
  347:     );
  348: 
  349:     $r->print(
  350:         &Apache::loncommon::start_data_table()
  351:        .&Apache::loncommon::start_data_table_header_row()
  352:        .'<th>'.&mt('Import?').'</th>'
  353:        .'<th>'.&mt('Content type').'</th>'
  354:        .'<th>'.&mt('Additional options').'</th>'
  355:        .&Apache::loncommon::end_data_table_header_row()
  356:     );
  357: 
  358:     # Display import row for each area/content type
  359:     foreach my $area (@{$areasref}) {
  360:         unless ($count{$area} > 0) { next };
  361: 
  362:         my $count_tag = 'flag_'.$counter;
  363: 
  364:         # Checkbox: Import?
  365:         $r->print(
  366:             &Apache::loncommon::start_data_table_row()
  367:            .'<td><input name="'.$area.'" type="checkbox"'
  368:         );
  369:         if ($area eq 'board' || $area eq 'users') {
  370:             $r->print(qq| onclick='javascript:setOptions("$area","$counter")'|);
  371:         }
  372: 
  373:         $r->print(' /></td>');
  374: 
  375:         # Content Type
  376:         $r->print(
  377:             '<td>'
  378:            .$$areaname{$area}.'&nbsp;&nbsp; - '
  379:            .&mt('[quant,_1,item]',$count{$area})
  380:            .'</td>'
  381:         );
  382: 
  383:         # Additional Options
  384:         $r->print('<td>');
  385:         if ($area eq 'board') {
  386:             $r->print(
  387:                 '<select name="db_handling">'
  388:                .'<option value="-2">&lt;-- '.&mt('Check Import first').'</option>'
  389:                .'</select>'
  390:             );
  391:         } elsif ($area eq 'users') {
  392:             $r->print(
  393:                 '<select name="user_handling">'
  394:                .'<option value="-2">&lt;-- '.&mt('Check Import first').'</option>'
  395:                .'</select>'
  396:             );
  397:         } else {
  398:             $r->print(
  399:                 &mt('None')
  400:                .'<input type="hidden" name="'.$count_tag.'" />'
  401:             );
  402:         }
  403:         $r->print('</td>');
  404: 
  405:         $r->print(&Apache::loncommon::end_data_table_row());
  406:         $counter ++;
  407:     }
  408: 
  409:     $r->print(&Apache::loncommon::end_data_table());
  410: 
  411:     $r->print(
  412:         &Apache::lonhtmlcommon::topic_bar(
  413:             4,&mt('Choose display options for listing of contents of top level of package'))
  414:        .'<p>'
  415:        .&mt('Select a display option for the package content:')
  416:        .'</p>'
  417:     );
  418:     $r->print(
  419:         '<label>'
  420:        .'<input type="radio" name="toplevel" value="newfolder" />'
  421:        .&mt('Display listing of contents in a new folder, with folder name:')
  422:        .'</label>'
  423:        .' <input type="text" name="foldername" size="15" value="'.&mt('Type Name Here').'" />'
  424:        .'<br />'
  425:        .'<label>'
  426:        .'<input type="radio" name="toplevel" value="oldfolder" />'
  427:        .&mt('Append listing of contents of top level of package to contents list for the current folder.')
  428:        .'</label>'
  429:     );
  430: 
  431:     # Buttons
  432:     $r->print(
  433:         '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
  434:        .'<input type="hidden" name="source" value="'.$cms.'" />'
  435:        .'<input type="hidden" name="tempdir" value="'.$tempdir.'" />'
  436:        .'<input type="hidden" name="phase" value="three" />'
  437:     );
  438:     $r->print(
  439:         '<hr />'
  440:        .'<p>'
  441:        .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
  442:        .' onclick="javascript:self.close()" />'
  443:        .' '
  444:        .'<input type="button" name="nextpage" value="'.&mt('Finish Import').'"'
  445:        .' onclick="javascript:nextPage('.$counter.')" />'
  446:        .'</p>'
  447:     );
  448: 
  449:    $r->print('</form>');
  450: }
  451: 
  452: 
  453: sub display_three {
  454:     my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_;
  455:     my $folder = $env{'form.folder'};
  456:     my $cms = $env{'form.source'};
  457:     my $tempdir = $env{'form.tempdir'};
  458:     my $longcrs = '';
  459:     if ($crs =~ m/^(\d)(\d)(\d)/) {
  460:         $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
  461:     }
  462:     my %importareas = ();
  463:     my %includedres = ();
  464:     my %includeditems = ();
  465:     my @targets = ();
  466:     my %resources = ();
  467:     my %items = ();
  468:     my %hrefs = ();
  469:     my %urls = ();
  470:     my %resinfo = ();
  471:     my %total = (
  472:                  page => 0,
  473:                  prob => 0,
  474:                  seq => 0,
  475:                  board => 0,         
  476:                  quiz => 0,
  477:                  surv => 0,
  478:                 );
  479:     my @pages = ();
  480:     my @sequences = ();
  481:     my @resrcfiles = ();
  482: 
  483:     my $timenow = time;
  484: 
  485:     my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow;
  486:     my $seqstem = "/uploaded/$cdom/$crs/$timenow";
  487:     my $db_handling = '';
  488:     my $user_handling = '';
  489: 
  490:     my $toplevel = '';
  491:     my $foldername = '';
  492:     my %topitems = ();
  493:     if (defined($env{'form.toplevel'}) ) {
  494:         $toplevel = $env{'form.toplevel'};     
  495:     }
  496:     if (defined($env{'form.foldername'}) ) {
  497:         $foldername = $env{'form.foldername'}; 
  498:     }
  499: 
  500:     foreach my $area (@{$areas}) {
  501:         if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) {
  502:             if ($cms eq 'angel5' && $area eq 'doc') {
  503:                 foreach (@{$cmsmap{$cms}{$area}}) {
  504:                     $importareas{$_} = 1;
  505:                 }
  506:             } else {
  507:                 $importareas{$cmsmap{$cms}{$area}} = 1;
  508:             }
  509:             if ($area eq 'board') {
  510:                 $db_handling = $env{'form.db_handling'};
  511:             } elsif ($area eq 'users') {
  512:                 $user_handling = $env{'form.user_handling'};
  513:             }
  514:         }
  515:     }
  516: 
  517:     my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems);
  518:     if ($manifest_result eq 'ok') {
  519:         foreach my $res (sort keys %resources) {
  520:             if ($importareas{$resources{$res}{type}}) {
  521:                 $includedres{$res} = 1;
  522:             }
  523:         }
  524:         foreach my $itm (sort keys %items) {
  525:             &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
  526:         }
  527:     }
  528:     foreach my $itm (sort keys %includeditems) {
  529:         &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
  530:     }
  531: 
  532:     $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
  533:     if ($manifest_result eq 'ok') {
  534: 
  535:         my @path = ($cdom,$crs,$timenow);
  536:         my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
  537:         foreach my $item (@path) {
  538:             $fullpath .= '/'.$item;
  539:             if (!-e "$fullpath") {
  540:                 mkdir("$fullpath",0770);
  541:             }
  542:         }
  543:         my @namedirs = ("resfiles","sequences","pages","problems");
  544:         foreach my $name (@namedirs) {
  545:             if (!-e "$fullpath/$name") {
  546:                 mkdir("$fullpath/$name",0770);
  547:             }
  548:         }
  549:         &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
  550: 
  551:         my @boards = ();
  552:         my @announcements = ();
  553:         my @quizzes = ();
  554:         my @surveys = ();
  555:         my @pools = ();
  556:         my @groups = ();
  557:         my %messages = ();
  558:         my @timestamp = ();
  559:         my %boardnum = ();
  560:         my @topurls = ();
  561:         my @topnames = ();
  562:         my @packages = ();
  563: 
  564:         &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);
  565: 
  566:         my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
  567: 
  568:         &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);
  569: 
  570:         foreach my $item (@pages) {
  571:             my $filename = $timenow.'/pages/'.$item;
  572:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  573:         }
  574:         foreach my $item (@sequences) {
  575:             unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
  576:                 my $filename = $timenow.'/sequences/'.$item;
  577:                 my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  578:             }
  579:         }
  580:         foreach my $item (@resrcfiles) {
  581:             my $filename = $timenow.'/resfiles/'.$item;
  582:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  583:         }
  584: 
  585:         my @imports = ();
  586:         if ($toplevel eq 'oldfolder') {
  587:             for (my $i=0; $i<@topurls; $i++) {
  588:                 my $url = &unescape($topurls[$i]);
  589:                 my $name = &unescape($topnames[$i]);
  590:                 push(@imports, [$name, $url]);
  591:             }
  592:         } elsif ($toplevel eq 'newfolder') {
  593:             my $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
  594:             my $name = &unescape("$env{'form.foldername'}");
  595:             push(@imports, [$name, $url]);
  596:         }
  597:         my $errtext='';
  598:         my $fatal=0;
  599:         ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
  600:         if ($#LONCAPA::map::order<1) {
  601:             $LONCAPA::map::order[0]=1;
  602:             $LONCAPA::map::resources[1]='';
  603:         }
  604:         my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
  605:         if ($fatal) {
  606:             &Apache::lonnet::logthis("Fatal error during group_import.");
  607:         }
  608:     }
  609:     if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
  610:         system("rm -r -f $tempdir");
  611:     }
  612:     $r->print(<<ENDBLOCK);
  613:   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
  614:    <tr>
  615:     <td colspan='2'>
  616:      <table border='0' cellspacing='0' cellpadding='0'>
  617:       <tr>
  618:        <td colspan='2'  align='left'>&nbsp;
  619:        </td>
  620:       </tr>
  621:       <tr bgcolor='#CCCCFF'>
  622:        <td valign="middle"><img src="/res/adm/pages/bl_step5.gif" alt="5" />
  623:        </td>
  624:        <td width='100%' align='left'>&nbsp;&nbsp;
  625:         <font face='arial,helvetica,sans-serif'><b>Your import is complete</b></font>
  626:        </td>
  627:       </tr>
  628:       <tr>
  629:        <td colspan='2'>&nbsp;</td>
  630:       </tr>
  631:       <tr>
  632:        <td>&nbsp;</td>
  633:        <td>
  634: ENDBLOCK
  635:     my $initblock = qq|  
  636:          <form method="post" action="/adm/roles" target="loncapaclient" name="importDone">
  637:            <input type="hidden" name="orgurl" value="/adm/coursedocs" />
  638:            <input type="hidden" name="selectrole" value="1" />
  639:            <h3><font color="red">Changes will become active for your current session after
  640:            <input type="hidden" name="$env{'request.role'}" value="1" />
  641:            <input type="button" value="|;
  642:     $initblock .= &mt('re-initializing course');
  643:     $initblock .= qq|" onClick="javascript:init(this.form)" />|;
  644:     $initblock .= ', '.&mt('or the next time you log in.');
  645:     $initblock .= qq|</font></h3></form>|;  
  646:     $r->print($initblock);
  647:     $r->print(<<ENDBLOCKTWO);
  648:      </table>
  649:     </td>
  650:    </tr>
  651:   </table>
  652: ENDBLOCKTWO
  653: }
  654: 
  655: 1;
  656: __END__

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