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

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.68.6.4! raeburn     5: # $Id: groupsort.pm,v 1.68.6.3 2012/08/01 12:52:41 raeburn 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.68.6.3  raeburn    40: use LONCAPA qw(:DEFAULT :match);
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.68      foxr       89:     my $diropendb = LONCAPA::tempdir() .
                     90:        "$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);
1.68.6.4! raeburn   155:         my ($token,$donechk,%allmaps);
1.34      www       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; }
1.68.6.4! raeburn   161:                         if ($token->[2]->{'src'} =~ /\.(page|sequence)$/) {
        !           162:                             unless ($donechk) {
        !           163:                                 $donechk = &get_allmaps(\%allmaps);
        !           164:                             }
        !           165:                             if ($allmaps{$token->[2]->{'src'}}) { next; }
        !           166:                         }
1.34      www       167: 		    } else {
                    168: 			if ($token->[2]->{'type'} eq 'zombie') { next; }
                    169: 		    }
1.35      www       170: 
1.34      www       171:                     my $name=$token->[2]->{'title'};
1.50      albertel  172: 		    $name=~s/ \[\((\d+)\,($LONCAPA::username_re)\,($LONCAPA::domain_re)\)\]$//;
1.57      albertel  173: 		    my $note;
1.34      www       174: 		    if ($1) {
1.57      albertel  175: 			$note = '<br />'.&mt('Removed by ').
1.34      www       176: 			    &Apache::loncommon::plainname($2,$3).', '.
                    177: 			    &Apache::lonlocal::locallocaltime($1);
                    178: 		    }
1.37      www       179: 		    $name=~s/\&colon\;/\:/g;
1.58      albertel  180: 		    push(@{$resources}, {'url'   => $token->[2]->{'src'},
1.57      albertel  181: 					 'title' => $name,
1.58      albertel  182: 					 'note'  => $note,
                    183: 				         'id'    => $token->[2]->{'id'},});
1.34      www       184: 		}
                    185: 	    }
                    186: 	}
                    187:     }
                    188: }
                    189: 
1.68.6.4! raeburn   190: sub get_allmaps {
        !           191:     my ($allmaps) = @_;
        !           192:     return unless (ref($allmaps) eq 'HASH');
        !           193:     if (($env{'form.recover'}) &&
        !           194:         ($env{'request.course.id'}) &&
        !           195:         ($env{'form.readfile'} =~ m{/default(|_\d+)\.(page|sequence)$})) {
        !           196:         my $cid = $env{'request.course.id'};
        !           197:         my $cdom = $env{'course.'.$cid.'.domain'};
        !           198:         my $cnum = $env{'course.'.$cid.'.num'};
        !           199:         my $chome = $env{'course.'.$cid.'.home'};
        !           200:         my $lastchange =
        !           201:             &Apache::lonnet::get_coursechange($cdom,$cnum);
        !           202:         if ($lastchange > $env{'request.course.tied'}) {
        !           203:             my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
        !           204:             unless ($ferr) {
        !           205:                 &Apache::loncommon::update_content_constraints($cdom,$cnum,
        !           206:                                                                $chome,$cid);
        !           207:             }
        !           208:         }
        !           209:         my $navmap = Apache::lonnavmaps::navmap->new();
        !           210:         if (defined($navmap)) {
        !           211:             foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
        !           212:                 $allmaps->{$res->src()} = 1;
        !           213:             }
        !           214:         }
        !           215:     }
        !           216:     return 1;
        !           217: }
1.44      www       218: 
1.33      www       219: # ---------------------------------------------------------------- Main Handler
                    220: sub handler {
                    221:     my $r = shift;
                    222:  
                    223:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.68.6.2  raeburn   224: 			     ['acts','mode','readfile','recover']);
1.33      www       225: 
                    226:     &Apache::loncommon::content_type($r,'text/html');
                    227:     $r->send_http_header;
                    228:     return OK if $r->header_only;
                    229: 
                    230: # finish_import looks different for graphical or "simple" RAT
                    231:     my $finishimport='';
1.37      www       232:     my $begincondition='';
                    233:     my $endcondition='';
