Annotation of rat/lonratedt.pm, revision 1.84

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

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