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

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.66    ! bisitz      5: # $Id: groupsort.pm,v 1.65 2009/03/13 15:39:43 bisitz 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.61      albertel   40: use LONCAPA;
1.1       harris41   41: 
1.33      www        42: my $iconpath; # variable to be accessible to multiple subroutines
1.2       harris41   43: my %hash; # variable to tie to user specific database
1.8       www        44: 
1.2       harris41   45: 
1.55      albertel   46: sub update_actions_hash {
                     47:     my ($hash) = @_;
1.60      banghart   48:     # be careful in here, there is also a global %hash
1.55      albertel   49:     my $acts=$env{'form.acts'};
                     50:     my @Acts=split(/b/,$acts);
                     51:     my %ahash;
                     52:     my %achash;
1.60      banghart   53:     # some initial hashes for working with data
1.55      albertel   54:     my $ac=0;
                     55:     foreach (@Acts) {
1.60      banghart   56:  	my ($state,$ref)=split(/a/);
1.55      albertel   57: 	$ahash{$ref}=$state;
                     58: 	$achash{$ref}=$ac;
                     59: 	$ac++;
                     60:     }
                     61:     # sorting through the actions and changing the global database hash
                     62:     foreach my $key (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
                     63: 	if ($ahash{$key} eq '1') {
1.60      banghart   64: 	    $hash->{'store_'.$hash->{'pre_'.$key.'_link'}}=
1.55      albertel   65: 		$hash->{'pre_'.$key.'_title'};
1.60      banghart   66: 	    $hash->{'storectr_'.$hash->{'pre_'.$key.'_link'}}=
1.55      albertel   67: 		$hash->{'storectr'}+0;
                     68: 	    $hash->{'storectr'}++;
                     69: 	}
                     70: 	if ($ahash{$key} eq '0') {
1.60      banghart   71: 	    if ($hash->{'store_'.$hash->{'pre_'.$key.'_link'}}) {
                     72: 		delete($hash->{'store_'.$hash->{'pre_'.$key.'_link'}});
                     73: 		delete($hash->{'storectr_'.$hash->{'pre_'.$key.'_link'}});
1.55      albertel   74: 	    }
                     75: 	}
                     76:     }
                     77:     # deleting the previously cached listing
                     78:     foreach my $key (keys(%{ $hash })) {
                     79: 	next if ($key !~ /^pre_(\d+)_link/);
                     80: 	my $which = $1;
                     81: 	delete($hash->{'pre_'.$which.'_title'});
                     82: 	delete($hash->{'pre_'.$which.'_link'});
                     83:     }
                     84: }
                     85: 
1.33      www        86: sub readfromdb {
1.57      albertel   87:     my ($r,$resources)=@_;
1.9       www        88: 
1.42      www        89:     my $diropendb = 
                     90:        "/home/httpd/perl/tmp/$env{'user.domain'}_$env{'user.name'}_sel_res.db";
1.11      www        91: 
                     92: # ----------------------------- diropendb is now the filename of the db to open
1.13      albertel   93:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
1.55      albertel   94: 	&update_actions_hash(\%hash);
                     95: 
1.57      albertel   96: 	my %temp_resources;
                     97: 	foreach my $key (keys(%hash)) {
                     98: 	    next if ($key !~ /^store_/);
                     99: 	    my ($url) = ($key =~ /^store_(.*)/);
                    100: 	    $temp_resources{$hash{'storectr_'.$url}}{'url'}=$url;
                    101: 	    $temp_resources{$hash{'storectr_'.$url}}{'title'}=
                    102: 		&Apache::lonnet::gettitle($url);
                    103: 	}
                    104: 
                    105: 	# use the temp, since there might be gaps in the counting
                    106: 	foreach my $item (sort {$a <=> $b} (keys(%temp_resources))) {
                    107: 	    push(@{ $resources },$temp_resources{$item});
1.5       harris41  108: 	}
1.57      albertel  109: 
1.31      albertel  110: 	if ($env{'form.oldval'}) {
1.57      albertel  111: 	    my $res = splice(@{$resources},$env{'form.oldval'}-1,1);
                    112: 	    if ($env{'form.newval'} == 0) {
                    113: 		# picked 'discard'
                    114: 		my $url =  $res->{'url'};
                    115: 		delete($hash{'storectr_'.$url});
                    116: 		delete($hash{'store_'.$url});
                    117: 	    } else {
                    118: 		splice(@{$resources},$env{'form.newval'}-1,0,$res);
1.1       harris41  119: 	    }
1.57      albertel  120: 	}
                    121: 	# store out new order
                    122: 	foreach my $which (0..$#$resources) {
                    123: 	    my $url =  $resources->[$which]{'url'};
                    124: 	    $hash{'storectr_'.$url} = $which;
1.1       harris41  125: 	}
                    126:     } else {
1.34      www       127: 	$r->print('Unable to tie hash to db file');
1.1       harris41  128:     }
1.57      albertel  129:     untie(%hash);
1.33      www       130: }
                    131: 
                    132: 
                    133: 
                    134: sub cleanup {
                    135:     if (tied(%hash)){
                    136: 	&Apache::lonnet::logthis('Cleanup groupsort: hash');
                    137:         unless (untie(%hash)) {
                    138: 	    &Apache::lonnet::logthis('Failed cleanup groupsort: hash');
                    139:         }
                    140:     }
1.39      albertel  141:     return OK;
1.33      www       142: }
                    143: 
