Annotation of rat/lonratedt.pm, revision 1.24
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.24 ! www 4: # $Id: lonratedt.pm,v 1.23 2002/05/21 13:41:13 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.24 ! 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.24 ! 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'}) {
1.24 ! www 475: my $lastsel;
! 476: if (defined($targetselect[-1])) {
! 477: $lastsel=$targetselect[-1];
! 478: } else {
! 479: $lastsel=$#order+1;
! 480: }
! 481: my @newsequence;
! 482: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
! 483: foreach (@importselect) {
! 484: $newsequence[$#newsequence+1]=$curimport[$_];
! 485: }
! 486: &pastetarget($lastsel,@newsequence);
! 487: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 488: # ------------------------------------------------
1.13 www 489: }
1.12 www 490: # ------------------------------------------------------------ Assemble windows
1.20 www 491:
1.13 www 492: my $idx=-1;
493: my $importwindow=join("\n",map {
494: $idx++;
495: if ($_) {
1.15 www 496: my ($name,$url)=split(/\=/,$_);
497: unless ($name) { $name=(split(/\//,$url))[-1]; }
498: unless ($name) { $name='EMPTY'; }
1.13 www 499: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
500: '</option>';
501: }
502: } split(/\&/,$importdetail));
1.12 www 503:
1.13 www 504: $idx=0;
1.11 www 505: my $targetwindow=join("\n",map {
1.13 www 506: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 507: unless ($name) { $name=(split(/\//,$url))[-1]; }
508: unless ($name) { $name='EMPTY'; }
1.13 www 509: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
510: &Apache::lonnet::escape($url);
511: $idx++;
1.20 www 512: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 513: } @order);
514:
1.8 www 515: # ----------------------------------------------------- Start simple RAT screen
1.3 www 516: $r->print(<<ENDSMPHEAD);
517: <html>
1.6 www 518: <head>
519: <script>
520: var srch;
521: var srchflag=-1; // 1 means currently open
522: // 0 means closed (but has been open)
523: // -1 means never yet opened/defined
524: var srchmode='';
525:
526: var idx;
527: var idxflag=-1; // 1 means currently open
528: // 0 means closed (but has been open)
529: // -1 means never yet opened/defined
530: var idxmode='';
531:
532: // ------------------------------------------------------ Clears indexer window
533: function idxclear() {
534: idx.document.clear();
535: }
536:
537: // ------------------------------------------------------- Clears search window
538: function srchclear() {
539: srch.document.clear();
540: }
541:
542: // ------------------------------------------------------ Closes indexer window
543: function idxclose() {
544: if (idx && !idx.closed) {
545: idxflag=0;
546: idx.close();
547: }
548: }
549:
550: // ------------------------------------------------------- Closes search window
551: function srchclose() {
552: if (srch && !srch.closed) {
553: srchflag=0;
554: srch.close();
555: }
556: }
557:
558: // -------------------------------------------------------- Open indexer window
559: function idxopen(mode) {
560: var options="scrollbars=1,resizable=1,menubar=0";
561: idxmode=mode;
562: idxflag=1;
563: idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
564: idx.focus();
565: }
566:
567: // --------------------------------------------------------- Open search window
568: function srchopen(mode) {
569: var options="scrollbars=1,resizable=1,menubar=0";
570: srchmode=mode;
571: srchflag=1;
572: srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
573: srch.focus();
574: }
575: // ----------------------------------------------------- launch indexer browser
576: function groupsearch() {
577: srchcheck('groupsearch');
578: }
579:
580: function groupimport() {
581: idxcheck('groupimport');
582: }
583: // ------------------------------------------------------- Do srch status check
584: function srchcheck(mode) {
585: if (!srch || srch.closed || srchmode!=mode) {
586: srchopen(mode);
587: }
588: srch.focus();
589: }
590:
591: // -------------------------------------------------------- Do idx status check
592: function idxcheck(mode) {
593: if (!idx || idx.closed || idxmode!=mode) {
594: idxopen(mode);
595: }
596: idx.focus();
597: }
1.15 www 598:
599:
600: var editbrowser;
601: function openbrowser(formname,elementname,only,omit) {
602: var url = '/res/?';
603: if (editbrowser == null) {
604: url += 'launch=1&';
605: }
606: url += 'catalogmode=interactive&';
607: url += 'mode=edit&';
608: url += 'form=' + formname + '&';
609: if (only != null) {
610: url += 'only=' + only + '&';
611: }
612: if (omit != null) {
613: url += 'omit=' + omit + '&';
614: }
615: url += 'element=' + elementname + '';
616: var title = 'Browser';
617: var options = 'scrollbars=1,resizable=1,menubar=0';
618: options += ',width=700,height=600';
619: editbrowser = open(url,title,options,'1');
620: editbrowser.focus();
621: }
1.19 www 622:
623: function openview(entry) {
624: var url=unescape((entry.split('='))[1]);
1.20 www 625: var parts=new Array;
626: parts=url.split(':');
627: url=parts.join(':');
1.19 www 628: if (url) { open(url,'cat'); }
629: }
630:
631: function viewtarget() {
632: openview((document.forms.simpleedit.targetdetail.value.split('&'))
633: [document.forms.simpleedit.target.selectedIndex+1]);
634: }
635:
636: function viewimport() {
637: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
638: [document.forms.simpleedit.import.selectedIndex+1]);
639: }
640:
1.6 www 641: </script>
642: </head>
1.3 www 643: <body bgcolor='#FFFFFF'>
1.8 www 644: $buttons
1.7 www 645: <font color=red>$errtext</font>
1.13 www 646: <form name=simpleedit method=post>
1.11 www 647: <input type=hidden name=forcesmp value=1>
648: <table>
1.12 www 649: <tr><th width="40%">Import</th>
650: <th> </th>
651: <th width="40%">Target</th></tr>
652: <tr><td bgcolor="#FFFFCC">
653: <input type=button onClick="javascript:groupsearch()" value="Group Search">
1.13 www 654: <input type=button onClick="javascript:groupimport();" value="Group Import">
1.15 www 655: after selected
1.14 www 656: <hr>
1.15 www 657: <input type=text size=20 name=importmap>
658: <input type=button
659: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
660: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
1.14 www 661: <input type=submit name="discard" value="Discard Selected">
662: <input type=submit name="clear" value="Clear All">
1.12 www 663: <input type=button onClick="javascript:viewimport()" value="View">
1.16 www 664:
1.12 www 665: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 666:
667: <input type=button onClick=
668: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
669: <input type=button onClick=
670: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
671: after selected
672: <hr><input type=button onClick="javascript:viewtarget()" value="View">
1.12 www 673: </td></tr>
1.16 www 674:
1.12 www 675: <tr><td bgcolor="#FFFFCC"><select name="import" multiple>
676: $importwindow
677: </select>
1.11 www 678: </td>
1.12 www 679: <td bgcolor="#FFFFAA" align="center">
680: Cut selected<br>
1.11 www 681: <input type=submit name=cut value='<<<'><p>
1.12 www 682: <hr>
683: Paste after selected<br>
1.11 www 684: <input type=submit name=paste value='>>>'>
685: </td>
1.12 www 686: <td bgcolor="#FFFFCC"><select name="target" multiple>
1.11 www 687: $targetwindow
688: </select>
1.12 www 689: </table>
1.13 www 690: <input type=hidden name=importdetail value="">
691: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 692: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 693: <input type=hidden name=impfortarget value="0">
1.12 www 694: </form>
695: </body></html>
1.3 www 696: ENDSMPHEAD
697: }
698:
1.11 www 699: # ----------------------------------------------------------------- No such dir
1.4 www 700: sub nodir {
701: my ($r,$dir)=@_;
702: $dir=~s/^\/home\/\w+\/public\_html//;
703: $r->print(<<ENDNODIR);
704: <html>
705: <body bgcolor='#FFFFFF'>
706: <h1>No such directory: $dir</h1>
707: </body>
708: </html>
709: ENDNODIR
710: }
711:
1.8 www 712: # ---------------------------------------------------------------- View Handler
713:
714: sub viewmap {
1.17 www 715: my ($r,$url,$adv,$errtext)=@_;
1.8 www 716: $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
1.10 www 717: if ($errtext) {
718: $r->print($errtext.'<hr>');
719: }
1.17 www 720: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 721: if (defined($_)) {
722: my ($title,$url)=split(/\:/,$_);
723: $title=~s/\&colon\;/\:/g;
724: $url=~s/\&colon\;/\:/g;
1.15 www 725: unless ($title) { $title=(split(/\//,$url))[-1] };
726: unless ($title) { $title='<i>Empty</i>'; }
1.9 www 727: if ($url) {
728: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
729: }
730: $r->print(&Apache::lonratsrv::qtescape($title));
731: if ($url) { $r->print('</a>'); }
732: $r->print('<br>');
733: }
734: }
1.8 www 735: $r->print('</body></html>');
736: }
737:
1.3 www 738: # ================================================================ Main Handler
739:
740: sub handler {
741: my $r=shift;
742: $r->content_type('text/html');
743: $r->send_http_header;
744:
745: return OK if $r->header_only;
746:
747: my $url=$r->uri;
748: my $fn=&Apache::lonnet::filelocation('',$url);
749:
1.4 www 750: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
751: unless (-e $dir) {
752: &nodir($r,$dir);
753: return OK;
754: }
1.8 www 755:
756: # ------------------------------------------- Determine which tools can be used
1.3 www 757: my $adv=0;
758:
759: unless ($ENV{'form.forcesmp'}) {
760: if ($ENV{'form.forceadv'}) {
761: $adv=1;
762: } elsif (my $fh=Apache::File->new($fn)) {
763: my $allmap=join('',<$fh>);
764: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
765: }
766: }
767:
1.8 www 768: my $errtext='';
769: my $fatal=0;
770:
771: # -------------------------------------------------------------------- Load map
772: ($errtext,$fatal)=&mapread($fn,$errtext);
773:
774: if ($fatal==1) { $adv=1; }
775:
776: # ----------------------------------- adv==1 now means "graphical MUST be used"
777:
778: if ($ENV{'form.forceadv'}) {
1.3 www 779: &ratedt($r,$url);
1.8 www 780: } elsif ($ENV{'form.forcesmp'}) {
1.22 www 781: &smpedt($r,$url,$errtext);
1.3 www 782: } else {
1.17 www 783: &viewmap($r,$url,$adv,$errtext);
1.3 www 784: }
1.1 www 785: return OK;
786: }
787:
788: 1;
789: __END__
790:
791:
792:
793:
794:
795:
796:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>