--- loncom/interface/loncommon.pm 2009/10/12 08:01:08 1.896 +++ loncom/interface/loncommon.pm 2022/10/29 18:13:28 1.1395 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.896 2009/10/12 08:01:08 amueller Exp $ +# $Id: loncommon.pm,v 1.1395 2022/10/29 18:13:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -61,15 +61,34 @@ use POSIX qw(strftime mktime); use Apache::lonmenu(); use Apache::lonenc(); use Apache::lonlocal; -use Apache::lonnet(); +use Apache::lonnavmaps(); use HTML::Entities; use Apache::lonhtmlcommon(); use Apache::loncoursedata(); use Apache::lontexconvert(); use Apache::lonclonecourse(); +use Apache::lonuserutils(); +use Apache::lonuserstate(); +use Apache::courseclassifier(); use LONCAPA qw(:DEFAULT :match); +use LONCAPA::LWPReq; +use LONCAPA::map(); +use HTTP::Request; use DateTime::TimeZone; -use DateTime::Locale::Catalog; +use DateTime::Locale; +use Encode(); +use Text::Aspell; +use Authen::Captcha; +use Captcha::reCAPTCHA; +use JSON::DWIW; +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); @@ -154,6 +173,9 @@ sub ssi_with_retries { # ----------------------------------------------- Filetypes/Languages/Copyright my %language; my %supported_language; +my %supported_codes; +my %latex_language; # For choosing hyphenation in +my %latex_language_bykey; # for choosing hyphenation from metadata my %cprtag; my %scprtag; my %fe; my %fd; my %fm; @@ -182,15 +204,20 @@ BEGIN { { my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}. '/language.tab'; - if ( open(my $fh,"<$langtabfile") ) { + if ( open(my $fh,'<',$langtabfile) ) { while (my $line = <$fh>) { next if ($line=~/^\#/); chomp($line); - my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line)); + my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line)); $language{$key}=$val.' - '.$enc; if ($sup) { $supported_language{$key}=$sup; + $supported_codes{$key} = $code; } + if ($latex) { + $latex_language_bykey{$key} = $latex; + $latex_language{$code} = $latex; + } } close($fh); } @@ -199,7 +226,7 @@ BEGIN { { my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}. '/copyright.tab'; - if ( open (my $fh,"<$copyrightfile") ) { + if ( open (my $fh,'<',$copyrightfile) ) { while (my $line = <$fh>) { next if ($line=~/^\#/); chomp($line); @@ -213,7 +240,7 @@ BEGIN { { my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}. '/source_copyright.tab'; - if ( open (my $fh,"<$sourcecopyrightfile") ) { + if ( open (my $fh,'<',$sourcecopyrightfile) ) { while (my $line = <$fh>) { next if ($line =~ /^\#/); chomp($line); @@ -227,7 +254,7 @@ BEGIN { # -------------------------------------------------------------- default domain designs my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors'; my $designfile = $designdir.'/default.tab'; - if ( open (my $fh,"<$designfile") ) { + if ( open (my $fh,'<',$designfile) ) { while (my $line = <$fh>) { next if ($line =~ /^\#/); chomp($line); @@ -241,12 +268,12 @@ BEGIN { { my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}. '/filecategories.tab'; - if ( open (my $fh,"<$categoryfile") ) { + if ( open (my $fh,'<',$categoryfile) ) { while (my $line = <$fh>) { next if ($line =~ /^\#/); chomp($line); my ($extension,$category)=(split(/\s+/,$line,2)); - push @{$category_extensions{lc($category)}},$extension; + push(@{$category_extensions{lc($category)}},$extension); } close($fh); } @@ -256,7 +283,7 @@ BEGIN { { my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}. '/filetypes.tab'; - if ( open (my $fh,"<$typesfile") ) { + if ( open (my $fh,'<',$typesfile) ) { while (my $line = <$fh>) { next if ($line =~ /^\#/); chomp($line); @@ -409,7 +436,7 @@ sub studentbrowser_javascript { +ENDRESBRW +} + sub selectstudent_link { - my ($form,$unameele,$udomele,$courseadvonly)=@_; - my $callargs = "'".$form."','".$unameele."','".$udomele."'"; + my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_; + my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','". + &Apache::lonhtmlcommon::entity_encode($unameele)."','". + &Apache::lonhtmlcommon::entity_encode($udomele)."'"; if ($env{'request.course.id'}) { if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { return ''; } - if ($courseadvonly) { - $callargs .= ",'',1,1"; + $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'"; + if ($courseadv eq 'only') { + $callargs .= ",'',1,'$courseadv'"; + } elsif ($courseadv eq 'none') { + $callargs .= ",'','','$courseadv'"; + } elsif ($courseadv eq 'condition') { + $callargs .= ",'','','$courseadv'"; } return ''. ''. &mt('Select User').''; } if ($env{'request.role'}=~/^(au|dc|su)/) { - $callargs .= ",1"; + $callargs .= ",'',1"; return ''. ''. &mt('Select User').''; @@ -460,6 +519,19 @@ sub selectstudent_link { return ''; } +sub selectresource_link { + my ($form,$reslink,$arg)=@_; + + my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','". + &Apache::lonhtmlcommon::entity_encode($reslink)."'"; + unless ($env{'request.course.id'}) { return $arg; } + return ''. + ''. + $arg.''; +} + + + sub authorbrowser_javascript { return <<"ENDAUTHORBRW"; + +ENDJS + +} + sub userbrowser_javascript { my $id_functions = &javascript_index_functions(); return <<"ENDUSERBRW"; @@ -661,7 +783,28 @@ ENDUSERBRW } sub setsec_javascript { - my ($sec_element,$formname) = @_; + my ($sec_element,$formname,$role_element,$credits_element) = @_; + my (@courserolenames,@communityrolenames,$rolestr,$courserolestr, + $communityrolestr); + if ($role_element ne '') { + my @allroles = ('st','ta','ep','in','ad'); + foreach my $crstype ('Course','Community') { + if ($crstype eq 'Community') { + foreach my $role (@allroles) { + push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype)); + } + push(@communityrolenames,&Apache::lonnet::plaintext('co')); + } else { + foreach my $role (@allroles) { + push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype)); + } + push(@courserolenames,&Apache::lonnet::plaintext('cc')); + } + } + $rolestr = '"'.join('","',@allroles).'"'; + $courserolestr = '"'.join('","',@courserolenames).'"'; + $communityrolestr = '"'.join('","',@communityrolenames).'"'; + } my $setsections = qq| function setSect(sectionlist) { var sectionsArray = new Array(); @@ -695,22 +838,78 @@ function setSect(sectionlist) { } } } + +function setRole(crstype) { |; + if ($role_element eq '') { + $setsections .= ' return; +} +'; + } else { + $setsections .= qq| + var elementLength = document.$formname.$role_element.length; + var allroles = Array($rolestr); + var courserolenames = Array($courserolestr); + var communityrolenames = Array($communityrolestr); + if (elementLength != undefined) { + if (document.$formname.$role_element.options[5].value == 'cc') { + if (crstype == 'Course') { + return; + } else { + allroles[5] = 'co'; + for (var i=0; i<6; i++) { + document.$formname.$role_element.options[i].value = allroles[i]; + document.$formname.$role_element.options[i].text = communityrolenames[i]; + } + } + } else { + if (crstype == 'Community') { + return; + } else { + allroles[5] = 'cc'; + for (var i=0; i<6; i++) { + document.$formname.$role_element.options[i].value = allroles[i]; + document.$formname.$role_element.options[i].text = courserolenames[i]; + } + } + } + } + return; +} +|; + } + if ($credits_element) { + $setsections .= qq| +function setCredits(defaultcredits) { + document.$formname.$credits_element.value = defaultcredits; + return; +} +|; + } return $setsections; } - sub selectcourse_link { - my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_; + my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype, + $typeelement) = @_; + my $type = $selecttype; my $linktext = &mt('Select Course'); if ($selecttype eq 'Community') { - $linktext = &mt('Select Community'); + $linktext = &mt('Select Community'); + } elsif ($selecttype eq 'Placement') { + $linktext = &mt('Select Placement Test'); + } elsif ($selecttype eq 'Course/Community') { + $linktext = &mt('Select Course/Community'); + $type = ''; + } elsif ($selecttype eq 'Select') { + $linktext = &mt('Select'); + $type = ''; } return '' ."".$linktext.'' .''; } @@ -734,10 +933,14 @@ sub check_uncheck_jscript { function checkAll(field) { if (field.length > 0) { for (i = 0; i < field.length; i++) { - field[i].checked = true ; + if (!field[i].disabled) { + field[i].checked = true; + } } } else { - field.checked = true + if (!field.disabled) { + field.checked = true; + } } } @@ -755,8 +958,8 @@ ENDSCRT } sub select_timezone { - my ($name,$selected,$onchange,$includeempty)=@_; - my $output=''."\n"; if ($includeempty) { $output .= '