[LON-CAPA-cvs] cvs: loncom /homework imageresponse.pm randomlabel.pm randomlylabel.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 11 Nov 2003 00:25:25 -0000


This is a MIME encoded message

--albertel1068510325
Content-Type: text/plain

albertel		Mon Nov 10 19:25:25 2003 EDT

  Modified files:              
    /loncom/homework	randomlabel.pm randomlylabel.pm imageresponse.pm 
  Log:
  - modified to use the cgi.$id. mechanism 
  
  
--albertel1068510325
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20031110192525.txt"

Index: loncom/homework/randomlabel.pm
diff -u loncom/homework/randomlabel.pm:1.52 loncom/homework/randomlabel.pm:1.53
--- loncom/homework/randomlabel.pm:1.52	Thu Oct 30 15:52:54 2003
+++ loncom/homework/randomlabel.pm	Mon Nov 10 19:25:24 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # random labelling tool
 #
-# $Id: randomlabel.pm,v 1.52 2003/10/30 20:52:54 albertel Exp $
+# $Id: randomlabel.pm,v 1.53 2003/11/11 00:25:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -63,6 +63,9 @@
 use Apache::File();
 use Apache::Constants qw(:common :http);
 
+my %args;
+my $cgi_id;
+
 BEGIN {
     &Apache::lonxml::register('Apache::randomlabel',('randomlabel','labelgroup','location','label'));
 }
