--- loncom/interface/loncommon.pm 2002/06/24 19:06:05 1.38 +++ loncom/interface/loncommon.pm 2002/07/01 15:24:44 1.42 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.38 2002/06/24 19:06:05 albertel Exp $ +# $Id: loncommon.pm,v 1.42 2002/07/01 15:24:44 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -85,7 +85,7 @@ my $readit; my %language; my %cprtag; my %fe; my %fd; -my %fc; +my %category_extensions; # -------------------------------------------------------------- Thesaurus data my @therelated; @@ -146,8 +146,8 @@ BEGIN { while (<$fh>) { next if /^\#/; chomp; - my ($key,$val)=(split(/\s+/,$_,2)); - push @{$fc{$key}},$val; + my ($extension,$category)=(split(/\s+/,$_,2)); + push @{$category_extensions{lc($category)}},$extension; } } } @@ -190,6 +190,92 @@ BEGIN { } # ============================================================= END BEGIN BLOCK +############################################################### +## HTML and Javascript Helper Functions ## +############################################################### + +=pod + +=item browser_and_searcher_javascript + +Returns scalar containing javascript to open a browser window +or a searcher window. Also creates + +=over 4 + +=item openbrowser(formname,elementname,only,omit) [javascript] + +inputs: formname, elementname, only, omit + +formname and elementname indicate the name of the html form and name of +the element that the results of the browsing selection are to be placed in. + +Specifying 'only' will restrict the browser to displaying only files +with the given extension. Can be a comma seperated list. + +Specifying 'omit' will restrict the browser to NOT displaying files +with the given extension. Can be a comma seperated list. + +=item opensearcher(formname, elementname) [javascript] + +Inputs: formname, elementname + +formname and elementname specify the name of the html form and the name +of the element the selection from the search results will be placed in. + +=back + +=cut + +############################################################### +sub browser_and_searcher_javascript { + return <{'text'}. The values +first menu value is given in $menu{$choice1}->{'text'}. The values and text for the second menu are given in the hash pointed to by $menu{$choice1}->{'select2'}. - my %menu = ( A1 => { text =>"Choice A1" , +my %menu = ( A1 => { text =>"Choice A1" , default => "B3", select2 => { B1 => "Choice B1", @@ -741,12 +829,12 @@ sub copyrightdescription { # ------------------------------------------------------------- File Categories sub filecategories { - return sort(keys(%fc)); + return sort(keys(%category_extensions)); } # -------------------------------------- File Types within a specified category sub filecategorytypes { - return @{$fc{lc(shift(@_))}}; + return @{$category_extensions{lc($_[0])}}; } # ------------------------------------------------------------------ File Types @@ -770,8 +858,18 @@ sub filedescriptionex { return '.'.$ex.' '.$fd{lc($ex)}; } +# ---- Retrieve attempts by students +# input +# $symb - problem including path +# $username,$domain - that of the student +# $course - course name +# $getattempt - leave blank if want all attempts, else put something. +# +# output +# formatted as a table all the attempts, if any. +# sub get_previous_attempt { - my ($symb,$username,$domain,$course)=@_; + my ($symb,$username,$domain,$course,$getattempt)=@_; my $prevattempts=''; if ($symb) { my (%returnhash)= @@ -784,13 +882,14 @@ sub get_previous_attempt { $lasthash{$_}=$returnhash{$version.':'.$_}; } } - $prevattempts=''; + $prevattempts='
History
'; + $prevattempts.=''; foreach (sort(keys %lasthash)) { my ($ign,@parts) = split(/\./,$_); if ($#parts > 0) { my $data=$parts[-1]; pop(@parts); - $prevattempts.=''; + $prevattempts.=''; } else { if ($#parts == 0) { $prevattempts.=''; @@ -799,19 +898,21 @@ sub get_previous_attempt { } } } - for ($version=1;$version<=$returnhash{'version'};$version++) { - $prevattempts.=''; - foreach (sort(keys %lasthash)) { - my $value; - if ($_ =~ /timestamp/) { - $value=scalar(localtime($returnhash{$version.':'.$_})); - } else { - $value=$returnhash{$version.':'.$_}; - } - $prevattempts.=''; - } + if ($getattempt eq '') { + for ($version=1;$version<=$returnhash{'version'};$version++) { + $prevattempts.=''; + foreach (sort(keys %lasthash)) { + my $value; + if ($_ =~ /timestamp/) { + $value=scalar(localtime($returnhash{$version.':'.$_})); + } else { + $value=$returnhash{$version.':'.$_}; + } + $prevattempts.=''; + } + } } - $prevattempts.=''; + $prevattempts.=''; foreach (sort(keys %lasthash)) { my $value; if ($_ =~ /timestamp/) { @@ -819,9 +920,9 @@ sub get_previous_attempt { } else { $value=$lasthash{$_}; } - $prevattempts.=''; + $prevattempts.=''; } - $prevattempts.='
HistoryPart '.join('.',@parts).'
'.$data.'
Part '.join('.',@parts).'
'.$data.' 
'.$parts[0].'
Attempt '.$version.''.$value.'
Transaction '.$version.''.$value.' 
Current
Current'.$value.''.$value.' 
'; + $prevattempts.='
'; } else { $prevattempts='Nothing submitted - no attempts.'; } @@ -930,8 +1031,6 @@ sub add_to_env { =pod -=back - =head2 CSV Upload/Handling functions =over 4