File:  [LON-CAPA] / loncom / imspackages / imsimportdocs.pm
Revision 1.24: download - view: text, annotated - select for diffs
Fri Nov 6 17:16:53 2009 UTC (14 years, 7 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Optimizations for IMS upload to course docs, part 1 (display_one):
- Replaced hardcoded HTML code by standard topic_bar calls
- No special font/... needed
- Added missing &mt() calls
- Wrapped warning messages in paragraphs and added warning style
- Consistent wording: "Exit now" -> just "Cancel"
- Removed unneccessary text which says in simple words: "Click upload to upload"
- Added "File: " in front of file selection box
- XHTML: lower case HTML attributes

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: imsimportdocs.pm,v 1.24 2009/11/06 17:16:53 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('<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.').
  170: 		  &Apache::loncommon::end_page());
  171:         return OK;
  172:     }
  173: 
  174:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  175:        ['phase']);
  176: 
  177:     if ($env{'form.phase'} eq 'one') {    
  178:         &jscript_one(\$javascript);
  179:     } elsif ($env{'form.phase'} eq 'two') {
  180:         &jscript_two(\$javascript);
  181:     } elsif ($env{'form.phase'} eq 'three') {
  182:         &jscript_three(\$javascript);
  183:     }
  184: 
  185:     $javascript = 
  186: 	 "<script type=\"text/javascript\">\n".
  187: 	 "//<!--\n$javascript\n// --></script>\n";
  188:     my $start_page = &Apache::loncommon::start_page('Import IMS package',
  189: 						    $javascript,
  190: 						    {'only_body' => 1,});
  191: # print screen
  192:     $r->print($start_page);
  193: 
  194:     if ($env{'form.phase'} eq 'one') {
  195:         &display_one($r);       
  196:     } elsif ($env{'form.phase'} eq 'two') {
  197:         &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap);
  198:     } elsif ($env{'form.phase'} eq 'three') {
  199:         &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
  200:     }   
  201:     $r->print(&Apache::loncommon::end_page());
  202:     return OK;
  203: } 
  204: 
  205: 
  206: sub display_one {
  207:     my ($r) = @_;
  208:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
  209: 
  210:     $r->print(
  211:         '<form action="/adm/imsimportdocs" method="post"'
  212:        .' enctype="multipart/form-data" name="pickcms">'
  213:        .&Apache::lonhtmlcommon::topic_bar(
  214:             1,&mt('Specify the Course Management system used to create the package'))
  215:        .&mt('Please choose the CMS used to create your IMS content package:').' '
  216:        .'<select name="source">'
  217:        .'<option value="-1" selected="selected">'.&mt('Please select').'</option>'
  218:        .'<option value="bb5">Blackboard 5</option>'
  219:        .'<option value="bb6">Blackboard 6</option>'
  220:        .'<option value="angel5">ANGEL 5.5</option>'
  221:        .'<option value="webctce4">WebCT 4 Campus Edition</option>'
  222:        .'</select>'
  223:     );
  224:     $r->print(
  225:        &Apache::lonhtmlcommon::topic_bar(
  226:            2,&mt('Locate the IMS content package you wish to upload'))
  227:       .'<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
  228:       .'<input type="hidden" name="phase" value="two" />'
  229:       .&mt('File:')
  230:       .' <input type="file" name="uploadname" size="40" />'
  231:     );
  232:     $r->print(
  233:        '<hr />'
  234:       .'<p>'
  235:       .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
  236:       .' onclick="javascript:self.close()" />'
  237:       .' '
  238:       .'<input type="button" name="nextpage" value="'.&mt('Upload IMS package').'"'
  239:       .' onclick="javascript:nextPage()" />'
  240:       .'</p>'
  241:     );
  242: }
  243: 
  244: 
  245: sub display_two {
  246:     my ($r,$crs,$areasref,$areaname,%cmsmap) = @_;
  247:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
  248:     my $cms = $env{'form.source'};
  249:     my $timenow = time;
  250:     my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
  251:     my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir);
  252:     my $unzip_result = '';
  253:     my $manifest_result = '';
  254:     unless ($tempdir eq '') {
  255:         $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
  256:     }
  257:     my %resources = ();
  258:     my %includedres = ();
  259:     my %includeditems = ();
  260:     my %items = ();
  261:     my %hrefs = ();
  262:     my %resinfo = ();
  263:     my %count = ();
  264:     my @bgcolors = ("#eeeeee","#dddddd");
  265: 
  266:     my $counter = 0;
  267:     my $iter = 0;
  268:     my %count = (
  269:                 announce => 0,
  270:                 board => 0,
  271:                 doc => 0,
  272:                 extlink => 0,
  273:                 msg => 0,
  274:                 pool => 0,
  275:                 quiz => 0,
  276:                 staff => 0,
  277:                 survey => 0,
  278:                 users => 0,
  279:                 );
  280: 
  281:     if ($unzip_result eq 'ok') {
  282:         $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems);
  283:         if ($manifest_result eq 'ok') {
  284:             foreach my $res (sort keys %resources) {
  285:                 if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') {
  286:                     foreach my $area (keys %{$cmsmap{$cms}}) {
  287:                         if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
  288:                             $count{$area} ++;
  289:                         }
  290:                     }
  291:                 } elsif ($cms eq 'angel5') {
  292:                     foreach my $area (keys %{$cmsmap{$cms}}) {
  293:                         if ($area eq 'doc') {
  294:                             if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
  295:                                 $count{$area} ++;
  296:                             }
  297:                         } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
  298:                             $count{$area} ++;
  299:                         }
  300:                     }
  301:                 }
  302:             }
  303:             $r->print(<<ENDBLOCK);
  304: <form name="pickoptions" method="post">
  305:   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
  306:    <tr>
  307:     <td colspan='2'>
  308:      <table border='0' cellspacing='0' cellpadding='0'>
  309:       <tr>
  310:        <td colspan='2'  align='left'>&nbsp;
  311:        </td>
  312:       </tr>
  313:       <tr bgcolor='#CCCCFF'>
  314:        <td valign="middle"><img src="/res/adm/pages/bl_step3.gif" alt="3" />
  315:        </td>
  316:        <td width='100%' align='left'>&nbsp;&nbsp;
  317:         <font face='arial,helvetica,sans-serif'><b>Choose which content types you wish to import</b></font>
  318:        </td>
  319:       </tr>
  320:       <tr>
  321:        <td colspan='2'>&nbsp;</td>
  322:       </tr>
  323:       <tr>
  324:        <td>&nbsp;</td>
  325:        <td>
  326:         <table border='0' cellspacing='0' cellpadding='1' bgcolor='#000000'>
  327:          <tr>
  328:           <td>
  329:            <table border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' width='100%'>
  330:             <tr>
  331:              <td>
  332:               <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width='100%'>
  333:                <tr bgcolor='#CCCCFF'>
  334:                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Import?</b></font></td>           
  335:                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Content type</b></font></td>
  336:                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Additional options</b></font></td>
  337:                </tr>
  338: ENDBLOCK
  339:             foreach my $area (@{$areasref}) {
  340:                 if ($count{$area} > 0) {
  341:                     my $count_tag = 'flag_'.$counter;
  342:                     $r->print("               <tr bgcolor='@bgcolors[$iter]'>
  343:                 <td align='left'><font face='arial,helvetica,sans-serif'><input name='$area' type='checkbox' ");
  344:                     if ($area eq 'board' || $area eq 'users') {
  345:                         $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|);
  346:                     }
  347:                     $r->print("/></font></td>
  348:                 <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;$$areaname{$area}&nbsp;&nbsp; - $count{$area} item(s)</font></td>");
  349:                     if ($area eq 'board') {
  350:                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;
  351:                  <select name='db_handling'>
  352:                   <option value='-2'>&lt;-- Check Import first</option>
  353:                  </select></font>
  354:                 </td>");
  355:                     } elsif ($area eq 'users') {
  356:                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;
  357:                  <select name='user_handling'>
  358:                   <option value='-2'>&lt;-- Check Import first</option>
  359:                  </select>
  360:                  </font>        
  361:                 </td>");
  362:                     } else {
  363:                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;None<input type='hidden' name='$count_tag' /></font></td>");
  364:                     }
  365:                     $counter ++;
  366:                     $iter = $counter%2;
  367:                 }
  368:             }
  369:             $r->print(<<ENDDOCUMENT);
  370:                </tr>
  371:               </table>
  372:              </td>
  373:             </tr>
  374:            </table>
  375:           </td>
  376:          </tr>
  377:         </table>
  378:        </td>
  379:       </tr>
  380:       <tr>
  381:        <td colspan='2'>&nbsp;<br /><br /></td>
  382:       </tr>
  383:       <tr bgcolor='#CCCCFF'>
  384:        <td valign="middle"><img src="/res/adm/pages/bl_step4.gif" alt="4" />
  385:        </td>
  386:        <td width='100%' align='left'>&nbsp;&nbsp;
  387:         <font face='arial,helvetica,sans-serif'><b>Choose display options for listing of contents of top level of package</b></font>
  388:        </td>
  389:       </tr>
  390:       <tr>
  391:        <td colspan='2'>&nbsp;</td>
  392:       </tr>
  393:       <tr>
  394:        <td>&nbsp;</td>
  395:        <td>
  396:         <table border='0'>
  397:          <tr>
  398:           <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>
  399:          </tr>
  400:          <tr>
  401:           <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>
  402:          </tr>
  403:         </table>
  404:        </td>
  405:       </tr>
  406:       <tr>
  407:        <td colspan='2'>&nbsp;</td>
  408:       </tr>
  409:       <tr>
  410:        <td>&nbsp;</td>
  411:        <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>
  412:       </tr>
  413:       <tr>
  414:        <td colspan='2'>&nbsp;
  415:           <input type="hidden" name="folder" value="$env{'form.folder'}" />
  416:           <input type="hidden" name="source" value="$cms" />
  417:           <input type="hidden" name="tempdir" value="$tempdir" />
  418:           <input type="hidden" name="phase" value="three" />
  419:        </td>
  420:       </tr>
  421:       <tr>
  422:        <td colspan='2'>
  423:         <table border='0' cellspacing='0' cellpadding='0' width="100%">
  424:          <tr>
  425:           <td align='left'>
  426:            <input type='button' name='exitpage' value='Cancel' onClick="javascript:self.close()" />
  427:           </td>
  428:           <td align='right'>
  429:            <input type="button" name="nextpage" value="Complete Import" onClick="javascript:nextPage($counter)" />
  430:           </td>
  431:          </tr>
  432:         </table>
  433:        </td>
  434:       </tr>
  435:      </table>
  436:     </td>
  437:    </tr>
  438:   </table>
  439: ENDDOCUMENT
  440:         } else {
  441:             $r->print(
  442:                '<p class="LC_warning">'
  443:                .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.')
  444:                .'</p>'
  445:             );
  446:         }
  447:     } else {
  448:         $r->print(
  449:             '<p class="LC_warning">'
  450:            .&mt('Processing of your IMS package failed because the file you'
  451:                .' uploaded could not be unzipped.')
  452:            .'</p>'
  453:         );
  454:     }
  455: }
  456: 
  457: 
  458: sub display_three {
  459:     my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_;
  460:     my $folder = $env{'form.folder'};
  461:     my $cms = $env{'form.source'};
  462:     my $tempdir = $env{'form.tempdir'};
  463:     my $longcrs = '';
  464:     if ($crs =~ m/^(\d)(\d)(\d)/) {
  465:         $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
  466:     }
  467:     my %importareas = ();
  468:     my %includedres = ();
  469:     my %includeditems = ();
  470:     my @targets = ();
  471:     my %resources = ();
  472:     my %items = ();
  473:     my %hrefs = ();
  474:     my %urls = ();
  475:     my %resinfo = ();
  476:     my %total = (
  477:                  page => 0,
  478:                  prob => 0,
  479:                  seq => 0,
  480:                  board => 0,         
  481:                  quiz => 0,
  482:                  surv => 0,
  483:                 );
  484:     my @pages = ();
  485:     my @sequences = ();
  486:     my @resrcfiles = ();
  487: 
  488:     my $timenow = time;
  489: 
  490:     my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow;
  491:     my $seqstem = "/uploaded/$cdom/$crs/$timenow";
  492:     my $db_handling = '';
  493:     my $user_handling = '';
  494: 
  495:     my $toplevel = '';
  496:     my $foldername = '';
  497:     my %topitems = ();
  498:     if (defined($env{'form.toplevel'}) ) {
  499:         $toplevel = $env{'form.toplevel'};     
  500:     }
  501:     if (defined($env{'form.foldername'}) ) {
  502:         $foldername = $env{'form.foldername'}; 
  503:     }
  504: 
  505:     foreach my $area (@{$areas}) {
  506:         if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) {
  507:             if ($cms eq 'angel5' && $area eq 'doc') {
  508:                 foreach (@{$cmsmap{$cms}{$area}}) {
  509:                     $importareas{$_} = 1;
  510:                 }
  511:             } else {
  512:                 $importareas{$cmsmap{$cms}{$area}} = 1;
  513:             }
  514:             if ($area eq 'board') {
  515:                 $db_handling = $env{'form.db_handling'};
  516:             } elsif ($area eq 'users') {
  517:                 $user_handling = $env{'form.user_handling'};
  518:             }
  519:         }
  520:     }
  521: 
  522:     my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems);
  523:     if ($manifest_result eq 'ok') {
  524:         foreach my $res (sort keys %resources) {
  525:             if ($importareas{$resources{$res}{type}}) {
  526:                 $includedres{$res} = 1;
  527:             }
  528:         }
  529:         foreach my $itm (sort keys %items) {
  530:             &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
  531:         }
  532:     }
  533:     foreach my $itm (sort keys %includeditems) {
  534:         &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
  535:     }
  536: 
  537:     $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
  538:     if ($manifest_result eq 'ok') {
  539: 
  540:         my @path = ($cdom,$crs,$timenow);
  541:         my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
  542:         foreach my $item (@path) {
  543:             $fullpath .= '/'.$item;
  544:             if (!-e "$fullpath") {
  545:                 mkdir("$fullpath",0770);
  546:             }
  547:         }
  548:         my @namedirs = ("resfiles","sequences","pages","problems");
  549:         foreach my $name (@namedirs) {
  550:             if (!-e "$fullpath/$name") {
  551:                 mkdir("$fullpath/$name",0770);
  552:             }
  553:         }
  554:         &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
  555: 
  556:         my @boards = ();
  557:         my @announcements = ();
  558:         my @quizzes = ();
  559:         my @surveys = ();
  560:         my @pools = ();
  561:         my @groups = ();
  562:         my %messages = ();
  563:         my @timestamp = ();
  564:         my %boardnum = ();
  565:         my @topurls = ();
  566:         my @topnames = ();
  567:         my @packages = ();
  568: 
  569:         &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);
  570: 
  571:         my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
  572: 
  573:         &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);
  574: 
  575:         foreach my $item (@pages) {
  576:             my $filename = $timenow.'/pages/'.$item;
  577:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  578:         }
  579:         foreach my $item (@sequences) {
  580:             unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
  581:                 my $filename = $timenow.'/sequences/'.$item;
  582:                 my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  583:             }
  584:         }
  585:         foreach my $item (@resrcfiles) {
  586:             my $filename = $timenow.'/resfiles/'.$item;
  587:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
  588:         }
  589: 
  590:         my @imports = ();
  591:         if ($toplevel eq 'oldfolder') {
  592:             for (my $i=0; $i<@topurls; $i++) {
  593:                 my $url = &unescape($topurls[$i]);
  594:                 my $name = &unescape($topnames[$i]);
  595:                 push(@imports, [$name, $url]);
  596:             }
  597:         } elsif ($toplevel eq 'newfolder') {
  598:             my $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
  599:             my $name = &unescape("$env{'form.foldername'}");
  600:             push(@imports, [$name, $url]);
  601:         }
  602:         my $errtext='';
  603:         my $fatal=0;
  604:         ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
  605:         if ($#LONCAPA::map::order<1) {
  606:             $LONCAPA::map::order[0]=1;
  607:             $LONCAPA::map::resources[1]='';
  608:         }
  609:         my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
  610:         if ($fatal) {
  611:             &Apache::lonnet::logthis("Fatal error during group_import.");
  612:         }
  613:     }
  614:     if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
  615:         system("rm -r -f $tempdir");
  616:     }
  617:     $r->print(<<ENDBLOCK);
  618:   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
  619:    <tr>
  620:     <td colspan='2'>
  621:      <table border='0' cellspacing='0' cellpadding='0'>
  622:       <tr>
  623:        <td colspan='2'  align='left'>&nbsp;
  624:        </td>
  625:       </tr>
  626:       <tr bgcolor='#CCCCFF'>
  627:        <td valign="middle"><img src="/res/adm/pages/bl_step5.gif" alt="5" />
  628:        </td>
  629:        <td width='100%' align='left'>&nbsp;&nbsp;
  630:         <font face='arial,helvetica,sans-serif'><b>Your import is complete</b></font>
  631:        </td>
  632:       </tr>
  633:       <tr>
  634:        <td colspan='2'>&nbsp;</td>
  635:       </tr>
  636:       <tr>
  637:        <td>&nbsp;</td>
  638:        <td>
  639: ENDBLOCK
  640:     my $initblock = qq|  
  641:          <form method="post" action="/adm/roles" target="loncapaclient" name="importDone">
  642:            <input type="hidden" name="orgurl" value="/adm/coursedocs" />
  643:            <input type="hidden" name="selectrole" value="1" />
  644:            <h3><font color="red">Changes will become active for your current session after
  645:            <input type="hidden" name="$env{'request.role'}" value="1" />
  646:            <input type="button" value="|;
  647:     $initblock .= &mt('re-initializing course');
  648:     $initblock .= qq|" onClick="javascript:init(this.form)" />|;
  649:     $initblock .= ', '.&mt('or the next time you log in.');
  650:     $initblock .= qq|</font></h3></form>|;  
  651:     $r->print($initblock);
  652:     $r->print(<<ENDBLOCKTWO);
  653:      </table>
  654:     </td>
  655:    </tr>
  656:   </table>
  657: ENDBLOCKTWO
  658: }
  659: 
  660: 1;
  661: __END__

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