Annotation of rat/lonratedt.pm, revision 1.21
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.21 ! www 4: # $Id: lonratedt.pm,v 1.20 2002/05/16 21:10:05 www Exp $
1.5 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: # (TeX Content Handler
29: #
30: # 05/29/00,05/30 Gerd Kortemeyer)
1.4 www 31: # 7/1,6/30 Gerd Kortemeyer
1.1 www 32:
33: package Apache::lonratedt;
34:
35: use strict;
36: use Apache::Constants qw(:common);
1.3 www 37: use Apache::lonnet;
1.7 www 38: use Apache::lonratsrv;
1.1 www 39:
1.10 www 40: my @order=();
1.8 www 41: my @resources=();
42:
43:
44: # Mapread read maps into global arrays @links and @resources, determines status
1.10 www 45: # sets @order - pointer to resources in right order
46: # sets @resources - array with the resources with correct idx
47: #
1.8 www 48: sub mapread {
49: my $fn=shift;
50:
1.10 www 51: my @links;
1.8 www 52: undef @links;
53: undef @resources;
1.10 www 54: undef @order;
1.8 www 55:
56: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
57: if ($errtext) { return ($errtext,2); }
58:
1.9 www 59: # -------------------------------------------------------------------- Read map
1.8 www 60: foreach (split(/\<\&\>/,$outtext)) {
1.9 www 61: my ($command,$number,$content)=split(/\<\:\>/,$_);
1.8 www 62: if ($command eq 'objcont') {
1.9 www 63: $resources[$number]=$content;
1.8 www 64: }
65: if ($command eq 'objlinks') {
1.9 www 66: $links[$number]=$content;
67: }
68: }
69: # ------------------------------------------------------- Is this a linear map?
70: my @starters=();
71: my @endings=();
72: undef @starters;
73: undef @endings;
74:
75: foreach (@links) {
76: if (defined($_)) {
77: my ($start,$end,$cond)=split(/\:/,$_);
78: if ((defined($starters[$start])) || (defined($endings[$end]))) {
1.8 www 79: return
1.10 www 80: ('Map has branchings. Use advanced editor.',1);
1.8 www 81: }
1.9 www 82: $starters[$start]=1;
83: $endings[$end]=1;
84: if ($cond) {
1.8 www 85: return
1.10 www 86: ('Map has conditions. Use advanced editor.',1);
1.8 www 87: }
88: }
89:
90: }
1.10 www 91: for (my $i=0; $i<=$#resources; $i++) {
92: if (defined($resources[$i])) {
93: unless (($starters[$i]) || ($endings[$i])) {
94: return
95: ('Map has unconnected resources. Use advanced editor.',1);
96: }
97: }
98: }
99:
100: # -------------------------------------------------- This is a linear map, sort
101:
102: my $startidx=0;
103: my $endidx=0;
104: for (my $i=0; $i<=$#resources; $i++) {
105: if (defined($resources[$i])) {
106: my ($title,$url,$ext,$type)=split(/\:/,$resources[$i]);
107: if ($type eq 'start') { $startidx=$i; }
108: if ($type eq 'finish') { $endidx=$i; }
109: }
110: }
111: my $k=0;
112: my $currentidx=$startidx;
113: $order[$k]=$currentidx;
114: for (my $i=0; $i<=$#resources; $i++) {
115: foreach (@links) {
116: my ($start,$end)=split(/\:/,$_);
117: if ($start==$currentidx) {
118: $currentidx=$end;
119: $k++;
120: $order[$k]=$currentidx;
121: last;
122: }
123: }
124: if ($currentidx==$endidx) { last; }
125: }
1.8 www 126: return $errtext;
127: }
128:
1.16 www 129: # ---------------------------------------------- Read a map as well as possible
130:
131: sub attemptread {
132: my $fn=shift;
133:
134: my @links;
135: undef @links;
136: my @theseres;
137: undef @theseres;
138:
139: my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
140: if ($errtext) { return @theseres }
141:
142: # -------------------------------------------------------------------- Read map
143: foreach (split(/\<\&\>/,$outtext)) {
144: my ($command,$number,$content)=split(/\<\:\>/,$_);
145: if ($command eq 'objcont') {
146: $theseres[$number]=$content;
147: }
148: if ($command eq 'objlinks') {
149: $links[$number]=$content;
150: }
151: }
152:
153: # --------------------------------------------------------------- Sort, sort of
154:
1.17 www 155: my @objsort=();
156: undef @objsort;
1.16 www 157:
1.17 www 158: my @data1=();
159: my @data2=();
160: undef @data1;
161: undef @data2;
162:
163: my $k;
164: my $kj;
165: my $j;
166: my $ij;
167:
168: for ($k=1;$k<=$#theseres;$k++) {
169: if (defined($theseres[$k])) {
170: $objsort[$#objsort+1]=$k;
171: }
172: }
1.16 www 173:
1.17 www 174: for ($k=1;$k<=$#links;$k++) {
175: if (defined($links[$k])) {
176: @data1=split(/\:/,$links[$k]);
177: $kj=-1;
178: for (my $j=0;$j<=$#objsort;$j++) {
179: if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
180: $kj=$j;
181: }
182: }
183: if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
184: }
185: }
186: for ($k=0;$k<=$#objsort;$k++) {
187: for ($j=0;$j<=$#objsort;$j++) {
188: if ($k!=$j) {
189: @data1=split(/\:/,$objsort[$k]);
190: @data2=split(/\:/,$objsort[$j]);
191: my $dol=$#data1+1;
192: my $dtl=$#data2+1;
193: if ($dol+$dtl<1000) {
194: for ($kj=1;$kj<$dol;$kj++) {
195: if ($data1[$kj]==$data2[0]) {
196: for ($ij=1;$ij<$dtl;$ij++) {
197: $data1[$#data1+1]=$data2[$ij];
198: }
199: }
200: }
201: for ($kj=1;$kj<$dtl;$kj++) {
202: if ($data2[$kj]==$data1[0]) {
203: for ($ij=1;$ij<$dol;$ij++) {
204: $data2[$#data2+1]=$data1[$ij];
205: }
206: }
207: }
208: $objsort[$k]=join(':',@data1);
209: $objsort[$j]=join(':',@data2);
210: }
211: }
212: }
213: }
214: # ---------------------------------------------------------------- Now sort out
1.16 www 215:
1.17 www 216: @objsort=sort {
217: my @data1=split(/\:/,$a);
218: my @data2=split(/\:/,$b);
219: my $rvalue=0;
220: my $k;
221: for ($k=1;$k<=$#data1;$k++) {
222: if ($data1[$k]==$data2[0]) { $rvalue--; }
223: }
224: for ($k=1;$k<=$#data2;$k++) {
225: if ($data2[$k]==$data1[0]) { $rvalue++; }
226: }
227: if ($rvalue==0) { $rvalue=$#data2-$#data1; }
228: $rvalue;
229: } @objsort;
230:
231: my @outres=();
232: undef @outres;
233:
234: for ($k=0;$k<=$#objsort;$k++) {
235: $outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
236: }
237: return @outres;
1.16 www 238: }
239:
1.3 www 240: # --------------------------------------------------------- Build up RAT screen
241: sub ratedt {
242: my ($r,$url)=@_;
1.1 www 243: $r->print(<<ENDDOCUMENT);
244:
245: <html>
1.2 harris41 246: <head>
247: <script language="JavaScript">
248: var flag=0;
249: </script>
250: </head>
1.1 www 251: <frameset rows="1,50,*" border=0>
252: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
253: <frame name=code src="/adm/rat/code.html">
254: <frame name=mapout src="/adm/rat/map.html">
255: </frameset>
256: </html>
257:
258: ENDDOCUMENT
1.3 www 259: }
260:
1.8 www 261: # ---------------------------------------------------------------- Make buttons
262:
263: sub buttons {
264: my $adv=shift;
265: my $output='<form method=post>';
266: if ($adv==1) {
267: $output.='<input type=submit name=forceadv value="Edit">';
268: } else {
269: unless ($adv==2) {
270: $output.='<input type=submit name=forcesmp value="Simple Edit">';
271: }
272: $output.='<input type=submit name=forceadv value="Advanced Edit">';
273: }
274: return $output.'</form><hr>';
275: }
276:
1.20 www 277: # ----------------------------------------------------------- Paste into target
278: # modifies @order, @resources
279:
280: sub pastetarget {
281: my ($after,@which)=@_;
282: my @insertorder=();
283: foreach (@which) {
284: if (defined($_)) {
285: my ($name,$url)=split(/\=/,$_);
1.21 ! www 286: $name=&Apache::lonnet::unescape($name);
! 287: $url=&Apache::lonnet::unescape($url);
! 288: if ($url) {
! 289: my $idx=$#resources+1;
! 290: $insertorder[$#insertorder+1]=$idx;
! 291: my $ext='false';
! 292: if ($url=~/^http\:\/\//) { $ext='true'; }
! 293: $url=~s/\:/\:/g;
! 294: $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
! 295: }
1.20 www 296: }
297: }
298: my @oldorder=splice(@order,$after,$#insertorder+1,@insertorder);
1.21 ! www 299: @order=(@order,@oldorder);
! 300: }
! 301:
! 302: # ------------------------------------------------ Get start and finish correct
! 303: # modifies @resources
! 304:
! 305: sub startfinish {
! 306: foreach (@order) {
! 307: my ($name,$url,$ext)=split(/\:/,$resources[$_]);
! 308: $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
! 309: }
! 310: my ($name,$url,$ext)=split(/\:/,$resources[0]);
! 311: $resources[0]=$name.':'.$url.':'.$ext.':start:res';
! 312: my ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
! 313: $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
1.20 www 314: }
315:
316: # ------------------------------------------------------- Simple edit processor
317:
1.3 www 318: sub smpedt {
1.8 www 319: my ($r,$errtext)=@_;
320: my $buttons=&buttons(2);
1.12 www 321:
322: # ---------------------------------------------------------- Process form input
323:
324: my @importselect=();
325: my @targetselect=();
326: undef @importselect;
327: undef @targetselect;
328: if (defined($ENV{'form.import'})) {
329: if (ref($ENV{'form.import'})) {
1.13 www 330: @importselect=sort($ENV->{'form.import'});
1.12 www 331: } else {
332: @importselect=($ENV{'form.import'});
333: }
334: }
335: if (defined($ENV{'form.target'})) {
336: if (ref($ENV{'form.target'})) {
1.13 www 337: @targetselect=sort($ENV->{'form.target'});
1.12 www 338: } else {
339: @targetselect=($ENV{'form.target'});
340: }
341: }
1.13 www 342: # ============================================================ Process commands
1.12 www 343:
1.14 www 344: my $targetdetail=$ENV{'form.targetdetail'};
345: my $importdetail=$ENV{'form.curimpdetail'};
1.13 www 346:
347: # ---------------------------------------------------- Importing from groupsort
1.16 www 348: if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
1.13 www 349:
1.14 www 350: $importdetail='';
1.13 www 351: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
352:
353: my $lastsel;
354:
355: if (defined($importselect[-1])) {
356: $lastsel=$importselect[-1];
357: } else {
358: $lastsel=$#curimport;
359: }
360:
361: for (my $i=0;$i<=$lastsel;$i++) {
362: my ($name,$url)=split(/\=/,$curimport[$i]);
363: if ($url) {
1.18 www 364: $importdetail.='&'.$name.'='.$url;
1.13 www 365: }
366: }
367:
368: $importdetail.='&'.$ENV{'form.importdetail'};
369:
370: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
371: my ($name,$url)=split(/\=/,$curimport[$i]);
372: if ($url) {
1.18 www 373: $importdetail.='&'.$name.'='.$url;
1.13 www 374: }
375: }
376: $importdetail=~s/\&+/\&/g;
377: $importdetail=~s/^\&//;
378:
1.14 www 379: # ------------------------------------------------------------------- Clear all
380: } elsif ($ENV{'form.clear'}) {
381: $importdetail='';
382: # ------------------------------------------------------------ Discard selected
383: } elsif ($ENV{'form.discard'}) {
384: $importdetail='';
385: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
386: foreach (@importselect) {
387: $curimport[$_]='';
388: }
389: for (my $i=0;$i<=$#curimport;$i++) {
390: my ($name,$url)=split(/\=/,$curimport[$i]);
391: if ($url) {
1.18 www 392: $importdetail.='&'.$name.'='.$url;
1.14 www 393: }
394: }
1.17 www 395: # --------------------------------------------------------- Loading another map
396: } elsif ($ENV{'form.loadmap'}) {
397: $importdetail='';
398: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
399:
400: my $lastsel;
401:
402: if (defined($importselect[-1])) {
403: $lastsel=$importselect[-1];
404: } else {
405: $lastsel=$#curimport;
406: }
407:
408: for (my $i=0;$i<=$lastsel;$i++) {
409: my ($name,$url)=split(/\=/,$curimport[$i]);
410: if ($url) {
1.18 www 411: $importdetail.='&'.$name.'='.$url;
1.17 www 412: }
413: }
414:
415: foreach (
416: &attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
417: my ($name,$url)=split(/\:/,$_);
418: if ($url) {
419: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
420: &Apache::lonnet::escape($url);
421: }
422: }
423:
424: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
425: my ($name,$url)=split(/\=/,$curimport[$i]);
426: if ($url) {
1.18 www 427: $importdetail.='&'.$name.'='.$url;
1.17 www 428: }
429: }
430: $importdetail=~s/\&+/\&/g;
431: $importdetail=~s/^\&//;
432:
1.20 www 433: # ------------------------------------------------ Groupimport/search to target
434: } elsif ($ENV{'form.importdetail'}) {
435: my $lastsel;
436:
437: if (defined($targetselect[-1])) {
438: $lastsel=$targetselect[-1];
439: } else {
440: $lastsel=$#order;
441: }
1.21 ! www 442: &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
! 443: &startfinish();
1.20 www 444: # ------------------------------------------------------------------------- Cut
445: } elsif ($ENV{'form.cut'}) {
446: # ----------------------------------------------------------------------- Paste
447: } elsif ($ENV{'form.paste'}) {
448: # ------------------------------------------------
1.13 www 449: }
1.12 www 450: # ------------------------------------------------------------ Assemble windows
1.20 www 451:
1.13 www 452: my $idx=-1;
453: my $importwindow=join("\n",map {
454: $idx++;
455: if ($_) {
1.15 www 456: my ($name,$url)=split(/\=/,$_);
457: unless ($name) { $name=(split(/\//,$url))[-1]; }
458: unless ($name) { $name='EMPTY'; }
1.13 www 459: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
460: '</option>';
461: }
462: } split(/\&/,$importdetail));
1.12 www 463:
1.13 www 464: $idx=0;
1.11 www 465: my $targetwindow=join("\n",map {
1.13 www 466: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 467: unless ($name) { $name=(split(/\//,$url))[-1]; }
468: unless ($name) { $name='EMPTY'; }
1.13 www 469: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
470: &Apache::lonnet::escape($url);
471: $idx++;
1.20 www 472: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 473: } @order);
474:
1.8 www 475: # ----------------------------------------------------- Start simple RAT screen
1.3 www 476: $r->print(<<ENDSMPHEAD);
477: <html>
1.6 www 478: <head>
479: <script>
480: var srch;
481: var srchflag=-1; // 1 means currently open
482: // 0 means closed (but has been open)
483: // -1 means never yet opened/defined
484: var srchmode='';
485:
486: var idx;
487: var idxflag=-1; // 1 means currently open
488: // 0 means closed (but has been open)
489: // -1 means never yet opened/defined
490: var idxmode='';
491:
492: // ------------------------------------------------------ Clears indexer window
493: function idxclear() {
494: idx.document.clear();
495: }
496:
497: // ------------------------------------------------------- Clears search window
498: function srchclear() {
499: srch.document.clear();
500: }
501:
502: // ------------------------------------------------------ Closes indexer window
503: function idxclose() {
504: if (idx && !idx.closed) {
505: idxflag=0;
506: idx.close();
507: }
508: }
509:
510: // ------------------------------------------------------- Closes search window
511: function srchclose() {
512: if (srch && !srch.closed) {
513: srchflag=0;
514: srch.close();
515: }
516: }
517:
518: // -------------------------------------------------------- Open indexer window
519: function idxopen(mode) {
520: var options="scrollbars=1,resizable=1,menubar=0";
521: idxmode=mode;
522: idxflag=1;
523: idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
524: idx.focus();
525: }
526:
527: // --------------------------------------------------------- Open search window
528: function srchopen(mode) {
529: var options="scrollbars=1,resizable=1,menubar=0";
530: srchmode=mode;
531: srchflag=1;
532: srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
533: srch.focus();
534: }
535: // ----------------------------------------------------- launch indexer browser
536: function groupsearch() {
537: srchcheck('groupsearch');
538: }
539:
540: function groupimport() {
541: idxcheck('groupimport');
542: }
543: // ------------------------------------------------------- Do srch status check
544: function srchcheck(mode) {
545: if (!srch || srch.closed || srchmode!=mode) {
546: srchopen(mode);
547: }
548: srch.focus();
549: }
550:
551: // -------------------------------------------------------- Do idx status check
552: function idxcheck(mode) {
553: if (!idx || idx.closed || idxmode!=mode) {
554: idxopen(mode);
555: }
556: idx.focus();
557: }
1.15 www 558:
559:
560: var editbrowser;
561: function openbrowser(formname,elementname,only,omit) {
562: var url = '/res/?';
563: if (editbrowser == null) {
564: url += 'launch=1&';
565: }
566: url += 'catalogmode=interactive&';
567: url += 'mode=edit&';
568: url += 'form=' + formname + '&';
569: if (only != null) {
570: url += 'only=' + only + '&';
571: }
572: if (omit != null) {
573: url += 'omit=' + omit + '&';
574: }
575: url += 'element=' + elementname + '';
576: var title = 'Browser';
577: var options = 'scrollbars=1,resizable=1,menubar=0';
578: options += ',width=700,height=600';
579: editbrowser = open(url,title,options,'1');
580: editbrowser.focus();
581: }
1.19 www 582:
583: function openview(entry) {
584: var url=unescape((entry.split('='))[1]);
1.20 www 585: var parts=new Array;
586: parts=url.split(':');
587: url=parts.join(':');
1.19 www 588: if (url) { open(url,'cat'); }
589: }
590:
591: function viewtarget() {
592: openview((document.forms.simpleedit.targetdetail.value.split('&'))
593: [document.forms.simpleedit.target.selectedIndex+1]);
594: }
595:
596: function viewimport() {
597: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
598: [document.forms.simpleedit.import.selectedIndex+1]);
599: }
600:
1.6 www 601: </script>
602: </head>
1.3 www 603: <body bgcolor='#FFFFFF'>
1.8 www 604: $buttons
1.7 www 605: <font color=red>$errtext</font>
1.13 www 606: <form name=simpleedit method=post>
1.11 www 607: <input type=hidden name=forcesmp value=1>
608: <table>
1.12 www 609: <tr><th width="40%">Import</th>
610: <th> </th>
611: <th width="40%">Target</th></tr>
612: <tr><td bgcolor="#FFFFCC">
613: <input type=button onClick="javascript:groupsearch()" value="Group Search">
1.13 www 614: <input type=button onClick="javascript:groupimport();" value="Group Import">
1.15 www 615: after selected
1.14 www 616: <hr>
1.15 www 617: <input type=text size=20 name=importmap>
618: <input type=button
619: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
620: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
1.14 www 621: <input type=submit name="discard" value="Discard Selected">
622: <input type=submit name="clear" value="Clear All">
1.12 www 623: <input type=button onClick="javascript:viewimport()" value="View">
1.16 www 624:
1.12 www 625: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 626:
627: <input type=button onClick=
628: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
629: <input type=button onClick=
630: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
631: after selected
632: <hr><input type=button onClick="javascript:viewtarget()" value="View">
1.12 www 633: </td></tr>
1.16 www 634:
1.12 www 635: <tr><td bgcolor="#FFFFCC"><select name="import" multiple>
636: $importwindow
637: </select>
1.11 www 638: </td>
1.12 www 639: <td bgcolor="#FFFFAA" align="center">
640: Cut selected<br>
1.11 www 641: <input type=submit name=cut value='<<<'><p>
1.12 www 642: <hr>
643: Paste after selected<br>
1.11 www 644: <input type=submit name=paste value='>>>'>
645: </td>
1.12 www 646: <td bgcolor="#FFFFCC"><select name="target" multiple>
1.11 www 647: $targetwindow
648: </select>
1.12 www 649: </table>
1.13 www 650: <input type=hidden name=importdetail value="">
651: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 652: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 653: <input type=hidden name=impfortarget value="0">
1.12 www 654: </form>
655: </body></html>
1.3 www 656: ENDSMPHEAD
657: }
658:
1.11 www 659: # ----------------------------------------------------------------- No such dir
1.4 www 660: sub nodir {
661: my ($r,$dir)=@_;
662: $dir=~s/^\/home\/\w+\/public\_html//;
663: $r->print(<<ENDNODIR);
664: <html>
665: <body bgcolor='#FFFFFF'>
666: <h1>No such directory: $dir</h1>
667: </body>
668: </html>
669: ENDNODIR
670: }
671:
1.8 www 672: # ---------------------------------------------------------------- View Handler
673:
674: sub viewmap {
1.17 www 675: my ($r,$url,$adv,$errtext)=@_;
1.8 www 676: $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
1.10 www 677: if ($errtext) {
678: $r->print($errtext.'<hr>');
679: }
1.17 www 680: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 681: if (defined($_)) {
682: my ($title,$url)=split(/\:/,$_);
683: $title=~s/\&colon\;/\:/g;
684: $url=~s/\&colon\;/\:/g;
1.15 www 685: unless ($title) { $title=(split(/\//,$url))[-1] };
686: unless ($title) { $title='<i>Empty</i>'; }
1.9 www 687: if ($url) {
688: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
689: }
690: $r->print(&Apache::lonratsrv::qtescape($title));
691: if ($url) { $r->print('</a>'); }
692: $r->print('<br>');
693: }
694: }
1.8 www 695: $r->print('</body></html>');
696: }
697:
1.3 www 698: # ================================================================ Main Handler
699:
700: sub handler {
701: my $r=shift;
702: $r->content_type('text/html');
703: $r->send_http_header;
704:
705: return OK if $r->header_only;
706:
707: my $url=$r->uri;
708: my $fn=&Apache::lonnet::filelocation('',$url);
709:
1.4 www 710: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
711: unless (-e $dir) {
712: &nodir($r,$dir);
713: return OK;
714: }
1.8 www 715:
716: # ------------------------------------------- Determine which tools can be used
1.3 www 717: my $adv=0;
718:
719: unless ($ENV{'form.forcesmp'}) {
720: if ($ENV{'form.forceadv'}) {
721: $adv=1;
722: } elsif (my $fh=Apache::File->new($fn)) {
723: my $allmap=join('',<$fh>);
724: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
725: }
726: }
727:
1.8 www 728: my $errtext='';
729: my $fatal=0;
730:
731: # -------------------------------------------------------------------- Load map
732: ($errtext,$fatal)=&mapread($fn,$errtext);
733:
734: if ($fatal==1) { $adv=1; }
735:
736: # ----------------------------------- adv==1 now means "graphical MUST be used"
737:
738: if ($ENV{'form.forceadv'}) {
1.3 www 739: &ratedt($r,$url);
1.8 www 740: } elsif ($ENV{'form.forcesmp'}) {
741: &smpedt($r,$errtext);
1.3 www 742: } else {
1.17 www 743: &viewmap($r,$url,$adv,$errtext);
1.3 www 744: }
1.1 www 745: return OK;
746: }
747:
748: 1;
749: __END__
750:
751:
752:
753:
754:
755:
756:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>