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

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

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