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