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

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'};
1.1       raeburn   148: 
                    149: # get personal data
                    150:  
1.12      albertel  151:     my $uname=$env{'user.name'};
                    152:     my $udom=$env{'user.domain'};
1.1       raeburn   153:     my $plainname=&Apache::lonnet::escape(
                    154:                      &Apache::loncommon::plainname($uname,$udom));
                    155: 
                    156: # does this user have privileges to post, etc?
1.12      albertel  157:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.1       raeburn   158:     unless ($allowed) {
                    159:         $r->print("<html><head><title>The LearningOnline Network with CAPA</title></head>");
1.8       raeburn   160:         $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1));  
1.1       raeburn   161:         $r->print('<h3>'.&mt('Modification of Course Contents Disallowed').'</h3>'.&mt('Your current role does not grant you the right to modify course content in this course.').'</body></html>');
                    162:         return OK;
                    163:     }
                    164: 
                    165:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    166:        ['phase']);
                    167: 
1.12      albertel  168:     if ($env{'form.phase'} eq 'one') {    
1.1       raeburn   169:         &jscript_one(\$javascript);
1.12      albertel  170:     } elsif ($env{'form.phase'} eq 'two') {
1.1       raeburn   171:         &jscript_two(\$javascript);
1.12      albertel  172:     } elsif ($env{'form.phase'} eq 'three') {
1.2       raeburn   173:         &jscript_three(\$javascript);
1.1       raeburn   174:     }
                    175: 
                    176: # print screen
                    177:     $r->print(<<ENDHEAD);
                    178: <html>
                    179: <head>
                    180: <title>The LearningOnline Network with CAPA</title>
                    181: <script type="text/javascript">
                    182: <!--
                    183: $javascript
                    184: -->
                    185: </script>
                    186: </head>
                    187: ENDHEAD
                    188: # -------------------------------------------------------------------- Body tag
1.8       raeburn   189:     $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1));
1.12      albertel  190:     if ($env{'form.phase'} eq 'one') {
1.1       raeburn   191:         &display_one($r);       
1.12      albertel  192:     } elsif ($env{'form.phase'} eq 'two') {
1.3       raeburn   193:         &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap);
1.12      albertel  194:     } elsif ($env{'form.phase'} eq 'three') {
1.14    ! raeburn   195:         &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
1.1       raeburn   196:     }   
                    197:     $r->print("</body><html>");
