[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm londocs.pm lonextresedit.pm lonexttool.pm

raeburn raeburn at source.lon-capa.org
Mon Jun 6 13:40:48 EDT 2016


raeburn		Mon Jun  6 17:40:48 2016 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm londocs.pm lonextresedit.pm 
                     	lonexttool.pm 
  Log:
  - Bug 6754. Make LON-CAPA an LTI Tool Consumer (LTI 1.1).
    - Domain cofiguration to determine whether context_label, context_title,
      and launch_presentation_document_target LTI parameters can be configured
      for each instance of use of LTI Tool in a course.  
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.272 loncom/interface/domainprefs.pm:1.273
--- loncom/interface/domainprefs.pm:1.272	Mon Apr  4 01:09:47 2016
+++ loncom/interface/domainprefs.pm	Mon Jun  6 17:40:47 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.272 2016/04/04 01:09:47 raeburn Exp $
+# $Id: domainprefs.pm,v 1.273 2016/06/06 17:40:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3154,7 +3154,24 @@
                 }
                 $datatable .= '</select></td>';
             }
-            $datatable .= '</tr></table></fieldset>'.
+            $datatable .= '</tr></table></fieldset>';
+            my %courseconfig;
+            if (ref($settings->{$item}) eq 'HASH') {
+                if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
+                    %courseconfig = %{$settings->{$item}->{'crsconf'}};
+                }
+            }
+            $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
+            foreach my $item ('label','title','target') {
+                my $checked;
+                if ($courseconfig{$item}) {
+                    $checked = ' checked="checked"';
+                }
+                $datatable .= '<label>'.
+                       '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
+                       $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
+            }
+            $datatable .= '</span></fieldset>'.
                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
@@ -3260,6 +3277,13 @@
         $datatable .= '</select></td>';
     }
     $datatable .= '</tr></table></fieldset>'.
+                  '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
+    foreach my $item ('label','title','target') {
+         $datatable .= '<label>'.
+                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
+                       $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
+    }
+    $datatable .= '</span></fieldset>'.
                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   '<tr><td><span class="LC_nobreak">'.
@@ -3294,6 +3318,9 @@
                                           'width'     => 'Width',
                                           'passback'  => 'Tool can return grades:',
                                           'roster'    => 'Tool can retrieve roster:',
+                                          'crstarget' => 'Display target',
+                                          'crslabel'  => 'Course label',
+                                          'crstitle'  => 'Course title', 
                                         );
     return %lt;
 }
@@ -8435,6 +8462,10 @@
                     }
                 }
             }
+            my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
+            foreach my $item (@courseconfig) {
+                $confhash{$newid}{'crsconf'}{$item} = 1;
+            }
             if ($env{'form.ltitools_add_custom'}) {
                 my $name = $env{'form.ltitools_add_custom_name'};
                 my $value = $env{'form.ltitools_add_custom_value'};
@@ -8522,6 +8553,19 @@
                             $changes{$itemid} = 1;
                         }
                     }
