Annotation of rat/lonratedt.pm, revision 1.105.2.7

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

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