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