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