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