Annotation of loncom/interface/groupsort.pm, revision 1.45

1.1       harris41    1: # The LearningOnline Network with CAPA
1.4       harris41    2: # The LON-CAPA group sort handler
                      3: # Allows for sorting prior to import into RAT.
                      4: #
1.45    ! www         5: # $Id: groupsort.pm,v 1.44 2006/06/19 09:40:17 www Exp $
1.4       harris41    6: # 
                      7: # Copyright Michigan State University Board of Trustees
                      8: #
                      9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     10: #
                     11: # LON-CAPA is free software; you can redistribute it and/or modify
                     12: # it under the terms of the GNU General Public License as published by
                     13: # the Free Software Foundation; either version 2 of the License, or
                     14: # (at your option) any later version.
                     15: #
                     16: # LON-CAPA is distributed in the hope that it will be useful,
                     17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     19: # GNU General Public License for more details.
1.1       harris41   20: #
1.4       harris41   21: # You should have received a copy of the GNU General Public License
                     22: # along with LON-CAPA; if not, write to the Free Software
                     23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     24: #
                     25: # /home/httpd/html/adm/gpl.txt
1.1       harris41   26: #
1.4       harris41   27: # http://www.lon-capa.org/
1.1       harris41   28: #
1.4       harris41   29: ###
1.1       harris41   30: 
                     31: package Apache::groupsort;
                     32: 
                     33: use strict;
                     34: 
                     35: use Apache::Constants qw(:common);
                     36: use GDBM_File;