1.34      www       144: # -------------------------------------------------------------- Read from file
                    145: 
                    146: sub readfromfile {
1.57      albertel  147:     my ($r,$resources)=@_;
1.34      www       148:     my $cont=&Apache::lonnet::getfile
                    149: 	(&Apache::lonnet::filelocation('',$env{'form.readfile'}));
                    150:     if ($cont==-1) {
                    151: 	$r->print('Unable to read file: '.
                    152: 		  &Apache::lonnet::filelocation('',$env{'form.readfile'}));
                    153:     } else {
                    154:         my $parser = HTML::TokeParser->new(\$cont);
                    155:         my $token;
                    156:         while ($token = $parser->get_token) {
                    157: 	    if ($token->[0] eq 'S') {
                    158:                 if ($token->[1] eq 'resource') {
                    159: 		    if ($env{'form.recover'}) {
                    160: 			if ($token->[2]->{'type'} ne 'zombie') { next; }
                    161: 		    } else {
                    162: 			if ($token->[2]->{'type'} eq 'zombie') { next; }
                    163: 		    }
1.35      www       164: 
1.34      www       165:                     my $name=$token->[2]->{'title'};
1.50      albertel  166: 		    $name=~s/ \[\((\d+)\,($LONCAPA::username_re)\,($LONCAPA::domain_re)\)\]$//;
1.57      albertel  167: 		    my $note;
1.34      www       168: 		    if ($1) {
1.57      albertel  169: 			$note = '<br />'.&mt('Removed by ').
1.34      www       170: 			    &Apache::loncommon::plainname($2,$3).', '.
                    171: 			    &Apache::lonlocal::locallocaltime($1);
                    172: 		    }
1.37      www       173: 		    $name=~s/\&colon\;/\:/g;
1.58      albertel  174: 		    push(@{$resources}, {'url'   => $token->[2]->{'src'},
1.57      albertel  175: 					 'title' => $name,
1.58      albertel  176: 					 'note'  => $note,
                    177: 				         'id'    => $token->[2]->{'id'},});
1.34      www       178: 		}
                    179: 	    }
                    180: 	}
                    181:     }
                    182: }
                    183: 
