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