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