1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.86 2006/12/20 22:42:48 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:
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: $targetdetail.='&'.&escape($name).'='.
606: &escape($url);
607: $idx++;
608: $name=~s/\:/\:/g;
609: '<option value="'.$idx.'">'.$name.'</option>';
610: } @LONCAPA::map::order);
611:
612: # ----------------------------------------------------- Start simple RAT screen
613: my $editscript=&editscript('simple');
614:
615: my %lt=&Apache::lonlocal::texthash(
616: 'sa' => 'Save',
617: 'nt' => 'New Title',
618: 'se' => 'Search',
619: 'im' => 'Import',
620: 'bk' => 'Import Bookmarks',
621: 'vi' => 'View',
622: 'lm' => 'Load Map',
623: 'ds' => 'Discard Selected',
624: 'ca' => 'Clear All',
625: 'ta' => 'Temporary Assembly Workspace',
626: 'rv' => 'Revert to Last Saved',
627: 'sa' => 'Save',
628: 'mu' => 'Move Up',
629: 'md' => 'Move Down',
630: 're' => 'Rename',
631: 'as' => 'after selected',
632: 'cs' => 'Cut selected',
633: 'ps' => 'Copy selected',
634: 'pas' => 'Paste after selected',
635: 'reco' => 'Recover Deleted'
636: );
637: my $js=<<ENDJS;
638: <script type="text/javascript">
639:
640: $editscript
641:
642: function openview(entry) {
643: var url=unescape((entry.split('='))[1]);
644: var parts=new Array;
645: parts=url.split(':');
646: url=parts.join(':');
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: var nameparts=oldname.split(':');
666: oldname=unescape(nameparts.join(':'));
667: nameparts=oldname.split('"');
668: oldname=unescape(nameparts.join('"'));
669: nameparts=oldname.split(''');
670: oldname=unescape(nameparts.join("'"));
671: newtitle=prompt('$lt{'nt'}',oldname);
672: if (newtitle) {
673: document.forms.simpleedit.renameres.value=1;
674: document.forms.simpleedit.renameidx.value=selidx;
675: document.forms.simpleedit.renametitle.value=newtitle;
676: document.forms.simpleedit.submit();
677: }
678: }
679:
680: </script>
681: ENDJS
682:
683: my $start_page = &Apache::loncommon::start_page(undef,$js).
684: &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
685: 'Sequence_Simple_Editor_Creation',
686: 6,'RAT');
687: my $end_page = &Apache::loncommon::end_page();
688:
689: $r->print(<<ENDSMPHEAD);
690: $start_page
691: $buttons
692: <font color=red>$errtext</font>
693: <form name=simpleedit method=post>
694: <input type=hidden name=forcesmp value=1>
695: <input type=hidden name=renameres value=0>
696: <input type=hidden name=renametitle value=''>
697: <input type=hidden name=renameidx value=0>
698: <table>
699: <tr><th width="40%">$lt{'ta'}</th>
700: <th> </th>
701: <th width="40%">File: $url</th></tr>
702: <tr><td bgcolor="#FFFFCC">
703: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
704: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
705: $lt{'as'}
706: <hr>
707: <input type=text size=20 name=importmap>
708: <input type=button
709: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
710: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
711: <input type=submit name="discard" value="$lt{'ds'}">
712: <input type=submit name="clear" value="$lt{'ca'}">
713: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
714:
715: </td><td> </td><td bgcolor="#FFFFCC">
716:
717: <input type=button onClick=
718: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
719: <input type=button onClick=
720: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
721: <input type=button onClick=
722: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}">
723: <input type=button onClick=
724: "javascript:impfortarget.value=1;groupopen('$url',1,0);" value="$lt{'reco'}">
725: $lt{'as'}
726: <hr>
727: <input type=submit name="moveup" value="$lt{'mu'}">
728: <input type=submit name="movedown" value="$lt{'md'}">
729: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
730: <hr>$targetmsg
731: <input type=submit name="revert" value="$lt{'rv'}">
732: <input type=submit name="save" value="$lt{'sa'}">
733: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
734: </td></tr>
735:
736: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
737: $importwindow
738: </select>
739: </td>
740: <td bgcolor="#FFFFAA" align="center">
741: $lt{'cs'}<br>
742: <input type=submit name=cut value='<<<'><p>
743: <hr>
744: $lt{'ps'}<br>
745: <input type=submit name=copy value='<--'><p>
746: <hr>
747: $lt{'pas'}<br>
748: <input type=submit name=paste value='-->'>
749: </td>
750: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
751: $targetwindow
752: </select>
753: </table>
754: <input type=hidden name=importdetail value="">
755: <input type=hidden name=curimpdetail value="$importdetail">
756: <input type=hidden name=targetdetail value="$targetdetail">
757: <input type=hidden name=impfortarget value="0">
758: </form>
759: $end_page
760: ENDSMPHEAD
761: }
762:
763: # ----------------------------------------------------------------- No such dir
764: sub nodir {
765: my ($r,$dir)=@_;
766: $dir=~s{^/home/$LONCAPA::username_re/public_html}{};
767: $r->print(&Apache::loncommon::start_page(undef,undef,
768: {'only_body' => 1,
769: 'bgcolor' => '#FFFFFF',}).
770: "<h1>No such directory: $dir</h1>".
771: &Apache::loncommon::end_page());
772: }
773:
774: # ---------------------------------------------------------------- View Handler
775:
776: sub viewmap {
777: my ($r,$url,$adv,$errtext)=@_;
778: $r->print(
779: &Apache::loncommon::start_page('Edit Content of a Map').
780: &Apache::loncommon::help_open_menu('','',6,'RAT').
781: &buttons($adv));
782: if ($errtext) {
783: $r->print($errtext.'<hr />');
784: }
785: my $idx=0;
786: $r->print('<h1>'.$url.'</h1>');
787: if ($adv) {
788: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
789: }
790: $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
791: '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
792: '<th>'.&mt('Title in map').'</th>'.
793: '<th>'.&mt('Filename of resource').'</th>'.
794: '<th>'.&mt('Link to published resource').'</th>'.
795: '<th>'.&mt('Link to resource in Construction Space').'</th>'.
796: '</tr>');
797: my @backgroundColors = ("#FFFFFF", "#F6F6F6");
798: foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
799: if (defined($_)) {
800: $idx++;
801: my ($title,$url,$cond)=split(/\:/,$_);
802: if ($cond eq 'cond') { next; }
803: $title=~s/\&colon\;/\:/g;
804: $url=~s/\&colon\;/\:/g;
805: unless ($title) { $title=(split(/\//,$url))[-1] };
806: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
807: my $resurl = &LONCAPA::map::qtescape($url);
808: my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
809: my $filename;
810: if ($resurl =~ m#/([^/]+)$#) {
811: $filename = $1;
812: }
813: my $cstrurl = $resurl;
814: $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
815: my $bgcol = $idx%2;
816: $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
817: '<img src="'.&Apache::loncommon::icon($resfilepath).
818: '" /></td><td>'.&LONCAPA::map::qtescape($title).
819: '</td><td>'.$filename.'</td><td>');
820: if ($url) {
821: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
822: }
823: $r->print('</td><td>');
824: if ($url) {
825: $r->print('<a href="'.$cstrurl.'">'.
826: &mt('Construction space').'</a>');
827: }
828: $r->print('</td></tr>'."\n");
829: }
830: }
831: $r->print('</table>');
832: $r->print(&Apache::loncommon::end_page());
833: }
834:
835: # ================================================================ Main Handler
836:
837: sub handler {
838: my $r=shift;
839: &Apache::loncommon::content_type($r,'text/html');
840: $r->send_http_header;
841:
842: return OK if $r->header_only;
843: my $target = $env{'form.grade_target'};
844: if ($target eq 'meta') {
845: &Apache::loncommon::content_type($r,'text/html');
846: $r->send_http_header;
847: return OK;
848: }
849:
850: my $url=$r->uri;
851: my $fn=&Apache::lonnet::filelocation('',$url);
852:
853: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
854: unless (-e $dir) {
855: &nodir($r,$dir);
856: return OK;
857: }
858:
859: # ------------------------------------------- Determine which tools can be used
860: my $adv=0;
861:
862: unless ($env{'form.forcesmp'}) {
863: if ($env{'form.forceadv'}) {
864: $adv=1;
865: } elsif (my $fh=Apache::File->new($fn)) {
866: my $allmap=join('',<$fh>);
867: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
868: }
869: }
870:
871: my $errtext='';
872: my $fatal=0;
873:
874: # -------------------------------------------------------------------- Load map
875: ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
876:
877: if ($fatal==1) { $adv=1; }
878:
879: # ----------------------------------- adv==1 now means "graphical MUST be used"
880:
881: if ($env{'form.forceadv'}) {
882: &ratedt($r,$url);
883: } elsif ($env{'form.forcesmp'}) {
884: &smpedt($r,$url,$errtext);
885: } else {
886: &viewmap($r,$url,$adv,$errtext);
887: }
888: return OK;
889: }
890:
891: 1;
892: __END__
893:
894:
895:
896:
897:
898:
899:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>