1.68.6.2  raeburn   234:     if (($env{'form.readfile'}))  {
1.37      www       235:         $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';
                    236: 	$endcondition='}';
                    237:     }
1.33      www       238:     if ($env{'form.mode'} eq 'simple' || $env{'form.mode'} eq '') {
                    239:         $finishimport=(<<ENDSMP);
                    240: function finish_import() {
                    241:     opener.document.forms.simpleedit.importdetail.value='';
                    242:     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
1.37      www       243: 	$begincondition
1.33      www       244: 	opener.document.forms.simpleedit.importdetail.value+='&'+
1.61      albertel  245:               eval("document.forms.groupsort.title"+num+".value")+'='+
                    246: 	      eval("document.forms.groupsort.filelink"+num+".value")+'='+
                    247: 	      eval("document.forms.groupsort.id"+num+".value");
1.37      www       248: 	$endcondition
1.33      www       249:     }
                    250:     opener.document.forms.simpleedit.submit();
                    251:     self.close();
                    252: }
                    253: ENDSMP
                    254:     } else {
                    255:         $finishimport=(<<ENDADV);
                    256: function finish_import() {
                    257:     var linkflag=false;
                    258:     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
1.37      www       259: 	$begincondition
1.33      www       260: 	insertRowInLastRow();
                    261: 	placeResourceInLastRow(
                    262: 	       eval("document.forms.groupsort.title"+num+".value"),
                    263:  	       eval("document.forms.groupsort.filelink"+num+".value"),
1.59      albertel  264:  	       eval("document.forms.groupsort.id"+num+".value"),
1.33      www       265: 	       linkflag
                    266: 	);
                    267:         linkflag=true;
1.37      www       268: 	$endcondition
1.33      www       269:     }
                    270:     opener.editmode=0;
                    271:     opener.notclear=0;
                    272:     opener.linkmode=0;
                    273:     opener.draw();
                    274:     self.close();
                    275: }
                    276: ENDADV
                    277:     }
                    278: 
                    279: # output start of web page
1.40      albertel  280:     my $js = <<END;
                    281: <script type="text/javascript">
1.33      www       282: function insertRowInLastRow() {
                    283:     opener.insertrow(opener.maxrow);
                    284:     opener.addobj(opener.maxrow,'e&2');
                    285: }
1.59      albertel  286: function placeResourceInLastRow (title,url,id,linkflag) {
1.33      www       287:     opener.mostrecent=opener.newresource(opener.maxrow,2,opener.escape(title),
1.59      albertel  288: 		       opener.escape(url),'false','normal',id);
1.33      www       289:     opener.save();
                    290:     if (linkflag) {
                    291: 	opener.joinres(opener.linkmode,opener.mostrecent,0);
                    292:     }
                    293:     opener.linkmode=opener.mostrecent;
                    294: }
                    295: $finishimport
                    296: function selectchange(val) {
                    297:     var newval=0+eval("document.forms.groupsort.alt"+val+".selectedIndex");
                    298:     orderchange(val,newval);
                    299: }
                    300: function move(val,newval) {
                    301:     orderchange(val,newval);
                    302: }
                    303: function orderchange(val,newval) {
                    304:     document.forms.groupsort.oldval.value=val;
                    305:     document.forms.groupsort.newval.value=newval;
                    306:     document.forms.groupsort.submit();
                    307: }
                    308: </script>
                    309: END
                    310:     # read pertinent machine configuration
                    311:     my $domain  = $r->dir_config('lonDefDomain');
                    312:     $iconpath = $r->dir_config('lonIconsURL') . "/";
                    313: 
1.57      albertel  314:     my @resources;
1.33      www       315: 
1.34      www       316:     if ($env{'form.readfile'}) {
1.57      albertel  317: 	&readfromfile($r,\@resources);
1.34      www       318:     } else {
1.57      albertel  319: 	&readfromdb($r,\@resources);
1.34      www       320:     }
1.33      www       321: 
1.2       harris41  322:     my $ctr = 0;
1.57      albertel  323:     my $clen = scalar(@resources);
1.66      bisitz    324:     my $title = '';
                    325:     if ($env{'form.recover'}) {
                    326:         $title = 'Recover Removed Resources';
                    327:     } else {
                    328:         $title = 'Sort Imported Resources';
                    329:     }
