Annotation of loncom/imspackages/imsimportdocs.pm, revision 1.37

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

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