--- loncom/interface/lonhtmlcommon.pm 2006/07/18 21:55:24 1.144
+++ loncom/interface/lonhtmlcommon.pm 2018/09/03 20:37:00 1.358.2.13
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.144 2006/07/18 21:55:24 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.358.2.13 2018/09/03 20:37:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,15 +60,193 @@ use Time::Local;
use Time::HiRes;
use Apache::lonlocal;
use Apache::lonnet;
-use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use HTML::Entities();
+use LONCAPA qw(:DEFAULT :match);
+sub java_not_enabled {
+ if (($env{'browser.mobile'}) && ($env{'browser.mobile'} =~ /^ipad|ipod|iphone$/i)) {
+ return "\n".''.
+ &mt('The required Java applet could not be started, because Java is not supported by your mobile device.').
+ "\n";
+ } else {
+ return "\n".''.
+ &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.').
+ "\n";
+ }
+}
+
+sub coursepreflink {
+ my ($text,$category)=@_;
+ if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
+ return '&"').'">'.$text.'';
+ } else {
+ return '';
+ }
+}
+
+sub raw_href_to_link {
+ my ($message)=@_;
+ $message=~s/(https?\:\/\/[^\s\'\"\<]+)([\s\<]|$)/$1<\/tt><\/a>$2/gi;
+ return $message;
+}
+
+sub entity_encode {
+ my ($text)=@_;
+ return &HTML::Entities::encode($text, '\'<>&"');
+}
+
+sub direct_parm_link {
+ my ($linktext,$symb,$filter,$part,$target)=@_;
+ $symb=&entity_encode($symb);
+ $filter=&entity_encode($filter);
+ $part=&entity_encode($part);
+ if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) {
+ return "$linktext";
+ } else {
+ return $linktext;
+ }
+}
+##############################################
+##############################################
+
+=item &confirm_success()
+
+Successful completion of an operation message
+
+=cut
+
+sub confirm_success {
+ my ($message,$failure)=@_;
+ if ($failure) {
+ return ''."\n"
+ .' '."\n"
+ .$message."\n"
+ .''."\n";
+ } else {
+ return ''."\n"
+ .' '."\n"
+ .$message."\n"
+ .''."\n";
+ }
+}
+
+##############################################
##############################################
+
+=pod
+
+=item &dragmath_button()
+
+Creates a button that launches a dragmath popup-window, in which an
+expression can be edited and pasted as LaTeX into a specified textarea.
+
+ textarea - Name of the textarea to edit.
+ helpicon - If true, show a help icon to the right of the button.
+
+=cut
+
+sub dragmath_button {
+ my ($textarea,$helpicon) = @_;
+ my $help_text;
+ if ($helpicon) {
+ $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor',undef,undef,undef,undef,'mathhelpicon_'.$textarea);
+ }
+ my $buttontext=&mt('Edit Math');
+ return <$help_text
+ENDDRAGMATH
+}
+
##############################################
=pod
-=item authorbombs
+=item &dragmath_js()
+
+Javascript used to open pop-up window containing dragmath applet which
+can be used to paste LaTeX into a textarea.
+
+=cut
+
+sub dragmath_js {
+ my ($popup) = @_;
+ return <
+ //
+
+
+ENDDRAGMATHJS
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item &dependencies_button()
+
+Creates a button that launches a popup-window, in which dependencies
+for the web page in the main window can be added to, replaced or deleted.
+
+=cut
+
+sub dependencies_button {
+ my $buttontext=&mt('Manage Dependencies');
+ return <<"END";
+
+END
+}
+
+##############################################
+
+=pod
+
+=item &dependencycheck_js()
+
+Javascript used to open pop-up window containing interface to manage
+dependencies for a web page uploaded diretcly to a course.
+
+=cut
+
+sub dependencycheck_js {
+ my ($symb,$title,$url,$folderpath,$uri) = @_;
+ my $link;
+ if ($symb) {
+ $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"');
+ } elsif ($folderpath) {
+ $link = '/adm/dependencies?folderpath='.&HTML::Entities::encode($folderpath,'<>&"');
+ $url = $uri;
+ } elsif ($uri =~ m{^/public/$match_domain/$match_courseid/syllabus$}) {
+ $link = '/adm/dependencies';
+ }
+ $link .= (($link=~/\?/)?'&':'?').'title='.
+ &HTML::Entities::encode($title,'<>&"');
+ if ($url) {
+ $link .= '&url='.&HTML::Entities::encode($url,'<>&"');
+ }
+ return <
+ //
+
+ENDJS
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item &authorbombs()
=cut
@@ -78,12 +256,12 @@ use LONCAPA;
sub authorbombs {
my $url=shift;
$url=&Apache::lonnet::declutter($url);
- my ($udom,$uname)=($url=~/^(\w+)\/(\w+)\//);
+ my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
- foreach (keys %bombs) {
- if ($_=~/^$udom\/$uname\//) {
+ foreach my $bomb (keys(%bombs)) {
+ if ($bomb =~ /^$udom\/$uname\//) {
return ''.
+ '">'.
&Apache::loncommon::help_open_topic('About_Bombs');
}
}
@@ -141,6 +319,10 @@ sub select_recent {
foreach my $value (sort(keys(%recent))) {
unless ($value =~/^error\:/) {
my $escaped = &Apache::loncommon::escape_url($value);
+ &Apache::loncommon::inhibit_menu_check(\$escaped);
+ if ($area eq 'residx') {
+ next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value)));
+ }
$return.="\n';
@@ -158,7 +340,7 @@ sub get_recent {
# Begin filling return_hash with any 'always_include' option
my %time_hash = ();
my %return_hash = ();
- foreach my $item (keys %recent) {
+ foreach my $item (keys(%recent)) {
my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
if ($thistime eq 'always_include') {
$return_hash{$item} = &unescape($thisvalue);
@@ -198,7 +380,7 @@ sub get_recent_frozen {
=pod
-=item textbox
+=item &textbox()
=cut
@@ -218,29 +400,29 @@ sub textbox {
=pod
-=item checkbox
+=item &checkbox()
=cut
##############################################
##############################################
sub checkbox {
- my ($name,$checked,$value) = @_;
+ my ($name,$checked,$value,$special) = @_;
my $Str = '';
return $Str;
}
=pod
-=item radiobutton
+=item &radiobutton()
=cut
@@ -253,7 +435,7 @@ sub radio {
$Str .= 'value="'.$value.'"';
}
if ($checked eq $value) {
- $Str .= ' checked="1"';
+ $Str .= ' checked="checked"';
}
$Str .= ' />';
return $Str;
@@ -264,10 +446,10 @@ sub radio {
=pod
-=item &date_setter
+=item &date_setter()
&date_setter returns html and javascript for a compact date-setting form.
-To retrieve values from it, use &get_date_from_form().
+To retrieve values from it, use &get_date_from_form.
Inputs
@@ -283,7 +465,8 @@ dname_hour, dname_min, and dname_sec.
The current setting for this time parameter. A unix format time
(time in seconds since the beginning of Jan 1st, 1970, GMT.
-An undefined value is taken to indicate the value is the current time.
+An undefined value is taken to indicate the value is the current time
+unless it is requested to leave it empty. See $includeempty.
Also, to be explicit, a value of 'now' also indicates the current time.
=item $special
@@ -293,10 +476,42 @@ the date_setter. See lonparmset for exa
=item $includeempty
+If it is set (true) and no date/time value is provided,
+the date/time fields are left empty.
+
=item $state
Specifies the initial state of the form elements. Either 'disabled' or empty.
-Defaults to empty, which indiciates the form elements are not disabled.
+Defaults to empty, which indicates the form elements are not disabled.
+
+=item $no_hh_mm_ss
+
+If true, text boxes for hours, minutes and seconds are omitted.
+
+=item $defhour
+
+Default value for hours (a default of 0 is used otherwise).
+
+=item $defmin
+
+Default value for minutes (a default of 0 is used otherwise).
+
+=item defsec
+
+Default value for seconds (a default of 0 is used otherwise).
+
+=item $nolink
+
+If true, a "Select calendar" link (to pop-up a calendar) is not displayed
+to the right of the items.
+
+=item $no_mm_ss
+
+If true, text boxes for minutes and seconds are omitted.
+
+=item $no_ss
+
+If true, text boxes for seconds are omitted.
=back
@@ -310,49 +525,45 @@ The method used to restrict user input w
##############################################
sub date_setter {
my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
- $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_;
- my $wasdefined=1;
+ $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$no_mm_ss,$no_ss) = @_;
+ my $now = time;
+
+ my $tzname;
+ my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.'');
+ #other potentially useful values: wkday,yrday,is_daylight_savings
+
if (! defined($state) || $state ne 'disabled') {
$state = '';
+ } else {
+ $state = 'disabled="disabled"';
}
if (! defined($no_hh_mm_ss)) {
$no_hh_mm_ss = 0;
}
if ($currentvalue eq 'now') {
- $currentvalue=time;
+ $currentvalue = $now;
}
- if ((!defined($currentvalue)) || ($currentvalue eq '')) {
- $wasdefined=0;
- if ($includeempty) {
- $currentvalue = 0;
- } else {
- $currentvalue = time;
- }
+
+ # Default value: Set empty date field to current time
+ # unless empty inclusion is requested
+ if ((!$includeempty) && (!$currentvalue)) {
+ $currentvalue = $now;
}
- # other potentially useful values: wkday,yrday,is_daylight_savings
- my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','','');
+ # Do we have a date? Split it!
if ($currentvalue) {
- ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) =
- localtime($currentvalue);
- $year += 1900;
- }
- unless ($wasdefined) {
- if (($defhour) || ($defmin) || ($defsec)) {
- ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) =
- localtime(time);
- $year += 1900;
- $sec=($defsec?$defsec:0);
- $min=($defmin?$defmin:0);
- $hour=($defhour?$defhour:0);
- } elsif (!$includeempty) {
- $sec=0;
- $min=0;
- $hour=0;
- }
+ ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
+
+ #No values provided for hour, min, sec? Use default 0
+ if (($defhour) || ($defmin) || ($defsec)) {
+ $sec = ($defsec ? $defsec : 0);
+ $min = ($defmin ? $defmin : 0);
+ $hour = ($defhour ? $defhour : 0);
+ }
}
my $result = "\n\n";
$result .= <
+//
ENDJS
- $result .= ' ';
+ $result .= ' ';
my $monthselector = qq{';
# Day
my $dayselector = qq{};
# Year
- my $yearselector = qq{};
+ my $yearselector = qq{};
#
my $hourselector = qq{\n\n";
return $result;
}
+sub get_timedates {
+ my ($epoch) = @_;
+ my $dt = DateTime->from_epoch(epoch => $epoch)
+ ->set_time_zone(&Apache::lonlocal::gettimezone());
+ my $tzname = $dt->time_zone_short_name();
+ my $sec = $dt->second;
+ my $min = $dt->minute;
+ my $hour = $dt->hour;
+ my $mday = $dt->day;
+ my $month = $dt->month;
+ if ($month) {
+ $month --;
+ }
+ my $year = $dt->year;
+ return ($tzname,$sec,$min,$hour,$mday,$month,$year);
+}
+
+sub build_url {
+ my ($base, $fields)=@_;
+ my $url;
+ $url = $base.'?';
+ foreach my $key (keys(%$fields)) {
+ $url.=&escape($key).'='.&escape($$fields{$key}).'&';
+ }
+ $url =~ s/&$//;
+ return $url;
+}
+
+
##############################################
##############################################
=pod
-=item &get_date_from_form
+=item &get_date_from_form()
get_date_from_form retrieves the date specified in an &date_setter form.
@@ -496,7 +747,7 @@ Inputs:
=item $dname
-The name passed to &datesetter, which prefixes the form elements.
+The name passed to &date_setter, which prefixes the form elements.
=item $defaulttime
@@ -549,20 +800,33 @@ sub get_date_from_form {
if (defined($env{'form.'.$dname.'_month'})) {
my $tmpmonth = $env{'form.'.$dname.'_month'};
if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
- $month = $tmpmonth - 1;
+ $month = $tmpmonth;
}
}
if (defined($env{'form.'.$dname.'_year'})) {
my $tmpyear = $env{'form.'.$dname.'_year'};
- if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) {
- $year = $tmpyear - 1900;
+ if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
+ $year = $tmpyear;
}
}
- if (($year<70) || ($year>137)) { return undef; }
+ if (($year<1970) || ($year>2037)) { return undef; }
if (defined($sec) && defined($min) && defined($hour) &&
- defined($day) && defined($month) && defined($year) &&
- eval('&timelocal($sec,$min,$hour,$day,$month,$year)')) {
- return &timelocal($sec,$min,$hour,$day,$month,$year);
+ defined($day) && defined($month) && defined($year)) {
+ my $timezone = &Apache::lonlocal::gettimezone();
+ my $dt = DateTime->new( year => $year,
+ month => $month,
+ day => $day,
+ hour => $hour,
+ minute => $min,
+ second => $sec,
+ time_zone => $timezone,
+ );
+ my $epoch_time = $dt->epoch;
+ if ($epoch_time ne '') {
+ return $epoch_time;
+ } else {
+ return undef;
+ }
} else {
return undef;
}
@@ -585,13 +849,12 @@ parameter setting wizard.
sub pjump_javascript_definition {
my $Str = <'.
- &mt('Currently Enrolled').''."\n";
- $Str .= ''."\n";
- $Str .= ''."\n";
+ foreach my $type (['Active', &mt('Currently Has Access')],
+ ['Future', &mt('Will Have Future Access')],
+ ['Expired', &mt('Previously Had Access')],
+ ['Any', &mt('Any Access Status')]) {
+ my ($name,$label) = @$type;
+ $Str .= '';
+
+
+ return $output;
}
# --------------------- A function that generates a window for the spellchecker
@@ -1039,16 +1229,18 @@ sub spellheader {
my $nothing=&javascript_nothing();
return (<
+// <\/form>$end_page');
+ checkwin.document.writeln('$start_page