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