1.68.6.2  raeburn   330:     if (($clen > 1) || ($env{'form.readfile'})) {
1.23      www       331: 	my %lt=&Apache::lonlocal::texthash(
                    332: 		'fin'=> 'Finalize order of resources',
1.42      www       333: 		'ci' => 'Continue Import',
                    334: 		'cs' => 'Continue Search',
1.23      www       335: 		'fi' => 'Finish Import',
1.51      albertel  336: 		're' => 'Recover Checked',
1.64      bisitz    337: 		'ip' => 'Import Checked',
1.23      www       338: 		'ca' => 'Cancel',
                    339: 		'co' => 'Change Order',
                    340: 		'ti' => 'Title',
1.37      www       341: 		'pa' => 'Path',
                    342:                 'in' => 'Include'
1.23      www       343: 		);
1.64      bisitz    344: 
1.56      albertel  345: 	$r->print(&Apache::loncommon::start_page($title, $js));
1.66      bisitz    346: 	$r->print('<h1>'.&mt($title).'</h1>');
1.56      albertel  347: 
1.22      albertel  348: 	$r->print(<<END);
1.14      matthew   349: <form method='post' action='/adm/groupsort' name='groupsort'
                    350:       enctype='application/x-www-form-urlencoded'>
1.1       harris41  351: <input type="hidden" name="fnum" value="$clen" />
                    352: <input type="hidden" name="oldval" value="" />
                    353: <input type="hidden" name="newval" value="" />
1.31      albertel  354: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1.36      www       355: <input type="hidden" name="readfile" value="$env{'form.readfile'}" />
                    356: <input type="hidden" name="recover" value="$env{'form.recover'}" />
1.3       harris41  357: END
1.11      www       358: 
1.54      albertel  359:         $r->print(&Apache::loncommon::inhibit_menu_check('input'));
1.51      albertel  360:         # ---
1.65      bisitz    361: 
                    362:         my $buttontext = $lt{'re'};
1.68.6.2  raeburn   363:         if ($env{'form.recover'}) {
1.51      albertel  364: 	    $r->print(<<END);
1.65      bisitz    365: <input type="button" name="alter" value="$buttontext"
1.51      albertel  366:  onClick="finish_import()" />&nbsp;
                    367: <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />
                    368: END
                    369: 	} else {
1.42      www       370:         # --- Continue Buttons
1.51      albertel  371: 	    my $resurl = 
                    372: 		&Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
                    373: 	    $r->print(<<END);
1.62      bisitz    374: <h2>$lt{'fin'}</h2>
                    375: <div>
1.42      www       376: <input type="button" name="alter" value="$lt{'ci'}"
1.54      albertel  377:  onClick="window.location='$resurl?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;
1.42      www       378: <input type="button" name="altersearch" value="$lt{'cs'}"
1.54      albertel  379:  onClick="window.location='/adm/searchcat?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;
1.23      www       380: <input type="button" name="alter" value="$lt{'fi'}"
1.2       harris41  381:  onClick="finish_import()" />&nbsp;
1.23      www       382: <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />
1.62      bisitz    383: </div>
                    384: <br />
1.1       harris41  385: END
1.51      albertel  386:         }
1.65      bisitz    387: 
                    388:         # Only display header if content exists
                    389:         if ($clen > 0) {
                    390:             $r->print(&Apache::loncommon::start_data_table()
                    391:                      .&Apache::loncommon::start_data_table_header_row());
1.67      wenzelju  392:             if (($env{'form.readfile'})) { 
1.65      bisitz    393:                 $r->print("<th>$lt{'in'}</th>\n");
                    394:             } else { 
                    395:                 $r->print('<th colspan="2">'.$lt{'co'}.'</th>'."\n"); 
                    396:             }
                    397:             $r->print('<th colspan="2">'.$lt{'ti'}.'</th>'."\n");
                    398:             $r->print("<th>$lt{'pa'}</th>");
                    399:             $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
                    400:         } else {
1.66      bisitz    401:             my $errtxt = '';
                    402:             if ($env{'form.recover'}) {
                    403:                 $errtxt = 'There are no resources to recover.';
                    404:             } else {
                    405:                 $errtxt = 'There are no resources to import.';
                    406:             }
                    407:             $r->print('<p class="LC_info">'.&mt($errtxt).'</p>');
1.65      bisitz    408:         }
1.22      albertel  409:     } else {
1.40      albertel  410: 	$r->print(&Apache::loncommon::start_page(undef,$js,
1.41      banghart  411: 						 {'only_body' => 1}));
1.66      bisitz    412: #       $r->print('<h1>'.&mt($title).'</h1>');
1.22      albertel  413: 	$r->print(<<END);
                    414: <form method='post' action='/adm/groupsort' name='groupsort'
                    415:       enctype='application/x-www-form-urlencoded'>
                    416: <input type="hidden" name="fnum" value="$clen" />
                    417: <input type="hidden" name="oldval" value="" />
                    418: <input type="hidden" name="newval" value="" />
1.31      albertel  419: <input type="hidden" name="mode" value="$env{'form.mode'}" />
1.22      albertel  420: END
1.54      albertel  421:         $r->print(&Apache::loncommon::inhibit_menu_check('input'));
                    422: 
1.22      albertel  423:     }
1.57      albertel  424:     foreach my $resource (@resources) {
1.1       harris41  425: 	$ctr++;
1.57      albertel  426: 	my $iconname=&Apache::loncommon::icon($resource->{'url'});
1.68.6.2  raeburn   427: 	if (($clen > 1) || ($env{'form.readfile'})) {
1.62      bisitz    428: 	    $r->print(&Apache::loncommon::start_data_table_row()
                    429:                      ."<td>");
1.68.6.2  raeburn   430:             if (($env{'form.readfile'})) {
1.37      www       431: 		$r->print(&checkbox($ctr-1));
                    432: 	    } else {
                    433: 		$r->print(&movers($clen,$ctr));
                    434: 	    }
1.22      albertel  435: 	}
1.58      albertel  436: 	$r->print(&hidden($ctr-1,$resource->{'title'},$resource->{'url'},
                    437: 			  $resource->{'id'}));
1.68.6.2  raeburn   438: 	if (($clen > 1)  || ($env{'form.readfile'})) {
1.37      www       439: 	    $r->print("</td>");
1.68.6.2  raeburn   440:             unless (($env{'form.readfile'})) {
1.62      bisitz    441: 		$r->print("<td>".
1.37      www       442: 			  &select_box($clen,$ctr).
                    443: 			  "</td>");
                    444: 	    }
1.62      bisitz    445: 	    $r->print("<td>");
1.26      albertel  446: 	    $r->print("<img src='$iconname' />");
1.62      bisitz    447: 	    $r->print("</td><td>");
1.68.6.3  raeburn   448:             if (($env{'form.recover'}) &&
                    449:                 ($resource->{'url'} =~ m{/uploaded/$match_domain/$match_courseid/supplemental/})) {
                    450:                 my $title = &Apache::loncommon::parse_supplemental_title($resource->{'title'});
                    451:                 $r->print($title);
                    452:             } else {
                    453:                 $r->print($resource->{'title'});
                    454:             }
                    455: 	    $r->print($resource->{'notes'}."</td><td>\n");
1.62      bisitz    456: 	    $r->print($resource->{'url'}."</td>"
                    457:                      .&Apache::loncommon::end_data_table_row()
                    458:                      ."\n");
1.22      albertel  459: 	} 
                    460:     }
