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

1.18    ! www         1: # The LearningOnline Network with CAPA
        !             2: #
        !             3: # $Id: lonfeedback.pm,v 1.203 2006/05/10 22:47:22 albertel Exp $
        !             4: #
1.7       raeburn     5: # Copyright Michigan State University Board of Trustees
                      6: #
                      7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      8: #
                      9: # LON-CAPA is free software; you can redistribute it and/or modify
                     10: # it under the terms of the GNU General Public License as published by
                     11: # the Free Software Foundation; either version 2 of the License, or
                     12: # (at your option) any later version.
                     13: #
                     14: # LON-CAPA is distributed in the hope that it will be useful,
                     15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     17: # GNU General Public License for more details.
                     18: #
                     19: # You should have received a copy of the GNU General Public License
                     20: # along with LON-CAPA; if not, write to the Free Software
                     21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     22: #
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: 
1.1       raeburn    28: package Apache::imsimportdocs;
                     29: 
1.2       raeburn    30: use Apache::Constants qw(:common :http :methods);
1.1       raeburn    31: use Apache::lonnet;
1.2       raeburn    32: use Apache::londocs;
1.1       raeburn    33: use Apache::loncommon;
                     34: use Apache::lonlocal;
                     35: use Apache::imsprocessor;
                     36: use LONCAPA::Configuration;
1.18    ! www        37: use lib '/home/httpd/lib/perl/';
        !            38: use LONCAPA;
        !            39:  
1.2       raeburn    40: use strict;
1.1       raeburn    41: 
                     42: sub jscript_one {
                     43:     my $javascript = shift;
                     44:     $$javascript = qq#
                     45: function verify() {
                     46:  if ((document.forms.pickcms.uploadname.value == '')  || (!document.forms.pickcms.uploadname.value)) {
                     47:    alert("You must provide the name of the IMS package to be imported")
                     48:    return false
                     49:  }
                     50:  if (document.forms.pickcms.source.selectedIndex == 0) {
                     51:    alert("You must choose the Course Management System from which the IMS package was exported");
                     52:    return false
                     53:  }
                     54:  return true
                     55: }
                     56: 
                     57: function nextPage() {
                     58:  if (verify()) {
                     59:    document.forms.pickcms.submit()
                     60:  }
                     61: }
                     62: #;
                     63:  
                     64: }
                     65: 
                     66: sub jscript_two {
                     67:     my $javascript = shift;
                     68:     $$javascript = qq#
                     69: function setOptions(caller,itemnum) {
                     70:   var opForm = document.forms.pickoptions
                     71:   var menu = 1 + itemnum*2
                     72:   opForm.elements[menu].length = 0
                     73:   if (opForm.elements[itemnum*2].checked == true) {
                     74:     if (caller == "board") {
                     75:       opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
                     76:       opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
1.4       raeburn    77:       opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true)
                     78:       opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true)
1.1       raeburn    79:     }
                     80:     else { 
                     81:       if (caller == "users") {
                     82:         opForm.elements[menu].length = 0
                     83:         opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
                     84:         opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true)
                     85:         opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true)
                     86:       }
                     87:     }
                     88:   }
                     89:   else {
                     90:     opForm.elements[menu].options[0] = new Option("Not required","0",true,true)
                     91:   }
                     92:   opForm.elements[menu].selectedIndex = 0
                     93: }
                     94: 
                     95: function verify(caller) { 
                     96:   var opForm = document.forms.pickoptions
                     97:   var totcheck = 0;
                     98:   for (var i=0; i<caller; i++) {
                     99:     if (opForm.elements[2*i].checked == true) {
                    100:       totcheck ++
                    101:       if (opForm.elements[2*i].name == "board") { 
                    102:         if (opForm.elements[2*i+1].selectedIndex == 0) {     
                    103:           alert("You must select one of the additional options when importing Discussion Boards ")
                    104:           return false
                    105:         }
                    106:       }
                    107:       if (opForm.elements[2*i].name == "users") {
                    108:         if (opForm.elements[2*i+1].selectedIndex == 0) {     
                    109:           alert("You must select one of the additional options when importing Enrollment")
                    110:           return false
                    111:         }
                    112:       }
                    113:     }
                    114:   }
                    115:   if (totcheck == 0) {
                    116:     alert("You must check the Checkbox for at least one Content Type");
                    117:     return false
                    118:   }
                    119:   return true
                    120: }
                    121: 
                    122: function nextPage(caller) {
                    123:  if (verify(caller)) {
                    124:    document.forms.pickoptions.submit()
                    125:  }
                    126: }
                    127: #;
                    128: }
                    129: 
