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