File:
[LON-CAPA] /
rat /
lonratedt.pm
Revision
1.28:
download - view:
text,
annotated -
select for diffs
Thu May 23 10:19:30 2002 UTC (22 years, 2 months ago) by
www
Branches:
MAIN
CVS tags:
HEAD
Selection of resources from sequences for RAT should be done out of
resource space - moved code for that from lonratedt
Starting to work on viewing of sequences out of course context
1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.28 2002/05/23 10:19:30 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: # Also used by the sequence handler
133: # Call lonsequence::attemptread to read from resource space
134: #
135: sub attemptread {
136: my $fn=shift;
137:
138: my @links;
139: undef @links;
140: my @theseres;
141: undef @theseres;
142:
143: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
144: if ($errtext) { return @theseres }
145:
146: # -------------------------------------------------------------------- Read map
147: foreach (split(/\<\&\>/,$outtext)) {
148: my ($command,$number,$content)=split(/\<\:\>/,$_);
149: if ($command eq 'objcont') {
150: $theseres[$number]=$content;
151: }
152: if ($command eq 'objlinks') {
153: $links[$number]=$content;
154: }
155: }
156:
157: # --------------------------------------------------------------- Sort, sort of
158:
159: my @objsort=();
160: undef @objsort;
161:
162: my @data1=();
163: my @data2=();
164: undef @data1;
165: undef @data2;
166:
167: my $k;
168: my $kj;
169: my $j;
170: my $ij;
171:
172: for ($k=1;$k<=$#theseres;$k++) {
173: if (defined($theseres[$k])) {
174: $objsort[$#objsort+1]=$k;
175: }
176: }
177:
178: for ($k=1;$k<=$#links;$k++) {
179: if (defined($links[$k])) {
180: @data1=split(/\:/,$links[$k]);
181: $kj=-1;
182: for (my $j=0;$j<=$#objsort;$j++) {
183: if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
184: $kj=$j;
185: }
186: }
187: if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
188: }
189: }
190: for ($k=0;$k<=$#objsort;$k++) {
191: for ($j=0;$j<=$#objsort;$j++) {
192: if ($k!=$j) {
193: @data1=split(/\:/,$objsort[$k]);
194: @data2=split(/\:/,$objsort[$j]);
195: my $dol=$#data1+1;
196: my $dtl=$#data2+1;
197: if ($dol+$dtl<1000) {
198: for ($kj=1;$kj<$dol;$kj++) {
199: if ($data1[$kj]==$data2[0]) {
200: for ($ij=1;$ij<$dtl;$ij++) {
201: $data1[$#data1+1]=$data2[$ij];
202: }
203: }
204: }
205: for ($kj=1;$kj<$dtl;$kj++) {
206: if ($data2[$kj]==$data1[0]) {
207: for ($ij=1;$ij<$dol;$ij++) {
208: $data2[$#data2+1]=$data1[$ij];
209: }
210: }
211: }
212: $objsort[$k]=join(':',@data1);
213: $objsort[$j]=join(':',@data2);
214: }
215: }
216: }
217: }
218: # ---------------------------------------------------------------- Now sort out
219:
220: @objsort=sort {
221: my @data1=split(/\:/,$a);
222: my @data2=split(/\:/,$b);
223: my $rvalue=0;
224: my $k;
225: for ($k=1;$k<=$#data1;$k++) {
226: if ($data1[$k]==$data2[0]) { $rvalue--; }
227: }
228: for ($k=1;$k<=$#data2;$k++) {
229: if ($data2[$k]==$data1[0]) { $rvalue++; }
230: }
231: if ($rvalue==0) { $rvalue=$#data2-$#data1; }
232: $rvalue;
233: } @objsort;
234:
235: my @outres=();
236: undef @outres;
237:
238: for ($k=0;$k<=$#objsort;$k++) {
239: $outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
240: }
241: return @outres;
242: }
243:
244: # --------------------------------------------------------- Build up RAT screen
245: sub ratedt {
246: my ($r,$url)=@_;
247: $r->print(<<ENDDOCUMENT);
248:
249: <html>
250: <head>
251: <script language="JavaScript">
252: var flag=0;
253: </script>
254: </head>
255: <frameset rows="1,50,*" border=0>
256: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
257: <frame name=code src="/adm/rat/code.html">
258: <frame name=mapout src="/adm/rat/map.html">
259: </frameset>
260: </html>
261:
262: ENDDOCUMENT
263: }
264:
265: # ---------------------------------------------------------------- Make buttons
266:
267: sub buttons {
268: my $adv=shift;
269: my $output='<form method=post>';
270: if ($adv==1) {
271: $output.='<input type=submit name=forceadv value="Edit">';
272: } else {
273: unless ($adv==2) {
274: $output.='<input type=submit name=forcesmp value="Simple Edit">';
275: }
276: $output.='<input type=submit name=forceadv value="Advanced Edit">';
277: }
278: return $output.'</form><hr>';
279: }
280:
281: # ----------------------------------------------------------- Paste into target
282: # modifies @order, @resources
283:
284: sub pastetarget {
285: my ($after,@which)=@_;
286: my @insertorder=();
287: foreach (@which) {
288: if (defined($_)) {
289: my ($name,$url)=split(/\=/,$_);
290: $name=&Apache::lonnet::unescape($name);
291: $url=&Apache::lonnet::unescape($url);
292: if ($url) {
293: my $idx=$#resources+1;
294: $insertorder[$#insertorder+1]=$idx;
295: my $ext='false';
296: if ($url=~/^http\:\/\//) { $ext='true'; }
297: $url=~s/\:/\:/g;
298: $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
299: }
300: }
301: }
302: my @oldorder=splice(@order,$after);
303: @order=(@order,@insertorder,@oldorder);
304: }
305:
306: # ------------------------------------------------ Get start and finish correct
307: # modifies @resources
308:
309: sub startfinish {
310: foreach (@order) {
311: my ($name,$url,$ext)=split(/\:/,$resources[$_]);
312: if ($url=~/http\&colon\:\/\//) { $ext='true'; }
313: $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
314: }
315: my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
316: $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
317: my ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
318: $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
319: }
320:
321: # ------------------------------------------------------------------- Store map
322:
323: sub storemap {
324: my $fn=shift;
325: &startfinish();
326: my $output='graphdef<:>no';
327: my $k=1;
328: for (my $i=0; $i<=$#order; $i++) {
329: if (defined($resources[$order[$i]])) {
330: $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
331: }
332: if (defined($order[$i+1])) {
333: if (defined($resources[$order[$i+1]])) {
334: $output.='<&>objlinks<:>'.$k.'<:>'.
335: $order[$i].':'.$order[$i+1].':0';
336: $k++;
337: }
338: }
339: }
340: $output=~s/http\&colon\;\/\///g;
341: $ENV{'form.output'}=$output;
342: return
343: &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
344: }
345:
346: # ------------------------------------------------------- Simple edit processor
347:
348: sub smpedt {
349: my ($r,$url,$errtext)=@_;
350: my $buttons=&buttons(2);
351:
352: # ---------------------------------------------------------- Process form input
353:
354: my @importselect=();
355: my @targetselect=();
356: undef @importselect;
357: undef @targetselect;
358: if (defined($ENV{'form.importsel'})) {
359: if (ref($ENV{'form.importsel'})) {
360: @importselect=sort(@{$ENV{'form.importsel'}});
361: } else {
362: @importselect=($ENV{'form.importsel'});
363: }
364: }
365: if (defined($ENV{'form.target'})) {
366: if (ref($ENV{'form.target'})) {
367: @targetselect=sort(@{$ENV{'form.target'}});
368: } else {
369: @targetselect=($ENV{'form.target'});
370: }
371: }
372: # ============================================================ Process commands
373:
374: my $targetdetail=$ENV{'form.targetdetail'};
375: my $importdetail=$ENV{'form.curimpdetail'};
376:
377: # ---------------------------------------------------- Importing from groupsort
378: if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
379:
380: $importdetail='';
381: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
382:
383: my $lastsel;
384:
385: if (defined($importselect[-1])) {
386: $lastsel=$importselect[-1];
387: } else {
388: $lastsel=$#curimport;
389: }
390:
391: for (my $i=0;$i<=$lastsel;$i++) {
392: my ($name,$url)=split(/\=/,$curimport[$i]);
393: if ($url) {
394: $importdetail.='&'.$name.'='.$url;
395: }
396: }
397:
398: $importdetail.='&'.$ENV{'form.importdetail'};
399:
400: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
401: my ($name,$url)=split(/\=/,$curimport[$i]);
402: if ($url) {
403: $importdetail.='&'.$name.'='.$url;
404: }
405: }
406: $importdetail=~s/\&+/\&/g;
407: $importdetail=~s/^\&//;
408:
409: # ------------------------------------------------------------------- Clear all
410: } elsif ($ENV{'form.clear'}) {
411: $importdetail='';
412: # ------------------------------------------------------------ Discard selected
413: } elsif ($ENV{'form.discard'}) {
414: $importdetail='';
415: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
416: foreach (@importselect) {
417: $curimport[$_]='';
418: }
419: for (my $i=0;$i<=$#curimport;$i++) {
420: my ($name,$url)=split(/\=/,$curimport[$i]);
421: if ($url) {
422: $importdetail.='&'.$name.'='.$url;
423: }
424: }
425: # --------------------------------------------------------- Loading another map
426: } elsif ($ENV{'form.loadmap'}) {
427: $importdetail='';
428: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
429:
430: my $lastsel;
431:
432: if (defined($importselect[-1])) {
433: $lastsel=$importselect[-1];
434: } else {
435: $lastsel=$#curimport;
436: }
437:
438: for (my $i=0;$i<=$lastsel;$i++) {
439: my ($name,$url)=split(/\=/,$curimport[$i]);
440: if ($url) {
441: $importdetail.='&'.$name.'='.$url;
442: }
443: }
444:
445: foreach (
446: &attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
447: my ($name,$url)=split(/\:/,$_);
448: if ($url) {
449: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
450: &Apache::lonnet::escape($url);
451: }
452: }
453:
454: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
455: my ($name,$url)=split(/\=/,$curimport[$i]);
456: if ($url) {
457: $importdetail.='&'.$name.'='.$url;
458: }
459: }
460: $importdetail=~s/\&+/\&/g;
461: $importdetail=~s/^\&//;
462:
463: # ------------------------------------------------ Groupimport/search to target
464: } elsif ($ENV{'form.importdetail'}) {
465: my $lastsel;
466: if (defined($targetselect[-1])) {
467: $lastsel=$targetselect[-1];
468: } else {
469: $lastsel=$#order+1;
470: }
471: &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
472: &storemap(&Apache::lonnet::filelocation('',$url));
473: # ------------------------------------------------------------------------- Cut
474: } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
475: $importdetail='';
476: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
477:
478: my $lastsel;
479:
480: if (defined($importselect[-1])) {
481: $lastsel=$importselect[-1];
482: } else {
483: $lastsel=$#curimport;
484: }
485:
486: for (my $i=0;$i<=$lastsel;$i++) {
487: my ($name,$url)=split(/\=/,$curimport[$i]);
488: if ($url) {
489: $importdetail.='&'.$name.'='.$url;
490: }
491: }
492:
493: foreach (@targetselect) {
494: my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
495: if ($url) {
496: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
497: &Apache::lonnet::escape($url);
498: }
499: }
500:
501: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
502: my ($name,$url)=split(/\=/,$curimport[$i]);
503: if ($url) {
504: $importdetail.='&'.$name.'='.$url;
505: }
506: }
507: $importdetail=~s/\&+/\&/g;
508: $importdetail=~s/^\&//;
509:
510: if ($ENV{'form.cut'}) {
511: my @neworder=();
512: for (my $i=0;$i<=$#order;$i++) {
513: my $include=1;
514: foreach (@targetselect) {
515: if ($_-1==$i) { $include=0; }
516: }
517: if ($include) { $neworder[$#neworder+1]=$order[$i]; }
518: }
519: @order=@neworder;
520: &storemap(&Apache::lonnet::filelocation('',$url));
521: }
522:
523: # ----------------------------------------------------------------------- Paste
524: } elsif ($ENV{'form.paste'}) {
525: my $lastsel;
526: if (defined($targetselect[-1])) {
527: $lastsel=$targetselect[-1];
528: } else {
529: $lastsel=$#order+1;
530: }
531: my @newsequence;
532: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
533: foreach (@importselect) {
534: $newsequence[$#newsequence+1]=$curimport[$_];
535: }
536: &pastetarget($lastsel,@newsequence);
537: &storemap(&Apache::lonnet::filelocation('',$url));
538: # ------------------------------------------------
539: }
540: # ------------------------------------------------------------ Assemble windows
541:
542: my $idx=-1;
543: my $importwindow=join("\n",map {
544: $idx++;
545: if ($_) {
546: my ($name,$url)=split(/\=/,$_);
547: unless ($name) { $name=(split(/\//,$url))[-1]; }
548: unless ($name) { $name='EMPTY'; }
549: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
550: '</option>';
551: }
552: } split(/\&/,$importdetail));
553:
554: $idx=0;
555: my $targetwindow=join("\n",map {
556: my ($name,$url)=split(/\:/,$resources[$_]);
557: unless ($name) { $name=(split(/\//,$url))[-1]; }
558: unless ($name) { $name='EMPTY'; }
559: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
560: &Apache::lonnet::escape($url);
561: $idx++;
562: '<option value="'.$idx.'">'.$name.'</option>';
563: } @order);
564:
565: # ----------------------------------------------------- Start simple RAT screen
566: $r->print(<<ENDSMPHEAD);
567: <html>
568: <head>
569: <script>
570: var srch;
571: var srchflag=-1; // 1 means currently open
572: // 0 means closed (but has been open)
573: // -1 means never yet opened/defined
574: var srchmode='';
575:
576: var idx;
577: var idxflag=-1; // 1 means currently open
578: // 0 means closed (but has been open)
579: // -1 means never yet opened/defined
580: var idxmode='';
581:
582: // ------------------------------------------------------ Clears indexer window
583: function idxclear() {
584: idx.document.clear();
585: }
586:
587: // ------------------------------------------------------- Clears search window
588: function srchclear() {
589: srch.document.clear();
590: }
591:
592: // ------------------------------------------------------ Closes indexer window
593: function idxclose() {
594: if (idx && !idx.closed) {
595: idxflag=0;
596: idx.close();
597: }
598: }
599:
600: // ------------------------------------------------------- Closes search window
601: function srchclose() {
602: if (srch && !srch.closed) {
603: srchflag=0;
604: srch.close();
605: }
606: }
607:
608: // -------------------------------------------------------- Open indexer window
609: function idxopen(mode) {
610: var options="scrollbars=1,resizable=1,menubar=0";
611: idxmode=mode;
612: idxflag=1;
613: idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
614: idx.focus();
615: }
616:
617: // --------------------------------------------------------- Open search window
618: function srchopen(mode) {
619: var options="scrollbars=1,resizable=1,menubar=0";
620: srchmode=mode;
621: srchflag=1;
622: srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
623: srch.focus();
624: }
625: // ----------------------------------------------------- launch indexer browser
626: function groupsearch() {
627: srchcheck('groupsearch');
628: }
629:
630: function groupimport() {
631: idxcheck('groupimport');
632: }
633: // ------------------------------------------------------- Do srch status check
634: function srchcheck(mode) {
635: if (!srch || srch.closed || srchmode!=mode) {
636: srchopen(mode);
637: }
638: srch.focus();
639: }
640:
641: // -------------------------------------------------------- Do idx status check
642: function idxcheck(mode) {
643: if (!idx || idx.closed || idxmode!=mode) {
644: idxopen(mode);
645: }
646: idx.focus();
647: }
648:
649:
650: var editbrowser;
651: function openbrowser(formname,elementname,only,omit) {
652: var url = '/res/?';
653: if (editbrowser == null) {
654: url += 'launch=1&';
655: }
656: url += 'catalogmode=interactive&';
657: url += 'mode=edit&';
658: url += 'form=' + formname + '&';
659: if (only != null) {
660: url += 'only=' + only + '&';
661: }
662: if (omit != null) {
663: url += 'omit=' + omit + '&';
664: }
665: url += 'element=' + elementname + '';
666: var title = 'Browser';
667: var options = 'scrollbars=1,resizable=1,menubar=0';
668: options += ',width=700,height=600';
669: editbrowser = open(url,title,options,'1');
670: editbrowser.focus();
671: }
672:
673: function openview(entry) {
674: var url=unescape((entry.split('='))[1]);
675: var parts=new Array;
676: parts=url.split(':');
677: url=parts.join(':');
678: if (url) { open(url,'cat'); }
679: }
680:
681: function viewtarget() {
682: openview((document.forms.simpleedit.targetdetail.value.split('&'))
683: [document.forms.simpleedit.target.selectedIndex+1]);
684: }
685:
686: function viewimport() {
687: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
688: [document.forms.simpleedit.importsel.selectedIndex+1]);
689: }
690:
691: </script>
692: </head>
693: <body bgcolor='#FFFFFF'>
694: $buttons
695: <font color=red>$errtext</font>
696: <form name=simpleedit method=post>
697: <input type=hidden name=forcesmp value=1>
698: <table>
699: <tr><th width="40%">Import</th>
700: <th> </th>
701: <th width="40%">Target</th></tr>
702: <tr><td bgcolor="#FFFFCC">
703: <input type=button onClick="javascript:groupsearch()" value="Group Search">
704: <input type=button onClick="javascript:groupimport();" value="Group Import">
705: after selected
706: <hr>
707: <input type=text size=20 name=importmap>
708: <input type=button
709: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
710: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
711: <input type=submit name="discard" value="Discard Selected">
712: <input type=submit name="clear" value="Clear All">
713: <input type=button onClick="javascript:viewimport()" value="View">
714:
715: </td><td> </td><td bgcolor="#FFFFCC">
716:
717: <input type=button onClick=
718: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
719: <input type=button onClick=
720: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
721: after selected
722: <hr><input type=button onClick="javascript:viewtarget()" value="View">
723: </td></tr>
724:
725: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
726: $importwindow
727: </select>
728: </td>
729: <td bgcolor="#FFFFAA" align="center">
730: Cut selected<br>
731: <input type=submit name=cut value='<<<'><p>
732: <hr>
733: Copy selected<br>
734: <input type=submit name=copy value='<--'><p>
735: <hr>
736: Paste after selected<br>
737: <input type=submit name=paste value='-->'>
738: </td>
739: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
740: $targetwindow
741: </select>
742: </table>
743: <input type=hidden name=importdetail value="">
744: <input type=hidden name=curimpdetail value="$importdetail">
745: <input type=hidden name=targetdetail value="$targetdetail">
746: <input type=hidden name=impfortarget value="0">
747: </form>
748: </body></html>
749: ENDSMPHEAD
750: }
751:
752: # ----------------------------------------------------------------- No such dir
753: sub nodir {
754: my ($r,$dir)=@_;
755: $dir=~s/^\/home\/\w+\/public\_html//;
756: $r->print(<<ENDNODIR);
757: <html>
758: <body bgcolor='#FFFFFF'>
759: <h1>No such directory: $dir</h1>
760: </body>
761: </html>
762: ENDNODIR
763: }
764:
765: # ---------------------------------------------------------------- View Handler
766:
767: sub viewmap {
768: my ($r,$url,$adv,$errtext)=@_;
769: $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
770: if ($errtext) {
771: $r->print($errtext.'<hr>');
772: }
773: my $idx=0;
774: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
775: if (defined($_)) {
776: $idx++;
777: my ($title,$url)=split(/\:/,$_);
778: $title=~s/\&colon\;/\:/g;
779: $url=~s/\&colon\;/\:/g;
780: unless ($title) { $title=(split(/\//,$url))[-1] };
781: unless ($title) { $title='<i>Empty</i>'; }
782: if ($url) {
783: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
784: }
785: $r->print(&Apache::lonratsrv::qtescape($title));
786: if ($url) { $r->print('</a>'); }
787: $r->print('<br>');
788: }
789: }
790: $r->print('</body></html>');
791: }
792:
793: # ================================================================ Main Handler
794:
795: sub handler {
796: my $r=shift;
797: $r->content_type('text/html');
798: $r->send_http_header;
799:
800: return OK if $r->header_only;
801:
802: my $url=$r->uri;
803: my $fn=&Apache::lonnet::filelocation('',$url);
804:
805: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
806: unless (-e $dir) {
807: &nodir($r,$dir);
808: return OK;
809: }
810:
811: # ------------------------------------------- Determine which tools can be used
812: my $adv=0;
813:
814: unless ($ENV{'form.forcesmp'}) {
815: if ($ENV{'form.forceadv'}) {
816: $adv=1;
817: } elsif (my $fh=Apache::File->new($fn)) {
818: my $allmap=join('',<$fh>);
819: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
820: }
821: }
822:
823: my $errtext='';
824: my $fatal=0;
825:
826: # -------------------------------------------------------------------- Load map
827: ($errtext,$fatal)=&mapread($fn,$errtext);
828:
829: if ($fatal==1) { $adv=1; }
830:
831: # ----------------------------------- adv==1 now means "graphical MUST be used"
832:
833: if ($ENV{'form.forceadv'}) {
834: &ratedt($r,$url);
835: } elsif ($ENV{'form.forcesmp'}) {
836: &smpedt($r,$url,$errtext);
837: } else {
838: &viewmap($r,$url,$adv,$errtext);
839: }
840: return OK;
841: }
842:
843: 1;
844: __END__
845:
846:
847:
848:
849:
850:
851:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>