+                    my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
+                    foreach my $item ('label','title','target') {
+                        if (grep(/^\Q$item\E$/, at courseconfig)) {
+                            $confhash{$itemid}{'crsconf'}{$item} = 1;
+                            if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
+                                if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
+                                    $changes{$itemid} = 1;
+                                }
+                            } else {
+                                $changes{$itemid} = 1;
+                            }
+                        }
+                    }
                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                     foreach my $field (@fields) {
                         if ($possfield{$field}) {
@@ -8685,6 +8729,21 @@
                         my $num = length($confhash{$itemid}{'secret'});
                         $resulttext .= ('*'x$num).'</li>';
                     }
+                    $resulttext .= '<li>'.&mt('Configurable in course:');
+                    my @possconfig = ('label','title','target');
+                    my $numconfig = 0; 
+                    if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
+                        foreach my $item (@possconfig) {
+                            if ($confhash{$itemid}{'crsconf'}{$item}) {
+                                $numconfig ++;
+                                $resulttext .= ' '.$lt{'crs'.$item};
+                            }
+                        }
+                    }
+                    if (!$numconfig) {
+                        $resulttext .= &mt('None');
+                    }
+                    $resulttext .= '</li>';
                     foreach my $item ('passback','roster') {
                         $resulttext .= '<li>'.$lt{$item}.' ';
                         if ($confhash{$itemid}{$item}) {
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.603 loncom/interface/londocs.pm:1.604
--- loncom/interface/londocs.pm:1.603	Mon May  9 02:25:33 2016
+++ loncom/interface/londocs.pm	Mon Jun  6 17:40:48 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.603 2016/05/09 02:25:33 raeburn Exp $
+# $Id: londocs.pm,v 1.604 2016/06/06 17:40:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -619,32 +619,82 @@
                 $url = $1;
                 my $marker = $2;
                 my $info = $3;
-                my ($toolid,%toolhash);
+                my ($toolid,%toolhash,%toolsettings);
                 my @toolinfo = split(/:/,$info);
                 if ($residx) {
-                    my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
+                    %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                     $toolid = $toolsettings{'id'};
                 } else {
-                    $toolid = shift(@toolinfo);  
+                    $toolid = shift(@toolinfo);
                 }
                 $toolid =~ s/\D//g;
-                ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}) = @toolinfo;
+                ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
+                 $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
+                $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
+                $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
                 if (ref($ltitoolsref) eq 'HASH') {
+                    my @deleted;
                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
                         if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
                             $url =~ s/exttool$/exttools/;
                         }
                         $toolhash{'id'} = $toolid;
+                        if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
+                            if ($toolhash{'target'} eq 'window') {
+                                foreach my $item ('width','height') {
+                                    $toolhash{$item} =~ s/^\s+//;
+                                    $toolhash{$item} =~ s/\s+$//;
+                                }
+                            }
+                        } elsif ($residx) {
+                            $toolhash{'target'} = $toolsettings{'target'};
+                            if ($toolhash{'target'} eq 'window') {
+                                $toolhash{'width'} = $toolsettings{'width'};
+                                $toolhash{'height'} = $toolsettings{'height'};  
+                            }
+                        } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
+                            $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
+                            if ($toolhash{'target'} eq 'window') {
+                                $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
+                                $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
+                            }
+                        }
                         if ($toolhash{'target'} eq 'iframe') {
                             delete($toolhash{'width'});
                             delete($toolhash{'height'});
-                        } elsif ($toolhash{'target'} eq 'window') {
-                            foreach my $item ('width','height') {
-                                $toolhash{$item} =~ s/^\s+//;
-                                $toolhash{$item} =~ s/\s+$//;
+                            if ($residx) {
+                                if ($toolsettings{'width'}) {
+                                    push(@deleted,'width');
+                                }
+                                if ($toolsettings{'height'}) {
+                                    push(@deleted,'height');
+                                }
+                            }
+                        }
+                        if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
+                            foreach my $item ('label','title') { 
+                                if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
+                                    $toolhash{'crs'.$item} =~ s/^\s+//;
+                                    $toolhash{'crs'.$item} =~ s/\s+$//;
+                                    if ($toolhash{'crs'.$item} eq '') {
+                                        delete($toolhash{'crs'.$item});
+                                    }
+                                } else {
+                                    delete($toolhash{'crs'.$item});
+                                }
+                                if (($residx) && (exists($toolsettings{'crs'.$item}))) {
+                                    unless (exists($toolhash{'crs'.$item})) {
+                                        push(@deleted,'crs'.$item);
+                                    }
+                                }
                             }
                         }
                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
+                        if ($putres eq 'ok') {
+                            if (@deleted) {
+                                &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
+                            } 
+                        }
                     }
                 }
             }
@@ -4999,7 +5049,6 @@
             my $tabidstr = join("','", at tabids);
             %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
             my $posslti = keys(%ltitools);
