--- loncom/interface/loncommon.pm	2003/06/06 02:24:49	1.103
+++ loncom/interface/loncommon.pm	2003/06/24 22:16:32	1.107
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.103 2003/06/06 02:24:49 www Exp $
+# $Id: loncommon.pm,v 1.107 2003/06/24 22:16:32 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -586,6 +586,26 @@ ENDTEMPLATE
 
 }
 
+# This is a quicky function for Latex cheatsheet editing, since it 
+# appears in at least four places
+sub helpLatexCheatsheet {
+    my $other = shift;
+    my $addOther = '';
+    if ($other) {
+	$addOther = Apache::loncommon::help_open_topic($other, shift,
+						       undef, undef, 600) .
+							   '</td><td>';
+    }
+    return '<table><tr><td>'.
+	$addOther .
+	&Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
+					    undef,undef,600)
+	.'</td><td>'.
+	&Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
+					    undef,undef,600)
+	.'</td></tr></table>';
+}
+
 =pod
 
 =item csv_translate($text) 
@@ -1358,6 +1378,12 @@ sub display_languages {
 	    $languages{$_}=1;
         }
     }
+    if ($ENV{'course.'.$ENV{'request.course.id'}.'.languages'}) {
+	foreach (split(/\s*(\,|\;|\:)\s*/,
+	$ENV{'course.'.$ENV{'request.course.id'}.'.languages'})) {
+	    $languages{$_}=1;
+        }
+    }
     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
     if ($ENV{'form.displaylanguage'}) {
 	foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'form.displaylanguage'})) {
@@ -1485,6 +1511,41 @@ sub get_previous_attempt {
   }
 }
 
+sub relative_to_absolute {
+    my ($url,$output)=@_;
+    my $parser=HTML::TokeParser->new(\$output);
+    my $token;
+    my $thisdir=$url;
+    my @rlinks=();
+    while ($token=$parser->get_token) {
+	if ($token->[0] eq 'S') {
+	    if ($token->[1] eq 'a') {
+		if ($token->[2]->{'href'}) {
+		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
+		}
+	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
+		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
+	    } elsif ($token->[1] eq 'base') {
+		$thisdir=$token->[2]->{'href'};
+	    }
+	}
+    }
+    $thisdir=~s-/[^/]*$--;
+    foreach (@rlinks) {
+	unless (($_=~/^http:\/\//i) ||
+		($_=~/^\//) ||
+		($_=~/^javascript:/i) ||
+		($_=~/^mailto:/i) ||
+		($_=~/^\#/)) {
+	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$_);
+	    $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
+	}
+    }
+# -------------------------------------------------- Deal with Applet codebases
+    $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
+    return $output;
+}
+
 sub get_student_view {
   my ($symb,$username,$domain,$courseid,$target) = @_;
   my ($map,$id,$feedurl) = split(/___/,$symb);
@@ -1496,7 +1557,8 @@ sub get_student_view {
   }
   if ($target eq 'tex') {$moreenv{'form.grade_target'} = 'tex';}
   &Apache::lonnet::appenv(%moreenv);
-  my $userview=&Apache::lonnet::ssi('/res/'.$feedurl);
+  $feedurl=&Apache::lonnet::clutter($feedurl);
+  my $userview=&Apache::lonnet::ssi_body($feedurl);
   &Apache::lonnet::delenv('form.grade_');
   foreach my $element (@elements) {
     $ENV{'form.grade_'.$element}=$old{$element};
@@ -1508,6 +1570,7 @@ sub get_student_view {
   $userview=~s/\<head\>//gi;
   $userview=~s/\<\/head\>//gi;
   $userview=~s/action\s*\=/would_be_action\=/gi;
+  $userview=&relative_to_absolute($feedurl,$userview);
   return $userview;
 }