1.68.6.2  raeburn   461:     if (($clen > 1) || ($env{'form.readfile'})) {
1.65      bisitz    462:         if ($clen > 0) {
                    463:             $r->print(&Apache::loncommon::end_data_table());
                    464:         }
                    465:         $r->print('</form>');
1.22      albertel  466:     } else {
                    467: 	$r->print(<<END);
                    468: <script type="text/javascript">
                    469:     finish_import();
                    470: </script>
                    471: END
                    472:     }
1.40      albertel  473: 
                    474:     $r->print(&Apache::loncommon::end_page());
1.22      albertel  475: 
1.1       harris41  476:     return OK;
                    477: }
                    478: 
1.2       harris41  479: # --------------------------------------- Hidden values (returns scalar string)
1.1       harris41  480: sub hidden {
1.58      albertel  481:     my ($sel,$title,$filelink,$id) = @_;
1.61      albertel  482:     my $string = '<input type="hidden" name="title'.$sel.'" value="'.
                    483: 	&escape($title).'" />';
1.48      albertel  484:     $filelink=~s|^/ext/|http://|;
1.2       harris41  485:     $string .= '<input type="hidden" name="filelink'.$sel.'" value="'.
1.61      albertel  486: 	&escape($filelink).'" />';
                    487:     $string .= '<input type="hidden" name="id'.$sel.'" value="'.&escape($id).'" />';
1.1       harris41  488:     return $string;
                    489: }
                    490: 