1.44      www       184: # --------------------------------------------------------- Read from bookmarks
                    185: 
                    186: sub readfrombookmarks {
1.57      albertel  187:     my ($r,$resources)=@_;
1.44      www       188:     my %bookmarks=&Apache::lonnet::dump('bookmarks');
                    189: # the bookmark "hash" is just one entry
                    190: # it's a javascript program code with arguments like ('title','url');
                    191:     my @bookmarks=($bookmarks{'bookmarks'}=~/\((?:\'([^\']+)\'\,\'([^\']+)\'|\"([^\"]+)\"\,\"([^\"]+)\")\)\;/g);
                    192:     for (my $index=0;$index<($#bookmarks+1)/2;$index++) {
                    193:         if ($bookmarks[$index*2+1]) {
1.57      albertel  194: 	    my $url  = $bookmarks[$index*2+1];
                    195: 	    my $name = $bookmarks[$index*2];
                    196: 	    $name =~ s/^LON\-CAPA\s+//;
                    197: 
                    198: 	    push(@{$resources},{'url' => $url, 'title' => $name});
1.44      www       199: 	}
                    200:     }
                    201: }
                    202: 
1.33      www       203: # ---------------------------------------------------------------- Main Handler
                    204: sub handler {
                    205:     my $r = shift;
                    206:  
                    207:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.44      www       208: 			     ['acts','mode','readfile','recover','bookmarks']);
1.33      www       209: 
                    210:     &Apache::loncommon::content_type($r,'text/html');
                    211:     $r->send_http_header;
                    212:     return OK if $r->header_only;
                    213: 
                    214: # finish_import looks different for graphical or "simple" RAT
                    215:     my $finishimport='';
1.37      www       216:     my $begincondition='';
                    217:     my $endcondition='';
1.44      www       218:     if (($env{'form.readfile'}) || ($env{'form.bookmarks'}))  {
1.37      www       219:         $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';
                    220: 	$endcondition='}';
                    221:     }
1.33      www       222:     if ($env{'form.mode'} eq 'simple' || $env{'form.mode'} eq '') {
                    223:         $finishimport=(<<ENDSMP);
                    224: function finish_import() {
                    225:     opener.document.forms.simpleedit.importdetail.value='';
                    226:     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
1.37      www       227: 	$begincondition
1.33      www       228: 	opener.document.forms.simpleedit.importdetail.value+='&'+
1.61      albertel  229:               eval("document.forms.groupsort.title"+num+".value")+'='+
                    230: 	      eval("document.forms.groupsort.filelink"+num+".value")+'='+
                    231: 	      eval("document.forms.groupsort.id"+num+".value");
1.37      www       232: 	$endcondition
1.33      www       233:     }
                    234:     opener.document.forms.simpleedit.submit();
                    235:     self.close();
                    236: }
                    237: ENDSMP
                    238:     } else {
                    239:         $finishimport=(<<ENDADV);
                    240: function finish_import() {
                    241:     var linkflag=false;
                    242:     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
1.37      www       243: 	$begincondition
1.33      www       244: 	insertRowInLastRow();
                    245: 	placeResourceInLastRow(
                    246: 	       eval("document.forms.groupsort.title"+num+".value"),
                    247:  	       eval("document.forms.groupsort.filelink"+num+".value"),
1.59      albertel  248:  	       eval("document.forms.groupsort.id"+num+".value"),
1.33      www       249: 	       linkflag
                    250: 	);
                    251:         linkflag=true;
1.37      www       252: 	$endcondition
1.33      www       253:     }
                    254:     opener.editmode=0;
                    255:     opener.notclear=0;
                    256:     opener.linkmode=0;
                    257:     opener.draw();
                    258:     self.close();
                    259: }
                    260: ENDADV
                    261:     }
                    262: 
                    263: # output start of web page
1.40      albertel  264:     my $js = <<END;
                    265: <script type="text/javascript">
1.33      www       266: function insertRowInLastRow() {
                    267:     opener.insertrow(opener.maxrow);
                    268:     opener.addobj(opener.maxrow,'e&2');
                    269: }
1.59      albertel  270: function placeResourceInLastRow (title,url,id,linkflag) {
1.33      www       271:     opener.mostrecent=opener.newresource(opener.maxrow,2,opener.escape(title),
1.59      albertel  272: 		       opener.escape(url),'false','normal',id);
1.33      www       273:     opener.save();
                    274:     if (linkflag) {
                    275: 	opener.joinres(opener.linkmode,opener.mostrecent,0);
                    276:     }
                    277:     opener.linkmode=opener.mostrecent;
                    278: }
                    279: $finishimport
                    280: function selectchange(val) {
                    281:     var newval=0+eval("document.forms.groupsort.alt"+val+".selectedIndex");
                    282:     orderchange(val,newval);
                    283: }
                    284: function move(val,newval) {
                    285:     orderchange(val,newval);
                    286: }
                    287: function orderchange(val,newval) {
                    288:     document.forms.groupsort.oldval.value=val;
                    289:     document.forms.groupsort.newval.value=newval;
                    290:     document.forms.groupsort.submit();
                    291: }
                    292: </script>
                    293: END
                    294:     # read pertinent machine configuration
                    295:     my $domain  = $r->dir_config('lonDefDomain');
                    296:     $iconpath = $r->dir_config('lonIconsURL') . "/";
                    297: 
1.57      albertel  298:     my @resources;
1.33      www       299: 
1.34      www       300:     if ($env{'form.readfile'}) {
1.57      albertel  301: 	&readfromfile($r,\@resources);
1.44      www       302:     } elsif ($env{'form.bookmarks'}) {
1.57      albertel  303: 	&readfrombookmarks($r,\@resources);
1.34      www       304:     } else {
1.57      albertel  305: 	&readfromdb($r,\@resources);
1.34      www       306:     }
1.33      www       307: 
1.2       harris41  308:     my $ctr = 0;
1.57      albertel  309:     my $clen = scalar(@resources);
1.66    ! bisitz    310:     my $title = '';
        !           311:     if ($env{'form.recover'}) {
        !           312:         $title = 'Recover Removed Resources';
        !           313:     } else {
        !           314:         $title = 'Sort Imported Resources';
        !           315:     }
        !           316:     if ($env{'form.bookmarks'}) {
        !           317:         $title = 'Import Resources from Bookmarks';
        !           318:     }
1.44      www       319:     if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.23      www       320: 	my %lt=&Apache::lonlocal::texthash(
                    321: 		'fin'=> 'Finalize order of resources',
1.42      www       322: 		'ci' => 'Continue Import',
                    323: 		'cs' => 'Continue Search',
1.23      www       324: 		'fi' => 'Finish Import',
1.51      albertel  325: 		're' => 'Recover Checked',
1.64      bisitz    326: 		'ip' => 'Import Checked',
1.23      www       327: 		'ca' => 'Cancel',
                    328: 		'co' => 'Change Order',
                    329: 		'ti' => 'Title',
1.37      www       330: 		'pa' => 'Path',
                    331:                 'in' => 'Include'
1.23      www       332: 		);
1.64      bisitz    333: 
1.56      albertel  334: 	$r->print(&Apache::loncommon::start_page($title, $js));
1.66    ! bisitz    335: 	$r->print('<h1>'.&mt($title).'</h1>');
1.56      albertel  336: 
1.22      albertel  337: 	$r->print(<<END);
1.14      matthew   338: <form method='post' action='/adm/groupsort' name='groupsort'
                    339:       enctype='application/x-www-form-urlencoded'>
1.1       harris41  340: <input type="hidden" name="fnum" value="$clen" />
                    341: <input type="hidden" name="oldval" value="" />
                    342: <input type="hidden" name="newval" value="" />
1.31      albertel  343: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1.36      www       344: <input type="hidden" name="readfile" value="$env{'form.readfile'}" />
1.44      www       345: <input type="hidden" name="bookmarks" value="$env{'form.bookmarks'}" />
1.36      www       346: <input type="hidden" name="recover" value="$env{'form.recover'}" />
1.3       harris41  347: END
1.11      www       348: 
1.54      albertel  349:         $r->print(&Apache::loncommon::inhibit_menu_check('input'));
1.51      albertel  350:         # ---
1.65      bisitz    351: 
                    352:         my $buttontext = $lt{'re'};
                    353:         if ($env{'form.bookmarks'}) {
                    354:             $buttontext = $lt{'ip'}
                    355:         }
                    356:         if ($env{'form.recover'} || $env{'form.bookmarks'}) {
1.51      albertel  357: 	    $r->print(<<END);
1.65      bisitz    358: <input type="button" name="alter" value="$buttontext"
1.51      albertel  359:  onClick="finish_import()" />&nbsp;
                    360: <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />
                    361: END
                    362: 	} else {
1.42      www       363:         # --- Continue Buttons
1.51      albertel  364: 	    my $resurl = 
                    365: 		&Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
                    366: 	    $r->print(<<END);
1.62      bisitz    367: <h2>$lt{'fin'}</h2>
                    368: <div>
1.42      www       369: <input type="button" name="alter" value="$lt{'ci'}"
1.54      albertel  370:  onClick="window.location='$resurl?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;
1.42      www       371: <input type="button" name="altersearch" value="$lt{'cs'}"
1.54      albertel  372:  onClick="window.location='/adm/searchcat?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;
1.23      www       373: <input type="button" name="alter" value="$lt{'fi'}"
1.2       harris41  374:  onClick="finish_import()" />&nbsp;
1.23      www       375: <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />
1.62      bisitz    376: </div>
                    377: <br />
1.1       harris41  378: END
1.51      albertel  379:         }
1.65      bisitz    380: 
                    381:         # Only display header if content exists
                    382:         if ($clen > 0) {
                    383:             $r->print(&Apache::loncommon::start_data_table()
                    384:                      .&Apache::loncommon::start_data_table_header_row());
                    385:             if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) { 
                    386:                 $r->print("<th>$lt{'in'}</th>\n");
                    387:             } else { 
                    388:                 $r->print('<th colspan="2">'.$lt{'co'}.'</th>'."\n"); 
                    389:             }
                    390:             $r->print('<th colspan="2">'.$lt{'ti'}.'</th>'."\n");
                    391:             $r->print("<th>$lt{'pa'}</th>");
                    392:             $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
                    393:         } else {
1.66    ! bisitz    394:             my $errtxt = '';
        !           395:             if ($env{'form.recover'}) {
        !           396:                 $errtxt = 'There are no resources to recover.';
        !           397:             } else {
        !           398:                 $errtxt = 'There are no resources to import.';
        !           399:             }
1.65      bisitz    400:             if ($env{'form.bookmarks'}) {
1.66    ! bisitz    401:                 $errtxt = 'There are no resources in your bookmarks to import.';
1.65      bisitz    402:             }
1.66    ! bisitz    403:             $r->print('<p class="LC_info">'.&mt($errtxt).'</p>');
1.65      bisitz    404:         }
1.22      albertel  405:     } else {
1.40      albertel  406: 	$r->print(&Apache::loncommon::start_page(undef,$js,
1.41      banghart  407: 						 {'only_body' => 1}));
1.66    ! bisitz    408: #       $r->print('<h1>'.&mt($title).'</h1>');
1.22      albertel  409: 	$r->print(<<END);
                    410: <form method='post' action='/adm/groupsort' name='groupsort'
                    411:       enctype='application/x-www-form-urlencoded'>
                    412: <input type="hidden" name="fnum" value="$clen" />
                    413: <input type="hidden" name="oldval" value="" />
                    414: <input type="hidden" name="newval" value="" />
1.31      albertel  415: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1.22      albertel  416: END
1.54      albertel  417:         $r->print(&Apache::loncommon::inhibit_menu_check('input'));
                    418: 
1.22      albertel  419:     }
1.57      albertel  420:     foreach my $resource (@resources) {
1.1       harris41  421: 	$ctr++;
1.57      albertel  422: 	my $iconname=&Apache::loncommon::icon($resource->{'url'});
1.44      www       423: 	if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.62      bisitz    424: 	    $r->print(&Apache::loncommon::start_data_table_row()
                    425:                      ."<td>");
1.44      www       426:             if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.37      www       427: 		$r->print(&checkbox($ctr-1));
                    428: 	    } else {
                    429: 		$r->print(&movers($clen,$ctr));
                    430: 	    }
