Annotation of rat/lonratedt.pm, revision 1.57
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.57 ! www 4: # $Id: lonratedt.pm,v 1.56 2004/04/24 15:37: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.55 www 28:
1.1 www 29:
30: package Apache::lonratedt;
1.46 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::lonratedt: advanced resource assembly tool
37:
38: =head1 SYNOPSIS
39:
40: lonratedt provides the routines and the handler for the Advanced
41: Resource Assembly Tool (RAT), and ties the various pieces together
42: with Javascript.
43:
44: =head1 OVERVIEW
45:
46: =head2 Map Representation
47:
48: =begin latex
49:
50: %
51: \begin{figure}
52: \begin{center}\includegraphics[%
53: width=0.55\paperwidth,bb = 0 0 200 100, draft, type=eps]{Map_Example}\end{center}
54:
55:
56: \caption{\label{Map_In_Advanced_Editor}Example of a Map in the Advanced Editor}
57: \end{figure}
58: %
59: \begin{figure}
60: \begin{lyxcode}
61: <map>
62:
63: ~~<resource~id=\char`\"{}1\char`\"{}
64:
65: ~~~~src=\char`\"{}/res/msu/korte/phy231welcome.html\char`\"{}
66:
67: ~~~~type=\char`\"{}start\char`\"{}
68:
69: ~~~~title=\char`\"{}Start\char`\"{}>
70:
71: ~~~~</resource>
72:
73: ~~<resource~id=\char`\"{}2\char`\"{}
74:
75: ~~~~src=\char`\"{}\char`\"{}~type=\char`\"{}finish\char`\"{}
76:
77: ~~~~title=\char`\"{}Finish\char`\"{}>
78:
79: ~~~~</resource>
80:
81: ~~<resource~id=\char`\"{}6\char`\"{}
82:
83: ~~~~src=\char`\"{}/res/msu/korte/tests/units.problem\char`\"{}
84:
85: ~~~~type=\char`\"{}mandatory\char`\"{}
86:
87: ~~~~title=\char`\"{}Physical~Units~Test\char`\"{}>
88:
89: ~~~~</resource>
90:
91: ~~<resource~id=\char`\"{}9\char`\"{}
92:
93: ~~~~src=\char`\"{}/res/msu/korte/chapters/onedim.sequence\char`\"{}
94:
95: ~~~~title=\char`\"{}Motion~in~One~Dimension\char`\"{}>
96:
97: ~~~~</resource>
98:
99: ~~<resource~id=\char`\"{}11\char`\"{}
100:
101: ~~~~src=\char`\"{}/res/msu/bauer/bridges/units.sequence\char`\"{}
102:
103: ~~~~title=\char`\"{}Physical~Units~Refresher\char`\"{}>
104:
105: ~~~~</resource>
106:
107: ~~<condition~id=\char`\"{}19\char`\"{}
108:
109: ~~~~type=\char`\"{}stop\char`\"{}
110:
111: ~~~~value=\char`\"{}user.assessments{[}this./res/msu/korte/tests/units.problem{]}.status=solved\char`\"{}>
112:
113: ~~~~</condition>
114:
115: ~~<link~from=\char`\"{}1\char`\"{}~to=\char`\"{}6\char`\"{}></link>
116:
117: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}9\char`\"{}~condition=\char`\"{}19\char`\"{}></link>
118:
119: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}11\char`\"{}></link>
120:
121: ~~<link~from=\char`\"{}11\char`\"{}~to=\char`\"{}6\char`\"{}></link>
122:
123: ~~</map>
124: \end{lyxcode}
125:
126: \caption{\label{XML}XML for Map in Figure \ref{Map_In_Advanced_Editor}}
127: \end{figure}
128:
129: =end latex
130:
131: Fig. "XML for Map in Figure" shows the XML representation of the
132: resource map shown in Fig. "Example of a Map in the Advanced Editor",
133: which is the format in which maps are stored. In the figure, however,
134: additional graphical map layout information generated by the Advanced
135: Resource Assembly Tool is not displayed. This graphical information is
136: optional to re-generate the same graphical layout when the map is
137: brought up again in the Resource Assembly Tool, and is not needed for
138: any other system functionality.
139:
140: Maps can be generated by tools other than the Resource Assembly
141: Tool. In particular, an author might have some other representation of
142: a course sequence, which can be converted into a map using scripts. If
143: this map then were to be brought up in the Resource Assembly Tool, the
144: Tool would automatically generate a graphical layout for it. Each
145: entry of the map (resources, conditions and links) is stored in a
146: separate tag.
147:
148: Resources and conditionsX<conditions> have to have unique ID
149: numbers. These numbers are automatically generated by the Resource
150: Assembly Tool when the entry is first created, or added to the entries
151: when a map generated outside the Resource Assembly Tool is first
152: retrieved. They can also be assigned by custom scripts or added in by
153: hand.
154:
155: In the XML example, entry 1 is the start resource of the map. When
156: this map is accessed, the source (src) URL of this tag will be the
157: first resource rendered. Entry 2 is the finish resource of this
158: map. This resource will be the last resource in the sequence of
159: resources. Entry 6 is a problem resource with the given URL and title,
160: as well as the priority "mandatory". Entry 19 is a condition, which is
161: used by the link between entries 6, the problem, and 9, a
162: sequence. I<The final syntax for conditions has not yet been
163: determined.>
164:
165: =cut
1.1 www 166:
167: use strict;
168: use Apache::Constants qw(:common);
1.3 www 169: use Apache::lonnet;
1.7 www 170: use Apache::lonratsrv;
1.30 www 171: use Apache::lonsequence;
1.34 www 172: use Apache::loncommon;
1.47 www 173: use Apache::lonlocal;
1.34 www 174: use File::Copy;
1.1 www 175:
1.54 www 176: use vars qw(@order @resources @resparms);
1.8 www 177:
178:
179: # Mapread read maps into global arrays @links and @resources, determines status
1.10 www 180: # sets @order - pointer to resources in right order
181: # sets @resources - array with the resources with correct idx
182: #
1.8 www 183: sub mapread {
184: my $fn=shift;
185:
1.10 www 186: my @links;
1.8 www 187: undef @links;
188: undef @resources;
1.10 www 189: undef @order;
1.23 www 190: @resources=('');
191: @order=();
1.8 www 192:
193: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
194: if ($errtext) { return ($errtext,2); }
195:
1.9 www 196: # -------------------------------------------------------------------- Read map
1.8 www 197: foreach (split(/\<\&\>/,$outtext)) {
1.9 www 198: my ($command,$number,$content)=split(/\<\:\>/,$_);
1.8 www 199: if ($command eq 'objcont') {
1.9 www 200: $resources[$number]=$content;
1.8 www 201: }
202: if ($command eq 'objlinks') {
1.9 www 203: $links[$number]=$content;
1.31 www 204: }
205: if ($command eq 'objparms') {
1.55 www 206: if ($resparms[$number]) {
207: $resparms[$number].='&&&'.$content;
208: } else {
209: $resparms[$number]=$content;
210: }
1.9 www 211: }
212: }
213: # ------------------------------------------------------- Is this a linear map?
214: my @starters=();
215: my @endings=();
216: undef @starters;
217: undef @endings;
218:
219: foreach (@links) {
220: if (defined($_)) {
221: my ($start,$end,$cond)=split(/\:/,$_);
222: if ((defined($starters[$start])) || (defined($endings[$end]))) {
1.8 www 223: return
1.49 sakharuk 224: (&mt('Map has branchings. Use advanced editor.'),1);
1.8 www 225: }
1.9 www 226: $starters[$start]=1;
227: $endings[$end]=1;
228: if ($cond) {
1.8 www 229: return
1.49 sakharuk 230: (&mt('Map has conditions. Use advanced editor.'),1);
1.8 www 231: }
232: }
233:
234: }
1.23 www 235: for (my $i=1; $i<=$#resources; $i++) {
1.10 www 236: if (defined($resources[$i])) {
237: unless (($starters[$i]) || ($endings[$i])) {
238: return
1.49 sakharuk 239: (&mt('Map has unconnected resources. Use advanced editor.'),1);
1.10 www 240: }
241: }
242: }
1.38 www 243: # ---------------------------------------------- Did we just read an empty map?
244: if ($#resources<1) {
245: undef $resources[0];
246: $resources[1]=':::start';
247: $resources[2]=':::finish';
248: }
1.10 www 249: # -------------------------------------------------- This is a linear map, sort
250:
251: my $startidx=0;
252: my $endidx=0;
253: for (my $i=0; $i<=$#resources; $i++) {
254: if (defined($resources[$i])) {
255: my ($title,$url,$ext,$type)=split(/\:/,$resources[$i]);
256: if ($type eq 'start') { $startidx=$i; }
257: if ($type eq 'finish') { $endidx=$i; }
258: }
259: }
260: my $k=0;
261: my $currentidx=$startidx;
262: $order[$k]=$currentidx;
263: for (my $i=0; $i<=$#resources; $i++) {
264: foreach (@links) {
265: my ($start,$end)=split(/\:/,$_);
266: if ($start==$currentidx) {
267: $currentidx=$end;
268: $k++;
269: $order[$k]=$currentidx;
270: last;
271: }
272: }
273: if ($currentidx==$endidx) { last; }
274: }
1.8 www 275: return $errtext;
276: }
277:
1.16 www 278: # ---------------------------------------------- Read a map as well as possible
1.28 www 279: # Also used by the sequence handler
280: # Call lonsequence::attemptread to read from resource space
281: #
1.16 www 282: sub attemptread {
283: my $fn=shift;
284:
285: my @links;
286: undef @links;
287: my @theseres;
288: undef @theseres;
289:
290: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
291: if ($errtext) { return @theseres }
292:
293: # -------------------------------------------------------------------- Read map
294: foreach (split(/\<\&\>/,$outtext)) {
295: my ($command,$number,$content)=split(/\<\:\>/,$_);
296: if ($command eq 'objcont') {
297: $theseres[$number]=$content;
298: }
299: if ($command eq 'objlinks') {
300: $links[$number]=$content;
301: }
302: }
303:
304: # --------------------------------------------------------------- Sort, sort of
305:
1.17 www 306: my @objsort=();
307: undef @objsort;
1.16 www 308:
1.17 www 309: my @data1=();
310: my @data2=();
311: undef @data1;
312: undef @data2;
313:
314: my $k;
315: my $kj;
316: my $j;
317: my $ij;
318:
319: for ($k=1;$k<=$#theseres;$k++) {
320: if (defined($theseres[$k])) {
321: $objsort[$#objsort+1]=$k;
322: }
323: }
1.16 www 324:
1.17 www 325: for ($k=1;$k<=$#links;$k++) {
326: if (defined($links[$k])) {
327: @data1=split(/\:/,$links[$k]);
328: $kj=-1;
329: for (my $j=0;$j<=$#objsort;$j++) {
330: if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
331: $kj=$j;
332: }
333: }
334: if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
335: }
336: }
337: for ($k=0;$k<=$#objsort;$k++) {
338: for ($j=0;$j<=$#objsort;$j++) {
339: if ($k!=$j) {
340: @data1=split(/\:/,$objsort[$k]);
341: @data2=split(/\:/,$objsort[$j]);
342: my $dol=$#data1+1;
343: my $dtl=$#data2+1;
344: if ($dol+$dtl<1000) {
345: for ($kj=1;$kj<$dol;$kj++) {
346: if ($data1[$kj]==$data2[0]) {
347: for ($ij=1;$ij<$dtl;$ij++) {
348: $data1[$#data1+1]=$data2[$ij];
349: }
350: }
351: }
352: for ($kj=1;$kj<$dtl;$kj++) {
353: if ($data2[$kj]==$data1[0]) {
354: for ($ij=1;$ij<$dol;$ij++) {
355: $data2[$#data2+1]=$data1[$ij];
356: }
357: }
358: }
359: $objsort[$k]=join(':',@data1);
360: $objsort[$j]=join(':',@data2);
361: }
362: }
363: }
364: }
365: # ---------------------------------------------------------------- Now sort out
1.16 www 366:
1.17 www 367: @objsort=sort {
368: my @data1=split(/\:/,$a);
369: my @data2=split(/\:/,$b);
370: my $rvalue=0;
371: my $k;
372: for ($k=1;$k<=$#data1;$k++) {
373: if ($data1[$k]==$data2[0]) { $rvalue--; }
374: }
375: for ($k=1;$k<=$#data2;$k++) {
376: if ($data2[$k]==$data1[0]) { $rvalue++; }
377: }
378: if ($rvalue==0) { $rvalue=$#data2-$#data1; }
379: $rvalue;
380: } @objsort;
381:
382: my @outres=();
383: undef @outres;
384:
385: for ($k=0;$k<=$#objsort;$k++) {
386: $outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
387: }
388: return @outres;
1.16 www 389: }
390:
1.3 www 391: # --------------------------------------------------------- Build up RAT screen
392: sub ratedt {
393: my ($r,$url)=@_;
1.1 www 394: $r->print(<<ENDDOCUMENT);
395:
396: <html>
1.2 harris41 397: <head>
398: <script language="JavaScript">
399: var flag=0;
400: </script>
401: </head>
1.1 www 402: <frameset rows="1,50,*" border=0>
403: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
404: <frame name=code src="/adm/rat/code.html">
405: <frame name=mapout src="/adm/rat/map.html">
406: </frameset>
407: </html>
408:
409: ENDDOCUMENT
1.3 www 410: }
411:
1.8 www 412: # ---------------------------------------------------------------- Make buttons
413:
414: sub buttons {
415: my $adv=shift;
416: my $output='<form method=post>';
417: if ($adv==1) {
1.52 www 418: $output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
419: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
1.8 www 420: } else {
421: unless ($adv==2) {
1.52 www 422: $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
423: &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
1.8 www 424: }
1.52 www 425: $output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
426: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
1.8 www 427: }
428: return $output.'</form><hr>';
429: }
430:
1.20 www 431: # ----------------------------------------------------------- Paste into target
432: # modifies @order, @resources
433:
434: sub pastetarget {
435: my ($after,@which)=@_;
436: my @insertorder=();
437: foreach (@which) {
438: if (defined($_)) {
439: my ($name,$url)=split(/\=/,$_);
1.21 www 440: $name=&Apache::lonnet::unescape($name);
441: $url=&Apache::lonnet::unescape($url);
442: if ($url) {
443: my $idx=$#resources+1;
444: $insertorder[$#insertorder+1]=$idx;
445: my $ext='false';
446: if ($url=~/^http\:\/\//) { $ext='true'; }
447: $url=~s/\:/\:/g;
1.37 www 448: $name=~s/\:/\:/g;
1.21 www 449: $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
450: }
1.20 www 451: }
452: }
1.23 www 453: my @oldorder=splice(@order,$after);
454: @order=(@order,@insertorder,@oldorder);
1.21 www 455: }
456:
457: # ------------------------------------------------ Get start and finish correct
458: # modifies @resources
459:
460: sub startfinish {
1.43 www 461: # Remove all start and finish
1.21 www 462: foreach (@order) {
463: my ($name,$url,$ext)=split(/\:/,$resources[$_]);
1.22 www 464: if ($url=~/http\&colon\:\/\//) { $ext='true'; }
1.21 www 465: $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
466: }
1.43 www 467: # Garbage collection
468: my $stillchange=1;
469: while (($#order>1) && ($stillchange)) {
470: $stillchange=0;
471: for (my $i=0;$i<=$#order;$i++) {
472: my ($name,$url,$ext)=split(/\:/,$resources[$order[$i]]);
473: unless ($url) {
474: # Take out empty resource
475: for (my $j=$i+1;$j<=$#order;$j++) {
476: $order[$j-1]=$order[$j];
477: }
478: $#order--;
479: $stillchange=1;
480: last;
481: }
482: }
483: }
484: # Put in a start resource
1.23 www 485: my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
486: $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
1.43 www 487: # Make sure this has at least start and finish
1.33 www 488: if ($#order==0) {
489: $resources[$#resources+1]='::false';
490: $order[1]=$#resources;
491: }
1.43 www 492: # Make the last one a finish resource
1.42 www 493: ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
1.21 www 494: $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
1.20 www 495: }
496:
1.22 www 497: # ------------------------------------------------------------------- Store map
498:
499: sub storemap {
1.34 www 500: my $realfn=shift;
1.35 www 501: my $fn=$realfn;
502: # unless this is forced to work from the original file, use a temporary file
503: # instead
504: unless (shift) {
505: $fn=$realfn.'.tmp';
506: unless (-e $fn) {
507: copy($realfn,$fn);
508: }
1.34 www 509: }
1.35 www 510: # store data either into tmp or real file
1.22 www 511: &startfinish();
512: my $output='graphdef<:>no';
513: my $k=1;
514: for (my $i=0; $i<=$#order; $i++) {
515: if (defined($resources[$order[$i]])) {
516: $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
517: }
1.54 www 518: if (defined($resparms[$order[$i]])) {
1.55 www 519: foreach (split('&&&',$resparms[$order[$i]])) {
520: if ($_) {
521: $output.='<&>objparms<:>'.$order[$i].'<:>'.$_;
522: }
523: }
1.54 www 524: }
1.22 www 525: if (defined($order[$i+1])) {
526: if (defined($resources[$order[$i+1]])) {
527: $output.='<&>objlinks<:>'.$k.'<:>'.
528: $order[$i].':'.$order[$i+1].':0';
529: $k++;
530: }
531: }
532: }
1.23 www 533: $output=~s/http\&colon\;\/\///g;
1.22 www 534: $ENV{'form.output'}=$output;
535: return
536: &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
537: }
538:
1.56 www 539: # ------------------------------------------ Store and get parameters in global
540:
541: sub storeparameter {
542: my ($to,$name,$value,$ptype)=@_;
543: my $newentry='';
544: my $nametype='';
545: foreach (split('&&&',$resparms[$to])) {
546: my ($thistype,$thisname,$thisvalue)=split('___',$_);
547: if ($thisname) {
548: unless ($thisname eq $name) {
549: $newentry.=$_.'&&&';
550: } else {
551: $nametype=$thistype;
552: }
553: }
554: }
555: unless ($ptype) { $ptype=$nametype; }
556: unless ($ptype) { $ptype='string'; }
557: $newentry.=$ptype.'___'.$name.'___'.$value;
1.57 ! www 558: $resparms[$to]=$newentry;
! 559: }
! 560:
! 561: sub delparameter {
! 562: my ($to,$name)=@_;
! 563: my $newentry='';
! 564: my $nametype='';
! 565: foreach (split('&&&',$resparms[$to])) {
! 566: my ($thistype,$thisname,$thisvalue)=split('___',$_);
! 567: if ($thisname) {
! 568: unless ($thisname eq $name) {
! 569: $newentry.=$_.'&&&';
! 570: }
! 571: }
! 572: }
1.56 www 573: $resparms[$to]=$newentry;
574: }
575:
576: sub getparameter {
577: my ($to,$name);
578: my $value=undef;
579: my $ptype=undef;
580: foreach (split('&&&',$resparms[$to])) {
581: my ($thistype,$thisname,$thisvalue)=split('___',$_);
582: if ($thisname eq $name) {
583: $value=$thisvalue;
584: $ptype=$thistype;
585: }
586: }
587: return ($value,$ptype);
588: }
589:
590: # ----------------------------------------------------------------- Edit script
1.32 www 591: sub editscript {
592: my $mode=shift;
1.51 www 593: my $resurl=&Apache::loncommon::lastresurl();
1.32 www 594: return(<<ENDSCRIPT);
595: var srch;
596: var srchflag=-1; // 1 means currently open
597: // 0 means closed (but has been open)
598: // -1 means never yet opened/defined
599: var srchmode='';
600:
601: var idx;
602: var idxflag=-1; // 1 means currently open
603: // 0 means closed (but has been open)
604: // -1 means never yet opened/defined
605: var idxmode='';
606:
607: // ------------------------------------------------------ Clears indexer window
608: function idxclear() {
609: idx.document.clear();
610: }
611:
612: // ------------------------------------------------------- Clears search window
613: function srchclear() {
614: srch.document.clear();
615: }
616:
617: // ------------------------------------------------------ Closes indexer window
618: function idxclose() {
619: if (idx && !idx.closed) {
620: idxflag=0;
621: idx.close();
622: }
623: }
624:
625: // ------------------------------------------------------- Closes search window
626: function srchclose() {
627: if (srch && !srch.closed) {
628: srchflag=0;
629: srch.close();
630: }
631: }
632:
633: // -------------------------------------------------------- Open indexer window
634: function idxopen(mode) {
635: var options="scrollbars=1,resizable=1,menubar=0";
636: idxmode=mode;
637: idxflag=1;
1.51 www 638: idx=open("$resurl/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
1.32 www 639: idx.focus();
640: }
641:
642: // --------------------------------------------------------- Open search window
643: function srchopen(mode) {
644: var options="scrollbars=1,resizable=1,menubar=0";
645: srchmode=mode;
646: srchflag=1;
647: srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
648: srch.focus();
649: }
650: // ----------------------------------------------------- launch indexer browser
651: function groupsearch() {
652: srchcheck('groupsearch');
653: }
654:
655: function groupimport() {
656: idxcheck('groupimport');
657: }
658: // ------------------------------------------------------- Do srch status check
659: function srchcheck(mode) {
660: if (!srch || srch.closed || srchmode!=mode) {
661: srchopen(mode);
662: }
663: srch.focus();
664: }
665:
666: // -------------------------------------------------------- Do idx status check
667: function idxcheck(mode) {
668: if (!idx || idx.closed || idxmode!=mode) {
669: idxopen(mode);
670: }
671: idx.focus();
672: }
673:
674:
675: var editbrowser;
676: function openbrowser(formname,elementname,only,omit) {
1.51 www 677: var url = '$resurl/?';
1.32 www 678: if (editbrowser == null) {
679: url += 'launch=1&';
680: }
681: url += 'catalogmode=interactive&';
682: url += 'mode=edit&';
683: url += 'form=' + formname + '&';
684: if (only != null) {
685: url += 'only=' + only + '&';
686: }
687: if (omit != null) {
688: url += 'omit=' + omit + '&';
689: }
690: url += 'element=' + elementname + '';
691: var title = 'Browser';
692: var options = 'scrollbars=1,resizable=1,menubar=0';
693: options += ',width=700,height=600';
694: editbrowser = open(url,title,options,'1');
695: editbrowser.focus();
696: }
697: ENDSCRIPT
698: }
1.20 www 699: # ------------------------------------------------------- Simple edit processor
700:
1.3 www 701: sub smpedt {
1.22 www 702: my ($r,$url,$errtext)=@_;
1.8 www 703: my $buttons=&buttons(2);
1.34 www 704: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
705: my $targetmsg='';
706: if ($ENV{'form.save'}) {
707: $targetmsg='<b>Saving ...</b><br>';
708: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
709: unlink($tmpfn);
1.35 www 710: my ($errtext,$fatal)=
711: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.34 www 712: }
713: if ($ENV{'form.revert'}) {
714: $targetmsg='<b>Reverting ...</b><br>';
715: unlink($tmpfn);
1.35 www 716: my ($errtext,$fatal)=
717: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.34 www 718: }
719: if (-e $tmpfn) {
720: $targetmsg=
1.49 sakharuk 721: '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
1.34 www 722: my ($errtext,$fatal)=&mapread($tmpfn,'');
723: }
1.12 www 724: # ---------------------------------------------------------- Process form input
725:
726: my @importselect=();
727: my @targetselect=();
728: undef @importselect;
729: undef @targetselect;
1.27 www 730: if (defined($ENV{'form.importsel'})) {
731: if (ref($ENV{'form.importsel'})) {
732: @importselect=sort(@{$ENV{'form.importsel'}});
1.12 www 733: } else {
1.27 www 734: @importselect=($ENV{'form.importsel'});
1.12 www 735: }
736: }
737: if (defined($ENV{'form.target'})) {
738: if (ref($ENV{'form.target'})) {
1.25 www 739: @targetselect=sort(@{$ENV{'form.target'}});
1.12 www 740: } else {
741: @targetselect=($ENV{'form.target'});
742: }
743: }
1.13 www 744: # ============================================================ Process commands
1.12 www 745:
1.14 www 746: my $targetdetail=$ENV{'form.targetdetail'};
747: my $importdetail=$ENV{'form.curimpdetail'};
1.13 www 748:
749: # ---------------------------------------------------- Importing from groupsort
1.16 www 750: if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
1.13 www 751:
1.14 www 752: $importdetail='';
1.13 www 753: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
754:
755: my $lastsel;
756:
757: if (defined($importselect[-1])) {
758: $lastsel=$importselect[-1];
759: } else {
760: $lastsel=$#curimport;
761: }
762:
763: for (my $i=0;$i<=$lastsel;$i++) {
764: my ($name,$url)=split(/\=/,$curimport[$i]);
765: if ($url) {
1.18 www 766: $importdetail.='&'.$name.'='.$url;
1.13 www 767: }
768: }
769:
770: $importdetail.='&'.$ENV{'form.importdetail'};
771:
772: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
773: my ($name,$url)=split(/\=/,$curimport[$i]);
774: if ($url) {
1.18 www 775: $importdetail.='&'.$name.'='.$url;
1.13 www 776: }
777: }
778: $importdetail=~s/\&+/\&/g;
779: $importdetail=~s/^\&//;
780:
1.14 www 781: # ------------------------------------------------------------------- Clear all
782: } elsif ($ENV{'form.clear'}) {
783: $importdetail='';
784: # ------------------------------------------------------------ Discard selected
785: } elsif ($ENV{'form.discard'}) {
786: $importdetail='';
787: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
788: foreach (@importselect) {
789: $curimport[$_]='';
790: }
791: for (my $i=0;$i<=$#curimport;$i++) {
792: my ($name,$url)=split(/\=/,$curimport[$i]);
793: if ($url) {
1.18 www 794: $importdetail.='&'.$name.'='.$url;
1.14 www 795: }
796: }
1.17 www 797: # --------------------------------------------------------- Loading another map
798: } elsif ($ENV{'form.loadmap'}) {
799: $importdetail='';
800: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
801:
802: my $lastsel;
803:
804: if (defined($importselect[-1])) {
805: $lastsel=$importselect[-1];
806: } else {
807: $lastsel=$#curimport;
808: }
809:
810: for (my $i=0;$i<=$lastsel;$i++) {
811: my ($name,$url)=split(/\=/,$curimport[$i]);
812: if ($url) {
1.18 www 813: $importdetail.='&'.$name.'='.$url;
1.17 www 814: }
815: }
816:
817: foreach (
1.30 www 818: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.17 www 819: my ($name,$url)=split(/\:/,$_);
820: if ($url) {
821: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
822: &Apache::lonnet::escape($url);
823: }
824: }
825:
826: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
827: my ($name,$url)=split(/\=/,$curimport[$i]);
828: if ($url) {
1.18 www 829: $importdetail.='&'.$name.'='.$url;
1.17 www 830: }
831: }
832: $importdetail=~s/\&+/\&/g;
833: $importdetail=~s/^\&//;
834:
1.20 www 835: # ------------------------------------------------ Groupimport/search to target
836: } elsif ($ENV{'form.importdetail'}) {
837: my $lastsel;
838: if (defined($targetselect[-1])) {
839: $lastsel=$targetselect[-1];
840: } else {
1.23 www 841: $lastsel=$#order+1;
1.20 www 842: }
1.21 www 843: &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
1.22 www 844: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 845: # ------------------------------------------------------------------------- Cut
1.25 www 846: } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
847: $importdetail='';
848: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
849:
850: my $lastsel;
851:
852: if (defined($importselect[-1])) {
853: $lastsel=$importselect[-1];
854: } else {
855: $lastsel=$#curimport;
856: }
857:
858: for (my $i=0;$i<=$lastsel;$i++) {
859: my ($name,$url)=split(/\=/,$curimport[$i]);
860: if ($url) {
861: $importdetail.='&'.$name.'='.$url;
862: }
863: }
864:
865: foreach (@targetselect) {
866: my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
867: if ($url) {
868: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
869: &Apache::lonnet::escape($url);
870: }
871: }
872:
873: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
874: my ($name,$url)=split(/\=/,$curimport[$i]);
875: if ($url) {
876: $importdetail.='&'.$name.'='.$url;
877: }
878: }
879: $importdetail=~s/\&+/\&/g;
880: $importdetail=~s/^\&//;
881:
882: if ($ENV{'form.cut'}) {
883: my @neworder=();
884: for (my $i=0;$i<=$#order;$i++) {
885: my $include=1;
886: foreach (@targetselect) {
887: if ($_-1==$i) { $include=0; }
888: }
889: if ($include) { $neworder[$#neworder+1]=$order[$i]; }
890: }
891: @order=@neworder;
892: &storemap(&Apache::lonnet::filelocation('',$url));
893: }
894:
1.20 www 895: # ----------------------------------------------------------------------- Paste
896: } elsif ($ENV{'form.paste'}) {
1.24 www 897: my $lastsel;
898: if (defined($targetselect[-1])) {
899: $lastsel=$targetselect[-1];
900: } else {
901: $lastsel=$#order+1;
902: }
903: my @newsequence;
904: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
905: foreach (@importselect) {
906: $newsequence[$#newsequence+1]=$curimport[$_];
907: }
908: &pastetarget($lastsel,@newsequence);
909: &storemap(&Apache::lonnet::filelocation('',$url));
1.39 www 910: # -------------------------------------------------------------------- Move up
911: } elsif ($ENV{'form.moveup'}) {
912: foreach (sort @targetselect) {
913: if ($_-1>0) {
914: my $movethis=$order[$_-1];
915: $order[$_-1]=$order[$_-2];
916: $order[$_-2]=$movethis;
917: }
918: }
919: &storemap(&Apache::lonnet::filelocation('',$url));
920: # ------------------------------------------------------------------ Move down
921: } elsif ($ENV{'form.movedown'}) {
922: foreach (reverse sort @targetselect) {
923: if ($_-1<$#order) {
924: my $movethis=$order[$_-1];
925: $order[$_-1]=$order[$_];
926: $order[$_]=$movethis;
927: }
928: }
929: &storemap(&Apache::lonnet::filelocation('',$url));
930: # --------------------------------------------------------------------- Rename
931: } elsif ($ENV{'form.renameres'}) {
932: my $residx=$Apache::lonratedt::order[$ENV{'form.renameidx'}-1];
933: my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);
1.40 www 934: $name=$ENV{'form.renametitle'};
935: $name=~s/\:/\&colon\;/g;
1.41 www 936: $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);
1.39 www 937: &storemap(&Apache::lonnet::filelocation('',$url));
1.13 www 938: }
1.12 www 939: # ------------------------------------------------------------ Assemble windows
1.20 www 940:
1.13 www 941: my $idx=-1;
1.34 www 942: $importdetail='&'.$importdetail;
943: $importdetail=~s/^\&+/\&/;
1.29 www 944: my $importwindow=
1.50 sakharuk 945: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
1.29 www 946: join("\n",map {
1.13 www 947: $idx++;
948: if ($_) {
1.15 www 949: my ($name,$url)=split(/\=/,$_);
950: unless ($name) { $name=(split(/\//,$url))[-1]; }
951: unless ($name) { $name='EMPTY'; }
1.13 www 952: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
953: '</option>';
954: }
955: } split(/\&/,$importdetail));
1.12 www 956:
1.13 www 957: $idx=0;
1.39 www 958: $targetdetail='';
1.29 www 959: my $targetwindow=
1.49 sakharuk 960: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
1.29 www 961: join("\n",map {
1.13 www 962: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 963: unless ($name) { $name=(split(/\//,$url))[-1]; }
964: unless ($name) { $name='EMPTY'; }
1.13 www 965: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
966: &Apache::lonnet::escape($url);
967: $idx++;
1.37 www 968: $name=~s/\:/\:/g;
1.20 www 969: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 970: } @order);
971:
1.8 www 972: # ----------------------------------------------------- Start simple RAT screen
1.32 www 973: my $editscript=&editscript('simple');
1.53 www 974: my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1).
975: &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation').
976: &Apache::loncommon::help_open_faq(6).
977: &Apache::loncommon::help_open_bug('RAT');
1.47 www 978: my %lt=&Apache::lonlocal::texthash(
979: 'sa' => 'Save',
980: 'nt' => 'New Title',
981: 'se' => 'Search',
982: 'im' => 'Import',
983: 'vi' => 'View',
984: 'lm' => 'Load Map',
985: 'ds' => 'Discard Selected',
986: 'ca' => 'Clear All',
987: 'ta' => 'Temporary Assembly Workspace',
988: 'rv' => 'Revert to Last Saved',
989: 'sa' => 'Save',
990: 'mu' => 'Move Up',
991: 'md' => 'Move Down',
992: 're' => 'Rename',
1.49 sakharuk 993: 'as' => 'after selected',
994: 'cs' => 'Cut selected',
995: 'ps' => 'Copy selected',
996: 'pas' => 'Paste after selected',
1.47 www 997: );
1.3 www 998: $r->print(<<ENDSMPHEAD);
999: <html>
1.6 www 1000: <head>
1001: <script>
1.15 www 1002:
1.32 www 1003: $editscript
1.19 www 1004:
1005: function openview(entry) {
1006: var url=unescape((entry.split('='))[1]);
1.20 www 1007: var parts=new Array;
1008: parts=url.split(':');
1009: url=parts.join(':');
1.19 www 1010: if (url) { open(url,'cat'); }
1011: }
1012:
1013: function viewtarget() {
1014: openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34 www 1015: [document.forms.simpleedit.target.selectedIndex]);
1.19 www 1016: }
1017:
1018: function viewimport() {
1019: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34 www 1020: [document.forms.simpleedit.importsel.selectedIndex]);
1.19 www 1021: }
1022:
1.39 www 1023: function renametarget() {
1024: var selidx=document.forms.simpleedit.target.selectedIndex;
1025: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
1026: [selidx];
1.41 www 1027: var oldname=unescape((entry.split('='))[0]);
1028: var nameparts=oldname.split(':');
1029: oldname=unescape(nameparts.join(':'));
1030: nameparts=oldname.split('"');
1031: oldname=unescape(nameparts.join('"'));
1032: nameparts=oldname.split(''');
1033: oldname=unescape(nameparts.join("'"));
1.47 www 1034: newtitle=prompt('$lt{'nt'}',oldname);
1.39 www 1035: if (newtitle) {
1036: document.forms.simpleedit.renameres.value=1;
1037: document.forms.simpleedit.renameidx.value=selidx;
1038: document.forms.simpleedit.renametitle.value=newtitle;
1039: document.forms.simpleedit.submit();
1040: }
1041: }
1042:
1.6 www 1043: </script>
1044: </head>
1.34 www 1045: $bodytag
1.8 www 1046: $buttons
1.7 www 1047: <font color=red>$errtext</font>
1.13 www 1048: <form name=simpleedit method=post>
1.11 www 1049: <input type=hidden name=forcesmp value=1>
1.39 www 1050: <input type=hidden name=renameres value=0>
1051: <input type=hidden name=renametitle value=''>
1052: <input type=hidden name=renameidx value=0>
1.11 www 1053: <table>
1.47 www 1054: <tr><th width="40%">$lt{'ta'}</th>
1.12 www 1055: <th> </th>
1.37 www 1056: <th width="40%">File: $url</th></tr>
1.12 www 1057: <tr><td bgcolor="#FFFFCC">
1.47 www 1058: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
1059: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
1.49 sakharuk 1060: $lt{'as'}
1.14 www 1061: <hr>
1.15 www 1062: <input type=text size=20 name=importmap>
1063: <input type=button
1064: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
1.47 www 1065: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
1066: <input type=submit name="discard" value="$lt{'ds'}">
1067: <input type=submit name="clear" value="$lt{'ca'}">
1068: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
1.16 www 1069:
1.12 www 1070: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 1071:
1072: <input type=button onClick=
1.47 www 1073: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
1.16 www 1074: <input type=button onClick=
1.47 www 1075: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
1.49 sakharuk 1076: $lt{'as'}
1.39 www 1077: <hr>
1.47 www 1078: <input type=submit name="moveup" value="$lt{'mu'}">
1079: <input type=submit name="movedown" value="$lt{'md'}">
1080: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
1.34 www 1081: <hr>$targetmsg
1.47 www 1082: <input type=submit name="revert" value="$lt{'rv'}">
1083: <input type=submit name="save" value="$lt{'sa'}">
1084: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
1.12 www 1085: </td></tr>
1.16 www 1086:
1.27 www 1087: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12 www 1088: $importwindow
1089: </select>
1.11 www 1090: </td>
1.12 www 1091: <td bgcolor="#FFFFAA" align="center">
1.49 sakharuk 1092: $lt{'cs'}<br>
1.11 www 1093: <input type=submit name=cut value='<<<'><p>
1.12 www 1094: <hr>
1.49 sakharuk 1095: $lt{'ps'}<br>
1.25 www 1096: <input type=submit name=copy value='<--'><p>
1097: <hr>
1.49 sakharuk 1098: $lt{'pas'}<br>
1.25 www 1099: <input type=submit name=paste value='-->'>
1.11 www 1100: </td>
1.27 www 1101: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11 www 1102: $targetwindow
1103: </select>
1.12 www 1104: </table>
1.13 www 1105: <input type=hidden name=importdetail value="">
1106: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 1107: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 1108: <input type=hidden name=impfortarget value="0">
1.12 www 1109: </form>
1110: </body></html>
1.3 www 1111: ENDSMPHEAD
1112: }
1113:
1.11 www 1114: # ----------------------------------------------------------------- No such dir
1.4 www 1115: sub nodir {
1116: my ($r,$dir)=@_;
1117: $dir=~s/^\/home\/\w+\/public\_html//;
1118: $r->print(<<ENDNODIR);
1119: <html>
1120: <body bgcolor='#FFFFFF'>
1121: <h1>No such directory: $dir</h1>
1122: </body>
1123: </html>
1124: ENDNODIR
1125: }
1126:
1.8 www 1127: # ---------------------------------------------------------------- View Handler
1128:
1129: sub viewmap {
1.17 www 1130: my ($r,$url,$adv,$errtext)=@_;
1.34 www 1131: $r->print('<html>'.
1132: &Apache::loncommon::bodytag('Edit Content of a Map').
1.53 www 1133: &Apache::loncommon::help_open_faq(6).
1134: &Apache::loncommon::help_open_bug('RAT').
1135: &buttons($adv));
1.10 www 1136: if ($errtext) {
1.53 www 1137: $r->print($errtext.'<hr />');
1.10 www 1138: }
1.26 www 1139: my $idx=0;
1.34 www 1140: $r->print('<h1>'.$url.'</h1>');
1.44 www 1141: if ($adv) {
1.47 www 1142: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.44 www 1143: }
1.17 www 1144: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 1145: if (defined($_)) {
1.26 www 1146: $idx++;
1.9 www 1147: my ($title,$url)=split(/\:/,$_);
1148: $title=~s/\&colon\;/\:/g;
1149: $url=~s/\&colon\;/\:/g;
1.15 www 1150: unless ($title) { $title=(split(/\//,$url))[-1] };
1151: unless ($title) { $title='<i>Empty</i>'; }
1.9 www 1152: if ($url) {
1153: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
1154: }
1155: $r->print(&Apache::lonratsrv::qtescape($title));
1156: if ($url) { $r->print('</a>'); }
1.28 www 1157: $r->print('<br>');
1.9 www 1158: }
1159: }
1.8 www 1160: $r->print('</body></html>');
1161: }
1162:
1.3 www 1163: # ================================================================ Main Handler
1164:
1165: sub handler {
1166: my $r=shift;
1.47 www 1167: &Apache::loncommon::content_type($r,'text/html');
1.3 www 1168: $r->send_http_header;
1169:
1170: return OK if $r->header_only;
1.48 albertel 1171: my $target = $ENV{'form.grade_target'};
1172: if ($target eq 'meta') {
1173: &Apache::loncommon::content_type($r,'text/html');
1174: $r->send_http_header;
1175: return OK;
1176: }
1177:
1.3 www 1178: my $url=$r->uri;
1179: my $fn=&Apache::lonnet::filelocation('',$url);
1180:
1.4 www 1181: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
1182: unless (-e $dir) {
1183: &nodir($r,$dir);
1184: return OK;
1185: }
1.8 www 1186:
1187: # ------------------------------------------- Determine which tools can be used
1.3 www 1188: my $adv=0;
1189:
1190: unless ($ENV{'form.forcesmp'}) {
1191: if ($ENV{'form.forceadv'}) {
1192: $adv=1;
1193: } elsif (my $fh=Apache::File->new($fn)) {
1194: my $allmap=join('',<$fh>);
1195: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
1196: }
1197: }
1198:
1.8 www 1199: my $errtext='';
1200: my $fatal=0;
1201:
1202: # -------------------------------------------------------------------- Load map
1203: ($errtext,$fatal)=&mapread($fn,$errtext);
1204:
1205: if ($fatal==1) { $adv=1; }
1206:
1207: # ----------------------------------- adv==1 now means "graphical MUST be used"
1208:
1209: if ($ENV{'form.forceadv'}) {
1.3 www 1210: &ratedt($r,$url);
1.8 www 1211: } elsif ($ENV{'form.forcesmp'}) {
1.22 www 1212: &smpedt($r,$url,$errtext);
1.3 www 1213: } else {
1.17 www 1214: &viewmap($r,$url,$adv,$errtext);
1.3 www 1215: }
1.1 www 1216: return OK;
1217: }
1218:
1219: 1;
1220: __END__
1221:
1222:
1223:
1224:
1225:
1226:
1227:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>