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