Annotation of rat/lonratedt.pm, revision 1.83
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.83 ! albertel 4: # $Id: lonratedt.pm,v 1.82 2006/07/20 04:17:45 albertel 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:
1.71 www 36: Apache::lonratedt: simple resource assembly tool
1.46 bowersj2 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.78 www 175: use lib '/home/httpd/lib/perl/';
176: use LONCAPA;
177:
1.1 www 178:
1.70 www 179: use vars qw(@order @resources @resparms @zombies);
1.8 www 180:
181:
182: # Mapread read maps into global arrays @links and @resources, determines status
1.10 www 183: # sets @order - pointer to resources in right order
184: # sets @resources - array with the resources with correct idx
185: #
1.8 www 186: sub mapread {
187: my $fn=shift;
188:
1.10 www 189: my @links;
1.8 www 190: undef @links;
191: undef @resources;
1.10 www 192: undef @order;
1.58 www 193: undef @resparms;
1.67 www 194: undef @zombies;
195:
1.23 www 196: @resources=('');
197: @order=();
1.58 www 198: @resparms=();
1.67 www 199: @zombies=();
1.8 www 200:
201: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
202: if ($errtext) { return ($errtext,2); }
203:
1.9 www 204: # -------------------------------------------------------------------- Read map
1.8 www 205: foreach (split(/\<\&\>/,$outtext)) {
1.9 www 206: my ($command,$number,$content)=split(/\<\:\>/,$_);
1.8 www 207: if ($command eq 'objcont') {
1.67 www 208: my ($title,$src,$ext,$type)=split(/\:/,$content);
1.69 www 209: if ($ext eq 'cond') { next; }
1.67 www 210: if ($type ne 'zombie') {
211: $resources[$number]=$content;
212: } else {
213: $zombies[$number]=$content;
214: }
1.8 www 215: }
216: if ($command eq 'objlinks') {
1.9 www 217: $links[$number]=$content;
1.31 www 218: }
219: if ($command eq 'objparms') {
1.55 www 220: if ($resparms[$number]) {
221: $resparms[$number].='&&&'.$content;
222: } else {
223: $resparms[$number]=$content;
224: }
1.9 www 225: }
226: }
227: # ------------------------------------------------------- Is this a linear map?
228: my @starters=();
229: my @endings=();
230: undef @starters;
231: undef @endings;
232:
233: foreach (@links) {
234: if (defined($_)) {
235: my ($start,$end,$cond)=split(/\:/,$_);
236: if ((defined($starters[$start])) || (defined($endings[$end]))) {
1.8 www 237: return
1.49 sakharuk 238: (&mt('Map has branchings. Use advanced editor.'),1);
1.8 www 239: }
1.9 www 240: $starters[$start]=1;
241: $endings[$end]=1;
242: if ($cond) {
1.8 www 243: return
1.49 sakharuk 244: (&mt('Map has conditions. Use advanced editor.'),1);
1.8 www 245: }
246: }
247:
248: }
1.23 www 249: for (my $i=1; $i<=$#resources; $i++) {
1.10 www 250: if (defined($resources[$i])) {
251: unless (($starters[$i]) || ($endings[$i])) {
252: return
1.49 sakharuk 253: (&mt('Map has unconnected resources. Use advanced editor.'),1);
1.10 www 254: }
255: }
256: }
1.38 www 257: # ---------------------------------------------- Did we just read an empty map?
258: if ($#resources<1) {
259: undef $resources[0];
260: $resources[1]=':::start';
261: $resources[2]=':::finish';
262: }
1.10 www 263: # -------------------------------------------------- This is a linear map, sort
264:
265: my $startidx=0;
266: my $endidx=0;
267: for (my $i=0; $i<=$#resources; $i++) {
268: if (defined($resources[$i])) {
269: my ($title,$url,$ext,$type)=split(/\:/,$resources[$i]);
270: if ($type eq 'start') { $startidx=$i; }
271: if ($type eq 'finish') { $endidx=$i; }
272: }
273: }
274: my $k=0;
275: my $currentidx=$startidx;
276: $order[$k]=$currentidx;
277: for (my $i=0; $i<=$#resources; $i++) {
278: foreach (@links) {
279: my ($start,$end)=split(/\:/,$_);
280: if ($start==$currentidx) {
281: $currentidx=$end;
282: $k++;
283: $order[$k]=$currentidx;
284: last;
285: }
286: }
287: if ($currentidx==$endidx) { last; }
288: }
1.8 www 289: return $errtext;
290: }
291:
1.16 www 292: # ---------------------------------------------- Read a map as well as possible
1.28 www 293: # Also used by the sequence handler
294: # Call lonsequence::attemptread to read from resource space
295: #
1.16 www 296: sub attemptread {
297: my $fn=shift;
298:
299: my @links;
300: undef @links;
301: my @theseres;
302: undef @theseres;
303:
304: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
305: if ($errtext) { return @theseres }
306:
307: # -------------------------------------------------------------------- Read map
308: foreach (split(/\<\&\>/,$outtext)) {
309: my ($command,$number,$content)=split(/\<\:\>/,$_);
310: if ($command eq 'objcont') {
1.67 www 311: my ($title,$src,$ext,$type)=split(/\:/,$content);
312: unless ($type eq 'zombie') {
313: $theseres[$number]=$content;
314: }
1.16 www 315: }
316: if ($command eq 'objlinks') {
317: $links[$number]=$content;
318: }
319: }
320:
321: # --------------------------------------------------------------- Sort, sort of
322:
1.17 www 323: my @objsort=();
324: undef @objsort;
1.16 www 325:
1.17 www 326: my @data1=();
327: my @data2=();
328: undef @data1;
329: undef @data2;
330:
331: my $k;
332: my $kj;
333: my $j;
334: my $ij;
335:
336: for ($k=1;$k<=$#theseres;$k++) {
337: if (defined($theseres[$k])) {
338: $objsort[$#objsort+1]=$k;
339: }
340: }
1.16 www 341:
1.17 www 342: for ($k=1;$k<=$#links;$k++) {
343: if (defined($links[$k])) {
344: @data1=split(/\:/,$links[$k]);
345: $kj=-1;
346: for (my $j=0;$j<=$#objsort;$j++) {
347: if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
348: $kj=$j;
349: }
350: }
351: if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
352: }
353: }
354: for ($k=0;$k<=$#objsort;$k++) {
355: for ($j=0;$j<=$#objsort;$j++) {
356: if ($k!=$j) {
357: @data1=split(/\:/,$objsort[$k]);
358: @data2=split(/\:/,$objsort[$j]);
359: my $dol=$#data1+1;
360: my $dtl=$#data2+1;
361: if ($dol+$dtl<1000) {
362: for ($kj=1;$kj<$dol;$kj++) {
363: if ($data1[$kj]==$data2[0]) {
364: for ($ij=1;$ij<$dtl;$ij++) {
365: $data1[$#data1+1]=$data2[$ij];
366: }
367: }
368: }
369: for ($kj=1;$kj<$dtl;$kj++) {
370: if ($data2[$kj]==$data1[0]) {
371: for ($ij=1;$ij<$dol;$ij++) {
372: $data2[$#data2+1]=$data1[$ij];
373: }
374: }
375: }
376: $objsort[$k]=join(':',@data1);
377: $objsort[$j]=join(':',@data2);
378: }
379: }
380: }
381: }
382: # ---------------------------------------------------------------- Now sort out
1.16 www 383:
1.17 www 384: @objsort=sort {
385: my @data1=split(/\:/,$a);
386: my @data2=split(/\:/,$b);
387: my $rvalue=0;
388: my $k;
389: for ($k=1;$k<=$#data1;$k++) {
390: if ($data1[$k]==$data2[0]) { $rvalue--; }
391: }
392: for ($k=1;$k<=$#data2;$k++) {
393: if ($data2[$k]==$data1[0]) { $rvalue++; }
394: }
395: if ($rvalue==0) { $rvalue=$#data2-$#data1; }
396: $rvalue;
397: } @objsort;
398:
399: my @outres=();
400: undef @outres;
401:
402: for ($k=0;$k<=$#objsort;$k++) {
403: $outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
404: }
405: return @outres;
1.16 www 406: }
407:
1.3 www 408: # --------------------------------------------------------- Build up RAT screen
409: sub ratedt {
410: my ($r,$url)=@_;
1.75 albertel 411: my %layout = ('border' => "0");
412: if ($env{'environment.remote'} eq 'off') {
413: $layout{'rows'} = "1,250,*";
414: } else {
415: $layout{'rows'} = "1,70,*";
1.63 raeburn 416: }
1.75 albertel 417: my $js ='
418: <script type="text/javascript">
419: var flag=0;
420: </script>';
1.1 www 421:
1.75 albertel 422: my $start_page =
423: &Apache::loncommon::start_page('Edit Sequence',$js,
424: {'frameset' => 1,
425: 'add_entries' => \%layout});
426: my $end_page =
427: &Apache::loncommon::end_page({'frameset' => 1});
1.1 www 428:
1.75 albertel 429: $r->print(<<ENDDOCUMENT);
430: $start_page
431: <frame name="server" src="$url/loadonly/ratserver" noresize="noresize"
432: noscroll="noscroll" />
433: <frame name="code" src="$url/loadonly/adveditmenu" />
434: <frame name="mapout" src="/adm/rat/map.html" />
435: $end_page
1.1 www 436: ENDDOCUMENT
1.3 www 437: }
438:
1.8 www 439: # ---------------------------------------------------------------- Make buttons
440:
441: sub buttons {
442: my $adv=shift;
443: my $output='<form method=post>';
444: if ($adv==1) {
1.52 www 445: $output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
446: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
1.8 www 447: } else {
448: unless ($adv==2) {
1.52 www 449: $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
450: &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
1.8 www 451: }
1.52 www 452: $output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
453: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
1.8 www 454: }
455: return $output.'</form><hr>';
456: }
457:
1.70 www 458: # ------------------------------------- Revive zombie idx or get unused number
1.68 www 459:
1.70 www 460: sub getresidx {
461: my $url=shift;
462: my $max=1+($#resources>$#zombies?$#resources:$#zombies);
463: unless ($url) { return $max; }
464: for (my $i=0; $i<=$#zombies; $i++) {
465: my ($title,$src,$ext,$type)=split(/\:/,$zombies[$i]);
466: if ($src eq $url) {
467: undef $zombies[$i];
468: return $i;
469: }
470: }
471: return $max;
1.68 www 472: }
473:
1.71 www 474: # --------------------------------------------------------------- Make a zombie
475:
476: sub makezombie {
477: my $idx=shift;
478: my ($name,$url,$ext)=split(/\:/,$resources[$idx]);
1.72 www 479: my $now=time;
480: $zombies[$idx]=$name.
481: ' [('.$now.','.$env{'user.name'}.','.$env{'user.domain'}.')]:'.
482: $url.':'.$ext.':zombie';
1.71 www 483: }
484:
1.20 www 485: # ----------------------------------------------------------- Paste into target
486: # modifies @order, @resources
487:
488: sub pastetarget {
489: my ($after,@which)=@_;
490: my @insertorder=();
491: foreach (@which) {
492: if (defined($_)) {
493: my ($name,$url)=split(/\=/,$_);
1.78 www 494: $name=&unescape($name);
495: $url=&unescape($url);
1.21 www 496: if ($url) {
1.70 www 497: my $idx=&getresidx($url);
1.21 www 498: $insertorder[$#insertorder+1]=$idx;
499: my $ext='false';
500: if ($url=~/^http\:\/\//) { $ext='true'; }
501: $url=~s/\:/\:/g;
1.37 www 502: $name=~s/\:/\:/g;
1.21 www 503: $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
504: }
1.20 www 505: }
506: }
1.23 www 507: my @oldorder=splice(@order,$after);
508: @order=(@order,@insertorder,@oldorder);
1.21 www 509: }
510:
511: # ------------------------------------------------ Get start and finish correct
512: # modifies @resources
513:
514: sub startfinish {
1.43 www 515: # Remove all start and finish
1.21 www 516: foreach (@order) {
517: my ($name,$url,$ext)=split(/\:/,$resources[$_]);
1.22 www 518: if ($url=~/http\&colon\:\/\//) { $ext='true'; }
1.21 www 519: $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
520: }
1.43 www 521: # Garbage collection
522: my $stillchange=1;
523: while (($#order>1) && ($stillchange)) {
524: $stillchange=0;
525: for (my $i=0;$i<=$#order;$i++) {
526: my ($name,$url,$ext)=split(/\:/,$resources[$order[$i]]);
527: unless ($url) {
528: # Take out empty resource
529: for (my $j=$i+1;$j<=$#order;$j++) {
530: $order[$j-1]=$order[$j];
531: }
532: $#order--;
533: $stillchange=1;
534: last;
535: }
536: }
537: }
538: # Put in a start resource
1.23 www 539: my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
540: $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
1.43 www 541: # Make sure this has at least start and finish
1.33 www 542: if ($#order==0) {
1.70 www 543: $resources[&getresidx()]='::false';
1.33 www 544: $order[1]=$#resources;
545: }
1.43 www 546: # Make the last one a finish resource
1.42 www 547: ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
1.21 www 548: $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
1.20 www 549: }
550:
1.22 www 551: # ------------------------------------------------------------------- Store map
552:
553: sub storemap {
1.34 www 554: my $realfn=shift;
1.35 www 555: my $fn=$realfn;
556: # unless this is forced to work from the original file, use a temporary file
557: # instead
558: unless (shift) {
559: $fn=$realfn.'.tmp';
560: unless (-e $fn) {
561: copy($realfn,$fn);
562: }
1.34 www 563: }
1.35 www 564: # store data either into tmp or real file
1.22 www 565: &startfinish();
566: my $output='graphdef<:>no';
567: my $k=1;
568: for (my $i=0; $i<=$#order; $i++) {
569: if (defined($resources[$order[$i]])) {
570: $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
571: }
1.54 www 572: if (defined($resparms[$order[$i]])) {
1.55 www 573: foreach (split('&&&',$resparms[$order[$i]])) {
574: if ($_) {
575: $output.='<&>objparms<:>'.$order[$i].'<:>'.$_;
576: }
577: }
1.54 www 578: }
1.22 www 579: if (defined($order[$i+1])) {
580: if (defined($resources[$order[$i+1]])) {
581: $output.='<&>objlinks<:>'.$k.'<:>'.
582: $order[$i].':'.$order[$i+1].':0';
583: $k++;
584: }
585: }
586: }
1.69 www 587: for (my $i=0; $i<=$#zombies; $i++) {
588: if (defined($zombies[$i])) {
589: $output.='<&>objcont<:>'.$i.'<:>'.$zombies[$i];
590: }
591: }
1.23 www 592: $output=~s/http\&colon\;\/\///g;
1.65 albertel 593: $env{'form.output'}=$output;
1.22 www 594: return
595: &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
596: }
597:
1.56 www 598: # ------------------------------------------ Store and get parameters in global
599:
600: sub storeparameter {
601: my ($to,$name,$value,$ptype)=@_;
602: my $newentry='';
603: my $nametype='';
604: foreach (split('&&&',$resparms[$to])) {
605: my ($thistype,$thisname,$thisvalue)=split('___',$_);
606: if ($thisname) {
607: unless ($thisname eq $name) {
608: $newentry.=$_.'&&&';
609: } else {
610: $nametype=$thistype;
611: }
612: }
613: }
614: unless ($ptype) { $ptype=$nametype; }
615: unless ($ptype) { $ptype='string'; }
616: $newentry.=$ptype.'___'.$name.'___'.$value;
1.57 www 617: $resparms[$to]=$newentry;
618: }
619:
620: sub delparameter {
621: my ($to,$name)=@_;
622: my $newentry='';
623: my $nametype='';
624: foreach (split('&&&',$resparms[$to])) {
625: my ($thistype,$thisname,$thisvalue)=split('___',$_);
626: if ($thisname) {
627: unless ($thisname eq $name) {
628: $newentry.=$_.'&&&';
629: }
630: }
631: }
1.56 www 632: $resparms[$to]=$newentry;
633: }
634:
635: sub getparameter {
1.58 www 636: my ($to,$name)=@_;
1.56 www 637: my $value=undef;
638: my $ptype=undef;
639: foreach (split('&&&',$resparms[$to])) {
640: my ($thistype,$thisname,$thisvalue)=split('___',$_);
641: if ($thisname eq $name) {
642: $value=$thisvalue;
643: $ptype=$thistype;
644: }
645: }
646: return ($value,$ptype);
647: }
648:
649: # ----------------------------------------------------------------- Edit script
1.32 www 650: sub editscript {
651: my $mode=shift;
1.83 ! albertel 652: my $resurl=
! 653: &Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
1.32 www 654: return(<<ENDSCRIPT);
655: var srch;
656: var srchflag=-1; // 1 means currently open
657: // 0 means closed (but has been open)
658: // -1 means never yet opened/defined
659: var srchmode='';
660:
661: var idx;
662: var idxflag=-1; // 1 means currently open
663: // 0 means closed (but has been open)
664: // -1 means never yet opened/defined
665: var idxmode='';
666:
667: // ------------------------------------------------------ Clears indexer window
668: function idxclear() {
669: idx.document.clear();
670: }
671:
672: // ------------------------------------------------------- Clears search window
673: function srchclear() {
674: srch.document.clear();
675: }
676:
677: // ------------------------------------------------------ Closes indexer window
678: function idxclose() {
679: if (idx && !idx.closed) {
680: idxflag=0;
681: idx.close();
682: }
683: }
684:
685: // ------------------------------------------------------- Closes search window
686: function srchclose() {
687: if (srch && !srch.closed) {
688: srchflag=0;
689: srch.close();
690: }
691: }
692:
693: // -------------------------------------------------------- Open indexer window
694: function idxopen(mode) {
1.81 albertel 695: var options="scrollbars=1,resizable=1,menubar=0,location=1,toolbar=1";
1.32 www 696: idxmode=mode;
697: idxflag=1;
1.83 ! albertel 698: idx=open('$resurl/?launch=1&mode=$mode&catalogmode='+mode,'idxout',options);
1.32 www 699: idx.focus();
700: }
701:
1.73 www 702: // ------------------------------------------------------ Open groupsort window
1.80 www 703: function groupopen(url,recover,bookmarks) {
1.73 www 704: var options="scrollbars=1,resizable=1,menubar=0";
705: idxflag=1;
1.80 www 706: idx=open("/adm/groupsort?mode=$mode&recover="+recover+"&readfile="+url+"&bookmarks="+bookmarks,"idxout",options);
1.73 www 707: idx.focus();
708: }
709:
1.32 www 710: // --------------------------------------------------------- Open search window
711: function srchopen(mode) {
712: var options="scrollbars=1,resizable=1,menubar=0";
713: srchmode=mode;
714: srchflag=1;
715: srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
716: srch.focus();
717: }
718: // ----------------------------------------------------- launch indexer browser
719: function groupsearch() {
1.79 www 720: srchcheck('import');
1.32 www 721: }
722:
723: function groupimport() {
1.79 www 724: idxcheck('import');
1.32 www 725: }
1.73 www 726:
1.32 www 727: // ------------------------------------------------------- Do srch status check
728: function srchcheck(mode) {
729: if (!srch || srch.closed || srchmode!=mode) {
730: srchopen(mode);
731: }
732: srch.focus();
733: }
734:
735: // -------------------------------------------------------- Do idx status check
736: function idxcheck(mode) {
737: if (!idx || idx.closed || idxmode!=mode) {
738: idxopen(mode);
739: }
740: idx.focus();
741: }
742:
743:
744: var editbrowser;
745: function openbrowser(formname,elementname,only,omit) {
1.51 www 746: var url = '$resurl/?';
1.32 www 747: if (editbrowser == null) {
748: url += 'launch=1&';
749: }
750: url += 'catalogmode=interactive&';
751: url += 'mode=edit&';
752: url += 'form=' + formname + '&';
753: if (only != null) {
754: url += 'only=' + only + '&';
755: }
756: if (omit != null) {
757: url += 'omit=' + omit + '&';
758: }
759: url += 'element=' + elementname + '';
760: var title = 'Browser';
1.82 albertel 761: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.32 www 762: options += ',width=700,height=600';
763: editbrowser = open(url,title,options,'1');
764: editbrowser.focus();
765: }
766: ENDSCRIPT
767: }
1.20 www 768: # ------------------------------------------------------- Simple edit processor
769:
1.3 www 770: sub smpedt {
1.22 www 771: my ($r,$url,$errtext)=@_;
1.8 www 772: my $buttons=&buttons(2);
1.34 www 773: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
774: my $targetmsg='';
1.65 albertel 775: if ($env{'form.save'}) {
1.34 www 776: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
777: unlink($tmpfn);
1.35 www 778: my ($errtext,$fatal)=
779: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.60 www 780: unless ($fatal) {
781: $targetmsg='<b>'.&mt('Saved.').'</b><br />';
782: } else {
783: $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
784: }
1.34 www 785: }
1.65 albertel 786: if ($env{'form.revert'}) {
1.60 www 787: $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
1.34 www 788: unlink($tmpfn);
1.35 www 789: my ($errtext,$fatal)=
790: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.34 www 791: }
792: if (-e $tmpfn) {
793: $targetmsg=
1.49 sakharuk 794: '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
1.34 www 795: my ($errtext,$fatal)=&mapread($tmpfn,'');
796: }
1.12 www 797: # ---------------------------------------------------------- Process form input
798:
1.66 albertel 799: my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
800: my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
1.13 www 801: # ============================================================ Process commands
1.12 www 802:
1.65 albertel 803: my $targetdetail=$env{'form.targetdetail'};
804: my $importdetail=$env{'form.curimpdetail'};
1.13 www 805:
806: # ---------------------------------------------------- Importing from groupsort
1.65 albertel 807: if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
1.13 www 808:
1.14 www 809: $importdetail='';
1.65 albertel 810: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.13 www 811:
812: my $lastsel;
813:
814: if (defined($importselect[-1])) {
815: $lastsel=$importselect[-1];
816: } else {
817: $lastsel=$#curimport;
818: }
819:
820: for (my $i=0;$i<=$lastsel;$i++) {
821: my ($name,$url)=split(/\=/,$curimport[$i]);
822: if ($url) {
1.18 www 823: $importdetail.='&'.$name.'='.$url;
1.13 www 824: }
825: }
826:
1.65 albertel 827: $importdetail.='&'.$env{'form.importdetail'};
1.13 www 828:
829: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
830: my ($name,$url)=split(/\=/,$curimport[$i]);
831: if ($url) {
1.18 www 832: $importdetail.='&'.$name.'='.$url;
1.13 www 833: }
834: }
835: $importdetail=~s/\&+/\&/g;
836: $importdetail=~s/^\&//;
837:
1.14 www 838: # ------------------------------------------------------------------- Clear all
1.65 albertel 839: } elsif ($env{'form.clear'}) {
1.14 www 840: $importdetail='';
841: # ------------------------------------------------------------ Discard selected
1.65 albertel 842: } elsif ($env{'form.discard'}) {
1.14 www 843: $importdetail='';
1.65 albertel 844: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.14 www 845: foreach (@importselect) {
846: $curimport[$_]='';
847: }
848: for (my $i=0;$i<=$#curimport;$i++) {
849: my ($name,$url)=split(/\=/,$curimport[$i]);
850: if ($url) {
1.18 www 851: $importdetail.='&'.$name.'='.$url;
1.14 www 852: }
853: }
1.17 www 854: # --------------------------------------------------------- Loading another map
1.65 albertel 855: } elsif ($env{'form.loadmap'}) {
1.17 www 856: $importdetail='';
1.65 albertel 857: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.17 www 858:
859: my $lastsel;
860:
861: if (defined($importselect[-1])) {
862: $lastsel=$importselect[-1];
863: } else {
864: $lastsel=$#curimport;
865: }
866:
867: for (my $i=0;$i<=$lastsel;$i++) {
868: my ($name,$url)=split(/\=/,$curimport[$i]);
869: if ($url) {
1.18 www 870: $importdetail.='&'.$name.'='.$url;
1.17 www 871: }
872: }
873:
874: foreach (
1.65 albertel 875: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.17 www 876: my ($name,$url)=split(/\:/,$_);
877: if ($url) {
1.78 www 878: $importdetail.='&'.&escape($name).'='.
879: &escape($url);
1.17 www 880: }
881: }
882:
883: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
884: my ($name,$url)=split(/\=/,$curimport[$i]);
885: if ($url) {
1.18 www 886: $importdetail.='&'.$name.'='.$url;
1.17 www 887: }
888: }
889: $importdetail=~s/\&+/\&/g;
890: $importdetail=~s/^\&//;
891:
1.20 www 892: # ------------------------------------------------ Groupimport/search to target
1.65 albertel 893: } elsif ($env{'form.importdetail'}) {
1.20 www 894: my $lastsel;
895: if (defined($targetselect[-1])) {
896: $lastsel=$targetselect[-1];
897: } else {
1.23 www 898: $lastsel=$#order+1;
1.20 www 899: }
1.65 albertel 900: &pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
1.22 www 901: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 902: # ------------------------------------------------------------------------- Cut
1.65 albertel 903: } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
1.25 www 904: $importdetail='';
1.65 albertel 905: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.25 www 906:
907: my $lastsel;
908:
909: if (defined($importselect[-1])) {
910: $lastsel=$importselect[-1];
911: } else {
912: $lastsel=$#curimport;
913: }
914:
915: for (my $i=0;$i<=$lastsel;$i++) {
916: my ($name,$url)=split(/\=/,$curimport[$i]);
917: if ($url) {
918: $importdetail.='&'.$name.'='.$url;
919: }
920: }
921:
922: foreach (@targetselect) {
923: my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
924: if ($url) {
1.78 www 925: $importdetail.='&'.&escape($name).'='.
926: &escape($url);
1.25 www 927: }
928: }
929:
930: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
931: my ($name,$url)=split(/\=/,$curimport[$i]);
932: if ($url) {
933: $importdetail.='&'.$name.'='.$url;
934: }
935: }
936: $importdetail=~s/\&+/\&/g;
937: $importdetail=~s/^\&//;
938:
1.65 albertel 939: if ($env{'form.cut'}) {
1.25 www 940: my @neworder=();
941: for (my $i=0;$i<=$#order;$i++) {
942: my $include=1;
943: foreach (@targetselect) {
944: if ($_-1==$i) { $include=0; }
945: }
1.71 www 946: if ($include) {
947: $neworder[$#neworder+1]=$order[$i];
948: } else {
949: &makezombie($order[$i]);
950: }
1.25 www 951: }
952: @order=@neworder;
953: &storemap(&Apache::lonnet::filelocation('',$url));
954: }
955:
1.20 www 956: # ----------------------------------------------------------------------- Paste
1.65 albertel 957: } elsif ($env{'form.paste'}) {
1.24 www 958: my $lastsel;
959: if (defined($targetselect[-1])) {
960: $lastsel=$targetselect[-1];
961: } else {
962: $lastsel=$#order+1;
963: }
964: my @newsequence;
1.65 albertel 965: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.24 www 966: foreach (@importselect) {
967: $newsequence[$#newsequence+1]=$curimport[$_];
968: }
969: &pastetarget($lastsel,@newsequence);
970: &storemap(&Apache::lonnet::filelocation('',$url));
1.39 www 971: # -------------------------------------------------------------------- Move up
1.65 albertel 972: } elsif ($env{'form.moveup'}) {
1.39 www 973: foreach (sort @targetselect) {
974: if ($_-1>0) {
975: my $movethis=$order[$_-1];
976: $order[$_-1]=$order[$_-2];
977: $order[$_-2]=$movethis;
978: }
979: }
980: &storemap(&Apache::lonnet::filelocation('',$url));
981: # ------------------------------------------------------------------ Move down
1.65 albertel 982: } elsif ($env{'form.movedown'}) {
1.39 www 983: foreach (reverse sort @targetselect) {
984: if ($_-1<$#order) {
985: my $movethis=$order[$_-1];
986: $order[$_-1]=$order[$_];
987: $order[$_]=$movethis;
988: }
989: }
990: &storemap(&Apache::lonnet::filelocation('',$url));
991: # --------------------------------------------------------------------- Rename
1.65 albertel 992: } elsif ($env{'form.renameres'}) {
993: my $residx=$Apache::lonratedt::order[$env{'form.renameidx'}-1];
1.39 www 994: my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);
1.65 albertel 995: $name=$env{'form.renametitle'};
1.40 www 996: $name=~s/\:/\&colon\;/g;
1.41 www 997: $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);
1.39 www 998: &storemap(&Apache::lonnet::filelocation('',$url));
1.13 www 999: }
1.12 www 1000: # ------------------------------------------------------------ Assemble windows
1.20 www 1001:
1.13 www 1002: my $idx=-1;
1.34 www 1003: $importdetail='&'.$importdetail;
1004: $importdetail=~s/^\&+/\&/;
1.29 www 1005: my $importwindow=
1.50 sakharuk 1006: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
1.29 www 1007: join("\n",map {
1.13 www 1008: $idx++;
1009: if ($_) {
1.15 www 1010: my ($name,$url)=split(/\=/,$_);
1011: unless ($name) { $name=(split(/\//,$url))[-1]; }
1012: unless ($name) { $name='EMPTY'; }
1.78 www 1013: '<option value="'.$idx.'">'.&unescape($name).
1.13 www 1014: '</option>';
1015: }
1016: } split(/\&/,$importdetail));
1.12 www 1017:
1.13 www 1018: $idx=0;
1.39 www 1019: $targetdetail='';
1.29 www 1020: my $targetwindow=
1.49 sakharuk 1021: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
1.29 www 1022: join("\n",map {
1.13 www 1023: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 1024: unless ($name) { $name=(split(/\//,$url))[-1]; }
1025: unless ($name) { $name='EMPTY'; }
1.78 www 1026: $targetdetail.='&'.&escape($name).'='.
1027: &escape($url);
1.13 www 1028: $idx++;
1.37 www 1029: $name=~s/\:/\:/g;
1.20 www 1030: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 1031: } @order);
1032:
1.8 www 1033: # ----------------------------------------------------- Start simple RAT screen
1.32 www 1034: my $editscript=&editscript('simple');
1.75 albertel 1035:
1.47 www 1036: my %lt=&Apache::lonlocal::texthash(
1037: 'sa' => 'Save',
1038: 'nt' => 'New Title',
1039: 'se' => 'Search',
1040: 'im' => 'Import',
1.80 www 1041: 'bk' => 'Import Bookmarks',
1.47 www 1042: 'vi' => 'View',
1043: 'lm' => 'Load Map',
1044: 'ds' => 'Discard Selected',
1045: 'ca' => 'Clear All',
1046: 'ta' => 'Temporary Assembly Workspace',
1047: 'rv' => 'Revert to Last Saved',
1048: 'sa' => 'Save',
1049: 'mu' => 'Move Up',
1050: 'md' => 'Move Down',
1051: 're' => 'Rename',
1.49 sakharuk 1052: 'as' => 'after selected',
1053: 'cs' => 'Cut selected',
1054: 'ps' => 'Copy selected',
1055: 'pas' => 'Paste after selected',
1.74 www 1056: 'reco' => 'Recover Deleted'
1.47 www 1057: );
1.75 albertel 1058: my $js=<<ENDJS;
1.77 albertel 1059: <script type="text/javascript">
1.15 www 1060:
1.32 www 1061: $editscript
1.19 www 1062:
1063: function openview(entry) {
1064: var url=unescape((entry.split('='))[1]);
1.20 www 1065: var parts=new Array;
1066: parts=url.split(':');
1067: url=parts.join(':');
1.19 www 1068: if (url) { open(url,'cat'); }
1069: }
1070:
1071: function viewtarget() {
1072: openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34 www 1073: [document.forms.simpleedit.target.selectedIndex]);
1.19 www 1074: }
1075:
1076: function viewimport() {
1077: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34 www 1078: [document.forms.simpleedit.importsel.selectedIndex]);
1.19 www 1079: }
1080:
1.39 www 1081: function renametarget() {
1082: var selidx=document.forms.simpleedit.target.selectedIndex;
1083: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
1084: [selidx];
1.41 www 1085: var oldname=unescape((entry.split('='))[0]);
1086: var nameparts=oldname.split(':');
1087: oldname=unescape(nameparts.join(':'));
1088: nameparts=oldname.split('"');
1089: oldname=unescape(nameparts.join('"'));
1090: nameparts=oldname.split(''');
1091: oldname=unescape(nameparts.join("'"));
1.47 www 1092: newtitle=prompt('$lt{'nt'}',oldname);
1.39 www 1093: if (newtitle) {
1094: document.forms.simpleedit.renameres.value=1;
1095: document.forms.simpleedit.renameidx.value=selidx;
1096: document.forms.simpleedit.renametitle.value=newtitle;
1097: document.forms.simpleedit.submit();
1098: }
1099: }
1100:
1.6 www 1101: </script>
1.75 albertel 1102: ENDJS
1103:
1.76 albertel 1104: my $start_page = &Apache::loncommon::start_page(undef,$js).
1.81 albertel 1105: &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
1.76 albertel 1106: 'Sequence_Simple_Editor_Creation',
1.81 albertel 1107: 6,'RAT');
1.75 albertel 1108: my $end_page = &Apache::loncommon::end_page();
1109:
1110: $r->print(<<ENDSMPHEAD);
1111: $start_page
1.8 www 1112: $buttons
1.7 www 1113: <font color=red>$errtext</font>
1.13 www 1114: <form name=simpleedit method=post>
1.11 www 1115: <input type=hidden name=forcesmp value=1>
1.39 www 1116: <input type=hidden name=renameres value=0>
1117: <input type=hidden name=renametitle value=''>
1118: <input type=hidden name=renameidx value=0>
1.11 www 1119: <table>
1.47 www 1120: <tr><th width="40%">$lt{'ta'}</th>
1.12 www 1121: <th> </th>
1.37 www 1122: <th width="40%">File: $url</th></tr>
1.12 www 1123: <tr><td bgcolor="#FFFFCC">
1.47 www 1124: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
1125: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
1.49 sakharuk 1126: $lt{'as'}
1.14 www 1127: <hr>
1.15 www 1128: <input type=text size=20 name=importmap>
1129: <input type=button
1130: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
1.47 www 1131: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
1132: <input type=submit name="discard" value="$lt{'ds'}">
1133: <input type=submit name="clear" value="$lt{'ca'}">
1134: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
1.16 www 1135:
1.12 www 1136: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 1137:
1138: <input type=button onClick=
1.47 www 1139: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
1.16 www 1140: <input type=button onClick=
1.47 www 1141: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
1.74 www 1142: <input type=button onClick=
1.80 www 1143: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}">
1144: <input type=button onClick=
1145: "javascript:impfortarget.value=1;groupopen('$url',1,0);" value="$lt{'reco'}">
1.49 sakharuk 1146: $lt{'as'}
1.39 www 1147: <hr>
1.47 www 1148: <input type=submit name="moveup" value="$lt{'mu'}">
1149: <input type=submit name="movedown" value="$lt{'md'}">
1150: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
1.34 www 1151: <hr>$targetmsg
1.47 www 1152: <input type=submit name="revert" value="$lt{'rv'}">
1153: <input type=submit name="save" value="$lt{'sa'}">
1154: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
1.12 www 1155: </td></tr>
1.16 www 1156:
1.27 www 1157: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12 www 1158: $importwindow
1159: </select>
1.11 www 1160: </td>
1.12 www 1161: <td bgcolor="#FFFFAA" align="center">
1.49 sakharuk 1162: $lt{'cs'}<br>
1.11 www 1163: <input type=submit name=cut value='<<<'><p>
1.12 www 1164: <hr>
1.49 sakharuk 1165: $lt{'ps'}<br>
1.25 www 1166: <input type=submit name=copy value='<--'><p>
1167: <hr>
1.49 sakharuk 1168: $lt{'pas'}<br>
1.25 www 1169: <input type=submit name=paste value='-->'>
1.11 www 1170: </td>
1.27 www 1171: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11 www 1172: $targetwindow
1173: </select>
1.12 www 1174: </table>
1.13 www 1175: <input type=hidden name=importdetail value="">
1176: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 1177: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 1178: <input type=hidden name=impfortarget value="0">
1.12 www 1179: </form>
1.75 albertel 1180: $end_page
1.3 www 1181: ENDSMPHEAD
1182: }
1183:
1.11 www 1184: # ----------------------------------------------------------------- No such dir
1.4 www 1185: sub nodir {
1186: my ($r,$dir)=@_;
1.75 albertel 1187: $dir=~s{^/home/\w+/public_html}{};
1188: $r->print(&Apache::loncommon::start_page(undef,undef,
1189: {'only_body' => 1,
1190: 'bgcolor' => '#FFFFFF',}).
1191: "<h1>No such directory: $dir</h1>".
1192: &Apache::loncommon::end_page());
1.4 www 1193: }
1194:
1.8 www 1195: # ---------------------------------------------------------------- View Handler
1196:
1197: sub viewmap {
1.17 www 1198: my ($r,$url,$adv,$errtext)=@_;
1.75 albertel 1199: $r->print(
1200: &Apache::loncommon::start_page('Edit Content of a Map').
1.81 albertel 1201: &Apache::loncommon::help_open_menu('','',6,'RAT').
1.53 www 1202: &buttons($adv));
1.10 www 1203: if ($errtext) {
1.53 www 1204: $r->print($errtext.'<hr />');
1.10 www 1205: }
1.26 www 1206: my $idx=0;
1.34 www 1207: $r->print('<h1>'.$url.'</h1>');
1.44 www 1208: if ($adv) {
1.47 www 1209: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.44 www 1210: }
1.64 raeburn 1211: $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
1212: '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
1213: '<th>'.&mt('Title in map').'</th>'.
1214: '<th>'.&mt('Filename of resource').'</th>'.
1215: '<th>'.&mt('Link to published resource').'</th>'.
1216: '<th>'.&mt('Link to resource in Construction Space').'</th>'.
1217: '</tr>');
1218: my @backgroundColors = ("#FFFFFF", "#F6F6F6");
1.17 www 1219: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 1220: if (defined($_)) {
1.26 www 1221: $idx++;
1.62 albertel 1222: my ($title,$url,$cond)=split(/\:/,$_);
1223: if ($cond eq 'cond') { next; }
1.9 www 1224: $title=~s/\&colon\;/\:/g;
1225: $url=~s/\&colon\;/\:/g;
1.15 www 1226: unless ($title) { $title=(split(/\//,$url))[-1] };
1.64 raeburn 1227: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
1228: my $resurl = &Apache::lonratsrv::qtescape($url);
1229: my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
1230: my $filename;
1231: if ($resurl =~ m#/([^/]+)$#) {
1232: $filename = $1;
1233: }
1234: my $cstrurl = $resurl;
1235: $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
1236: my $bgcol = $idx%2;
1237: $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
1238: '<img src="'.&Apache::loncommon::icon($resfilepath).
1239: '" /></td><td>'.&Apache::lonratsrv::qtescape($title).
1240: '</td><td>'.$filename.'</td><td>');
1241: if ($url) {
1.68 www 1242: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
1.64 raeburn 1243: }
1244: $r->print('</td><td>');
1.9 www 1245: if ($url) {
1.64 raeburn 1246: $r->print('<a href="'.$cstrurl.'">'.
1247: &mt('Construction space').'</a>');
1.9 www 1248: }
1.64 raeburn 1249: $r->print('</td></tr>'."\n");
1.9 www 1250: }
1251: }
1.64 raeburn 1252: $r->print('</table>');
1.75 albertel 1253: $r->print(&Apache::loncommon::end_page());
1.8 www 1254: }
1255:
1.3 www 1256: # ================================================================ Main Handler
1257:
1258: sub handler {
1259: my $r=shift;
1.47 www 1260: &Apache::loncommon::content_type($r,'text/html');
1.3 www 1261: $r->send_http_header;
1262:
1263: return OK if $r->header_only;
1.65 albertel 1264: my $target = $env{'form.grade_target'};
1.48 albertel 1265: if ($target eq 'meta') {
1266: &Apache::loncommon::content_type($r,'text/html');
1267: $r->send_http_header;
1268: return OK;
1269: }
1270:
1.3 www 1271: my $url=$r->uri;
1272: my $fn=&Apache::lonnet::filelocation('',$url);
1273:
1.4 www 1274: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
1275: unless (-e $dir) {
1276: &nodir($r,$dir);
1277: return OK;
1278: }
1.8 www 1279:
1280: # ------------------------------------------- Determine which tools can be used
1.3 www 1281: my $adv=0;
1282:
1.65 albertel 1283: unless ($env{'form.forcesmp'}) {
1284: if ($env{'form.forceadv'}) {
1.3 www 1285: $adv=1;
1286: } elsif (my $fh=Apache::File->new($fn)) {
1287: my $allmap=join('',<$fh>);
1288: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
1289: }
1290: }
1291:
1.8 www 1292: my $errtext='';
1293: my $fatal=0;
1294:
1295: # -------------------------------------------------------------------- Load map
1296: ($errtext,$fatal)=&mapread($fn,$errtext);
1297:
1298: if ($fatal==1) { $adv=1; }
1299:
1300: # ----------------------------------- adv==1 now means "graphical MUST be used"
1301:
1.65 albertel 1302: if ($env{'form.forceadv'}) {
1.3 www 1303: &ratedt($r,$url);
1.65 albertel 1304: } elsif ($env{'form.forcesmp'}) {
1.22 www 1305: &smpedt($r,$url,$errtext);
1.3 www 1306: } else {
1.17 www 1307: &viewmap($r,$url,$adv,$errtext);
1.3 www 1308: }
1.1 www 1309: return OK;
1310: }
1311:
1312: 1;
1313: __END__
1314:
1315:
1316:
1317:
1318:
1319:
1320:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>