--- loncom/interface/lonhtmlcommon.pm 2004/09/29 14:50:43 1.90
+++ loncom/interface/lonhtmlcommon.pm 2010/08/08 02:00:38 1.282
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.90 2004/09/29 14:50:43 www Exp $
+# $Id: lonhtmlcommon.pm,v 1.282 2010/08/08 02:00:38 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -55,10 +55,106 @@ html.
package Apache::lonhtmlcommon;
+use strict;
use Time::Local;
use Time::HiRes;
use Apache::lonlocal;
-use strict;
+use Apache::lonnet;
+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;
+}
+
+##############################################
+##############################################
+
+=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 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
+}
+
##############################################
##############################################
@@ -75,12 +171,12 @@ use strict;
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');
}
}
@@ -92,29 +188,35 @@ sub authorbombs {
sub recent_filename {
my $area=shift;
- return 'nohist_recent_'.&Apache::lonnet::escape($area);
+ return 'nohist_recent_'.&escape($area);
}
sub store_recent {
- my ($area,$name,$value)=@_;
+ my ($area,$name,$value,$freeze)=@_;
my $file=&recent_filename($area);
my %recent=&Apache::lonnet::dump($file);
- if (scalar(keys(%recent))>10) {
+ if (scalar(keys(%recent))>20) {
# remove oldest value
- my $oldest=time;
+ my $oldest=time();
my $delkey='';
- foreach (keys %recent) {
- my $thistime=(split(/\&/,$recent{$_}))[0];
- if ($thistime<$oldest) {
+ foreach my $item (keys(%recent)) {
+ my $thistime=(split(/\&/,$recent{$item}))[0];
+ if (($thistime ne "always_include") && ($thistime<$oldest)) {
$oldest=$thistime;
- $delkey=$_;
+ $delkey=$item;
}
}
&Apache::lonnet::del($file,[$delkey]);
}
# store new value
+ my $timestamp;
+ if ($freeze) {
+ $timestamp = "always_include";
+ } else {
+ $timestamp = time();
+ }
&Apache::lonnet::put($file,{ $name =>
- time.'&'.&Apache::lonnet::escape($value) });
+ $timestamp.'&'.&escape($value) });
}
sub remove_recent {
@@ -127,12 +229,17 @@ sub select_recent {
my ($area,$fieldname,$event)=@_;
my %recent=&Apache::lonnet::dump(&recent_filename($area));
my $return="\n'."\n";
}
@@ -679,7 +927,7 @@ Returns: none
=item Increment_PrgWin
-Increment the count of items completed for the progress window by 1.
+Increment the count of items completed for the progress window by $step or 1 if no step is provided.
Inputs:
@@ -692,6 +940,8 @@ Inputs:
=item $extraInfo A description of the items being iterated over. Typically
'student'.
+=item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
+
=back
Returns: none
@@ -736,35 +986,41 @@ sub Create_PrgWin {
$prog_state{'type'}=$type;
if ($type eq 'popup') {
$prog_state{'window'}='popwin';
+ my $start_page =
+ &Apache::loncommon::start_page($title,undef,
+ {'only_body' => 1,
+ 'bgcolor' => '#88DDFF',
+ 'js_ready' => 1});
+ my $end_page = &Apache::loncommon::end_page({'js_ready' => 1});
+
#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)"
+ ));
$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,'