Annotation of rat/lonratedt.pm, revision 1.109

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

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