--- loncom/interface/lonhtmlcommon.pm 2003/06/11 14:20:29 1.23
+++ loncom/interface/lonhtmlcommon.pm 2009/08/10 12:32:34 1.229
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.23 2003/06/11 14:20:29 matthew Exp $
+# $Id: lonhtmlcommon.pm,v 1.229 2009/08/10 12:32:34 droeschl Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -55,8 +55,290 @@ html.
package Apache::lonhtmlcommon;
-use Time::Local;
use strict;
+use Time::Local;
+use Time::HiRes;
+use Apache::lonlocal;
+use Apache::lonnet;
+use LONCAPA;
+
+##############################################
+##############################################
+
+=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
+}
+
+
+##############################################
+##############################################
+
+=pod
+
+=item authorbombs
+
+=cut
+
+##############################################
+##############################################
+
+sub authorbombs {
+ my $url=shift;
+ $url=&Apache::lonnet::declutter($url);
+ 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\//) {
+ return ''.
+ &Apache::loncommon::help_open_topic('About_Bombs');
+ }
+ }
+ return '';
+}
+
+##############################################
+##############################################
+
+sub recent_filename {
+ my $area=shift;
+ return 'nohist_recent_'.&escape($area);
+}
+
+sub store_recent {
+ my ($area,$name,$value,$freeze)=@_;
+ my $file=&recent_filename($area);
+ my %recent=&Apache::lonnet::dump($file);
+ if (scalar(keys(%recent))>20) {
+# remove oldest value
+ my $oldest=time();
+ my $delkey='';
+ foreach my $item (keys(%recent)) {
+ my $thistime=(split(/\&/,$recent{$item}))[0];
+ if (($thistime ne "always_include") && ($thistime<$oldest)) {
+ $oldest=$thistime;
+ $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 =>
+ $timestamp.'&'.&escape($value) });
+}
+
+sub remove_recent {
+ my ($area,$names)=@_;
+ my $file=&recent_filename($area);
+ return &Apache::lonnet::del($file,$names);
+}
+
+sub select_recent {
+ my ($area,$fieldname,$event)=@_;
+ my %recent=&Apache::lonnet::dump(&recent_filename($area));
+ my $return="\n\n";
+ return $return;
+}
+
+sub get_recent {
+ my ($area, $n) = @_;
+ my %recent=&Apache::lonnet::dump(&recent_filename($area));
+
+# Create hash with key as time and recent as value
+# Begin filling return_hash with any 'always_include' option
+ my %time_hash = ();
+ my %return_hash = ();
+ foreach my $item (keys %recent) {
+ my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
+ if ($thistime eq 'always_include') {
+ $return_hash{$item} = &unescape($thisvalue);
+ $n--;
+ } else {
+ $time_hash{$thistime} = $item;
+ }
+ }
+
+# Sort by decreasing time and return key value pairs
+ my $idx = 1;
+ foreach my $item (reverse(sort(keys(%time_hash)))) {
+ $return_hash{$time_hash{$item}} =
+ &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
+ if ($n && ($idx++ >= $n)) {last;}
+ }
+
+ return %return_hash;
+}
+
+sub get_recent_frozen {
+ my ($area) = @_;
+ my %recent=&Apache::lonnet::dump(&recent_filename($area));
+
+# Create hash with all 'frozen' items
+ my %return_hash = ();
+ foreach my $item (keys(%recent)) {
+ my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
+ if ($thistime eq 'always_include') {
+ $return_hash{$item} = &unescape($thisvalue);
+ }
+ }
+ return %return_hash;
+}
+
+
+
+=pod
+
+=item textbox
+
+=cut
+
+##############################################
+##############################################
+sub textbox {
+ my ($name,$value,$size,$special) = @_;
+ $size = 40 if (! defined($size));
+ $value = &HTML::Entities::encode($value,'<>&"');
+ my $Str = '';
+ return $Str;
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item checkbox
+
+=cut
+
+##############################################
+##############################################
+sub checkbox {
+ my ($name,$checked,$value) = @_;
+ my $Str = '\n";
$result .= <
+
ENDJS
- $result .= " '."\n";
-}
-
-
-########################################################
-########################################################
-
-=pod
-
-=item &MultipleSectionSelect()
-
-Inputs:
-
-=over 4
-
-=item $sections A references to an array containing the names of all the
-sections used in a class.
-
-=item $selectedSections A reference to an array containing the names of the
-currently selected sections.
-
-=back
-
-Returns: a string containing HTML for a multiple select box for
-selecting sections of a course.
-
-The form element name is 'Section'. @$sections is sorted prior to output.
-
-=cut
-
-########################################################
-########################################################
-sub MultipleSectionSelect {
- my ($sections,$selectedSections)=@_;
-
- my $Str = '';
- $Str .= ''."\n";
-
- foreach (sort @$sections) {
- $Str .= ''."\n";
-
- return $Str;
-}
-
-########################################################
-########################################################
-
-=pod
-
-=item &Title()
-
-Inputs: $pageName a string containing the name of the page to be sent
-to &Apache::loncommon::bodytag.
-
-Returns: string containing being and complete and
-as well as a '."\n";
-
- return $Str;
-}
-
-########################################################
-########################################################
-
-=pod
-
-=item &CreateHeadings()
-
-This function generates the column headings for the chart.
-
-=over 4
-
-Inputs: $CacheData, $keyID, $headings, $spacePadding
-
-$CacheData: pointer to a hash tied to the cached data database
-
-$keyID: a pointer to an array containing the names of the data
-held in a column and is used as part of a key into $CacheData
-
-$headings: The names of the headings for the student information
-
-$spacePadding: The spaces to go between columns
-
-Output: $Str
-
-$Str: A formatted string of the table column headings.
-
-=back
-
-=cut
-
-########################################################
-########################################################
-sub CreateHeadings {
- my ($data,$keyID,$headings,$displayString,$format)=@_;
- my $Str='';
- my $formatting = '';
-
- for(my $index=0; $index<(scalar @$headings); $index++) {
- my $currentHeading=$headings->[$index];
- if($format eq 'preformatted') {
- my @dataLength=split(//,$currentHeading);
- my $length=scalar @dataLength;
- $formatting = (' 'x
- ($data->{$keyID->[$index].':columnWidth'}-$length));
- }
- my $linkdata=$keyID->[$index];
-
- my $tempString = $displayString;
- $tempString =~ s/LINKDATA/$linkdata/;
- $tempString =~ s/DISPLAYDATA/$currentHeading/;
- $tempString =~ s/FORMATTING/$formatting/;
-
- $Str .= $tempString;
- }
-
- return $Str;
-}
-
-########################################################
-########################################################
-
-=pod
-
-=item &FormatStudentInformation()
-
-This function produces a formatted string of the student\'s information:
-username, domain, section, full name, and PID.
-
-=over 4
-
-Input: $cache, $name, $keyID, $spacePadding
-
-$cache: This is a pointer to a hash that is tied to the cached data
-
-$name: The name and domain of the current student in name:domain format
-
-$keyID: A pointer to an array holding the names used to
-
-remove data from the hash. They represent the name of the data to be removed.
-
-$spacePadding: Extra spaces that represent the space between columns
-
-Output: $Str
-
-$Str: Formatted string.
-
-=back
-
-=cut
-
-########################################################
-########################################################
-sub FormatStudentInformation {
- my ($data,$name,$keyID,$displayString,$format)=@_;
- my $Str='';
- my $currentColumn;
-
- for(my $index=0; $index<(scalar @$keyID); $index++) {
- $currentColumn=$data->{$name.':'.$keyID->[$index]};
-
- if($format eq 'preformatted') {
- my @dataLength=split(//,$currentColumn);
- my $length=scalar @dataLength;
- $currentColumn.= (' 'x
- ($data->{$keyID->[$index].':columnWidth'}-$length));
- }
-
- my $tempString = $displayString;
- $tempString =~ s/DISPLAYDATA/$currentColumn/;
-
- $Str .= $tempString;
+ 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 .= '