Diff for /loncom/imspackages/imsexport.pm between versions 1.8 and 1.12

version 1.8, 2012/01/29 19:51:01 version 1.12, 2014/12/11 00:33:22
Line 32  use Apache::lonnet; Line 32  use Apache::lonnet;
 use Apache::loncommon;  use Apache::loncommon;
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
 use Apache::lonnavmaps;  use Apache::lonnavmaps;
   use Apache::loncourserespicker;
   use Apache::londocs;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Cwd;  use Cwd;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
Line 39  use LONCAPA qw(:DEFAULT :match); Line 41  use LONCAPA qw(:DEFAULT :match);
 sub exportcourse {  sub exportcourse {
     my $r=shift;      my $r=shift;
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
     my %discussiontime = &Apache::lonnet::dump('discussiontimes',      my ($navmap,$errormsg) = 
                                                $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});          &Apache::loncourserespicker::get_navmap_object($crstype,'imsexport'); 
     my $numdisc = keys(%discussiontime);      unless (ref($navmap)) {
     my $numprobs = 0;          $r->print($errormsg);
     my $navmap = Apache::lonnavmaps::navmap->new();  
     if (!defined($navmap)) {  
         $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').  
                   '<h2>'.&mt('IMS Export Failed').'</h2>'.  
                   '<div class="LC_error">');  
         if ($crstype eq 'Community') {  
             $r->print(&mt('Unable to retrieve information about community contents'));  
         } else {  
             $r->print(&mt('Unable to retrieve information about course contents'));  
         }  
         $r->print('</div><a href="/adm/coursedocs">');  
         if ($crstype eq 'Community') {  
             $r->print(&mt('Return to Community Editor'));  
         } else {  
             $r->print(&mt('Return to Course Editor'));  
         }  
         $r->print('</a>');  
         &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});  
         return;          return;
     }      }
     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);  
     my $curRes;  
     my $outcome;  
   
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['finishexport']);                                              ['finishexport']);
     if ($env{'form.finishexport'}) {      if ($env{'form.finishexport'}) {
         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['archive','discussion']);                                              ['archive','discussion']);
           my $outcome; 
         my $format = $env{'form.format'};          my $format = $env{'form.format'};
         my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');          my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
         my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');          my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