1.2       raeburn   130: sub jscript_three {
                    131:     my $javascript = shift;
                    132:     $$javascript = qq|
                    133: function init(tf) {
                    134:     setTimeout("self.close()",3000)
                    135:     tf.submit();   
                    136: }
                    137:     |;
                    138: }
                    139: 
1.1       raeburn   140: sub handler {
                    141:     my $r = shift;
                    142:     my $javascript = '';
                    143:     &Apache::loncommon::content_type($r,'text/html');
                    144:     $r->send_http_header;
                    145:     return OK if $r->header_only;
                    146: 
1.3       raeburn   147:     my @areas = ();
1.1       raeburn   148:     my %cmsmap = ();
1.3       raeburn   149:     my %areaname = ();
                    150:     &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname);
1.1       raeburn   151: 
                    152: # get course data
1.12      albertel  153:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                    154:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.1       raeburn   155: 
                    156: # get personal data
                    157:  
1.12      albertel  158:     my $uname=$env{'user.name'};
                    159:     my $udom=$env{'user.domain'};
1.18    ! www       160:     my $plainname=&escape(
1.1       raeburn   161:                      &Apache::loncommon::plainname($uname,$udom));
                    162: 
                    163: # does this user have privileges to post, etc?
1.12      albertel  164:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.1       raeburn   165:     unless ($allowed) {
1.15      albertel  166:         $r->print(&Apache::loncommon::start_page('Import IMS package',undef,
                    167: 						 {'only_body' => 1,}));  
                    168:         $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.').
                    169: 		  &Apache::loncommon::end_page());
1.1       raeburn   170:         return OK;
                    171:     }
                    172: 
                    173:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    174:        ['phase']);
                    175: 
1.12      albertel  176:     if ($env{'form.phase'} eq 'one') {    
1.1       raeburn   177:         &jscript_one(\$javascript);
1.12      albertel  178:     } elsif ($env{'form.phase'} eq 'two') {
1.1       raeburn   179:         &jscript_two(\$javascript);
1.12      albertel  180:     } elsif ($env{'form.phase'} eq 'three') {
1.2       raeburn   181:         &jscript_three(\$javascript);
1.1       raeburn   182:     }
                    183: 
1.15      albertel  184:     $javascript = 
                    185: 	 "<script type=\"text/javascript\">\n".
                    186: 	 "//<!--\n$javascript\n// --></script>\n";
                    187:     my $start_page = &Apache::loncommon::start_page('Import IMS package',
                    188: 						    $javascript,
                    189: 						    {'only_body' => 1,});
1.1       raeburn   190: # print screen
1.15      albertel  191:     $r->print($start_page);
                    192: 