1.22      albertel  431: 	}
1.58      albertel  432: 	$r->print(&hidden($ctr-1,$resource->{'title'},$resource->{'url'},
                    433: 			  $resource->{'id'}));
1.44      www       434: 	if (($clen > 1)  || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.37      www       435: 	    $r->print("</td>");
1.44      www       436:             unless (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.62      bisitz    437: 		$r->print("<td>".
1.37      www       438: 			  &select_box($clen,$ctr).
                    439: 			  "</td>");
                    440: 	    }
1.62      bisitz    441: 	    $r->print("<td>");
1.26      albertel  442: 	    $r->print("<img src='$iconname' />");
1.62      bisitz    443: 	    $r->print("</td><td>");
                    444: 	    $r->print($resource->{'title'}.$resource->{'notes'}."</td><td>\n");
                    445: 	    $r->print($resource->{'url'}."</td>"
                    446:                      .&Apache::loncommon::end_data_table_row()
                    447:                      ."\n");
1.22      albertel  448: 	} 
                    449:     }
1.44      www       450:     if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {
1.65      bisitz    451:         if ($clen > 0) {
                    452:             $r->print(&Apache::loncommon::end_data_table());
                    453:         }
                    454:         $r->print('</form>');
1.22      albertel  455:     } else {
                    456: 	$r->print(<<END);
                    457: <script type="text/javascript">
                    458:     finish_import();
                    459: </script>
                    460: END
                    461:     }
