Annotation of rat/lonratedt.pm, revision 1.35
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.35 ! www 4: # $Id: lonratedt.pm,v 1.34 2002/08/31 00:42:30 www Exp $
1.5 www 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: #
1.1 www 28: # (TeX Content Handler
29: #
30: # 05/29/00,05/30 Gerd Kortemeyer)
1.4 www 31: # 7/1,6/30 Gerd Kortemeyer
1.1 www 32:
33: package Apache::lonratedt;
34:
35: use strict;
36: use Apache::Constants qw(:common);
1.3 www 37: use Apache::lonnet;
1.7 www 38: use Apache::lonratsrv;
1.30 www 39: use Apache::lonsequence;
1.34 www 40: use Apache::loncommon;
41: use File::Copy;
1.1 www 42:
1.33 www 43: use vars qw(@order @resources);
1.8 www 44:
45:
46: # Mapread read maps into global arrays @links and @resources, determines status
1.10 www 47: # sets @order - pointer to resources in right order
48: # sets @resources - array with the resources with correct idx
49: #
1.8 www 50: sub mapread {
51: my $fn=shift;
52:
1.10 www 53: my @links;
1.8 www 54: undef @links;
55: undef @resources;
1.10 www 56: undef @order;
1.23 www 57: @resources=('');
58: @order=();
1.8 www 59:
60: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
61: if ($errtext) { return ($errtext,2); }
62:
1.9 www 63: # -------------------------------------------------------------------- Read map
1.8 www 64: foreach (split(/\<\&\>/,$outtext)) {
1.9 www 65: my ($command,$number,$content)=split(/\<\:\>/,$_);
1.8 www 66: if ($command eq 'objcont') {
1.9 www 67: $resources[$number]=$content;
1.8 www 68: }
69: if ($command eq 'objlinks') {
1.9 www 70: $links[$number]=$content;
1.31 www 71: }
72: if ($command eq 'objparms') {
73: return('Map has resource parameters. Use advanced editor.',1);
1.9 www 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]))) {
1.8 www 86: return
1.10 www 87: ('Map has branchings. Use advanced editor.',1);
1.8 www 88: }
1.9 www 89: $starters[$start]=1;
90: $endings[$end]=1;
91: if ($cond) {
1.8 www 92: return
1.10 www 93: ('Map has conditions. Use advanced editor.',1);
1.8 www 94: }
95: }
96:
97: }
1.23 www 98: for (my $i=1; $i<=$#resources; $i++) {
1.10 www 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: }
1.8 www 133: return $errtext;
134: }
135:
1.16 www 136: # ---------------------------------------------- Read a map as well as possible
1.28 www 137: # Also used by the sequence handler
138: # Call lonsequence::attemptread to read from resource space
139: #
1.16 www 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:
1.17 www 164: my @objsort=();
165: undef @objsort;
1.16 www 166:
1.17 www 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: }
1.16 www 182:
1.17 www 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
1.16 www 224:
1.17 www 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;
1.16 www 247: }
248:
1.3 www 249: # --------------------------------------------------------- Build up RAT screen
250: sub ratedt {
251: my ($r,$url)=@_;
1.1 www 252: $r->print(<<ENDDOCUMENT);
253:
254: <html>
1.2 harris41 255: <head>
256: <script language="JavaScript">
257: var flag=0;
258: </script>
259: </head>
1.1 www 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
1.3 www 268: }
269:
1.8 www 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:
1.20 www 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(/\=/,$_);
1.21 www 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: }
1.20 www 305: }
306: }
1.23 www 307: my @oldorder=splice(@order,$after);
308: @order=(@order,@insertorder,@oldorder);
1.21 www 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[$_]);
1.22 www 317: if ($url=~/http\&colon\:\/\//) { $ext='true'; }
1.21 www 318: $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
319: }
1.23 www 320: my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
321: $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
1.33 www 322: if ($#order==0) {
323: $resources[$#resources+1]='::false';
324: $order[1]=$#resources;
325: }
1.21 www 326: my ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
327: $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
1.20 www 328: }
329:
1.22 www 330: # ------------------------------------------------------------------- Store map
331:
332: sub storemap {
1.34 www 333: my $realfn=shift;
1.35 ! www 334: my $fn=$realfn;
! 335: # unless this is forced to work from the original file, use a temporary file
! 336: # instead
! 337: unless (shift) {
! 338: $fn=$realfn.'.tmp';
! 339: unless (-e $fn) {
! 340: copy($realfn,$fn);
! 341: }
1.34 www 342: }
1.35 ! www 343: # store data either into tmp or real file
1.22 www 344: &startfinish();
345: my $output='graphdef<:>no';
346: my $k=1;
347: for (my $i=0; $i<=$#order; $i++) {
348: if (defined($resources[$order[$i]])) {
349: $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
350: }
351: if (defined($order[$i+1])) {
352: if (defined($resources[$order[$i+1]])) {
353: $output.='<&>objlinks<:>'.$k.'<:>'.
354: $order[$i].':'.$order[$i+1].':0';
355: $k++;
356: }
357: }
358: }
1.23 www 359: $output=~s/http\&colon\;\/\///g;
1.22 www 360: $ENV{'form.output'}=$output;
361: return
362: &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
363: }
364:
1.32 www 365: sub editscript {
366: my $mode=shift;
367: return(<<ENDSCRIPT);
368: var srch;
369: var srchflag=-1; // 1 means currently open
370: // 0 means closed (but has been open)
371: // -1 means never yet opened/defined
372: var srchmode='';
373:
374: var idx;
375: var idxflag=-1; // 1 means currently open
376: // 0 means closed (but has been open)
377: // -1 means never yet opened/defined
378: var idxmode='';
379:
380: // ------------------------------------------------------ Clears indexer window
381: function idxclear() {
382: idx.document.clear();
383: }
384:
385: // ------------------------------------------------------- Clears search window
386: function srchclear() {
387: srch.document.clear();
388: }
389:
390: // ------------------------------------------------------ Closes indexer window
391: function idxclose() {
392: if (idx && !idx.closed) {
393: idxflag=0;
394: idx.close();
395: }
396: }
397:
398: // ------------------------------------------------------- Closes search window
399: function srchclose() {
400: if (srch && !srch.closed) {
401: srchflag=0;
402: srch.close();
403: }
404: }
405:
406: // -------------------------------------------------------- Open indexer window
407: function idxopen(mode) {
408: var options="scrollbars=1,resizable=1,menubar=0";
409: idxmode=mode;
410: idxflag=1;
411: idx=open("/res/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
412: idx.focus();
413: }
414:
415: // --------------------------------------------------------- Open search window
416: function srchopen(mode) {
417: var options="scrollbars=1,resizable=1,menubar=0";
418: srchmode=mode;
419: srchflag=1;
420: srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
421: srch.focus();
422: }
423: // ----------------------------------------------------- launch indexer browser
424: function groupsearch() {
425: srchcheck('groupsearch');
426: }
427:
428: function groupimport() {
429: idxcheck('groupimport');
430: }
431: // ------------------------------------------------------- Do srch status check
432: function srchcheck(mode) {
433: if (!srch || srch.closed || srchmode!=mode) {
434: srchopen(mode);
435: }
436: srch.focus();
437: }
438:
439: // -------------------------------------------------------- Do idx status check
440: function idxcheck(mode) {
441: if (!idx || idx.closed || idxmode!=mode) {
442: idxopen(mode);
443: }
444: idx.focus();
445: }
446:
447:
448: var editbrowser;
449: function openbrowser(formname,elementname,only,omit) {
450: var url = '/res/?';
451: if (editbrowser == null) {
452: url += 'launch=1&';
453: }
454: url += 'catalogmode=interactive&';
455: url += 'mode=edit&';
456: url += 'form=' + formname + '&';
457: if (only != null) {
458: url += 'only=' + only + '&';
459: }
460: if (omit != null) {
461: url += 'omit=' + omit + '&';
462: }
463: url += 'element=' + elementname + '';
464: var title = 'Browser';
465: var options = 'scrollbars=1,resizable=1,menubar=0';
466: options += ',width=700,height=600';
467: editbrowser = open(url,title,options,'1');
468: editbrowser.focus();
469: }
470: ENDSCRIPT
471: }
1.20 www 472: # ------------------------------------------------------- Simple edit processor
473:
1.3 www 474: sub smpedt {
1.22 www 475: my ($r,$url,$errtext)=@_;
1.8 www 476: my $buttons=&buttons(2);
1.34 www 477: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
478: my $targetmsg='';
479: if ($ENV{'form.save'}) {
480: $targetmsg='<b>Saving ...</b><br>';
481: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
482: unlink($tmpfn);
1.35 ! www 483: my ($errtext,$fatal)=
! 484: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.34 www 485: }
486: if ($ENV{'form.revert'}) {
487: $targetmsg='<b>Reverting ...</b><br>';
488: unlink($tmpfn);
1.35 ! www 489: my ($errtext,$fatal)=
! 490: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.34 www 491: }
492: if (-e $tmpfn) {
493: $targetmsg=
494: '<b><font color="red">You are working with an unsaved version of your map.</font></b><br>';
495: my ($errtext,$fatal)=&mapread($tmpfn,'');
496: }
1.12 www 497: # ---------------------------------------------------------- Process form input
498:
499: my @importselect=();
500: my @targetselect=();
501: undef @importselect;
502: undef @targetselect;
1.27 www 503: if (defined($ENV{'form.importsel'})) {
504: if (ref($ENV{'form.importsel'})) {
505: @importselect=sort(@{$ENV{'form.importsel'}});
1.12 www 506: } else {
1.27 www 507: @importselect=($ENV{'form.importsel'});
1.12 www 508: }
509: }
510: if (defined($ENV{'form.target'})) {
511: if (ref($ENV{'form.target'})) {
1.25 www 512: @targetselect=sort(@{$ENV{'form.target'}});
1.12 www 513: } else {
514: @targetselect=($ENV{'form.target'});
515: }
516: }
1.13 www 517: # ============================================================ Process commands
1.12 www 518:
1.14 www 519: my $targetdetail=$ENV{'form.targetdetail'};
520: my $importdetail=$ENV{'form.curimpdetail'};
1.13 www 521:
522: # ---------------------------------------------------- Importing from groupsort
1.16 www 523: if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
1.13 www 524:
1.14 www 525: $importdetail='';
1.13 www 526: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
527:
528: my $lastsel;
529:
530: if (defined($importselect[-1])) {
531: $lastsel=$importselect[-1];
532: } else {
533: $lastsel=$#curimport;
534: }
535:
536: for (my $i=0;$i<=$lastsel;$i++) {
537: my ($name,$url)=split(/\=/,$curimport[$i]);
538: if ($url) {
1.18 www 539: $importdetail.='&'.$name.'='.$url;
1.13 www 540: }
541: }
542:
543: $importdetail.='&'.$ENV{'form.importdetail'};
544:
545: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
546: my ($name,$url)=split(/\=/,$curimport[$i]);
547: if ($url) {
1.18 www 548: $importdetail.='&'.$name.'='.$url;
1.13 www 549: }
550: }
551: $importdetail=~s/\&+/\&/g;
552: $importdetail=~s/^\&//;
553:
1.14 www 554: # ------------------------------------------------------------------- Clear all
555: } elsif ($ENV{'form.clear'}) {
556: $importdetail='';
557: # ------------------------------------------------------------ Discard selected
558: } elsif ($ENV{'form.discard'}) {
559: $importdetail='';
560: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
561: foreach (@importselect) {
562: $curimport[$_]='';
563: }
564: for (my $i=0;$i<=$#curimport;$i++) {
565: my ($name,$url)=split(/\=/,$curimport[$i]);
566: if ($url) {
1.18 www 567: $importdetail.='&'.$name.'='.$url;
1.14 www 568: }
569: }
1.17 www 570: # --------------------------------------------------------- Loading another map
571: } elsif ($ENV{'form.loadmap'}) {
572: $importdetail='';
573: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
574:
575: my $lastsel;
576:
577: if (defined($importselect[-1])) {
578: $lastsel=$importselect[-1];
579: } else {
580: $lastsel=$#curimport;
581: }
582:
583: for (my $i=0;$i<=$lastsel;$i++) {
584: my ($name,$url)=split(/\=/,$curimport[$i]);
585: if ($url) {
1.18 www 586: $importdetail.='&'.$name.'='.$url;
1.17 www 587: }
588: }
589:
590: foreach (
1.30 www 591: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.17 www 592: my ($name,$url)=split(/\:/,$_);
593: if ($url) {
594: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
595: &Apache::lonnet::escape($url);
596: }
597: }
598:
599: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
600: my ($name,$url)=split(/\=/,$curimport[$i]);
601: if ($url) {
1.18 www 602: $importdetail.='&'.$name.'='.$url;
1.17 www 603: }
604: }
605: $importdetail=~s/\&+/\&/g;
606: $importdetail=~s/^\&//;
607:
1.20 www 608: # ------------------------------------------------ Groupimport/search to target
609: } elsif ($ENV{'form.importdetail'}) {
610: my $lastsel;
611: if (defined($targetselect[-1])) {
612: $lastsel=$targetselect[-1];
613: } else {
1.23 www 614: $lastsel=$#order+1;
1.20 www 615: }
1.21 www 616: &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
1.22 www 617: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 618: # ------------------------------------------------------------------------- Cut
1.25 www 619: } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
620: $importdetail='';
621: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
622:
623: my $lastsel;
624:
625: if (defined($importselect[-1])) {
626: $lastsel=$importselect[-1];
627: } else {
628: $lastsel=$#curimport;
629: }
630:
631: for (my $i=0;$i<=$lastsel;$i++) {
632: my ($name,$url)=split(/\=/,$curimport[$i]);
633: if ($url) {
634: $importdetail.='&'.$name.'='.$url;
635: }
636: }
637:
638: foreach (@targetselect) {
639: my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
640: if ($url) {
641: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
642: &Apache::lonnet::escape($url);
643: }
644: }
645:
646: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
647: my ($name,$url)=split(/\=/,$curimport[$i]);
648: if ($url) {
649: $importdetail.='&'.$name.'='.$url;
650: }
651: }
652: $importdetail=~s/\&+/\&/g;
653: $importdetail=~s/^\&//;
654:
655: if ($ENV{'form.cut'}) {
656: my @neworder=();
657: for (my $i=0;$i<=$#order;$i++) {
658: my $include=1;
659: foreach (@targetselect) {
660: if ($_-1==$i) { $include=0; }
661: }
662: if ($include) { $neworder[$#neworder+1]=$order[$i]; }
663: }
664: @order=@neworder;
665: &storemap(&Apache::lonnet::filelocation('',$url));
666: }
667:
1.20 www 668: # ----------------------------------------------------------------------- Paste
669: } elsif ($ENV{'form.paste'}) {
1.24 www 670: my $lastsel;
671: if (defined($targetselect[-1])) {
672: $lastsel=$targetselect[-1];
673: } else {
674: $lastsel=$#order+1;
675: }
676: my @newsequence;
677: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
678: foreach (@importselect) {
679: $newsequence[$#newsequence+1]=$curimport[$_];
680: }
681: &pastetarget($lastsel,@newsequence);
682: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 683: # ------------------------------------------------
1.13 www 684: }
1.12 www 685: # ------------------------------------------------------------ Assemble windows
1.20 www 686:
1.13 www 687: my $idx=-1;
1.34 www 688: $importdetail='&'.$importdetail;
689: $importdetail=~s/^\&+/\&/;
1.29 www 690: my $importwindow=
691: '<option value="-1"> ---- Import and Paste Area ---- </option>'.
692: join("\n",map {
1.13 www 693: $idx++;
694: if ($_) {
1.15 www 695: my ($name,$url)=split(/\=/,$_);
696: unless ($name) { $name=(split(/\//,$url))[-1]; }
697: unless ($name) { $name='EMPTY'; }
1.13 www 698: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
699: '</option>';
700: }
701: } split(/\&/,$importdetail));
1.12 www 702:
1.13 www 703: $idx=0;
1.29 www 704: my $targetwindow=
705: '<option value="0"> ------- Target Edit Map ------- </option>'.
706: join("\n",map {
1.13 www 707: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 708: unless ($name) { $name=(split(/\//,$url))[-1]; }
709: unless ($name) { $name='EMPTY'; }
1.13 www 710: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
711: &Apache::lonnet::escape($url);
712: $idx++;
1.20 www 713: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 714: } @order);
715:
1.8 www 716: # ----------------------------------------------------- Start simple RAT screen
1.32 www 717: my $editscript=&editscript('simple');
1.34 www 718: my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.3 www 719: $r->print(<<ENDSMPHEAD);
720: <html>
1.6 www 721: <head>
722: <script>
1.15 www 723:
1.32 www 724: $editscript
1.19 www 725:
726: function openview(entry) {
727: var url=unescape((entry.split('='))[1]);
1.20 www 728: var parts=new Array;
729: parts=url.split(':');
730: url=parts.join(':');
1.19 www 731: if (url) { open(url,'cat'); }
732: }
733:
734: function viewtarget() {
735: openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34 www 736: [document.forms.simpleedit.target.selectedIndex]);
1.19 www 737: }
738:
739: function viewimport() {
740: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34 www 741: [document.forms.simpleedit.importsel.selectedIndex]);
1.19 www 742: }
743:
1.6 www 744: </script>
745: </head>
1.34 www 746: $bodytag
1.8 www 747: $buttons
1.7 www 748: <font color=red>$errtext</font>
1.29 www 749: <h1>$url</h1>
1.13 www 750: <form name=simpleedit method=post>
1.11 www 751: <input type=hidden name=forcesmp value=1>
752: <table>
1.12 www 753: <tr><th width="40%">Import</th>
754: <th> </th>
755: <th width="40%">Target</th></tr>
756: <tr><td bgcolor="#FFFFCC">
757: <input type=button onClick="javascript:groupsearch()" value="Group Search">
1.13 www 758: <input type=button onClick="javascript:groupimport();" value="Group Import">
1.15 www 759: after selected
1.14 www 760: <hr>
1.15 www 761: <input type=text size=20 name=importmap>
762: <input type=button
763: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
764: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
1.14 www 765: <input type=submit name="discard" value="Discard Selected">
766: <input type=submit name="clear" value="Clear All">
1.12 www 767: <input type=button onClick="javascript:viewimport()" value="View">
1.16 www 768:
1.12 www 769: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 770:
771: <input type=button onClick=
772: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
773: <input type=button onClick=
774: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
775: after selected
1.34 www 776: <hr>$targetmsg
777: <input type=submit name="revert" value="Revert to Last Saved">
778: <input type=submit name="save" value="Save">
779: <input type=button onClick="javascript:viewtarget()" value="View">
1.12 www 780: </td></tr>
1.16 www 781:
1.27 www 782: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12 www 783: $importwindow
784: </select>
1.11 www 785: </td>
1.12 www 786: <td bgcolor="#FFFFAA" align="center">
787: Cut selected<br>
1.11 www 788: <input type=submit name=cut value='<<<'><p>
1.12 www 789: <hr>
1.25 www 790: Copy selected<br>
791: <input type=submit name=copy value='<--'><p>
792: <hr>
1.12 www 793: Paste after selected<br>
1.25 www 794: <input type=submit name=paste value='-->'>
1.11 www 795: </td>
1.27 www 796: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11 www 797: $targetwindow
798: </select>
1.12 www 799: </table>
1.13 www 800: <input type=hidden name=importdetail value="">
801: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 802: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 803: <input type=hidden name=impfortarget value="0">
1.12 www 804: </form>
805: </body></html>
1.3 www 806: ENDSMPHEAD
807: }
808:
1.11 www 809: # ----------------------------------------------------------------- No such dir
1.4 www 810: sub nodir {
811: my ($r,$dir)=@_;
812: $dir=~s/^\/home\/\w+\/public\_html//;
813: $r->print(<<ENDNODIR);
814: <html>
815: <body bgcolor='#FFFFFF'>
816: <h1>No such directory: $dir</h1>
817: </body>
818: </html>
819: ENDNODIR
820: }
821:
1.8 www 822: # ---------------------------------------------------------------- View Handler
823:
824: sub viewmap {
1.17 www 825: my ($r,$url,$adv,$errtext)=@_;
1.34 www 826: $r->print('<html>'.
827: &Apache::loncommon::bodytag('Edit Content of a Map').
828: &buttons($adv));
1.10 www 829: if ($errtext) {
830: $r->print($errtext.'<hr>');
831: }
1.26 www 832: my $idx=0;
1.34 www 833: $r->print('<h1>'.$url.'</h1>');
1.17 www 834: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 835: if (defined($_)) {
1.26 www 836: $idx++;
1.9 www 837: my ($title,$url)=split(/\:/,$_);
838: $title=~s/\&colon\;/\:/g;
839: $url=~s/\&colon\;/\:/g;
1.15 www 840: unless ($title) { $title=(split(/\//,$url))[-1] };
841: unless ($title) { $title='<i>Empty</i>'; }
1.9 www 842: if ($url) {
843: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
844: }
845: $r->print(&Apache::lonratsrv::qtescape($title));
846: if ($url) { $r->print('</a>'); }
1.28 www 847: $r->print('<br>');
1.9 www 848: }
849: }
1.8 www 850: $r->print('</body></html>');
851: }
852:
1.3 www 853: # ================================================================ Main Handler
854:
855: sub handler {
856: my $r=shift;
857: $r->content_type('text/html');
858: $r->send_http_header;
859:
860: return OK if $r->header_only;
861:
862: my $url=$r->uri;
863: my $fn=&Apache::lonnet::filelocation('',$url);
864:
1.4 www 865: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
866: unless (-e $dir) {
867: &nodir($r,$dir);
868: return OK;
869: }
1.8 www 870:
871: # ------------------------------------------- Determine which tools can be used
1.3 www 872: my $adv=0;
873:
874: unless ($ENV{'form.forcesmp'}) {
875: if ($ENV{'form.forceadv'}) {
876: $adv=1;
877: } elsif (my $fh=Apache::File->new($fn)) {
878: my $allmap=join('',<$fh>);
879: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
880: }
881: }
882:
1.8 www 883: my $errtext='';
884: my $fatal=0;
885:
886: # -------------------------------------------------------------------- Load map
887: ($errtext,$fatal)=&mapread($fn,$errtext);
888:
889: if ($fatal==1) { $adv=1; }
890:
891: # ----------------------------------- adv==1 now means "graphical MUST be used"
892:
893: if ($ENV{'form.forceadv'}) {
1.3 www 894: &ratedt($r,$url);
1.8 www 895: } elsif ($ENV{'form.forcesmp'}) {
1.22 www 896: &smpedt($r,$url,$errtext);
1.3 www 897: } else {
1.17 www 898: &viewmap($r,$url,$adv,$errtext);
1.3 www 899: }
1.1 www 900: return OK;
901: }
902:
903: 1;
904: __END__
905:
906:
907:
908:
909:
910:
911:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>