1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.84 2006/11/02 21:03:28 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::lonratsrv;
171: use Apache::lonsequence;
172: use Apache::loncommon;
173: use Apache::lonlocal;
174: use LONCAPA::map();
175: use File::Copy;
176: use lib '/home/httpd/lib/perl/';
177: use LONCAPA;
178:
179:
180:
181: # --------------------------------------------------------- Build up RAT screen
182: sub ratedt {
183: my ($r,$url)=@_;
184: my %layout = ('border' => "0");
185: if ($env{'environment.remote'} eq 'off') {
186: $layout{'rows'} = "1,250,*";
187: } else {
188: $layout{'rows'} = "1,70,*";
189: }
190: my $js ='
191: <script type="text/javascript">
192: var flag=0;
193: </script>';
194:
195: my $start_page =
196: &Apache::loncommon::start_page('Edit Sequence',$js,
197: {'frameset' => 1,
198: 'add_entries' => \%layout});
199: my $end_page =
200: &Apache::loncommon::end_page({'frameset' => 1});
201:
202: $r->print(<<ENDDOCUMENT);
203: $start_page
204: <frame name="server" src="$url/loadonly/ratserver" noresize="noresize"
205: noscroll="noscroll" />
206: <frame name="code" src="$url/loadonly/adveditmenu" />
207: <frame name="mapout" src="/adm/rat/map.html" />
208: $end_page
209: ENDDOCUMENT
210: }
211:
212: # ---------------------------------------------------------------- Make buttons
213:
214: sub buttons {
215: my $adv=shift;
216: my $output='<form method=post>';
217: if ($adv==1) {
218: $output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
219: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
220: } else {
221: unless ($adv==2) {
222: $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
223: &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
224: }
225: $output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
226: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
227: }
228: return $output.'</form><hr>';
229: }
230:
231: # ----------------------------------------------------------------- Edit script
232: sub editscript {
233: my $mode=shift;
234: my $resurl=
235: &Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
236: return(<<ENDSCRIPT);
237: var srch;
238: var srchflag=-1; // 1 means currently open
239: // 0 means closed (but has been open)
240: // -1 means never yet opened/defined
241: var srchmode='';
242:
243: var idx;
244: var idxflag=-1; // 1 means currently open
245: // 0 means closed (but has been open)
246: // -1 means never yet opened/defined
247: var idxmode='';
248:
249: // ------------------------------------------------------ Clears indexer window
250: function idxclear() {
251: idx.document.clear();
252: }
253:
254: // ------------------------------------------------------- Clears search window
255: function srchclear() {
256: srch.document.clear();
257: }
258:
259: // ------------------------------------------------------ Closes indexer window
260: function idxclose() {
261: if (idx && !idx.closed) {
262: idxflag=0;
263: idx.close();
264: }
265: }
266:
267: // ------------------------------------------------------- Closes search window
268: function srchclose() {
269: if (srch && !srch.closed) {
270: srchflag=0;
271: srch.close();
272: }
273: }
274:
275: // -------------------------------------------------------- Open indexer window
276: function idxopen(mode) {
277: var options="scrollbars=1,resizable=1,menubar=0,location=1,toolbar=1";
278: idxmode=mode;
279: idxflag=1;
280: idx=open('$resurl/?launch=1&mode=$mode&catalogmode='+mode,'idxout',options);
281: idx.focus();
282: }
283:
284: // ------------------------------------------------------ Open groupsort window
285: function groupopen(url,recover,bookmarks) {
286: var options="scrollbars=1,resizable=1,menubar=0";
287: idxflag=1;
288: idx=open("/adm/groupsort?mode=$mode&recover="+recover+"&readfile="+url+"&bookmarks="+bookmarks,"idxout",options);
289: idx.focus();
290: }
291:
292: // --------------------------------------------------------- Open search window
293: function srchopen(mode) {
294: var options="scrollbars=1,resizable=1,menubar=0";
295: srchmode=mode;
296: srchflag=1;
297: srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
298: srch.focus();
299: }
300: // ----------------------------------------------------- launch indexer browser
301: function groupsearch() {
302: srchcheck('import');
303: }
304:
305: function groupimport() {
306: idxcheck('import');
307: }
308:
309: // ------------------------------------------------------- Do srch status check
310: function srchcheck(mode) {
311: if (!srch || srch.closed || srchmode!=mode) {
312: srchopen(mode);
313: }
314: srch.focus();
315: }
316:
317: // -------------------------------------------------------- Do idx status check
318: function idxcheck(mode) {
319: if (!idx || idx.closed || idxmode!=mode) {
320: idxopen(mode);
321: }
322: idx.focus();
323: }
324:
325:
326: var editbrowser;
327: function openbrowser(formname,elementname,only,omit) {
328: var url = '$resurl/?';
329: if (editbrowser == null) {
330: url += 'launch=1&';
331: }
332: url += 'catalogmode=interactive&';
333: url += 'mode=edit&';
334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
337: }
338: if (omit != null) {
339: url += 'omit=' + omit + '&';
340: }
341: url += 'element=' + elementname + '';
342: var title = 'Browser';
343: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
344: options += ',width=700,height=600';
345: editbrowser = open(url,title,options,'1');
346: editbrowser.focus();
347: }
348: ENDSCRIPT
349: }
350: # ------------------------------------------------------- Simple edit processor
351:
352: sub smpedt {
353: my ($r,$url,$errtext)=@_;
354: my $buttons=&buttons(2);
355: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
356: my $targetmsg='';
357: if ($env{'form.save'}) {
358: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
359: unlink($tmpfn);
360: my ($errtext,$fatal)=
361: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
362: unless ($fatal) {
363: $targetmsg='<b>'.&mt('Saved.').'</b><br />';
364: } else {
365: $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
366: }
367: }
368: if ($env{'form.revert'}) {
369: $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
370: unlink($tmpfn);
371: my ($errtext,$fatal)=
372: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
373: }
374: if (-e $tmpfn) {
375: $targetmsg=
376: '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
377: my ($errtext,$fatal)=&LONCAPA::map::mapread($tmpfn,'');
378: }
379: # ---------------------------------------------------------- Process form input
380:
381: my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
382: my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
383: # ============================================================ Process commands
384:
385: my $targetdetail=$env{'form.targetdetail'};
386: my $importdetail=$env{'form.curimpdetail'};
387:
388: # ---------------------------------------------------- Importing from groupsort
389: if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
390:
391: $importdetail='';
392: my @curimport=split(/\&/,$env{'form.curimpdetail'});
393:
394: my $lastsel;
395:
396: if (defined($importselect[-1])) {
397: $lastsel=$importselect[-1];
398: } else {
399: $lastsel=$#curimport;
400: }
401:
402: for (my $i=0;$i<=$lastsel;$i++) {
403: my ($name,$url)=split(/\=/,$curimport[$i]);
404: if ($url) {
405: $importdetail.='&'.$name.'='.$url;
406: }
407: }
408:
409: $importdetail.='&'.$env{'form.importdetail'};
410:
411: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
412: my ($name,$url)=split(/\=/,$curimport[$i]);
413: if ($url) {
414: $importdetail.='&'.$name.'='.$url;
415: }
416: }
417: $importdetail=~s/\&+/\&/g;
418: $importdetail=~s/^\&//;
419:
420: # ------------------------------------------------------------------- Clear all
421: } elsif ($env{'form.clear'}) {
422: $importdetail='';
423: # ------------------------------------------------------------ Discard selected
424: } elsif ($env{'form.discard'}) {
425: $importdetail='';
426: my @curimport=split(/\&/,$env{'form.curimpdetail'});
427: foreach (@importselect) {
428: $curimport[$_]='';
429: }
430: for (my $i=0;$i<=$#curimport;$i++) {
431: my ($name,$url)=split(/\=/,$curimport[$i]);
432: if ($url) {
433: $importdetail.='&'.$name.'='.$url;
434: }
435: }
436: # --------------------------------------------------------- Loading another map
437: } elsif ($env{'form.loadmap'}) {
438: $importdetail='';
439: my @curimport=split(/\&/,$env{'form.curimpdetail'});
440:
441: my $lastsel;
442:
443: if (defined($importselect[-1])) {
444: $lastsel=$importselect[-1];
445: } else {
446: $lastsel=$#curimport;
447: }
448:
449: for (my $i=0;$i<=$lastsel;$i++) {
450: my ($name,$url)=split(/\=/,$curimport[$i]);
451: if ($url) {
452: $importdetail.='&'.$name.'='.$url;
453: }
454: }
455:
456: foreach (
457: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
458: my ($name,$url)=split(/\:/,$_);
459: if ($url) {
460: $importdetail.='&'.&escape($name).'='.
461: &escape($url);
462: }
463: }
464:
465: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
466: my ($name,$url)=split(/\=/,$curimport[$i]);
467: if ($url) {
468: $importdetail.='&'.$name.'='.$url;
469: }
470: }
471: $importdetail=~s/\&+/\&/g;
472: $importdetail=~s/^\&//;
473:
474: # ------------------------------------------------ Groupimport/search to target
475: } elsif ($env{'form.importdetail'}) {
476: my $lastsel;
477: if (defined($targetselect[-1])) {
478: $lastsel=$targetselect[-1];
479: } else {
480: $lastsel=$#LONCAPA::map::order+1;
481: }
482: &LONCAPA::map::pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
483: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
484: # ------------------------------------------------------------------------- Cut
485: } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
486: $importdetail='';
487: my @curimport=split(/\&/,$env{'form.curimpdetail'});
488:
489: my $lastsel;
490:
491: if (defined($importselect[-1])) {
492: $lastsel=$importselect[-1];
493: } else {
494: $lastsel=$#curimport;
495: }
496:
497: for (my $i=0;$i<=$lastsel;$i++) {
498: my ($name,$url)=split(/\=/,$curimport[$i]);
499: if ($url) {
500: $importdetail.='&'.$name.'='.$url;
501: }
502: }
503:
504: foreach (@targetselect) {
505: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$LONCAPA::map::order[$_-1]]);
506: if ($url) {
507: $importdetail.='&'.&escape($name).'='.
508: &escape($url);
509: }
510: }
511:
512: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
513: my ($name,$url)=split(/\=/,$curimport[$i]);
514: if ($url) {
515: $importdetail.='&'.$name.'='.$url;
516: }
517: }
518: $importdetail=~s/\&+/\&/g;
519: $importdetail=~s/^\&//;
520:
521: if ($env{'form.cut'}) {
522: my @neworder=();
523: for (my $i=0;$i<=$#LONCAPA::map::order;$i++) {
524: my $include=1;
525: foreach (@targetselect) {
526: if ($_-1==$i) { $include=0; }
527: }
528: if ($include) {
529: $neworder[$#neworder+1]=$LONCAPA::map::order[$i];
530: } else {
531: &LONCAPA::map::makezombie($LONCAPA::map::order[$i]);
532: }
533: }
534: @LONCAPA::map::order=@neworder;
535: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
536: }
537:
538: # ----------------------------------------------------------------------- Paste
539: } elsif ($env{'form.paste'}) {
540: my $lastsel;
541: if (defined($targetselect[-1])) {
542: $lastsel=$targetselect[-1];
543: } else {
544: $lastsel=$#LONCAPA::map::order+1;
545: }
546: my @newsequence;
547: my @curimport=split(/\&/,$env{'form.curimpdetail'});
548: foreach (@importselect) {
549: $newsequence[$#newsequence+1]=$curimport[$_];
550: }
551: &LONCAPA::map::pastetarget($lastsel,@newsequence);
552: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
553: # -------------------------------------------------------------------- Move up
554: } elsif ($env{'form.moveup'}) {
555: foreach (sort @targetselect) {
556: if ($_-1>0) {
557: my $movethis=$LONCAPA::map::order[$_-1];
558: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_-2];
559: $LONCAPA::map::order[$_-2]=$movethis;
560: }
561: }
562: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
563: # ------------------------------------------------------------------ Move down
564: } elsif ($env{'form.movedown'}) {
565: foreach (reverse sort @targetselect) {
566: if ($_-1<$#LONCAPA::map::order) {
567: my $movethis=$LONCAPA::map::order[$_-1];
568: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_];
569: $LONCAPA::map::order[$_]=$movethis;
570: }
571: }
572: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
573: # --------------------------------------------------------------------- Rename
574: } elsif ($env{'form.renameres'}) {
575: my $residx=$LONCAPA::map::order[$env{'form.renameidx'}-1];
576: my ($name,@resrest)=split(/\:/,$LONCAPA::map::resources[$residx]);
577: $name=$env{'form.renametitle'};
578: $name=~s/\:/\&colon\;/g;
579: $LONCAPA::map::resources[$residx]=$name.':'.join(':',@resrest);
580: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
581: }
582: # ------------------------------------------------------------ Assemble windows
583:
584: my $idx=-1;
585: $importdetail='&'.$importdetail;
586: $importdetail=~s/^\&+/\&/;
587: my $importwindow=
588: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
589: join("\n",map {
590: $idx++;
591: if ($_) {
592: my ($name,$url)=split(/\=/,$_);
593: unless ($name) { $name=(split(/\//,$url))[-1]; }
594: unless ($name) { $name='EMPTY'; }
595: '<option value="'.$idx.'">'.&unescape($name).
596: '</option>';
597: }
598: } split(/\&/,$importdetail));
599:
600: $idx=0;
601: $targetdetail='';
602: my $targetwindow=
603: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
604: join("\n",map {
605: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
606: unless ($name) { $name=(split(/\//,$url))[-1]; }
607: unless ($name) { $name='EMPTY'; }
608: $targetdetail.='&'.&escape($name).'='.
609: &escape($url);
610: $idx++;
611: $name=~s/\:/\:/g;
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: parts=url.split(':');
649: url=parts.join(':');
650: if (url) { open(url,'cat'); }
651: }
652:
653: function viewtarget() {
654: openview((document.forms.simpleedit.targetdetail.value.split('&'))
655: [document.forms.simpleedit.target.selectedIndex]);
656: }
657:
658: function viewimport() {
659: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
660: [document.forms.simpleedit.importsel.selectedIndex]);
661: }
662:
663: function renametarget() {
664: var selidx=document.forms.simpleedit.target.selectedIndex;
665: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
666: [selidx];
667: var oldname=unescape((entry.split('='))[0]);
668: var nameparts=oldname.split(':');
669: oldname=unescape(nameparts.join(':'));
670: nameparts=oldname.split('"');
671: oldname=unescape(nameparts.join('"'));
672: nameparts=oldname.split(''');
673: oldname=unescape(nameparts.join("'"));
674: newtitle=prompt('$lt{'nt'}',oldname);
675: if (newtitle) {
676: document.forms.simpleedit.renameres.value=1;
677: document.forms.simpleedit.renameidx.value=selidx;
678: document.forms.simpleedit.renametitle.value=newtitle;
679: document.forms.simpleedit.submit();
680: }
681: }
682:
683: </script>
684: ENDJS
685:
686: my $start_page = &Apache::loncommon::start_page(undef,$js).
687: &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
688: 'Sequence_Simple_Editor_Creation',
689: 6,'RAT');
690: my $end_page = &Apache::loncommon::end_page();
691:
692: $r->print(<<ENDSMPHEAD);
693: $start_page
694: $buttons
695: <font color=red>$errtext</font>
696: <form name=simpleedit method=post>
697: <input type=hidden name=forcesmp value=1>
698: <input type=hidden name=renameres value=0>
699: <input type=hidden name=renametitle value=''>
700: <input type=hidden name=renameidx value=0>
701: <table>
702: <tr><th width="40%">$lt{'ta'}</th>
703: <th> </th>
704: <th width="40%">File: $url</th></tr>
705: <tr><td bgcolor="#FFFFCC">
706: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
707: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
708: $lt{'as'}
709: <hr>
710: <input type=text size=20 name=importmap>
711: <input type=button
712: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
713: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
714: <input type=submit name="discard" value="$lt{'ds'}">
715: <input type=submit name="clear" value="$lt{'ca'}">
716: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
717:
718: </td><td> </td><td bgcolor="#FFFFCC">
719:
720: <input type=button onClick=
721: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
722: <input type=button onClick=
723: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
724: <input type=button onClick=
725: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}">
726: <input type=button onClick=
727: "javascript:impfortarget.value=1;groupopen('$url',1,0);" value="$lt{'reco'}">
728: $lt{'as'}
729: <hr>
730: <input type=submit name="moveup" value="$lt{'mu'}">
731: <input type=submit name="movedown" value="$lt{'md'}">
732: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
733: <hr>$targetmsg
734: <input type=submit name="revert" value="$lt{'rv'}">
735: <input type=submit name="save" value="$lt{'sa'}">
736: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
737: </td></tr>
738:
739: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
740: $importwindow
741: </select>
742: </td>
743: <td bgcolor="#FFFFAA" align="center">
744: $lt{'cs'}<br>
745: <input type=submit name=cut value='<<<'><p>
746: <hr>
747: $lt{'ps'}<br>
748: <input type=submit name=copy value='<--'><p>
749: <hr>
750: $lt{'pas'}<br>
751: <input type=submit name=paste value='-->'>
752: </td>
753: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
754: $targetwindow
755: </select>
756: </table>
757: <input type=hidden name=importdetail value="">
758: <input type=hidden name=curimpdetail value="$importdetail">
759: <input type=hidden name=targetdetail value="$targetdetail">
760: <input type=hidden name=impfortarget value="0">
761: </form>
762: $end_page
763: ENDSMPHEAD
764: }
765:
766: # ----------------------------------------------------------------- No such dir
767: sub nodir {
768: my ($r,$dir)=@_;
769: $dir=~s{^/home/\w+/public_html}{};
770: $r->print(&Apache::loncommon::start_page(undef,undef,
771: {'only_body' => 1,
772: 'bgcolor' => '#FFFFFF',}).
773: "<h1>No such directory: $dir</h1>".
774: &Apache::loncommon::end_page());
775: }
776:
777: # ---------------------------------------------------------------- View Handler
778:
779: sub viewmap {
780: my ($r,$url,$adv,$errtext)=@_;
781: $r->print(
782: &Apache::loncommon::start_page('Edit Content of a Map').
783: &Apache::loncommon::help_open_menu('','',6,'RAT').
784: &buttons($adv));
785: if ($errtext) {
786: $r->print($errtext.'<hr />');
787: }
788: my $idx=0;
789: $r->print('<h1>'.$url.'</h1>');
790: if ($adv) {
791: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
792: }
793: $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
794: '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
795: '<th>'.&mt('Title in map').'</th>'.
796: '<th>'.&mt('Filename of resource').'</th>'.
797: '<th>'.&mt('Link to published resource').'</th>'.
798: '<th>'.&mt('Link to resource in Construction Space').'</th>'.
799: '</tr>');
800: my @backgroundColors = ("#FFFFFF", "#F6F6F6");
801: foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
802: if (defined($_)) {
803: $idx++;
804: my ($title,$url,$cond)=split(/\:/,$_);
805: if ($cond eq 'cond') { next; }
806: $title=~s/\&colon\;/\:/g;
807: $url=~s/\&colon\;/\:/g;
808: unless ($title) { $title=(split(/\//,$url))[-1] };
809: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
810: my $resurl = &Apache::lonratsrv::qtescape($url);
811: my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
812: my $filename;
813: if ($resurl =~ m#/([^/]+)$#) {
814: $filename = $1;
815: }
816: my $cstrurl = $resurl;
817: $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
818: my $bgcol = $idx%2;
819: $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
820: '<img src="'.&Apache::loncommon::icon($resfilepath).
821: '" /></td><td>'.&Apache::lonratsrv::qtescape($title).
822: '</td><td>'.$filename.'</td><td>');
823: if ($url) {
824: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
825: }
826: $r->print('</td><td>');
827: if ($url) {
828: $r->print('<a href="'.$cstrurl.'">'.
829: &mt('Construction space').'</a>');
830: }
831: $r->print('</td></tr>'."\n");
832: }
833: }
834: $r->print('</table>');
835: $r->print(&Apache::loncommon::end_page());
836: }
837:
838: # ================================================================ Main Handler
839:
840: sub handler {
841: my $r=shift;
842: &Apache::loncommon::content_type($r,'text/html');
843: $r->send_http_header;
844:
845: return OK if $r->header_only;
846: my $target = $env{'form.grade_target'};
847: if ($target eq 'meta') {
848: &Apache::loncommon::content_type($r,'text/html');
849: $r->send_http_header;
850: return OK;
851: }
852:
853: my $url=$r->uri;
854: my $fn=&Apache::lonnet::filelocation('',$url);
855:
856: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
857: unless (-e $dir) {
858: &nodir($r,$dir);
859: return OK;
860: }
861:
862: # ------------------------------------------- Determine which tools can be used
863: my $adv=0;
864:
865: unless ($env{'form.forcesmp'}) {
866: if ($env{'form.forceadv'}) {
867: $adv=1;
868: } elsif (my $fh=Apache::File->new($fn)) {
869: my $allmap=join('',<$fh>);
870: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
871: }
872: }
873:
874: my $errtext='';
875: my $fatal=0;
876:
877: # -------------------------------------------------------------------- Load map
878: ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
879:
880: if ($fatal==1) { $adv=1; }
881:
882: # ----------------------------------- adv==1 now means "graphical MUST be used"
883:
884: if ($env{'form.forceadv'}) {
885: &ratedt($r,$url);
886: } elsif ($env{'form.forcesmp'}) {
887: &smpedt($r,$url,$errtext);
888: } else {
889: &viewmap($r,$url,$adv,$errtext);
890: }
891: return OK;
892: }
893:
894: 1;
895: __END__
896:
897:
898:
899:
900:
901:
902:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>