Annotation of rat/lonratedt.pm, revision 1.87
1.1 www 1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
1.5 www 3: #
1.87 ! albertel 4: # $Id: lonratedt.pm,v 1.86 2006/12/20 22:42:48 albertel Exp $
1.5 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.55 www 28:
1.1 www 29:
30: package Apache::lonratedt;
1.46 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.71 www 36: Apache::lonratedt: simple resource assembly tool
1.46 bowersj2 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
1.1 www 166:
167: use strict;
168: use Apache::Constants qw(:common);
1.3 www 169: use Apache::lonnet;
1.85 albertel 170: use Apache::lonsequence();
171: use Apache::loncommon();
1.47 www 172: use Apache::lonlocal;
1.84 albertel 173: use LONCAPA::map();
1.34 www 174: use File::Copy;
1.78 www 175: use LONCAPA;
1.87 ! albertel 176: use HTML::Entities();
1.16 www 177:
1.3 www 178: # --------------------------------------------------------- Build up RAT screen
179: sub ratedt {
180: my ($r,$url)=@_;
1.75 albertel 181: my %layout = ('border' => "0");
182: if ($env{'environment.remote'} eq 'off') {
183: $layout{'rows'} = "1,250,*";
184: } else {
185: $layout{'rows'} = "1,70,*";
1.63 raeburn 186: }
1.75 albertel 187: my $js ='
188: <script type="text/javascript">
189: var flag=0;
190: </script>';
1.1 www 191:
1.75 albertel 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});
1.1 www 198:
1.75 albertel 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
1.1 www 206: ENDDOCUMENT
1.3 www 207: }
208:
1.8 www 209: # ---------------------------------------------------------------- Make buttons
210:
211: sub buttons {
212: my $adv=shift;
213: my $output='<form method=post>';
214: if ($adv==1) {
1.52 www 215: $output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
216: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
1.8 www 217: } else {
218: unless ($adv==2) {
1.52 www 219: $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
220: &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
1.8 www 221: }
1.52 www 222: $output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
223: &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
1.8 www 224: }
225: return $output.'</form><hr>';
226: }
227:
1.56 www 228: # ----------------------------------------------------------------- Edit script
1.32 www 229: sub editscript {
230: my $mode=shift;
1.83 albertel 231: my $resurl=
232: &Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
1.32 www 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) {
1.81 albertel 274: var options="scrollbars=1,resizable=1,menubar=0,location=1,toolbar=1";
1.32 www 275: idxmode=mode;
276: idxflag=1;
1.83 albertel 277: idx=open('$resurl/?launch=1&mode=$mode&catalogmode='+mode,'idxout',options);
1.32 www 278: idx.focus();
279: }
280:
1.73 www 281: // ------------------------------------------------------ Open groupsort window
1.80 www 282: function groupopen(url,recover,bookmarks) {
1.73 www 283: var options="scrollbars=1,resizable=1,menubar=0";
284: idxflag=1;
1.80 www 285: idx=open("/adm/groupsort?mode=$mode&recover="+recover+"&readfile="+url+"&bookmarks="+bookmarks,"idxout",options);
1.73 www 286: idx.focus();
287: }
288:
1.32 www 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() {
1.79 www 299: srchcheck('import');
1.32 www 300: }
301:
302: function groupimport() {
1.79 www 303: idxcheck('import');
1.32 www 304: }
1.73 www 305:
1.32 www 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) {
1.51 www 325: var url = '$resurl/?';
1.32 www 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';
1.82 albertel 340: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.32 www 341: options += ',width=700,height=600';
342: editbrowser = open(url,title,options,'1');
343: editbrowser.focus();
344: }
345: ENDSCRIPT
346: }
1.20 www 347: # ------------------------------------------------------- Simple edit processor
348:
1.3 www 349: sub smpedt {
1.22 www 350: my ($r,$url,$errtext)=@_;
1.8 www 351: my $buttons=&buttons(2);
1.34 www 352: my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
353: my $targetmsg='';
1.65 albertel 354: if ($env{'form.save'}) {
1.34 www 355: copy($tmpfn,&Apache::lonnet::filelocation('',$url));
356: unlink($tmpfn);
1.35 www 357: my ($errtext,$fatal)=
1.84 albertel 358: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
1.60 www 359: unless ($fatal) {
360: $targetmsg='<b>'.&mt('Saved.').'</b><br />';
361: } else {
362: $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
363: }
1.34 www 364: }
1.65 albertel 365: if ($env{'form.revert'}) {
1.60 www 366: $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
1.34 www 367: unlink($tmpfn);
1.35 www 368: my ($errtext,$fatal)=
1.84 albertel 369: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
1.34 www 370: }
371: if (-e $tmpfn) {
372: $targetmsg=
1.49 sakharuk 373: '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
1.84 albertel 374: my ($errtext,$fatal)=&LONCAPA::map::mapread($tmpfn,'');
1.34 www 375: }
1.12 www 376: # ---------------------------------------------------------- Process form input
377:
1.66 albertel 378: my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
379: my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
1.13 www 380: # ============================================================ Process commands
1.12 www 381:
1.65 albertel 382: my $targetdetail=$env{'form.targetdetail'};
383: my $importdetail=$env{'form.curimpdetail'};
1.13 www 384:
385: # ---------------------------------------------------- Importing from groupsort
1.65 albertel 386: if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
1.13 www 387:
1.14 www 388: $importdetail='';
1.65 albertel 389: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.13 www 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) {
1.18 www 402: $importdetail.='&'.$name.'='.$url;
1.13 www 403: }
404: }
405:
1.65 albertel 406: $importdetail.='&'.$env{'form.importdetail'};
1.13 www 407:
408: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
409: my ($name,$url)=split(/\=/,$curimport[$i]);
410: if ($url) {
1.18 www 411: $importdetail.='&'.$name.'='.$url;
1.13 www 412: }
413: }
414: $importdetail=~s/\&+/\&/g;
415: $importdetail=~s/^\&//;
416:
1.14 www 417: # ------------------------------------------------------------------- Clear all
1.65 albertel 418: } elsif ($env{'form.clear'}) {
1.14 www 419: $importdetail='';
420: # ------------------------------------------------------------ Discard selected
1.65 albertel 421: } elsif ($env{'form.discard'}) {
1.14 www 422: $importdetail='';
1.65 albertel 423: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.14 www 424: foreach (@importselect) {
425: $curimport[$_]='';
426: }
427: for (my $i=0;$i<=$#curimport;$i++) {
428: my ($name,$url)=split(/\=/,$curimport[$i]);
429: if ($url) {
1.18 www 430: $importdetail.='&'.$name.'='.$url;
1.14 www 431: }
432: }
1.17 www 433: # --------------------------------------------------------- Loading another map
1.65 albertel 434: } elsif ($env{'form.loadmap'}) {
1.17 www 435: $importdetail='';
1.65 albertel 436: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.17 www 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) {
1.18 www 449: $importdetail.='&'.$name.'='.$url;
1.17 www 450: }
451: }
452:
453: foreach (
1.65 albertel 454: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.17 www 455: my ($name,$url)=split(/\:/,$_);
456: if ($url) {
1.78 www 457: $importdetail.='&'.&escape($name).'='.
458: &escape($url);
1.17 www 459: }
460: }
461:
462: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
463: my ($name,$url)=split(/\=/,$curimport[$i]);
464: if ($url) {
1.18 www 465: $importdetail.='&'.$name.'='.$url;
1.17 www 466: }
467: }
468: $importdetail=~s/\&+/\&/g;
469: $importdetail=~s/^\&//;
470:
1.20 www 471: # ------------------------------------------------ Groupimport/search to target
1.65 albertel 472: } elsif ($env{'form.importdetail'}) {
1.20 www 473: my $lastsel;
474: if (defined($targetselect[-1])) {
475: $lastsel=$targetselect[-1];
476: } else {
1.84 albertel 477: $lastsel=$#LONCAPA::map::order+1;
1.20 www 478: }
1.84 albertel 479: &LONCAPA::map::pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
480: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.20 www 481: # ------------------------------------------------------------------------- Cut
1.65 albertel 482: } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
1.25 www 483: $importdetail='';
1.65 albertel 484: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.25 www 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) {
1.84 albertel 502: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$LONCAPA::map::order[$_-1]]);
1.25 www 503: if ($url) {
1.78 www 504: $importdetail.='&'.&escape($name).'='.
505: &escape($url);
1.25 www 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:
1.65 albertel 518: if ($env{'form.cut'}) {
1.25 www 519: my @neworder=();
1.84 albertel 520: for (my $i=0;$i<=$#LONCAPA::map::order;$i++) {
1.25 www 521: my $include=1;
522: foreach (@targetselect) {
523: if ($_-1==$i) { $include=0; }
524: }
1.71 www 525: if ($include) {
1.84 albertel 526: $neworder[$#neworder+1]=$LONCAPA::map::order[$i];
1.71 www 527: } else {
1.84 albertel 528: &LONCAPA::map::makezombie($LONCAPA::map::order[$i]);
1.71 www 529: }
1.25 www 530: }
1.84 albertel 531: @LONCAPA::map::order=@neworder;
532: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.25 www 533: }
534:
1.20 www 535: # ----------------------------------------------------------------------- Paste
1.65 albertel 536: } elsif ($env{'form.paste'}) {
1.24 www 537: my $lastsel;
538: if (defined($targetselect[-1])) {
539: $lastsel=$targetselect[-1];
540: } else {
1.84 albertel 541: $lastsel=$#LONCAPA::map::order+1;
1.24 www 542: }
543: my @newsequence;
1.65 albertel 544: my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.24 www 545: foreach (@importselect) {
546: $newsequence[$#newsequence+1]=$curimport[$_];
547: }
1.84 albertel 548: &LONCAPA::map::pastetarget($lastsel,@newsequence);
549: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39 www 550: # -------------------------------------------------------------------- Move up
1.65 albertel 551: } elsif ($env{'form.moveup'}) {
1.39 www 552: foreach (sort @targetselect) {
553: if ($_-1>0) {
1.84 albertel 554: my $movethis=$LONCAPA::map::order[$_-1];
555: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_-2];
556: $LONCAPA::map::order[$_-2]=$movethis;
1.39 www 557: }
558: }
1.84 albertel 559: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39 www 560: # ------------------------------------------------------------------ Move down
1.65 albertel 561: } elsif ($env{'form.movedown'}) {
1.39 www 562: foreach (reverse sort @targetselect) {
1.84 albertel 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;
1.39 www 567: }
568: }
1.84 albertel 569: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39 www 570: # --------------------------------------------------------------------- Rename
1.65 albertel 571: } elsif ($env{'form.renameres'}) {
1.84 albertel 572: my $residx=$LONCAPA::map::order[$env{'form.renameidx'}-1];
573: my ($name,@resrest)=split(/\:/,$LONCAPA::map::resources[$residx]);
1.65 albertel 574: $name=$env{'form.renametitle'};
1.40 www 575: $name=~s/\:/\&colon\;/g;
1.84 albertel 576: $LONCAPA::map::resources[$residx]=$name.':'.join(':',@resrest);
577: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.13 www 578: }
1.12 www 579: # ------------------------------------------------------------ Assemble windows
1.20 www 580:
1.13 www 581: my $idx=-1;
1.34 www 582: $importdetail='&'.$importdetail;
583: $importdetail=~s/^\&+/\&/;
1.29 www 584: my $importwindow=
1.50 sakharuk 585: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
1.29 www 586: join("\n",map {
1.13 www 587: $idx++;
588: if ($_) {
1.15 www 589: my ($name,$url)=split(/\=/,$_);
590: unless ($name) { $name=(split(/\//,$url))[-1]; }
591: unless ($name) { $name='EMPTY'; }
1.78 www 592: '<option value="'.$idx.'">'.&unescape($name).
1.13 www 593: '</option>';
594: }
595: } split(/\&/,$importdetail));
1.12 www 596:
1.13 www 597: $idx=0;
1.39 www 598: $targetdetail='';
1.29 www 599: my $targetwindow=
1.49 sakharuk 600: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
1.29 www 601: join("\n",map {
1.84 albertel 602: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
1.15 www 603: unless ($name) { $name=(split(/\//,$url))[-1]; }
604: unless ($name) { $name='EMPTY'; }
1.87 ! albertel 605: $name = &LONCAPA::map::qtescape($name);
! 606: $url = &LONCAPA::map::qtescape($url);
1.78 www 607: $targetdetail.='&'.&escape($name).'='.
608: &escape($url);
1.13 www 609: $idx++;
1.87 ! albertel 610: $name = &HTML::Entities::encode($name,'\'"<>&');
1.20 www 611: '<option value="'.$idx.'">'.$name.'</option>';
1.84 albertel 612: } @LONCAPA::map::order);
1.11 www 613:
1.8 www 614: # ----------------------------------------------------- Start simple RAT screen
1.32 www 615: my $editscript=&editscript('simple');
1.75 albertel 616:
1.47 www 617: my %lt=&Apache::lonlocal::texthash(
618: 'sa' => 'Save',
619: 'nt' => 'New Title',
620: 'se' => 'Search',
621: 'im' => 'Import',
1.80 www 622: 'bk' => 'Import Bookmarks',
1.47 www 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',
1.49 sakharuk 633: 'as' => 'after selected',
634: 'cs' => 'Cut selected',
635: 'ps' => 'Copy selected',
636: 'pas' => 'Paste after selected',
1.74 www 637: 'reco' => 'Recover Deleted'
1.47 www 638: );
1.75 albertel 639: my $js=<<ENDJS;
1.77 albertel 640: <script type="text/javascript">
1.15 www 641:
1.32 www 642: $editscript
1.19 www 643:
644: function openview(entry) {
645: var url=unescape((entry.split('='))[1]);
1.20 www 646: var parts=new Array;
1.19 www 647: if (url) { open(url,'cat'); }
648: }
649:
650: function viewtarget() {
651: openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34 www 652: [document.forms.simpleedit.target.selectedIndex]);
1.19 www 653: }
654:
655: function viewimport() {
656: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34 www 657: [document.forms.simpleedit.importsel.selectedIndex]);
1.19 www 658: }
659:
1.39 www 660: function renametarget() {
661: var selidx=document.forms.simpleedit.target.selectedIndex;
662: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
663: [selidx];
1.41 www 664: var oldname=unescape((entry.split('='))[0]);
1.47 www 665: newtitle=prompt('$lt{'nt'}',oldname);
1.39 www 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:
1.6 www 674: </script>
1.75 albertel 675: ENDJS
676:
1.76 albertel 677: my $start_page = &Apache::loncommon::start_page(undef,$js).
1.81 albertel 678: &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
1.76 albertel 679: 'Sequence_Simple_Editor_Creation',
1.81 albertel 680: 6,'RAT');
1.75 albertel 681: my $end_page = &Apache::loncommon::end_page();
682:
683: $r->print(<<ENDSMPHEAD);
684: $start_page
1.8 www 685: $buttons
1.7 www 686: <font color=red>$errtext</font>
1.13 www 687: <form name=simpleedit method=post>
1.11 www 688: <input type=hidden name=forcesmp value=1>
1.39 www 689: <input type=hidden name=renameres value=0>
690: <input type=hidden name=renametitle value=''>
691: <input type=hidden name=renameidx value=0>
1.11 www 692: <table>
1.47 www 693: <tr><th width="40%">$lt{'ta'}</th>
1.12 www 694: <th> </th>
1.37 www 695: <th width="40%">File: $url</th></tr>
1.12 www 696: <tr><td bgcolor="#FFFFCC">
1.47 www 697: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
698: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
1.49 sakharuk 699: $lt{'as'}
1.14 www 700: <hr>
1.15 www 701: <input type=text size=20 name=importmap>
702: <input type=button
703: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
1.47 www 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'}">
1.16 www 708:
1.12 www 709: </td><td> </td><td bgcolor="#FFFFCC">
1.16 www 710:
711: <input type=button onClick=
1.47 www 712: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
1.16 www 713: <input type=button onClick=
1.47 www 714: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
1.74 www 715: <input type=button onClick=
1.80 www 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'}">
1.49 sakharuk 719: $lt{'as'}
1.39 www 720: <hr>
1.47 www 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'}">
1.34 www 724: <hr>$targetmsg
1.47 www 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'}">
1.12 www 728: </td></tr>
1.16 www 729:
1.27 www 730: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12 www 731: $importwindow
732: </select>
1.11 www 733: </td>
1.12 www 734: <td bgcolor="#FFFFAA" align="center">
1.49 sakharuk 735: $lt{'cs'}<br>
1.11 www 736: <input type=submit name=cut value='<<<'><p>
1.12 www 737: <hr>
1.49 sakharuk 738: $lt{'ps'}<br>
1.25 www 739: <input type=submit name=copy value='<--'><p>
740: <hr>
1.49 sakharuk 741: $lt{'pas'}<br>
1.25 www 742: <input type=submit name=paste value='-->'>
1.11 www 743: </td>
1.27 www 744: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11 www 745: $targetwindow
746: </select>
1.12 www 747: </table>
1.13 www 748: <input type=hidden name=importdetail value="">
749: <input type=hidden name=curimpdetail value="$importdetail">
1.12 www 750: <input type=hidden name=targetdetail value="$targetdetail">
1.16 www 751: <input type=hidden name=impfortarget value="0">
1.12 www 752: </form>
1.75 albertel 753: $end_page
1.3 www 754: ENDSMPHEAD
755: }
756:
1.11 www 757: # ----------------------------------------------------------------- No such dir
1.4 www 758: sub nodir {
759: my ($r,$dir)=@_;
1.86 albertel 760: $dir=~s{^/home/$LONCAPA::username_re/public_html}{};
1.75 albertel 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());
1.4 www 766: }
767:
1.8 www 768: # ---------------------------------------------------------------- View Handler
769:
770: sub viewmap {
1.17 www 771: my ($r,$url,$adv,$errtext)=@_;
1.75 albertel 772: $r->print(
773: &Apache::loncommon::start_page('Edit Content of a Map').
1.81 albertel 774: &Apache::loncommon::help_open_menu('','',6,'RAT').
1.53 www 775: &buttons($adv));
1.10 www 776: if ($errtext) {
1.53 www 777: $r->print($errtext.'<hr />');
1.10 www 778: }
1.26 www 779: my $idx=0;
1.34 www 780: $r->print('<h1>'.$url.'</h1>');
1.44 www 781: if ($adv) {
1.47 www 782: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.44 www 783: }
1.64 raeburn 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");
1.84 albertel 792: foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9 www 793: if (defined($_)) {
1.26 www 794: $idx++;
1.62 albertel 795: my ($title,$url,$cond)=split(/\:/,$_);
796: if ($cond eq 'cond') { next; }
1.87 ! albertel 797: $title= &LONCAPA::map::qtescape($title);
! 798: $url = &LONCAPA::map::qtescape($url);
1.15 www 799: unless ($title) { $title=(split(/\//,$url))[-1] };
1.64 raeburn 800: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
1.87 ! albertel 801: my $resurl = $url;
1.64 raeburn 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).
1.87 ! albertel 812: '" /></td><td>'.&HTML::Entities::encode(&LONCAPA::map::qtescape($title)).
1.64 raeburn 813: '</td><td>'.$filename.'</td><td>');
814: if ($url) {
1.68 www 815: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
1.64 raeburn 816: }
817: $r->print('</td><td>');
1.9 www 818: if ($url) {
1.64 raeburn 819: $r->print('<a href="'.$cstrurl.'">'.
820: &mt('Construction space').'</a>');
1.9 www 821: }
1.64 raeburn 822: $r->print('</td></tr>'."\n");
1.9 www 823: }
824: }
1.64 raeburn 825: $r->print('</table>');
1.75 albertel 826: $r->print(&Apache::loncommon::end_page());
1.8 www 827: }
828:
1.3 www 829: # ================================================================ Main Handler
830:
831: sub handler {
832: my $r=shift;
1.47 www 833: &Apache::loncommon::content_type($r,'text/html');
1.3 www 834: $r->send_http_header;
835:
836: return OK if $r->header_only;
1.65 albertel 837: my $target = $env{'form.grade_target'};
1.48 albertel 838: if ($target eq 'meta') {
839: &Apache::loncommon::content_type($r,'text/html');
840: $r->send_http_header;
841: return OK;
842: }
843:
1.3 www 844: my $url=$r->uri;
845: my $fn=&Apache::lonnet::filelocation('',$url);
846:
1.4 www 847: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
848: unless (-e $dir) {
849: &nodir($r,$dir);
850: return OK;
851: }
1.8 www 852:
853: # ------------------------------------------- Determine which tools can be used
1.3 www 854: my $adv=0;
855:
1.65 albertel 856: unless ($env{'form.forcesmp'}) {
857: if ($env{'form.forceadv'}) {
1.3 www 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:
1.8 www 865: my $errtext='';
866: my $fatal=0;
867:
868: # -------------------------------------------------------------------- Load map
1.84 albertel 869: ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
1.8 www 870:
871: if ($fatal==1) { $adv=1; }
872:
873: # ----------------------------------- adv==1 now means "graphical MUST be used"
874:
1.65 albertel 875: if ($env{'form.forceadv'}) {
1.3 www 876: &ratedt($r,$url);
1.65 albertel 877: } elsif ($env{'form.forcesmp'}) {
1.22 www 878: &smpedt($r,$url,$errtext);
1.3 www 879: } else {
1.17 www 880: &viewmap($r,$url,$adv,$errtext);
1.3 www 881: }
1.1 www 882: return OK;
883: }
884:
885: 1;
886: __END__
887:
888:
889:
890:
891:
892:
893:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>