File:  [LON-CAPA] / loncom / imspackages / imsimportdocs.pm
Revision 1.25: download - view: text, annotated - select for diffs
Fri Nov 20 11:16:59 2009 UTC (14 years, 8 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
- Code style: Early escape in phase two when errors occurred/not allowed
- Show warning message for unsupported cms types found in IMS package
- Added error style to error message when privs are not sufficiant
- Added headline to PopUp window
- Added some code comments

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

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