1.12      albertel  193:     if ($env{'form.phase'} eq 'one') {
1.1       raeburn   194:         &display_one($r);       
1.12      albertel  195:     } elsif ($env{'form.phase'} eq 'two') {
1.3       raeburn   196:         &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap);
1.12      albertel  197:     } elsif ($env{'form.phase'} eq 'three') {
1.14      raeburn   198:         &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
1.1       raeburn   199:     }   
1.15      albertel  200:     $r->print(&Apache::loncommon::end_page());
1.2       raeburn   201:     return OK;
1.1       raeburn   202: } 
                    203: 
                    204: 
                    205: sub display_one {
1.2       raeburn   206:     my ($r) = @_;
1.1       raeburn   207:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
                    208: 
                    209:     $r->print(<<ENDBLOCK);
                    210: <form action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" name="pickcms">
                    211:   <table border='0' bgcolor='#F6F6F6' cellspacing='0' cellpadding ='0' width='100%'>
                    212:    <tr>
                    213:     <td colspan='2'>
                    214:      <table border='0' cellspacing='0' cellpadding='0'>
                    215:       <tr>
                    216:         <td colspan='2'  align='left'>&nbsp;
                    217:         </td>
                    218:        </tr>
                    219:        <tr bgcolor='#CCCCFF'>
                    220:         <td valign='middle'><img src='/res/adm/pages/bl_step1.gif'>&nbsp;
                    221:         </td>
                    222:         <td width='100%' align='left'>&nbsp;&nbsp;
                    223:          <font face='arial,helvetica,sans-serif'><b>Specify the Course Management system used to create the package.</b>&nbsp;&nbsp;
                    224:          </font>
                    225:        </td>
                    226:       </tr>
                    227:       <tr>
                    228:        <td colspan='2'>&nbsp;</td>
                    229:       </tr>
                    230:       <tr>
                    231:        <td>&nbsp;</td>
                    232:        <td>
                    233:         <font face='Arial,Helvetica,sans-serif'>
                    234: Please choose the CMS used to create your IMS content package.&nbsp;&nbsp;
                    235:         <select name="source">
1.16      albertel  236:          <option value='-1' selected="true">Please select</option>
                    237:          <option value='bb5'>Blackboard 5</option>
                    238:          <option value='bb6'>Blackboard 6</option>
                    239:          <option value='angel'>ANGEL</option>
1.17      raeburn   240:          <option value='webctce4'>WebCT 4 Campus Edition</option>
1.1       raeburn   241:         </select>
                    242:         </font>
                    243:        </td>
                    244:       </tr>
                    245:       <tr>
                    246:        <td colspan='2'>&nbsp;</td>
                    247:       </tr>
                    248:       <tr>
                    249:        <td colspan='2'>&nbsp;</td>
                    250:       </tr>
                    251:       <tr bgcolor='#CCCCFF'>
                    252:         <td valign='middle'><img src='/res/adm/pages/bl_step2.gif'>&nbsp;
                    253:         </td>
                    254:         <td width='100%' align='left'>&nbsp;&nbsp;
                    255:          <font face='arial,helvetica,sans-serif'><b>Locate the IMS content package you wish to upload.</b>&nbsp;&nbsp;
                    256:          </font>
                    257:        </td>
                    258:       </tr>
                    259:       <tr>
                    260:        <td colspan='2'>&nbsp;</td>
                    261:       </tr>
                    262:       <tr>
                    263:        <td colspan='2'>&nbsp;
1.12      albertel  264:         <input type="hidden" name="folder" value="$env{'form.folder'}" />
1.1       raeburn   265:         <input type="hidden" name="phase" value="two" />
                    266:         <input type="file" name="uploadname" size="40" />
                    267:        </td>
                    268:       </tr>
                    269:       <tr>
                    270:        <td colspan='2'>&nbsp;</td>
                    271:       </tr>
                    272:       <tr>
                    273:        <td>&nbsp;</td>
                    274:        <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>
                    275:       </tr>
                    276:       <tr>
                    277:        <td colspan='2'>&nbsp;</td>
                    278:       </tr>
                    279:       <tr
                    280:        <td colspan='2'>
                    281:         <table border='0' cellspacing='0' cellpadding='0' width="100%">
                    282:          <tr>
                    283:           <td align='left'>
1.16      albertel  284:            <input type="button" name="exitpage" value="Exit now" onClick="javascript:self.close()" />
1.1       raeburn   285:           </td>
                    286:           <td align='right'>
1.16      albertel  287:            <input type="button" name="nextpage" value="Upload IMS package" onClick="javascript:nextPage()" />
1.1       raeburn   288:           </td>
                    289:          </tr>
                    290:         </table>
                    291:        </td>
                    292:       </tr>
                    293:      </table>
                    294:     </td>
                    295:    </tr>
                    296:   </table>
                    297: </form>
                    298: ENDBLOCK
                    299: }
                    300: 
                    301: 
                    302: sub display_two {
1.3       raeburn   303:     my ($r,$crs,$areasref,$areaname,%cmsmap) = @_;
1.1       raeburn   304:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
1.12      albertel  305:     my $cms = $env{'form.source'};
1.2       raeburn   306:     my $timenow = time;
                    307:     my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
1.3       raeburn   308:     my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir);
1.1       raeburn   309:     my $unzip_result = '';
                    310:     my $manifest_result = '';
                    311:     unless ($tempdir eq '') {
                    312:         $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
                    313:     }
                    314:     my %resources = ();
1.9       raeburn   315:     my %includedres = ();
                    316:     my %includeditems = ();