1.40      albertel  462: 
                    463:     $r->print(&Apache::loncommon::end_page());
1.22      albertel  464: 
1.1       harris41  465:     return OK;
                    466: }
                    467: 
1.2       harris41  468: # --------------------------------------- Hidden values (returns scalar string)
1.1       harris41  469: sub hidden {
1.58      albertel  470:     my ($sel,$title,$filelink,$id) = @_;
1.61      albertel  471:     my $string = '<input type="hidden" name="title'.$sel.'" value="'.
                    472: 	&escape($title).'" />';
1.48      albertel  473:     $filelink=~s|^/ext/|http://|;
1.2       harris41  474:     $string .= '<input type="hidden" name="filelink'.$sel.'" value="'.
1.61      albertel  475: 	&escape($filelink).'" />';
                    476:     $string .= '<input type="hidden" name="id'.$sel.'" value="'.&escape($id).'" />';
1.1       harris41  477:     return $string;
                    478: }
                    479: 
1.2       harris41  480: # --------------------------------------- Moving arrows (returns scalar string)
1.1       harris41  481: sub movers {
1.2       harris41  482:     my ($total,$sel) = @_;
                    483:     my $dsel = $sel-1;
                    484:     my $usel = $sel+1;
                    485:     $usel = 1 if $usel > $total;
                    486:     $dsel = $total if $dsel < 1;
1.1       harris41  487:     my $string;
1.2       harris41  488:     $string = (<<END);
1.1       harris41  489: <table border='0' cellspacing='0' cellpadding='0'>
1.2       harris41  490: <tr><td><a href='javascript:move($sel,$dsel)'>
                    491: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
                    492: <tr><td><a href='javascript:move($sel,$usel)'>
                    493: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
1.1       harris41  494: </table>
                    495: END
                    496:     return $string;
                    497: }
