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