1.15      www        37: use Apache::loncommon;
1.23      www        38: use Apache::lonlocal;
1.27      taceyjo1   39: use Apache::lonnet;
1.1       harris41   40: 
1.33      www        41: my $iconpath; # variable to be accessible to multiple subroutines
1.2       harris41   42: my %hash; # variable to tie to user specific database
1.8       www        43: 
1.2       harris41   44: 
1.33      www        45: sub readfromdb {
                     46:     my ($r,$shash,$thash)=@_;
1.9       www        47: 
1.42      www        48:     my $diropendb = 
                     49:        "/home/httpd/perl/tmp/$env{'user.domain'}_$env{'user.name'}_sel_res.db";
1.11      www        50: 
                     51: # ----------------------------- diropendb is now the filename of the db to open
1.13      albertel   52:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
1.31      albertel   53: 	my $acts = $env{'form.acts'};
1.2       harris41   54: 	my @Acts = split(/b/,$acts);
1.1       harris41   55: 	my %ahash;
                     56: 	my %achash;
1.2       harris41   57: 	my $ac = 0;
1.5       harris41   58: 	foreach (@Acts) {
1.2       harris41   59: 	    my ($state,$ref) = split(/a/);
                     60: 	    $ahash{$ref} = $state;
                     61: 	    $achash{$ref} = $ac;
1.1       harris41   62: 	    $ac++;
1.5       harris41   63: 	}
                     64: 	foreach (sort {$achash{$a} <=> $achash{$b}} (keys %ahash)) {
1.2       harris41   65: 	    my $key = $_;
1.1       harris41   66: 	    if ($ahash{$key} eq '1') {
1.2       harris41   67: 		$hash{'store_'.$hash{'pre_'.$key.'_link'}} =
1.1       harris41   68: 		    $hash{'pre_'.$key.'_title'};
1.2       harris41   69: 		$hash{'storectr_'.$hash{'pre_'.$key.'_link'}} =
1.1       harris41   70: 		    $hash{'storectr'}+0;
                     71: 		$hash{'storectr'}++;
                     72: 	    }
                     73: 	    if ($ahash{$key} eq '0') {
                     74: 		if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
                     75: 		    delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
                     76: 		}
                     77: 	    }
1.5       harris41   78: 	}
                     79: 	foreach (keys %hash) {
1.1       harris41   80: 	    if ($_ =~ /^store_/) {
1.2       harris41   81: 		my $key = $_;
                     82: 		$key =~ s/^store_//;
1.33      www        83: 		$$shash{$key} = $hash{'storectr_'.$key};
1.27      taceyjo1   84: 		if (&Apache::lonnet::gettitle($key) eq '') {
1.33      www        85: 		    $$thash{$key} = $hash{'store_'.$key};
1.28      albertel   86: 		} else {
1.33      www        87: 		    $$thash{$key} = &Apache::lonnet::gettitle($key);
1.28      albertel   88: 		}
1.1       harris41   89: 	    }
1.5       harris41   90: 	}
1.31      albertel   91: 	if ($env{'form.oldval'}) {
1.2       harris41   92: 	    my $newctr = 0;
1.1       harris41   93: 	    my %chash;
1.33      www        94: 	    foreach (sort {$$shash{$a} <=> $$shash{$b}} (keys %{$shash})) {
1.2       harris41   95: 		my $key = $_;
1.1       harris41   96: 		$newctr++;
1.33      www        97: 		$$shash{$key} = $newctr;
1.2       harris41   98: 		$hash{'storectr_'.$key} = $newctr;
                     99: 		$chash{$newctr} = $key;
1.5       harris41  100: 	    }
1.31      albertel  101: 	    my $oldval = $env{'form.oldval'};
                    102: 	    my $newval = $env{'form.newval'};
1.2       harris41  103: 	    if ($oldval != $newval) {
1.3       harris41  104: 		# when newval==0, then push down and delete
                    105: 		if ($newval!=0) {
1.33      www       106: 		    $$shash{$chash{$oldval}} = $newval;
1.3       harris41  107: 		    $hash{'storectr_'.$chash{$oldval}} = $newval;
1.33      www       108: 		} else {
                    109: 		    $$shash{$chash{$oldval}} = $newctr;
1.3       harris41  110: 		    $hash{'storectr_'.$chash{$oldval}} = $newctr;
                    111: 		}
                    112: 		if ($newval==0) { # push down
                    113: 		    my $newval2=$newctr;
                    114: 		    for my $idx ($oldval..($newval2-1)) {
1.33      www       115: 			$$shash{$chash{$idx+1}} = $idx;
1.3       harris41  116: 			$hash{'storectr_'.$chash{$idx+1}} = $idx;
                    117: 		    }
1.33      www       118: 		    delete $$shash{$chash{$oldval}};
1.3       harris41  119: 		    delete $hash{'storectr_'.$chash{$oldval}};
                    120: 		    delete $hash{'store_'.$chash{$oldval}};
1.33      www       121: 		} elsif ($oldval < $newval) { # push down
1.1       harris41  122: 		    for my $idx ($oldval..($newval-1)) {
1.33      www       123: 			$$shash{$chash{$idx+1}} = $idx;
1.2       harris41  124: 			$hash{'storectr_'.$chash{$idx+1}} = $idx;
1.1       harris41  125: 		    }
1.33      www       126: 		} elsif ($oldval > $newval) { # push up
1.1       harris41  127: 		    for my $idx (reverse($newval..($oldval-1))) {
1.33      www       128: 			$$shash{$chash{$idx}} = $idx+1;
1.2       harris41  129: 			$hash{'storectr_'.$chash{$idx}} = $idx+1;
1.1       harris41  130: 		    }
                    131: 		}
                    132: 	    }
                    133: 	}
                    134:     } else {
1.34      www       135: 	$r->print('Unable to tie hash to db file');
1.1       harris41  136:     }
                    137:     untie %hash;
1.33      www       138:     return ($shash,$thash);
                    139: }
                    140: 
                    141: 
                    142: 
                    143: sub cleanup {
                    144:     if (tied(%hash)){
                    145: 	&Apache::lonnet::logthis('Cleanup groupsort: hash');
                    146:         unless (untie(%hash)) {
                    147: 	    &Apache::lonnet::logthis('Failed cleanup groupsort: hash');
                    148:         }
                    149:     }
1.39      albertel  150:     return OK;
1.33      www       151: }
                    152: 
