File:
[LON-CAPA] /
rat /
lonratedt.pm
Revision
1.88:
download - view:
text,
annotated -
select for diffs
Wed Jul 11 20:32:01 2007 UTC (17 years, 1 month ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_99_0,
HEAD
- BUG#4168 inhibit the inline menu in the seraching/browsing popup window.
1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.88 2007/07/11 20:32:01 albertel Exp $
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: #
28:
29:
30: package Apache::lonratedt;
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::lonratedt: simple resource assembly tool
37:
38: =head1 SYNOPSIS
39:
40: lonratedt provides the routines and the handler for the Advanced
41: Resource Assembly Tool (RAT), and ties the various pieces together
42: with Javascript.
43:
44: =head1 OVERVIEW
45:
46: =head2 Map Representation
47:
48: =begin latex
49:
50: %
51: \begin{figure}
52: \begin{center}\includegraphics[%
53: width=0.55\paperwidth,bb = 0 0 200 100, draft, type=eps]{Map_Example}\end{center}
54:
55:
56: \caption{\label{Map_In_Advanced_Editor}Example of a Map in the Advanced Editor}
57: \end{figure}
58: %
59: \begin{figure}
60: \begin{lyxcode}
61: <map>
62:
63: ~~<resource~id=\char`\"{}1\char`\"{}
64:
65: ~~~~src=\char`\"{}/res/msu/korte/phy231welcome.html\char`\"{}
66:
67: ~~~~type=\char`\"{}start\char`\"{}
68:
69: ~~~~title=\char`\"{}Start\char`\"{}>
70:
71: ~~~~</resource>
72:
73: ~~<resource~id=\char`\"{}2\char`\"{}
74:
75: ~~~~src=\char`\"{}\char`\"{}~type=\char`\"{}finish\char`\"{}
76:
77: ~~~~title=\char`\"{}Finish\char`\"{}>
78:
79: ~~~~</resource>
80:
81: ~~<resource~id=\char`\"{}6\char`\"{}
82:
83: ~~~~src=\char`\"{}/res/msu/korte/tests/units.problem\char`\"{}
84:
85: ~~~~type=\char`\"{}mandatory\char`\"{}
86:
87: ~~~~title=\char`\"{}Physical~Units~Test\char`\"{}>
88:
89: ~~~~</resource>
90:
91: ~~<resource~id=\char`\"{}9\char`\"{}
92:
93: ~~~~src=\char`\"{}/res/msu/korte/chapters/onedim.sequence\char`\"{}
94:
95: ~~~~title=\char`\"{}Motion~in~One~Dimension\char`\"{}>
96:
97: ~~~~</resource>
98:
99: ~~<resource~id=\char`\"{}11\char`\"{}
100:
101: ~~~~src=\char`\"{}/res/msu/bauer/bridges/units.sequence\char`\"{}
102:
103: ~~~~title=\char`\"{}Physical~Units~Refresher\char`\"{}>
104:
105: ~~~~</resource>
106:
107: ~~<condition~id=\char`\"{}19\char`\"{}
108:
109: ~~~~type=\char`\"{}stop\char`\"{}
110:
111: ~~~~value=\char`\"{}user.assessments{[}this./res/msu/korte/tests/units.problem{]}.status=solved\char`\"{}>
112:
113: ~~~~</condition>
114:
115: ~~<link~from=\char`\"{}1\char`\"{}~to=\char`\"{}6\char`\"{}></link>
116:
117: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}9\char`\"{}~condition=\char`\"{}19\char`\"{}></link>
118:
119: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}11\char`\"{}></link>
120:
121: ~~<link~from=\char`\"{}11\char`\"{}~to=\char`\"{}6\char`\"{}></link>
122:
123: ~~</map>
124: \end{lyxcode}
125:
126: \caption{\label{XML}XML for Map in Figure \ref{Map_In_Advanced_Editor}}
127: \end{figure}
128:
129: =end latex
130:
131: Fig. "XML for Map in Figure" shows the XML representation of the
132: resource map shown in Fig. "Example of a Map in the Advanced Editor",
133: which is the format in which maps are stored. In the figure, however,
134: additional graphical map layout information generated by the Advanced
135: Resource Assembly Tool is not displayed. This graphical information is
136: optional to re-generate the same graphical layout when the map is
137: brought up again in the Resource Assembly Tool, and is not needed for
138: any other system functionality.
139:
140: Maps can be generated by tools other than the Resource Assembly
141: Tool. In particular, an author might have some other representation of
142: a course sequence, which can be converted into a map using scripts. If
143: this map then were to be brought up in the Resource Assembly Tool, the
144: Tool would automatically generate a graphical layout for it. Each
145: entry of the map (resources, conditions and links) is stored in a
146: separate tag.
147:
148: Resources and conditionsX<conditions> have to have unique ID
149: numbers. These numbers are automatically generated by the Resource
150: Assembly Tool when the entry is first created, or added to the entries
151: when a map generated outside the Resource Assembly Tool is first
152: retrieved. They can also be assigned by custom scripts or added in by
153: hand.
154:
155: In the XML example, entry 1 is the start resource of the map. When
156: this map is accessed, the source (src) URL of this tag will be the
157: first resource rendered. Entry 2 is the finish resource of this
158: map. This resource will be the last resource in the sequence of
159: resources. Entry 6 is a problem resource with the given URL and title,
160: as well as the priority "mandatory". Entry 19 is a condition, which is
161: used by the link between entries 6, the problem, and 9, a
162: sequence. I<The final syntax for conditions has not yet been
163: determined.>
164:
165: =cut
166:
167: use strict;
168: use Apache::Constants qw(:common);
169: use Apache::lonnet;
170: use Apache::lonsequence();
171: use Apache::loncommon();
172: use Apache::lonlocal;
173: use LONCAPA::map();
174: use File::Copy;
175: use LONCAPA;
176: use HTML::Entities();
177:
178: # --------------------------------------------------------- Build up RAT screen
179: sub ratedt {
180: my ($r,$url)=@_;
181: my %layout = ('border' => "0");
182: if ($env{'environment.remote'} eq 'off') {
183: $layout{'rows'} = "1,250,*";
184: } else {
185: $layout{'rows'} = "1,70,*";
186: }
187: my $js ='
188: <script type="text/javascript">
189: var flag=0;
190: </script>';
191:
192: my $start_page =
193: &Apache::loncommon::start_page('Edit Sequence',$js,
194: {'frameset' => 1,
195: 'add_entries' => \%layout});
196: my $end_page =
197: &Apache::loncommon::end_page({'frameset' => 1});
198:
199: $r->print(<<ENDDOCUMENT);
200: $start_page
201: <frame name="server" src="$url/loadonly/ratserver" noresize="noresize"
202: noscroll="noscroll" />
203: <frame name="code" src="$url/loadonly/adveditmenu" />
204: <frame name="mapout" src="/adm/rat/map.html" />
205: $end_page
206: ENDDOCUMENT
207: }
208:
209: # ---------------------------------------------------------------- Make buttons
210:
211: sub buttons {
212: my $adv=shift;
213: my $output='<form method=post>';
214: if ($adv==1) {
215: $output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
216: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
217: } else {
218: unless ($adv==2) {
219: $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
220: &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
221: }
222: $output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
223: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
224: }
225: return $output.'</form><hr>';
226: }
227:
228: # ----------------------------------------------------------------- Edit script
229: sub editscript {
230: my $mode=shift;
231: my $resurl=
232: &Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
233: return(<<ENDSCRIPT);
234: var srch;
235: var srchflag=-1; // 1 means currently open
236: // 0 means closed (but has been open)
237: // -1 means never yet opened/defined
238: var srchmode='';
239:
240: var idx;
241: var idxflag=-1; // 1 means currently open
242: // 0 means closed (but has been open)
243: // -1 means never yet opened/defined
244: var idxmode='';
245:
246: // ------------------------------------------------------ Clears indexer window
247: function idxclear() {
248: idx.document.clear();
249: }
250:
251: // ------------------------------------------------------- Clears search window
252: function srchclear() {
253: srch.document.clear();
254: }
255:
256: // ------------------------------------------------------ Closes indexer window
257: function idxclose() {
258: if (idx && !idx.closed) {
259: idxflag=0;
260: idx.close();
261: }
262: }
263:
264: // ------------------------------------------------------- Closes search window
265: function srchclose() {
266: if (srch && !srch.closed) {
267: srchflag=0;
268: srch.close();
269: }
270: }
271:
272: // -------------------------------------------------------- Open indexer window
273: function idxopen(mode) {
274: var options="scrollbars=1,resizable=1,menubar=0,location=1,toolbar=1";
275: idxmode=mode;
276: idxflag=1;
277: idx=open('$resurl/?inhibitmenu=yes&launch=1&mode=$mode&catalogmode='+mode,'idxout',options);
278: idx.focus();
279: }
280:
281: // ------------------------------------------------------ Open groupsort window
282: function groupopen(url,recover,bookmarks) {
283: var options="scrollbars=1,resizable=1,menubar=0";
284: idxflag=1;
285: idx=open("/adm/groupsort?inhibitmenu=yes&mode=$mode&recover="+recover+"&readfile="+url+"&bookmarks="+bookmarks,"idxout",options);
286: idx.focus();
287: }
288:
289: // --------------------------------------------------------- Open search window
290: function srchopen(mode) {
291: var options="scrollbars=1,resizable=1,menubar=0";
292: srchmode=mode;
293: srchflag=1;
294: srch=open("/adm/searchcat?inhibitmenu=yes&launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
295: srch.focus();
296: }
297: // ----------------------------------------------------- launch indexer browser
298: function groupsearch() {
299: srchcheck('import');
300: }
301:
302: function groupimport() {
303: idxcheck('import');
304: }
305:
306: // ------------------------------------------------------- Do srch status check
307: function srchcheck(mode) {
308: if (!srch || srch.closed || srchmode!=mode) {
309: srchopen(mode);
310: }
311: srch.focus();
312: }
313:
314: // -------------------------------------------------------- Do idx status check
315: function idxcheck(mode) {
316: if (!idx || idx.closed || idxmode!=mode) {
317: idxopen(mode);
318: }
319: idx.focus();
320: }
321:
322:
323: var editbrowser;
324: function openbrowser(formname,elementname,only,omit) {
325: var url = '$resurl/?';
326: if (editbrowser == null) {
327: url += 'launch=1&';
328: }
329: url += 'inhibitmenu=yes&';
330: url += 'catalogmode=interactive&';
331: url += 'mode=edit&';
332: url += 'form=' + formname + '&';
333: if (only != null) {
334: url += 'only=' + only + '&';
335: }
336: if (omit != null) {
337: url += 'omit=' + omit + '&';
338: }
339: url += 'element=' + elementname + '';
340: var title = 'Browser';
341: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
342: options += ',width=700,height=600';
343: editbrowser = open(url,title,options,'1');
344: editbrowser.focus();
345: }
346: ENDSCRIPT
347: }
348: # ------------------------------------------------------- Simple edit processor
349:
350: sub smpedt {
351: my ($r,$url,$errtext)=@_;
352: my $buttons=&buttons(2);
353: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
354: my $targetmsg='';
355: if ($env{'form.save'}) {
356: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
357: unlink($tmpfn);
358: my ($errtext,$fatal)=
359: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
360: unless ($fatal) {
361: $targetmsg='<b>'.&mt('Saved.').'</b><br />';
362: } else {
363: $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
364: }
365: }
366: if ($env{'form.revert'}) {
367: $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
368: unlink($tmpfn);
369: my ($errtext,$fatal)=
370: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
371: }
372: if (-e $tmpfn) {
373: $targetmsg=
374: '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
375: my ($errtext,$fatal)=&LONCAPA::map::mapread($tmpfn,'');
376: }
377: # ---------------------------------------------------------- Process form input
378:
379: my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
380: my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
381: # ============================================================ Process commands
382:
383: my $targetdetail=$env{'form.targetdetail'};
384: my $importdetail=$env{'form.curimpdetail'};
385:
386: # ---------------------------------------------------- Importing from groupsort
387: if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
388:
389: $importdetail='';
390: my @curimport=split(/\&/,$env{'form.curimpdetail'});
391:
392: my $lastsel;
393:
394: if (defined($importselect[-1])) {
395: $lastsel=$importselect[-1];
396: } else {
397: $lastsel=$#curimport;
398: }
399:
400: for (my $i=0;$i<=$lastsel;$i++) {
401: my ($name,$url)=split(/\=/,$curimport[$i]);
402: if ($url) {
403: $importdetail.='&'.$name.'='.$url;
404: }
405: }
406:
407: $importdetail.='&'.$env{'form.importdetail'};
408:
409: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
410: my ($name,$url)=split(/\=/,$curimport[$i]);
411: if ($url) {
412: $importdetail.='&'.$name.'='.$url;
413: }
414: }
415: $importdetail=~s/\&+/\&/g;
416: $importdetail=~s/^\&//;
417:
418: # ------------------------------------------------------------------- Clear all
419: } elsif ($env{'form.clear'}) {
420: $importdetail='';
421: # ------------------------------------------------------------ Discard selected
422: } elsif ($env{'form.discard'}) {
423: $importdetail='';
424: my @curimport=split(/\&/,$env{'form.curimpdetail'});
425: foreach (@importselect) {
426: $curimport[$_]='';
427: }
428: for (my $i=0;$i<=$#curimport;$i++) {
429: my ($name,$url)=split(/\=/,$curimport[$i]);
430: if ($url) {
431: $importdetail.='&'.$name.'='.$url;
432: }
433: }
434: # --------------------------------------------------------- Loading another map
435: } elsif ($env{'form.loadmap'}) {
436: $importdetail='';
437: my @curimport=split(/\&/,$env{'form.curimpdetail'});
438:
439: my $lastsel;
440:
441: if (defined($importselect[-1])) {
442: $lastsel=$importselect[-1];
443: } else {
444: $lastsel=$#curimport;
445: }
446:
447: for (my $i=0;$i<=$lastsel;$i++) {
448: my ($name,$url)=split(/\=/,$curimport[$i]);
449: if ($url) {
450: $importdetail.='&'.$name.'='.$url;
451: }
452: }
453:
454: foreach (
455: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
456: my ($name,$url)=split(/\:/,$_);
457: if ($url) {
458: $importdetail.='&'.&escape($name).'='.
459: &escape($url);
460: }
461: }
462:
463: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
464: my ($name,$url)=split(/\=/,$curimport[$i]);
465: if ($url) {
466: $importdetail.='&'.$name.'='.$url;
467: }
468: }
469: $importdetail=~s/\&+/\&/g;
470: $importdetail=~s/^\&//;
471:
472: # ------------------------------------------------ Groupimport/search to target
473: } elsif ($env{'form.importdetail'}) {
474: my $lastsel;
475: if (defined($targetselect[-1])) {
476: $lastsel=$targetselect[-1];
477: } else {
478: $lastsel=$#LONCAPA::map::order+1;
479: }
480: &LONCAPA::map::pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
481: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
482: # ------------------------------------------------------------------------- Cut
483: } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
484: $importdetail='';
485: my @curimport=split(/\&/,$env{'form.curimpdetail'});
486:
487: my $lastsel;
488:
489: if (defined($importselect[-1])) {
490: $lastsel=$importselect[-1];
491: } else {
492: $lastsel=$#curimport;
493: }
494:
495: for (my $i=0;$i<=$lastsel;$i++) {
496: my ($name,$url)=split(/\=/,$curimport[$i]);
497: if ($url) {
498: $importdetail.='&'.$name.'='.$url;
499: }
500: }
501:
502: foreach (@targetselect) {
503: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$LONCAPA::map::order[$_-1]]);
504: if ($url) {
505: $importdetail.='&'.&escape($name).'='.
506: &escape($url);
507: }
508: }
509:
510: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
511: my ($name,$url)=split(/\=/,$curimport[$i]);
512: if ($url) {
513: $importdetail.='&'.$name.'='.$url;
514: }
515: }
516: $importdetail=~s/\&+/\&/g;
517: $importdetail=~s/^\&//;
518:
519: if ($env{'form.cut'}) {
520: my @neworder=();
521: for (my $i=0;$i<=$#LONCAPA::map::order;$i++) {
522: my $include=1;
523: foreach (@targetselect) {
524: if ($_-1==$i) { $include=0; }
525: }
526: if ($include) {
527: $neworder[$#neworder+1]=$LONCAPA::map::order[$i];
528: } else {
529: &LONCAPA::map::makezombie($LONCAPA::map::order[$i]);
530: }
531: }
532: @LONCAPA::map::order=@neworder;
533: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
534: }
535:
536: # ----------------------------------------------------------------------- Paste
537: } elsif ($env{'form.paste'}) {
538: my $lastsel;
539: if (defined($targetselect[-1])) {
540: $lastsel=$targetselect[-1];
541: } else {
542: $lastsel=$#LONCAPA::map::order+1;
543: }
544: my @newsequence;
545: my @curimport=split(/\&/,$env{'form.curimpdetail'});
546: foreach (@importselect) {
547: $newsequence[$#newsequence+1]=$curimport[$_];
548: }
549: &LONCAPA::map::pastetarget($lastsel,@newsequence);
550: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
551: # -------------------------------------------------------------------- Move up
552: } elsif ($env{'form.moveup'}) {
553: foreach (sort @targetselect) {
554: if ($_-1>0) {
555: my $movethis=$LONCAPA::map::order[$_-1];
556: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_-2];
557: $LONCAPA::map::order[$_-2]=$movethis;
558: }
559: }
560: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
561: # ------------------------------------------------------------------ Move down
562: } elsif ($env{'form.movedown'}) {
563: foreach (reverse sort @targetselect) {
564: if ($_-1<$#LONCAPA::map::order) {
565: my $movethis=$LONCAPA::map::order[$_-1];
566: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_];
567: $LONCAPA::map::order[$_]=$movethis;
568: }
569: }
570: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
571: # --------------------------------------------------------------------- Rename
572: } elsif ($env{'form.renameres'}) {
573: my $residx=$LONCAPA::map::order[$env{'form.renameidx'}-1];
574: my ($name,@resrest)=split(/\:/,$LONCAPA::map::resources[$residx]);
575: $name=$env{'form.renametitle'};
576: $name=~s/\:/\&colon\;/g;
577: $LONCAPA::map::resources[$residx]=$name.':'.join(':',@resrest);
578: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
579: }
580: # ------------------------------------------------------------ Assemble windows
581:
582: my $idx=-1;
583: $importdetail='&'.$importdetail;
584: $importdetail=~s/^\&+/\&/;
585: my $importwindow=
586: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
587: join("\n",map {
588: $idx++;
589: if ($_) {
590: my ($name,$url)=split(/\=/,$_);
591: unless ($name) { $name=(split(/\//,$url))[-1]; }
592: unless ($name) { $name='EMPTY'; }
593: '<option value="'.$idx.'">'.&unescape($name).
594: '</option>';
595: }
596: } split(/\&/,$importdetail));
597:
598: $idx=0;
599: $targetdetail='';
600: my $targetwindow=
601: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
602: join("\n",map {
603: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
604: unless ($name) { $name=(split(/\//,$url))[-1]; }
605: unless ($name) { $name='EMPTY'; }
606: $name = &LONCAPA::map::qtescape($name);
607: $url = &LONCAPA::map::qtescape($url);
608: $targetdetail.='&'.&escape($name).'='.
609: &escape($url);
610: $idx++;
611: $name = &HTML::Entities::encode($name,'\'"<>&');
612: '<option value="'.$idx.'">'.$name.'</option>';
613: } @LONCAPA::map::order);
614:
615: # ----------------------------------------------------- Start simple RAT screen
616: my $editscript=&editscript('simple');
617:
618: my %lt=&Apache::lonlocal::texthash(
619: 'sa' => 'Save',
620: 'nt' => 'New Title',
621: 'se' => 'Search',
622: 'im' => 'Import',
623: 'bk' => 'Import Bookmarks',
624: 'vi' => 'View',
625: 'lm' => 'Load Map',
626: 'ds' => 'Discard Selected',
627: 'ca' => 'Clear All',
628: 'ta' => 'Temporary Assembly Workspace',
629: 'rv' => 'Revert to Last Saved',
630: 'sa' => 'Save',
631: 'mu' => 'Move Up',
632: 'md' => 'Move Down',
633: 're' => 'Rename',
634: 'as' => 'after selected',
635: 'cs' => 'Cut selected',
636: 'ps' => 'Copy selected',
637: 'pas' => 'Paste after selected',
638: 'reco' => 'Recover Deleted'
639: );
640: my $js=<<ENDJS;
641: <script type="text/javascript">
642:
643: $editscript
644:
645: function openview(entry) {
646: var url=unescape((entry.split('='))[1]);
647: var parts=new Array;
648: if (url) { open(url,'cat'); }
649: }
650:
651: function viewtarget() {
652: openview((document.forms.simpleedit.targetdetail.value.split('&'))
653: [document.forms.simpleedit.target.selectedIndex]);
654: }
655:
656: function viewimport() {
657: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
658: [document.forms.simpleedit.importsel.selectedIndex]);
659: }
660:
661: function renametarget() {
662: var selidx=document.forms.simpleedit.target.selectedIndex;
663: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
664: [selidx];
665: var oldname=unescape((entry.split('='))[0]);
666: newtitle=prompt('$lt{'nt'}',oldname);
667: if (newtitle) {
668: document.forms.simpleedit.renameres.value=1;
669: document.forms.simpleedit.renameidx.value=selidx;
670: document.forms.simpleedit.renametitle.value=newtitle;
671: document.forms.simpleedit.submit();
672: }
673: }
674:
675: </script>
676: ENDJS
677:
678: my $start_page = &Apache::loncommon::start_page(undef,$js).
679: &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
680: 'Sequence_Simple_Editor_Creation',
681: 6,'RAT');
682: my $end_page = &Apache::loncommon::end_page();
683:
684: $r->print(<<ENDSMPHEAD);
685: $start_page
686: $buttons
687: <font color=red>$errtext</font>
688: <form name=simpleedit method=post>
689: <input type=hidden name=forcesmp value=1>
690: <input type=hidden name=renameres value=0>
691: <input type=hidden name=renametitle value=''>
692: <input type=hidden name=renameidx value=0>
693: <table>
694: <tr><th width="40%">$lt{'ta'}</th>
695: <th> </th>
696: <th width="40%">File: $url</th></tr>
697: <tr><td bgcolor="#FFFFCC">
698: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
699: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
700: $lt{'as'}
701: <hr>
702: <input type=text size=20 name=importmap>
703: <input type=button
704: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
705: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
706: <input type=submit name="discard" value="$lt{'ds'}">
707: <input type=submit name="clear" value="$lt{'ca'}">
708: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
709:
710: </td><td> </td><td bgcolor="#FFFFCC">
711:
712: <input type=button onClick=
713: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
714: <input type=button onClick=
715: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
716: <input type=button onClick=
717: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}">
718: <input type=button onClick=
719: "javascript:impfortarget.value=1;groupopen('$url',1,0);" value="$lt{'reco'}">
720: $lt{'as'}
721: <hr>
722: <input type=submit name="moveup" value="$lt{'mu'}">
723: <input type=submit name="movedown" value="$lt{'md'}">
724: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
725: <hr>$targetmsg
726: <input type=submit name="revert" value="$lt{'rv'}">
727: <input type=submit name="save" value="$lt{'sa'}">
728: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
729: </td></tr>
730:
731: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
732: $importwindow
733: </select>
734: </td>
735: <td bgcolor="#FFFFAA" align="center">
736: $lt{'cs'}<br>
737: <input type=submit name=cut value='<<<'><p>
738: <hr>
739: $lt{'ps'}<br>
740: <input type=submit name=copy value='<--'><p>
741: <hr>
742: $lt{'pas'}<br>
743: <input type=submit name=paste value='-->'>
744: </td>
745: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
746: $targetwindow
747: </select>
748: </table>
749: <input type=hidden name=importdetail value="">
750: <input type=hidden name=curimpdetail value="$importdetail">
751: <input type=hidden name=targetdetail value="$targetdetail">
752: <input type=hidden name=impfortarget value="0">
753: </form>
754: $end_page
755: ENDSMPHEAD
756: }
757:
758: # ----------------------------------------------------------------- No such dir
759: sub nodir {
760: my ($r,$dir)=@_;
761: $dir=~s{^/home/$LONCAPA::username_re/public_html}{};
762: $r->print(&Apache::loncommon::start_page(undef,undef,
763: {'only_body' => 1,
764: 'bgcolor' => '#FFFFFF',}).
765: "<h1>No such directory: $dir</h1>".
766: &Apache::loncommon::end_page());
767: }
768:
769: # ---------------------------------------------------------------- View Handler
770:
771: sub viewmap {
772: my ($r,$url,$adv,$errtext)=@_;
773: $r->print(
774: &Apache::loncommon::start_page('Edit Content of a Map').
775: &Apache::loncommon::help_open_menu('','',6,'RAT').
776: &buttons($adv));
777: if ($errtext) {
778: $r->print($errtext.'<hr />');
779: }
780: my $idx=0;
781: $r->print('<h1>'.$url.'</h1>');
782: if ($adv) {
783: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
784: }
785: $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
786: '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
787: '<th>'.&mt('Title in map').'</th>'.
788: '<th>'.&mt('Filename of resource').'</th>'.
789: '<th>'.&mt('Link to published resource').'</th>'.
790: '<th>'.&mt('Link to resource in Construction Space').'</th>'.
791: '</tr>');
792: my @backgroundColors = ("#FFFFFF", "#F6F6F6");
793: foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
794: if (defined($_)) {
795: $idx++;
796: my ($title,$url,$cond)=split(/\:/,$_);
797: if ($cond eq 'cond') { next; }
798: $title= &LONCAPA::map::qtescape($title);
799: $url = &LONCAPA::map::qtescape($url);
800: unless ($title) { $title=(split(/\//,$url))[-1] };
801: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
802: my $resurl = $url;
803: my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
804: my $filename;
805: if ($resurl =~ m#/([^/]+)$#) {
806: $filename = $1;
807: }
808: my $cstrurl = $resurl;
809: $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
810: my $bgcol = $idx%2;
811: $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
812: '<img src="'.&Apache::loncommon::icon($resfilepath).
813: '" /></td><td>'.&HTML::Entities::encode(&LONCAPA::map::qtescape($title)).
814: '</td><td>'.$filename.'</td><td>');
815: if ($url) {
816: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
817: }
818: $r->print('</td><td>');
819: if ($url) {
820: $r->print('<a href="'.$cstrurl.'">'.
821: &mt('Construction space').'</a>');
822: }
823: $r->print('</td></tr>'."\n");
824: }
825: }
826: $r->print('</table>');
827: $r->print(&Apache::loncommon::end_page());
828: }
829:
830: # ================================================================ Main Handler
831:
832: sub handler {
833: my $r=shift;
834: &Apache::loncommon::content_type($r,'text/html');
835: $r->send_http_header;
836:
837: return OK if $r->header_only;
838: my $target = $env{'form.grade_target'};
839: if ($target eq 'meta') {
840: &Apache::loncommon::content_type($r,'text/html');
841: $r->send_http_header;
842: return OK;
843: }
844:
845: my $url=$r->uri;
846: my $fn=&Apache::lonnet::filelocation('',$url);
847:
848: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
849: unless (-e $dir) {
850: &nodir($r,$dir);
851: return OK;
852: }
853:
854: # ------------------------------------------- Determine which tools can be used
855: my $adv=0;
856:
857: unless ($env{'form.forcesmp'}) {
858: if ($env{'form.forceadv'}) {
859: $adv=1;
860: } elsif (my $fh=Apache::File->new($fn)) {
861: my $allmap=join('',<$fh>);
862: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
863: }
864: }
865:
866: my $errtext='';
867: my $fatal=0;
868:
869: # -------------------------------------------------------------------- Load map
870: ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
871:
872: if ($fatal==1) { $adv=1; }
873:
874: # ----------------------------------- adv==1 now means "graphical MUST be used"
875:
876: if ($env{'form.forceadv'}) {
877: &ratedt($r,$url);
878: } elsif ($env{'form.forcesmp'}) {
879: &smpedt($r,$url,$errtext);
880: } else {
881: &viewmap($r,$url,$adv,$errtext);
882: }
883: return OK;
884: }
885:
886: 1;
887: __END__
888:
889:
890:
891:
892:
893:
894:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>