1.1       raeburn   317:     my %items = ();
                    318:     my %hrefs = ();
1.2       raeburn   319:     my %resinfo = ();
1.1       raeburn   320:     my %count = ();
                    321:     my @bgcolors = ("#eeeeee","#dddddd");
                    322: 
                    323:     my $counter = 0;
                    324:     my $iter = 0;
                    325:     my %count = (
                    326:                 announce => 0,
                    327:                 board => 0,
                    328:                 doc => 0,
                    329:                 extlink => 0,
                    330:                 msg => 0,
                    331:                 pool => 0,
                    332:                 quiz => 0,
                    333:                 staff => 0,
                    334:                 survey => 0,
                    335:                 users => 0,
                    336:                 );
                    337: 
                    338:     if ($unzip_result eq 'ok') {
1.9       raeburn   339:         $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems);
1.1       raeburn   340:         if ($manifest_result eq 'ok') {
                    341:             foreach my $res (sort keys %resources) {
1.17      raeburn   342:                 if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') {
1.1       raeburn   343:                     foreach my $area (keys %{$cmsmap{$cms}}) {
                    344:                         if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
                    345:                             $count{$area} ++;
                    346:                         }
                    347:                     }
                    348:                 } elsif ($cms eq 'angel') {
                    349:                     foreach my $area (keys %{$cmsmap{$cms}}) {
                    350:                         if ($area eq 'doc') {
                    351:                             if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
                    352:                                 $count{$area} ++;
                    353:                             }
                    354:                         } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
                    355:                             $count{$area} ++;
                    356:                         }
                    357:                     }
                    358:                 }
                    359:             }
                    360:             $r->print(<<ENDBLOCK);
                    361: <form name="pickoptions" method="post">
                    362:   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
                    363:    <tr>
                    364:     <td colspan='2'>
                    365:      <table border='0' cellspacing='0' cellpadding='0'>
                    366:       <tr>
                    367:        <td colspan='2'  align='left'>&nbsp;
                    368:        </td>
                    369:       </tr>
                    370:       <tr bgcolor='#CCCCFF'>
                    371:        <td valign='middle'><img src='/res/adm/pages/bl_step3.gif'>
                    372:        </td>
                    373:        <td width='100%' align='left'>&nbsp;&nbsp;
                    374:         <font face='arial,helvetica,sans-serif'><b>Choose which content types you wish to import</b></font>
                    375:        </td>
                    376:       </tr>
                    377:       <tr>
                    378:        <td colspan='2'>&nbsp;</td>
                    379:       </tr>
                    380:       <tr>
                    381:        <td>&nbsp;</td>
                    382:        <td>
                    383:         <table border='0' cellspacing='0' cellpadding='1' bgcolor='#000000'>
                    384:          <tr>
                    385:           <td>
                    386:            <table border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' width='100%'>
                    387:             <tr>
                    388:              <td>
                    389:               <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width='100%'>
                    390:                <tr bgcolor='#CCCCFF'>
                    391:                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Import?</b></font></td>           
                    392:                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Content type</b></font></td>
                    393:                 <td align='center'><font face='arial,helvetica,sans-serif'><b>Additional options</b></font></td>
                    394:                </tr>
                    395: ENDBLOCK
                    396:             foreach my $area (@{$areasref}) {
                    397:                 if ($count{$area} > 0) {
                    398:                     my $count_tag = 'flag_'.$counter;
                    399:                     $r->print("               <tr bgcolor='@bgcolors[$iter]'>
                    400:                 <td align='left'><font face='arial,helvetica,sans-serif'><input name='$area' type='checkbox' ");
                    401:                     if ($area eq 'board' || $area eq 'users') {
                    402:                         $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|);
                    403:                     }
                    404:                     $r->print("/></font></td>
1.3       raeburn   405:                 <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;$$areaname{$area}&nbsp;&nbsp; - $count{$area} item(s)</font></td>");
1.1       raeburn   406:                     if ($area eq 'board') {
                    407:                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;
1.2       raeburn   408:                  <select name='db_handling'>
1.16      albertel  409:                   <option value='-2'>&lt;-- Check Import first</option>
1.1       raeburn   410:                  </select></font>
                    411:                 </td>");
                    412:                     } elsif ($area eq 'users') {
                    413:                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;
                    414:                  <select name='user_handling'>
1.16      albertel  415:                   <option value='-2'>&lt;-- Check Import first</option>
1.1       raeburn   416:                  </select>
                    417:                  </font>        
                    418:                 </td>");
                    419:                     } else {
                    420:                         $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;None<input type='hidden' name='$count_tag' /></font></td>");
                    421:                     }
                    422:                     $counter ++;
                    423:                     $iter = $counter%2;
                    424:                 }
                    425:             }
                    426:             $r->print(<<ENDDOCUMENT);
                    427:                </tr>
                    428:               </table>
                    429:              </td>
                    430:             </tr>
                    431:            </table>
                    432:           </td>
                    433:          </tr>
                    434:         </table>
                    435:        </td>
                    436:       </tr>
                    437:       <tr>
                    438:        <td colspan='2'>&nbsp;<br /><br /></td>
                    439:       </tr>
1.2       raeburn   440:       <tr bgcolor='#CCCCFF'>
                    441:        <td valign='middle'><img src='/res/adm/pages/bl_step4.gif'>
                    442:        </td>
                    443:        <td width='100%' align='left'>&nbsp;&nbsp;
                    444:         <font face='arial,helvetica,sans-serif'><b>Choose display options for listing of contents of top level of package.</b></font>
                    445:        </td>
                    446:       </tr>
                    447:       <tr>
                    448:        <td colspan='2'>&nbsp;</td>
                    449:       </tr>
1.1       raeburn   450:       <tr>
                    451:        <td>&nbsp;</td>
1.2       raeburn   452:        <td>
                    453:         <table border='0'>
                    454:          <tr>
1.16      albertel  455:           <td><font face='arial,helvetica,sans-serif'><label><input type="radio" name="toplevel" value="newfolder" />Display listing of contents in a new folder, with folder name:</label>&nbsp;&nbsp;&nbsp;<input type="text" name="foldername" size="15" value="Type Name Here" /></font></td>
1.2       raeburn   456:          </tr>
                    457:          <tr>
1.16      albertel  458:           <td><font face='arial,helvetica,sans-serif'><label><input type="radio" name="toplevel" value="oldfolder" />Append listing of contents of top level of package to contents list for the current folder.</label></font></td>
1.2       raeburn   459:          </tr>
                    460:         </table>
                    461:        </td>
                    462:       </tr>
                    463:       <tr>
                    464:        <td colspan='2'>&nbsp;</td>
                    465:       </tr>
                    466:       <tr>
                    467:        <td>&nbsp;</td>
                    468:        <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   469:       </tr>
                    470:       <tr>
                    471:        <td colspan='2'>&nbsp;
1.12      albertel  472:           <input type="hidden" name="folder" value="$env{'form.folder'}" />
1.1       raeburn   473:           <input type="hidden" name="source" value="$cms" />
                    474:           <input type="hidden" name="tempdir" value="$tempdir" />
                    475:           <input type="hidden" name="phase" value="three" />
                    476:        </td>
                    477:       </tr>
                    478:       <tr>
                    479:        <td colspan='2'>
                    480:         <table border='0' cellspacing='0' cellpadding='0' width="100%">
                    481:          <tr>
                    482:           <td align='left'>
1.16      albertel  483:            <input type='button' name='exitpage' value='Exit now' onClick="javascript:self.close()" />
1.1       raeburn   484:           </td>
                    485:           <td align='right'>
1.16      albertel  486:            <input type="button" name="nextpage" value="Complete Import" onClick="javascript:nextPage($counter)" />
1.1       raeburn   487:           </td>
                    488:          </tr>
                    489:         </table>
                    490:        </td>
                    491:       </tr>
                    492:      </table>
                    493:     </td>
                    494:    </tr>
                    495:   </table>
                    496: ENDDOCUMENT
                    497:         } else {
                    498:             $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n");
                    499:         }
                    500:     } else {
                    501:         $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n");
                    502:     }
                    503: }
                    504: 
                    505: 
                    506: sub display_three {
1.14      raeburn   507:     my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_;
1.12      albertel  508:     my $folder = $env{'form.folder'};
                    509:     my $cms = $env{'form.source'};
                    510:     my $tempdir = $env{'form.tempdir'};
1.2       raeburn   511:     my $longcrs = '';
                    512:     if ($crs =~ m/^(\d)(\d)(\d)/) {
                    513:         $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
                    514:     }
1.9       raeburn   515:     my %importareas = ();
                    516:     my %includedres = ();
                    517:     my %includeditems = ();
1.2       raeburn   518:     my @targets = ();
                    519:     my %resources = ();
                    520:     my %items = ();
                    521:     my %hrefs = ();
                    522:     my %urls = ();
                    523:     my %resinfo = ();
                    524:     my %total = (
                    525:                  page => 0,
                    526:                  prob => 0,
                    527:                  seq => 0,
                    528:                  board => 0,         
                    529:                  quiz => 0,
                    530:                  surv => 0,
                    531:                 );
                    532:     my @pages = ();
                    533:     my @sequences = ();
                    534:     my @resrcfiles = ();
                    535: 
                    536:     my $timenow = time;
                    537: 
                    538:     my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow;
                    539:     my $seqstem = "/uploaded/$cdom/$crs/$timenow";
                    540:     my $db_handling = '';
                    541:     my $user_handling = '';
                    542: 
                    543:     my $toplevel = '';
                    544:     my $foldername = '';
                    545:     my %topitems = ();
1.12      albertel  546:     if (defined($env{'form.toplevel'}) ) {
                    547:         $toplevel = $env{'form.toplevel'};     
1.2       raeburn   548:     }
1.12      albertel  549:     if (defined($env{'form.foldername'}) ) {
                    550:         $foldername = $env{'form.foldername'}; 
1.2       raeburn   551:     }
1.8       raeburn   552: 
1.2       raeburn   553:     foreach my $area (@{$areas}) {
1.12      albertel  554:         if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) {
1.2       raeburn   555:             if ($cms eq 'angel' && $area eq 'doc') {
                    556:                 foreach (@{$cmsmap{$cms}{$area}}) {
1.9       raeburn   557:                     $importareas{$_} = 1;
1.2       raeburn   558:                 }
                    559:             } else {
1.9       raeburn   560:                 $importareas{$cmsmap{$cms}{$area}} = 1;
1.2       raeburn   561:             }
                    562:             if ($area eq 'board') {
1.12      albertel  563:                 $db_handling = $env{'form.db_handling'};
1.2       raeburn   564:             } elsif ($area eq 'users') {
1.12      albertel  565:                 $user_handling = $env{'form.user_handling'};
1.2       raeburn   566:             }
                    567:         }
                    568:     }