1.2       harris41  498: 
                    499: # ------------------------------------------ Select box (returns scalar string)
1.1       harris41  500: sub select_box {
1.2       harris41  501:     my ($total,$sel) = @_;
1.1       harris41  502:     my $string;
1.2       harris41  503:     $string = '<select name="alt'.$sel.'"';
                    504:     $string .= " onChange='selectchange($sel)'>";
1.36      www       505:     $string .= "<option name='o0' value='0'>".&mt('discard')."</option>";
1.1       harris41  506:     for my $cur (1..$total) {
1.2       harris41  507: 	$string .= "<option name='o$cur' value='$cur'";
                    508: 	if ($cur == $sel) {
                    509: 	    $string .= "selected";
1.1       harris41  510: 	}
1.2       harris41  511: 	$string .= ">$cur</option>";
1.1       harris41  512:     }
1.2       harris41  513:     $string .= "</select>\n";
1.1       harris41  514:     return $string;
                    515: }
                    516: 
1.37      www       517: # ------------------------------------------------------------------- Checkbox
                    518: 
                    519: sub checkbox {
                    520:     my $sel=shift;
                    521:     return "<label><input type='checkbox' name='include$sel'".
                    522:        ($env{"form.include$sel"}?' checked="checked"':'').
                    523:        ' />'.&mt('Include').'</label>';
                    524: }
                    525: 
1.1       harris41  526: 1;
                    527: 
                    528: __END__
1.63      jms       529: 
                    530: =pod
                    531: 
                    532: =head1 NAME
                    533: 
                    534: Apache::groupsort.pm
                    535: 
                    536: =head1 SYNOPSIS
                    537: 
                    538: Implements a second phase of importing
                    539: multiple resources into the RAT. Allows for
                    540: reordering the sequence of resources
                    541: 
                    542: This is part of the LearningOnline Network with CAPA project
                    543: described at http://www.lon-capa.org.
                    544: 
                    545: 
                    546: =head1 NOTABLE SUBROUTINES
                    547: 
                    548: =over
                    549: 
                    550: =item 
                    551: 
                    552: =back
                    553: 
                    554: =cut
                    555: 

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