[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf /homework edit.pm imagechoice.pm imageresponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 14 Jan 2004 22:59:18 -0000


This is a MIME encoded message

--albertel1074121158
Content-Type: text/plain

albertel		Wed Jan 14 17:59:18 2004 EDT

  Modified files:              
    /loncom	loncapa_apache.conf 
    /loncom/homework	edit.pm imagechoice.pm imageresponse.pm 
  Log:
  - imagechoice.pm now understands boxes, <rectangle> on images works with this now
  - BUG#2576 
  
  
--albertel1074121158
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040114175918.txt"

Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.68 loncom/loncapa_apache.conf:1.69
--- loncom/loncapa_apache.conf:1.68	Tue Jan 13 14:43:42 2004
+++ loncom/loncapa_apache.conf	Wed Jan 14 17:59:18 2004
@@ -1,7 +1,7 @@
 ##
 ## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
 ##
-## $Id: loncapa_apache.conf,v 1.68 2004/01/13 19:43:42 www Exp $
+## $Id: loncapa_apache.conf,v 1.69 2004/01/14 22:59:18 albertel Exp $
 ##
 
 #
@@ -242,6 +242,14 @@
 PerlAccessHandler       Apache::lonacc
 SetHandler perl-script
 PerlHandler Apache::randomlylabel
+ErrorDocument     403 /adm/login
+ErrorDocument	  500 /adm/errorhandler
+</Location>
+
+<Location /adm/imagechoice>
+PerlAccessHandler       Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::imagechoice
 ErrorDocument     403 /adm/login
 ErrorDocument	  500 /adm/errorhandler
 </Location>
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.76 loncom/homework/edit.pm:1.77
--- loncom/homework/edit.pm:1.76	Mon Jan 12 14:53:54 2004
+++ loncom/homework/edit.pm	Wed Jan 14 17:59:18 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.76 2004/01/12 19:53:54 albertel Exp $
+# $Id: edit.pm,v 1.77 2004/01/14 22:59:18 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -739,51 +739,23 @@
     return $result;
 }
 
-# coordinate pair (x1,y1)-(x2,y2)
-sub entercoordpair {
-    my ($id,$mode,$width,$height) = @_;
+# coordinates (x1,y1)-(x2,y2)...
+# mode can be either box, or polygon
+sub entercoord {
+    my ($idx,$mode,$width,$height,$type) = @_;
     unless ($Apache::edit::bgimgsrc) { return ''; }
-    my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
-    my $form    = 'lonhomework';
-    my $element;
-    if (! defined($mode) || $mode eq 'attribute') {
-        $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
-    } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
-        $element = &Apache::lonnet::escape('homework_edit_'.
-                                           $Apache::lonxml::curdepth);
-    }
-    my $formheight='';
-    if ($height) {
-	$formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
-    }
-    my $formwidth='';
-    if ($width) {
-	$formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
-    }
-    my $result = <<"ENDBUTTON";
-<a href="/cgi-bin/imagechoice.pl?mode=pair&formname=$form&file=$bgfile$formheight$formwidth&formcoord=$element"
-target="imagechoice">Click Coordinate Pair</a>
-ENDBUTTON
-    return $result;
-}
-
-# coordinate polygon (x1,y1)-(x2,y2)...
-sub entercoordpolygon {
-    my ($id,$mode,$width,$height) = @_;
-    unless ($Apache::edit::bgimgsrc) { return ''; }
-    &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') {
-        $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
+        $element = &Apache::lonnet::escape("$idx\_$Apache::lonxml::curdepth");
     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
         $element = &Apache::lonnet::escape('homework_edit_'.
                                            $Apache::lonxml::curdepth);
     }
     my $id=$Apache::lonxml::curdepth;
-    my %data=("imagechoice.$id.mode"      =>'polygon',
+    my %data=("imagechoice.$id.type"      =>$type,
 	      "imagechoice.$id.formname"  =>$form,
 	      "imagechoice.$id.file"      =>$bgfile,
 	      "imagechoice.$id.formcoord" =>$element);
@@ -796,7 +768,9 @@
 	    $Apache::edit::bgimgsrccurdepth;
     }
     &Apache::lonnet::appenv(%data);