1.34      www       153: # -------------------------------------------------------------- Read from file
                    154: 
                    155: sub readfromfile {
1.35      www       156:     my ($r,$shash,$thash,$nhash)=@_;
1.34      www       157:     my $cont=&Apache::lonnet::getfile
                    158: 	(&Apache::lonnet::filelocation('',$env{'form.readfile'}));
                    159:     if ($cont==-1) {
                    160: 	$r->print('Unable to read file: '.
                    161: 		  &Apache::lonnet::filelocation('',$env{'form.readfile'}));
                    162:     } else {
                    163:         my $parser = HTML::TokeParser->new(\$cont);
                    164:         my $token;
1.35      www       165: 	my $n=1;
1.34      www       166:         while ($token = $parser->get_token) {
                    167: 	    if ($token->[0] eq 'S') {
                    168:                 if ($token->[1] eq 'resource') {
                    169: 		    if ($env{'form.recover'}) {
                    170: 			if ($token->[2]->{'type'} ne 'zombie') { next; }
                    171: 		    } else {
                    172: 			if ($token->[2]->{'type'} eq 'zombie') { next; }
                    173: 		    }
1.35      www       174: 
                    175: 		    my $url=$token->[2]->{'src'};
1.34      www       176:                     my $name=$token->[2]->{'title'};
                    177: 		    $name=~s/ \[\((\d+)\,(\w+)\,(\w+)\)\]$//;
                    178: 		    if ($1) {
1.35      www       179: 			$$nhash{$url}='<br />'.&mt('Removed by ').
1.34      www       180: 			    &Apache::loncommon::plainname($2,$3).', '.
                    181: 			    &Apache::lonlocal::locallocaltime($1);
                    182: 		    }
1.37      www       183: 		    $name=~s/\&colon\;/\:/g;
1.35      www       184: 		    $$thash{$url}=$name;
                    185:                     $$shash{$url}=$n;
                    186:                     $n++;
1.34      www       187: 		}
                    188: 	    }
                    189: 	}
                    190:     }
                    191:     return ($shash,$thash);
                    192: }
                    193: 
