Diff for /loncom/homework/imagechoice.pm between versions 1.11 and 1.16

version 1.11, 2006/05/30 12:45:37 version 1.16, 2009/02/18 07:06:12
Line 26  package Apache::imagechoice; Line 26  package Apache::imagechoice;
 use strict;  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Apache::lonnet;  use Apache::lonnet;
 use lib '/home/httpd/lib/perl/';  use Apache::lonlocal;
 use LONCAPA;  use LONCAPA;
     
   
 sub deletedata {  sub deletedata {
     my ($id)=@_;      my ($id)=@_;
     &Apache::lonnet::delenv("imagechoice\\.$id\\.coords");      &Apache::lonnet::delenv('imagechoice.'.$id.'.coords');
 }  }
   
 sub closewindow {  sub closewindow {
Line 59  ENDSUBM Line 59  ENDSUBM
     my $end_page =      my $end_page =
         &Apache::loncommon::end_page();          &Apache::loncommon::end_page();
   
     my $js=<<"ENDSUBM";      $r->print(<<"ENDSUBM");
 $start_page  $start_page
 <h3>Position Selected</h3>  <h3>Position Selected</h3>
 $display  $display
Line 113  sub storedata { Line 113  sub storedata {
   
 sub getcoord {  sub getcoord {
     my ($r,$type,$filename,$id)=@_;      my ($r,$type,$filename,$id)=@_;
     my $heading='Select Position on Image';      my $heading=&mt('Select Position on Image');
     my $nextstage='';      my $nextstage='';
     if ($type eq 'box') {      if ($type eq 'box') {
  my (undef,@coords)=split(':',$env{"imagechoice.$id.coords"});   my (undef,@coords)=split(':',$env{"imagechoice.$id.coords"});
  my $step=scalar(@coords)/2;   my $step=scalar(@coords)/2;
  if ($step == 0) {    if ($step == 0) { 
     $heading='Select First Coordinate on Image';      $heading=&mt('Select First Coordinate on Image');
     #$nextstage='<input type="hidden" name="type" value="pairtwo" />';      #$nextstage='<input type="hidden" name="type" value="pairtwo" />';
  } elsif ($step == 1) {   } elsif ($step == 1) {
     $heading='Select Second Coordinate on Image';      $heading=&mt('Select Second Coordinate on Image');
     #$nextstage='<input type="hidden" name="type" value="pairthree" />';      #$nextstage='<input type="hidden" name="type" value="pairthree" />';
  } else {   } else {
     $heading='Select Finish to store selection.';      $heading=&mt('Select Finish to save selection');
     $nextstage='<input type="submit" name="finish" value="Finish" />';      $nextstage='<input type="submit" name="finish" value="'.&mt('Finish').'" />';
  }   }
     } elsif ($type eq 'polygon') {      } elsif ($type eq 'polygon') {
  $heading='Enter Coordinate or click finish to close Polygon';   $heading=&mt('Enter Coordinate or click finish to close Polygon');
  $nextstage='<input type="submit" name="finish" value="Finish" />';   $nextstage='<input type="submit" name="finish" value="'.&mt('Finish').'" />';
     } elsif ($type eq 'point') {      } elsif ($type eq 'point') {
  $heading='Click to select a Coordinate or click Finish to store current selection.';   $heading=&mt('Click to select a Coordinate or click Finish to save current selection');
  $nextstage='<input type="submit" name="finish" value="Finish" />';   $nextstage='<input type="submit" name="finish" value="'.&mt('Finish').'" />';
     }      }
   
     my $start_page =      my $start_page =
Line 143  sub getcoord { Line 143  sub getcoord {
   
     my $end_page =      my $end_page =
         &Apache::loncommon::end_page();          &Apache::loncommon::end_page();
       my $canceltext=&mt('Cancel');
     $r->print(<<"END");      $r->print(<<"END");
 $start_page  $start_page
 <h3>$heading</h3>  <h3>$heading</h3>
 <form method="POST" action="/adm/imagechoice?token=$id">  <form method="POST" action="/adm/imagechoice?token=$id">
 $nextstage  $nextstage
 <input type="submit" name="cancel" value="Cancel" />  <input type="submit" name="cancel" value="$canceltext" />
 <br />  <br />
 <input name="image" type="image" src="$filename" />  <input name="image" type="image" src="$filename" />
 </form>  </form>
Line 166  sub savecoord { Line 167  sub savecoord {
     $data=join(':',($env{"imagechoice.$id.coords"},      $data=join(':',($env{"imagechoice.$id.coords"},
     $env{"form.image.x"},$env{"form.image.y"}));      $env{"form.image.x"},$env{"form.image.y"}));
  }   }
  &Apache::lonnet::appenv("imagechoice.$id.coords"=>$data);   &Apache::lonnet::appenv({"imagechoice.$id.coords"=>$data});
     }      }
     return int(scalar(split(':',$env{"imagechoice.$id.coords"}))/2);      return int(scalar(split(':',$env{"imagechoice.$id.coords"}))/2);
 }  }
Line 238  sub drawimage { Line 239  sub drawimage {
     &drawX(\%data,$imid,$x,$y);      &drawX(\%data,$imid,$x,$y);
     if ($type eq "polygon") { &drawPolygon(\%data,$id,$imid); }      if ($type eq "polygon") { &drawPolygon(\%data,$id,$imid); }
     if ($type eq "box") { &drawBox(\%data,$id,$imid); }      if ($type eq "box") { &drawBox(\%data,$id,$imid); }
     &Apache::lonnet::appenv(%data);      &Apache::lonnet::appenv(\%data);
     return "/adm/randomlabel.png?token=$imid"      return "/adm/randomlabel.png?token=$imid"
 }  }
   
Line 250  sub handler { Line 251  sub handler {
     my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'});      my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'});
     my $filename = &unescape($env{"imagechoice.$id.file"});      my $filename = &unescape($env{"imagechoice.$id.file"});
     my $formname = $env{"imagechoice.$id.formname"};      my $formname = $env{"imagechoice.$id.formname"};
     if ($env{'form.cancel'} eq 'Cancel') {      if ($env{'form.cancel'} eq &mt('Cancel')) {
  &deletedata($id);   &deletedata($id);
  &closewindow($r,'',$filename);   &closewindow($r,'',$filename);
  return OK;   return OK;
Line 259  sub handler { Line 260  sub handler {
     if (defined($env{'form.type'})) { $type=$env{'form.type'}; }      if (defined($env{'form.type'})) { $type=$env{'form.type'}; }
     my $numcoords=&savecoord($id,$type);      my $numcoords=&savecoord($id,$type);
     my $imurl=&drawimage($r,$type,$filename,$id);      my $imurl=&drawimage($r,$type,$filename,$id);
     if (($env{'form.finish'} eq 'Finish')) {      if ($env{'form.finish'} eq &mt('Finish')) {
  &storedata($r,$type,$imurl,$id);   &storedata($r,$type,$imurl,$id);
     } else {      } else {
  &getcoord($r,$type,$imurl,$id);   &getcoord($r,$type,$imurl,$id);

Removed from v.1.11  
changed lines
  Added in v.1.16


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>