-    my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">Create Polygon Data</a>';
+    my $text="Enter Coordinates";
+    if ($type eq 'polygon') { $text='Create Polygon Data'; }
+    my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>';
     return $result;
 }
 
Index: loncom/homework/imagechoice.pm
diff -u loncom/homework/imagechoice.pm:1.2 loncom/homework/imagechoice.pm:1.3
--- loncom/homework/imagechoice.pm:1.2	Mon Jan 12 14:53:54 2004
+++ loncom/homework/imagechoice.pm	Wed Jan 14 17:59:18 2004
@@ -1,4 +1,4 @@
-# $Id: imagechoice.pm,v 1.2 2004/01/12 19:53:54 albertel Exp $
+# $Id: imagechoice.pm,v 1.3 2004/01/14 22:59:18 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -29,7 +29,7 @@
 
 sub deletedata {
     my ($id)=@_;
-    &Apache::lonnet::delenv("imagechoice\\.$id");
+    &Apache::lonnet::delenv("imagechoice\\.$id\\.coords");
 }
 
 sub closewindow {
@@ -51,7 +51,7 @@
 }
 
 sub storedata {
-    my ($r,$mode,$filename,$id)=@_;
+    my ($r,$type,$filename,$id)=@_;
 
     my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
 
@@ -65,7 +65,7 @@
     }
 
     if ((defined($ENV{"imagechoice.$id.x"})) && (defined($ENV{"imagechoice.$id.y"})) && 
-	($mode ne 'pairtwo') && ($mode ne 'pairthree')) {
+	($type ne 'pairtwo') && ($type ne 'pairthree')) {
 	my $output='';
 	if ($ENV{"imagechoice.$id.formx"}) {
 	    $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formx"}.
@@ -75,15 +75,7 @@
 	    $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{"imagechoice.$id.selx"}.','.$ENV{"imagechoice.$id.sely"}.')-('.$ENV{"imagechoice.$id.x"}.','.$ENV{"imagechoice.$id.y"}.')';
-
-	if ($ENV{"imagechoice.$id.formcoord"}) {
-	    $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formcoord"}.
-		'.value="'.$outputpair.'";';
-	}
-    } elsif ($mode eq 'polygon') {
+    } elsif ($type eq 'polygon' or $type eq 'box') {
 	my $coordstr;
 	while (@coords) {
 	    $coordstr.='('.shift(@coords).','.shift(@coords).')-';
@@ -96,16 +88,23 @@
 }
 
 sub getcoord {
-    my ($r,$mode,$filename,$id)=@_;
+    my ($r,$type,$filename,$id)=@_;
     my $heading='Position';
     my $nextstage='';
-    if ($mode eq 'pair') {
-	$heading='First Coordinate';
-	$nextstage='<input type="hidden" name="mode" value="pairtwo" />';
-    } elsif ($mode eq 'pairtwo') {
-	$heading='Second Coordinate';
-	$nextstage='<input type="hidden" name="mode" value="pairthree" />';
-    } elsif ($mode eq 'polygon') {
+    if ($type eq 'box') {
+	my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
+	my $step=scalar(@coords)/2;
+	if ($step == 0) { 
+	    $heading='First Coordinate';
+	    #$nextstage='<input type="hidden" name="type" value="pairtwo" />';
+	} elsif ($step == 1) {
+	    $heading='Second Coordinate';
+	    #$nextstage='<input type="hidden" name="type" value="pairthree" />';
+	} else {
+	    $heading='Finish or Cancel';
+	    $nextstage='<input type="submit" name="finish" value="Finish" />';
+	}
+    } elsif ($type eq 'polygon') {
 	$heading='Enter Coordinate or click finish to close Polygon';
 	$nextstage='<input type="submit" name="finish" value="Finish" />';
     }
@@ -131,6 +130,7 @@
 			   $ENV{"form.image.y"}));
 	&Apache::lonnet::appenv("imagechoice.$id.coords"=>$data);
     }
+    return int(scalar(split(':',$ENV{"imagechoice.$id.coords"}))/2);
 }
 
 sub drawX {
@@ -175,17 +175,32 @@
     return %x;
 }
 