1.2       harris41  491: # --------------------------------------- Moving arrows (returns scalar string)
1.1       harris41  492: sub movers {
1.2       harris41  493:     my ($total,$sel) = @_;
                    494:     my $dsel = $sel-1;
                    495:     my $usel = $sel+1;
                    496:     $usel = 1 if $usel > $total;
                    497:     $dsel = $total if $dsel < 1;
1.1       harris41  498:     my $string;
1.2       harris41  499:     $string = (<<END);
1.1       harris41  500: <table border='0' cellspacing='0' cellpadding='0'>
1.2       harris41  501: <tr><td><a href='javascript:move($sel,$dsel)'>
                    502: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
                    503: <tr><td><a href='javascript:move($sel,$usel)'>
                    504: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
1.1       harris41  505: </table>
                    506: END
                    507:     return $string;
                    508: }
1.2       harris41  509: 
                    510: # ------------------------------------------ Select box (returns scalar string)
1.1       harris41  511: sub select_box {
1.2       harris41  512:     my ($total,$sel) = @_;
1.1       harris41  513:     my $string;
1.2       harris41  514:     $string = '<select name="alt'.$sel.'"';
                    515:     $string .= " onChange='selectchange($sel)'>";
1.36      www       516:     $string .= "<option name='o0' value='0'>".&mt('discard')."</option>";
1.1       harris41  517:     for my $cur (1..$total) {
1.2       harris41  518: 	$string .= "<option name='o$cur' value='$cur'";
                    519: 	if ($cur == $sel) {
                    520: 	    $string .= "selected";
1.1       harris41  521: 	}
1.2       harris41  522: 	$string .= ">$cur</option>";
1.1       harris41  523:     }
1.2       harris41  524:     $string .= "</select>\n";
1.1       harris41  525:     return $string;
                    526: }
                    527: 
1.37      www       528: # ------------------------------------------------------------------- Checkbox
                    529: 
                    530: sub checkbox {
                    531:     my $sel=shift;
                    532:     return "<label><input type='checkbox' name='include$sel'".
                    533:        ($env{"form.include$sel"}?' checked="checked"':'').
                    534:        ' />'.&mt('Include').'</label>';
                    535: }
                    536: 
1.1       harris41  537: 1;
                    538: 
                    539: __END__
1.63      jms       540: 
                    541: =pod
                    542: 
                    543: =head1 NAME
                    544: 
                    545: Apache::groupsort.pm
                    546: 
                    547: =head1 SYNOPSIS
                    548: 
                    549: Implements a second phase of importing
                    550: multiple resources into the RAT. Allows for
                    551: reordering the sequence of resources
                    552: 
                    553: This is part of the LearningOnline Network with CAPA project
                    554: described at http://www.lon-capa.org.
                    555: 
                    556: 
                    557: =head1 NOTABLE SUBROUTINES
                    558: 
                    559: =over
                    560: 
                    561: =item 
                    562: 
                    563: =back
                    564: 
                    565: =cut
                    566: 

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