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

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

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