File:
[LON-CAPA] /
loncom /
interface /
groupsort.pm
Revision
1.16:
download - view:
text,
annotated -
select for diffs
Mon Sep 16 20:57:28 2002 UTC (22 years ago) by
matthew
Branches:
MAIN
CVS tags:
HEAD
Fixes for bug 775.
lonsearchcat.pm was modified to take a new parameter, cleargroupsort, which
causes it to clear the GDBM file used by the groupsort.pm handler.
&catalogmode_output was modified to take two new parameters which identify
uniquely the radiobutton it produces and the resource the radiobutton
refers to.
The javascript function queue was modified to take two parameters which
correspond to the two new ones passed to &catalogmode_output.
groupsort.pm was modified to pass 'cleargroupsort' to lonspreadsheet.pm
when the 'new search' button is hit.
1: # The LearningOnline Network with CAPA
2: # The LON-CAPA group sort handler
3: # Allows for sorting prior to import into RAT.
4: #
5: # $Id: groupsort.pm,v 1.16 2002/09/16 20:57:28 matthew Exp $
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.
20: #
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
26: #
27: # http://www.lon-capa.org/
28: #
29: # YEAR=2001
30: # 8/7,8/8,10/14,10/15,12/10 Scott Harrison
31: # YEAR=2002
32: # 1/17 Scott Harrison
33: #
34: ###
35:
36: package Apache::groupsort;
37:
38: use strict;
39:
40: use Apache::Constants qw(:common);
41: use GDBM_File;
42: use Apache::loncommon;
43:
44: my %hash; # variable to tie to user specific database
45: my $iconpath; # variable to be accessible to multiple subroutines
46:
47: # ---------------------------------------------------------------- Main Handler
48: sub handler {
49: my $r = shift;
50:
51: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
52: ['acts','catalogmode','mode']);
53: # color scheme
54: my $fileclr = '#ffffe6';
55: my $titleclr = '#ddffff';
56:
57: $r->content_type('text/html');
58: $r->send_http_header;
59: return OK if $r->header_only;
60:
61: # finish_import looks different for graphical or "simple" RAT
62: my $finishimport='';
63: if ($ENV{'form.mode'} eq 'simple') {
64: $finishimport=(<<ENDSMP);
65: function finish_import() {
66: opener.document.forms.simpleedit.importdetail.value='';
67: for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
68: opener.document.forms.simpleedit.importdetail.value+='&'+
69: escape(eval("document.forms.groupsort.title"+num+".value"))+'='+
70: escape(eval("document.forms.groupsort.filelink"+num+".value"));
71: }
72: opener.document.forms.simpleedit.submit();
73: self.close();
74: }
75: ENDSMP
76: } else {
77: $finishimport=(<<ENDADV);
78: function finish_import() {
79: var linkflag=false;
80: for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
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;
88: }
89: opener.editmode=0;
90: opener.notclear=0;
91: opener.linkmode=0;
92: opener.draw();
93: self.close();
94: }
95: ENDADV
96: }
97:
98: # output start of web page
99:
100: $r->print(<<END);
101: <html>
102: <head>
103: <title>The LearningOnline Network With CAPA Group Sorter</title>
104: <script language='javascript'>
105: function insertRowInLastRow() {
106: opener.insertrow(opener.maxrow);
107: opener.addobj(opener.maxrow,'e&2');
108: }
109: function placeResourceInLastRow (title,url,linkflag) {
110: opener.newresource(opener.maxrow,2,opener.escape(title),
111: opener.escape(url),'false','normal');
112: opener.save();
113: opener.mostrecent=opener.obj.length-1;
114: if (linkflag) {
115: opener.joinres(opener.linkmode,opener.mostrecent,0);
116: }
117: opener.linkmode=opener.mostrecent;
118: }
119: $finishimport
120: function selectchange(val) {
121: var newval=0+eval("document.forms.groupsort.alt"+val+".selectedIndex");
122: orderchange(val,newval);
123: }
124: function move(val,newval) {
125: orderchange(val,newval);
126: }
127: function orderchange(val,newval) {
128: document.forms.groupsort.oldval.value=val;
129: document.forms.groupsort.newval.value=newval;
130: document.forms.groupsort.submit();
131: }
132: </script>
133: </head>
134: END
135: $r->print(&Apache::loncommon::bodytag('Sort Imported Resources'));
136: # read pertinent machine configuration
137: my $domain = $r->dir_config('lonDefDomain');
138: $iconpath = $r->dir_config('lonIconsURL') . "/";
139:
140: my %shash; # sort order (key is resource location, value is sort order)
141: my %thash; # title (key is resource location, value is title)
142:
143: my $diropendb;
144: # ------------------------------ which file do we open? Easy if explictly given
145: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
146: $diropendb =
147: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
148: }
149: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
150: $diropendb =
151: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
152: }
153: elsif ($ENV{'form.catalogmode'} eq 'groupsec') {
154: $diropendb =
155: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_groupsec.db";
156: }
157: # --------------------- not explicitly given, choose the one most recently used
158: else { # choose last accessed
159: my @dbfn;
160: my @dbst;
161:
162: $dbfn[0] =
163: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
164: $dbst[0]=-1;
165: if (-e $dbfn[0]) {
166: $dbst[0]=(stat($dbfn[0]))[9];
167: }
168: $dbfn[1] =
169: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
170: $dbst[1]=-1;
171: if (-e $dbfn[1]) {
172: $dbst[1]=(stat($dbfn[1]))[9];
173: }
174: $dbfn[2] =
175: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_groupsec.db";
176: $dbst[2]=-1;
177: if (-e $dbfn[2]) {
178: $dbst[2]=(stat($dbfn[2]))[9];
179: }
180: # Expand here for more modes
181: # ....
182:
183: # Okay, find most recent existing
184:
185: my $newest=0;
186: $diropendb='';
187: for (my $i=0; $i<=$#dbfn; $i++) {
188: if ($dbst[$i]>$newest) {
189: $newest=$dbst[$i];
190: $diropendb=$dbfn[$i];
191: }
192: }
193:
194: }
195: # ----------------------------- diropendb is now the filename of the db to open
196: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
197: my $acts = $ENV{'form.acts'};
198: my @Acts = split(/b/,$acts);
199: my %ahash;
200: my %achash;
201: my $ac = 0;
202: foreach (@Acts) {
203: my ($state,$ref) = split(/a/);
204: $ahash{$ref} = $state;
205: $achash{$ref} = $ac;
206: $ac++;
207: }
208: foreach (sort {$achash{$a} <=> $achash{$b}} (keys %ahash)) {
209: my $key = $_;
210: if ($ahash{$key} eq '1') {
211: # my $keyz=join("<br />",keys %hash);
212: # print "<br />$key<br />$keyz".$hash{'pre_'.$key.'_link'}."<br />\n";
213: $hash{'store_'.$hash{'pre_'.$key.'_link'}} =
214: $hash{'pre_'.$key.'_title'};
215: $hash{'storectr_'.$hash{'pre_'.$key.'_link'}} =
216: $hash{'storectr'}+0;
217: $hash{'storectr'}++;
218: }
219: if ($ahash{$key} eq '0') {
220: if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
221: delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
222: }
223: }
224: }
225: foreach (keys %hash) {
226: if ($_ =~ /^store_/) {
227: my $key = $_;
228: $key =~ s/^store_//;
229: $shash{$key} = $hash{'storectr_'.$key};
230: $thash{$key} = $hash{'store_'.$key};
231: }
232: }
233: if ($ENV{'form.oldval'}) {
234: my $newctr = 0;
235: my %chash;
236: foreach (sort {$shash{$a} <=> $shash{$b}} (keys %shash)) {
237: my $key = $_;
238: $newctr++;
239: $shash{$key} = $newctr;
240: $hash{'storectr_'.$key} = $newctr;
241: $chash{$newctr} = $key;
242: }
243: my $oldval = $ENV{'form.oldval'};
244: my $newval = $ENV{'form.newval'};
245: if ($oldval != $newval) {
246: # when newval==0, then push down and delete
247: if ($newval!=0) {
248: $shash{$chash{$oldval}} = $newval;
249: $hash{'storectr_'.$chash{$oldval}} = $newval;
250: }
251: else {
252: $shash{$chash{$oldval}} = $newctr;
253: $hash{'storectr_'.$chash{$oldval}} = $newctr;
254: }
255: if ($newval==0) { # push down
256: my $newval2=$newctr;
257: for my $idx ($oldval..($newval2-1)) {
258: $shash{$chash{$idx+1}} = $idx;
259: $hash{'storectr_'.$chash{$idx+1}} = $idx;
260: }
261: delete $shash{$chash{$oldval}};
262: delete $hash{'storectr_'.$chash{$oldval}};
263: delete $hash{'store_'.$chash{$oldval}};
264: }
265: elsif ($oldval < $newval) { # push down
266: for my $idx ($oldval..($newval-1)) {
267: $shash{$chash{$idx+1}} = $idx;
268: $hash{'storectr_'.$chash{$idx+1}} = $idx;
269: }
270: }
271: elsif ($oldval > $newval) { # push up
272: for my $idx (reverse($newval..($oldval-1))) {
273: $shash{$chash{$idx}} = $idx+1;
274: $hash{'storectr_'.$chash{$idx}} = $idx+1;
275: }
276: }
277: }
278: }
279: } else {
280: $r->print('Unable to tie hash to db file</body></html>');
281: return OK;
282: }
283: untie %hash;
284: my $ctr = 0;
285: my $clen = scalar(keys %shash);
286: $r->print(<<END);
287: <b><font color="#888888">Finalize order of resources</font></b>
288: <form method='post' action='/adm/groupsort' name='groupsort'
289: enctype='application/x-www-form-urlencoded'>
290: <input type="hidden" name="fnum" value="$clen" />
291: <input type="hidden" name="oldval" value="" />
292: <input type="hidden" name="newval" value="" />
293: <input type="hidden" name="mode" value="$ENV{'form.mode'}" />
294: END
295:
296: # --- Expand here if "GO BACK" button desired
297: if ($ENV{'form.catalogmode'} eq 'groupimport') {
298: $r->print(<<END);
299: <input type="button" name="alter" value="GO BACK"
300: onClick="window.location='/res/?catalogmode=groupimport'" />
301: END
302: }
303: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
304: $r->print(<<END);
305: <input type="button" name="alter" value="New Search"
306: onClick="window.location='/adm/searchcat?catalogmode=groupsearch&cleargroupsort=1'" />
307: END
308: }
309: # ---
310:
311: $r->print(<<END);
312: <input type="button" name="alter" value="FINISH IMPORT"
313: onClick="finish_import()" />
314: <input type="button" name="alter" value="CANCEL" onClick="self.close()" />
315: END
316: $r->print("<table border='0'><tr><td bgcolor='#eeeeee'>");
317: $r->print("<table border=0><tr>\n");
318: $r->print("<td colspan='2' bgcolor='$titleclr'><b>Change order</b></td>".
319: "\n");
320: $r->print("<td colspan='2' bgcolor='$titleclr'><b>Title</b></td>\n");
321: $r->print("<td bgcolor='$titleclr'><b>Path</b></td></tr>\n");
322: foreach (sort {$shash{$a}<=>$shash{$b}} (keys %shash)) {
323: my $key=$_;
324: $ctr++;
325: my @file_ext = split(/\./,$key);
326: my $curfext = $file_ext[scalar(@file_ext)-1];
327: $r->print("<tr><td bgcolor='$fileclr'>");
328: $r->print(&movers($clen,$ctr));
329: $r->print(&hidden($ctr-1,$thash{$key},$key));
330: $r->print("</td><td bgcolor='$fileclr'>");
331: $r->print(&select_box($clen,$ctr));
332: $r->print("</td><td bgcolor='$fileclr'>");
333: $r->print("<img src='$iconpath$curfext.gif'>");
334: $r->print("</td><td bgcolor='$fileclr'>");
335: $r->print("$thash{$key}</td><td bgcolor='$fileclr'>\n");
336: $r->print("$key</td></tr>\n");
337: }
338: $r->print("</table></td></tr></table></form>");
339: $r->print(<<END);
340: </body>
341: </html>
342: END
343: return OK;
344: }
345:
346: # --------------------------------------- Hidden values (returns scalar string)
347: sub hidden {
348: my ($sel,$title,$filelink) = @_;
349: my $string = '<input type="hidden" name="title'.$sel.'" value="'.$title.
350: '" />';
351: $string .= '<input type="hidden" name="filelink'.$sel.'" value="'.
352: $filelink.'" />';
353: return $string;
354: }
355:
356: # --------------------------------------- Moving arrows (returns scalar string)
357: sub movers {
358: my ($total,$sel) = @_;
359: my $dsel = $sel-1;
360: my $usel = $sel+1;
361: $usel = 1 if $usel > $total;
362: $dsel = $total if $dsel < 1;
363: my $string;
364: $string = (<<END);
365: <table border='0' cellspacing='0' cellpadding='0'>
366: <tr><td><a href='javascript:move($sel,$dsel)'>
367: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
368: <tr><td><a href='javascript:move($sel,$usel)'>
369: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
370: </table>
371: END
372: return $string;
373: }
374:
375: # ------------------------------------------ Select box (returns scalar string)
376: sub select_box {
377: my ($total,$sel) = @_;
378: my $string;
379: $string = '<select name="alt'.$sel.'"';
380: $string .= " onChange='selectchange($sel)'>";
381: $string .= "<option name='o0' value='0'>remove</option>";
382: for my $cur (1..$total) {
383: $string .= "<option name='o$cur' value='$cur'";
384: if ($cur == $sel) {
385: $string .= "selected";
386: }
387: $string .= ">$cur</option>";
388: }
389: $string .= "</select>\n";
390: return $string;
391: }
392:
393: 1;
394:
395: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>