1.44      www       194: # --------------------------------------------------------- Read from bookmarks
                    195: 
                    196: sub readfrombookmarks {
                    197:     my ($r,$shash,$thash)=@_;
                    198:     my %bookmarks=&Apache::lonnet::dump('bookmarks');
                    199: # the bookmark "hash" is just one entry
                    200: # it's a javascript program code with arguments like ('title','url');
                    201:     my @bookmarks=($bookmarks{'bookmarks'}=~/\((?:\'([^\']+)\'\,\'([^\']+)\'|\"([^\"]+)\"\,\"([^\"]+)\")\)\;/g);
                    202:     my $order=1;
                    203:     for (my $index=0;$index<($#bookmarks+1)/2;$index++) {
                    204:         if ($bookmarks[$index*2+1]) {
                    205: 	    $$thash{$bookmarks[$index*2+1]}=$bookmarks[$index*2];
                    206: 	    $$thash{$bookmarks[$index*2+1]}=~s/^LON\-CAPA\s+//;
                    207: 	    $$shash{$bookmarks[$index*2+1]}=$order;
                    208: 	    $order++;
                    209: 	}
                    210:     }
                    211:     return ($shash,$thash);
                    212: }
                    213: 
1.45    ! www       214: # ---------------------------------------------------------- Clear the database
        !           215: 
        !           216: sub clear_basket {
        !           217:     my $diropendb =
        !           218:        "/home/httpd/perl/tmp/$env{'user.domain'}_$env{'user.name'}_sel_res.db";
        !           219:     unlink ($diropendb);
        !           220: }                                                                                                         
        !           221: 
1.33      www       222: # ---------------------------------------------------------------- Main Handler
                    223: sub handler {
                    224:     my $r = shift;
                    225:  
                    226:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.44      www       227: 			     ['acts','mode','readfile','recover','bookmarks']);
1.33      www       228:     # color scheme
                    229:     my $fileclr = '#ffffe6';
                    230:     my $titleclr = '#ddffff';
                    231: 
                    232:     &Apache::loncommon::content_type($r,'text/html');
                    233:     $r->send_http_header;
                    234:     return OK if $r->header_only;
                    235: 
                    236: # finish_import looks different for graphical or "simple" RAT
                    237:     my $finishimport='';
1.37      www       238:     my $begincondition='';
                    239:     my $endcondition='';
1.44      www       240:     if (($env{'form.readfile'}) || ($env{'form.bookmarks'}))  {
1.37      www       241:         $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';
                    242: 	$endcondition='}';
                    243:     }
1.33      www       244:     if ($env{'form.mode'} eq 'simple' || $env{'form.mode'} eq '') {
                    245:         $finishimport=(<<ENDSMP);
                    246: function finish_import() {
                    247:     opener.document.forms.simpleedit.importdetail.value='';
                    248:     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
1.37      www       249: 	$begincondition
1.33      www       250: 	opener.document.forms.simpleedit.importdetail.value+='&'+
                    251:               escape(eval("document.forms.groupsort.title"+num+".value"))+'='+
                    252: 	      escape(eval("document.forms.groupsort.filelink"+num+".value"));
1.37      www       253: 	$endcondition
1.33      www       254:     }
                    255:     opener.document.forms.simpleedit.submit();
                    256:     self.close();
                    257: }
                    258: ENDSMP
                    259:     } else {
                    260:         $finishimport=(<<ENDADV);
                    261: function finish_import() {
                    262:     var linkflag=false;
                    263:     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
1.37      www       264: 	$begincondition
1.33      www       265: 	insertRowInLastRow();
                    266: 	placeResourceInLastRow(
                    267: 	       eval("document.forms.groupsort.title"+num+".value"),
                    268:  	       eval("document.forms.groupsort.filelink"+num+".value"),
                    269: 	       linkflag
                    270: 	);
                    271:         linkflag=true;
1.37      www       272: 	$endcondition
1.33      www       273:     }
                    274:     opener.editmode=0;
                    275:     opener.notclear=0;
                    276:     opener.linkmode=0;
                    277:     opener.draw();
                    278:     self.close();
                    279: }
                    280: ENDADV
                    281:     }
                    282: 
                    283: # output start of web page
1.40      albertel  284:     my $js = <<END;
                    285: <script type="text/javascript">
1.33      www       286: function insertRowInLastRow() {
                    287:     opener.insertrow(opener.maxrow);
                    288:     opener.addobj(opener.maxrow,'e&2');
                    289: }
                    290: function placeResourceInLastRow (title,url,linkflag) {
                    291:     opener.mostrecent=opener.newresource(opener.maxrow,2,opener.escape(title),
                    292: 		       opener.escape(url),'false','normal');
                    293:     opener.save();
                    294:     if (linkflag) {
                    295: 	opener.joinres(opener.linkmode,opener.mostrecent,0);
                    296:     }
                    297:     opener.linkmode=opener.mostrecent;
                    298: }
                    299: $finishimport
                    300: function selectchange(val) {
                    301:     var newval=0+eval("document.forms.groupsort.alt"+val+".selectedIndex");
                    302:     orderchange(val,newval);
                    303: }
                    304: function move(val,newval) {
                    305:     orderchange(val,newval);
                    306: }
                    307: function orderchange(val,newval) {
                    308:     document.forms.groupsort.oldval.value=val;
                    309:     document.forms.groupsort.newval.value=newval;
                    310:     document.forms.groupsort.submit();
                    311: }
                    312: </script>
                    313: END
                    314:     # read pertinent machine configuration
                    315:     my $domain  = $r->dir_config('lonDefDomain');
                    316:     $iconpath = $r->dir_config('lonIconsURL') . "/";
                    317: 
                    318:     my %shash; # sort order (key is resource location, value is sort order)
                    319:     my %thash; # title (key is resource location, value is title)
1.35      www       320:     my %nhash; # notes (key is resource location);
1.33      www       321: 
1.34      www       322:     if ($env{'form.readfile'}) {
1.35      www       323: 	&readfromfile($r,\%shash,\%thash,\%nhash);
1.44      www       324:     } elsif ($env{'form.bookmarks'}) {
                    325: 	&readfrombookmarks($r,\%shash,\%thash);
1.34      www       326:     } else {
                    327: 	&readfromdb($r,\%shash,\%thash);
                    328:     }
1.33      www       329: 
1.2       harris41  330:     my $ctr = 0;
                    331:     my $clen = scalar(keys %shash);
1.44      www       332:     if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.23      www       333: 	my %lt=&Apache::lonlocal::texthash(
                    334: 		'fin'=> 'Finalize order of resources',
1.42      www       335: 		'ci' => 'Continue Import',
                    336: 		'cs' => 'Continue Search',
1.23      www       337: 		'fi' => 'Finish Import',
                    338: 		'ca' => 'Cancel',
                    339: 		'co' => 'Change Order',
                    340: 		'ti' => 'Title',
1.37      www       341: 		'pa' => 'Path',
                    342:                 'in' => 'Include'
1.23      www       343: 		);
1.40      albertel  344: 	$r->print(&Apache::loncommon::start_page('Sort Imported Resources',
                    345: 						 $js));
1.22      albertel  346: 	$r->print(<<END);
1.23      www       347: <b><font color="#888888">$lt{'fin'}</font></b>
1.14      matthew   348: <form method='post' action='/adm/groupsort' name='groupsort'
                    349:       enctype='application/x-www-form-urlencoded'>
1.1       harris41  350: <input type="hidden" name="fnum" value="$clen" />
                    351: <input type="hidden" name="oldval" value="" />
                    352: <input type="hidden" name="newval" value="" />
1.31      albertel  353: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1.36      www       354: <input type="hidden" name="readfile" value="$env{'form.readfile'}" />
1.44      www       355: <input type="hidden" name="bookmarks" value="$env{'form.bookmarks'}" />
1.36      www       356: <input type="hidden" name="recover" value="$env{'form.recover'}" />
1.3       harris41  357: END
1.11      www       358: 
1.42      www       359:         # --- Continue Buttons
                    360:         my $resurl = &Apache::loncommon::lastresurl();
                    361:         $r->print(<<END);
                    362: <input type="button" name="alter" value="$lt{'ci'}"
1.43      www       363:  onClick="window.location='$resurl?catalogmode=import'" />&nbsp;
1.42      www       364: <input type="button" name="altersearch" value="$lt{'cs'}"
1.43      www       365:  onClick="window.location='/adm/searchcat?catalogmode=import'" />&nbsp;
1.3       harris41  366: END
1.22      albertel  367:         # ---
1.11      www       368: 
1.22      albertel  369: 	$r->print(<<END);
1.23      www       370: <input type="button" name="alter" value="$lt{'fi'}"
1.2       harris41  371:  onClick="finish_import()" />&nbsp;
1.23      www       372: <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />
1.1       harris41  373: END
1.22      albertel  374:         $r->print("<table border='0'><tr><td bgcolor='#eeeeee'>");
                    375: 	$r->print("<table border=0><tr>\n");
1.44      www       376: 	if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) { 
1.37      www       377: 	    $r->print("<td bgcolor='$titleclr'><b>$lt{'in'}</b></td>\n");
                    378: 	} else { 
                    379: 	    $r->print("<td colspan='2' bgcolor='$titleclr'><b>$lt{'co'}</b></td>\n"); 
                    380: 	}
1.23      www       381: 	$r->print("<td colspan='2' bgcolor='$titleclr'><b>$lt{'ti'}</b></td>\n");
                    382: 	$r->print("<td bgcolor='$titleclr'><b>$lt{'pa'}</b></td></tr>\n");
1.22      albertel  383:     } else {
1.40      albertel  384: 	$r->print(&Apache::loncommon::start_page(undef,$js,
1.41      banghart  385: 						 {'only_body' => 1}));
1.22      albertel  386: 	$r->print(<<END);
                    387: <form method='post' action='/adm/groupsort' name='groupsort'
                    388:       enctype='application/x-www-form-urlencoded'>
                    389: <input type="hidden" name="fnum" value="$clen" />
                    390: <input type="hidden" name="oldval" value="" />
                    391: <input type="hidden" name="newval" value="" />
1.31      albertel  392: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1.22      albertel  393: END
                    394:     }