Line 135  sub exportcourse { Line 115  sub exportcourse {
         }          }
         $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'));          $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'));
         $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));          $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
           $r->print(&Apache::londocs::startContentScreen('tools')); 
         $r->print($outcome);          $r->print($outcome);
           $r->print(&Apache::londocs::endContentScreen());
         $r->print(&Apache::loncommon::end_page());          $r->print(&Apache::loncommon::end_page());
     } else {      } else {
         my $display='<form name="exportdoc" action="" method="post">'."\n".          $r->print(&Apache::loncourserespicker::create_picker($navmap,'imsexport',
                     '<p>'.                                                               'exportdoc',$crstype));
                     &mt('Choose which items you wish to export from your '.$crstype.'.').  
                     '</p>'.  
                     '<div class="LC_columnSection"><fieldset>'.  
                     '<legend>'.&mt('Content items').'</legend>'.  
                     '<input type="button" value="'.&mt('check all').'" '.  
                     'onclick="javascript:checkAll(document.exportdoc.archive)" />'.  
                     '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.  
                     ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset>';  
         if ($numdisc > 0) {  
             $display .= '<fieldset>'.  
                         '<legend>'.&mt('Discussion posts').'</legend>'.  
                         '<input type="button" value="'.&mt('check all').'"'.  
                         ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.  
                         '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.  
                         ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" />'.  
                         '</fieldset>';  
         }  
         $display .= '</div>';  
         my $curRes;  
         my $depth = 0;  
         my $count = 0;  
         my $boards = 0;  
         my $startcount = 5;  
         my %parent = ();  
         my %children = ();  
         my $lastcontainer = $startcount;  
         $display .= &Apache::loncommon::start_data_table()  
                    .&Apache::loncommon::start_data_table_header_row()  
                    .'<th>'.&mt('Export content item?').'</th>';  
         if ($numdisc > 0) {  
             $display .= '<th>'.&mt('Export discussion posts?').'</th>';  
         }  
         $display .= &Apache::loncommon::end_data_table_header_row();  
         while ($curRes = $it->next()) {  
             if (ref($curRes)) {  
                 $count ++;  
             }  
             if ($curRes == $it->BEGIN_MAP()) {  
                 $depth++;  
                 $parent{$depth} = $lastcontainer;  
             }  
             if ($curRes == $it->END_MAP()) {  
                 $depth--;  
                 $lastcontainer = $parent{$depth};  
             }  
             if (ref($curRes)) {  
                 my $symb = $curRes->symb();  
                 my $ressymb = $symb;  
                 if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {  
                     unless ($ressymb =~ m|adm/wrapper/adm|) {  
                         $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';  
                     }  
                 }  
                 my $currelem = $count+$boards+$startcount;  
                 $display .= &Apache::loncommon::start_data_table_row()  
                            .'<td>'."\n"  
                            .'<input type="checkbox" name="archive" value="'.$count.'" ';  
                 if (($curRes->is_sequence()) || ($curRes->is_page())) {  
                     $lastcontainer = $currelem;  
                     $display .= 'onclick="javascript:propagateCheck(this.form,'."'$currelem'".')"';  
                 } elsif ($curRes->is_problem()) {  
                     $numprobs ++;  
                 }  
                 $display .= ' />'."\n";  
                 for (my $i=0; $i<$depth; $i++) {  
                     $display .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";  
                 }  
                 if ($curRes->is_sequence()) {  
                     $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n";  
                 } elsif ($curRes->is_page()) {  
                     $display .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />&nbsp;'."\n";  
                 }  
                 $children{$parent{$depth}} .= $currelem.':';  
                 $display .= '&nbsp;'.$curRes->title().'</td>'."\n";  
   
                 # Existing discussion posts?  
                 if ($discussiontime{$ressymb} > 0) {  
                     $boards ++;  
                     $display .= '<td align="right">'  
                                .'<input type="checkbox" name="discussion" value="'.$count.'" />'  
                                .'</td>'."\n";  
                 } elsif ($numdisc > 0) {  
                     $display .= '<td>&nbsp;</td>'."\n";  
                 }  
                 $display .= &Apache::loncommon::end_data_table_row();  
             }  
         }  
         $display .= &Apache::loncommon::end_data_table();  
         my $numcount = $count + $boards + $startcount;  
         my $scripttag = &export_javascript($startcount,$numcount,%children);  
         $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package',  
                                                  $scripttag));  
         $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));  
         if ($numprobs > 0) {  
             $display .= '<p><span class="LC_nobreak">'.  
                         &mt('Export format for LON-CAPA problems:').  
                         '<label><input type="radio" name="format" value="xml" checked="checked" />'.  
                         '&nbsp;'.&mt('XML').'</label>'.('&nbsp;' x3).  
                         '<label><input type="radio" name="format" value="html" />'.  
                         '&nbsp;'.&mt('HTML').'</label>'.('&nbsp;' x3).  
                         '<label><input type="radio" name="format" value="plaintext" />'.  
                         '&nbsp;'.&mt('Text').'</label></span></p>';  
         }  
         $r->print($display.  
                   '<p><input type="hidden" name="finishexport" value="1" />'.  
                   '<input type="submit" name="exportcourse" value="'.  
                   &mt('Export').'" /></p></form>');  
     }  
 }  
   
 sub export_javascript {  
     my ($startcount,$numitems,%children) = @_;  
     my $scripttag = <<"START";  
 <script type="text/javascript">  
 // <![CDATA[  
 function checkAll(field) {  
     if (field.length > 0) {  
         for (i = 0; i < field.length; i++) {  
             field[i].checked = true ;  
         }  
     } else {  
         field.checked = true  
     }  
 }  
   
 function uncheckAll(field) {  
     if (field.length > 0) {  
         for (i = 0; i < field.length; i++) {  
             field[i].checked = false ;  
         }  
     } else {  
         field.checked = false ;  
     }      }
 }      return;
   
 function propagateCheck(form,item) {  
     if (form.elements[item].checked == true) {  
         containerCheck(form,item)  
     }  
 }  
   
 numitems = $numitems  
 var parents = new Array(numitems)  
 for (var i=$startcount; i<numitems; i++) {  
     parents[i] = new Array  
 }  
   
 START  
   
     foreach my $container (sort { $a <=> $b } (keys(%children))) {  
         my @contents = split(/:/,$children{$container});  
         for (my $i=0; $i<@contents; $i ++) {  
             $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";  
         }  
     }  
   
     $scripttag .= <<"END";  
   
 function containerCheck(form,item) {  
     form.elements[item].checked = true;  
     if(Object.prototype.toString.call(parents[item]) === '[object Array]') {  
         if (parents[item].length > 0) {  
             for (var j=0; j<parents[item].length; j++) {  
                 containerCheck(form,parents[item][j])  
             }  
         }  
     }  
 }  
 // ]]>  
 </script>  
   
 END  
     return $scripttag;  
 }  }
   
 sub create_ims_store {  sub create_ims_store {
Line 862  sub simpleproblem  { Line 673  sub simpleproblem  {
                 %values = &evaloptionhash($options);                  %values = &evaloptionhash($options);
                 $output .= qq|                  $output .= qq|
 <problem>  <problem>
     <startouttext />$qtext<endouttext />
   <optionresponse max="$maxfoils" randomize="$randomize">    <optionresponse max="$maxfoils" randomize="$randomize">
     <foilgroup options="$options">      <foilgroup options="$options">
 |;  |;
Line 890  sub simpleproblem  { Line 702  sub simpleproblem  {
             } else {              } else {
                 $output .= qq|                  $output .= qq|
 <problem>  <problem>
     <startouttext />$qtext<endouttext />
   <radiobuttonresponse max="$maxfoils" randomize="$randomize">    <radiobuttonresponse max="$maxfoils" randomize="$randomize">
    <foilgroup>    <foilgroup>
 |;  |;
                 for (my $k=0; $k<10; $k++) {                  for (my $k=0; $k<10; $k++) {
                     my $iter = $k+1;                      my $iter = $k+1;
Line 916  sub simpleproblem  { Line 729  sub simpleproblem  {
 </problem>  </problem>
 |;  |;
             }              }
         } elsif ($qtype eq 'stringanswer') {          } elsif ($qtype eq 'string') {
             my $stringanswer = $qparms{$prefix.'stringanswer'};              my $stringanswer = $qparms{$prefix.'stringanswer'};
             my $stringtype=$qparms{$prefix.'stringtype'};              my $stringtype=$qparms{$prefix.'stringtype'};
             $output .= qq|              $output .= qq|
 <problem>  <problem>
   <stringresponse answer="$stringanswer" type="$stringtype">    <stringresponse answer="$stringanswer" type="$stringtype">
     <textline>    <startouttext />$qtext<endouttext />
     </textline>      <textline />
             |;              |;
             if ($hint) {              if ($hint) {
                 $output .= '                  $output .= '
Line 937  sub simpleproblem  { Line 750  sub simpleproblem  {
   </stringresponse>    </stringresponse>
 </problem>  </problem>
 |;  |;
           } elsif ($qtype eq 'numerical') {
               my $sigfigs = $qparms{$prefix.'numericalsigfigs'};
               my $unit = $qparms{$prefix.'numericalunit'};
               my $answer = $qparms{$prefix.'numericalanswer'};
               my $tolerance = $qparms{$prefix.'numericaltolerance'};
               my $format = $qparms{$prefix.'numericalformat'};
               my $scriptblock = $qparms{$prefix.'numericalscript'};
               $output .= qq|
   <problem>
   |;
               if ($scriptblock) {
                   $output .= qq|
   <script type="loncapa/perl">
   $scriptblock
   </script>|;
                }
                $output .= qq|
   <startouttext />$qtext<endouttext />
   <numericalresponse answer="$answer" |;
                if ($unit ne '') {
                    $output .= qq|unit="$unit" |;
                }
                if ($format ne '') {
                    $output .= qq|format="$format" |;
                }
                $output =~ s{ $}{};
                $output .= '>';
                if ($tolerance ne '') {
                    $output .= qq|
     <responseparam name="tol" type="tolerance" default="$tolerance" description="Numerical Tolerance" />|;
                }
                if ($sigfigs) {
                    $output .= qq|
     <responseparam name="sig" type="int_range" default="$sigfigs" description="Significant Digits" />|;
                }
                $output .= qq|
     <textline />|;
               if ($hint) {
                   $output .= qq|
     <hintgroup>
       <hintpart on="default">
         <startouttext />'.$hint.'<endouttext/>
       </hintpart>
     </hintgroup>|;
               }
               $output .= qq|
   </numericalresponse>
   </problem>
   |;
         } else {          } else {
             $output .= qq|              $output .= qq|
 <problem>  <problem>
Line 1035  sub templatedpage { Line 897  sub templatedpage {
   <domain>$udom</domain>    <domain>$udom</domain>
 |;  |;
     }      }
     foreach (sort keys %syllabusfields) {      foreach (sort(keys(%syllabusfields))) {
         $output .= qq|          $output .= qq|
 <$_>  <$_>
  <name>$syllabusfields{$_}</name>   <name>$syllabusfields{$_}</name>
Line 1075  described at http://www.lon-capa.org. Line 937  described at http://www.lon-capa.org.
   
 =item exportcourse()  =item exportcourse()
   
 =item export_javascript()  
   
 =item create_ims_store()  =item create_ims_store()
   
 =item build_package()  =item build_package()

Removed from v.1.8  
changed lines
  Added in v.1.12


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