[LON-CAPA-cvs] cvs: loncom /homework edit.pm imagechoice.pm randomlylabel.pm /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 12 Jan 2004 19:53:54 -0000


This is a MIME encoded message

--albertel1073937234
Content-Type: text/plain

albertel		Mon Jan 12 14:53:54 2004 EDT

  Modified files:              
    /loncom/homework	edit.pm imagechoice.pm randomlylabel.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - polygons set the request width now
  - imagechoice stores its data where it won't be thrown away before we are ready
  - imageresponse tries to cleanup after itself
  - lonnet::hreflocation() understands what to do with /home references
  - relative image URLs work now
  
  
--albertel1073937234
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040112145354.txt"

Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.75 loncom/homework/edit.pm:1.76
--- loncom/homework/edit.pm:1.75	Fri Jan  9 18:22:18 2004
+++ loncom/homework/edit.pm	Mon Jan 12 14:53:54 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.75 2004/01/09 23:22:18 albertel Exp $
+# $Id: edit.pm,v 1.76 2004/01/12 19:53:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -771,7 +771,9 @@
 sub entercoordpolygon {
     my ($id,$mode,$width,$height) = @_;
     unless ($Apache::edit::bgimgsrc) { return ''; }
-    my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
+    &Apache::lonnet::logthis($Apache::edit::bgimgsrc);
+    my $bgfile=&Apache::lonnet::escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
+    &Apache::lonnet::logthis($Apache::edit::bgfile);
     my $form    = 'lonhomework';
     my $element;
     if (! defined($mode) || $mode eq 'attribute') {
@@ -780,21 +782,28 @@
         $element = &Apache::lonnet::escape('homework_edit_'.
                                            $Apache::lonxml::curdepth);
     }
-    my $id=&Apache::loncommon::get_cgi_id();
-    my %data=("cgi.$id.mode"      =>'polygon',
-	      "cgi.$id.formname"  =>$form,
-	      "cgi.$id.file"      =>$bgfile,
-	      "cgi.$id.formcoord" =>$element);
+    my $id=$Apache::lonxml::curdepth;
+    my %data=("imagechoice.$id.mode"      =>'polygon',
+	      "imagechoice.$id.formname"  =>$form,
+	      "imagechoice.$id.file"      =>$bgfile,
+	      "imagechoice.$id.formcoord" =>$element);
     if ($height) {
-	$data{"cgi.$id.formheight"}=$height.'_'.$Apache::edit::bgimgsrccurdepth;
+	$data{"imagechoice.$id.formheight"}=$height.'_'.
+	    $Apache::edit::bgimgsrccurdepth;
     }
     if ($width) {
-	$data{"cgi.$id.formwidth"}=$width.'_'.$Apache::edit::bgimgsrccurdepth;
+	$data{"imagechoice.$id.formwidth"}=$width.'_'.
+	    $Apache::edit::bgimgsrccurdepth;
     }
     &Apache::lonnet::appenv(%data);
     my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">Create Polygon Data</a>';
     return $result;
 }