1.9       raeburn   569: 
                    570:     my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems);
1.2       raeburn   571:     if ($manifest_result eq 'ok') {
1.9       raeburn   572:         foreach my $res (sort keys %resources) {
                    573:             if ($importareas{$resources{$res}{type}}) {
                    574:                 $includedres{$res} = 1;
                    575:             }
                    576:         }
                    577:         foreach my $itm (sort keys %items) {
                    578:             &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
                    579:         }
                    580:     }
                    581:     foreach my $itm (sort keys %includeditems) {
                    582:         &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
                    583:     }
                    584: 
                    585:     $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
                    586:     if ($manifest_result eq 'ok') {
                    587: 
1.5       raeburn   588:         my @path = ($cdom,$crs,$timenow);
                    589:         my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
                    590:         foreach my $item (@path) {
                    591:             $fullpath .= '/'.$item;
                    592:             if (!-e "$fullpath") {
                    593:                 mkdir("$fullpath",0770);
                    594:             }
                    595:         }
                    596:         my @namedirs = ("resfiles","sequences","pages","problems");
                    597:         foreach my $name (@namedirs) {
                    598:             if (!-e "$fullpath/$name") {
                    599:                 mkdir("$fullpath/$name",0770);
                    600:             }
                    601:         }
1.9       raeburn   602:         &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
1.2       raeburn   603: 
                    604:         my @boards = ();
                    605:         my @announcements = ();
                    606:         my @quizzes = ();
                    607:         my @surveys = ();
1.9       raeburn   608:         my @pools = ();
1.2       raeburn   609:         my @groups = ();
                    610:         my %messages = ();
                    611:         my @timestamp = ();
                    612:         my %boardnum = ();
                    613:         my @topurls = ();
                    614:         my @topnames = ();
1.7       raeburn   615:         my @packages = ();
1.2       raeburn   616: 
1.9       raeburn   617:         &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   618: 
1.14      raeburn   619:         my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
1.2       raeburn   620: 
1.9       raeburn   621:         &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   622: 
1.2       raeburn   623:         foreach my $item (@pages) {
1.3       raeburn   624:             my $filename = $timenow.'/pages/'.$item;
1.13      raeburn   625:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   626:         }
                    627:         foreach my $item (@sequences) {
                    628:             unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
1.3       raeburn   629:                 my $filename = $timenow.'/sequences/'.$item;
1.13      raeburn   630:                 my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   631:             }
                    632:         }
                    633:         foreach my $item (@resrcfiles) {
1.3       raeburn   634:             my $filename = $timenow.'/resfiles/'.$item;
1.13      raeburn   635:             my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2       raeburn   636:         }
                    637: 
                    638:         my @imports = ();
                    639:         if ($toplevel eq 'oldfolder') {
                    640:             for (my $i=0; $i<@topurls; $i++) {
1.18    ! www       641:                 my $url = &unescape($topurls[$i]);
        !           642:                 my $name = &unescape($topnames[$i]);
1.2       raeburn   643:                 push @imports, $name, $url;
                    644:             }
                    645:         } elsif ($toplevel eq 'newfolder') {
1.18    ! www       646:             my $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
        !           647:             my $name = &unescape("$env{'form.foldername'}");
1.2       raeburn   648:             push @imports, $name, $url;
                    649:         }
                    650:         my $errtext='';
                    651:         my $fatal=0;
                    652:         ($errtext,$fatal)=  &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
                    653:         if ($#Apache::lonratedt::order<1) {
                    654:             $Apache::lonratedt::order[0]=1;
                    655:             $Apache::lonratedt::resources[1]='';
                    656:         }
