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