+
+sub deletecoorddata {
+    &Apache::lonnet::delenv("imagechoice\\.");
+}
+
 #----------------------------------------------------- browse
 sub browse {
     # insert a link to call up the filesystem browser (lonindexer)
Index: loncom/homework/imagechoice.pm
diff -u loncom/homework/imagechoice.pm:1.1 loncom/homework/imagechoice.pm:1.2
--- loncom/homework/imagechoice.pm:1.1	Fri Jan  9 18:22:19 2004
+++ loncom/homework/imagechoice.pm	Mon Jan 12 14:53:54 2004
@@ -1,4 +1,4 @@
-# $Id: imagechoice.pm,v 1.1 2004/01/09 23:22:19 albertel Exp $
+# $Id: imagechoice.pm,v 1.2 2004/01/12 19:53:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -26,10 +26,11 @@
 use strict;
 use Apache::Constants qw(:common :http);
 
-#
-# Single coordinate, defined - store it
-#
 
+sub deletedata {
+    my ($id)=@_;
+    &Apache::lonnet::delenv("imagechoice\\.$id");
+}
 
 sub closewindow {
     my ($r,$output,$filename)=@_;
@@ -43,7 +44,7 @@
 </script>
 <body bgcolor="#FFFFFF" onLoad="submitthis()">
 <h3>Position Selected</h3>
-<img name="pickimg" src="$filename" />
+<!--<img name="pickimg" src="$filename" />-->
 </body>
 </html>
 ENDSUBM
@@ -52,34 +53,34 @@
 sub storedata {
     my ($r,$mode,$filename,$id)=@_;
 
-    my (undef,@coords)=split(':',$ENV{"cgi.$id.coords"});
+    my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
 
     my $output;
 
-    if ($ENV{"cgi.$id.formwidth"}) {
-	$output.='opener.document.forms.'.$ENV{"cgi.$id.formname"}.'.'.$ENV{"cgi.$id.formwidth"}.'.value=document.pickimg.width;';
+    if ($ENV{"imagechoice.$id.formwidth"}) {
+	$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formwidth"}.'.value=document.pickimg.width;';
     }
-    if ($ENV{"cgi.$id.formheight"}) {
-	$output.='opener.document.forms.'.$ENV{"cgi.$id.formname"}.'.'.$ENV{"cgi.$id.formheight"}.'.value=document.pickimg.height;';
+    if ($ENV{"imagechoice.$id.formheight"}) {
+	$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formheight"}.'.value=document.pickimg.height;';
     }
 
-    if ((defined($ENV{"cgi.$id.x"})) && (defined($ENV{"cgi.$id.y"})) && 
+    if ((defined($ENV{"imagechoice.$id.x"})) && (defined($ENV{"imagechoice.$id.y"})) && 
 	($mode ne 'pairtwo') && ($mode ne 'pairthree')) {
 	my $output='';
-	if ($ENV{"cgi.$id.formx"}) {
-	    $output.='opener.document.forms.'.$ENV{"cgi.$id.formname"}.'.'.$ENV{"cgi.$id.formx"}.
-		'.value='.$ENV{"cgi.$id.x"}.';';
+	if ($ENV{"imagechoice.$id.formx"}) {
+	    $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formx"}.
+		'.value='.$ENV{"imagechoice.$id.x"}.';';
 	}
-	if ($ENV{"cgi.$id.formy"}) {
-	    $output.='opener.document.forms.'.$ENV{"cgi.$id.formname"}.'.'.$ENV{"cgi.$id.formy"}.
-		'.value='.$ENV{"cgi.$id.y"}.';';
+	if ($ENV{"imagechoice.$id.formy"}) {
+	    $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formy"}.
+		'.value='.$ENV{"imagechoice.$id.y"}.';';
 	}
     } elsif ($mode eq 'pairthree') {
 	my $output='';
-	my $outputpair='('.$ENV{"cgi.$id.selx"}.','.$ENV{"cgi.$id.sely"}.')-('.$ENV{"cgi.$id.x"}.','.$ENV{"cgi.$id.y"}.')';
+	my $outputpair='('.$ENV{"imagechoice.$id.selx"}.','.$ENV{"imagechoice.$id.sely"}.')-('.$ENV{"imagechoice.$id.x"}.','.$ENV{"imagechoice.$id.y"}.')';
 
-	if ($ENV{"cgi.$id.formcoord"}) {
-	    $output.='opener.document.forms.'.$ENV{"cgi.$id.formname"}.'.'.$ENV{"cgi.$id.formcoord"}.
+	if ($ENV{"imagechoice.$id.formcoord"}) {
+	    $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formcoord"}.
 		'.value="'.$outputpair.'";';
 	}
     } elsif ($mode eq 'polygon') {
@@ -88,8 +89,9 @@
 	    $coordstr.='('.shift(@coords).','.shift(@coords).')-';
 	}
 	chop($coordstr);
-	$output.='opener.document.forms.'.$ENV{"cgi.$id.formname"}.'.'.$ENV{"cgi.$id.formcoord"}.'.value="'.$coordstr.'";';
+	$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formcoord"}.'.value="'.$coordstr.'";';
     }
+    &deletedata($id);
     &closewindow($r,$output,$filename);
 }
 
@@ -113,6 +115,8 @@
 <h3>Select $heading on Image</h3>
 <form method="POST" action="/adm/imagechoice?token=$id">
 $nextstage
+<input type="submit" name="cancel" value="Cancel" />
+<br />
 <input name="image" type="image" src="$filename" />
 </form>
 </body>
@@ -123,9 +127,9 @@
 sub savecoord {
     my ($id)=@_;
     if (defined($ENV{"form.image.x"}) && defined($ENV{"form.image.y"})) {
-	my $data=join(':',($ENV{"cgi.$id.coords"},$ENV{"form.image.x"},
+	my $data=join(':',($ENV{"imagechoice.$id.coords"},$ENV{"form.image.x"},
 			   $ENV{"form.image.y"}));
-	&Apache::lonnet::appenv("cgi.$id.coords"=>$data);
+	&Apache::lonnet::appenv("imagechoice.$id.coords"=>$data);
     }
 }
 
@@ -153,7 +157,7 @@
 
 sub drawPolygon {
     my ($id,$imid)=@_;
-    my (undef,@coords)=split(':',$ENV{"cgi.$id.coords"});
+    my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
     my $coordstr;
     while (@coords) {
 	$coordstr.='('.shift(@coords).','.shift(@coords).')-';
@@ -174,9 +178,8 @@
 sub drawimage {
     my ($r,$mode,$filename,$id)=@_;
     my $imid=&Apache::loncommon::get_cgi_id();
-    my (undef,@coords)=split(':',$ENV{"cgi.$id.coords"});
-    if (scalar(@coords) < 2) { return $filename; }
-    $filename=&Apache::lonnet::filelocation('',$filename);
+    my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
+    if (scalar(@coords) < 2) { return &Apache::lonnet::hreflocation('',$filename); }
     my %data;
     $data{"cgi.$imid.BGIMG"}=$filename;
     my $x=@coords[-2];
@@ -192,10 +195,13 @@
     $r->content_type('text/html');
     my %data;
     my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'});
-    my $filename = $ENV{"cgi.$id.file"};
-    my $formname = $ENV{"cgi.$id.formname"};
-    my $mode=$ENV{"cgi.$id.mode"};
-    $filename=&Apache::lonnet::unescape($filename);
+    my $filename = &Apache::lonnet::unescape($ENV{"imagechoice.$id.file"});
+    my $formname = $ENV{"imagechoice.$id.formname"};
+    my $mode=$ENV{"imagechoice.$id.mode"};
+    if ($ENV{'form.cancel'} eq 'Cancel') {
+	&deletedata($id);
+	&closewindow($r,'',$filename);
+    }
     &savecoord($id);
     my $imurl=&drawimage($r,$mode,$filename,$id);
     if ($ENV{'form.finish'} eq 'Finish') {
Index: loncom/homework/randomlylabel.pm
diff -u loncom/homework/randomlylabel.pm:1.13 loncom/homework/randomlylabel.pm:1.14
--- loncom/homework/randomlylabel.pm:1.13	Fri Jan  9 18:22:19 2004
+++ loncom/homework/randomlylabel.pm	Mon Jan 12 14:53:54 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # randomlabel.png: composite together text and images into 1 image
 #
-# $Id: randomlylabel.pm,v 1.13 2004/01/09 23:22:19 albertel Exp $
+# $Id: randomlylabel.pm,v 1.14 2004/01/12 19:53:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -131,6 +131,7 @@
 	    my ($x,$y)=($coord=~m/\(([0-9]+),([0-9]+)\)/);
 	    $polygon->addPt($x,$y);
 	}
+	$image->setThickness($width);
 	if ($open) {
 	    $image->polydraw($polygon,$imcolor);
 	} else {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.459 loncom/lonnet/perl/lonnet.pm:1.460
--- loncom/lonnet/perl/lonnet.pm:1.459	Thu Dec 11 19:20:08 2003
+++ loncom/lonnet/perl/lonnet.pm	Mon Jan 12 14:53:54 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.459 2003/12/12 00:20:08 albertel Exp $
+# $Id: lonnet.pm,v 1.460 2004/01/12 19:53:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4441,13 +4441,15 @@
 
 sub hreflocation {
     my ($dir,$file)=@_;
-    unless (($file=~/^http:\/\//i) || ($file=~/^\//)) {
-       my $finalpath=filelocation($dir,$file);
-       $finalpath=~s/^\/home\/httpd\/html//;
-       $finalpath=~s-/home/(\w+)/public_html/-/~$1/-;
-       return $finalpath;
-    } else {
-       return $file;
+    unless (($file=~m-^http://-i) || ($file=~m-^/-)) {
+	my $finalpath=filelocation($dir,$file);
+	$finalpath=~s-^/home/httpd/html--;
+	$finalpath=~s-/home/(\w+)/public_html/-/~$1/-;
+	return $finalpath;
+    } elsif ($file=~m-^/home-) {
+	$file=~s-^/home/httpd/html--;
+	$file=~s-/home/(\w+)/public_html/-/~$1/-;
+	return $file;
     }
 }
 

--albertel1073937234--