1.8       raeburn   657:         my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
1.2       raeburn   658:         if ($fatal) {
                    659:             print STDERR "Fatal error during group_import\n";
                    660:         }
                    661:     }
1.3       raeburn   662:     if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
                    663:         system("rm -r -f $tempdir");
                    664:     }
1.2       raeburn   665:     $r->print(<<ENDBLOCK);
                    666:   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
                    667:    <tr>
                    668:     <td colspan='2'>
                    669:      <table border='0' cellspacing='0' cellpadding='0'>
                    670:       <tr>
                    671:        <td colspan='2'  align='left'>&nbsp;
                    672:        </td>
                    673:       </tr>
                    674:       <tr bgcolor='#CCCCFF'>
                    675:        <td valign='middle'><img src='/res/adm/pages/bl_step5.gif'>
                    676:        </td>
                    677:        <td width='100%' align='left'>&nbsp;&nbsp;
                    678:         <font face='arial,helvetica,sans-serif'><b>Your import is complete</b></font>
                    679:        </td>
                    680:       </tr>
                    681:       <tr>
                    682:        <td colspan='2'>&nbsp;</td>
                    683:       </tr>
                    684:       <tr>
                    685:        <td>&nbsp;</td>
                    686:        <td>
                    687: ENDBLOCK
                    688:     my $initblock = qq|  
                    689:          <form method="post" action="/adm/roles" target="loncapaclient" name="importDone">
                    690:            <input type="hidden" name="orgurl" value="/adm/coursedocs" />
                    691:            <input type="hidden" name="selectrole" value="1" />
                    692:            <h3><font color="red">Changes will become active for your current session after
1.12      albertel  693:            <input type="hidden" name="$env{'request.role'}" value="1" />
1.2       raeburn   694:            <input type="button" value="|;
                    695:     $initblock .= &mt('re-initializing course');
1.16      albertel  696:     $initblock .= qq|" onClick="javascript:init(this.form)" />|;
1.8       raeburn   697:     $initblock .= ', '.&mt('or the next time you log in.');
1.2       raeburn   698:     $initblock .= qq|</font></h3></form>|;  
                    699:     $r->print($initblock);
                    700:     $r->print(<<ENDBLOCKTWO);
                    701:      </table>
                    702:     </td>
                    703:    </tr>
                    704:   </table>
                    705: ENDBLOCKTWO
1.1       raeburn   706: }
                    707: 
                    708: 1;
                    709: __END__

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