+sub drawBox {
+    my ($id,$imid)=@_;
+    my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
+    my %x;
+    if (scalar(@coords) < 4) { return %x; }
+    my $width = 1;
+    my $extrawidth = 2;
+    my $i=$x{"cgi.$imid.BOXCOUNT"}++;
+    $x{"cgi.$imid.BOX$i"}=join(':',(@coords,"FFFFFF",($width+$extrawidth)));
+    $i=$x{"cgi.$imid.BOXCOUNT"}++;
+    $x{"cgi.$imid.BOX$i"}=join(':',(@coords,"00FF00",$width));
+    return %x;
+}
+
 sub drawimage {
-    my ($r,$mode,$filename,$id)=@_;
+    my ($r,$type,$filename,$id)=@_;
     my $imid=&Apache::loncommon::get_cgi_id();
     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];
-    my $y=@coords[-1];
+    my $x=$coords[-2];
+    my $y=$coords[-1];
     %data=(%data,&drawX($imid,$x,$y));
-    if ($mode eq "polygon") { %data=(%data,&drawPolygon($id,$imid)); }
+    if ($type eq "polygon") { %data=(%data,&drawPolygon($id,$imid)); }
+    if ($type eq "box") { %data=(%data,&drawBox($id,$imid)); }
     &Apache::lonnet::appenv(%data);
     return "/adm/randomlabel.png?token=$imid"
 }
@@ -197,17 +212,21 @@
     my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'});
     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);
+	return OK;
     }
-    &savecoord($id);
-    my $imurl=&drawimage($r,$mode,$filename,$id);
-    if ($ENV{'form.finish'} eq 'Finish') {
-	&storedata($r,$mode,$imurl,$id);
+    my $type=$ENV{"imagechoice.$id.type"};
+    if (defined($ENV{'form.type'})) { $type=$ENV{'form.type'}; }
+    my $numcoords=&savecoord($id);
+    &Apache::lonnet::logthis("num coords is $numcoords");
+    my $imurl=&drawimage($r,$type,$filename,$id);
+    if (($ENV{'form.finish'} eq 'Finish')) {
+	&storedata($r,$type,$imurl,$id);
+    } else {
+	&getcoord($r,$type,$imurl,$id);
     }
-    &getcoord($r,$mode,$imurl,$id);
     return OK;
 }
 
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.43 loncom/homework/imageresponse.pm:1.44
--- loncom/homework/imageresponse.pm:1.43	Fri Jan  9 18:22:19 2004
+++ loncom/homework/imageresponse.pm	Wed Jan 14 17:59:18 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # image click response style
 #
-# $Id: imageresponse.pm,v 1.43 2004/01/09 23:22:19 albertel Exp $
+# $Id: imageresponse.pm,v 1.44 2004/01/14 22:59:18 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -489,9 +489,10 @@
 	my $coords=&Apache::lonxml::get_all_text('/rectangle',$parser);
 	$result=&Apache::edit::tag_start($target,$token,'Rectangle').
 	    &Apache::edit::editline($token->[1],$coords,'Coordinate Pairs',40).
-	    &Apache::edit::entercoordpair(undef,'textnode').
+	    &Apache::edit::entercoord(undef,'textnode',undef,undef,'box').
 	    &Apache::edit::end_row();
     } elsif ($target eq "modified") {
+	&Apache::edit::deletecoorddata();
 	$result=$token->[4].&Apache::edit::modifiedfield('/rectangle',$parser);
     }
     return $result;
@@ -540,7 +541,7 @@
 	my $coords=&Apache::lonxml::get_all_text('/polygon',$parser);
 	$result=&Apache::edit::tag_start($target,$token,'Polygon').
 	    &Apache::edit::editline($token->[1],$coords,'Coordinate list',40).
-	    &Apache::edit::entercoordpolygon(undef,'textnode').
+	    &Apache::edit::entercoord(undef,'textnode',undef,undef,'polygon').
 	    &Apache::edit::end_row();
     } elsif ($target eq "modified") {
 	$result=$token->[4].&Apache::edit::modifiedfield('/polygon',$parser);

--albertel1074121158--