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