Annotation of rat/lonratedt.pm, revision 1.33
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.33 ! www 4: # $Id: lonratedt.pm,v 1.32 2002/08/20 13:02:41 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.33 ! www 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.33 ! www 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.32 www 353: sub editscript {
354: my $mode=shift;
355: return(<<ENDSCRIPT);
356: var srch;
357: var srchflag=-1; // 1 means currently open
358: // 0 means closed (but has been open)
359: // -1 means never yet opened/defined
360: var srchmode='';
361:
362: var idx;
363: var idxflag=-1; // 1 means currently open
364: // 0 means closed (but has been open)
365: // -1 means never yet opened/defined
366: var idxmode='';
367:
368: // ------------------------------------------------------ Clears indexer window
369: function idxclear() {
370: idx.document.clear();
371: }
372:
373: // ------------------------------------------------------- Clears search window
374: function srchclear() {
375: srch.document.clear();
376: }
377:
378: // ------------------------------------------------------ Closes indexer window
379: function idxclose() {
380: if (idx && !idx.closed) {
381: idxflag=0;
382: idx.close();
383: }
384: }
385:
386: // ------------------------------------------------------- Closes search window
387: function srchclose() {
388: if (srch && !srch.closed) {
389: srchflag=0;
390: srch.close();
391: }
392: }
393:
394: // -------------------------------------------------------- Open indexer window
395: function idxopen(mode) {
396: var options="scrollbars=1,resizable=1,menubar=0";
397: idxmode=mode;
398: idxflag=1;
399: idx=open("/res/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
400: idx.focus();
401: }
402:
403: // --------------------------------------------------------- Open search window
404: function srchopen(mode) {
405: var options="scrollbars=1,resizable=1,menubar=0";
406: srchmode=mode;
407: srchflag=1;
408: srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
409: srch.focus();
410: }
411: // ----------------------------------------------------- launch indexer browser
412: function groupsearch() {
413: srchcheck('groupsearch');
414: }
415:
416: function groupimport() {
417: idxcheck('groupimport');
418: }
419: // ------------------------------------------------------- Do srch status check
420: function srchcheck(mode) {
421: if (!srch || srch.closed || srchmode!=mode) {
422: srchopen(mode);
423: }
424: srch.focus();
425: }
426:
427: // -------------------------------------------------------- Do idx status check
428: function idxcheck(mode) {
429: if (!idx || idx.closed || idxmode!=mode) {
430: idxopen(mode);
431: }
432: idx.focus();
433: }
434:
435:
436: var editbrowser;
437: function openbrowser(formname,elementname,only,omit) {
438: var url = '/res/?';
439: if (editbrowser == null) {
440: url += 'launch=1&';
441: }
442: url += 'catalogmode=interactive&';
443: url += 'mode=edit&';
444: url += 'form=' + formname + '&';
445: if (only != null) {
446: url += 'only=' + only + '&';
447: }
448: if (omit != null) {
449: url += 'omit=' + omit + '&';
450: }
451: url += 'element=' + elementname + '';
452: var title = 'Browser';
453: var options = 'scrollbars=1,resizable=1,menubar=0';
454: options += ',width=700,height=600';
455: editbrowser = open(url,title,options,'1');
456: editbrowser.focus();
457: }
458: ENDSCRIPT
459: }
1.20 www 460: # ------------------------------------------------------- Simple edit processor
461:
1.3 www 462: sub smpedt {
1.22 www 463: my ($r,$url,$errtext)=@_;
1.8 www 464: my $buttons=&buttons(2);
1.12 www 465:
466: # ---------------------------------------------------------- Process form input
467:
468: my @importselect=();
469: my @targetselect=();
470: undef @importselect;
471: undef @targetselect;
1.27 www 472: if (defined($ENV{'form.importsel'})) {
473: if (ref($ENV{'form.importsel'})) {
474: @importselect=sort(@{$ENV{'form.importsel'}});
1.12 www 475: } else {
1.27 www 476: @importselect=($ENV{'form.importsel'});
1.12 www 477: }
478: }
479: if (defined($ENV{'form.target'})) {
480: if (ref($ENV{'form.target'})) {
1.25 www 481: @targetselect=sort(@{$ENV{'form.target'}});
1.12 www 482: } else {
483: @targetselect=($ENV{'form.target'});
484: }
485: }
1.13 www 486: # ============================================================ Process commands
1.12 www 487:
1.14 www 488: my $targetdetail=$ENV{'form.targetdetail'};
489: my $importdetail=$ENV{'form.curimpdetail'};
1.13 www 490:
491: # ---------------------------------------------------- Importing from groupsort
1.16 www 492: if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
1.13 www 493:
1.14 www 494: $importdetail='';
1.13 www 495: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
496:
497: my $lastsel;
498:
499: if (defined($importselect[-1])) {
500: $lastsel=$importselect[-1];
501: } else {
502: $lastsel=$#curimport;
503: }
504:
505: for (my $i=0;$i<=$lastsel;$i++) {
506: my ($name,$url)=split(/\=/,$curimport[$i]);
507: if ($url) {
1.18 www 508: $importdetail.='&'.$name.'='.$url;
1.13 www 509: }
510: }
511:
512: $importdetail.='&'.$ENV{'form.importdetail'};
513:
514: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
515: my ($name,$url)=split(/\=/,$curimport[$i]);
516: if ($url) {
1.18 www 517: $importdetail.='&'.$name.'='.$url;
1.13 www 518: }
519: }
520: $importdetail=~s/\&+/\&/g;
521: $importdetail=~s/^\&//;
522:
1.14 www 523: # ------------------------------------------------------------------- Clear all
524: } elsif ($ENV{'form.clear'}) {
525: $importdetail='';
526: # ------------------------------------------------------------ Discard selected
527: } elsif ($ENV{'form.discard'}) {
528: $importdetail='';
529: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
530: foreach (@importselect) {
531: $curimport[$_]='';
532: }
533: for (my $i=0;$i<=$#curimport;$i++) {
534: my ($name,$url)=split(/\=/,$curimport[$i]);
535: if ($url) {
1.18 www 536: $importdetail.='&'.$name.'='.$url;
1.14 www 537: }
538: }
1.17 www 539: # --------------------------------------------------------- Loading another map
540: } elsif ($ENV{'form.loadmap'}) {
541: $importdetail='';
542: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
543:
544: my $lastsel;
545:
546: if (defined($importselect[-1])) {
547: $lastsel=$importselect[-1];
548: } else {
549: $lastsel=$#curimport;
550: }
551:
552: for (my $i=0;$i<=$lastsel;$i++) {
553: my ($name,$url)=split(/\=/,$curimport[$i]);
554: if ($url) {
1.18 www 555: $importdetail.='&'.$name.'='.$url;
1.17 www 556: }
557: }
558:
559: foreach (
1.30 www 560: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.17 www 561: my ($name,$url)=split(/\:/,$_);
562: if ($url) {
563: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
564: &Apache::lonnet::escape($url);
565: }
566: }
567:
568: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
569: my ($name,$url)=split(/\=/,$curimport[$i]);
570: if ($url) {
1.18 www 571: $importdetail.='&'.$name.'='.$url;
1.17 www 572: }
573: }
574: $importdetail=~s/\&+/\&/g;
575: $importdetail=~s/^\&//;
576:
1.20 www 577: # ------------------------------------------------ Groupimport/search to target
578: } elsif ($ENV{'form.importdetail'}) {
579: my $lastsel;
580: if (defined($targetselect[-1])) {
581: $lastsel=$targetselect[-1];
582: } else {
1.23 www 583: $lastsel=$#order+1;
1.20 www 584: }
1.21 www 585: &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
1.22 www 586: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 587: # ------------------------------------------------------------------------- Cut
1.25 www 588: } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
589: $importdetail='';
590: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
591:
592: my $lastsel;
593:
594: if (defined($importselect[-1])) {
595: $lastsel=$importselect[-1];
596: } else {
597: $lastsel=$#curimport;
598: }
599:
600: for (my $i=0;$i<=$lastsel;$i++) {
601: my ($name,$url)=split(/\=/,$curimport[$i]);
602: if ($url) {
603: $importdetail.='&'.$name.'='.$url;
604: }
605: }
606:
607: foreach (@targetselect) {
608: my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
609: if ($url) {
610: $importdetail.='&'.&Apache::lonnet::escape($name).'='.
611: &Apache::lonnet::escape($url);
612: }
613: }
614:
615: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
616: my ($name,$url)=split(/\=/,$curimport[$i]);
617: if ($url) {
618: $importdetail.='&'.$name.'='.$url;
619: }
620: }
621: $importdetail=~s/\&+/\&/g;
622: $importdetail=~s/^\&//;
623:
624: if ($ENV{'form.cut'}) {
625: my @neworder=();
626: for (my $i=0;$i<=$#order;$i++) {
627: my $include=1;
628: foreach (@targetselect) {
629: if ($_-1==$i) { $include=0; }
630: }
631: if ($include) { $neworder[$#neworder+1]=$order[$i]; }
632: }
633: @order=@neworder;
634: &storemap(&Apache::lonnet::filelocation('',$url));
635: }
636:
1.20 www 637: # ----------------------------------------------------------------------- Paste
638: } elsif ($ENV{'form.paste'}) {
1.24 www 639: my $lastsel;
640: if (defined($targetselect[-1])) {
641: $lastsel=$targetselect[-1];
642: } else {
643: $lastsel=$#order+1;
644: }
645: my @newsequence;
646: my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
647: foreach (@importselect) {
648: $newsequence[$#newsequence+1]=$curimport[$_];
649: }
650: &pastetarget($lastsel,@newsequence);
651: &storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 652: # ------------------------------------------------
1.13 www 653: }
1.12 www 654: # ------------------------------------------------------------ Assemble windows
1.20 www 655:
1.13 www 656: my $idx=-1;
1.29 www 657: my $importwindow=
658: '<option value="-1"> ---- Import and Paste Area ---- </option>'.
659: join("\n",map {
1.13 www 660: $idx++;
661: if ($_) {
1.15 www 662: my ($name,$url)=split(/\=/,$_);
663: unless ($name) { $name=(split(/\//,$url))[-1]; }
664: unless ($name) { $name='EMPTY'; }
1.13 www 665: '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
666: '</option>';
667: }
668: } split(/\&/,$importdetail));
1.12 www 669:
1.13 www 670: $idx=0;
1.29 www 671: my $targetwindow=
672: '<option value="0"> ------- Target Edit Map ------- </option>'.
673: join("\n",map {
1.13 www 674: my ($name,$url)=split(/\:/,$resources[$_]);
1.15 www 675: unless ($name) { $name=(split(/\//,$url))[-1]; }
676: unless ($name) { $name='EMPTY'; }
1.13 www 677: $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
678: &Apache::lonnet::escape($url);
679: $idx++;
1.20 www 680: '<option value="'.$idx.'">'.$name.'</option>';
1.11 www 681: } @order);
682:
1.8 www 683: # ----------------------------------------------------- Start simple RAT screen
1.32 www 684: my $editscript=&editscript('simple');
1.3 www 685: $r->print(<<ENDSMPHEAD);
686: <html>
1.6 www 687: <head>
688: <script>
1.15 www 689:
1.32 www 690: $editscript
1.19 www 691:
692: function openview(entry) {
693: var url=unescape((entry.split('='))[1]);
1.20 www 694: var parts=new Array;
695: parts=url.split(':');
696: url=parts.join(':');
1.19 www 697: if (url) { open(url,'cat'); }
698: }
699:
700: function viewtarget() {
701: openview((document.forms.simpleedit.targetdetail.value.split('&'))
702: [document.forms.simpleedit.target.selectedIndex+1]);
703: }
704:
705: function viewimport() {
706: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.27 www 707: [document.forms.simpleedit.importsel.selectedIndex+1]);
1.19 www 708: }
709:
1.6 www 710: </script>
711: </head>
1.3 www 712: <body bgcolor='#FFFFFF'>
1.8 www 713: $buttons
1.7 www 714: <font color=red>$errtext</font>
1.29 www 715: <h1>$url</h1>
1.13 www 716: <form name=simpleedit method=post>
1.11 www 717: <input type=hidden name=forcesmp value=1>
718: <table>
1.12 www 719: <tr><th width="40%">Import</th>
720: <th> </th>
721: <th width="40%">Target</th></tr>
722: <tr><td bgcolor="#FFFFCC">
723: <input type=button onClick="javascript:groupsearch()" value="Group Search">
1.13 www 724: <input type=button onClick="javascript:groupimport();" value="Group Import">
1.15 www 725: after selected
1.14 www 726: <hr>
1.15 www 727: <input type=text size=20 name=importmap>
728: <input type=button
729: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
730: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
1.14 www 731: <input type=submit name="discard" value="Discard Selected">
732: <input type=submit name="clear" value="Clear All">
1.12 www 733: <input type=button onClick="javascript:viewimport()" value="View">
1.16 www 734:
1.12 www 735: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 736:
737: <input type=button onClick=
738: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
739: <input type=button onClick=
740: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
741: after selected
742: <hr><input type=button onClick="javascript:viewtarget()" value="View">
1.12 www 743: </td></tr>
1.16 www 744:
1.27 www 745: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12 www 746: $importwindow
747: </select>
1.11 www 748: </td>
1.12 www 749: <td bgcolor="#FFFFAA" align="center">
750: Cut selected<br>
1.11 www 751: <input type=submit name=cut value='<<<'><p>
1.12 www 752: <hr>
1.25 www 753: Copy selected<br>
754: <input type=submit name=copy value='<--'><p>
755: <hr>
1.12 www 756: Paste after selected<br>
1.25 www 757: <input type=submit name=paste value='-->'>
1.11 www 758: </td>
1.27 www 759: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11 www 760: $targetwindow
761: </select>
1.12 www 762: </table>
1.13 www 763: <input type=hidden name=importdetail value="">
764: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 765: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 766: <input type=hidden name=impfortarget value="0">
1.12 www 767: </form>
768: </body></html>
1.3 www 769: ENDSMPHEAD
770: }
771:
1.11 www 772: # ----------------------------------------------------------------- No such dir
1.4 www 773: sub nodir {
774: my ($r,$dir)=@_;
775: $dir=~s/^\/home\/\w+\/public\_html//;
776: $r->print(<<ENDNODIR);
777: <html>
778: <body bgcolor='#FFFFFF'>
779: <h1>No such directory: $dir</h1>
780: </body>
781: </html>
782: ENDNODIR
783: }
784:
1.8 www 785: # ---------------------------------------------------------------- View Handler
786:
787: sub viewmap {
1.17 www 788: my ($r,$url,$adv,$errtext)=@_;
1.28 www 789: $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
1.10 www 790: if ($errtext) {
791: $r->print($errtext.'<hr>');
792: }
1.26 www 793: my $idx=0;
1.17 www 794: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 795: if (defined($_)) {
1.26 www 796: $idx++;
1.9 www 797: my ($title,$url)=split(/\:/,$_);
798: $title=~s/\&colon\;/\:/g;
799: $url=~s/\&colon\;/\:/g;
1.15 www 800: unless ($title) { $title=(split(/\//,$url))[-1] };
801: unless ($title) { $title='<i>Empty</i>'; }
1.9 www 802: if ($url) {
803: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
804: }
805: $r->print(&Apache::lonratsrv::qtescape($title));
806: if ($url) { $r->print('</a>'); }
1.28 www 807: $r->print('<br>');
1.9 www 808: }
809: }
1.8 www 810: $r->print('</body></html>');
811: }
812:
1.3 www 813: # ================================================================ Main Handler
814:
815: sub handler {
816: my $r=shift;
817: $r->content_type('text/html');
818: $r->send_http_header;
819:
820: return OK if $r->header_only;
821:
822: my $url=$r->uri;
823: my $fn=&Apache::lonnet::filelocation('',$url);
824:
1.4 www 825: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
826: unless (-e $dir) {
827: &nodir($r,$dir);
828: return OK;
829: }
1.8 www 830:
831: # ------------------------------------------- Determine which tools can be used
1.3 www 832: my $adv=0;
833:
834: unless ($ENV{'form.forcesmp'}) {
835: if ($ENV{'form.forceadv'}) {
836: $adv=1;
837: } elsif (my $fh=Apache::File->new($fn)) {
838: my $allmap=join('',<$fh>);
839: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
840: }
841: }
842:
1.8 www 843: my $errtext='';
844: my $fatal=0;
845:
846: # -------------------------------------------------------------------- Load map
847: ($errtext,$fatal)=&mapread($fn,$errtext);
848:
849: if ($fatal==1) { $adv=1; }
850:
851: # ----------------------------------- adv==1 now means "graphical MUST be used"
852:
853: if ($ENV{'form.forceadv'}) {
1.3 www 854: &ratedt($r,$url);
1.8 www 855: } elsif ($ENV{'form.forcesmp'}) {
1.22 www 856: &smpedt($r,$url,$errtext);
1.3 www 857: } else {
1.17 www 858: &viewmap($r,$url,$adv,$errtext);
1.3 www 859: }
1.1 www 860: return OK;
861: }
862:
863: 1;
864: __END__
865:
866:
867:
868:
869:
870:
871:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>