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