1.2       raeburn   198:     return OK;
1.1       raeburn   199: } 
                    200: 
                    201: 
                    202: sub display_one {
1.2       raeburn   203:     my ($r) = @_;
1.1       raeburn   204:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
                    205: 
                    206:     $r->print(<<ENDBLOCK);
                    207: <form action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" name="pickcms">
                    208:   <table border='0' bgcolor='#F6F6F6' cellspacing='0' cellpadding ='0' width='100%'>
                    209:    <tr>
                    210:     <td colspan='2'>
                    211:      <table border='0' cellspacing='0' cellpadding='0'>
                    212:       <tr>
                    213:         <td colspan='2'  align='left'>&nbsp;
                    214:         </td>
                    215:        </tr>
                    216:        <tr bgcolor='#CCCCFF'>
                    217:         <td valign='middle'><img src='/res/adm/pages/bl_step1.gif'>&nbsp;
                    218:         </td>
                    219:         <td width='100%' align='left'>&nbsp;&nbsp;
                    220:          <font face='arial,helvetica,sans-serif'><b>Specify the Course Management system used to create the package.</b>&nbsp;&nbsp;
                    221:          </font>
                    222:        </td>
                    223:       </tr>
                    224:       <tr>
                    225:        <td colspan='2'>&nbsp;</td>
                    226:       </tr>
                    227:       <tr>
                    228:        <td>&nbsp;</td>
                    229:        <td>
                    230:         <font face='Arial,Helvetica,sans-serif'>
                    231: Please choose the CMS used to create your IMS content package.&nbsp;&nbsp;
                    232:         <select name="source">
                    233:          <option value='-1' selected="true">Please select
                    234:          <option value='bb5'>Blackboard 5
1.7       raeburn   235:          <option value='bb6'>Blackboard 6
1.1       raeburn   236:          <option value='angel'>ANGEL
1.11      raeburn   237:          <option value='webct4'>WebCT 4
1.1       raeburn   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;
1.12      albertel  261:         <input type="hidden" name="folder" value="$env{'form.folder'}" />
1.1       raeburn   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']);
1.12      albertel  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.11      raeburn   339:                 if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') {
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;
1.12      albertel  469:           <input type="hidden" name="folder" value="$env{'form.folder'}" />
1.1       raeburn   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.14    ! raeburn   504:     my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_;
1.12      albertel  505:     my $folder = $env{'form.folder'};
                    506:     my $cms = $env{'form.source'};
                    507:     my $tempdir = $env{'form.tempdir'};
1.2       raeburn   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 = ();
1.12      albertel  543:     if (defined($env{'form.toplevel'}) ) {
                    544:         $toplevel = $env{'form.toplevel'};     
1.2       raeburn   545:     }
1.12      albertel  546:     if (defined($env{'form.foldername'}) ) {
                    547:         $foldername = $env{'form.foldername'}; 
1.2       raeburn   548:     }
1.8       raeburn   549: 
1.2       raeburn   550:     foreach my $area (@{$areas}) {
1.12      albertel  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') {
1.12      albertel  560:                 $db_handling = $env{'form.db_handling'};
1.2       raeburn   561:             } elsif ($area eq 'users') {
1.12      albertel  562:                 $user_handling = $env{'form.user_handling'};
1.2       raeburn   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: 
                    582:     $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
                    583:     if ($manifest_result eq 'ok') {
                    584: 
1.5       raeburn   585:         my @path = ($cdom,$crs,$timenow);
                    586:         my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
                    587:         foreach my $item (@path) {
                    588:             $fullpath .= '/'.$item;
                    589:             if (!-e "$fullpath") {
                    590:                 mkdir("$fullpath",0770);
                    591:             }
                    592:         }
                    593:         my @namedirs = ("resfiles","sequences","pages","problems");
                    594:         foreach my $name (@namedirs) {
                    595:             if (!-e "$fullpath/$name") {
                    596:                 mkdir("$fullpath/$name",0770);
                    597:             }
                    598:         }
1.9       raeburn   599:         &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
1.2       raeburn   600: 
                    601:         my @boards = ();
                    602:         my @announcements = ();
                    603:         my @quizzes = ();
                    604:         my @surveys = ();
1.9       raeburn   605:         my @pools = ();
1.2       raeburn   606:         my @groups = ();
                    607:         my %messages = ();
                    608:         my @timestamp = ();
                    609:         my %boardnum = ();
                    610:         my @topurls = ();
                    611:         my @topnames = ();
1.7       raeburn   612:         my @packages = ();
1.2       raeburn   613: 
1.9       raeburn   614:         &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   615: 
1.14    ! raeburn   616:         my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
1.2       raeburn   617: 
1.9       raeburn   618:         &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   619: 
1.2       raeburn   620:         foreach my $item (@pages) {
1.3       raeburn   621:             my $filename = $timenow.'/pages/'.$item;
1.13      raeburn   622:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   623:         }
                    624:         foreach my $item (@sequences) {
                    625:             unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
1.3       raeburn   626:                 my $filename = $timenow.'/sequences/'.$item;
1.13      raeburn   627:                 my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   628:             }
                    629:         }
                    630:         foreach my $item (@resrcfiles) {
1.3       raeburn   631:             my $filename = $timenow.'/resfiles/'.$item;
1.13      raeburn   632:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   633:         }
                    634: 
                    635:         my @imports = ();
                    636:         if ($toplevel eq 'oldfolder') {
                    637:             for (my $i=0; $i<@topurls; $i++) {
                    638:                 my $url = &Apache::lonnet::unescape($topurls[$i]);
                    639:                 my $name = &Apache::lonnet::unescape($topnames[$i]);
                    640:                 push @imports, $name, $url;
                    641:             }
                    642:         } elsif ($toplevel eq 'newfolder') {
                    643:             my $url = &Apache::lonnet::unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
1.12      albertel  644:             my $name = &Apache::lonnet::unescape("$env{'form.foldername'}");
1.2       raeburn   645:             push @imports, $name, $url;
                    646:         }
                    647:         my $errtext='';
                    648:         my $fatal=0;
                    649:         ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
                    650:         if ($#Apache::lonratedt::order<1) {
                    651:             $Apache::lonratedt::order[0]=1;
                    652:             $Apache::lonratedt::resources[1]='';
                    653:         }
1.8       raeburn   654:         my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
1.2       raeburn   655:         if ($fatal) {
                    656:             print STDERR "Fatal error during group_import\n";
                    657:         }
                    658:     }
1.3       raeburn   659:     if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
                    660:         system("rm -r -f $tempdir");
                    661:     }
1.2       raeburn   662:     $r->print(<<ENDBLOCK);
                    663:   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
                    664:    <tr>
                    665:     <td colspan='2'>
                    666:      <table border='0' cellspacing='0' cellpadding='0'>
                    667:       <tr>
                    668:        <td colspan='2'  align='left'>&nbsp;
                    669:        </td>
                    670:       </tr>
                    671:       <tr bgcolor='#CCCCFF'>
                    672:        <td valign='middle'><img src='/res/adm/pages/bl_step5.gif'>
                    673:        </td>
                    674:        <td width='100%' align='left'>&nbsp;&nbsp;
                    675:         <font face='arial,helvetica,sans-serif'><b>Your import is complete</b></font>
                    676:        </td>
                    677:       </tr>
                    678:       <tr>
                    679:        <td colspan='2'>&nbsp;</td>
                    680:       </tr>
                    681:       <tr>
                    682:        <td>&nbsp;</td>
                    683:        <td>
                    684: ENDBLOCK
                    685:     my $initblock = qq|  
                    686:          <form method="post" action="/adm/roles" target="loncapaclient" name="importDone">
                    687:            <input type="hidden" name="orgurl" value="/adm/coursedocs" />
                    688:            <input type="hidden" name="selectrole" value="1" />
                    689:            <h3><font color="red">Changes will become active for your current session after
1.12      albertel  690:            <input type="hidden" name="$env{'request.role'}" value="1" />
1.2       raeburn   691:            <input type="button" value="|;
                    692:     $initblock .= &mt('re-initializing course');
                    693:     $initblock .= qq|" onClick="javascript:init(this.form)"/>|;
1.8       raeburn   694:     $initblock .= ', '.&mt('or the next time you log in.');
1.2       raeburn   695:     $initblock .= qq|</font></h3></form>|;  
                    696:     $r->print($initblock);
                    697:     $r->print(<<ENDBLOCKTWO);
                    698:      </table>
                    699:     </td>
                    700:    </tr>
                    701:   </table>
                    702: ENDBLOCKTWO
1.1       raeburn   703: }
                    704: 
                    705: 1;
                    706: __END__

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