--- loncom/interface/loncommon.pm 2022/11/17 13:21:09 1.1397 +++ loncom/interface/loncommon.pm 2023/06/11 20:45:35 1.1407 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1397 2022/11/17 13:21:09 raeburn Exp $ +# $Id: loncommon.pm,v 1.1407 2023/06/11 20:45:35 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1233,7 +1233,12 @@ END $result.=">".&mt($hashref->{$value}->{'text'})."\n"; } $result .= "\n"; - my %select2 = %{$hashref->{$firstdefault}->{'select2'}}; + my %select2; + if (ref($hashref->{$firstdefault}) eq 'HASH') { + if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') { + %select2 = %{$hashref->{$firstdefault}->{'select2'}}; + } + } $result .= $middletext; $result .= "'. + ''; + if ($files{'/'}) { + $output .= ''."\n"; + } + foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) { + next if ($key eq '/'); + $output .= ''."\n"; + } + $output .= '
'."\n". + $lt{'fnam'}.': '."\n". + ''; + return ($numdirs,$output); +} + +sub show_crsfiles_js { + my $excluderef = &Apache::lonnet::priv_exclude(); + my $se = &js_escape(&mt('Select')); + my $exclude; + if (ref($excluderef) eq 'HASH') { + $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef}))); + } + my $js = <<"END"; + + + function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) { + var relpath = ''; + if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) { + var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value; + if (currdir == '') { + if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) { + selelem = form.elements[filesel]; + var j, numfiles = selelem.options.length -1; + if (numfiles >=0) { + for (j = numfiles; j >= 0; j--) { + selelem.remove(j); + } + } + if (selelem.options.length == 0) { + selelem.options[selelem.options.length] = new Option('',''); + selelem.selectedIndex = 0; } - $selimport_menus{$key}->{'select2'}->{$file} = $file; - push(@ordered,$file); - } - if (@ordered) { - push(@order,$key); - $nonemptydirs{$key} = 1; - $selimport_menus{$key}->{'text'} = $shown; - $selimport_menus{$key}->{'default'} = ''; - $selimport_menus{$key}->{'select2'}->{''} = ''; - $selimport_menus{$key}->{'order'} = \@ordered; } + return; + } else { + relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value); } } - $possdirs = scalar(keys(%nonemptydirs)); - if ($possdirs > 1) { - my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs)); - $output = $lt{'dire'}. - &linked_select_forms($form,'
'. - $lt{'fnam'},'', - $firstselectname,$secondselectname, - \%selimport_menus,\@order, - $onchangefirst,'',$suffix).'
'; - } elsif ($possdirs == 1) { - $singledir = (keys(%nonemptydirs))[0]; - if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') { - @singledirfiles = @{$selimport_menus{$singledir}->{'order'}}; - } - delete($selimport_menus{$singledir}); - } - } elsif ($numdirs == 1) { - $singledir = (keys(%files))[0]; - foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) { - if ($only) { - my ($ext) = ($file =~ /\.([^.]+)$/); - unless ($possexts{lc($ext)}) { - next; + var http = new XMLHttpRequest(); + var url = "/adm/courseauthor"; + var crsrole = "$env{'request.role'}"; + var exclude = ''; + if (exc) { + exclude = '$exclude'; + } + var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath; + http.open("POST", url, true); + http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + http.onreadystatechange = function() { + if (http.readyState == 4 && http.status == 200) { + var data = JSON.parse(http.responseText); + var selelem; + if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) { + if (Array.isArray(data.dirs)) { + selelem = form.elements[dirsel]; + var i, numdirs = selelem.options.length -1; + if (numdirs >=0) { + for (i = numdirs; i >= 0; i--) { + selelem.remove(i); + } + } + var len = data.dirs.length; + if (len) { + selelem.options[selelem.options.length] = new Option('$se',''); + var j; + for (j = 0; j < len; j++) { + selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]); + } + selelem.selectedIndex = 0; + } + if (!setfile) { + if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) { + selelem = form.elements[filesel]; + var j, numfiles = selelem.options.length -1; + if (numfiles >=0) { + for (j = numfiles; j >= 0; j--) { + selelem.remove(j); + } + } + if (selelem.options.length == 0) { + selelem.options[selelem.options.length] = new Option('',''); + selelem.selectedIndex = 0; + } + } + } + } + } + if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) { + selelem = form.elements[filesel]; + var i, numfiles = selelem.options.length -1; + if (numfiles >=0) { + for (i = numfiles; i >= 0; i--) { + selelem.remove(i); + } + } + var x; + for (x in data.files) { + if (Array.isArray(data.files[x])) { + if (data.files[x].length > 1) { + selelem.options[selelem.options.length] = new Option('$se',''); + } + var len = data.files[x].length; + if (len) { + var k; + for (k = 0; k < len; k++) { + selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]); + } + selelem.selectedIndex = 0; + } + } + } + if (selelem.options.length == 0) { + selelem.options[selelem.options.length] = new Option('',''); + selelem.selectedIndex = 0; + } } - } else { - next if ($file =~ /\.rights$/); } - push(@singledirfiles,$file); - } - if (@singledirfiles) { - $possdirs = 1; } + http.send(params); } - if (($possdirs == 1) && (@singledirfiles)) { - my $showdir = $singledir; - if ($singledir eq '') { - $showdir = '/'; - } - $output = $lt{'dire'}. - '
'. - $lt{'fnam'}.'
'."\n"; - } - return ($possdirs,$output); +END } =pod @@ -2672,7 +2781,7 @@ sub display_filter { my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context', '$secondid','$thirdid')"; return ' '. &mt('Filter: [_1]', @@ -6260,6 +6369,8 @@ Input: (optional) filename from which br If page header is being requested for use in a frameset, then the second (option) argument -- frameset will be true, and the target attribute set for links should be target="_parent". + If $title is supplied as the thitd arg, that will be used to + the left of the breadcrumbs tail for the current path. Returns: HTML div with CSTR path and recent box To be included on Authoring Space pages @@ -6267,7 +6378,7 @@ Returns: HTML div with CSTR path and rec =cut sub CSTR_pageheader { - my ($trailfile,$frameset) = @_; + my ($trailfile,$frameset,$title) = @_; if ($trailfile eq '') { $trailfile = $env{'request.filename'}; } @@ -6290,13 +6401,15 @@ sub CSTR_pageheader { $lastitem = $thisdisfn; } - my ($crsauthor,$title); + my $crsauthor; if (($env{'request.course.id'}) && ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) && ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) { $crsauthor = 1; - $title = &mt('Course Authoring Space'); - } else { + if ($title eq '') { + $title = &mt('Course Authoring Space'); + } + } elsif ($title eq '') { $title = &mt('Authoring Space'); } @@ -8051,6 +8164,11 @@ fieldset { /* overflow: hidden; */ } +fieldset#LC_selectuser { + margin: 0; + padding: 0; +} + article.geogebraweb div { margin: 0; } @@ -9650,6 +9768,50 @@ sub symb_from_tinyurl { } } +sub usable_exttools { + my %tooltypes; + if ($env{'request.course.id'}) { + if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) { + if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') { + %tooltypes = ( + crs => 1, + dom => 1, + ); + } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') { + $tooltypes{'crs'} = 1; + } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') { + $tooltypes{'dom'} = 1; + } + } else { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'}); + if ($crstype eq '') { + $crstype = 'course'; + } + if ($crstype eq 'course') { + if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) { + $crstype = 'official'; + } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) { + $crstype = 'textbook'; + } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) { + $crstype = 'lti'; + } else { + $crstype = 'unofficial'; + } + } + my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); + if ($domdefaults{$crstype.'domexttool'}) { + $tooltypes{'dom'} = 1; + } + if ($domdefaults{$crstype.'exttool'}) { + $tooltypes{'crs'} = 1; + } + } + } + return %tooltypes; +} + sub wishlist_window { return(<<'ENDWISHLIST');