-            my $exttoolurl = "/adm/$coursedom/$coursenum/new/exttool";
 	    $script .= &editing_js($udom,$uname,$supplementalflag,$posslti).
                        &history_tab_js().
                        &inject_data_js().
@@ -5451,7 +5500,7 @@
         $help{'Web_Page'}
         </form>
 NWEBFORM
- 
+
 
 my $specialdocumentsform;
 my @specialdocumentsforma;
@@ -6109,7 +6158,7 @@
                                           p_msb => 'Title for the Problem',
                                           p_mdb => 'Title for the Drop Box',
                                           p_mbb => 'Title for the Discussion Board',
-                                          p_mwp => 'Title for Web Page', 
+                                          p_mwp => 'Title for Web Page',
                                           p_mab => "Enter user:domain for User's Personal Information Page",
                                           p_mab2 => 'Personal Information Page of ',
                                           p_mab_alrt1 => 'Not a valid user:domain',
Index: loncom/interface/lonextresedit.pm
diff -u loncom/interface/lonextresedit.pm:1.9 loncom/interface/lonextresedit.pm:1.10
--- loncom/interface/lonextresedit.pm:1.9	Tue Jan 26 14:30:25 2016
+++ loncom/interface/lonextresedit.pm	Mon Jun  6 17:40:48 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: lonextresedit.pm,v 1.9 2016/01/26 14:30:25 raeburn Exp $
+# $Id: lonextresedit.pm,v 1.10 2016/06/06 17:40:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -259,32 +259,44 @@
 sub update_exttool {
     my ($marker,$cdom,$cnum,$args) = @_;
     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
-    my (%newhash,$changed,$errormsg);
-    ($newhash{'target'},$newhash{'width'},$newhash{'height'}) = split(/:/,$args);
+    my (%newhash,$changed, at deleted,$errormsg);
+    ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'crslabel'},$newhash{'crstitle'}) = split(/:/,$args);
+    $newhash{'crslabel'} = &unescape($newhash{'crslabel'});
+    $newhash{'crstitle'} = &unescape($newhash{'crstitle'});
     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
-    foreach my $item ('target','width','height') {
+    foreach my $item ('target','width','height','crslabel','crstitle') {
         $newhash{$item} =~ s/^\s+//;
         $newhash{$item} =~ s/\s+$//;
-        unless ($item eq 'target') {
+        if (($item eq 'width') || ($item eq 'height')) {
             if ($newhash{'target'} eq 'iframe') {
                 $newhash{$item} = '';
             }
         }
         if ($toolhash{$item} ne $newhash{$item}) {
             if ($newhash{$item} eq '') {
-                delete($toolhash{$item});
+                unless (($item eq 'target') ||
+                        ((($item eq 'width') || ($item eq 'height')) &&
+                         (($newhash{'target'} eq 'window') || 
+                          (($newhash{'target'} eq '') && ($toolhash{'target'} eq 'window'))))) {
+                    delete($toolhash{$item});
+                    push(@deleted,$item);
+                    $changed = 1;
+                }
             } else {
                 $toolhash{$item} = $newhash{$item};
+                $changed = 1; 
             }
-            $changed = 1;
         }
     }
     if ($changed) {
         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum);
         unless ($putres eq 'ok') {
-             $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
+            $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
         }
     }
+    if (@deleted) {
+        &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
+    }
     return ($changed,$errormsg);
 }
 
@@ -313,14 +325,17 @@
         $tabid = 'ee';
     }
     my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle,
-        $legend,$urlelem,$toolelem,%toolattr);
+        $labelstyle,$titlestyle,$legend,$urlelem,$toolelem,%toolattr);
     $formname = 'new'.$type;
     $toggle = $type;
     $fieldsetid = 'upload'.$type.'form';
     $urlid = $type.'url';
-    map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight');
+    map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
+                                       'crstitlediv','crslabeldiv','crstitle','crslabel');
     $dispdivstyle = 'display:none';
     $dimendivstyle = 'display:none';
