--- loncom/interface/lonhtmlcommon.pm 2006/06/22 23:22:41 1.136
+++ loncom/interface/lonhtmlcommon.pm 2010/03/19 22:34:23 1.182.4.13
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.136 2006/06/22 23:22:41 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.182.4.13 2010/03/19 22:34:23 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,9 +60,104 @@ use Time::Local;
use Time::HiRes;
use Apache::lonlocal;
use Apache::lonnet;
-use lib '/home/httpd/lib/perl/';
use LONCAPA;
+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;
+}
+
+##############################################
+##############################################
+
+=pod
+
+=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');
+ }
+ my $buttontext=&mt('Edit Math');
+ return <$help_text
+ENDDRAGMATH
+}
+
+##############################################
+
+=pod
+
+=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
+}
+
+
##############################################
##############################################
@@ -78,7 +173,7 @@ 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\//) {
@@ -141,6 +236,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';
@@ -231,7 +330,7 @@ sub checkbox {
$Str .= 'value="'.$value.'"';
}
if ($checked) {
- $Str .= ' checked="1"';
+ $Str .= ' checked="checked"';
}
$Str .= ' />';
return $Str;
@@ -253,7 +352,7 @@ sub radio {
$Str .= 'value="'.$value.'"';
}
if ($checked eq $value) {
- $Str .= ' checked="1"';
+ $Str .= ' checked="checked"';
}
$Str .= ' />';
return $Str;
@@ -311,6 +410,7 @@ 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 $now = time;
my $wasdefined=1;
if (! defined($state) || $state ne 'disabled') {
$state = '';
@@ -319,28 +419,25 @@ sub date_setter {
$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;
+ $currentvalue = $now;
}
}
# other potentially useful values: wkday,yrday,is_daylight_savings
+ my $tzname;
my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','','');
if ($currentvalue) {
- ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) =
- localtime($currentvalue);
- $year += 1900;
+ ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
}
unless ($wasdefined) {
if (($defhour) || ($defmin) || ($defsec)) {
- ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) =
- localtime(time);
- $year += 1900;
+ ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now);
$sec=($defsec?$defsec:0);
$min=($defmin?$defmin:0);
$hour=($defhour?$defhour:0);
@@ -353,6 +450,7 @@ sub date_setter {
my $result = "\n\n";
$result .= <
+//
ENDJS
$result .= ' ';
@@ -424,23 +523,23 @@ ENDJS
unshift(@Months,'If you can read this an error occurred');
if ($includeempty) { $monthselector.=""; }
for(my $m = 1;$m <=$#Months;$m++) {
- $monthselector .= qq{ ');
+ $result .= &mt('[_1]Select Date[_2]',$cal_link,'');
}
} else {
$result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
$monthselector,$dayselector,$yearselector,
- $hourselector,$minuteselector,$secondselector);
+ $hourselector,$minuteselector,$secondselector).
+ $tzone;
if (!$nolink) {
- $result .= &mt('[_7]Select Date[_8]',$cal_link,'');
+ $result .= &mt('[_1]Select Date[_2]',$cal_link,'');
}
}
$result .= "\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;
+}
+
+
##############################################
##############################################
@@ -496,7 +627,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 +680,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;
}
@@ -632,6 +776,8 @@ sub javascript_nothing {
##############################################
##############################################
sub javascript_docopen {
+ my ($mimetype) = @_;
+ $mimetype ||= 'text/html';
# safari does not understand document.open() and loads "text/html"
my $nothing = "''";
my $user_browser;
@@ -645,7 +791,7 @@ sub javascript_docopen {
if ($user_browser eq 'safari' && $user_os =~ 'mac') {
$nothing = "document.clear()";
} else {
- $nothing = "document.open('text/html','replace')";
+ $nothing = "document.open('$mimetype','replace')";
}
return $nothing;
}
@@ -682,23 +828,18 @@ Returns: a perl string as described.
##############################################
##############################################
sub StatusOptions {
- my ($status, $formName,$size,$onchange)=@_;
+ my ($status, $formName,$size,$onchange,$mult)=@_;
$size = 1 if (!defined($size));
if (! defined($status)) {
$status = 'Active';
$status = $env{'form.Status'} if (exists($env{'form.Status'}));
}
- my $OpSel1 = '';
- my $OpSel2 = '';
- my $OpSel3 = '';
-
- if($status eq 'Any') { $OpSel3 = ' selected'; }
- elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
- else { $OpSel1 = ' selected'; }
-
my $Str = '';
$Str .= ''."\n";
}
@@ -849,32 +996,34 @@ sub Create_PrgWin {
#the whole function called through timeout is due to issues
#in mozilla Read BUG #2665 if you want to know the whole story
- &r_print($r,'");
+ "\nwindow.setTimeout(openpopwin,0)\n".
+ '// ]]>'."\n".
+ '');
$prog_state{'formname'}='popremain';
$prog_state{'inputname'}="remaining";
} elsif ($type eq 'inline') {
$prog_state{'window'}='window';
if (!$formname) {
$prog_state{'formname'}=&get_uniq_name();
- &r_print($r,'