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