1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.29 2002/05/25 18:50:46 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=
544: '<option value="-1"> ---- Import and Paste Area ---- </option>'.
545: join("\n",map {
546: $idx++;
547: if ($_) {
548: my ($name,$url)=split(/\=/,$_);
549: unless ($name) { $name=(split(/\//,$url))[-1]; }
550: unless ($name) { $name='EMPTY'; }
551: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
552: '</option>';
553: }
554: } split(/\&/,$importdetail));
555:
556: $idx=0;
557: my $targetwindow=
558: '<option value="0"> ------- Target Edit Map ------- </option>'.
559: join("\n",map {
560: my ($name,$url)=split(/\:/,$resources[$_]);
561: unless ($name) { $name=(split(/\//,$url))[-1]; }
562: unless ($name) { $name='EMPTY'; }
563: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
564: &Apache::lonnet::escape($url);
565: $idx++;
566: '<option value="'.$idx.'">'.$name.'</option>';
567: } @order);
568:
569: # ----------------------------------------------------- Start simple RAT screen
570: $r->print(<<ENDSMPHEAD);
571: <html>
572: <head>
573: <script>
574: var srch;
575: var srchflag=-1; // 1 means currently open
576: // 0 means closed (but has been open)
577: // -1 means never yet opened/defined
578: var srchmode='';
579:
580: var idx;
581: var idxflag=-1; // 1 means currently open
582: // 0 means closed (but has been open)
583: // -1 means never yet opened/defined
584: var idxmode='';
585:
586: // ------------------------------------------------------ Clears indexer window
587: function idxclear() {
588: idx.document.clear();
589: }
590:
591: // ------------------------------------------------------- Clears search window
592: function srchclear() {
593: srch.document.clear();
594: }
595:
596: // ------------------------------------------------------ Closes indexer window
597: function idxclose() {
598: if (idx && !idx.closed) {
599: idxflag=0;
600: idx.close();
601: }
602: }
603:
604: // ------------------------------------------------------- Closes search window
605: function srchclose() {
606: if (srch && !srch.closed) {
607: srchflag=0;
608: srch.close();
609: }
610: }
611:
612: // -------------------------------------------------------- Open indexer window
613: function idxopen(mode) {
614: var options="scrollbars=1,resizable=1,menubar=0";
615: idxmode=mode;
616: idxflag=1;
617: idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
618: idx.focus();
619: }
620:
621: // --------------------------------------------------------- Open search window
622: function srchopen(mode) {
623: var options="scrollbars=1,resizable=1,menubar=0";
624: srchmode=mode;
625: srchflag=1;
626: srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
627: srch.focus();
628: }
629: // ----------------------------------------------------- launch indexer browser
630: function groupsearch() {
631: srchcheck('groupsearch');
632: }
633:
634: function groupimport() {
635: idxcheck('groupimport');
636: }
637: // ------------------------------------------------------- Do srch status check
638: function srchcheck(mode) {
639: if (!srch || srch.closed || srchmode!=mode) {
640: srchopen(mode);
641: }
642: srch.focus();
643: }
644:
645: // -------------------------------------------------------- Do idx status check
646: function idxcheck(mode) {
647: if (!idx || idx.closed || idxmode!=mode) {
648: idxopen(mode);
649: }
650: idx.focus();
651: }
652:
653:
654: var editbrowser;
655: function openbrowser(formname,elementname,only,omit) {
656: var url = '/res/?';
657: if (editbrowser == null) {
658: url += 'launch=1&';
659: }
660: url += 'catalogmode=interactive&';
661: url += 'mode=edit&';
662: url += 'form=' + formname + '&';
663: if (only != null) {
664: url += 'only=' + only + '&';
665: }
666: if (omit != null) {
667: url += 'omit=' + omit + '&';
668: }
669: url += 'element=' + elementname + '';
670: var title = 'Browser';
671: var options = 'scrollbars=1,resizable=1,menubar=0';
672: options += ',width=700,height=600';
673: editbrowser = open(url,title,options,'1');
674: editbrowser.focus();
675: }
676:
677: function openview(entry) {
678: var url=unescape((entry.split('='))[1]);
679: var parts=new Array;
680: parts=url.split(':');
681: url=parts.join(':');
682: if (url) { open(url,'cat'); }
683: }
684:
685: function viewtarget() {
686: openview((document.forms.simpleedit.targetdetail.value.split('&'))
687: [document.forms.simpleedit.target.selectedIndex+1]);
688: }
689:
690: function viewimport() {
691: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
692: [document.forms.simpleedit.importsel.selectedIndex+1]);
693: }
694:
695: </script>
696: </head>
697: <body bgcolor='#FFFFFF'>
698: $buttons
699: <font color=red>$errtext</font>
700: <h1>$url</h1>
701: <form name=simpleedit method=post>
702: <input type=hidden name=forcesmp value=1>
703: <table>
704: <tr><th width="40%">Import</th>
705: <th> </th>
706: <th width="40%">Target</th></tr>
707: <tr><td bgcolor="#FFFFCC">
708: <input type=button onClick="javascript:groupsearch()" value="Group Search">
709: <input type=button onClick="javascript:groupimport();" value="Group Import">
710: after selected
711: <hr>
712: <input type=text size=20 name=importmap>
713: <input type=button
714: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
715: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
716: <input type=submit name="discard" value="Discard Selected">
717: <input type=submit name="clear" value="Clear All">
718: <input type=button onClick="javascript:viewimport()" value="View">
719:
720: </td><td> </td><td bgcolor="#FFFFCC">
721:
722: <input type=button onClick=
723: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
724: <input type=button onClick=
725: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
726: after selected
727: <hr><input type=button onClick="javascript:viewtarget()" value="View">
728: </td></tr>
729:
730: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
731: $importwindow
732: </select>
733: </td>
734: <td bgcolor="#FFFFAA" align="center">
735: Cut selected<br>
736: <input type=submit name=cut value='<<<'><p>
737: <hr>
738: Copy selected<br>
739: <input type=submit name=copy value='<--'><p>
740: <hr>
741: Paste after selected<br>
742: <input type=submit name=paste value='-->'>
743: </td>
744: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
745: $targetwindow
746: </select>
747: </table>
748: <input type=hidden name=importdetail value="">
749: <input type=hidden name=curimpdetail value="$importdetail">
750: <input type=hidden name=targetdetail value="$targetdetail">
751: <input type=hidden name=impfortarget value="0">
752: </form>
753: </body></html>
754: ENDSMPHEAD
755: }
756:
757: # ----------------------------------------------------------------- No such dir
758: sub nodir {
759: my ($r,$dir)=@_;
760: $dir=~s/^\/home\/\w+\/public\_html//;
761: $r->print(<<ENDNODIR);
762: <html>
763: <body bgcolor='#FFFFFF'>
764: <h1>No such directory: $dir</h1>
765: </body>
766: </html>
767: ENDNODIR
768: }
769:
770: # ---------------------------------------------------------------- View Handler
771:
772: sub viewmap {
773: my ($r,$url,$adv,$errtext)=@_;
774: $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
775: if ($errtext) {
776: $r->print($errtext.'<hr>');
777: }
778: my $idx=0;
779: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
780: if (defined($_)) {
781: $idx++;
782: my ($title,$url)=split(/\:/,$_);
783: $title=~s/\&colon\;/\:/g;
784: $url=~s/\&colon\;/\:/g;
785: unless ($title) { $title=(split(/\//,$url))[-1] };
786: unless ($title) { $title='<i>Empty</i>'; }
787: if ($url) {
788: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
789: }
790: $r->print(&Apache::lonratsrv::qtescape($title));
791: if ($url) { $r->print('</a>'); }
792: $r->print('<br>');
793: }
794: }
795: $r->print('</body></html>');
796: }
797:
798: # ================================================================ Main Handler
799:
800: sub handler {
801: my $r=shift;
802: $r->content_type('text/html');
803: $r->send_http_header;
804:
805: return OK if $r->header_only;
806:
807: my $url=$r->uri;
808: my $fn=&Apache::lonnet::filelocation('',$url);
809:
810: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
811: unless (-e $dir) {
812: &nodir($r,$dir);
813: return OK;
814: }
815:
816: # ------------------------------------------- Determine which tools can be used
817: my $adv=0;
818:
819: unless ($ENV{'form.forcesmp'}) {
820: if ($ENV{'form.forceadv'}) {
821: $adv=1;
822: } elsif (my $fh=Apache::File->new($fn)) {
823: my $allmap=join('',<$fh>);
824: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
825: }
826: }
827:
828: my $errtext='';
829: my $fatal=0;
830:
831: # -------------------------------------------------------------------- Load map
832: ($errtext,$fatal)=&mapread($fn,$errtext);
833:
834: if ($fatal==1) { $adv=1; }
835:
836: # ----------------------------------- adv==1 now means "graphical MUST be used"
837:
838: if ($ENV{'form.forceadv'}) {
839: &ratedt($r,$url);
840: } elsif ($ENV{'form.forcesmp'}) {
841: &smpedt($r,$url,$errtext);
842: } else {
843: &viewmap($r,$url,$adv,$errtext);
844: }
845: return OK;
846: }
847:
848: 1;
849: __END__
850:
851:
852:
853:
854:
855:
856:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>