+    $labelstyle = 'display:none';
+    $titlestyle = 'display:none';
     if ($supplementalflag) {
         $formname = 'newsupp'.$type;
         $toggle = 'supp'.$type;
@@ -328,7 +343,7 @@
         $urlid = 'supp'.$type.'url';
         map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
     }
-    my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,
+    my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
         $fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,%chkstate);
     $fieldsetstyle = 'display: none;';
     $action = '/adm/coursedocs';
@@ -404,7 +419,6 @@
                 my $marker = $1;
                 my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
                 if ($toolhash{'id'}) {
-                    $dispdivstyle = 'display:block';
                     if (ref($ltitools) eq 'HASH') {
                         if (keys(%{$ltitools})) {
                             if (ref($ltitools->{$toolhash{'id'}}) eq 'HASH') {
@@ -423,6 +437,19 @@
                                 }
                                 $width = $toolhash{'width'};
                                 $height = $toolhash{'height'};
+                                if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') {
+                                    if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) {
+                                        $crstitle = $toolhash{'crstitle'};
+                                        $titlestyle = 'display:inline';
+                                    }
+                                    if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'label'}) {  
+                                        $crslabel = $toolhash{'crslabel'};
+                                        $labelstyle = 'display:inline';
+                                    }
+                                    if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'target'}) {
+                                        $dispdivstyle = 'display:block';
+                                    }
+                                }
                                 $toolelem = '<span class="LC_nobreak">'.$image.' '.$tooltitle.'</span><br />';
                             }
                         }
@@ -452,7 +479,9 @@
                     }
                 }
             }
-            $toolelem .= '</select></span>';
+            $toolelem .= '</select></span><br />';
+            $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
+            $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
         }
         $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
                     '<span class="'.$class.'">'.&mt('Display target:').' '.
@@ -464,7 +493,15 @@
                     '<span class="'.$class.'">'.
                     &mt('Width').'<input type="text" id="'.$toolattr{'dimenwidth'}.'" name="exttoolwidth" value="'.$width.'">'.(' 'x2).
                     &mt('Height').'<input type="text" id="'.$toolattr{'dimenheight'}.'" name="exttoolheight" value="'.$height.'"></span>'."\n".
