File:
[LON-CAPA] /
rat /
lonratedt.pm
Revision
1.87:
download - view:
text,
annotated -
select for diffs
Tue Jan 16 21:10:55 2007 UTC (17 years, 7 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_4_X,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
HEAD
- Simple Rat wasn't handling around urls with , correctly (BUG#5147)
1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.87 2007/01/16 21:10:55 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/?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?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?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 += 'catalogmode=interactive&';
330: url += 'mode=edit&';
331: url += 'form=' + formname + '&';
332: if (only != null) {
333: url += 'only=' + only + '&';
334: }
335: if (omit != null) {
336: url += 'omit=' + omit + '&';
337: }
338: url += 'element=' + elementname + '';
339: var title = 'Browser';
340: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
341: options += ',width=700,height=600';
342: editbrowser = open(url,title,options,'1');
343: editbrowser.focus();
344: }
345: ENDSCRIPT
346: }
347: # ------------------------------------------------------- Simple edit processor
348:
349: sub smpedt {
350: my ($r,$url,$errtext)=@_;
351: my $buttons=&buttons(2);
352: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
353: my $targetmsg='';
354: if ($env{'form.save'}) {
355: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
356: unlink($tmpfn);
357: my ($errtext,$fatal)=
358: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
359: unless ($fatal) {
360: $targetmsg='<b>'.&mt('Saved.').'</b><br />';
361: } else {
362: $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
363: }
364: }
365: if ($env{'form.revert'}) {
366: $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
367: unlink($tmpfn);
368: my ($errtext,$fatal)=
369: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
370: }
371: if (-e $tmpfn) {
372: $targetmsg=
373: '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
374: my ($errtext,$fatal)=&LONCAPA::map::mapread($tmpfn,'');
375: }
376: # ---------------------------------------------------------- Process form input
377:
378: my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
379: my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
380: # ============================================================ Process commands
381:
382: my $targetdetail=$env{'form.targetdetail'};
383: my $importdetail=$env{'form.curimpdetail'};
384:
385: # ---------------------------------------------------- Importing from groupsort
386: if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
387:
388: $importdetail='';
389: my @curimport=split(/\&/,$env{'form.curimpdetail'});
390:
391: my $lastsel;
392:
393: if (defined($importselect[-1])) {
394: $lastsel=$importselect[-1];
395: } else {
396: $lastsel=$#curimport;
397: }
398:
399: for (my $i=0;$i<=$lastsel;$i++) {
400: my ($name,$url)=split(/\=/,$curimport[$i]);
401: if ($url) {
402: $importdetail.='&'.$name.'='.$url;
403: }
404: }
405:
406: $importdetail.='&'.$env{'form.importdetail'};
407:
408: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
409: my ($name,$url)=split(/\=/,$curimport[$i]);
410: if ($url) {
411: $importdetail.='&'.$name.'='.$url;
412: }
413: }
414: $importdetail=~s/\&+/\&/g;
415: $importdetail=~s/^\&//;
416:
417: # ------------------------------------------------------------------- Clear all
418: } elsif ($env{'form.clear'}) {
419: $importdetail='';
420: # ------------------------------------------------------------ Discard selected
421: } elsif ($env{'form.discard'}) {
422: $importdetail='';
423: my @curimport=split(/\&/,$env{'form.curimpdetail'});
424: foreach (@importselect) {
425: $curimport[$_]='';
426: }
427: for (my $i=0;$i<=$#curimport;$i++) {
428: my ($name,$url)=split(/\=/,$curimport[$i]);
429: if ($url) {
430: $importdetail.='&'.$name.'='.$url;
431: }
432: }
433: # --------------------------------------------------------- Loading another map
434: } elsif ($env{'form.loadmap'}) {
435: $importdetail='';
436: my @curimport=split(/\&/,$env{'form.curimpdetail'});
437:
438: my $lastsel;
439:
440: if (defined($importselect[-1])) {
441: $lastsel=$importselect[-1];
442: } else {
443: $lastsel=$#curimport;
444: }
445:
446: for (my $i=0;$i<=$lastsel;$i++) {
447: my ($name,$url)=split(/\=/,$curimport[$i]);
448: if ($url) {
449: $importdetail.='&'.$name.'='.$url;
450: }
451: }
452:
453: foreach (
454: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
455: my ($name,$url)=split(/\:/,$_);
456: if ($url) {
457: $importdetail.='&'.&escape($name).'='.
458: &escape($url);
459: }
460: }
461:
462: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
463: my ($name,$url)=split(/\=/,$curimport[$i]);
464: if ($url) {
465: $importdetail.='&'.$name.'='.$url;
466: }
467: }
468: $importdetail=~s/\&+/\&/g;
469: $importdetail=~s/^\&//;
470:
471: # ------------------------------------------------ Groupimport/search to target
472: } elsif ($env{'form.importdetail'}) {
473: my $lastsel;
474: if (defined($targetselect[-1])) {
475: $lastsel=$targetselect[-1];
476: } else {
477: $lastsel=$#LONCAPA::map::order+1;
478: }
479: &LONCAPA::map::pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
480: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
481: # ------------------------------------------------------------------------- Cut
482: } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
483: $importdetail='';
484: my @curimport=split(/\&/,$env{'form.curimpdetail'});
485:
486: my $lastsel;
487:
488: if (defined($importselect[-1])) {
489: $lastsel=$importselect[-1];
490: } else {
491: $lastsel=$#curimport;
492: }
493:
494: for (my $i=0;$i<=$lastsel;$i++) {
495: my ($name,$url)=split(/\=/,$curimport[$i]);
496: if ($url) {
497: $importdetail.='&'.$name.'='.$url;
498: }
499: }
500:
501: foreach (@targetselect) {
502: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$LONCAPA::map::order[$_-1]]);
503: if ($url) {
504: $importdetail.='&'.&escape($name).'='.
505: &escape($url);
506: }
507: }
508:
509: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
510: my ($name,$url)=split(/\=/,$curimport[$i]);
511: if ($url) {
512: $importdetail.='&'.$name.'='.$url;
513: }
514: }
515: $importdetail=~s/\&+/\&/g;
516: $importdetail=~s/^\&//;
517:
518: if ($env{'form.cut'}) {
519: my @neworder=();
520: for (my $i=0;$i<=$#LONCAPA::map::order;$i++) {
521: my $include=1;
522: foreach (@targetselect) {
523: if ($_-1==$i) { $include=0; }
524: }
525: if ($include) {
526: $neworder[$#neworder+1]=$LONCAPA::map::order[$i];
527: } else {
528: &LONCAPA::map::makezombie($LONCAPA::map::order[$i]);
529: }
530: }
531: @LONCAPA::map::order=@neworder;
532: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
533: }
534:
535: # ----------------------------------------------------------------------- Paste
536: } elsif ($env{'form.paste'}) {
537: my $lastsel;
538: if (defined($targetselect[-1])) {
539: $lastsel=$targetselect[-1];
540: } else {
541: $lastsel=$#LONCAPA::map::order+1;
542: }
543: my @newsequence;
544: my @curimport=split(/\&/,$env{'form.curimpdetail'});
545: foreach (@importselect) {
546: $newsequence[$#newsequence+1]=$curimport[$_];
547: }
548: &LONCAPA::map::pastetarget($lastsel,@newsequence);
549: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
550: # -------------------------------------------------------------------- Move up
551: } elsif ($env{'form.moveup'}) {
552: foreach (sort @targetselect) {
553: if ($_-1>0) {
554: my $movethis=$LONCAPA::map::order[$_-1];
555: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_-2];
556: $LONCAPA::map::order[$_-2]=$movethis;
557: }
558: }
559: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
560: # ------------------------------------------------------------------ Move down
561: } elsif ($env{'form.movedown'}) {
562: foreach (reverse sort @targetselect) {
563: if ($_-1<$#LONCAPA::map::order) {
564: my $movethis=$LONCAPA::map::order[$_-1];
565: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_];
566: $LONCAPA::map::order[$_]=$movethis;
567: }
568: }
569: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
570: # --------------------------------------------------------------------- Rename
571: } elsif ($env{'form.renameres'}) {
572: my $residx=$LONCAPA::map::order[$env{'form.renameidx'}-1];
573: my ($name,@resrest)=split(/\:/,$LONCAPA::map::resources[$residx]);
574: $name=$env{'form.renametitle'};
575: $name=~s/\:/\&colon\;/g;
576: $LONCAPA::map::resources[$residx]=$name.':'.join(':',@resrest);
577: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
578: }
579: # ------------------------------------------------------------ Assemble windows
580:
581: my $idx=-1;
582: $importdetail='&'.$importdetail;
583: $importdetail=~s/^\&+/\&/;
584: my $importwindow=
585: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
586: join("\n",map {
587: $idx++;
588: if ($_) {
589: my ($name,$url)=split(/\=/,$_);
590: unless ($name) { $name=(split(/\//,$url))[-1]; }
591: unless ($name) { $name='EMPTY'; }
592: '<option value="'.$idx.'">'.&unescape($name).
593: '</option>';
594: }
595: } split(/\&/,$importdetail));
596:
597: $idx=0;
598: $targetdetail='';
599: my $targetwindow=
600: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
601: join("\n",map {
602: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
603: unless ($name) { $name=(split(/\//,$url))[-1]; }
604: unless ($name) { $name='EMPTY'; }
605: $name = &LONCAPA::map::qtescape($name);
606: $url = &LONCAPA::map::qtescape($url);
607: $targetdetail.='&'.&escape($name).'='.
608: &escape($url);
609: $idx++;
610: $name = &HTML::Entities::encode($name,'\'"<>&');
611: '<option value="'.$idx.'">'.$name.'</option>';
612: } @LONCAPA::map::order);
613:
614: # ----------------------------------------------------- Start simple RAT screen
615: my $editscript=&editscript('simple');
616:
617: my %lt=&Apache::lonlocal::texthash(
618: 'sa' => 'Save',
619: 'nt' => 'New Title',
620: 'se' => 'Search',
621: 'im' => 'Import',
622: 'bk' => 'Import Bookmarks',
623: 'vi' => 'View',
624: 'lm' => 'Load Map',
625: 'ds' => 'Discard Selected',
626: 'ca' => 'Clear All',
627: 'ta' => 'Temporary Assembly Workspace',
628: 'rv' => 'Revert to Last Saved',
629: 'sa' => 'Save',
630: 'mu' => 'Move Up',
631: 'md' => 'Move Down',
632: 're' => 'Rename',
633: 'as' => 'after selected',
634: 'cs' => 'Cut selected',
635: 'ps' => 'Copy selected',
636: 'pas' => 'Paste after selected',
637: 'reco' => 'Recover Deleted'
638: );
639: my $js=<<ENDJS;
640: <script type="text/javascript">
641:
642: $editscript
643:
644: function openview(entry) {
645: var url=unescape((entry.split('='))[1]);
646: var parts=new Array;
647: if (url) { open(url,'cat'); }
648: }
649:
650: function viewtarget() {
651: openview((document.forms.simpleedit.targetdetail.value.split('&'))
652: [document.forms.simpleedit.target.selectedIndex]);
653: }
654:
655: function viewimport() {
656: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
657: [document.forms.simpleedit.importsel.selectedIndex]);
658: }
659:
660: function renametarget() {
661: var selidx=document.forms.simpleedit.target.selectedIndex;
662: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
663: [selidx];
664: var oldname=unescape((entry.split('='))[0]);
665: newtitle=prompt('$lt{'nt'}',oldname);
666: if (newtitle) {
667: document.forms.simpleedit.renameres.value=1;
668: document.forms.simpleedit.renameidx.value=selidx;
669: document.forms.simpleedit.renametitle.value=newtitle;
670: document.forms.simpleedit.submit();
671: }
672: }
673:
674: </script>
675: ENDJS
676:
677: my $start_page = &Apache::loncommon::start_page(undef,$js).
678: &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
679: 'Sequence_Simple_Editor_Creation',
680: 6,'RAT');
681: my $end_page = &Apache::loncommon::end_page();
682:
683: $r->print(<<ENDSMPHEAD);
684: $start_page
685: $buttons
686: <font color=red>$errtext</font>
687: <form name=simpleedit method=post>
688: <input type=hidden name=forcesmp value=1>
689: <input type=hidden name=renameres value=0>
690: <input type=hidden name=renametitle value=''>
691: <input type=hidden name=renameidx value=0>
692: <table>
693: <tr><th width="40%">$lt{'ta'}</th>
694: <th> </th>
695: <th width="40%">File: $url</th></tr>
696: <tr><td bgcolor="#FFFFCC">
697: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
698: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
699: $lt{'as'}
700: <hr>
701: <input type=text size=20 name=importmap>
702: <input type=button
703: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
704: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
705: <input type=submit name="discard" value="$lt{'ds'}">
706: <input type=submit name="clear" value="$lt{'ca'}">
707: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
708:
709: </td><td> </td><td bgcolor="#FFFFCC">
710:
711: <input type=button onClick=
712: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
713: <input type=button onClick=
714: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
715: <input type=button onClick=
716: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}">
717: <input type=button onClick=
718: "javascript:impfortarget.value=1;groupopen('$url',1,0);" value="$lt{'reco'}">
719: $lt{'as'}
720: <hr>
721: <input type=submit name="moveup" value="$lt{'mu'}">
722: <input type=submit name="movedown" value="$lt{'md'}">
723: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
724: <hr>$targetmsg
725: <input type=submit name="revert" value="$lt{'rv'}">
726: <input type=submit name="save" value="$lt{'sa'}">
727: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
728: </td></tr>
729:
730: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
731: $importwindow
732: </select>
733: </td>
734: <td bgcolor="#FFFFAA" align="center">
735: $lt{'cs'}<br>
736: <input type=submit name=cut value='<<<'><p>
737: <hr>
738: $lt{'ps'}<br>
739: <input type=submit name=copy value='<--'><p>
740: <hr>
741: $lt{'pas'}<br>
742: <input type=submit name=paste value='-->'>
743: </td>
744: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
745: $targetwindow
746: </select>
747: </table>
748: <input type=hidden name=importdetail value="">
749: <input type=hidden name=curimpdetail value="$importdetail">
750: <input type=hidden name=targetdetail value="$targetdetail">
751: <input type=hidden name=impfortarget value="0">
752: </form>
753: $end_page
754: ENDSMPHEAD
755: }
756:
757: # ----------------------------------------------------------------- No such dir
758: sub nodir {
759: my ($r,$dir)=@_;
760: $dir=~s{^/home/$LONCAPA::username_re/public_html}{};
761: $r->print(&Apache::loncommon::start_page(undef,undef,
762: {'only_body' => 1,
763: 'bgcolor' => '#FFFFFF',}).
764: "<h1>No such directory: $dir</h1>".
765: &Apache::loncommon::end_page());
766: }
767:
768: # ---------------------------------------------------------------- View Handler
769:
770: sub viewmap {
771: my ($r,$url,$adv,$errtext)=@_;
772: $r->print(
773: &Apache::loncommon::start_page('Edit Content of a Map').
774: &Apache::loncommon::help_open_menu('','',6,'RAT').
775: &buttons($adv));
776: if ($errtext) {
777: $r->print($errtext.'<hr />');
778: }
779: my $idx=0;
780: $r->print('<h1>'.$url.'</h1>');
781: if ($adv) {
782: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
783: }
784: $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
785: '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
786: '<th>'.&mt('Title in map').'</th>'.
787: '<th>'.&mt('Filename of resource').'</th>'.
788: '<th>'.&mt('Link to published resource').'</th>'.
789: '<th>'.&mt('Link to resource in Construction Space').'</th>'.
790: '</tr>');
791: my @backgroundColors = ("#FFFFFF", "#F6F6F6");
792: foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
793: if (defined($_)) {
794: $idx++;
795: my ($title,$url,$cond)=split(/\:/,$_);
796: if ($cond eq 'cond') { next; }
797: $title= &LONCAPA::map::qtescape($title);
798: $url = &LONCAPA::map::qtescape($url);
799: unless ($title) { $title=(split(/\//,$url))[-1] };
800: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
801: my $resurl = $url;
802: my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
803: my $filename;
804: if ($resurl =~ m#/([^/]+)$#) {
805: $filename = $1;
806: }
807: my $cstrurl = $resurl;
808: $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
809: my $bgcol = $idx%2;
810: $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
811: '<img src="'.&Apache::loncommon::icon($resfilepath).
812: '" /></td><td>'.&HTML::Entities::encode(&LONCAPA::map::qtescape($title)).
813: '</td><td>'.$filename.'</td><td>');
814: if ($url) {
815: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
816: }
817: $r->print('</td><td>');
818: if ($url) {
819: $r->print('<a href="'.$cstrurl.'">'.
820: &mt('Construction space').'</a>');
821: }
822: $r->print('</td></tr>'."\n");
823: }
824: }
825: $r->print('</table>');
826: $r->print(&Apache::loncommon::end_page());
827: }
828:
829: # ================================================================ Main Handler
830:
831: sub handler {
832: my $r=shift;
833: &Apache::loncommon::content_type($r,'text/html');
834: $r->send_http_header;
835:
836: return OK if $r->header_only;
837: my $target = $env{'form.grade_target'};
838: if ($target eq 'meta') {
839: &Apache::loncommon::content_type($r,'text/html');
840: $r->send_http_header;
841: return OK;
842: }
843:
844: my $url=$r->uri;
845: my $fn=&Apache::lonnet::filelocation('',$url);
846:
847: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
848: unless (-e $dir) {
849: &nodir($r,$dir);
850: return OK;
851: }
852:
853: # ------------------------------------------- Determine which tools can be used
854: my $adv=0;
855:
856: unless ($env{'form.forcesmp'}) {
857: if ($env{'form.forceadv'}) {
858: $adv=1;
859: } elsif (my $fh=Apache::File->new($fn)) {
860: my $allmap=join('',<$fh>);
861: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
862: }
863: }
864:
865: my $errtext='';
866: my $fatal=0;
867:
868: # -------------------------------------------------------------------- Load map
869: ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
870:
871: if ($fatal==1) { $adv=1; }
872:
873: # ----------------------------------- adv==1 now means "graphical MUST be used"
874:
875: if ($env{'form.forceadv'}) {
876: &ratedt($r,$url);
877: } elsif ($env{'form.forcesmp'}) {
878: &smpedt($r,$url,$errtext);
879: } else {
880: &viewmap($r,$url,$adv,$errtext);
881: }
882: return OK;
883: }
884:
885: 1;
886: __END__
887:
888:
889:
890:
891:
892:
893:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>