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