-                    '</div></div>';
+                    '</div></div>'.
+                    '<div id="'.$toolattr{'crslabeldiv'}.'" style="'.$labelstyle.'">'.
+                    '<span class="'.$class.'">'.&mt('Course label:').' '.
+                    '<input type="text" id="'.$toolattr{'crslabel'}.'" name="exttoollabel" value="'.$crslabel.'"><br />'.
+                    '</div>'.
+                    '<div id="'.$toolattr{'crstitlediv'}.'" style="'.$titlestyle.'">'.
+                    '<span class="'.$class.'">'.&mt('Course title:').' '.
+                    '<input type="text" id="'.$toolattr{'crstitle'}.'" name="exttooltitle" value="'.$crstitle.'"><br />'.
+                    '</div>';
     }
     my $chooser = $toolelem;
     if ($type eq 'ext') {
@@ -491,7 +528,7 @@
 <input type="hidden" name="importdetail" value="" />
 $pathitem
 $hiddenelem
-<input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url');" />
+<input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url','$supplementalflag');" />
 </span>
 </div>
 </fieldset>
@@ -545,7 +582,10 @@
         $toolsjs = "        var ltitools = new Array($num);\n".
                    "        var ltitoolsTarget = new Array($num);\n".
                    "        var ltitoolsWidth = new Array($num);\n".
-                   "        var ltitoolsHeight = new Array($num);\n"; 
+                   "        var ltitoolsHeight = new Array($num);\n".
+                   "        var ltitoolsDisplay = new Array($num);\n".
+                   "        var ltitoolsLabel = new Array($num);\n".
+                   "        var ltitoolsTitle = new Array($num);\n";
         my $i = 0;
         foreach my $key (sort { $a <=> $b } keys(%{$toolsref})) {
             if (ref($toolsref->{$key})) {
@@ -556,6 +596,15 @@
                             '        ltitoolsTarget['.$i.'] = '."'$target';\n".
                             '        ltitoolsWidth['.$i.'] = '."'$width';\n".
                             '        ltitoolsHeight['.$i.'] = '."'$height';\n";
+                my %courseconfig;
+                if (ref($toolsref->{$key}->{'crsconf'}) eq 'HASH') {
+                    my $display = $toolsref->{$key}->{'crsconf'}->{'target'};
+                    $toolsjs .= '         ltitoolsDisplay['.$i.'] = '."'$display';\n";
+                    my $label = $toolsref->{$key}->{'crsconf'}->{'label'};
+                    $toolsjs .= '         ltitoolsLabel['.$i.'] = '."'$label';\n";
+                    my $title = $toolsref->{$key}->{'crsconf'}->{'title'};
+                    $toolsjs .= '         ltitoolsTitle['.$i.'] = '."'$title';\n";
+                }
                 $i++;
             }
         }
@@ -575,7 +624,7 @@
 
 var regexp = $urlregexp;
 
-function setExternal(extform,residx,type,exttoolurl) {
+function setExternal(extform,residx,type,exttoolurl,supplementalflag) {
     var title=extform.exttitle.value;
     if (!String.trim) {
         String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");};    }
@@ -610,20 +659,56 @@
             }
             info += ':'+toolid;
         }
-        if (extform.exttooltarget.length) {
-            for (var i=0; i<extform.exttooltarget.length; i++) {
-                if (extform.exttooltarget[i].checked) {
-                    if (extform.exttooltarget[i].value == 'window') {
-                        var width = extform.exttoolwidth.value;
-                        width.trim();
-                        var height = extform.exttoolheight.value;
-                        height.trim();
-                        info += ':window:'+width+':'+height;  
-                    } else {
-                        info += ':iframe';
+        var prefix = '';
+        if (supplementalflag == 1) {
+           prefix = 'supp';
+        }
+        var dispdiv = prefix+'tooldispdiv';
+        if (residx > 0) {
+            dispdiv += '_'+residx;
+        }
+        if (document.getElementById(dispdiv)) {
+            if (document.getElementById(dispdiv).style.display == 'block') {
+                if (extform.exttooltarget.length) {
+                    for (var i=0; i<extform.exttooltarget.length; i++) {
+                        if (extform.exttooltarget[i].checked) {
+                            if (extform.exttooltarget[i].value == 'window') {
+                                var width = extform.exttoolwidth.value;
+                                width.trim();
+                                var height = extform.exttoolheight.value;
+                                height.trim();
+                                info += ':window:'+width+':'+height;  
+                            } else {
+                                info += ':iframe::';
+                            }
+                        }
                     }
                 }
+            } else {
+                info += ':::';
             }
+        } else {
+            info += ':::';
+        }
+        var labelinput = prefix+'toolcrslabel';
+        var titleinput = prefix+'toolcrstitle';
+        if (residx > 0) {
+            labelinput += '_'+residx;
+            titleinput += '_'+residx;
+        }
+        if (document.getElementById(labelinput)) {
+            var crslabel = document.getElementById(labelinput).value;
+            crslabel.trim();
+            info += ':'+escape(crslabel);
+        } else {
+            info += ':';
+        } 
+        if (document.getElementById(titleinput)) {
+            var crstitle = document.getElementById(titleinput).value;
+            crstitle.trim();
+            info += ':'+escape(crstitle);
+        } else {
+            info += ':';
         }
         info=escape(info);
         if (residx > 0) {
@@ -668,6 +753,10 @@
     dimendiv = prefix+'tooldimendiv';
     widthinput = prefix+'toolwidth';
     heightinput = prefix+'toolheight';
+    labeldiv = prefix+'toolcrslabeldiv';
+    titlediv = prefix+'toolcrstitlediv';
+    labelinput = prefix+'toolcrslabel';
+    titleinput = prefix+'toolcrstitle';
     if (document.getElementById(dispdiv)) {
         var toolpick = caller.options[caller.selectedIndex].value;
         $toolsjs
@@ -678,41 +767,63 @@
             if (document.getElementById(dimendiv)) {
                 document.getElementById(dimendiv).style.display = 'none';
             }
-        } else {
-            if (document.getElementById(dispdiv)) {
-                document.getElementById(dispdiv).style.display = 'block';
+            if (document.getElementById(labeldiv)) {
+                document.getElementById(labeldiv).style.display = 'none';
+            }
+            if (document.getElementById(titlediv)) {
+                document.getElementById(titlediv).style.display = 'none';
             }
+        } else {
             if (ltitools.length > 0) {
                 for (var j=0; j<ltitools.length; j++) {
                     if (ltitools[j] == toolpick) {
-                        if (form.exttooltarget.length) {
-                            for (var k=0; k<form.exttooltarget.length; k++) {
-                                if (form.exttooltarget[k].value == ltitoolsTarget[j]) {
-                                    form.exttooltarget[k].checked = true;
-                                    break;
+                        if (document.getElementById(dispdiv)) {
+                            if (ltitoolsDisplay[j]) {
+                                document.getElementById(dispdiv).style.display = 'block';
+                                if (form.exttooltarget.length) {
+                                    for (var k=0; k<form.exttooltarget.length; k++) {
+                                        if (form.exttooltarget[k].value == ltitoolsTarget[j]) {
+                                            form.exttooltarget[k].checked = true;
+                                            break;
+                                        }
+                                    }
+                                }
+                                if (ltitoolsTarget[j] == 'window') {
+                                    dimen = 'block';
+                                    dimenwidth = ltitoolsWidth[j];
+                                    dimenheight = ltitoolsHeight[j];                    
+                                } else {
+                                    dimen = 'none';
+                                    dimenwidth = '';
+                                    dimenheight = '';
+                                }
+                                if (document.getElementById(dimendiv)) {
+                                    document.getElementById(dimendiv).style.display = dimen;
+                                }
+                                if (document.getElementById(widthinput)) {
+                                    document.getElementById(widthinput).value = dimenwidth;
+                                }
+                                if (document.getElementById(heightinput)) {
+                                    document.getElementById(heightinput).value = dimenheight;
                                 }
                             }
                         }
-                        if (ltitoolsTarget[j] == 'window') {
-                            dimen = 'block';
-                            dimenwidth = ltitoolsWidth[j];
-                            dimenheight = ltitoolsHeight[j];                    
-                        } else {
-                            dimen = 'none';
-                            dimenwidth = '';
-                            dimenheight = '';
-                        }
-                        if (document.getElementById(dimendiv)) {
-                            document.getElementById(dimendiv).style.display = dimen;
-                        }
-                        if (document.getElementById(widthinput)) {
-                            document.getElementById(widthinput).value = dimenwidth;
+                        if (document.getElementById(labeldiv)) {
+                            if (ltitoolsLabel[j]) {
+                                document.getElementById(labeldiv).style.display = 'inline';
+                            } else {
+                                document.getElementById(labeldiv).style.display = 'none';
+                            } 
                         }
-                        if (document.getElementById(heightinput)) {
-                            document.getElementById(heightinput).value = dimenheight;
+                        if (document.getElementById(titlediv)) {
+                            if (ltitoolsTitle[j]) {
+                                document.getElementById(titlediv).style.display = 'inline';
+                            } else {
+                                document.getElementById(titlediv).style.display = 'none';
+                            }
                         }
+                        break;
                     }
-                    break;
                 }
             }
         }
Index: loncom/interface/lonexttool.pm
diff -u loncom/interface/lonexttool.pm:1.3 loncom/interface/lonexttool.pm:1.4
--- loncom/interface/lonexttool.pm:1.3	Tue Jan 26 14:30:25 2016
+++ loncom/interface/lonexttool.pm	Mon Jun  6 17:40:48 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Launch External Tool Provider (LTI)
 #
-# $Id: lonexttool.pm,v 1.3 2016/01/26 14:30:25 raeburn Exp $
+# $Id: lonexttool.pm,v 1.4 2016/06/06 17:40:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -102,13 +102,15 @@
                                            width  => $toolsettings{'width'},
                                            height => $toolsettings{'height'},
                                        };
+                $toolhash{'crslabel'} = $toolsettings{'crslabel'};
+                $toolhash{'crstitle'} = $toolsettings{'crstitle'};
                 $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);
+                        my %lti = &lti_params($r,$cnum,$cdom,$submittext,\%toolhash);
                         $r->print(&launch_html($toolhash{'url'},$toolhash{'key'},
                                                $toolhash{'secret'},$submittext,\%lti));
                     } else {
@@ -129,9 +131,9 @@
 }
 
 sub lti_params {
-    my ($r,$submittext,$toolsref) = @_;
+    my ($r,$cnum,$cdom,$submittext,$toolsref) = @_;
     my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
-        %fields,%rolesmap,%display,%custom, at userlangs);
+        $crslabel,$crstitle,%fields,%rolesmap,%display,%custom, at userlangs);
     if (ref($toolsref) eq 'HASH') {
         $version = $toolsref->{'version'};
         $toolname = $toolsref->{'title'};
@@ -150,6 +152,8 @@
         if (ref($toolsref->{'custom'}) eq 'HASH') {
             %custom = %{$toolsref->{'custom'}};
         }
+        $crslabel = $toolsref->{'crslabel'};
+        $crstitle = $toolsref->{'crstitle'};
     }
     if ($version eq '') {
         $version = 'LTI-1p0';
@@ -160,6 +164,12 @@
     if ($msgtype eq '') {
         $msgtype = 'basic-lti-launch-request';
     }
+    if ($crslabel eq '') {
+        $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
+    }
+    if ($crstitle eq '') {
+        $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'},;
+    }
     my $lonhost = $r->dir_config('lonHostID');
     my $loncaparev = $r->dir_config('lonVersion');
     my $uname = $env{'user.name'};
@@ -202,21 +212,28 @@
             }
         }
     }
+    my $domdesc = &Apache::lonnet::domain($cdom);
+    my $primary_id = &Apache::lonnet::domain($cdom,'primary');
+    my $int_dom = &Apache::lonnet::internet_dom($primary_id);
+    my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom);
+
     my %ltiparams = (
         lti_version                            => $version,
         lti_message_type                       => $msgtype,
         resource_link_title                    => $title,
         resource_link_id                       => $digest_symb,
         tool_consumer_instance_guid            => $lonhost,
+        tool_consumer_instance_description     => $domdesc,
         tool_consumer_info_product_family_code => 'loncapa',
+        tool_consumer_instance_name            => $int_dom,  
+        tool_consumer_instance_url             => $portal_url,
         tool_consumer_info_version             => $loncaparev,
         user_id                                => $digest_user,
-        lis_person_sourcedid                   => $uname.':'.$udom,
         roles                                  => $ltirole,
         context_id                             => $env{'request.course.id'},
         context_type                           => $context_type,
-        context_label                          => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
-        context_title                          => $env{'course.'.$env{'request.course.id'}.'.description'},
+        context_label                          => $crslabel,
+        context_title                          => $crstitle,
         launch_presentation_locale             => $locale,
     );
     my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
@@ -269,6 +286,9 @@
         }
         $ltiparams{'lis_person_contact_email_primary'} = $contact_email;
     }
+    if ($fields{'user'}) {
+        $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom; 
+    }
     if (keys(%custom)) {
         foreach my $key (keys(%custom)) {
             $ltiparams{'custom_'.$key} = $custom{$key};


More information about the LON-CAPA-cvs mailing list