Annotation of rat/lonratedt.pm, revision 1.105.2.1

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Edit Handler for RAT Maps
1.5       www         3: #
1.105.2.1! raeburn     4: # $Id: lonratedt.pm,v 1.105 2012/04/18 17:37:12 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.105.2.1! raeburn    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:   }
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.105.2.1! raeburn   158: function groupopen(url,recover,bookmarks) {
1.73      www       159:    var options="scrollbars=1,resizable=1,menubar=0";
                    160:    idxflag=1;
1.105.2.1! raeburn   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.105.2.1! raeburn   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.104     raeburn   556:         href  => &Apache::loncommon::authorspace($url),
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>&nbsp;</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>&nbsp;</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=
1.105.2.1! raeburn   608: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}" />
1.100     wenzelju  609: <input type="button" onClick=
1.105.2.1! raeburn   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.103     raeburn   652:    my $londocroot = $r->dir_config('lonDocRoot');
1.104     raeburn   653:    my ($path) = ($dir =~ m{^\Q$londocroot\E?(/priv/[^/]+/[^/]+/)});
1.103     raeburn   654:    $dir=~s{^\Q$londocroot/priv/\E[^/]+/[^/]+}{};
1.104     raeburn   655:    my $brcrum = [{'href' => &Apache::loncommon::authorspace($path),
1.97      bisitz    656:                   'text' => 'Construction Space'}];
                    657: #                 {'href' => '',
                    658: #                  'text' => 'No such directory'}];
                    659:    $r->print(&Apache::loncommon::start_page('Construction Space',
                    660:                                             undef,
                    661:                                             {'bread_crumbs' => $brcrum,})
1.95      bisitz    662:             .&Apache::loncommon::head_subbox(
                    663:                  &Apache::loncommon::CSTR_pageheader())
                    664:             .'<p class="LC_error">'
                    665:             .&mt('No such directory: [_1]','<span class="LC_filename">'.$dir.'</span>'
                    666:             .'</p>'
                    667:             .&Apache::loncommon::end_page())
                    668:    );
1.4       www       669: }
                    670: 
