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

1.18      www         1: # The LearningOnline Network with CAPA
                      2: #
1.35    ! raeburn     3: # $Id: imsimportdocs.pm,v 1.34 2014/12/11 00:35:53 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.9       raeburn   399:     my %importareas = ();
                    400:     my %includedres = ();
                    401:     my %includeditems = ();
1.2       raeburn   402:     my @targets = ();
                    403:     my %resources = ();
                    404:     my %items = ();
                    405:     my %hrefs = ();
                    406:     my %urls = ();
                    407:     my %resinfo = ();
                    408:     my %total = (
                    409:                  page => 0,
                    410:                  prob => 0,
                    411:                  seq => 0,
                    412:                  board => 0,         
                    413:                  quiz => 0,
                    414:                  surv => 0,
                    415:                 );
                    416:     my @pages = ();
                    417:     my @sequences = ();
                    418:     my @resrcfiles = ();
                    419: 
                    420:     my $timenow = time;
                    421: 
                    422:     my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow;
                    423:     my $seqstem = "/uploaded/$cdom/$crs/$timenow";
                    424:     my $db_handling = '';
                    425:     my $user_handling = '';
                    426: 
                    427:     my $toplevel = '';
                    428:     my $foldername = '';
                    429:     my %topitems = ();
1.12      albertel  430:     if (defined($env{'form.toplevel'}) ) {
                    431:         $toplevel = $env{'form.toplevel'};     
1.2       raeburn   432:     }
1.12      albertel  433:     if (defined($env{'form.foldername'}) ) {
                    434:         $foldername = $env{'form.foldername'}; 
1.2       raeburn   435:     }
1.8       raeburn   436: 
1.2       raeburn   437:     foreach my $area (@{$areas}) {
1.12      albertel  438:         if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) {
1.23      raeburn   439:             if ($cms eq 'angel5' && $area eq 'doc') {
1.2       raeburn   440:                 foreach (@{$cmsmap{$cms}{$area}}) {
1.9       raeburn   441:                     $importareas{$_} = 1;
1.2       raeburn   442:                 }
                    443:             } else {
1.9       raeburn   444:                 $importareas{$cmsmap{$cms}{$area}} = 1;
1.2       raeburn   445:             }
                    446:             if ($area eq 'board') {
1.12      albertel  447:                 $db_handling = $env{'form.db_handling'};
1.2       raeburn   448:             } elsif ($area eq 'users') {
1.12      albertel  449:                 $user_handling = $env{'form.user_handling'};
1.2       raeburn   450:             }
                    451:         }
                    452:     }
1.9       raeburn   453: 
                    454:     my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems);
1.2       raeburn   455:     if ($manifest_result eq 'ok') {
1.34      raeburn   456:         foreach my $res (sort(keys(%resources))) {
1.9       raeburn   457:             if ($importareas{$resources{$res}{type}}) {
                    458:                 $includedres{$res} = 1;
                    459:             }
                    460:         }
1.34      raeburn   461:         foreach my $itm (sort(keys(%items))) {
1.9       raeburn   462:             &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
                    463:         }
                    464:     }
