Diff for /loncom/interface/lonexttool.pm between versions 1.2 and 1.3

version 1.2, 2016/01/25 20:13:02 version 1.3, 2016/01/26 14:30:25
Line 74  sub handler { Line 74  sub handler {
         return OK;          return OK;
     }      }
   
     my $marker = (split(m{/},$r->uri))[4];      my ($marker,$exttool) = (split(m{/},$r->uri))[4,5];
     $marker=~s/\D//g;      $marker=~s/\D//g;
   
     if (!$marker) {      if (!$marker) {
         if ($target ne 'tex') {          if ($target ne 'tex') {
             &Apache::loncommon::simple_error_page($r,'Invalid Call',              $r->print(&mt('Invalid Call'));
                                                   'Invalid Call');  
         } else {          } else {
             $r->print('\textbf{Invalid call}\end{document}');              $r->print('\textbf{'&mt('Invalid Call').'}\end{document}');
         }          }
         return OK;          return OK;
     }      }
Line 90  sub handler { Line 89  sub handler {
     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};      my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};      my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};      my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
       my $is_tool;
   
     if ($r->uri eq "/adm/$cdom/$cnum/$marker/exttool") {      if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {
         my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);          my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
         if ($target eq 'tex') {          if ($toolsettings{'id'}) {
             $r->print(&mt('External Tool'));              my %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
         } else {              if (ref($ltitools{$toolsettings{'id'}}) eq 'HASH') {
             if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && ($toolhash{'url'} ne '')) {                  my %toolhash = %{$ltitools{$toolsettings{'id'}}}; 
                 my %lti = &lti_params($r,\%toolhash);                  $toolhash{'display'} = {
                 $r->print(&launch_html($toolhash{'url'},$toolhash{'key'},                                             target => $toolsettings{'target'},
                                        $toolhash{'secret'},$toolhash{'title'},\%lti));                                             width  => $toolsettings{'width'},
             } else {                                             height => $toolsettings{'height'},
                 &Apache::loncommon::simple_error_page($r,'External Tool Unavailable',                                         };
                                                       'External Tool Unavailable');                  $is_tool = 1;
                   if ($target eq 'tex') {
                       $r->print(&mt('External Tool'));
                   } else {
                       my $submittext = &mt('Launch [_1]',$toolhash{'title'});
                       if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && ($toolhash{'url'} ne '')) {
                           my %lti = &lti_params($r,$submittext,\%toolhash);
                           $r->print(&launch_html($toolhash{'url'},$toolhash{'key'},
                                                  $toolhash{'secret'},$submittext,\%lti));
                       } else {
                           $r->print('<div>'.&mt('External Tool Unavailable').'</div>');
                       }
                   }
             }              }
         }          }
     } else {      }
       unless ($is_tool) {
         if ($target ne 'tex') {          if ($target ne 'tex') {
             &Apache::loncommon::simple_error_page($r,'Invalid Call',              $r->print('<div>'.&mt('Invalid Call').'</div>');
                                                   'Invalid Call');  
         } else {          } else {
             $r->print('\textbf{Invalid call}\end{document}');              $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');
         }          }
         return OK;  
     }      }
   
     &print_end_page($r,$target);  
     return OK;      return OK;
 }  }
   
 sub print_end_page {  
     my ($r,$target) = @_;  
     if ($target ne 'tex') {  
         $r->print(&Apache::loncommon::end_page());  
     } else {  
         $r->print('\end{document}');  
     }  
 }  
   
 sub lti_params {  sub lti_params {
     my ($r,$toolsref) = @_;      my ($r,$submittext,$toolsref) = @_;
     my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,      my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
         %fields,%rolesmap,%display,%custom,@userlangs);          %fields,%rolesmap,%display,%custom,@userlangs);
     if (ref($toolsref) eq 'HASH') {      if (ref($toolsref) eq 'HASH') {
Line 165  sub lti_params { Line 165  sub lti_params {
     my $uname = $env{'user.name'};      my $uname = $env{'user.name'};
     my $udom = $env{'user.domain'};      my $udom = $env{'user.domain'};
     my @possroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);      my @possroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
     my $ltirole = $rolesmap{$env{'request.role'}};      my ($roleprefix) = ($env{'request.role'} =~ /^(\w+)\./);
       my $ltirole = $rolesmap{$roleprefix};
     unless (grep(/^\Q$ltirole\E$/,@possroles)) {      unless (grep(/^\Q$ltirole\E$/,@possroles)) {
         $ltirole = 'Learner';          $ltirole = 'Learner';
     }      }
Line 218  sub lti_params { Line 219  sub lti_params {
         context_title                          => $env{'course.'.$env{'request.course.id'}.'.description'},          context_title                          => $env{'course.'.$env{'request.course.id'}.'.description'},
         launch_presentation_locale             => $locale,          launch_presentation_locale             => $locale,
     );      );
     my $crshostname = $env{'course.'.$env{'request.course.id'}.'.home'};      my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
     my $crsprotocol = $Apache::lonnet::protocol{$crshostname};      my $crshostname = &Apache::lonnet::hostname($crshome);
     if ($crshostname) {      if ($crshostname) {
         my $crsprotocol = $Apache::lonnet::protocol{$crshostname};          my $crsprotocol = $Apache::lonnet::protocol{$crshome};
         unless ($crsprotocol eq 'https') {          unless ($crsprotocol eq 'https') {
             $crsprotocol = 'http';              $crsprotocol = 'http';
         }           } 
Line 260  sub lti_params { Line 261  sub lti_params {
     if ($fields{'email'}) {      if ($fields{'email'}) {
         my %emails = &Apache::loncommon::getemails($uname,$udom);          my %emails = &Apache::loncommon::getemails($uname,$udom);
         my $contact_email;          my $contact_email;
         foreach my $email ('permanentemail','critnotification','notification') {          foreach my $type ('permanentemail','critnotification','notification') {
             if ($email =~ /\@/) {              if ($emails{$type} =~ /\@/) {
                 $contact_email = $email;                  $contact_email = $emails{$type};
                 last;                  last;
             }              }
         }          }
Line 276  sub lti_params { Line 277  sub lti_params {
     foreach my $key (keys(%ltiparams)) {      foreach my $key (keys(%ltiparams)) {
         $ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});          $ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});
     }      }
       $ltiparams{'basiclti_submit'} = $submittext;
     return %ltiparams;      return %ltiparams;
 }  }
   
 sub launch_html {  sub launch_html {
     my ($url,$key,$secret,$toolname,$paramsref) = @_;      my ($url,$key,$secret,$submittext,$paramsref) = @_;
     my $hashref = &sign_params($url,$key,$secret,$paramsref);      my $hashref = &sign_params($url,$key,$secret,$paramsref);
     my $submittext = &mt('Launch [_1]',$toolname);  
     my $form = <<"END";      my $form = <<"END";
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <body>  <body>
 <div id="LCltiLaunch">  <div id="LCltiLaunch">
 <form name="LCltiLaunchForm" action="$url" method="post" encType="application/x-www-form-urlencoded">  <form name="LCltiLaunchForm" id="LCltiLaunchFormId" action="$url" method="post" encType="application/x-www-form-urlencoded">
 <input type="submit" name="LCbasicltiSubmit" value="$submittext" />  
 END  END
     if (ref($hashref) eq 'HASH') {      if (ref($hashref) eq 'HASH') {
         foreach my $item (keys(%{$hashref})) {          foreach my $item (keys(%{$hashref})) {
             $form .= '<input type="hidden" name="'.$item.'" value="'.$hashref->{$item}.'" id="id_'.$item.'" />'."\n";              my $type = 'hidden';
               if ($item eq 'basiclti_submit') {
                   $type = 'submit';
               }
               $form .= '<input type="'.$type.'" name="'.$item.'" value="'.$hashref->{$item}.'" id="id_'.$item.'" />'."\n";
         }          }
     }      }
     $form .= "</form></div>\n";      $form .= "</form></div>\n";
Line 302  END Line 306  END
     document.getElementById("LCltiLaunch").style.display = "none";      document.getElementById("LCltiLaunch").style.display = "none";
     nei = document.createElement('input');      nei = document.createElement('input');
     nei.setAttribute('type','hidden');      nei.setAttribute('type','hidden');
     nei.setAttribute('name','LCbasicltiSubmit');      nei.setAttribute('name','basiclti_submit');
     nei.setAttribute('value','$submittext');      nei.setAttribute('value','$submittext');
     document.getElementById("LCltiLaunchForm").appendChild(nei);      document.getElementById("LCltiLaunchFormId").appendChild(nei);
     document.LCltiLaunchForm.submit();      document.LCltiLaunchForm.submit();
  </script>   </script>
 ENDJS  ENDJS

Removed from v.1.2  
changed lines
  Added in v.1.3


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