File:  [LON-CAPA] / loncom / imspackages / imsimportdocs.pm
Revision 1.17: download - view: text, annotated - select for diffs
Fri Mar 24 17:36:27 2006 UTC (18 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Existing webct4 code identified as appropriate for WebCT 4 Campus Edition. Vista to follow.

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

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