File:
[LON-CAPA] /
rat /
lonratedt.pm
Revision
1.27:
download - view:
text,
annotated -
select for diffs
Wed May 22 20:39:59 2002 UTC (22 years, 4 months ago) by
www
Branches:
MAIN
CVS tags:
HEAD
Apparently, "import" is a reserved word in NS 6.2 and Explorer. Renamed
select field. Fixed error in <script> block, and group search, etc, runs now.
Bug #466
1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.27 2002/05/22 20:39:59 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # (TeX Content Handler
29: #
30: # 05/29/00,05/30 Gerd Kortemeyer)
31: # 7/1,6/30 Gerd Kortemeyer
32:
33: package Apache::lonratedt;
34:
35: use strict;
36: use Apache::Constants qw(:common);
37: use Apache::lonnet;
38: use Apache::lonratsrv;
39:
40: my @order;
41: my @resources;
42:
43:
44: # Mapread read maps into global arrays @links and @resources, determines status
45: # sets @order - pointer to resources in right order
46: # sets @resources - array with the resources with correct idx
47: #
48: sub mapread {
49: my $fn=shift;
50:
51: my @links;
52: undef @links;
53: undef @resources;
54: undef @order;
55: @resources=('');
56: @order=();
57:
58: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
59: if ($errtext) { return ($errtext,2); }
60:
61: # -------------------------------------------------------------------- Read map
62: foreach (split(/\<\&\>/,$outtext)) {
63: my ($command,$number,$content)=split(/\<\:\>/,$_);
64: if ($command eq 'objcont') {
65: $resources[$number]=$content;
66: }
67: if ($command eq 'objlinks') {
68: $links[$number]=$content;
69: }
70: }
71: # ------------------------------------------------------- Is this a linear map?
72: my @starters=();
73: my @endings=();
74: undef @starters;
75: undef @endings;
76:
77: foreach (@links) {
78: if (defined($_)) {
79: my ($start,$end,$cond)=split(/\:/,$_);
80: if ((defined($starters[$start])) || (defined($endings[$end]))) {
81: return
82: ('Map has branchings. Use advanced editor.',1);
83: }
84: $starters[$start]=1;
85: $endings[$end]=1;
86: if ($cond) {
87: return
88: ('Map has conditions. Use advanced editor.',1);
89: }
90: }
91:
92: }
93: for (my $i=1; $i<=$#resources; $i++) {
94: if (defined($resources[$i])) {
95: unless (($starters[$i]) || ($endings[$i])) {
96: return
97: ('Map has unconnected resources. Use advanced editor.',1);
98: }
99: }
100: }
101:
102: # -------------------------------------------------- This is a linear map, sort
103:
104: my $startidx=0;
105: my $endidx=0;
106: for (my $i=0; $i<=$#resources; $i++) {
107: if (defined($resources[$i])) {
108: my ($title,$url,$ext,$type)=split(/\:/,$resources[$i]);
109: if ($type eq 'start') { $startidx=$i; }
110: if ($type eq 'finish') { $endidx=$i; }
111: }
112: }
113: my $k=0;
114: my $currentidx=$startidx;
115: $order[$k]=$currentidx;
116: for (my $i=0; $i<=$#resources; $i++) {
117: foreach (@links) {
118: my ($start,$end)=split(/\:/,$_);
119: if ($start==$currentidx) {
120: $currentidx=$end;
121: $k++;
122: $order[$k]=$currentidx;
123: last;
124: }
125: }
126: if ($currentidx==$endidx) { last; }
127: }
128: return $errtext;
129: }
130:
131: # ---------------------------------------------- Read a map as well as possible
132:
133: sub attemptread {
134: my $fn=shift;
135:
136: my @links;
137: undef @links;
138: my @theseres;
139: undef @theseres;
140:
141: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
142: if ($errtext) { return @theseres }
143:
144: # -------------------------------------------------------------------- Read map
145: foreach (split(/\<\&\>/,$outtext)) {
146: my ($command,$number,$content)=split(/\<\:\>/,$_);
147: if ($command eq 'objcont') {
148: $theseres[$number]=$content;
149: }
150: if ($command eq 'objlinks') {
151: $links[$number]=$content;
152: }
153: }
154:
155: # --------------------------------------------------------------- Sort, sort of
156:
157: my @objsort=();
158: undef @objsort;
159:
160: my @data1=();
161: my @data2=();
162: undef @data1;
163: undef @data2;
164:
165: my $k;
166: my $kj;
167: my $j;
168: my $ij;
169:
170: for ($k=1;$k<=$#theseres;$k++) {
171: if (defined($theseres[$k])) {
172: $objsort[$#objsort+1]=$k;
173: }
174: }
175:
176: for ($k=1;$k<=$#links;$k++) {
177: if (defined($links[$k])) {
178: @data1=split(/\:/,$links[$k]);
179: $kj=-1;
180: for (my $j=0;$j<=$#objsort;$j++) {
181: if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
182: $kj=$j;
183: }
184: }
185: if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
186: }
187: }
188: for ($k=0;$k<=$#objsort;$k++) {
189: for ($j=0;$j<=$#objsort;$j++) {
190: if ($k!=$j) {
191: @data1=split(/\:/,$objsort[$k]);
192: @data2=split(/\:/,$objsort[$j]);
193: my $dol=$#data1+1;
194: my $dtl=$#data2+1;
195: if ($dol+$dtl<1000) {
196: for ($kj=1;$kj<$dol;$kj++) {
197: if ($data1[$kj]==$data2[0]) {
198: for ($ij=1;$ij<$dtl;$ij++) {
199: $data1[$#data1+1]=$data2[$ij];
200: }
201: }
202: }
203: for ($kj=1;$kj<$dtl;$kj++) {
204: if ($data2[$kj]==$data1[0]) {
205: for ($ij=1;$ij<$dol;$ij++) {
206: $data2[$#data2+1]=$data1[$ij];
207: }
208: }
209: }
210: $objsort[$k]=join(':',@data1);
211: $objsort[$j]=join(':',@data2);
212: }
213: }
214: }
215: }
216: # ---------------------------------------------------------------- Now sort out
217:
218: @objsort=sort {
219: my @data1=split(/\:/,$a);
220: my @data2=split(/\:/,$b);
221: my $rvalue=0;
222: my $k;
223: for ($k=1;$k<=$#data1;$k++) {
224: if ($data1[$k]==$data2[0]) { $rvalue--; }
225: }
226: for ($k=1;$k<=$#data2;$k++) {
227: if ($data2[$k]==$data1[0]) { $rvalue++; }
228: }
229: if ($rvalue==0) { $rvalue=$#data2-$#data1; }
230: $rvalue;
231: } @objsort;
232:
233: my @outres=();
234: undef @outres;
235:
236: for ($k=0;$k<=$#objsort;$k++) {
237: $outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
238: }
239: return @outres;
240: }
241:
242: # --------------------------------------------------------- Build up RAT screen
243: sub ratedt {
244: my ($r,$url)=@_;
245: $r->print(<<ENDDOCUMENT);
246:
247: <html>
248: <head>
249: <script language="JavaScript">
250: var flag=0;
251: </script>
252: </head>
253: <frameset rows="1,50,*" border=0>
254: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
255: <frame name=code src="/adm/rat/code.html">
256: <frame name=mapout src="/adm/rat/map.html">
257: </frameset>
258: </html>
259:
260: ENDDOCUMENT
261: }
262:
263: # ---------------------------------------------------------------- Make buttons
264:
265: sub buttons {
266: if ($ENV{'form.forceselect'}) { return ''; }
267: my $adv=shift;
268: my $output='<form method=post>';
269: if ($adv==1) {
270: $output.='<input type=submit name=forceadv value="Edit">';
271: } else {
272: unless ($adv==2) {
273: $output.='<input type=submit name=forcesmp value="Simple Edit">';
274: }
275: $output.='<input type=submit name=forceadv value="Advanced Edit">';
276: }
277: return $output.'</form><hr>';
278: }
279:
280: # ----------------------------------------------------------- Paste into target
281: # modifies @order, @resources
282:
283: sub pastetarget {
284: my ($after,@which)=@_;
285: my @insertorder=();
286: foreach (@which) {
287: if (defined($_)) {
288: my ($name,$url)=split(/\=/,$_);
289: $name=&Apache::lonnet::unescape($name);
290: $url=&Apache::lonnet::unescape($url);
291: if ($url) {
292: my $idx=$#resources+1;
293: $insertorder[$#insertorder+1]=$idx;
294: my $ext='false';
295: if ($url=~/^http\:\/\//) { $ext='true'; }
296: $url=~s/\:/\:/g;
297: $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
298: }
299: }
300: }
301: my @oldorder=splice(@order,$after);
302: @order=(@order,@insertorder,@oldorder);
303: }
304:
305: # ------------------------------------------------ Get start and finish correct
306: # modifies @resources
307:
308: sub startfinish {
309: foreach (@order) {
310: my ($name,$url,$ext)=split(/\:/,$resources[$_]);
311: if ($url=~/http\&colon\:\/\//) { $ext='true'; }
312: $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
313: }
314: my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
315: $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
316: my ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
317: $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
318: }
319:
320: # ------------------------------------------------------------------- Store map
321:
322: sub storemap {
323: my $fn=shift;
324: &startfinish();
325: my $output='graphdef<:>no';
326: my $k=1;
327: for (my $i=0; $i<=$#order; $i++) {
328: if (defined($resources[$order[$i]])) {
329: $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
330: }
331: if (defined($order[$i+1])) {
332: if (defined($resources[$order[$i+1]])) {
333: $output.='<&>objlinks<:>'.$k.'<:>'.
334: $order[$i].':'.$order[$i+1].':0';
335: $k++;
336: }
337: }
338: }
339: $output=~s/http\&colon\;\/\///g;
340: $ENV{'form.output'}=$output;
341: return
342: &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
343: }
344:
345: # ------------------------------------------------------- Simple edit processor
346:
347: sub smpedt {
348: my ($r,$url,$errtext)=@_;
349: my $buttons=&buttons(2);
350:
351: # ---------------------------------------------------------- Process form input
352:
353: my @importselect=();
354: my @targetselect=();
355: undef @importselect;
356: undef @targetselect;
357: if (defined($ENV{'form.importsel'})) {
358: if (ref($ENV{'form.importsel'})) {
359: @importselect=sort(@{$ENV{'form.importsel'}});
360: } else {
361: @importselect=($ENV{'form.importsel'});
362: }
363: }
364: if (defined($ENV{'form.target'})) {
365: if (ref($ENV{'form.target'})) {
366: @targetselect=sort(@{$ENV{'form.target'}});
367: } else {
368: @targetselect=($ENV{'form.target'});
369: }
370: }
371: # ============================================================ Process commands
372:
373: my $targetdetail=$ENV{'form.targetdetail'};
374: my $importdetail=$ENV{'form.curimpdetail'};
375:
376: # ---------------------------------------------------- Importing from groupsort
377: if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
378:
379: $importdetail='';
380: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
381:
382: my $lastsel;
383:
384: if (defined($importselect[-1])) {
385: $lastsel=$importselect[-1];
386: } else {
387: $lastsel=$#curimport;
388: }
389:
390: for (my $i=0;$i<=$lastsel;$i++) {
391: my ($name,$url)=split(/\=/,$curimport[$i]);
392: if ($url) {
393: $importdetail.='&'.$name.'='.$url;
394: }
395: }
396:
397: $importdetail.='&'.$ENV{'form.importdetail'};
398:
399: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
400: my ($name,$url)=split(/\=/,$curimport[$i]);
401: if ($url) {
402: $importdetail.='&'.$name.'='.$url;
403: }
404: }
405: $importdetail=~s/\&+/\&/g;
406: $importdetail=~s/^\&//;
407:
408: # ------------------------------------------------------------------- Clear all
409: } elsif ($ENV{'form.clear'}) {
410: $importdetail='';
411: # ------------------------------------------------------------ Discard selected
412: } elsif ($ENV{'form.discard'}) {
413: $importdetail='';
414: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
415: foreach (@importselect) {
416: $curimport[$_]='';
417: }
418: for (my $i=0;$i<=$#curimport;$i++) {
419: my ($name,$url)=split(/\=/,$curimport[$i]);
420: if ($url) {
421: $importdetail.='&'.$name.'='.$url;
422: }
423: }
424: # --------------------------------------------------------- Loading another map
425: } elsif ($ENV{'form.loadmap'}) {
426: $importdetail='';
427: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
428:
429: my $lastsel;
430:
431: if (defined($importselect[-1])) {
432: $lastsel=$importselect[-1];
433: } else {
434: $lastsel=$#curimport;
435: }
436:
437: for (my $i=0;$i<=$lastsel;$i++) {
438: my ($name,$url)=split(/\=/,$curimport[$i]);
439: if ($url) {
440: $importdetail.='&'.$name.'='.$url;
441: }
442: }
443:
444: foreach (
445: &attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
446: my ($name,$url)=split(/\:/,$_);
447: if ($url) {
448: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
449: &Apache::lonnet::escape($url);
450: }
451: }
452:
453: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
454: my ($name,$url)=split(/\=/,$curimport[$i]);
455: if ($url) {
456: $importdetail.='&'.$name.'='.$url;
457: }
458: }
459: $importdetail=~s/\&+/\&/g;
460: $importdetail=~s/^\&//;
461:
462: # ------------------------------------------------ Groupimport/search to target
463: } elsif ($ENV{'form.importdetail'}) {
464: my $lastsel;
465: if (defined($targetselect[-1])) {
466: $lastsel=$targetselect[-1];
467: } else {
468: $lastsel=$#order+1;
469: }
470: &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
471: &storemap(&Apache::lonnet::filelocation('',$url));
472: # ------------------------------------------------------------------------- Cut
473: } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
474: $importdetail='';
475: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
476:
477: my $lastsel;
478:
479: if (defined($importselect[-1])) {
480: $lastsel=$importselect[-1];
481: } else {
482: $lastsel=$#curimport;
483: }
484:
485: for (my $i=0;$i<=$lastsel;$i++) {
486: my ($name,$url)=split(/\=/,$curimport[$i]);
487: if ($url) {
488: $importdetail.='&'.$name.'='.$url;
489: }
490: }
491:
492: foreach (@targetselect) {
493: my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
494: if ($url) {
495: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
496: &Apache::lonnet::escape($url);
497: }
498: }
499:
500: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
501: my ($name,$url)=split(/\=/,$curimport[$i]);
502: if ($url) {
503: $importdetail.='&'.$name.'='.$url;
504: }
505: }
506: $importdetail=~s/\&+/\&/g;
507: $importdetail=~s/^\&//;
508:
509: if ($ENV{'form.cut'}) {
510: my @neworder=();
511: for (my $i=0;$i<=$#order;$i++) {
512: my $include=1;
513: foreach (@targetselect) {
514: if ($_-1==$i) { $include=0; }
515: }
516: if ($include) { $neworder[$#neworder+1]=$order[$i]; }
517: }
518: @order=@neworder;
519: &storemap(&Apache::lonnet::filelocation('',$url));
520: }
521:
522: # ----------------------------------------------------------------------- Paste
523: } elsif ($ENV{'form.paste'}) {
524: my $lastsel;
525: if (defined($targetselect[-1])) {
526: $lastsel=$targetselect[-1];
527: } else {
528: $lastsel=$#order+1;
529: }
530: my @newsequence;
531: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
532: foreach (@importselect) {
533: $newsequence[$#newsequence+1]=$curimport[$_];
534: }
535: &pastetarget($lastsel,@newsequence);
536: &storemap(&Apache::lonnet::filelocation('',$url));
537: # ------------------------------------------------
538: }
539: # ------------------------------------------------------------ Assemble windows
540:
541: my $idx=-1;
542: my $importwindow=join("\n",map {
543: $idx++;
544: if ($_) {
545: my ($name,$url)=split(/\=/,$_);
546: unless ($name) { $name=(split(/\//,$url))[-1]; }
547: unless ($name) { $name='EMPTY'; }
548: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
549: '</option>';
550: }
551: } split(/\&/,$importdetail));
552:
553: $idx=0;
554: my $targetwindow=join("\n",map {
555: my ($name,$url)=split(/\:/,$resources[$_]);
556: unless ($name) { $name=(split(/\//,$url))[-1]; }
557: unless ($name) { $name='EMPTY'; }
558: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
559: &Apache::lonnet::escape($url);
560: $idx++;
561: '<option value="'.$idx.'">'.$name.'</option>';
562: } @order);
563:
564: # ----------------------------------------------------- Start simple RAT screen
565: $r->print(<<ENDSMPHEAD);
566: <html>
567: <head>
568: <script>
569: var srch;
570: var srchflag=-1; // 1 means currently open
571: // 0 means closed (but has been open)
572: // -1 means never yet opened/defined
573: var srchmode='';
574:
575: var idx;
576: var idxflag=-1; // 1 means currently open
577: // 0 means closed (but has been open)
578: // -1 means never yet opened/defined
579: var idxmode='';
580:
581: // ------------------------------------------------------ Clears indexer window
582: function idxclear() {
583: idx.document.clear();
584: }
585:
586: // ------------------------------------------------------- Clears search window
587: function srchclear() {
588: srch.document.clear();
589: }
590:
591: // ------------------------------------------------------ Closes indexer window
592: function idxclose() {
593: if (idx && !idx.closed) {
594: idxflag=0;
595: idx.close();
596: }
597: }
598:
599: // ------------------------------------------------------- Closes search window
600: function srchclose() {
601: if (srch && !srch.closed) {
602: srchflag=0;
603: srch.close();
604: }
605: }
606:
607: // -------------------------------------------------------- Open indexer window
608: function idxopen(mode) {
609: var options="scrollbars=1,resizable=1,menubar=0";
610: idxmode=mode;
611: idxflag=1;
612: idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
613: idx.focus();
614: }
615:
616: // --------------------------------------------------------- Open search window
617: function srchopen(mode) {
618: var options="scrollbars=1,resizable=1,menubar=0";
619: srchmode=mode;
620: srchflag=1;
621: srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
622: srch.focus();
623: }
624: // ----------------------------------------------------- launch indexer browser
625: function groupsearch() {
626: srchcheck('groupsearch');
627: }
628:
629: function groupimport() {
630: idxcheck('groupimport');
631: }
632: // ------------------------------------------------------- Do srch status check
633: function srchcheck(mode) {
634: if (!srch || srch.closed || srchmode!=mode) {
635: srchopen(mode);
636: }
637: srch.focus();
638: }
639:
640: // -------------------------------------------------------- Do idx status check
641: function idxcheck(mode) {
642: if (!idx || idx.closed || idxmode!=mode) {
643: idxopen(mode);
644: }
645: idx.focus();
646: }
647:
648:
649: var editbrowser;
650: function openbrowser(formname,elementname,only,omit) {
651: var url = '/res/?';
652: if (editbrowser == null) {
653: url += 'launch=1&';
654: }
655: url += 'catalogmode=interactive&';
656: url += 'mode=edit&';
657: url += 'form=' + formname + '&';
658: if (only != null) {
659: url += 'only=' + only + '&';
660: }
661: if (omit != null) {
662: url += 'omit=' + omit + '&';
663: }
664: url += 'element=' + elementname + '';
665: var title = 'Browser';
666: var options = 'scrollbars=1,resizable=1,menubar=0';
667: options += ',width=700,height=600';
668: editbrowser = open(url,title,options,'1');
669: editbrowser.focus();
670: }
671:
672: function openview(entry) {
673: var url=unescape((entry.split('='))[1]);
674: var parts=new Array;
675: parts=url.split(':');
676: url=parts.join(':');
677: if (url) { open(url,'cat'); }
678: }
679:
680: function viewtarget() {
681: openview((document.forms.simpleedit.targetdetail.value.split('&'))
682: [document.forms.simpleedit.target.selectedIndex+1]);
683: }
684:
685: function viewimport() {
686: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
687: [document.forms.simpleedit.importsel.selectedIndex+1]);
688: }
689:
690: </script>
691: </head>
692: <body bgcolor='#FFFFFF'>
693: $buttons
694: <font color=red>$errtext</font>
695: <form name=simpleedit method=post>
696: <input type=hidden name=forcesmp value=1>
697: <table>
698: <tr><th width="40%">Import</th>
699: <th> </th>
700: <th width="40%">Target</th></tr>
701: <tr><td bgcolor="#FFFFCC">
702: <input type=button onClick="javascript:groupsearch()" value="Group Search">
703: <input type=button onClick="javascript:groupimport();" value="Group Import">
704: after selected
705: <hr>
706: <input type=text size=20 name=importmap>
707: <input type=button
708: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
709: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
710: <input type=submit name="discard" value="Discard Selected">
711: <input type=submit name="clear" value="Clear All">
712: <input type=button onClick="javascript:viewimport()" value="View">
713:
714: </td><td> </td><td bgcolor="#FFFFCC">
715:
716: <input type=button onClick=
717: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
718: <input type=button onClick=
719: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
720: after selected
721: <hr><input type=button onClick="javascript:viewtarget()" value="View">
722: </td></tr>
723:
724: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
725: $importwindow
726: </select>
727: </td>
728: <td bgcolor="#FFFFAA" align="center">
729: Cut selected<br>
730: <input type=submit name=cut value='<<<'><p>
731: <hr>
732: Copy selected<br>
733: <input type=submit name=copy value='<--'><p>
734: <hr>
735: Paste after selected<br>
736: <input type=submit name=paste value='-->'>
737: </td>
738: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
739: $targetwindow
740: </select>
741: </table>
742: <input type=hidden name=importdetail value="">
743: <input type=hidden name=curimpdetail value="$importdetail">
744: <input type=hidden name=targetdetail value="$targetdetail">
745: <input type=hidden name=impfortarget value="0">
746: </form>
747: </body></html>
748: ENDSMPHEAD
749: }
750:
751: # ----------------------------------------------------------------- No such dir
752: sub nodir {
753: my ($r,$dir)=@_;
754: $dir=~s/^\/home\/\w+\/public\_html//;
755: $r->print(<<ENDNODIR);
756: <html>
757: <body bgcolor='#FFFFFF'>
758: <h1>No such directory: $dir</h1>
759: </body>
760: </html>
761: ENDNODIR
762: }
763:
764: # ---------------------------------------------------------------- View Handler
765:
766: sub viewmap {
767: my ($r,$url,$adv,$errtext)=@_;
768: $r->print('<html>');
769: if ($ENV{'form.forceselect'}) { $r->print(<<ENDSCRIPT);
770: <script>
771:
772: function select_group() {
773: window.location="/adm/groupsort?catalogmode=groupimport&mode=rat&acts="+document.forms.fileattr.acts.value;
774: }
775:
776: function queue(val) {
777: if (eval("document.forms."+val+".filelink.checked")) {
778: var l=val.length;
779: var v=val.substring(4,l);
780: document.forms.fileattr.acts.value+='1a'+v+'b';
781: }
782: else {
783: var l=val.length;
784: var v=val.substring(4,l);
785: document.forms.fileattr.acts.value+='0a'+v+'b';
786: }
787: }
788:
789:
790:
791: </script>
792: ENDSCRIPT
793: }
794: $r->print('<body bgcolor="#FFFFFF">'.&buttons($adv));
795: if ($ENV{'form.forceselect'}) { $r->print(<<ENDSELECT);
796: <form name=fileattr><input type=hidden name=acts value=''>
797: <input type="button" name="close" value='CLOSE' onClick="self.close()">
798: <input type="button" name="groupimport" value='GROUP IMPORT'
799: onClick="javascript:select_group()">
800: </form>
801: ENDSELECT
802: }
803: if ($errtext) {
804: $r->print($errtext.'<hr>');
805: }
806: my $idx=0;
807: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
808: if (defined($_)) {
809: $idx++;
810: if ($ENV{'form.forceselect'}) {
811: $r->print('<form name="form'.$idx.'">');
812: }
813: my ($title,$url)=split(/\:/,$_);
814: $title=~s/\&colon\;/\:/g;
815: $url=~s/\&colon\;/\:/g;
816: unless ($title) { $title=(split(/\//,$url))[-1] };
817: unless ($title) { $title='<i>Empty</i>'; }
818: if ($url) {
819: if ($ENV{'form.forceselect'}) {
820: $r->print(<<ENDCHECKBOX);
821: <input type='checkbox' name='filelink'
822: value='$url' onClick='javascript:queue("form$idx")' >
823: <input type='hidden' name='title' value='$title'>
824: ENDCHECKBOX
825: }
826: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
827: }
828: $r->print(&Apache::lonratsrv::qtescape($title));
829: if ($url) { $r->print('</a>'); }
830: if ($ENV{'form.forceselect'}) {
831: $r->print('</form>');
832: } else {
833: $r->print('<br>');
834: }
835: }
836: }
837: $r->print('</body></html>');
838: }
839:
840: # ================================================================ Main Handler
841:
842: sub handler {
843: my $r=shift;
844: $r->content_type('text/html');
845: $r->send_http_header;
846:
847: return OK if $r->header_only;
848:
849: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
850: ['forceselect']);
851:
852: my $url=$r->uri;
853: my $fn=&Apache::lonnet::filelocation('',$url);
854:
855: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
856: unless (-e $dir) {
857: &nodir($r,$dir);
858: return OK;
859: }
860:
861: # ------------------------------------------- Determine which tools can be used
862: my $adv=0;
863:
864: unless ($ENV{'form.forcesmp'}) {
865: if ($ENV{'form.forceadv'}) {
866: $adv=1;
867: } elsif (my $fh=Apache::File->new($fn)) {
868: my $allmap=join('',<$fh>);
869: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
870: }
871: }
872:
873: my $errtext='';
874: my $fatal=0;
875:
876: # -------------------------------------------------------------------- Load map
877: ($errtext,$fatal)=&mapread($fn,$errtext);
878:
879: if ($fatal==1) { $adv=1; }
880:
881: # ----------------------------------- adv==1 now means "graphical MUST be used"
882:
883: if ($ENV{'form.forceadv'}) {
884: &ratedt($r,$url);
885: } elsif ($ENV{'form.forcesmp'}) {
886: &smpedt($r,$url,$errtext);
887: } else {
888: &viewmap($r,$url,$adv,$errtext);
889: }
890: return OK;
891: }
892:
893: 1;
894: __END__
895:
896:
897:
898:
899:
900:
901:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>