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