1.5       harris41  395:     foreach (sort {$shash{$a}<=>$shash{$b}} (keys %shash)) {
1.1       harris41  396: 	my $key=$_;
                    397: 	$ctr++;
1.25      albertel  398: 	my $iconname=&Apache::loncommon::icon($key);
1.44      www       399: 	if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.22      albertel  400: 	    $r->print("<tr><td bgcolor='$fileclr'>");
1.44      www       401:             if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.37      www       402: 		$r->print(&checkbox($ctr-1));
                    403: 	    } else {
                    404: 		$r->print(&movers($clen,$ctr));
                    405: 	    }
1.22      albertel  406: 	}
1.1       harris41  407: 	$r->print(&hidden($ctr-1,$thash{$key},$key));
1.44      www       408: 	if (($clen > 1)  || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.37      www       409: 	    $r->print("</td>");
1.44      www       410:             unless (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.37      www       411: 		$r->print("<td bgcolor='$fileclr'>".
                    412: 			  &select_box($clen,$ctr).
                    413: 			  "</td>");
                    414: 	    }
                    415: 	    $r->print("<td bgcolor='$fileclr'>");
1.26      albertel  416: 	    $r->print("<img src='$iconname' />");
1.22      albertel  417: 	    $r->print("</td><td bgcolor='$fileclr'>");
1.36      www       418: 	    $r->print("$thash{$key}$nhash{$key}</td><td bgcolor='$fileclr'>\n");
1.22      albertel  419: 	    $r->print("$key</td></tr>\n");
                    420: 	} 
                    421:     }
