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

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

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