Annotation of rat/lonratedt.pm, revision 1.69
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.69 ! www 4: # $Id: lonratedt.pm,v 1.68 2005/06/08 16:10:01 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.67 www 176: use vars qw(@order @resources @resparms @zombies %revzombies);
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.58 www 190: undef @resparms;
1.67 www 191: undef @zombies;
192: undef %revzombies;
193:
1.23 www 194: @resources=('');
195: @order=();
1.58 www 196: @resparms=();
1.67 www 197: @zombies=();
198: %revzombies=();
1.8 www 199:
200: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
201: if ($errtext) { return ($errtext,2); }
202:
1.9 www 203: # -------------------------------------------------------------------- Read map
1.8 www 204: foreach (split(/\<\&\>/,$outtext)) {
1.9 www 205: my ($command,$number,$content)=split(/\<\:\>/,$_);
1.8 www 206: if ($command eq 'objcont') {
1.67 www 207: my ($title,$src,$ext,$type)=split(/\:/,$content);
1.69 ! www 208: if ($ext eq 'cond') { next; }
1.67 www 209: if ($type ne 'zombie') {
210: $resources[$number]=$content;
211: } else {
212: $zombies[$number]=$content;
213: $revzombies{$src}=$number;
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.63 raeburn 411: my $frameset = '<frameset rows="1,70,*" border="0">';
1.65 albertel 412: if ($env{'environment.remote'} eq 'off') {
1.63 raeburn 413: $frameset = '<frameset rows="1,250,*" border="0">';
414: }
1.1 www 415: $r->print(<<ENDDOCUMENT);
416:
417: <html>
1.2 harris41 418: <head>
419: <script language="JavaScript">
420: var flag=0;
421: </script>
422: </head>
1.63 raeburn 423: $frameset
1.1 www 424: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
1.63 raeburn 425: <frame name=code src="$url/loadonly/adveditmenu">
1.1 www 426: <frame name=mapout src="/adm/rat/map.html">
427: </frameset>
428: </html>
429:
430: ENDDOCUMENT
1.3 www 431: }
432:
1.8 www 433: # ---------------------------------------------------------------- Make buttons
434:
435: sub buttons {
436: my $adv=shift;
437: my $output='<form method=post>';
438: if ($adv==1) {
1.52 www 439: $output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
440: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
1.8 www 441: } else {
442: unless ($adv==2) {
1.52 www 443: $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
444: &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
1.8 www 445: }
1.52 www 446: $output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
447: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
1.8 www 448: }
449: return $output.'</form><hr>';
450: }
451:
1.68 www 452: # ----------------------------------------------------- Get an unused res index
453:
454: sub unusedindex {
455: return 1+($#resources>$#zombies?$#resources:$#zombies);
456: }
457:
1.20 www 458: # ----------------------------------------------------------- Paste into target
459: # modifies @order, @resources
460:
461: sub pastetarget {
462: my ($after,@which)=@_;
463: my @insertorder=();
464: foreach (@which) {
465: if (defined($_)) {
466: my ($name,$url)=split(/\=/,$_);
1.21 www 467: $name=&Apache::lonnet::unescape($name);
468: $url=&Apache::lonnet::unescape($url);
469: if ($url) {
1.68 www 470: my $idx=&unusedindex();
1.21 www 471: $insertorder[$#insertorder+1]=$idx;
472: my $ext='false';
473: if ($url=~/^http\:\/\//) { $ext='true'; }
474: $url=~s/\:/\:/g;
1.37 www 475: $name=~s/\:/\:/g;
1.21 www 476: $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
477: }
1.20 www 478: }
479: }
1.23 www 480: my @oldorder=splice(@order,$after);
481: @order=(@order,@insertorder,@oldorder);
1.21 www 482: }
483:
484: # ------------------------------------------------ Get start and finish correct
485: # modifies @resources
486:
487: sub startfinish {
1.43 www 488: # Remove all start and finish
1.21 www 489: foreach (@order) {
490: my ($name,$url,$ext)=split(/\:/,$resources[$_]);
1.22 www 491: if ($url=~/http\&colon\:\/\//) { $ext='true'; }
1.21 www 492: $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
493: }
1.43 www 494: # Garbage collection
495: my $stillchange=1;
496: while (($#order>1) && ($stillchange)) {
497: $stillchange=0;
498: for (my $i=0;$i<=$#order;$i++) {
499: my ($name,$url,$ext)=split(/\:/,$resources[$order[$i]]);
500: unless ($url) {
501: # Take out empty resource
502: for (my $j=$i+1;$j<=$#order;$j++) {
503: $order[$j-1]=$order[$j];
504: }
505: $#order--;
506: $stillchange=1;
507: last;
508: }
509: }
510: }
511: # Put in a start resource
1.23 www 512: my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
513: $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
1.43 www 514: # Make sure this has at least start and finish
1.33 www 515: if ($#order==0) {
1.68 www 516: $resources[&unusedindex()]='::false';
1.33 www 517: $order[1]=$#resources;
518: }
1.43 www 519: # Make the last one a finish resource
1.42 www 520: ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
1.21 www 521: $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
1.20 www 522: }
523:
1.22 www 524: # ------------------------------------------------------------------- Store map
525:
526: sub storemap {
1.34 www 527: my $realfn=shift;
1.35 www 528: my $fn=$realfn;
529: # unless this is forced to work from the original file, use a temporary file
530: # instead
531: unless (shift) {
532: $fn=$realfn.'.tmp';
533: unless (-e $fn) {
534: copy($realfn,$fn);
535: }
1.34 www 536: }
1.35 www 537: # store data either into tmp or real file
1.22 www 538: &startfinish();
539: my $output='graphdef<:>no';
540: my $k=1;
541: for (my $i=0; $i<=$#order; $i++) {
542: if (defined($resources[$order[$i]])) {
543: $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
544: }
1.54 www 545: if (defined($resparms[$order[$i]])) {
1.55 www 546: foreach (split('&&&',$resparms[$order[$i]])) {
547: if ($_) {
548: $output.='<&>objparms<:>'.$order[$i].'<:>'.$_;
549: }
550: }
1.54 www 551: }
1.22 www 552: if (defined($order[$i+1])) {
553: if (defined($resources[$order[$i+1]])) {
554: $output.='<&>objlinks<:>'.$k.'<:>'.
555: $order[$i].':'.$order[$i+1].':0';
556: $k++;
557: }
558: }
559: }
1.69 ! www 560: for (my $i=0; $i<=$#zombies; $i++) {
! 561: if (defined($zombies[$i])) {
! 562: $output.='<&>objcont<:>'.$i.'<:>'.$zombies[$i];
! 563: }
! 564: }
1.23 www 565: $output=~s/http\&colon\;\/\///g;
1.65 albertel 566: $env{'form.output'}=$output;
1.22 www 567: return
568: &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
569: }
570:
1.56 www 571: # ------------------------------------------ Store and get parameters in global
572:
573: sub storeparameter {
574: my ($to,$name,$value,$ptype)=@_;
575: my $newentry='';
576: my $nametype='';
577: foreach (split('&&&',$resparms[$to])) {
578: my ($thistype,$thisname,$thisvalue)=split('___',$_);
579: if ($thisname) {
580: unless ($thisname eq $name) {
581: $newentry.=$_.'&&&';
582: } else {
583: $nametype=$thistype;
584: }
585: }
586: }
587: unless ($ptype) { $ptype=$nametype; }
588: unless ($ptype) { $ptype='string'; }
589: $newentry.=$ptype.'___'.$name.'___'.$value;
1.57 www 590: $resparms[$to]=$newentry;
591: }
592:
593: sub delparameter {
594: my ($to,$name)=@_;
595: my $newentry='';
596: my $nametype='';
597: foreach (split('&&&',$resparms[$to])) {
598: my ($thistype,$thisname,$thisvalue)=split('___',$_);
599: if ($thisname) {
600: unless ($thisname eq $name) {
601: $newentry.=$_.'&&&';
602: }
603: }
604: }
1.56 www 605: $resparms[$to]=$newentry;
606: }
607:
608: sub getparameter {
1.58 www 609: my ($to,$name)=@_;
1.56 www 610: my $value=undef;
611: my $ptype=undef;
612: foreach (split('&&&',$resparms[$to])) {
613: my ($thistype,$thisname,$thisvalue)=split('___',$_);
614: if ($thisname eq $name) {
615: $value=$thisvalue;
616: $ptype=$thistype;
617: }
618: }
619: return ($value,$ptype);
620: }
621:
622: # ----------------------------------------------------------------- Edit script
1.32 www 623: sub editscript {
624: my $mode=shift;
1.51 www 625: my $resurl=&Apache::loncommon::lastresurl();
1.32 www 626: return(<<ENDSCRIPT);
627: var srch;
628: var srchflag=-1; // 1 means currently open
629: // 0 means closed (but has been open)
630: // -1 means never yet opened/defined
631: var srchmode='';
632:
633: var idx;
634: var idxflag=-1; // 1 means currently open
635: // 0 means closed (but has been open)
636: // -1 means never yet opened/defined
637: var idxmode='';
638:
639: // ------------------------------------------------------ Clears indexer window
640: function idxclear() {
641: idx.document.clear();
642: }
643:
644: // ------------------------------------------------------- Clears search window
645: function srchclear() {
646: srch.document.clear();
647: }
648:
649: // ------------------------------------------------------ Closes indexer window
650: function idxclose() {
651: if (idx && !idx.closed) {
652: idxflag=0;
653: idx.close();
654: }
655: }
656:
657: // ------------------------------------------------------- Closes search window
658: function srchclose() {
659: if (srch && !srch.closed) {
660: srchflag=0;
661: srch.close();
662: }
663: }
664:
665: // -------------------------------------------------------- Open indexer window
666: function idxopen(mode) {
667: var options="scrollbars=1,resizable=1,menubar=0";
668: idxmode=mode;
669: idxflag=1;
1.51 www 670: idx=open("$resurl/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
1.32 www 671: idx.focus();
672: }
673:
674: // --------------------------------------------------------- Open search window
675: function srchopen(mode) {
676: var options="scrollbars=1,resizable=1,menubar=0";
677: srchmode=mode;
678: srchflag=1;
679: srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
680: srch.focus();
681: }
682: // ----------------------------------------------------- launch indexer browser
683: function groupsearch() {
684: srchcheck('groupsearch');
685: }
686:
687: function groupimport() {
688: idxcheck('groupimport');
689: }
690: // ------------------------------------------------------- Do srch status check
691: function srchcheck(mode) {
692: if (!srch || srch.closed || srchmode!=mode) {
693: srchopen(mode);
694: }
695: srch.focus();
696: }
697:
698: // -------------------------------------------------------- Do idx status check
699: function idxcheck(mode) {
700: if (!idx || idx.closed || idxmode!=mode) {
701: idxopen(mode);
702: }
703: idx.focus();
704: }
705:
706:
707: var editbrowser;
708: function openbrowser(formname,elementname,only,omit) {
1.51 www 709: var url = '$resurl/?';
1.32 www 710: if (editbrowser == null) {
711: url += 'launch=1&';
712: }
713: url += 'catalogmode=interactive&';
714: url += 'mode=edit&';
715: url += 'form=' + formname + '&';
716: if (only != null) {
717: url += 'only=' + only + '&';
718: }
719: if (omit != null) {
720: url += 'omit=' + omit + '&';
721: }
722: url += 'element=' + elementname + '';
723: var title = 'Browser';
724: var options = 'scrollbars=1,resizable=1,menubar=0';
725: options += ',width=700,height=600';
726: editbrowser = open(url,title,options,'1');
727: editbrowser.focus();
728: }
729: ENDSCRIPT
730: }
1.20 www 731: # ------------------------------------------------------- Simple edit processor
732:
1.3 www 733: sub smpedt {
1.22 www 734: my ($r,$url,$errtext)=@_;
1.8 www 735: my $buttons=&buttons(2);
1.34 www 736: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
737: my $targetmsg='';
1.65 albertel 738: if ($env{'form.save'}) {
1.34 www 739: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
740: unlink($tmpfn);
1.35 www 741: my ($errtext,$fatal)=
742: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.60 www 743: unless ($fatal) {
744: $targetmsg='<b>'.&mt('Saved.').'</b><br />';
745: } else {
746: $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
747: }
1.34 www 748: }
1.65 albertel 749: if ($env{'form.revert'}) {
1.60 www 750: $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
1.34 www 751: unlink($tmpfn);
1.35 www 752: my ($errtext,$fatal)=
753: &mapread(&Apache::lonnet::filelocation('',$url),'');
1.34 www 754: }
755: if (-e $tmpfn) {
756: $targetmsg=
1.49 sakharuk 757: '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
1.34 www 758: my ($errtext,$fatal)=&mapread($tmpfn,'');
759: }
1.12 www 760: # ---------------------------------------------------------- Process form input
761:
1.66 albertel 762: my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
763: my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
1.13 www 764: # ============================================================ Process commands
1.12 www 765:
1.65 albertel 766: my $targetdetail=$env{'form.targetdetail'};
767: my $importdetail=$env{'form.curimpdetail'};
1.13 www 768:
769: # ---------------------------------------------------- Importing from groupsort
1.65 albertel 770: if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
1.13 www 771:
1.14 www 772: $importdetail='';
1.65 albertel 773: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.13 www 774:
775: my $lastsel;
776:
777: if (defined($importselect[-1])) {
778: $lastsel=$importselect[-1];
779: } else {
780: $lastsel=$#curimport;
781: }
782:
783: for (my $i=0;$i<=$lastsel;$i++) {
784: my ($name,$url)=split(/\=/,$curimport[$i]);
785: if ($url) {
1.18 www 786: $importdetail.='&'.$name.'='.$url;
1.13 www 787: }
788: }
789:
1.65 albertel 790: $importdetail.='&'.$env{'form.importdetail'};
1.13 www 791:
792: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
793: my ($name,$url)=split(/\=/,$curimport[$i]);
794: if ($url) {
1.18 www 795: $importdetail.='&'.$name.'='.$url;
1.13 www 796: }
797: }
798: $importdetail=~s/\&+/\&/g;
799: $importdetail=~s/^\&//;
800:
1.14 www 801: # ------------------------------------------------------------------- Clear all
1.65 albertel 802: } elsif ($env{'form.clear'}) {
1.14 www 803: $importdetail='';
804: # ------------------------------------------------------------ Discard selected
1.65 albertel 805: } elsif ($env{'form.discard'}) {
1.14 www 806: $importdetail='';
1.65 albertel 807: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.14 www 808: foreach (@importselect) {
809: $curimport[$_]='';
810: }
811: for (my $i=0;$i<=$#curimport;$i++) {
812: my ($name,$url)=split(/\=/,$curimport[$i]);
813: if ($url) {
1.18 www 814: $importdetail.='&'.$name.'='.$url;
1.14 www 815: }
816: }
1.17 www 817: # --------------------------------------------------------- Loading another map
1.65 albertel 818: } elsif ($env{'form.loadmap'}) {
1.17 www 819: $importdetail='';
1.65 albertel 820: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.17 www 821:
822: my $lastsel;
823:
824: if (defined($importselect[-1])) {
825: $lastsel=$importselect[-1];
826: } else {
827: $lastsel=$#curimport;
828: }
829:
830: for (my $i=0;$i<=$lastsel;$i++) {
831: my ($name,$url)=split(/\=/,$curimport[$i]);
832: if ($url) {
1.18 www 833: $importdetail.='&'.$name.'='.$url;
1.17 www 834: }
835: }
836:
837: foreach (
1.65 albertel 838: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.17 www 839: my ($name,$url)=split(/\:/,$_);
840: if ($url) {
841: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
842: &Apache::lonnet::escape($url);
843: }
844: }
845:
846: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
847: my ($name,$url)=split(/\=/,$curimport[$i]);
848: if ($url) {
1.18 www 849: $importdetail.='&'.$name.'='.$url;
1.17 www 850: }
851: }
852: $importdetail=~s/\&+/\&/g;
853: $importdetail=~s/^\&//;
854:
1.20 www 855: # ------------------------------------------------ Groupimport/search to target
1.65 albertel 856: } elsif ($env{'form.importdetail'}) {
1.20 www 857: my $lastsel;
858: if (defined($targetselect[-1])) {
859: $lastsel=$targetselect[-1];
860: } else {
1.23 www 861: $lastsel=$#order+1;
1.20 www 862: }
1.65 albertel 863: &pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
1.22 www 864: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 865: # ------------------------------------------------------------------------- Cut
1.65 albertel 866: } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
1.25 www 867: $importdetail='';
1.65 albertel 868: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.25 www 869:
870: my $lastsel;
871:
872: if (defined($importselect[-1])) {
873: $lastsel=$importselect[-1];
874: } else {
875: $lastsel=$#curimport;
876: }
877:
878: for (my $i=0;$i<=$lastsel;$i++) {
879: my ($name,$url)=split(/\=/,$curimport[$i]);
880: if ($url) {
881: $importdetail.='&'.$name.'='.$url;
882: }
883: }
884:
885: foreach (@targetselect) {
886: my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
887: if ($url) {
888: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
889: &Apache::lonnet::escape($url);
890: }
891: }
892:
893: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
894: my ($name,$url)=split(/\=/,$curimport[$i]);
895: if ($url) {
896: $importdetail.='&'.$name.'='.$url;
897: }
898: }
899: $importdetail=~s/\&+/\&/g;
900: $importdetail=~s/^\&//;
901:
1.65 albertel 902: if ($env{'form.cut'}) {
1.25 www 903: my @neworder=();
904: for (my $i=0;$i<=$#order;$i++) {
905: my $include=1;
906: foreach (@targetselect) {
907: if ($_-1==$i) { $include=0; }
908: }
909: if ($include) { $neworder[$#neworder+1]=$order[$i]; }
910: }
911: @order=@neworder;
912: &storemap(&Apache::lonnet::filelocation('',$url));
913: }
914:
1.20 www 915: # ----------------------------------------------------------------------- Paste
1.65 albertel 916: } elsif ($env{'form.paste'}) {
1.24 www 917: my $lastsel;
918: if (defined($targetselect[-1])) {
919: $lastsel=$targetselect[-1];
920: } else {
921: $lastsel=$#order+1;
922: }
923: my @newsequence;
1.65 albertel 924: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.24 www 925: foreach (@importselect) {
926: $newsequence[$#newsequence+1]=$curimport[$_];
927: }
928: &pastetarget($lastsel,@newsequence);
929: &storemap(&Apache::lonnet::filelocation('',$url));
1.39 www 930: # -------------------------------------------------------------------- Move up
1.65 albertel 931: } elsif ($env{'form.moveup'}) {
1.39 www 932: foreach (sort @targetselect) {
933: if ($_-1>0) {
934: my $movethis=$order[$_-1];
935: $order[$_-1]=$order[$_-2];
936: $order[$_-2]=$movethis;
937: }
938: }
939: &storemap(&Apache::lonnet::filelocation('',$url));
940: # ------------------------------------------------------------------ Move down
1.65 albertel 941: } elsif ($env{'form.movedown'}) {
1.39 www 942: foreach (reverse sort @targetselect) {
943: if ($_-1<$#order) {
944: my $movethis=$order[$_-1];
945: $order[$_-1]=$order[$_];
946: $order[$_]=$movethis;
947: }
948: }
949: &storemap(&Apache::lonnet::filelocation('',$url));
950: # --------------------------------------------------------------------- Rename
1.65 albertel 951: } elsif ($env{'form.renameres'}) {
952: my $residx=$Apache::lonratedt::order[$env{'form.renameidx'}-1];
1.39 www 953: my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);
1.65 albertel 954: $name=$env{'form.renametitle'};
1.40 www 955: $name=~s/\:/\&colon\;/g;
1.41 www 956: $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);
1.39 www 957: &storemap(&Apache::lonnet::filelocation('',$url));
1.13 www 958: }
1.12 www 959: # ------------------------------------------------------------ Assemble windows
1.20 www 960:
1.13 www 961: my $idx=-1;
1.34 www 962: $importdetail='&'.$importdetail;
963: $importdetail=~s/^\&+/\&/;
1.29 www 964: my $importwindow=
1.50 sakharuk 965: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
1.29 www 966: join("\n",map {
1.13 www 967: $idx++;
968: if ($_) {
1.15 www 969: my ($name,$url)=split(/\=/,$_);
970: unless ($name) { $name=(split(/\//,$url))[-1]; }
971: unless ($name) { $name='EMPTY'; }
1.13 www 972: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
973: '</option>';
974: }
975: } split(/\&/,$importdetail));
1.12 www 976:
1.13 www 977: $idx=0;
1.39 www 978: $targetdetail='';
1.29 www 979: my $targetwindow=
1.49 sakharuk 980: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
1.29 www 981: join("\n",map {
1.13 www 982: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 983: unless ($name) { $name=(split(/\//,$url))[-1]; }
984: unless ($name) { $name='EMPTY'; }
1.13 www 985: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
986: &Apache::lonnet::escape($url);
987: $idx++;
1.37 www 988: $name=~s/\:/\:/g;
1.20 www 989: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 990: } @order);
991:
1.8 www 992: # ----------------------------------------------------- Start simple RAT screen
1.32 www 993: my $editscript=&editscript('simple');
1.61 albertel 994: my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
1.65 albertel 995: ($env{'environment.remote'} ne 'off')).
1.59 albertel 996: &Apache::loncommon::help_open_menu('','Sequence_Simple_Editor_Creation','Sequence_Simple_Editor_Creation','',6,'RAT');
1.47 www 997: my %lt=&Apache::lonlocal::texthash(
998: 'sa' => 'Save',
999: 'nt' => 'New Title',
1000: 'se' => 'Search',
1001: 'im' => 'Import',
1002: 'vi' => 'View',
1003: 'lm' => 'Load Map',
1004: 'ds' => 'Discard Selected',
1005: 'ca' => 'Clear All',
1006: 'ta' => 'Temporary Assembly Workspace',
1007: 'rv' => 'Revert to Last Saved',
1008: 'sa' => 'Save',
1009: 'mu' => 'Move Up',
1010: 'md' => 'Move Down',
1011: 're' => 'Rename',
1.49 sakharuk 1012: 'as' => 'after selected',
1013: 'cs' => 'Cut selected',
1014: 'ps' => 'Copy selected',
1015: 'pas' => 'Paste after selected',
1.47 www 1016: );
1.3 www 1017: $r->print(<<ENDSMPHEAD);
1018: <html>
1.6 www 1019: <head>
1020: <script>
1.15 www 1021:
1.32 www 1022: $editscript
1.19 www 1023:
1024: function openview(entry) {
1025: var url=unescape((entry.split('='))[1]);
1.20 www 1026: var parts=new Array;
1027: parts=url.split(':');
1028: url=parts.join(':');
1.19 www 1029: if (url) { open(url,'cat'); }
1030: }
1031:
1032: function viewtarget() {
1033: openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34 www 1034: [document.forms.simpleedit.target.selectedIndex]);
1.19 www 1035: }
1036:
1037: function viewimport() {
1038: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34 www 1039: [document.forms.simpleedit.importsel.selectedIndex]);
1.19 www 1040: }
1041:
1.39 www 1042: function renametarget() {
1043: var selidx=document.forms.simpleedit.target.selectedIndex;
1044: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
1045: [selidx];
1.41 www 1046: var oldname=unescape((entry.split('='))[0]);
1047: var nameparts=oldname.split(':');
1048: oldname=unescape(nameparts.join(':'));
1049: nameparts=oldname.split('"');
1050: oldname=unescape(nameparts.join('"'));
1051: nameparts=oldname.split(''');
1052: oldname=unescape(nameparts.join("'"));
1.47 www 1053: newtitle=prompt('$lt{'nt'}',oldname);
1.39 www 1054: if (newtitle) {
1055: document.forms.simpleedit.renameres.value=1;
1056: document.forms.simpleedit.renameidx.value=selidx;
1057: document.forms.simpleedit.renametitle.value=newtitle;
1058: document.forms.simpleedit.submit();
1059: }
1060: }
1061:
1.6 www 1062: </script>
1063: </head>
1.34 www 1064: $bodytag
1.8 www 1065: $buttons
1.7 www 1066: <font color=red>$errtext</font>
1.13 www 1067: <form name=simpleedit method=post>
1.11 www 1068: <input type=hidden name=forcesmp value=1>
1.39 www 1069: <input type=hidden name=renameres value=0>
1070: <input type=hidden name=renametitle value=''>
1071: <input type=hidden name=renameidx value=0>
1.11 www 1072: <table>
1.47 www 1073: <tr><th width="40%">$lt{'ta'}</th>
1.12 www 1074: <th> </th>
1.37 www 1075: <th width="40%">File: $url</th></tr>
1.12 www 1076: <tr><td bgcolor="#FFFFCC">
1.47 www 1077: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
1078: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
1.49 sakharuk 1079: $lt{'as'}
1.14 www 1080: <hr>
1.15 www 1081: <input type=text size=20 name=importmap>
1082: <input type=button
1083: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
1.47 www 1084: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
1085: <input type=submit name="discard" value="$lt{'ds'}">
1086: <input type=submit name="clear" value="$lt{'ca'}">
1087: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
1.16 www 1088:
1.12 www 1089: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 1090:
1091: <input type=button onClick=
1.47 www 1092: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
1.16 www 1093: <input type=button onClick=
1.47 www 1094: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
1.49 sakharuk 1095: $lt{'as'}
1.39 www 1096: <hr>
1.47 www 1097: <input type=submit name="moveup" value="$lt{'mu'}">
1098: <input type=submit name="movedown" value="$lt{'md'}">
1099: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
1.34 www 1100: <hr>$targetmsg
1.47 www 1101: <input type=submit name="revert" value="$lt{'rv'}">
1102: <input type=submit name="save" value="$lt{'sa'}">
1103: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
1.12 www 1104: </td></tr>
1.16 www 1105:
1.27 www 1106: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12 www 1107: $importwindow
1108: </select>
1.11 www 1109: </td>
1.12 www 1110: <td bgcolor="#FFFFAA" align="center">
1.49 sakharuk 1111: $lt{'cs'}<br>
1.11 www 1112: <input type=submit name=cut value='<<<'><p>
1.12 www 1113: <hr>
1.49 sakharuk 1114: $lt{'ps'}<br>
1.25 www 1115: <input type=submit name=copy value='<--'><p>
1116: <hr>
1.49 sakharuk 1117: $lt{'pas'}<br>
1.25 www 1118: <input type=submit name=paste value='-->'>
1.11 www 1119: </td>
1.27 www 1120: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11 www 1121: $targetwindow
1122: </select>
1.12 www 1123: </table>
1.13 www 1124: <input type=hidden name=importdetail value="">
1125: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 1126: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 1127: <input type=hidden name=impfortarget value="0">
1.12 www 1128: </form>
1129: </body></html>
1.3 www 1130: ENDSMPHEAD
1131: }
1132:
1.11 www 1133: # ----------------------------------------------------------------- No such dir
1.4 www 1134: sub nodir {
1135: my ($r,$dir)=@_;
1136: $dir=~s/^\/home\/\w+\/public\_html//;
1137: $r->print(<<ENDNODIR);
1138: <html>
1139: <body bgcolor='#FFFFFF'>
1140: <h1>No such directory: $dir</h1>
1141: </body>
1142: </html>
1143: ENDNODIR
1144: }
1145:
1.8 www 1146: # ---------------------------------------------------------------- View Handler
1147:
1148: sub viewmap {
1.17 www 1149: my ($r,$url,$adv,$errtext)=@_;
1.34 www 1150: $r->print('<html>'.
1151: &Apache::loncommon::bodytag('Edit Content of a Map').
1.59 albertel 1152: &Apache::loncommon::help_open_menu('','','','',6,'RAT').
1.53 www 1153: &buttons($adv));
1.10 www 1154: if ($errtext) {
1.53 www 1155: $r->print($errtext.'<hr />');
1.10 www 1156: }
1.26 www 1157: my $idx=0;
1.34 www 1158: $r->print('<h1>'.$url.'</h1>');
1.44 www 1159: if ($adv) {
1.47 www 1160: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.44 www 1161: }
1.64 raeburn 1162: $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
1163: '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
1164: '<th>'.&mt('Title in map').'</th>'.
1165: '<th>'.&mt('Filename of resource').'</th>'.
1166: '<th>'.&mt('Link to published resource').'</th>'.
1167: '<th>'.&mt('Link to resource in Construction Space').'</th>'.
1168: '</tr>');
1169: my @backgroundColors = ("#FFFFFF", "#F6F6F6");
1.17 www 1170: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 1171: if (defined($_)) {
1.26 www 1172: $idx++;
1.62 albertel 1173: my ($title,$url,$cond)=split(/\:/,$_);
1174: if ($cond eq 'cond') { next; }
1.9 www 1175: $title=~s/\&colon\;/\:/g;
1176: $url=~s/\&colon\;/\:/g;
1.15 www 1177: unless ($title) { $title=(split(/\//,$url))[-1] };
1.64 raeburn 1178: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
1179: my $resurl = &Apache::lonratsrv::qtescape($url);
1180: my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
1181: my $filename;
1182: if ($resurl =~ m#/([^/]+)$#) {
1183: $filename = $1;
1184: }
1185: my $cstrurl = $resurl;
1186: $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
1187: my $bgcol = $idx%2;
1188: $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
1189: '<img src="'.&Apache::loncommon::icon($resfilepath).
1190: '" /></td><td>'.&Apache::lonratsrv::qtescape($title).
1191: '</td><td>'.$filename.'</td><td>');
1192: if ($url) {
1.68 www 1193: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
1.64 raeburn 1194: }
1195: $r->print('</td><td>');
1.9 www 1196: if ($url) {
1.64 raeburn 1197: $r->print('<a href="'.$cstrurl.'">'.
1198: &mt('Construction space').'</a>');
1.9 www 1199: }
1.64 raeburn 1200: $r->print('</td></tr>'."\n");
1.9 www 1201: }
1202: }
1.64 raeburn 1203: $r->print('</table>');
1.8 www 1204: $r->print('</body></html>');
1205: }
1206:
1.3 www 1207: # ================================================================ Main Handler
1208:
1209: sub handler {
1210: my $r=shift;
1.47 www 1211: &Apache::loncommon::content_type($r,'text/html');
1.3 www 1212: $r->send_http_header;
1213:
1214: return OK if $r->header_only;
1.65 albertel 1215: my $target = $env{'form.grade_target'};
1.48 albertel 1216: if ($target eq 'meta') {
1217: &Apache::loncommon::content_type($r,'text/html');
1218: $r->send_http_header;
1219: return OK;
1220: }
1221:
1.3 www 1222: my $url=$r->uri;
1223: my $fn=&Apache::lonnet::filelocation('',$url);
1224:
1.4 www 1225: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
1226: unless (-e $dir) {
1227: &nodir($r,$dir);
1228: return OK;
1229: }
1.8 www 1230:
1231: # ------------------------------------------- Determine which tools can be used
1.3 www 1232: my $adv=0;
1233:
1.65 albertel 1234: unless ($env{'form.forcesmp'}) {
1235: if ($env{'form.forceadv'}) {
1.3 www 1236: $adv=1;
1237: } elsif (my $fh=Apache::File->new($fn)) {
1238: my $allmap=join('',<$fh>);
1239: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
1240: }
1241: }
1242:
1.8 www 1243: my $errtext='';
1244: my $fatal=0;
1245:
1246: # -------------------------------------------------------------------- Load map
1247: ($errtext,$fatal)=&mapread($fn,$errtext);
1248:
1249: if ($fatal==1) { $adv=1; }
1250:
1251: # ----------------------------------- adv==1 now means "graphical MUST be used"
1252:
1.65 albertel 1253: if ($env{'form.forceadv'}) {
1.3 www 1254: &ratedt($r,$url);
1.65 albertel 1255: } elsif ($env{'form.forcesmp'}) {
1.22 www 1256: &smpedt($r,$url,$errtext);
1.3 www 1257: } else {
1.17 www 1258: &viewmap($r,$url,$adv,$errtext);
1.3 www 1259: }
1.1 www 1260: return OK;
1261: }
1262:
1263: 1;
1264: __END__
1265:
1266:
1267:
1268:
1269:
1270:
1271:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>