1.44      www       422:     if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.22      albertel  423: 	$r->print("</table></td></tr></table></form>");
                    424:     } else {
                    425: 	$r->print(<<END);
                    426: <script type="text/javascript">
                    427:     finish_import();
                    428: </script>
                    429: END
                    430:     }
1.40      albertel  431: 
                    432:     $r->print(&Apache::loncommon::end_page());
1.22      albertel  433: 
1.1       harris41  434:     return OK;
                    435: }
                    436: 
1.2       harris41  437: # --------------------------------------- Hidden values (returns scalar string)
1.1       harris41  438: sub hidden {
1.2       harris41  439:     my ($sel,$title,$filelink) = @_;
                    440:     my $string = '<input type="hidden" name="title'.$sel.'" value="'.$title.
                    441: 	'" />';
                    442:     $string .= '<input type="hidden" name="filelink'.$sel.'" value="'.
                    443: 	$filelink.'" />';
1.1       harris41  444:     return $string;
                    445: }
                    446: 
1.2       harris41  447: # --------------------------------------- Moving arrows (returns scalar string)
1.1       harris41  448: sub movers {
1.2       harris41  449:     my ($total,$sel) = @_;
                    450:     my $dsel = $sel-1;
                    451:     my $usel = $sel+1;
                    452:     $usel = 1 if $usel > $total;
                    453:     $dsel = $total if $dsel < 1;
1.1       harris41  454:     my $string;
1.2       harris41  455:     $string = (<<END);
1.1       harris41  456: <table border='0' cellspacing='0' cellpadding='0'>
1.2       harris41  457: <tr><td><a href='javascript:move($sel,$dsel)'>
                    458: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
                    459: <tr><td><a href='javascript:move($sel,$usel)'>
                    460: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
1.1       harris41  461: </table>
                    462: END
                    463:     return $string;
                    464: }
1.2       harris41  465: 
                    466: # ------------------------------------------ Select box (returns scalar string)
1.1       harris41  467: sub select_box {
1.2       harris41  468:     my ($total,$sel) = @_;
1.1       harris41  469:     my $string;
1.2       harris41  470:     $string = '<select name="alt'.$sel.'"';
                    471:     $string .= " onChange='selectchange($sel)'>";
1.36      www       472:     $string .= "<option name='o0' value='0'>".&mt('discard')."</option>";
1.1       harris41  473:     for my $cur (1..$total) {
1.2       harris41  474: 	$string .= "<option name='o$cur' value='$cur'";
                    475: 	if ($cur == $sel) {
                    476: 	    $string .= "selected";
1.1       harris41  477: 	}
1.2       harris41  478: 	$string .= ">$cur</option>";
1.1       harris41  479:     }
1.2       harris41  480:     $string .= "</select>\n";
1.1       harris41  481:     return $string;
                    482: }
                    483: 
1.37      www       484: # ------------------------------------------------------------------- Checkbox
                    485: 
                    486: sub checkbox {
                    487:     my $sel=shift;
                    488:     return "<label><input type='checkbox' name='include$sel'".
                    489:        ($env{"form.include$sel"}?' checked="checked"':'').
                    490:        ' />'.&mt('Include').'</label>';
                    491: }
                    492: 
1.1       harris41  493: 1;
                    494: 
                    495: __END__

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