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