Annotation of loncom/interface/groupsort.pm, revision 1.6
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.6 ! harris41 5: # $Id: groupsort.pm,v 1.5 2001/12/11 03:37:11 harris41 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: #
29: # YEAR=2001
1.4 harris41 30: # 8/7,8/8,10/14,10/15,12/10 Scott Harrison
1.6 ! harris41 31: # YEAR=2002
! 32: # 1/17 Scott Harrison
1.4 harris41 33: #
34: ###
1.1 harris41 35:
36: package Apache::groupsort;
37:
38: use strict;
39:
40: use Apache::Constants qw(:common);
41: use GDBM_File;
42:
1.2 harris41 43: my %hash; # variable to tie to user specific database
44: my $iconpath; # variable to be accessible to multiple subroutines
45:
46: # ---------------------------------------------------------------- Main Handler
1.1 harris41 47: sub handler {
48: my $r = shift;
1.2 harris41 49:
50: # color scheme
51: my $fileclr = '#ffffe6';
52: my $titleclr = '#ddffff';
53:
1.1 harris41 54: $r->content_type('text/html');
55: $r->send_http_header;
56: return OK if $r->header_only;
1.2 harris41 57:
58: # output start of web page
1.1 harris41 59: $r->print(<<END);
60: <html>
61: <head>
62: <title>The LearningOnline Network With CAPA Group Sorter</title>
63: <script language='javascript'>
64: function insertRowInLastRow() {
65: opener.insertrow(opener.maxrow);
66: opener.addobj(opener.maxrow,'e&2');
67: }
68: function placeResourceInLastRow (title,url,linkflag) {
1.2 harris41 69: opener.newresource(opener.maxrow,2,opener.escape(title),
70: opener.escape(url),'false','normal');
1.1 harris41 71: opener.save();
72: opener.mostrecent=opener.obj.length-1;
73: if (linkflag) {
74: opener.joinres(opener.linkmode,opener.mostrecent,0);
75: }
76: opener.linkmode=opener.mostrecent;
77: }
78: function finish_import() {
79: var linkflag=false;
80: for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
1.2 harris41 81: insertRowInLastRow();
82: placeResourceInLastRow(
83: eval("document.forms.groupsort.title"+num+".value"),
84: eval("document.forms.groupsort.filelink"+num+".value"),
85: linkflag
86: );
87: linkflag=true;
1.1 harris41 88: }
89: opener.editmode=0;
90: opener.notclear=0;
91: opener.linkmode=0;
92: opener.infoclear();
93: opener.draw();
1.2 harris41 94: self.close();
1.1 harris41 95: }
96: function selectchange(val) {
1.3 harris41 97: var newval=0+eval("document.forms.groupsort.alt"+val+".selectedIndex");
1.1 harris41 98: orderchange(val,newval);
99: }
100: function move(val,newval) {
101: orderchange(val,newval);
102: }
103: function orderchange(val,newval) {
104: document.forms.groupsort.oldval.value=val;
105: document.forms.groupsort.newval.value=newval;
106: document.forms.groupsort.submit();
107: }
108: </script>
109: </head>
110: <body bgcolor="#FFFFFF">
111: END
1.2 harris41 112:
113: # read pertinent machine configuration
1.1 harris41 114: my $domain = $r->dir_config('lonDefDomain');
1.2 harris41 115: $iconpath = $r->dir_config('lonIconsURL') . "/";
116:
117: my %shash; # sort order (key is resource location, value is sort order)
118: my %thash; # title (key is resource location, value is title)
1.5 harris41 119: foreach (split(/&/,$ENV{'QUERY_STRING'})) {
1.1 harris41 120: my ($name, $value) = split(/=/,$_);
121: $value =~ tr/+/ /;
122: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
123: if ($name eq 'acts') {
124: $ENV{'form.'.$name}=$value;
125: }
1.3 harris41 126: if ($name eq 'catalogmode') {
127: $ENV{'form.'.$name}=$value;
128: }
1.5 harris41 129: }
1.4 harris41 130: my $diropendb;
131: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
132: $diropendb =
133: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
134: }
135: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
136: $diropendb =
137: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
1.6 ! harris41 138: }
! 139: else { # choose last accessed
! 140: my $dsearch; my $dindex;
! 141: my $dsearcht; my $dindext;
! 142: $dsearch =
! 143: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
! 144: if (-e $dsearch) {
! 145: $dsearcht=(stat($dsearch))[9];
! 146: }
! 147: $dindex =
! 148: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
! 149: if (-e $dindex) {
! 150: $dindext=(stat($dindex))[9];
! 151: }
! 152: if (!$dsearcht and !$dindext) {
! 153: $diropendb='';
! 154: }
! 155: elsif ($dsearcht>$dindext) {
! 156: $diropendb=$dsearch;
! 157: }
! 158: else {
! 159: $diropendb=$dindex;
! 160: }
1.4 harris41 161: }
1.1 harris41 162: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1.2 harris41 163: my $acts = $ENV{'form.acts'};
164: my @Acts = split(/b/,$acts);
1.1 harris41 165: my %ahash;
166: my %achash;
1.2 harris41 167: my $ac = 0;
1.5 harris41 168: foreach (@Acts) {
1.2 harris41 169: my ($state,$ref) = split(/a/);
170: $ahash{$ref} = $state;
171: $achash{$ref} = $ac;
1.1 harris41 172: $ac++;
1.5 harris41 173: }
174: foreach (sort {$achash{$a} <=> $achash{$b}} (keys %ahash)) {
1.2 harris41 175: my $key = $_;
1.1 harris41 176: if ($ahash{$key} eq '1') {
1.3 harris41 177: # my $keyz=join("<br />",keys %hash);
178: # print "<br />$key<br />$keyz".$hash{'pre_'.$key.'_link'}."<br />\n";
1.2 harris41 179: $hash{'store_'.$hash{'pre_'.$key.'_link'}} =
1.1 harris41 180: $hash{'pre_'.$key.'_title'};
1.2 harris41 181: $hash{'storectr_'.$hash{'pre_'.$key.'_link'}} =
1.1 harris41 182: $hash{'storectr'}+0;
183: $hash{'storectr'}++;
184: }
185: if ($ahash{$key} eq '0') {
186: if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
187: delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
188: }
189: }
1.5 harris41 190: }
191: foreach (keys %hash) {
1.1 harris41 192: if ($_ =~ /^store_/) {
1.2 harris41 193: my $key = $_;
194: $key =~ s/^store_//;
195: $shash{$key} = $hash{'storectr_'.$key};
196: $thash{$key} = $hash{'store_'.$key};
1.1 harris41 197: }
1.5 harris41 198: }
1.1 harris41 199: if ($ENV{'form.oldval'}) {
1.2 harris41 200: my $newctr = 0;
1.1 harris41 201: my %chash;
1.5 harris41 202: foreach (sort {$shash{$a} <=> $shash{$b}} (keys %shash)) {
1.2 harris41 203: my $key = $_;
1.1 harris41 204: $newctr++;
1.2 harris41 205: $shash{$key} = $newctr;
206: $hash{'storectr_'.$key} = $newctr;
207: $chash{$newctr} = $key;
1.5 harris41 208: }
1.2 harris41 209: my $oldval = $ENV{'form.oldval'};
210: my $newval = $ENV{'form.newval'};
211: if ($oldval != $newval) {
1.3 harris41 212: # when newval==0, then push down and delete
213: if ($newval!=0) {
214: $shash{$chash{$oldval}} = $newval;
215: $hash{'storectr_'.$chash{$oldval}} = $newval;
216: }
217: else {
218: $shash{$chash{$oldval}} = $newctr;
219: $hash{'storectr_'.$chash{$oldval}} = $newctr;
220: }
221: if ($newval==0) { # push down
222: my $newval2=$newctr;
223: for my $idx ($oldval..($newval2-1)) {
224: $shash{$chash{$idx+1}} = $idx;
225: $hash{'storectr_'.$chash{$idx+1}} = $idx;
226: }
227: delete $shash{$chash{$oldval}};
228: delete $hash{'storectr_'.$chash{$oldval}};
229: delete $hash{'store_'.$chash{$oldval}};
230: }
231: elsif ($oldval < $newval) { # push down
1.1 harris41 232: for my $idx ($oldval..($newval-1)) {
1.2 harris41 233: $shash{$chash{$idx+1}} = $idx;
234: $hash{'storectr_'.$chash{$idx+1}} = $idx;
1.1 harris41 235: }
236: }
1.2 harris41 237: elsif ($oldval > $newval) { # push up
1.1 harris41 238: for my $idx (reverse($newval..($oldval-1))) {
1.2 harris41 239: $shash{$chash{$idx}} = $idx+1;
240: $hash{'storectr_'.$chash{$idx}} = $idx+1;
1.1 harris41 241: }
242: }
243: }
244: }
245: } else {
1.2 harris41 246: $r->print('Unable to tie hash to db file</body></html>');
1.1 harris41 247: return OK;
248: }
249: untie %hash;
1.2 harris41 250: my $ctr = 0;
251: my $clen = scalar(keys %shash);
252: $r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
253: 'Group Sorter</font></h2>'."\n");
254: $r->print('<b><font color="#888888">Finalize order of resources</font>'.
255: '</b>'."\n");
256: $r->print("<form method='post' action='/adm/groupsort' name='groupsort' ".
257: "enctype='application/x-www-form-urlencoded'>");
1.1 harris41 258: $r->print(<<END);
259: <input type="hidden" name="fnum" value="$clen" />
260: <input type="hidden" name="oldval" value="" />
261: <input type="hidden" name="newval" value="" />
1.3 harris41 262: END
263: if ($ENV{'form.catalogmode'} eq 'groupimport') {
264: $r->print(<<END);
1.2 harris41 265: <input type="button" name="alter" value="GO BACK"
266: onClick="window.location='/res/?catalogmode=groupimport'" />
1.3 harris41 267: END
268: }
269: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
270: $r->print(<<END);
271: <input type="button" name="alter" value="GO BACK"
272: onClick="window.location='/adm/searchcat?catalogmode=groupsearch'" />
273: END
274: }
275: $r->print(<<END);
1.2 harris41 276: <input type="button" name="alter" value="FINISH IMPORT"
277: onClick="finish_import()" />
1.1 harris41 278: <input type="button" name="alter" value="CANCEL" onClick="self.close()" />
279: END
280: $r->print("<table border='0'><tr><td bgcolor='#eeeeee'>");
281: $r->print("<table border=0><tr>\n");
1.2 harris41 282: $r->print("<td colspan='2' bgcolor='$titleclr'><b>Change order</b></td>".
283: "\n");
1.1 harris41 284: $r->print("<td colspan='2' bgcolor='$titleclr'><b>Title</b></td>\n");
285: $r->print("<td bgcolor='$titleclr'><b>Path</b></td></tr>\n");
1.5 harris41 286: foreach (sort {$shash{$a}<=>$shash{$b}} (keys %shash)) {
1.1 harris41 287: my $key=$_;
288: $ctr++;
289: my @file_ext = split(/\./,$key);
290: my $curfext = $file_ext[scalar(@file_ext)-1];
291: $r->print("<tr><td bgcolor='$fileclr'>");
292: $r->print(&movers($clen,$ctr));
293: $r->print(&hidden($ctr-1,$thash{$key},$key));
294: $r->print("</td><td bgcolor='$fileclr'>");
295: $r->print(&select_box($clen,$ctr));
296: $r->print("</td><td bgcolor='$fileclr'>");
297: $r->print("<img src='$iconpath$curfext.gif'>");
298: $r->print("</td><td bgcolor='$fileclr'>");
299: $r->print("$thash{$key}</td><td bgcolor='$fileclr'>\n");
300: $r->print("$key</td></tr>\n");
1.5 harris41 301: }
1.1 harris41 302: $r->print("</table></td></tr></table></form>");
303: $r->print(<<END);
304: </body>
305: </html>
306: END
307: return OK;
308: }
309:
1.2 harris41 310: # --------------------------------------- Hidden values (returns scalar string)
1.1 harris41 311: sub hidden {
1.2 harris41 312: my ($sel,$title,$filelink) = @_;
313: my $string = '<input type="hidden" name="title'.$sel.'" value="'.$title.
314: '" />';
315: $string .= '<input type="hidden" name="filelink'.$sel.'" value="'.
316: $filelink.'" />';
1.1 harris41 317: return $string;
318: }
319:
1.2 harris41 320: # --------------------------------------- Moving arrows (returns scalar string)
1.1 harris41 321: sub movers {
1.2 harris41 322: my ($total,$sel) = @_;
323: my $dsel = $sel-1;
324: my $usel = $sel+1;
325: $usel = 1 if $usel > $total;
326: $dsel = $total if $dsel < 1;
1.1 harris41 327: my $string;
1.2 harris41 328: $string = (<<END);
1.1 harris41 329: <table border='0' cellspacing='0' cellpadding='0'>
1.2 harris41 330: <tr><td><a href='javascript:move($sel,$dsel)'>
331: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
332: <tr><td><a href='javascript:move($sel,$usel)'>
333: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
1.1 harris41 334: </table>
335: END
336: return $string;
337: }
1.2 harris41 338:
339: # ------------------------------------------ Select box (returns scalar string)
1.1 harris41 340: sub select_box {
1.2 harris41 341: my ($total,$sel) = @_;
1.1 harris41 342: my $string;
1.2 harris41 343: $string = '<select name="alt'.$sel.'"';
344: $string .= " onChange='selectchange($sel)'>";
1.3 harris41 345: $string .= "<option name='o0' value='0'>remove</option>";
1.1 harris41 346: for my $cur (1..$total) {
1.2 harris41 347: $string .= "<option name='o$cur' value='$cur'";
348: if ($cur == $sel) {
349: $string .= "selected";
1.1 harris41 350: }
1.2 harris41 351: $string .= ">$cur</option>";
1.1 harris41 352: }
1.2 harris41 353: $string .= "</select>\n";
1.1 harris41 354: return $string;
355: }
356:
357: 1;
358:
359: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>