Annotation of rat/lonratedt.pm, revision 1.28
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.28 ! www 4: # $Id: lonratedt.pm,v 1.27 2002/05/22 20:39:59 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;
543: my $importwindow=join("\n",map {
544: $idx++;
545: if ($_) {
1.15 www 546: my ($name,$url)=split(/\=/,$_);
547: unless ($name) { $name=(split(/\//,$url))[-1]; }
548: unless ($name) { $name='EMPTY'; }
1.13 www 549: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
550: '</option>';
551: }
552: } split(/\&/,$importdetail));
1.12 www 553:
1.13 www 554: $idx=0;
1.11 www 555: my $targetwindow=join("\n",map {
1.13 www 556: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 557: unless ($name) { $name=(split(/\//,$url))[-1]; }
558: unless ($name) { $name='EMPTY'; }
1.13 www 559: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
560: &Apache::lonnet::escape($url);
561: $idx++;
1.20 www 562: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 563: } @order);
564:
1.8 www 565: # ----------------------------------------------------- Start simple RAT screen
1.3 www 566: $r->print(<<ENDSMPHEAD);
567: <html>
1.6 www 568: <head>
569: <script>
570: var srch;
571: var srchflag=-1; // 1 means currently open
572: // 0 means closed (but has been open)
573: // -1 means never yet opened/defined
574: var srchmode='';
575:
576: var idx;
577: var idxflag=-1; // 1 means currently open
578: // 0 means closed (but has been open)
579: // -1 means never yet opened/defined
580: var idxmode='';
581:
582: // ------------------------------------------------------ Clears indexer window
583: function idxclear() {
584: idx.document.clear();
585: }
586:
587: // ------------------------------------------------------- Clears search window
588: function srchclear() {
589: srch.document.clear();
590: }
591:
592: // ------------------------------------------------------ Closes indexer window
593: function idxclose() {
594: if (idx && !idx.closed) {
595: idxflag=0;
596: idx.close();
597: }
598: }
599:
600: // ------------------------------------------------------- Closes search window
601: function srchclose() {
602: if (srch && !srch.closed) {
603: srchflag=0;
604: srch.close();
605: }
606: }
607:
608: // -------------------------------------------------------- Open indexer window
609: function idxopen(mode) {
610: var options="scrollbars=1,resizable=1,menubar=0";
611: idxmode=mode;
612: idxflag=1;
613: idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
614: idx.focus();
615: }
616:
617: // --------------------------------------------------------- Open search window
618: function srchopen(mode) {
619: var options="scrollbars=1,resizable=1,menubar=0";
620: srchmode=mode;
621: srchflag=1;
622: srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
623: srch.focus();
624: }
625: // ----------------------------------------------------- launch indexer browser
626: function groupsearch() {
627: srchcheck('groupsearch');
628: }
629:
630: function groupimport() {
631: idxcheck('groupimport');
632: }
633: // ------------------------------------------------------- Do srch status check
634: function srchcheck(mode) {
635: if (!srch || srch.closed || srchmode!=mode) {
636: srchopen(mode);
637: }
638: srch.focus();
639: }
640:
641: // -------------------------------------------------------- Do idx status check
642: function idxcheck(mode) {
643: if (!idx || idx.closed || idxmode!=mode) {
644: idxopen(mode);
645: }
646: idx.focus();
647: }
1.15 www 648:
649:
650: var editbrowser;
651: function openbrowser(formname,elementname,only,omit) {
652: var url = '/res/?';
653: if (editbrowser == null) {
654: url += 'launch=1&';
655: }
656: url += 'catalogmode=interactive&';
657: url += 'mode=edit&';
658: url += 'form=' + formname + '&';
659: if (only != null) {
660: url += 'only=' + only + '&';
661: }
662: if (omit != null) {
663: url += 'omit=' + omit + '&';
664: }
665: url += 'element=' + elementname + '';
666: var title = 'Browser';
667: var options = 'scrollbars=1,resizable=1,menubar=0';
668: options += ',width=700,height=600';
669: editbrowser = open(url,title,options,'1');
670: editbrowser.focus();
671: }
1.19 www 672:
673: function openview(entry) {
674: var url=unescape((entry.split('='))[1]);
1.20 www 675: var parts=new Array;
676: parts=url.split(':');
677: url=parts.join(':');
1.19 www 678: if (url) { open(url,'cat'); }
679: }
680:
681: function viewtarget() {
682: openview((document.forms.simpleedit.targetdetail.value.split('&'))
683: [document.forms.simpleedit.target.selectedIndex+1]);
684: }
685:
686: function viewimport() {
687: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.27 www 688: [document.forms.simpleedit.importsel.selectedIndex+1]);
1.19 www 689: }
690:
1.6 www 691: </script>
692: </head>
1.3 www 693: <body bgcolor='#FFFFFF'>
1.8 www 694: $buttons
1.7 www 695: <font color=red>$errtext</font>
1.13 www 696: <form name=simpleedit method=post>
1.11 www 697: <input type=hidden name=forcesmp value=1>
698: <table>
1.12 www 699: <tr><th width="40%">Import</th>
700: <th> </th>
701: <th width="40%">Target</th></tr>
702: <tr><td bgcolor="#FFFFCC">
703: <input type=button onClick="javascript:groupsearch()" value="Group Search">
1.13 www 704: <input type=button onClick="javascript:groupimport();" value="Group Import">
1.15 www 705: after selected
1.14 www 706: <hr>
1.15 www 707: <input type=text size=20 name=importmap>
708: <input type=button
709: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
710: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
1.14 www 711: <input type=submit name="discard" value="Discard Selected">
712: <input type=submit name="clear" value="Clear All">
1.12 www 713: <input type=button onClick="javascript:viewimport()" value="View">
1.16 www 714:
1.12 www 715: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 716:
717: <input type=button onClick=
718: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
719: <input type=button onClick=
720: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
721: after selected
722: <hr><input type=button onClick="javascript:viewtarget()" value="View">
1.12 www 723: </td></tr>
1.16 www 724:
1.27 www 725: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12 www 726: $importwindow
727: </select>
1.11 www 728: </td>
1.12 www 729: <td bgcolor="#FFFFAA" align="center">
730: Cut selected<br>
1.11 www 731: <input type=submit name=cut value='<<<'><p>
1.12 www 732: <hr>
1.25 www 733: Copy selected<br>
734: <input type=submit name=copy value='<--'><p>
735: <hr>
1.12 www 736: Paste after selected<br>
1.25 www 737: <input type=submit name=paste value='-->'>
1.11 www 738: </td>
1.27 www 739: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11 www 740: $targetwindow
741: </select>
1.12 www 742: </table>
1.13 www 743: <input type=hidden name=importdetail value="">
744: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 745: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 746: <input type=hidden name=impfortarget value="0">
1.12 www 747: </form>
748: </body></html>
1.3 www 749: ENDSMPHEAD
750: }
751:
1.11 www 752: # ----------------------------------------------------------------- No such dir
1.4 www 753: sub nodir {
754: my ($r,$dir)=@_;
755: $dir=~s/^\/home\/\w+\/public\_html//;
756: $r->print(<<ENDNODIR);
757: <html>
758: <body bgcolor='#FFFFFF'>
759: <h1>No such directory: $dir</h1>
760: </body>
761: </html>
762: ENDNODIR
763: }
764:
1.8 www 765: # ---------------------------------------------------------------- View Handler
766:
767: sub viewmap {
1.17 www 768: my ($r,$url,$adv,$errtext)=@_;
1.28 ! www 769: $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
1.10 www 770: if ($errtext) {
771: $r->print($errtext.'<hr>');
772: }
1.26 www 773: my $idx=0;
1.17 www 774: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 775: if (defined($_)) {
1.26 www 776: $idx++;
1.9 www 777: my ($title,$url)=split(/\:/,$_);
778: $title=~s/\&colon\;/\:/g;
779: $url=~s/\&colon\;/\:/g;
1.15 www 780: unless ($title) { $title=(split(/\//,$url))[-1] };
781: unless ($title) { $title='<i>Empty</i>'; }
1.9 www 782: if ($url) {
783: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
784: }
785: $r->print(&Apache::lonratsrv::qtescape($title));
786: if ($url) { $r->print('</a>'); }
1.28 ! www 787: $r->print('<br>');
1.9 www 788: }
789: }
1.8 www 790: $r->print('</body></html>');
791: }
792:
1.3 www 793: # ================================================================ Main Handler
794:
795: sub handler {
796: my $r=shift;
797: $r->content_type('text/html');
798: $r->send_http_header;
799:
800: return OK if $r->header_only;
801:
802: my $url=$r->uri;
803: my $fn=&Apache::lonnet::filelocation('',$url);
804:
1.4 www 805: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
806: unless (-e $dir) {
807: &nodir($r,$dir);
808: return OK;
809: }
1.8 www 810:
811: # ------------------------------------------- Determine which tools can be used
1.3 www 812: my $adv=0;
813:
814: unless ($ENV{'form.forcesmp'}) {
815: if ($ENV{'form.forceadv'}) {
816: $adv=1;
817: } elsif (my $fh=Apache::File->new($fn)) {
818: my $allmap=join('',<$fh>);
819: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
820: }
821: }
822:
1.8 www 823: my $errtext='';
824: my $fatal=0;
825:
826: # -------------------------------------------------------------------- Load map
827: ($errtext,$fatal)=&mapread($fn,$errtext);
828:
829: if ($fatal==1) { $adv=1; }
830:
831: # ----------------------------------- adv==1 now means "graphical MUST be used"
832:
833: if ($ENV{'form.forceadv'}) {
1.3 www 834: &ratedt($r,$url);
1.8 www 835: } elsif ($ENV{'form.forcesmp'}) {
1.22 www 836: &smpedt($r,$url,$errtext);
1.3 www 837: } else {
1.17 www 838: &viewmap($r,$url,$adv,$errtext);
1.3 www 839: }
1.1 www 840: return OK;
841: }
842:
843: 1;
844: __END__
845:
846:
847:
848:
849:
850:
851:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>