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

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

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