--- loncom/homework/randomlabel.pm 2003/09/08 19:08:57 1.47
+++ loncom/homework/randomlabel.pm 2003/10/30 20:52:54 1.52
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# random labelling tool
#
-# $Id: randomlabel.pm,v 1.47 2003/09/08 19:08:57 albertel Exp $
+# $Id: randomlabel.pm,v 1.52 2003/10/30 20:52:54 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -92,7 +92,8 @@ sub start_randomlabel {
}
my $w= &check_int(&Apache::lonxml::get_param('width',$parstack,$safeeval));
my $h= &check_int(&Apache::lonxml::get_param('height',$parstack,$safeeval));
- my $texwidth= &Apache::lonxml::get_param('texwidth',$parstack,$safeeval);
+ my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1));
+ if (!$texwidth) { $texwidth=90; }
$Apache::randomlabel::tlabel_cnt=0;
$Apache::randomlabel::ilabel_cnt=0;
if ($target eq 'web') {
@@ -119,20 +120,14 @@ sub start_randomlabel {
$temp_file = Apache::File->new('>>'.$filename);
$newbgimg =~ s/(.*)\/res\//\/home\/httpd\/html\/res\//;
print $temp_file "$newbgimg\n";
- $bgimg =~ m/\/([^\/]+)$/;
- $bgimg = '/home/httpd/prtspool/'.$1;
- }
+ $bgimg=~s/\/home\/httpd\/html\/res/\/home\/httpd\/prtspool/; }
}
}
$bgimg=~s/\/$//;
my $dirtywidth=$texwidth+5;
- if ($texwidth==90) {
- $result.='\vspace*{2mm}\noindent \parbox{'.$dirtywidth.' mm}{ \noindent \epsfxsize='.$texwidth.' mm \epsffile{'.
- $bgimg.'}\setlength{\unitlength}{1mm} \begin{picture}('.$texwidth.','.$texwidth*$h/$w.')(0,-'.$texwidth*$h/$w.')';
- } else {
- $result.='\vspace*{2mm}\noindent \parbox{'.$dirtywidth.' mm}{ \noindent \epsfxsize='.$texwidth.' mm \epsffile{'.
- $bgimg.'}\setlength{\unitlength}{1mm} \begin{picture}('.$texwidth.','.$texwidth*$h/$w.')(0,-'.$texwidth*$h/$w.')';
- }
+ $result.='\vspace*{2mm}\noindent \parbox{'.$dirtywidth.' mm}{ \noindent \epsfxsize='.
+ $texwidth.' mm \epsffile{'.$bgimg.'}\setlength{\unitlength}{1mm} \begin{picture}('.
+ $texwidth.','.$texwidth*$h/$w.')(0,-'.$texwidth*$h/$w.')';
} elsif ($target eq 'edit') {
$result.=&Apache::edit::tag_start($target,$token);
$Apache::edit::bgimgsrc=
@@ -178,7 +173,8 @@ sub end_randomlabel {
$result='\end{picture}\\\\';
my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
- my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval);
+ my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1));
+ if (!$texwidth) { $texwidth=90; }
my $howtoskipback = $texwidth*$height/$width;
$result.= ' \vskip -'.$howtoskipback.' mm } \\\\ ';
} elsif ($target eq 'edit') {
@@ -187,12 +183,23 @@ sub end_randomlabel {
return $result;
}
+sub adjust_textwidth {
+ my $texwidth=shift;
+ my $pagewidth=$ENV{'form.textwidth'};
+ $pagewidth=~s/\s*mm\s*$//;
+ if ($texwidth>$pagewidth) {$texwidth=$pagewidth;}
+ return $texwidth;
+}
+
sub start_labelgroup {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
$type =~tr/A-Z/a-z/;
+ if ($target ne 'modified' && ($name =~ /\W/ || $name =~ /^[0-9]/)) {
+ &Apache::lonxml::error("Only _ a-z A-Z and 0-9 are allowed in the name to a labelgroup, and the first character can not be a number.
");
+ }
if ($target eq 'web' || $target eq 'tex' ||
$target eq 'grade' || $target eq 'answer' || $target eq 'analyze') {
$Apache::randomlabel::groupname=$name;
@@ -282,7 +289,8 @@ sub end_labelgroup {
my $WY1=0; # Web y-coord. of (ULC)
my $wwidth=&Apache::lonxml::get_param('width',$parstack,$safeeval,-2);
my $wheight=&Apache::lonxml::get_param('height',$parstack,$safeeval,-2);
- my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,-2);
+ my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,-2,1));
+ if (!$texwidth) { $texwidth=90; }
my $TX1=0;
my $TY1=$texwidth*($wheight/$wwidth);
my $TX2=$texwidth;
@@ -396,7 +404,6 @@ sub start_label {
$result.=&Apache::edit::editline('',$text,'',50).
&Apache::edit::end_table();
} elsif ($target eq 'modified') {
- my $text=$$parser[-1]->get_text("/label");
$result = '