1.34      raeburn   465:     foreach my $itm (sort(keys(%includeditems))) {
1.9       raeburn   466:         &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
                    467:     }
                    468: 
                    469:     $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
                    470:     if ($manifest_result eq 'ok') {
                    471: 
1.5       raeburn   472:         my @path = ($cdom,$crs,$timenow);
                    473:         my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
                    474:         foreach my $item (@path) {
                    475:             $fullpath .= '/'.$item;
                    476:             if (!-e "$fullpath") {
                    477:                 mkdir("$fullpath",0770);
                    478:             }
                    479:         }
                    480:         my @namedirs = ("resfiles","sequences","pages","problems");
                    481:         foreach my $name (@namedirs) {
                    482:             if (!-e "$fullpath/$name") {
                    483:                 mkdir("$fullpath/$name",0770);
                    484:             }
                    485:         }
1.9       raeburn   486:         &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
1.2       raeburn   487: 
                    488:         my @boards = ();
                    489:         my @announcements = ();
                    490:         my @quizzes = ();
                    491:         my @surveys = ();
1.9       raeburn   492:         my @pools = ();
1.2       raeburn   493:         my @groups = ();
                    494:         my %messages = ();
                    495:         my @timestamp = ();
                    496:         my %boardnum = ();
                    497:         my @topurls = ();
                    498:         my @topnames = ();
1.7       raeburn   499:         my @packages = ();
1.2       raeburn   500: 
1.9       raeburn   501:         &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   502: 
1.31      raeburn   503:         my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,\%resources,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
1.2       raeburn   504: 
1.9       raeburn   505:         &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   506: 
1.2       raeburn   507:         foreach my $item (@pages) {
1.3       raeburn   508:             my $filename = $timenow.'/pages/'.$item;
1.13      raeburn   509:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   510:         }
                    511:         foreach my $item (@sequences) {
                    512:             unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
1.3       raeburn   513:                 my $filename = $timenow.'/sequences/'.$item;
1.13      raeburn   514:                 my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   515:             }
                    516:         }
                    517:         foreach my $item (@resrcfiles) {
1.3       raeburn   518:             my $filename = $timenow.'/resfiles/'.$item;
1.13      raeburn   519:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   520:         }
                    521: 
                    522:         my @imports = ();
                    523:         if ($toplevel eq 'oldfolder') {
                    524:             for (my $i=0; $i<@topurls; $i++) {
1.18      www       525:                 my $url = &unescape($topurls[$i]);
                    526:                 my $name = &unescape($topnames[$i]);
1.21      albertel  527:                 push(@imports, [$name, $url]);
1.2       raeburn   528:             }
                    529:         } elsif ($toplevel eq 'newfolder') {
1.18      www       530:             my $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
                    531:             my $name = &unescape("$env{'form.foldername'}");
1.21      albertel  532:             push(@imports, [$name, $url]);
1.2       raeburn   533:         }
                    534:         my $errtext='';
                    535:         my $fatal=0;
                    536:         ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
1.19      albertel  537:         if ($#LONCAPA::map::order<1) {
                    538:             $LONCAPA::map::order[0]=1;
                    539:             $LONCAPA::map::resources[1]='';
1.2       raeburn   540:         }
1.8       raeburn   541:         my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
1.2       raeburn   542:         if ($fatal) {
1.20      albertel  543:             &Apache::lonnet::logthis("Fatal error during group_import.");
1.2       raeburn   544:         }
                    545:     }
1.3       raeburn   546:     if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
                    547:         system("rm -r -f $tempdir");
                    548:     }
1.28      bisitz    549: 
                    550:     # All done, display success message
                    551:     $r->print(
                    552:         '<p class="LC_success">'
                    553:        .&mt('Your import is complete.')
                    554:        .'</p>'
                    555:     );
                    556:     # Re-initialize Button
                    557:     my $initbutton =
                    558:            '<input type="button" value="'
1.33      raeburn   559:           .&mt('re-initializing Course')
1.29      bisitz    560:           .'" onclick="javascript:init(this.form)" />';
1.28      bisitz    561:     $r->print(
                    562:         '<form method="post" action="/adm/roles" target="loncapaclient" name="importDone">'
                    563:        .'<input type="hidden" name="orgurl" value="/adm/coursedocs" />'
                    564:        .'<input type="hidden" name="selectrole" value="1" />'
                    565:        .'<input type="hidden" name="'.$env{'request.role'}.'" value="1" />'
                    566:        .'<p class="LC_warning">'
                    567:        .&mt('Changes will become active for your current session after [_1]'
                    568:            .', or the next time you log in.'
                    569:             ,$initbutton)
                    570:        .'</p>'
                    571:        .'</form>'
                    572:     );
1.1       raeburn   573: }
                    574: 
                    575: 1;
                    576: __END__

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