File:
[LON-CAPA] /
rat /
lonratedt.pm
Revision
1.105.2.7:
download - view:
text,
annotated -
select for diffs
Wed Mar 11 21:09:04 2015 UTC (9 years, 6 months ago) by
raeburn
Branches:
version_2_11_X
CVS tags:
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1
- For 2.11
Backport 1.111
1: # The LearningOnline Network with CAPA
2: # Edit Handler for RAT Maps
3: #
4: # $Id: lonratedt.pm,v 1.105.2.7 2015/03/11 21:09:04 raeburn 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" action="">';
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) {
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,"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=&Apache::lonhtmlcommon::confirm_success(&mt('Saved'));
237: } else {
238: $targetmsg=&Apache::lonhtmlcommon::confirm_success(
239: &mt('An error occurred while saving.'),1);
240: }
241: }
242: if ($env{'form.revert'}) {
243: $targetmsg=&Apache::lonhtmlcommon::confirm_success(&mt('Reverted'));
244: unlink($tmpfn);
245: my ($errtext,$fatal)=
246: &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
247: }
248: $targetmsg = &Apache::loncommon::confirmwrapper($targetmsg) if ($targetmsg);
249: if (-e $tmpfn) {
250: $targetmsg=
251: '<p class="LC_warning">'
252: .&mt('You are working with an unsaved version of your map.')
253: .'</p>';
254: my ($errtext,$fatal)=&LONCAPA::map::mapread($tmpfn,'');
255: }
256: $errtext = '<p class="LC_error">'.$errtext.'</p>' if ($errtext);
257: # ---------------------------------------------------------- Process form input
258:
259: my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
260: my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
261: # ============================================================ Process commands
262:
263: my $targetdetail=$env{'form.targetdetail'};
264: my $importdetail=$env{'form.curimpdetail'};
265:
266: # ---------------------------------------------------- Importing from groupsort
267: if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
268:
269: $importdetail='';
270: my @curimport=split(/\&/,$env{'form.curimpdetail'});
271:
272: my $lastsel;
273:
274: if (defined($importselect[-1])) {
275: $lastsel=$importselect[-1];
276: } else {
277: $lastsel=$#curimport;
278: }
279:
280: for (my $i=0;$i<=$lastsel;$i++) {
281: my ($name,$url)=split(/\=/,$curimport[$i]);
282: if ($url) {
283: $importdetail.='&'.$name.'='.$url;
284: }
285: }
286:
287: $importdetail.='&'.$env{'form.importdetail'};
288:
289: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
290: my ($name,$url)=split(/\=/,$curimport[$i]);
291: if ($url) {
292: $importdetail.='&'.$name.'='.$url;
293: }
294: }
295: $importdetail=~s/\&+/\&/g;
296: $importdetail=~s/^\&//;
297:
298: # ------------------------------------------------------------------- Clear all
299: } elsif ($env{'form.clear'}) {
300: $importdetail='';
301: # ------------------------------------------------------------ Discard selected
302: } elsif ($env{'form.discard'}) {
303: $importdetail='';
304: my @curimport=split(/\&/,$env{'form.curimpdetail'});
305: foreach (@importselect) {
306: $curimport[$_]='';
307: }
308: for (my $i=0;$i<=$#curimport;$i++) {
309: my ($name,$url)=split(/\=/,$curimport[$i]);
310: if ($url) {
311: $importdetail.='&'.$name.'='.$url;
312: }
313: }
314: # --------------------------------------------------------- Loading another map
315: } elsif ($env{'form.loadmap'}) {
316: $importdetail='';
317: my @curimport=split(/\&/,$env{'form.curimpdetail'});
318:
319: my $lastsel;
320:
321: if (defined($importselect[-1])) {
322: $lastsel=$importselect[-1];
323: } else {
324: $lastsel=$#curimport;
325: }
326:
327: for (my $i=0;$i<=$lastsel;$i++) {
328: my ($name,$url)=split(/\=/,$curimport[$i]);
329: if ($url) {
330: $importdetail.='&'.$name.'='.$url;
331: }
332: }
333:
334: foreach (
335: &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
336: my ($name,$url)=split(/\:/,$_);
337: if ($url) {
338: $importdetail.='&'.&escape($name).'='.
339: &escape($url);
340: }
341: }
342:
343: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
344: my ($name,$url)=split(/\=/,$curimport[$i]);
345: if ($url) {
346: $importdetail.='&'.$name.'='.$url;
347: }
348: }
349: $importdetail=~s/\&+/\&/g;
350: $importdetail=~s/^\&//;
351:
352: # ------------------------------------------------ Groupimport/search to target
353: } elsif ($env{'form.importdetail'}) {
354: my $lastsel;
355: if (defined($targetselect[-1])) {
356: $lastsel=$targetselect[-1];
357: } else {
358: $lastsel=$#LONCAPA::map::order+1;
359: }
360: &LONCAPA::map::pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
361: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
362: # ------------------------------------------------------------------------- Cut
363: } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
364: $importdetail='';
365: my @curimport=split(/\&/,$env{'form.curimpdetail'});
366:
367: my $lastsel;
368:
369: if (defined($importselect[-1])) {
370: $lastsel=$importselect[-1];
371: } else {
372: $lastsel=$#curimport;
373: }
374:
375: for (my $i=0;$i<=$lastsel;$i++) {
376: my ($name,$url)=split(/\=/,$curimport[$i]);
377: if ($url) {
378: $importdetail.='&'.$name.'='.$url;
379: }
380: }
381:
382: foreach (@targetselect) {
383: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$LONCAPA::map::order[$_-1]]);
384: if ($url) {
385: $importdetail.='&'.&escape($name).'='.
386: &escape($url);
387: }
388: }
389:
390: for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
391: my ($name,$url)=split(/\=/,$curimport[$i]);
392: if ($url) {
393: $importdetail.='&'.$name.'='.$url;
394: }
395: }
396: $importdetail=~s/\&+/\&/g;
397: $importdetail=~s/^\&//;
398:
399: if ($env{'form.cut'}) {
400: my @neworder=();
401: for (my $i=0;$i<=$#LONCAPA::map::order;$i++) {
402: my $include=1;
403: foreach (@targetselect) {
404: if ($_-1==$i) { $include=0; }
405: }
406: if ($include) {
407: $neworder[$#neworder+1]=$LONCAPA::map::order[$i];
408: } else {
409: &LONCAPA::map::makezombie($LONCAPA::map::order[$i]);
410: }
411: }
412: @LONCAPA::map::order=@neworder;
413: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
414: }
415:
416: # ----------------------------------------------------------------------- Paste
417: } elsif ($env{'form.paste'}) {
418: my $lastsel;
419: if (defined($targetselect[-1])) {
420: $lastsel=$targetselect[-1];
421: } else {
422: $lastsel=$#LONCAPA::map::order+1;
423: }
424: my @newsequence;
425: my @curimport=split(/\&/,$env{'form.curimpdetail'});
426: foreach (@importselect) {
427: $newsequence[$#newsequence+1]=$curimport[$_];
428: }
429: &LONCAPA::map::pastetarget($lastsel,@newsequence);
430: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
431: # -------------------------------------------------------------------- Move up
432: } elsif ($env{'form.moveup'}) {
433: foreach (sort @targetselect) {
434: if ($_-1>0) {
435: my $movethis=$LONCAPA::map::order[$_-1];
436: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_-2];
437: $LONCAPA::map::order[$_-2]=$movethis;
438: }
439: }
440: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
441: # ------------------------------------------------------------------ Move down
442: } elsif ($env{'form.movedown'}) {
443: foreach (reverse sort @targetselect) {
444: if ($_-1<$#LONCAPA::map::order) {
445: my $movethis=$LONCAPA::map::order[$_-1];
446: $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_];
447: $LONCAPA::map::order[$_]=$movethis;
448: }
449: }
450: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
451: # --------------------------------------------------------------------- Rename
452: } elsif ($env{'form.renameres'}) {
453: my $residx=$LONCAPA::map::order[$env{'form.renameidx'}-1];
454: my ($name,@resrest)=split(/\:/,$LONCAPA::map::resources[$residx]);
455: $name=$env{'form.renametitle'};
456: $name=~s/\:/\&colon\;/g;
457: $LONCAPA::map::resources[$residx]=$name.':'.join(':',@resrest);
458: &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
459: }
460: # ------------------------------------------------------------ Assemble windows
461:
462: my $idx=-1;
463: $importdetail='&'.$importdetail;
464: $importdetail=~s/^\&+/\&/;
465: my $importwindow=
466: '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
467: join("\n",map {
468: $idx++;
469: if ($_) {
470: my ($name,$url)=split(/\=/,$_);
471: unless ($name) { $name=(split(/\//,$url))[-1]; }
472: unless ($name) { $name='EMPTY'; }
473: '<option value="'.$idx.'">'.&unescape($name).
474: '</option>';
475: }
476: } split(/\&/,$importdetail));
477:
478: $idx=0;
479: $targetdetail='';
480: my $targetwindow=
481: '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
482: join("\n",map {
483: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
484: unless ($name) { $name=(split(/\//,$url))[-1]; }
485: unless ($name) { $name='EMPTY'; }
486: $name = &LONCAPA::map::qtescape($name);
487: $url = &LONCAPA::map::qtescape($url);
488: $targetdetail.='&'.&escape($name).'='.
489: &escape($url);
490: $idx++;
491: $name = &HTML::Entities::encode($name,'\'"<>&');
492: '<option value="'.$idx.'">'.$name.'</option>';
493: } @LONCAPA::map::order);
494:
495: # ----------------------------------------------------- Start simple RAT screen
496: my $editscript=&editscript('simple');
497:
498: my %lt=&Apache::lonlocal::texthash(
499: 'sm' => 'Select Map',
500: 'sa' => 'Save',
501: 'nt' => 'New Title',
502: 'se' => 'Search',
503: 'im' => 'Import',
504: 'wl' => 'Import from Stored Links',
505: 'vi' => 'View',
506: 'lm' => 'Load Map',
507: 'ds' => 'Discard Selected',
508: 'ca' => 'Clear All',
509: 'ta' => 'Temporary Assembly Workspace',
510: 'rv' => 'Revert to Last Saved',
511: 'sa' => 'Save',
512: 'mu' => 'Move Up',
513: 'md' => 'Move Down',
514: 're' => 'Rename',
515: 'as' => 'after selected',
516: 'cs' => 'Cut selected',
517: 'ps' => 'Copy selected',
518: 'pas' => 'Paste after selected',
519: 'reco' => 'Recover Deleted'
520: );
521: my $js=&Apache::lonhtmlcommon::scripttag("
522: $editscript
523:
524: function openview(entry) {
525: var url=unescape((entry.split('='))[1]);
526: var parts=new Array;
527: if (url) { open(url,'cat'); }
528: }
529:
530: function viewtarget() {
531: openview((document.forms.simpleedit.targetdetail.value.split('&'))
532: [document.forms.simpleedit.target.selectedIndex]);
533: }
534:
535: function viewimport() {
536: openview((document.forms.simpleedit.curimpdetail.value.split('&'))
537: [document.forms.simpleedit.importsel.selectedIndex]);
538: }
539:
540: function renametarget() {
541: var selidx=document.forms.simpleedit.target.selectedIndex;
542: var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
543: [selidx];
544: var oldname=unescape((entry.split('='))[0]);
545: newtitle=prompt('$lt{'nt'}',oldname);
546: if (newtitle) {
547: document.forms.simpleedit.renameres.value=1;
548: document.forms.simpleedit.renameidx.value=selidx;
549: document.forms.simpleedit.renametitle.value=newtitle;
550: document.forms.simpleedit.submit();
551: }
552: }
553: ");
554:
555: &Apache::lonhtmlcommon::clear_breadcrumbs();
556: &Apache::lonhtmlcommon::add_breadcrumb({
557: text => 'Authoring Space',
558: href => &Apache::loncommon::authorspace($url),
559: faq => 6,
560: bug => 'RAT',
561: help => 'Sequence_Simple_Editor_Creation',});
562: &Apache::lonhtmlcommon::add_breadcrumb({
563: text => 'RAT',
564: title => 'Resource Assembly Tool',
565: href => '',});
566: &Apache::lonhtmlcommon::add_breadcrumb({
567: text => 'Editor',
568: title => 'Simple Editor',
569: href => '',});
570:
571: # Breadcrumbs are included by &start_page
572: my $start_page = &Apache::loncommon::start_page('Authoring Space',$js)
573: .&Apache::loncommon::head_subbox(
574: &Apache::loncommon::CSTR_pageheader()
575: .&buttons(2));
576: my $end_page = &Apache::loncommon::end_page();
577:
578: my $filetext = &mt('File: [_1]','<span class="LC_filename">'.$url.'</span>');
579: $r->print(<<ENDSMPHEAD);
580: $start_page
581: $targetmsg
582: $errtext
583: <form name="simpleedit" method="post" action="">
584: <input type="hidden" name="forcesmp" value="1" />
585: <input type="hidden" name="renameres" value="0" />
586: <input type="hidden" name="renametitle" value="" />
587: <input type="hidden" name="renameidx" value="0" />
588: <table>
589: <tr><th width="40%">$lt{'ta'}</th>
590: <th> </th>
591: <th width="40%">$filetext</th></tr>
592: <tr><td bgcolor="#FFFFCC">
593: <input type="button" onclick="javascript:groupsearch()" value="$lt{'se'}" />
594: <input type="button" onclick="javascript:groupimport();" value="$lt{'im'}" />
595: $lt{'as'}
596: <hr />
597: <input type="text" size="20" name="importmap" />
598: <input type="button"
599: onclick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
600: value="$lt{'sm'}" /><input type="submit" name="loadmap" value="$lt{'lm'}" /><hr />
601: <input type="submit" name="discard" value="$lt{'ds'}" />
602: <input type="submit" name="clear" value="$lt{'ca'}" />
603: <input type="button" onclick="javascript:viewimport()" value="$lt{'vi'}" />
604:
605: </td><td> </td><td bgcolor="#FFFFCC">
606:
607: <input type="button" onclick=
608: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}" />
609: <input type="button" onclick=
610: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}" />
611: <input type="button" onclick=
612: "javascript:impfortarget.value=1;open_StoredLinks_Import('simple');" value="$lt{'wl'}" />
613: <input type="button" onclick=
614: "javascript:impfortarget.value=1;groupopen('$url',1);" value="$lt{'reco'}" />
615: $lt{'as'}
616: <hr />
617: <input type="submit" name="moveup" value="$lt{'mu'}" />
618: <input type="submit" name="movedown" value="$lt{'md'}" />
619: <input type="button" onclick="javascript:renametarget()" value="$lt{'re'}" />
620: <hr />
621: <input type="submit" name="revert" value="$lt{'rv'}" />
622: <input type="submit" name="save" value="$lt{'sa'}" />
623: <input type="button" onclick="javascript:viewtarget()" value="$lt{'vi'}" />
624: </td></tr>
625:
626: <tr><td bgcolor="#FFFFCC"><select name="importsel" size="10" multiple="multiple">
627: $importwindow
628: </select>
629: </td>
630: <td bgcolor="#FFFFAA" align="center">
631: $lt{'cs'}<br />
632: <input type="submit" name="cut" value="<<<" /><p>
633: <hr />
634: $lt{'ps'}<br />
635: <input type="submit" name="copy" value="<--" /><p>
636: <h /r>
637: $lt{'pas'}<br />
638: <input type="submit" name="paste" value="-->" />
639: </td>
640: <td bgcolor="#FFFFCC"><select name="target" size="10" multiple="multiple">
641: $targetwindow
642: </select>
643: </td></tr>
644: </table>
645: <input type="hidden" name="importdetail" value="" />
646: <input type="hidden" name="curimpdetail" value="$importdetail" />
647: <input type="hidden" name="targetdetail" value="$targetdetail" />
648: <input type="hidden" name="impfortarget" value="0" />
649: </form>
650: $end_page
651: ENDSMPHEAD
652: }
653:
654: # ----------------------------------------------------------------- No such dir
655: sub nodir {
656: my ($r,$dir)=@_;
657: my $londocroot = $r->dir_config('lonDocRoot');
658: my ($path) = ($dir =~ m{^\Q$londocroot\E?(/priv/[^/]+/[^/]+/)});
659: $dir=~s{^\Q$londocroot/priv/\E[^/]+/[^/]+}{};
660: my $brcrum = [{'href' => &Apache::loncommon::authorspace($path),
661: 'text' => 'Authoring Space'}];
662: # {'href' => '',
663: # 'text' => 'No such directory'}];
664: $r->print(&Apache::loncommon::start_page('Authoring Space',
665: undef,
666: {'bread_crumbs' => $brcrum,})
667: .&Apache::loncommon::head_subbox(
668: &Apache::loncommon::CSTR_pageheader())
669: .'<p class="LC_error">'
670: .&mt('No such directory: [_1]','<span class="LC_filename">'.$dir.'</span>'
671: .'</p>'
672: .&Apache::loncommon::end_page())
673: );
674: }
675:
676: # ---------------------------------------------------------------- View Handler
677:
678: sub viewmap {
679: my ($r,$url,$adv,$errtext)=@_;
680:
681: &Apache::lonhtmlcommon::clear_breadcrumbs();
682: &Apache::lonhtmlcommon::add_breadcrumb({
683: text => 'Authoring Space',
684: href => &Apache::loncommon::authorspace($url),
685: faq => 6,
686: bug => 'RAT',
687: help => 'Sequence_Simple_Editor_Creation',});
688: &Apache::lonhtmlcommon::add_breadcrumb({
689: text => 'RAT',
690: title => 'Resource Assembly Tool',
691: href => '',});
692:
693: # Breadcrumbs are included by &start_page
694: $r->print(&Apache::loncommon::start_page('Edit Content of a Map')
695: .&Apache::loncommon::head_subbox(
696: &Apache::loncommon::CSTR_pageheader()
697: .&buttons($adv))
698: );
699: if ($errtext) {
700: $r->print('<div class="LC_error">'
701: .$errtext
702: .'</div>'
703: .'<hr />'
704: );
705: }
706: my $idx=0;
707: $r->print('<p><span class="LC_filename">'.$url.'</span></p>');
708: if ($adv) {
709: $r->print('<p class="LC_warning">'
710: .&mt('Map contents are not shown in order.')
711: .'</p><br />'
712: );
713: }
714: $r->print(&Apache::loncommon::start_data_table()
715: .&Apache::loncommon::start_data_table_header_row()
716: .'<th>'.&mt('Type').'</th>'
717: .'<th>'.&mt('Title in map').'</th>'
718: .'<th>'.&mt('Filename of resource').'</th>'
719: .'<th>'.&mt('Link to published resource').'</th>'
720: .'<th>'.&mt('Link to resource in Authoring Space').'</th>'
721: .&Apache::loncommon::end_data_table_header_row()
722: );
723: foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
724: if (defined($_)) {
725: $idx++;
726: my ($title,$url,$cond)=split(/\:/,$_);
727: if ($cond eq 'cond') { next; }
728: $title= &LONCAPA::map::qtescape($title);
729: $url = &LONCAPA::map::qtescape($url);
730: unless ($title) { $title=(split(/\//,$url))[-1] };
731: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
732: my $resurl = $url;
733: my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
734: my $filename;
735: if ($resurl =~ m#/([^/]+)$#) {
736: $filename = $1;
737: }
738: my $cstrurl = $resurl;
739: $cstrurl =~ s{^/res/}{/priv/};
740: $r->print(&Apache::loncommon::start_data_table_row()
741: .'<td>'
742: .'<img src="'.&Apache::loncommon::icon($resfilepath).'" alt="" />'
743: .'</td>'
744: .'<td>'
745: .&HTML::Entities::encode(&LONCAPA::map::qtescape($title))
746: .'</td>'
747: .'<td>'.$filename.'</td>'
748: .'<td>'
749: );
750: if ($url) {
751: $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
752: } else {
753: $r->print(' ');
754: }
755: $r->print('</td><td>');
756: if ($url) {
757: $r->print('<a href="'.$cstrurl.'">'.
758: &mt('Authoring Space').'</a>');
759: } else {
760: $r->print(' ');
761: }
762: $r->print('</td>'
763: .&Apache::loncommon::end_data_table_row()
764: );
765: }
766: }
767: $r->print(&Apache::loncommon::end_data_table());
768: $r->print(&Apache::loncommon::end_page());
769: }
770:
771: # ================================================================ Main Handler
772:
773: sub handler {
774: my $r=shift;
775: &Apache::loncommon::content_type($r,'text/html');
776: $r->send_http_header;
777:
778: return OK if $r->header_only;
779: my $target = $env{'form.grade_target'};
780: if ($target eq 'meta') {
781: &Apache::loncommon::content_type($r,'text/html');
782: $r->send_http_header;
783: return OK;
784: }
785:
786: my $url=$r->uri;
787: my $fn=&Apache::lonnet::filelocation('',$url);
788:
789: my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
790: unless (-e $dir) {
791: &nodir($r,$dir);
792: return OK;
793: }
794:
795: # ------------------------------------------- Determine which tools can be used
796: my $adv=0;
797:
798: unless ($env{'form.forcesmp'}) {
799: if ($env{'form.forceadv'}) {
800: $adv=1;
801: } elsif (my $fh=Apache::File->new($fn)) {
802: my $allmap=join('',<$fh>);
803: $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
804: }
805: }
806:
807: my $errtext='';
808: my $fatal=0;
809:
810: # -------------------------------------------------------------------- Load map
811: ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
812:
813: if ($fatal==1) { $adv=1; }
814:
815: # ----------------------------------- adv==1 now means "graphical MUST be used"
816:
817: if ($env{'form.forceadv'}) {
818: &ratedt($r,$url);
819: } elsif ($env{'form.forcesmp'}) {
820: &smpedt($r,$url,$errtext);
821: } else {
822: &viewmap($r,$url,$adv,$errtext);
823: }
824: return OK;
825: }
826:
827: 1;
828: __END__
829:
830:
831:
832: =pod
833:
834: =head1 NAME
835:
836: Apache::lonratedt: simple resource assembly tool
837:
838: =head1 SYNOPSIS
839:
840: lonratedt provides the routines and the handler for the Advanced
841: Resource Assembly Tool (RAT), and ties the various pieces together
842: with Javascript.
843:
844: =head1 OVERVIEW
845:
846: =head2 Map Representation
847:
848: =begin latex
849:
850: %
851: \begin{figure}
852: \begin{center}\includegraphics[%
853: width=0.55\paperwidth,bb = 0 0 200 100, draft, type=eps]{Map_Example}\end{center}
854:
855:
856: \caption{\label{Map_In_Advanced_Editor}Example of a Map in the Advanced Editor}
857: \end{figure}
858: %
859: \begin{figure}
860: \begin{lyxcode}
861: <map>
862:
863: ~~<resource~id=\char`\"{}1\char`\"{}
864:
865: ~~~~src=\char`\"{}/res/msu/korte/phy231welcome.html\char`\"{}
866:
867: ~~~~type=\char`\"{}start\char`\"{}
868:
869: ~~~~title=\char`\"{}Start\char`\"{}>
870:
871: ~~~~</resource>
872:
873: ~~<resource~id=\char`\"{}2\char`\"{}
874:
875: ~~~~src=\char`\"{}\char`\"{}~type=\char`\"{}finish\char`\"{}
876:
877: ~~~~title=\char`\"{}Finish\char`\"{}>
878:
879: ~~~~</resource>
880:
881: ~~<resource~id=\char`\"{}6\char`\"{}
882:
883: ~~~~src=\char`\"{}/res/msu/korte/tests/units.problem\char`\"{}
884:
885: ~~~~type=\char`\"{}mandatory\char`\"{}
886:
887: ~~~~title=\char`\"{}Physical~Units~Test\char`\"{}>
888:
889: ~~~~</resource>
890:
891: ~~<resource~id=\char`\"{}9\char`\"{}
892:
893: ~~~~src=\char`\"{}/res/msu/korte/chapters/onedim.sequence\char`\"{}
894:
895: ~~~~title=\char`\"{}Motion~in~One~Dimension\char`\"{}>
896:
897: ~~~~</resource>
898:
899: ~~<resource~id=\char`\"{}11\char`\"{}
900:
901: ~~~~src=\char`\"{}/res/msu/bauer/bridges/units.sequence\char`\"{}
902:
903: ~~~~title=\char`\"{}Physical~Units~Refresher\char`\"{}>
904:
905: ~~~~</resource>
906:
907: ~~<condition~id=\char`\"{}19\char`\"{}
908:
909: ~~~~type=\char`\"{}stop\char`\"{}
910:
911: ~~~~value=\char`\"{}user.assessments{[}this./res/msu/korte/tests/units.problem{]}.status=solved\char`\"{}>
912:
913: ~~~~</condition>
914:
915: ~~<link~from=\char`\"{}1\char`\"{}~to=\char`\"{}6\char`\"{}></link>
916:
917: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}9\char`\"{}~condition=\char`\"{}19\char`\"{}></link>
918:
919: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}11\char`\"{}></link>
920:
921: ~~<link~from=\char`\"{}11\char`\"{}~to=\char`\"{}6\char`\"{}></link>
922:
923: ~~</map>
924: \end{lyxcode}
925:
926: \caption{\label{XML}XML for Map in Figure \ref{Map_In_Advanced_Editor}}
927: \end{figure}
928:
929: =end latex
930:
931: Fig. "XML for Map in Figure" shows the XML representation of the
932: resource map shown in Fig. "Example of a Map in the Advanced Editor",
933: which is the format in which maps are stored. In the figure, however,
934: additional graphical map layout information generated by the Advanced
935: Resource Assembly Tool is not displayed. This graphical information is
936: optional to re-generate the same graphical layout when the map is
937: brought up again in the Resource Assembly Tool, and is not needed for
938: any other system functionality.
939:
940: Maps can be generated by tools other than the Resource Assembly
941: Tool. In particular, an author might have some other representation of
942: a course sequence, which can be converted into a map using scripts. If
943: this map then were to be brought up in the Resource Assembly Tool, the
944: Tool would automatically generate a graphical layout for it. Each
945: entry of the map (resources, conditions and links) is stored in a
946: separate tag.
947:
948: Resources and conditionsX<conditions> have to have unique ID
949: numbers. These numbers are automatically generated by the Resource
950: Assembly Tool when the entry is first created, or added to the entries
951: when a map generated outside the Resource Assembly Tool is first
952: retrieved. They can also be assigned by custom scripts or added in by
953: hand.
954:
955: In the XML example, entry 1 is the start resource of the map. When
956: this map is accessed, the source (src) URL of this tag will be the
957: first resource rendered. Entry 2 is the finish resource of this
958: map. This resource will be the last resource in the sequence of
959: resources. Entry 6 is a problem resource with the given URL and title,
960: as well as the priority "mandatory". Entry 19 is a condition, which is
961: used by the link between entries 6, the problem, and 9, a
962: sequence. I<The final syntax for conditions has not yet been
963: determined.>
964:
965: =cut
966:
967:
968:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>