@@ -97,8 +100,9 @@
     $Apache::randomlabel::tlabel_cnt=0;
     $Apache::randomlabel::ilabel_cnt=0;
     if ($target eq 'web') {
-	&Apache::lonxml::startredirection();
-	$result.="BGIMG=".&Apache::lonnet::escape($bgimg);
+	$cgi_id=&Apache::loncommon::get_cgi_id();
+	%args=();
+	$args{"cgi.$cgi_id.BGIMG"}=&Apache::lonnet::escape($bgimg);
     } elsif ($target eq 'tex') {
 	my $newbgimg = $bgimg;
 	$bgimg=~s/\.(gif|jpg|png|jpeg)$/\.eps/i;
@@ -158,17 +162,12 @@
     my $count;
     pop @Apache::lonxml::namespace;
     if ($target eq 'web') {
-	my $args=&Apache::lonxml::endredirection();
-	$args=~s/\s*&/&/g;
-	$args=~s/\s*$//;
 	$count = $Apache::randomlabel::tlabel_cnt;
-	if( $count != 0) { $args.= "&COUNT=$count"; }
+	if( $count != 0) { $args{"cgi.$cgi_id.COUNT"}=$count; }
 	$count = $Apache::randomlabel::ilabel_cnt;
-	if( $count != 0) { $args.= "&ICOUNT=$count"; }
-	my $token=$Apache::lonxml::curdepth.'_'.$$;
-	$result.='<img src="/adm/randomlabel.png?token='.$token;
-	$result.='" /><br />'."\n";
-	&Apache::lonnet::appenv(("imagerequest.$token"=>&Apache::lonnet::escape($args)));
+	if( $count != 0) { $args{"cgi.$cgi_id.ICOUNT"}=$count; }
+	$result.='<img src="/adm/randomlabel.png?token='.$cgi_id.'" /><br />'."\n";
+	&Apache::lonnet::appenv(%args);
     } elsif ($target eq 'tex') {
 	$result='\end{picture}\\\\';
 	my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
@@ -279,9 +278,9 @@
 		&Apache::lonxml::error('Unknown type of label :'.$type.':');
 	    }
 	    if ($target eq 'web') {
-		$result .= '&'. $str  .'='.&Apache::lonnet::escape($label);
-		$result .= '&'. $xstr .'='.$x;
-		$result .= '&'. $ystr .'='.$y;
+		$args{"cgi.$cgi_id.$str"} =&Apache::lonnet::escape($label);
+		$args{"cgi.$cgi_id.$xstr"}=$x;
+		$args{"cgi.$cgi_id.$ystr"}=$y;
 	    }
 	}
     } elsif ($target eq 'tex') {
Index: loncom/homework/randomlylabel.pm
diff -u loncom/homework/randomlylabel.pm:1.10 loncom/homework/randomlylabel.pm:1.11
--- loncom/homework/randomlylabel.pm:1.10	Mon Nov 10 18:29:27 2003
+++ loncom/homework/randomlylabel.pm	Mon Nov 10 19:25:24 2003
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # randomlabel.png: composite together text and images into 1 image
 #
-# $Id: randomlylabel.pm,v 1.10 2003/11/10 23:29:27 albertel Exp $
+# $Id: randomlylabel.pm,v 1.11 2003/11/11 00:25:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,13 +60,11 @@
 sub handler {
     my $r = shift;
     $r->content_type('image/png');
-    my (undef,$token) = split(/=/,$ENV{'QUERY_STRING'});
-    &Apache::loncommon::get_unprocessed_cgi(
-               &Apache::lonnet::unescape($ENV{'imagerequest.'.$token}));
-    my $image=&get_image($ENV{"form.BGIMG"},0);
+    my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'});
+    my $image=&get_image(&Apache::lonnet::unescape($ENV{"cgi.$id.BGIMG"}),0);
     if (! defined($image)) {
-        &Apache::lonnet::logthis('Unable to create image object for '.
-				 $ENV{"form.BGIMG"});
+        &Apache::lonnet::logthis('Unable to create image object for -'.$id.'-'.
+				 $ENV{"cgi.$id.BGIMG"});
         return OK;
     }
     #binmode(STDOUT);
@@ -74,28 +72,24 @@
     if (!($black=$image->colorResolve(0,0,0))) {
 	$black = $image->colorClosestHWB(0,0,0);
     }
-    for(my $i=0;$i<$ENV{"form.ICOUNT"};$i++) {
-	my $subimage=&get_image($ENV{"form.IMG$i"},1);
+    for(my $i=0;$i<$ENV{"cgi.$id.ICOUNT"};$i++) {
+	my $subimage=&get_image(&Apache::lonnet::unescape($ENV{"cgi.$id.IMG$i"}),1);
 	if (!defined($subimage)) {
             &Apache::lonnet::logthis('Unable to create image object for '.
-                                 $ENV{"form.BGIMG"});
+                                 $ENV{"cgi.$id.BGIMG"});
             next;
         }
-	$image->copy($subimage,$ENV{"form.IX$i"},$ENV{"form.IY$i"},
+	$image->copy($subimage,$ENV{"cgi.$id.IX$i"},$ENV{"cgi.$id.IY$i"},
 		     0,0,$subimage->getBounds());
     }
     my $height=GD::Font->Giant->height;
-    for(my $i=0;$i<$ENV{"form.COUNT"};$i++) {
-	$image->string(gdGiantFont,$ENV{"form.X$i"},$ENV{"form.Y$i"}-$height,
-		       $ENV{"form.LB$i"},$black);
-    }
-    for(my $i=0;$i<$ENV{"form.LINECOUNT"};$i++) {
-	my $x1=$ENV{"form.LINEX1$i"};
-	my $y1=$ENV{"form.LINEY1$i"};
-	my $x2=$ENV{"form.LINEX2$i"};
-	my $y2=$ENV{"form.LINEY2$i"};
-	my $width=$ENV{"form.LINEW$i"};
-	my $color=$ENV{"form.LINEC$i"};
+    for(my $i=0;$i<$ENV{"cgi.$id.COUNT"};$i++) {
+	$image->string(gdGiantFont,$ENV{"cgi.$id.X$i"},
+		       $ENV{"cgi.$id.Y$i"}-$height,
+		       &Apache::lonnet::unescape($ENV{"cgi.$id.LB$i"}),$black);
+    }
+    for(my $i=0;$i<$ENV{"cgi.$id.LINECOUNT"};$i++) {
+	my ($x1,$y1,$x2,$y2,$color,$width)=split(':',$ENV{"cgi.$id.LINE$i"});
 	my (undef,$red,undef,$green,undef,$blue)=split(/(..)/,$color);
 	$red=hex($red);$green=hex($green);$blue=hex($blue);
 	my $imcolor;
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.40 loncom/homework/imageresponse.pm:1.41
--- loncom/homework/imageresponse.pm:1.40	Mon Nov 10 18:29:27 2003
+++ loncom/homework/imageresponse.pm	Mon Nov 10 19:25:24 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # image click response style
 #
-# $Id: imageresponse.pm,v 1.40 2003/11/10 23:29:27 albertel Exp $
+# $Id: imageresponse.pm,v 1.41 2003/11/11 00:25:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -106,39 +106,33 @@
 sub prep_image {
     my ($image)=@_;
     my $part=$Apache::inputtags::part;
-    my $id=$Apache::inputtags::response['-1'];
-    my $token=$Apache::lonxml::curdepth.'_'.$$;
-    my $args="BGIMG=".$image;
-    &Apache::lonxml::debug("args is $args image is $image");
-    my ($x,$y)=split(/:/,$Apache::lonhomework::history{"resource.$part.$id.submission"});
+    my $respid=$Apache::inputtags::response['-1'];
+    my $id=&Apache::loncommon::get_cgi_id();
+    my %x;
+    $x{"cgi.$id.BGIMG"}=$image;
+    my ($x,$y)=split(/:/,$Apache::lonhomework::history{"resource.$part.$respid.submission"});
     #draws 2 xs on the image at the clicked location
     #one in white and then one in red on top of the one in white
     if (defined($x) && defined($y)) {
-	$args.="&LINECOUNT=4";
+	$x{"cgi.$id.LINECOUNT"}=4;
 	my $length = 6;
 	my $width = 1;
 	my $extrawidth = 2;
-	$args.="&LINEW0=".($width+$extrawidth);
-	$args.="&LINEC0=FFFFFF";
-	$args.="&LINEX10=".($x-$length)."&LINEY10=".($y-$length);
-	$args.="&LINEX20=".($x+$length)."&LINEY20=".($y+$length);
-	$args.="&LINEW1=".($width+$extrawidth);
-	$args.="&LINEC1=FFFFFF";
-	$args.="&LINEX11=".($x-$length)."&LINEY11=".($y+$length);
-	$args.="&LINEX21=".($x+$length)."&LINEY21=".($y-$length);
-	$args.="&LINEW2=$width";
-	$args.="&LINEC2=FF0000";
-	$args.="&LINEX12=".($x-$length)."&LINEY12=".($y-$length);
-	$args.="&LINEX22=".($x+$length)."&LINEY22=".($y+$length);
-	$args.="&LINEW3=$width";
-	$args.="&LINEC3=FF0000";
-	$args.="&LINEX13=".($x-$length)."&LINEY13=".($y+$length);
-	$args.="&LINEX23=".($x+$length)."&LINEY23=".($y-$length);
+	$x{"cgi.$id.LINE0"}=
+	    join(':',(($x-$length),($y-$length),($x+$length),($y+$length),
+		      "FFFFFF",($width+$extrawidth)));
+	$x{"cgi.$id.LINE1"}=
+	    join(':',(($x-$length),($y+$length),($x+$length),($y-$length),
+		      "FFFFFF",($width+$extrawidth)));
+	$x{"cgi.$id.LINE2"}=
+	    join(':',(($x-$length),($y-$length),($x+$length),($y+$length),
+		      "FF0000",($width)));
+	$x{"cgi.$id.LINE3"}=
+	    join(':',(($x-$length),($y+$length),($x+$length),($y-$length),
+		      "FF0000",($width)));
     }
-    &Apache::lonxml::debug("args is $args image is $image");
-    &Apache::lonnet::appenv(("imagerequest.$token"=>
-			     &Apache::lonnet::escape($args)));
-    return $token;
+    &Apache::lonnet::appenv(%x);
+    return $id;
 }
 
 sub displayfoils {

--albertel1068510325--