--- loncom/interface/loncommon.pm 2012/01/03 22:36:36 1.1049 +++ loncom/interface/loncommon.pm 2016/09/15 04:18:38 1.1075.2.112 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1049 2012/01/03 22:36:36 www Exp $ +# $Id: loncommon.pm,v 1.1075.2.112 2016/09/15 04:18:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -67,9 +67,19 @@ 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 DateTime::TimeZone; -use DateTime::Locale::Catalog; +use DateTime::Locale; +use Encode(); +use Authen::Captcha; +use Captcha::reCAPTCHA; +use JSON::DWIW; +use LWP::UserAgent; +use Crypt::DES; +use DynaLoader; # for Crypt::DES version # ---------------------------------------------- Designs use vars qw(%defaultdesign); @@ -524,7 +534,8 @@ ENDAUTHORBRW } sub coursebrowser_javascript { - my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_; + my ($domainfilter,$sec_element,$formname,$role_element,$crstype, + $credits_element,$instcode) = @_; my $wintitle = 'Course_Browser'; if ($crstype eq 'Community') { $wintitle = 'Community_Browser'; @@ -575,6 +586,12 @@ sub coursebrowser_javascript { var ownername = document.forms[formid].ccuname.value; var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value; url += '&cloner='+ownername+':'+ownerdom; + if (type == 'Course') { + url += '&crscode='+document.forms[formid].crscode.value; + } + } + if (formname == 'requestcrs') { + url += '&crsdom=$domainfilter&crscode=$instcode'; } if (multflag !=null && multflag != '') { url += '&multiple='+multflag; @@ -587,8 +604,9 @@ sub coursebrowser_javascript { } $id_functions ENDSTDBRW - if (($sec_element ne '') || ($role_element ne '')) { - $output .= &setsec_javascript($sec_element,$formname,$role_element); + if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) { + $output .= &setsec_javascript($sec_element,$formname,$role_element, + $credits_element); } $output .= ' // ]]> @@ -745,7 +763,7 @@ ENDUSERBRW } sub setsec_javascript { - my ($sec_element,$formname,$role_element) = @_; + my ($sec_element,$formname,$role_element,$credits_element) = @_; my (@courserolenames,@communityrolenames,$rolestr,$courserolestr, $communityrolestr); if ($role_element ne '') { @@ -840,6 +858,14 @@ function setRole(crstype) { } |; } + if ($credits_element) { + $setsections .= qq| +function setCredits(defaultcredits) { + document.$formname.$credits_element.value = defaultcredits; + return; +} +|; + } return $setsections; } @@ -885,10 +911,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; + } } } @@ -937,15 +967,16 @@ sub select_datelocale { } $output .= '> '; } + my @languages = &Apache::lonlocal::preferred_languages(); my (@possibles,%locale_names); - my @locales = DateTime::Locale::Catalog::Locales; - foreach my $locale (@locales) { - if (ref($locale) eq 'HASH') { - my $id = $locale->{'id'}; - if ($id ne '') { - my $en_terr = $locale->{'en_territory'}; - my $native_terr = $locale->{'native_territory'}; - my @languages = &Apache::lonlocal::preferred_languages(); + my @locales = DateTime::Locale->ids(); + foreach my $id (@locales) { + if ($id ne '') { + my ($en_terr,$native_terr); + my $loc = DateTime::Locale->load($id); + if (ref($loc)) { + $en_terr = $loc->name(); + $native_terr = $loc->native_name(); if (grep(/^en$/,@languages) || !@languages) { if ($en_terr ne '') { $locale_names{$id} = '('.$en_terr.')'; @@ -959,7 +990,8 @@ sub select_datelocale { $locale_names{$id} = '('.$en_terr.')'; } } - push (@possibles,$id); + $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id}); + push(@possibles,$id); } } } @@ -970,7 +1002,7 @@ sub select_datelocale { } $output.=">$item"; if ($locale_names{$item} ne '') { - $output.=" $locale_names{$item}\n"; + $output.=' '.$locale_names{$item}; } $output.="\n"; } @@ -990,6 +1022,7 @@ sub select_language { $langchoices{$code} = &plainlanguagedescription($id); } } + %langchoices = &Apache::lonlocal::texthash(%langchoices); return &select_form($selected,$name,\%langchoices); } @@ -1021,6 +1054,12 @@ linked_select_forms takes the following =item * $menuorder, the order of values in the first menu +=item * $onchangefirst, additional javascript call to execute for an onchange + event for the first tag + =back Below is an example of such a hash. Only the 'text', 'default', and @@ -1074,6 +1113,8 @@ sub linked_select_forms { $secondselectname, $hashref, $menuorder, + $onchangefirst, + $onchangesecond ) = @_; my $second = "document.$formname.$secondselectname"; my $first = "document.$formname.$firstselectname"; @@ -1130,7 +1171,7 @@ function select1_changed() { END # output the initial values for the selection lists - $result .= "\n"; my @order = sort(keys(%{$hashref})); if (ref($menuorder) eq 'ARRAY') { @order = @{$menuorder}; @@ -1143,7 +1184,11 @@ END $result .= "\n"; my %select2 = %{$hashref->{$firstdefault}->{'select2'}}; $result .= $middletext; - $result .= "{$firstdefault}->{'default'}; my @secondorder = sort(keys(%select2)); @@ -1203,7 +1248,11 @@ sub help_open_topic { $topic=~s/\W/\_/g; if (!$stayOnPage) { - $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');"; + if ($env{'browser.mobile'}) { + $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');"; + } else { + $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))"; + } } elsif ($stayOnPage eq 'popup') { $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))"; } else { @@ -1254,7 +1303,9 @@ sub helpLatexCheatsheet { unless ($not_author) { $out .= ' ' .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600) - .''; + .' ' + .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600) + .''; } $out .= ''; # End cheatsheet return $out; @@ -1317,32 +1368,40 @@ sub help_open_menu { sub top_nav_help { my ($text) = @_; $text = &mt($text); - my $stay_on_page = 1; - - my $link = ($stay_on_page) ? "javascript:helpMenu('display')" - : "javascript:helpMenu('open')"; - my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page); - + my $stay_on_page; + unless ($env{'environment.remote'} eq 'on') { + $stay_on_page = 1; + } + my ($link,$banner_link); + unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) { + $link = ($stay_on_page) ? "javascript:helpMenu('display')" + : "javascript:helpMenu('open')"; + $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page); + } my $title = &mt('Get help'); - - return <<"END"; + if ($link) { + return <<"END"; $banner_link - $text +$text END + } else { + return ' '.$text.' '; + } } sub help_menu_js { - my ($text) = @_; + my ($httphost) = @_; my $stayOnPage = 1; my $width = 620; my $height = 600; my $helptopic=&general_help(); - my $details_link = '/adm/help/'.$helptopic.'.hlp'; + my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp'; my $nothing=&Apache::lonhtmlcommon::javascript_nothing(); my $start_page = &Apache::loncommon::start_page('Help Menu', undef, {'frameset' => 1, 'js_ready' => 1, + 'use_absolute' => $httphost, 'add_entries' => { 'border' => '0', 'rows' => "110,*",},}); @@ -1374,9 +1433,10 @@ function helpMenu(target) { return; } function writeHelp(caller) { - caller.document.writeln('$start_page $end_page') - caller.document.close() - caller.focus() + caller.document.writeln('$start_page\\n\\n'); + caller.document.writeln('\\n$end_page'); + caller.document.close(); + caller.focus(); } // END LON-CAPA Internal --> // ]]> @@ -1684,12 +1744,246 @@ RESIZE } +sub colorfuleditor_js { + return <<"COLORFULEDIT" + +COLORFULEDIT +} + +sub xmleditor_js { + return < + +XMLEDIT +} + +sub insert_folding_button { + my $curDepth = $Apache::lonxml::curdepth; + my $lastresource = $env{'request.ambiguous'}; + + return ""; +} + + =pod =head1 Excel and CSV file utility routines -=over 4 - =cut ############################################################### @@ -1697,6 +1991,8 @@ RESIZE =pod +=over 4 + =item * &csv_translate($text) Translate $text to allow it to be output as a 'comma separated values' @@ -1748,6 +2044,7 @@ Inputs: $workbook Returns: $format, a hash reference. + =cut ############################################################### @@ -1980,19 +2277,112 @@ sub select_form { # For display filters sub display_filter { + my ($context) = @_; if (!$env{'form.show'}) { $env{'form.show'}=10; } if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; } - return '