1.8       www       671: # ---------------------------------------------------------------- View Handler
                    672: 
                    673: sub viewmap {
1.17      www       674:     my ($r,$url,$adv,$errtext)=@_;
1.96      bisitz    675: 
                    676:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    677:     &Apache::lonhtmlcommon::add_breadcrumb({
                    678:         text  => 'Construction Space',
1.104     raeburn   679:         href  => &Apache::loncommon::authorspace($url),
1.96      bisitz    680:         faq   => 6,
                    681:         bug   => 'RAT',
                    682:         help  => 'Sequence_Simple_Editor_Creation',});
                    683:     &Apache::lonhtmlcommon::add_breadcrumb({
                    684:         text  => 'RAT',
                    685:         title => 'Resource Assembly Tool',
                    686:         href  => '',});
                    687: 
1.98      bisitz    688:     # Breadcrumbs are included by &start_page
1.95      bisitz    689:     $r->print(&Apache::loncommon::start_page('Edit Content of a Map')
                    690:              .&Apache::loncommon::head_subbox(
                    691:                   &Apache::loncommon::CSTR_pageheader()
                    692:                  .&buttons($adv))
                    693:     );
1.10      www       694:     if ($errtext) {
1.90      bisitz    695: 	$r->print('<div class="LC_error">'
                    696:                  .$errtext
                    697:                  .'</div>'
                    698:                  .'<hr />'
                    699:         );
1.10      www       700:     }
1.26      www       701:     my $idx=0;
1.97      bisitz    702:     $r->print('<p><span class="LC_filename">'.$url.'</span></p>');
1.44      www       703:     if ($adv) {
1.90      bisitz    704: 	$r->print('<p class="LC_warning">'
                    705:                  .&mt('Map contents are not shown in order.')
                    706:                  .'</p><br />'
                    707:         );
1.44      www       708:     }
1.90      bisitz    709:     $r->print(&Apache::loncommon::start_data_table()
                    710:              .&Apache::loncommon::start_data_table_header_row()
                    711:              .'<th>'.&mt('Type').'</th>'
                    712:              .'<th>'.&mt('Title in map').'</th>'
                    713:              .'<th>'.&mt('Filename of resource').'</th>'
                    714:              .'<th>'.&mt('Link to published resource').'</th>'
                    715:              .'<th>'.&mt('Link to resource in Construction Space').'</th>'
                    716:              .&Apache::loncommon::end_data_table_header_row()
                    717:     );
1.84      albertel  718:     foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9       www       719: 	if (defined($_)) {
1.26      www       720:             $idx++;
1.62      albertel  721: 	    my ($title,$url,$cond)=split(/\:/,$_);
                    722: 	    if ($cond eq 'cond') { next; }
1.87      albertel  723:             $title= &LONCAPA::map::qtescape($title);
                    724:             $url  = &LONCAPA::map::qtescape($url);
1.15      www       725:             unless ($title) { $title=(split(/\//,$url))[-1] };
1.64      raeburn   726:             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
1.87      albertel  727:             my $resurl = $url;
1.64      raeburn   728:             my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
                    729:             my $filename; 
                    730:             if ($resurl =~ m#/([^/]+)$#) {
                    731:                 $filename = $1;
                    732:             }
                    733:             my $cstrurl = $resurl;
1.105     raeburn   734:             $cstrurl =~ s{^/res/}{/priv/};
1.90      bisitz    735:             $r->print(&Apache::loncommon::start_data_table_row()
                    736:                      .'<td>'
                    737:                      .'<img src="'.&Apache::loncommon::icon($resfilepath).'" />'
                    738:                      .'</td>'
                    739:                      .'<td>'
                    740:                      .&HTML::Entities::encode(&LONCAPA::map::qtescape($title))
                    741:                      .'</td>'
                    742:                      .'<td>'.$filename.'</td>'
                    743:                      .'<td>'
                    744:             );
1.64      raeburn   745:             if ($url) {
1.68      www       746: 		$r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
1.90      bisitz    747:             } else {
                    748:                 $r->print('&nbsp;');
1.64      raeburn   749:             }
                    750:             $r->print('</td><td>');
1.9       www       751:             if ($url) {
1.64      raeburn   752:                $r->print('<a href="'.$cstrurl.'">'.
                    753:                          &mt('Construction space').'</a>');
1.90      bisitz    754:             } else {
                    755:                 $r->print('&nbsp;');
1.9       www       756:             }
1.90      bisitz    757:             $r->print('</td>'
                    758:                      .&Apache::loncommon::end_data_table_row()
                    759:             );
1.9       www       760:         }
                    761:     }
1.90      bisitz    762:     $r->print(&Apache::loncommon::end_data_table());
1.75      albertel  763:     $r->print(&Apache::loncommon::end_page());
1.8       www       764: }
                    765: 
1.3       www       766: # ================================================================ Main Handler
                    767: 
                    768: sub handler {
                    769:   my $r=shift;
1.47      www       770:   &Apache::loncommon::content_type($r,'text/html');
1.3       www       771:   $r->send_http_header;
                    772: 
                    773:   return OK if $r->header_only;
1.65      albertel  774:   my $target = $env{'form.grade_target'};
1.48      albertel  775:   if ($target eq 'meta') {
                    776:       &Apache::loncommon::content_type($r,'text/html');
                    777:       $r->send_http_header;
                    778:       return OK;
                    779:   }
                    780:   
1.3       www       781:   my $url=$r->uri;
                    782:   my $fn=&Apache::lonnet::filelocation('',$url);
                    783: 
1.4       www       784:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
                    785:   unless (-e $dir) {
                    786:       &nodir($r,$dir);
                    787:       return OK;
                    788:   }
1.8       www       789: 
                    790: # ------------------------------------------- Determine which tools can be used
1.3       www       791:   my $adv=0;
                    792: 
1.65      albertel  793:   unless ($env{'form.forcesmp'}) {
                    794:      if ($env{'form.forceadv'}) {
1.3       www       795:         $adv=1;
                    796:      } elsif (my $fh=Apache::File->new($fn)) {
                    797: 	 my $allmap=join('',<$fh>);
                    798:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
                    799:      }
                    800:   }
                    801: 
1.8       www       802:   my $errtext='';
                    803:   my $fatal=0;
                    804: 
                    805: # -------------------------------------------------------------------- Load map
1.84      albertel  806:   ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
1.8       www       807: 
                    808:   if ($fatal==1) { $adv=1; }
                    809: 
                    810: # ----------------------------------- adv==1 now means "graphical MUST be used"
                    811: 
1.65      albertel  812:   if ($env{'form.forceadv'}) {
1.3       www       813:       &ratedt($r,$url);
1.65      albertel  814:   } elsif ($env{'form.forcesmp'}) {
1.22      www       815:       &smpedt($r,$url,$errtext);
1.3       www       816:   } else {
1.17      www       817:       &viewmap($r,$url,$adv,$errtext);
1.3       www       818:   }
1.1       www       819:   return OK;
                    820: }
                    821: 
                    822: 1;
                    823: __END__
                    824: 
                    825: 
                    826: 
1.91      jms       827: =pod
                    828: 
                    829: =head1 NAME
                    830: 
                    831: Apache::lonratedt: simple resource assembly tool
                    832: 
                    833: =head1 SYNOPSIS
                    834: 
                    835: lonratedt provides the routines and the handler for the Advanced
                    836:     Resource Assembly Tool (RAT), and ties the various pieces together
                    837:     with Javascript.
                    838: 
                    839: =head1 OVERVIEW
                    840: 
                    841: =head2 Map Representation
                    842: 
                    843: =begin latex
                    844: 
                    845: %
                    846: \begin{figure}
                    847: \begin{center}\includegraphics[%
                    848:   width=0.55\paperwidth,bb = 0 0 200 100, draft, type=eps]{Map_Example}\end{center}
                    849: 
                    850: 
                    851: \caption{\label{Map_In_Advanced_Editor}Example of a Map in the Advanced Editor}
                    852: \end{figure}
                    853: %
                    854: \begin{figure}
                    855: \begin{lyxcode}
                    856: <map>
                    857: 
                    858: ~~<resource~id=\char`\"{}1\char`\"{}
                    859: 
                    860: ~~~~src=\char`\"{}/res/msu/korte/phy231welcome.html\char`\"{}
                    861: 
                    862: ~~~~type=\char`\"{}start\char`\"{}
                    863: 
                    864: ~~~~title=\char`\"{}Start\char`\"{}>
                    865: 
                    866: ~~~~</resource>
                    867: 
                    868: ~~<resource~id=\char`\"{}2\char`\"{}
                    869: 
                    870: ~~~~src=\char`\"{}\char`\"{}~type=\char`\"{}finish\char`\"{}
                    871: 
                    872: ~~~~title=\char`\"{}Finish\char`\"{}>
                    873: 
                    874: ~~~~</resource>
                    875: 
                    876: ~~<resource~id=\char`\"{}6\char`\"{}
                    877: 
                    878: ~~~~src=\char`\"{}/res/msu/korte/tests/units.problem\char`\"{}
                    879: 
                    880: ~~~~type=\char`\"{}mandatory\char`\"{}
                    881: 
                    882: ~~~~title=\char`\"{}Physical~Units~Test\char`\"{}>
                    883: 
                    884: ~~~~</resource>
                    885: 
                    886: ~~<resource~id=\char`\"{}9\char`\"{}
                    887: 
                    888: ~~~~src=\char`\"{}/res/msu/korte/chapters/onedim.sequence\char`\"{}
                    889: 
                    890: ~~~~title=\char`\"{}Motion~in~One~Dimension\char`\"{}>
                    891: 
                    892: ~~~~</resource>
                    893: 
                    894: ~~<resource~id=\char`\"{}11\char`\"{}
                    895: 
                    896: ~~~~src=\char`\"{}/res/msu/bauer/bridges/units.sequence\char`\"{}
                    897: 
                    898: ~~~~title=\char`\"{}Physical~Units~Refresher\char`\"{}>
                    899: 
                    900: ~~~~</resource>
                    901: 
                    902: ~~<condition~id=\char`\"{}19\char`\"{}
                    903: 
                    904: ~~~~type=\char`\"{}stop\char`\"{}
                    905: 
                    906: ~~~~value=\char`\"{}user.assessments{[}this./res/msu/korte/tests/units.problem{]}.status=solved\char`\"{}>
                    907: 
                    908: ~~~~</condition>
                    909: 
                    910: ~~<link~from=\char`\"{}1\char`\"{}~to=\char`\"{}6\char`\"{}></link>
                    911: 
                    912: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}9\char`\"{}~condition=\char`\"{}19\char`\"{}></link>
                    913: 
                    914: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}11\char`\"{}></link>
1.1       www       915: 
1.91      jms       916: ~~<link~from=\char`\"{}11\char`\"{}~to=\char`\"{}6\char`\"{}></link>
                    917: 
                    918: ~~</map>
                    919: \end{lyxcode}
                    920: 
                    921: \caption{\label{XML}XML for Map in Figure \ref{Map_In_Advanced_Editor}}
                    922: \end{figure}
                    923: 
                    924: =end latex
                    925: 
                    926: Fig. "XML for Map in Figure" shows the XML representation of the
                    927: resource map shown in Fig. "Example of a Map in the Advanced Editor",
                    928: which is the format in which maps are stored. In the figure, however,
                    929: additional graphical map layout information generated by the Advanced
                    930: Resource Assembly Tool is not displayed. This graphical information is
                    931: optional to re-generate the same graphical layout when the map is
                    932: brought up again in the Resource Assembly Tool, and is not needed for
                    933: any other system functionality.
                    934: 
                    935: Maps can be generated by tools other than the Resource Assembly
                    936: Tool. In particular, an author might have some other representation of
                    937: a course sequence, which can be converted into a map using scripts. If
                    938: this map then were to be brought up in the Resource Assembly Tool, the
                    939: Tool would automatically generate a graphical layout for it. Each
                    940: entry of the map (resources, conditions and links) is stored in a
                    941: separate tag.
                    942: 
                    943: Resources and conditionsX<conditions> have to have unique ID
                    944: numbers. These numbers are automatically generated by the Resource
                    945: Assembly Tool when the entry is first created, or added to the entries
                    946: when a map generated outside the Resource Assembly Tool is first
                    947: retrieved. They can also be assigned by custom scripts or added in by
                    948: hand.
                    949: 
                    950: In the XML example, entry 1 is the start resource of the map. When
                    951: this map is accessed, the source (src) URL of this tag will be the
                    952: first resource rendered. Entry 2 is the finish resource of this
                    953: map. This resource will be the last resource in the sequence of
                    954: resources. Entry 6 is a problem resource with the given URL and title,
                    955: as well as the priority "mandatory". Entry 19 is a condition, which is
                    956: used by the link between entries 6, the problem, and 9, a
                    957: sequence. I<The final syntax for conditions has not yet been
                    958: determined.>
                    959: 
                    960: =cut
1.1       www       961: 
                    962: 
                    963: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>