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