Annotation of rat/lonratedt.pm, revision 1.91

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

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