--- loncom/interface/loncommon.pm 2017/08/07 20:22:13 1.1287
+++ loncom/interface/loncommon.pm 2018/04/14 02:29:44 1.1312
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1287 2017/08/07 20:22:13 raeburn Exp $
+# $Id: loncommon.pm,v 1.1312 2018/04/14 02:29:44 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -84,6 +84,10 @@ use Crypt::DES;
use DynaLoader; # for Crypt::DES version
use MIME::Lite;
use MIME::Types;
+use File::Copy();
+use File::Path();
+use String::CRC32();
+use Short::URL();
# ---------------------------------------------- Designs
use vars qw(%defaultdesign);
@@ -2477,10 +2481,24 @@ sub create_text_file {
# ------------------------------------------
sub domain_select {
- my ($name,$value,$multiple)=@_;
+ my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
+ my @possdoms;
+ if (ref($incdoms) eq 'ARRAY') {
+ @possdoms = @{$incdoms};
+ } else {
+ @possdoms = &Apache::lonnet::all_domains();
+ }
+
my %domains=map {
$_ => $_.' '. &Apache::lonnet::domain($_,'description')
- } &Apache::lonnet::all_domains();
+ } @possdoms;
+
+ if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
+ foreach my $dom (@{$excdoms}) {
+ delete($domains{$dom});
+ }
+ }
+
if ($multiple) {
$domains{''}=&mt('Any domain');
$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
@@ -3009,6 +3027,8 @@ This is not an optimal method, but it wo
=item * authform_filesystem
+=item * authform_lti
+
=back
See loncreateuser.pm for invocation and use examples.
@@ -3425,14 +3445,69 @@ sub authform_filesystem {
$fsyscheck.' onchange="'.$jscall.'" onclick="'.
$jscall.'"'.$disabled.' />';
}
- $autharg = '';
$result = &mt
('[_1] Filesystem Authenticated (with initial password [_2])',
- '');
+ ''.$autharg);
+ return $result;
+}
+
+sub authform_lti {
+ my %in = (
+ formname => 'document.cu',
+ kerb_def_dom => 'MSU.EDU',
+ @_,
+ );
+ my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
+ my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ if ($in{'readonly'}) {
+ $disabled = ' disabled="disabled"';
+ }
+ if (defined($in{'curr_authtype'})) {
+ if ($in{'curr_authtype'} eq 'lti') {
+ if ($can_assign{'lti'}) {
+ $lticheck = 'checked="checked" ';
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifyuser') {
+ $lticheck = '';
+ }
+ }
+ } else {
+ $result = &mt('Currently LTI Authenticated.');
+ return $result;
+ }
+ }
+ } else {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
+ }
+ if (!$can_assign{'lti'}) {
+ return;
+ } elsif ($authtype eq '') {
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifycourse') {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
+ }
+ }
+ }
+ $jscall = "javascript:changed_radio('lti',$in{'formname'});";
+ if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
+ $authtype = '';
+ }
+ $autharg = '';
+ if ($authtype) {
+ $result = &mt('[_1] LTI Authenticated',
+ ''.$autharg);
+ } else {
+ $result = ''.&mt('LTI Authenticated').''.
+ $autharg;
+ }
return $result;
}
@@ -3446,6 +3521,7 @@ sub get_assignable_auth {
krb5 => 1,
int => 1,
loc => 1,
+ lti => 1,
);
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
if (ref($domconfig{'usercreation'}) eq 'HASH') {
@@ -4563,9 +4639,15 @@ sub get_previous_attempt {
}
$prevattempts.= &end_data_table_row().&end_data_table();
} else {
+ my $msg;
+ if ($symb =~ /ext\.tool$/) {
+ $msg = &mt('No grade passed back.');
+ } else {
+ $msg = &mt('Nothing submitted - no attempts.');
+ }
$prevattempts=
&start_data_table().&start_data_table_row().
- '
'.&mt('Nothing submitted - no attempts.').' | '.
+ ''.$msg.' | '.
&end_data_table_row().&end_data_table();
}
} else {
@@ -4670,6 +4752,9 @@ sub get_student_view {
}
if (defined($target)) { $form{'grade_target'} = $target; }
$feedurl=&Apache::lonnet::clutter($feedurl);
+ if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
+ $feedurl =~ s{^/adm/wrapper}{};
+ }
my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
$userview=~s/\]*\>//gi;
$userview=~s/\<\/body\>//gi;
@@ -5099,7 +5184,7 @@ sub blockcheck {
($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
next if ($no_userblock);
- # Retrieve blocking times and identity of locker for course
+ # Retrieve blocking times and identity of blocker for course
# of specified user, unless user has 'evb' privilege.
my ($start,$end,$trigger) =
@@ -8637,9 +8722,16 @@ sub start_page {
if (@advtools > 0) {
&Apache::lonmenu::advtools_crumbs(@advtools);
}
+ my $ltiscope;
+ if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ ($ltiscope) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
+ }
my $menulink;
# if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
if ((exists($args->{'bread_crumbs_nomenu'})) ||
+ ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
(!$env{'request.role.adv'}))) {
@@ -8877,8 +8969,9 @@ sub end_togglebox {
}
sub LCprogressbar_script {
- my ($id)=@_;
- return(<
//
ENDPROGRESS
+ } else {
+ return(<
+//
+
+ENDPROGRESS
+ }
}
sub LCprogressbarUpdate_script {
return(<
.ui-progressbar { position:relative; }
+.progress-label {position: absolute; width: 100%; text-align: center; top: 1px; font-weight: bold; text-shadow: 1px 1px 0 #fff;margin: 0; line-height: 200%; }
.pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
@@ -8917,37 +9032,54 @@ my $LCidcnt;
my $LCcurrentid;
sub LCprogressbar {
- my ($r)=(@_);
+ my ($r,$number_to_do,$preamble)=@_;
$LClastpercent=0;
$LCidcnt++;
$LCcurrentid=$$.'_'.$LCidcnt;
- my $starting=&mt('Starting');
- my $content=(<
$starting
ENDPROGBAR
- &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
+ } else {
+ $starting=&mt('Loading...');
+ $LClastpercent='false';
+ $content=(<
+ $starting
+
+ENDPROGBAR
+ }
+ &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
}
sub LCprogressbarUpdate {
- my ($r,$val,$text)=@_;
- unless ($val) {
- if ($LClastpercent) {
- $val=$LClastpercent;
- } else {
- $val=0;
- }
+ my ($r,$val,$text,$number_to_do)=@_;
+ if ($number_to_do) {
+ unless ($val) {
+ if ($LClastpercent) {
+ $val=$LClastpercent;
+ } else {
+ $val=0;
+ }
+ }
+ if ($val<0) { $val=0; }
+ if ($val>100) { $val=0; }
+ $LClastpercent=$val;
+ unless ($text) { $text=$val.'%'; }
+ } else {
+ $val = 'false';
}
- if ($val<0) { $val=0; }
- if ($val>100) { $val=0; }
- $LClastpercent=$val;
- unless ($text) { $text=$val.'%'; }
$text=&js_ready($text);
&r_print($r,<
//
ENDUPDATE
@@ -9132,14 +9264,21 @@ function expand_div(caller) {
sub simple_error_page {
my ($r,$title,$msg,$args) = @_;
+ my %displayargs;
if (ref($args) eq 'HASH') {
if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
+ if ($args->{'only_body'}) {
+ $displayargs{'only_body'} = 1;
+ }
+ if ($args->{'no_nav_bar'}) {
+ $displayargs{'no_nav_bar'} = 1;
+ }
} else {
$msg = &mt($msg);
}
my $page =
- &Apache::loncommon::start_page($title).
+ &Apache::loncommon::start_page($title,'',\%displayargs).
''.$msg.'
'.
&Apache::loncommon::end_page();
if (ref($r)) {
@@ -10138,15 +10277,15 @@ sub user_picker {
$domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
} else {
my $defdom = $env{'request.role.domain'};
- my ($trustedref,$untrustedref);
+ my ($trusted,$untrusted);
if (($context eq 'requestcrs') || ($context eq 'course')) {
- ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom);
+ ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
} elsif ($context eq 'author') {
- ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
+ ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
} elsif ($context eq 'domain') {
- ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('domroles',$defdom);
+ ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
}
- $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trustedref,$untrustedref);
+ $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
}
my $srchinsel = '