File:  [LON-CAPA] / loncom / homework / randomlabel.pm
Revision 1.58: download - view: text, annotated - select for diffs
Wed Feb 11 21:59:49 2004 UTC (20 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- remove some debug

    1: # The LearningOnline Network with CAPA
    2: # random labelling tool
    3: #
    4: # $Id: randomlabel.pm,v 1.58 2004/02/11 21:59:49 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # 7/20/2001 Isaac Tsai, initial syntax
   29: # 8/10/2001 Isaac Tsai, 
   30: # 8/30/2001 Isaac Tsai, 
   31: # SYNTAX:
   32: # <randomlabel bgimg="URL" width="12" height="45" texwidth="50">
   33: #    <labelgroup name="GroupOne" type="image">
   34: #      <location x="123" y="456" />
   35: #      <location x="321" y="654" />
   36: #      <location x="213" y="546" />
   37: #      <label description="TEXT-1">IMG-URL</label>
   38: #      <label description="TEXT-2">IMG-URL</label>
   39: #      <label description="TEXT-3">IMG-URL</label>
   40: #    </labelgroup>
   41: #    <labelgroup name="GroupTwo" type="text">
   42: #      <location x="12" y="45" />
   43: #      <location x="32" y="65" />
   44: #      <location x="21" y="54" />
   45: #      <label>TEXT-1</label>
   46: #      <label>TEXT-2</label>
   47: #      <label>TEXT-3</label>
   48: #    </labelgroup>
   49: #   </randomlabel>
   50: #  ===========================================
   51: #  side effect:
   52: #    location (123,456): $GroupOne[0] = 2  # images give out indexes
   53: #             (321,654): $GroupOne[1] = 1
   54: #             (213,546): $GroupOne[2] = 0
   55: #    location (12,45)  : $GroupTwo[0] = "TEXT-3"
   56: #             (32,65)  : $GroupTwo[1] = "TEXT-1"
   57: #             (21,54)  : $GroupTwo[2] = "TEXT-2"
   58: #  ===========================================
   59: package Apache::randomlabel;
   60: use Apache::lonnet;
   61: use strict;
   62: use Apache::edit;
   63: use Apache::File();
   64: use Apache::Constants qw(:common :http);
   65: 
   66: my %args;
   67: my $cgi_id;
   68: 
   69: BEGIN {
   70:     &Apache::lonxml::register('Apache::randomlabel',('randomlabel','labelgroup','location','label','bgimg'));
   71: }
   72: 
   73: sub check_int {
   74:     # utility function to do error checking on a integer.
   75:     my ($num,$default) = @_;
   76:     $default = 100 if (! defined($default));
   77:     $num =~ s/\s+//g;  # We dont need no stinkin white space!
   78:     # If it is a real, just grab the integer part.
   79:     ($num,undef) = split (/\./,$num) if ($num =~ /\./); 
   80:     # set to default if what we have left doesn't match anything...
   81:     $num = $default unless ($num =~/^\d+$/);
   82:     return $num;
   83: }
   84: 
   85: sub start_randomlabel {
   86:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   87:     my $result='';
   88:     push (@Apache::lonxml::namespace,'randomlabel');
   89:     my $bgimg= &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
   90:     if ( $bgimg !~ /^http:/ ) {
   91: 	$bgimg=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$bgimg);
   92: 	if (&Apache::lonnet::repcopy($bgimg) ne OK) {
   93: 	    $bgimg='/home/httpd/html/adm/lonKaputt/lonlogo_broken.gif';
   94: 	}
   95:     }
   96:     $Apache::randomlabel::tlabel_cnt=0;
   97:     $Apache::randomlabel::ilabel_cnt=0;
   98:     if ($target eq 'web') {
   99: 	$cgi_id=&Apache::loncommon::get_cgi_id();
  100: 	%args=();
  101: 	$args{"cgi.$cgi_id.BGIMG"}=&Apache::lonnet::escape($bgimg);
  102:     } elsif ($target eq 'tex') {
  103: 	my $w= &check_int(&Apache::lonxml::get_param('width',$parstack,$safeeval));
  104: 	my $h= &check_int(&Apache::lonxml::get_param('height',$parstack,$safeeval));
  105: 	my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1));
  106: 	if (!$texwidth) { $texwidth=90; }
  107: 	$result.=&make_eps_image($bgimg,$texwidth,$h,$w);
  108:     } elsif ($target eq 'edit') {
  109: 	$result.=&Apache::edit::tag_start($target,$token);
  110: 	$Apache::edit::bgimgsrc=
  111: 	    &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
  112: 	$Apache::edit::bgimgsrccurdepth=$Apache::lonxml::curdepth;
  113: 	$result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' ';
  114: 	$result.=&Apache::edit::browse('bgimg').' ';
  115: 	$result.=&Apache::edit::search('bgimg').'<br />'.
  116: 	    &Apache::edit::text_arg('Width(pixel):' ,'width'   ,$token,6).
  117: 	    &Apache::edit::text_arg('Height(pixel):','height'  ,$token,6).
  118: 	    &Apache::edit::text_arg('TeXWidth(mm):' ,'texwidth',$token,6).
  119: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row();     
  120:     } elsif ($target eq 'modified') {
  121: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  122: 						     $safeeval,'bgimg','width',
  123: 						     'height','texwidth');
  124: 	if ($constructtag) {
  125: 	    $result = &Apache::edit::rebuild_tag($token);
  126: 	    $result.=&Apache::edit::handle_insert();
  127: 	}
  128:     }
  129:     return $result;
  130: }
  131: 
  132: sub end_randomlabel {
  133:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  134:     my $result='';
  135:     my $count;
  136:     pop @Apache::lonxml::namespace;
  137:     if ($target eq 'web') {
  138: 	$count = $Apache::randomlabel::tlabel_cnt;
  139: 	if( $count != 0) { $args{"cgi.$cgi_id.COUNT"}=$count; }
  140: 	$count = $Apache::randomlabel::ilabel_cnt;
  141: 	if( $count != 0) { $args{"cgi.$cgi_id.ICOUNT"}=$count; }
  142: 	$result.='<img src="/adm/randomlabel.png?token='.$cgi_id.'" /><br />'."\n";
  143: 	&Apache::lonnet::appenv(%args);
  144:     } elsif ($target eq 'tex') {
  145: 	$result='\end{picture}\\\\';
  146: 	my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
  147: 	my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
  148: 	my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1));
  149:         if (!$texwidth) { $texwidth=90; }
  150: 	my $howtoskipback = $texwidth*$height/$width;
  151: 	$result.= ' \vskip -'.$howtoskipback.' mm }  \\\\ ';
  152:     } elsif ($target eq 'edit') {
  153: 	$result.=&Apache::edit::end_table;
  154:     }
  155:     return $result;
  156: }
  157: 
  158: sub start_bgimg {
  159:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  160:     my $result='';
  161:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 
  162: 	&Apache::lonxml::startredirection; 
  163:     }
  164:     return $result;
  165: }
  166: 
  167: sub end_bgimg {
  168:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  169:     my $result='';
  170:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 
  171: 	my $bgimg=&Apache::lonxml::endredirection; 
  172: 	if ($target eq 'web') {
  173: 	    $bgimg=&Apache::imageresponse::clean_up_image($bgimg);
  174: 	    $args{"cgi.$cgi_id.BGIMG"}=&Apache::lonnet::escape($bgimg);
  175: 	} elsif ($target eq 'tex') {
  176: 	    my $w=&check_int(&Apache::lonxml::get_param('width',$parstack,$safeeval,-2));
  177: 	    my $h=&check_int(&Apache::lonxml::get_param('height',$parstack,$safeeval,-2));
  178: 	    my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,-2));
  179: 	    if (!$texwidth) { $texwidth=90; }
  180: 	    $result.=&make_eps_image($bgimg,$texwidth,$h,$w);
  181: 	}
  182:     }
  183:     return $result;
  184: }
  185: 
  186: sub make_eps_image {
  187:     my ($bgimg,$texwidth,$h,$w)=@_;
  188:     my $newbgimg = $bgimg;
  189:     $bgimg=~s/\.(gif|jpg|png|jpeg)$/\.eps/i;
  190:     $bgimg= &Apache::lonnet::filelocation($bgimg);
  191:     $bgimg=~s|http:/[^/]*|/home/httpd/html|;
  192:     $bgimg=~s|/$||;
  193:     #if no eps file try to replicate it
  194:     if (not-e $bgimg) {
  195: 	if (&Apache::lonnet::repcopy($bgimg) ne OK ) {
  196: 	    #if replication failed try to find ps file
  197: 	    $bgimg=~s/\.eps$/\.ps/;
  198: 	    #if no ps file try to replicate it
  199: 	    if (not -e $bgimg &&
  200: 		&Apache::lonnet::repcopy($bgimg) ne OK) {
  201: 		#if replication failed try to produce eps file dynamically
  202: 		$bgimg=~s/\.ps$/\.eps/;
  203: 		my $temp_file;
  204: 		my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
  205: 		$temp_file = Apache::File->new('>>'.$filename);
  206: 		$newbgimg =~ s|(.*)/res/|/home/httpd/html/res/|;
  207: 		print $temp_file "$newbgimg\n";
  208: 		$bgimg=~s|/home/httpd/html/res|/home/httpd/prtspool|;
  209: 		$bgimg=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
  210: 	    }
  211: 	}
  212:     }
  213:     $bgimg=~s|/$||;
  214:     my $dirtywidth=$texwidth+5;
  215:     my $result.='\vspace*{2mm}\noindent \parbox{'.$dirtywidth.
  216: 	' mm}{  \noindent \epsfxsize='.$texwidth.' mm \epsffile{'.$bgimg.
  217: 	'}\setlength{\unitlength}{1mm}  \begin{picture}('.
  218: 	$texwidth.','.$texwidth*$h/$w.')(0,-'.$texwidth*$h/$w.')';
  219:     return $result;
  220: }
  221: 
  222: sub adjust_textwidth {
  223:     my $texwidth=shift; 
  224:     my $pagewidth=$ENV{'form.textwidth'};
  225:     $pagewidth=~s/\s*mm\s*$//;
  226:     if ($texwidth>$pagewidth) {$texwidth=$pagewidth;}
  227:     return $texwidth;
  228: }
  229: 
  230: sub start_labelgroup {
  231:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  232:     my $result='';
  233:     my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  234:     my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
  235:     $type =~tr/A-Z/a-z/;
  236:     if ($target ne 'modified' && ($name =~ /\W/ || $name =~ /^[0-9]/)) {
  237: 	&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.<br />");
  238:     }
  239:     if ($target eq 'web' || $target eq 'tex' ||
  240: 	$target eq 'grade' || $target eq 'answer' || $target eq 'analyze') {
  241: 	$Apache::randomlabel::groupname=$name;
  242: 	$Apache::randomlabel::type=$type;
  243: 	@Apache::randomlabel::xcoord = ();
  244: 	@Apache::randomlabel::ycoord = ();
  245: 	@Apache::randomlabel::value = ();
  246: 	@Apache::randomlabel::label_arr  = ();
  247: 	@Apache::randomlabel::decription  = ();
  248:     } elsif ($target eq 'edit') {
  249: 	$result.=&Apache::edit::tag_start($target,$token);
  250: 	$result.=&Apache::edit::text_arg('Name:','name',$token).
  251: 	    &Apache::edit::select_arg('Type:','type',['text','image'],$token).
  252: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row();
  253:     } elsif ($target eq 'modified') {
  254: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  255: 						     $safeeval,'name','type');
  256: 	if ($constructtag) {
  257: 	    $result = &Apache::edit::rebuild_tag($token);
  258: 	    $result.=&Apache::edit::handle_insert();
  259: 	}
  260:     }
  261:     return $result;
  262: }
  263: 
  264: sub add_vars {
  265:     my ($name,$order,$label,$labelorder,$value,$image,$safeeval) = @_;
  266:     my $code = '${'.$name."}{'".($order+1)."'}='".$label."';";
  267:     my $out=Apache::run::run($code,$safeeval);
  268:     if ($value) {
  269: 	$code = '${'.$name."}{'value_".($order+1)."'}='".$value."';";
  270: 	$out=Apache::run::run($code,$safeeval);
  271: 	$code = '${'.$name."}{'labelvalue_".($labelorder+1)."'}='".$value."';";
  272: 	$out=Apache::run::run($code,$safeeval);
  273:     }
  274:     if ($image) {
  275: 	my $code = '${'.$name."}{'image_".($order+1)."'}='".$image."';";
  276: 	my $out=Apache::run::run($code,$safeeval);
  277:     }
  278:     $code = '${'.$name."}{'numlocations'}='".($order+1)."';";
  279:     $out=Apache::run::run($code,$safeeval);
  280: }
  281: 
  282: # begin to assign labels to locations
  283: sub end_labelgroup {
  284:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  285:     my $gname = $Apache::randomlabel::groupname;
  286:     my $type  = $Apache::randomlabel::type;
  287:     my $result='';
  288:     if ($target eq 'web' || $target eq 'answer' || $target eq 'grade' ||
  289: 	$target eq 'analyze') {
  290: 	my @idx_arr = (0 .. $#Apache::randomlabel::label_arr);
  291: 	&Apache::structuretags::shuffle(\@idx_arr);
  292: 	for(0 .. $#Apache::randomlabel::label_arr) {
  293: 	    my $str;
  294: 	    my $xstr;
  295: 	    my $ystr;
  296: 	    my $label = "$Apache::randomlabel::label_arr[ $idx_arr[$_] ]";
  297: 	    my $x = $Apache::randomlabel::xcoord[$_];
  298: 	    my $y = $Apache::randomlabel::ycoord[$_];
  299: 	    my $value = $Apache::randomlabel::value[$_];
  300: 	    if( $type eq 'text') {
  301: 		&add_vars($gname,$_,$label,$idx_arr[$_],$value,'',$safeeval);
  302: 		$str = 'LB'.$Apache::randomlabel::tlabel_cnt;
  303: 		$xstr = 'X'.$Apache::randomlabel::tlabel_cnt;
  304: 		$ystr = 'Y'.$Apache::randomlabel::tlabel_cnt;
  305: 		$Apache::randomlabel::tlabel_cnt += 1;
  306: 	    } elsif ( $type eq 'image') {
  307: 		&add_vars($gname,$_,
  308: 			  $Apache::randomlabel::description[$idx_arr[$_]],
  309: 			  $idx_arr[$_],$value,$label,$safeeval);
  310: 		$str = 'IMG'.$Apache::randomlabel::ilabel_cnt;
  311: 		$xstr = 'IX'.$Apache::randomlabel::ilabel_cnt;
  312: 		$ystr = 'IY'.$Apache::randomlabel::ilabel_cnt;
  313: 		$Apache::randomlabel::ilabel_cnt += 1;
  314: 	    } else {
  315: 		&Apache::lonxml::error('Unknown type of label :'.$type.':');
  316: 	    }
  317: 	    if ($target eq 'web') {
  318: 		$args{"cgi.$cgi_id.$str"} =&Apache::lonnet::escape($label);
  319: 		$args{"cgi.$cgi_id.$xstr"}=$x;
  320: 		$args{"cgi.$cgi_id.$ystr"}=$y;
  321: 	    }
  322: 	}
  323:     } elsif ($target eq 'tex') {
  324: 	my $WX1=0; #  Web x-coord. of upper left corner (ULC)
  325: 	my $WY1=0; #  Web y-coord. of (ULC)
  326: 	my $wwidth=&Apache::lonxml::get_param('width',$parstack,$safeeval,-2);
  327: 	my $wheight=&Apache::lonxml::get_param('height',$parstack,$safeeval,-2);
  328: 	my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,-2,1));
  329: 	if (!$texwidth) { $texwidth=90; }
  330: 	my $TX1=0;
  331: 	my $TY1=$texwidth*($wheight/$wwidth);
  332: 	my $TX2=$texwidth;
  333: 	my $TY2=0;
  334: 
  335: 
  336: 	my $slopex=($wwidth-$WX1)/($TX2-$TX1);
  337: 	my $slopey=($wheight-$WY1)/($TY2-($TY1-1.0));
  338: 	my $cstx=$wwidth-$slopex*($TX2);
  339: 	my $csty=$wheight-$slopey*($TY2);
  340: 
  341: 	my @idx_arr = (0 .. $#Apache::randomlabel::label_arr);
  342: 	&Apache::structuretags::shuffle(\@idx_arr);
  343: 
  344: 	&Apache::lonxml::debug("Array is:".$#Apache::randomlabel::label_arr.":");
  345: 	for(my $i=0;$i <= $#Apache::randomlabel::label_arr; $i++) {
  346: 	    my $label = "$Apache::randomlabel::label_arr[ $idx_arr[$i] ]";
  347: 	    my $x = $Apache::randomlabel::xcoord[$i];
  348: 	    my $y = $Apache::randomlabel::ycoord[$i];
  349: 	    my $value = $Apache::randomlabel::value[$i];
  350: 	    #x latex coordinate
  351: 	    my $tcX=($x)*($texwidth/$wwidth);
  352: 	    #y latex coordinate
  353:             #      my $ratio=($wwidth > 0 ? $wheight/$wwidth : 1 );
  354: 	    my $tcY=$TY1-$y*($TY1/$wheight);
  355: 	    $tcX=sprintf('%.2f',$tcX);
  356: 	    $tcY=sprintf('%.2f',$tcY);
  357: 	    $result.='\put('.$tcX.','.$tcY.'){\normalsize \bf '.$label.'}'."\n";
  358: 	    if( $type eq 'text') {
  359: 		&add_vars($gname,$i,$label,$idx_arr[$i],$value,'',$safeeval);
  360: 	    } elsif ( $type eq 'image') {
  361: 		&add_vars($gname,$i,
  362: 			  $Apache::randomlabel::description[$idx_arr[$i]],
  363: 			  $idx_arr[$i],$value,$label,$safeeval);
  364: 	    } else {
  365: 		&Apache::lonxml::error('Unknown type of label :'.$type.':');
  366: 	    }
  367: 	}
  368:     } elsif ($target eq 'edit') {
  369: 	$result.=&Apache::edit::end_table;
  370:     }
  371:     return $result;
  372: }
  373: 
  374: # <location x="123" y="456" value="some value"/>
  375: sub start_location {
  376:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  377:     my $x= &check_int(&Apache::lonxml::get_param('x',$parstack,$safeeval),50);
  378:     my $y= &check_int(&Apache::lonxml::get_param('y',$parstack,$safeeval),50);
  379:     my $value= &Apache::lonxml::get_param('value',$parstack,$safeeval);
  380:     my $result='';
  381:     push(@Apache::randomlabel::xcoord,$x);
  382:     push(@Apache::randomlabel::ycoord,$y);
  383:     push(@Apache::randomlabel::value,$value);
  384:     if ($target eq 'edit') {
  385: 	$result.=&Apache::edit::tag_start($target,$token);
  386: 	$result.=&Apache::edit::text_arg('X:','x',$token,4).
  387: 	    &Apache::edit::text_arg('Y:','y',$token,4).
  388: 	    &Apache::edit::entercoords('x','y','attribute','width','height').'&nbsp;&nbsp;&nbsp;'.
  389: 	    &Apache::edit::text_arg('Value:','value',$token).
  390: 	    &Apache::edit::end_row();
  391: 	$result.=&Apache::edit::end_table;
  392:     } elsif ($target eq 'modified') {
  393: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  394: 						    $safeeval,'x','y','value');
  395: 	if ($constructtag) {
  396: 	    $result = &Apache::edit::rebuild_tag($token);
  397: 	    $result.=&Apache::edit::handle_insert();
  398: 	}
  399:     }
  400:     return $result;
  401: }
  402: 
  403: sub end_location {
  404:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  405:     my @result;
  406:     if ($target eq 'edit') { @result=('','no') }
  407:     return @result;
  408: }
  409: 
  410: # <label>$var_abc</label>
  411: sub start_label {
  412:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  413:     my $result='';
  414:     my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval,-2);
  415:     if ($target eq 'web' || $target eq 'tex' ||
  416: 	$target eq 'grade' || $target eq 'answer' || $target eq 'analyze') {
  417: 	&Apache::lonxml::startredirection; 
  418:     } elsif ($target eq 'edit') {
  419: 	$result.=&Apache::edit::tag_start($target,$token,"$type Label");
  420: 	my $text=&Apache::lonxml::get_all_text("/label",$parser);
  421: 	if ($type eq 'image') {
  422: 	    $result.=&Apache::edit::end_row().
  423: 		&Apache::edit::start_spanning_row();
  424: 	    $result.=&Apache::edit::text_arg('Description:','description',
  425: 					     $token);
  426: 	}
  427: 	if ($type eq 'text') { $result.="Label Text:"; }
  428: 	if ($type eq 'image') { $result.="Path to image:&nbsp;"; }
  429: 	$result.=&Apache::edit::editline('',$text,'',50).
  430: 	    &Apache::edit::end_table();
  431:     } elsif ($target eq 'modified') {
  432: 	$result = '<label>';
  433: 	if ($type eq 'image') {
  434: 	    my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  435: 							 $safeeval,
  436: 							 'description');
  437: 	    if ($constructtag) {
  438: 		$result = &Apache::edit::rebuild_tag($token);
  439: 	    } else {
  440: 		$result = $token->[4];
  441: 	    }
  442: 	}
  443: 	$result.=&Apache::edit::modifiedfield("/label",$parser);
  444:     }
  445:     return $result;
  446: }
  447: 
  448: sub end_label {
  449:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  450:     my @result;
  451:     if ($target eq 'edit') {
  452: 	@result=('','no') ;
  453:     } elsif ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
  454: 	     $target eq 'answer' || $target eq 'analyze') {
  455: 	my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval,-2);
  456: 	my $ltext=&Apache::lonxml::endredirection; 
  457: 	if ($type eq 'image') {
  458: 	    &Apache::lonxml::debug("Turning $ltext, $Apache::lonxml::pwd[-1]");
  459: 	    $ltext=&Apache::imageresponse::clean_up_image($ltext);
  460: #	    $ltext=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],
  461: #						 $ltext);
  462: 	    &Apache::lonxml::debug("into $ltext");
  463: 	    my $description = &Apache::lonxml::get_param('description',
  464: 							 $parstack,$safeeval);
  465: 	    push(@Apache::randomlabel::description,$description);
  466: 	}
  467: 	push(@Apache::randomlabel::label_arr,$ltext);
  468:     }
  469:     return @result;
  470: }
  471: 
  472: 1;
  473: __END__
  474:  

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