Annotation of rat/lonratedt.pm, revision 1.90

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Edit Handler for RAT Maps
1.5       www         3: #
1.90    ! bisitz      4: # $Id: lonratedt.pm,v 1.89 2008/09/11 14:47:24 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: 
                     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.85      albertel  170: use Apache::lonsequence();
                    171: use Apache::loncommon();
1.47      www       172: use Apache::lonlocal;
1.84      albertel  173: use LONCAPA::map();
1.34      www       174: use File::Copy;
1.78      www       175: use LONCAPA;
1.87      albertel  176: use HTML::Entities();
1.16      www       177: 
1.3       www       178: # --------------------------------------------------------- Build up RAT screen
                    179: sub ratedt {
                    180:   my ($r,$url)=@_;
1.75      albertel  181:   my %layout = ('border' => "0");
                    182:     if ($env{'environment.remote'} eq 'off') {
                    183:       $layout{'rows'} = "1,250,*";
                    184:   } else {
                    185:       $layout{'rows'} = "1,70,*";
1.63      raeburn   186:   }
1.75      albertel  187:   my $js ='
                    188: <script type="text/javascript">
                    189:     var flag=0;
                    190: </script>';
1.1       www       191: 
1.75      albertel  192:   my $start_page = 
                    193:       &Apache::loncommon::start_page('Edit Sequence',$js,
                    194: 				     {'frameset'    => 1,
                    195: 				      'add_entries' => \%layout});
                    196:   my $end_page = 
                    197:       &Apache::loncommon::end_page({'frameset' => 1});
1.1       www       198: 
1.75      albertel  199:   $r->print(<<ENDDOCUMENT);
                    200: $start_page
                    201: <frame name="server" src="$url/loadonly/ratserver" noresize="noresize"
                    202:        noscroll="noscroll" />
                    203: <frame name="code" src="$url/loadonly/adveditmenu" />
                    204: <frame name="mapout" src="/adm/rat/map.html" />
                    205: $end_page
1.1       www       206: ENDDOCUMENT
1.3       www       207: }
                    208: 
1.8       www       209: # ---------------------------------------------------------------- Make buttons
                    210: 
                    211: sub buttons {
                    212:     my $adv=shift;
                    213:     my $output='<form method=post>';     
                    214:     if ($adv==1) {
1.52      www       215: 	$output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
                    216: 	    &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
1.8       www       217:     } else {
                    218:         unless ($adv==2) {
1.52      www       219:            $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
                    220: 	    &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
1.8       www       221:         }
1.52      www       222: 	$output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
                    223: 	    &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
1.8       www       224:     }
                    225:     return $output.'</form><hr>';
                    226: }
                    227: 
1.56      www       228: # ----------------------------------------------------------------- Edit script
1.32      www       229: sub editscript {
                    230:     my $mode=shift;
1.83      albertel  231:     my $resurl=
                    232: 	&Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
1.32      www       233:     return(<<ENDSCRIPT);
                    234: var srch;
                    235: var srchflag=-1; // 1 means currently open
                    236:                  // 0 means closed (but has been open)
                    237:                  // -1 means never yet opened/defined
                    238: var srchmode='';
                    239: 
                    240: var idx;
                    241: var idxflag=-1; // 1 means currently open
                    242:                  // 0 means closed (but has been open)
                    243:                  // -1 means never yet opened/defined
                    244: var idxmode='';
                    245: 
                    246: // ------------------------------------------------------ Clears indexer window
                    247: function idxclear() {
                    248:   idx.document.clear();
                    249: }
                    250: 
                    251: // ------------------------------------------------------- Clears search window
                    252: function srchclear() {
                    253:   srch.document.clear();
                    254: }
                    255: 
                    256: // ------------------------------------------------------ Closes indexer window
                    257: function idxclose() {
                    258:   if (idx && !idx.closed) {
                    259:     idxflag=0;
                    260:     idx.close();
                    261:   }
                    262: }
                    263: 
                    264: // ------------------------------------------------------- Closes search window
                    265: function srchclose() {
                    266:   if (srch && !srch.closed) {
                    267:     srchflag=0;
                    268:     srch.close();
                    269:   }
                    270: }
                    271: 
                    272: // -------------------------------------------------------- Open indexer window
                    273: function idxopen(mode) {
1.81      albertel  274:    var options="scrollbars=1,resizable=1,menubar=0,location=1,toolbar=1";
1.32      www       275:    idxmode=mode;
                    276:    idxflag=1;
1.88      albertel  277:    idx=open('$resurl/?inhibitmenu=yes&launch=1&mode=$mode&catalogmode='+mode,'idxout',options);
1.32      www       278:    idx.focus();
                    279: }
                    280: 
1.73      www       281: // ------------------------------------------------------ Open groupsort window
1.80      www       282: function groupopen(url,recover,bookmarks) {
1.73      www       283:    var options="scrollbars=1,resizable=1,menubar=0";
                    284:    idxflag=1;
1.88      albertel  285:    idx=open("/adm/groupsort?inhibitmenu=yes&mode=$mode&recover="+recover+"&readfile="+url+"&bookmarks="+bookmarks,"idxout",options);
1.73      www       286:    idx.focus();
                    287: }
                    288: 
1.32      www       289: // --------------------------------------------------------- Open search window
                    290: function srchopen(mode) {
                    291:    var options="scrollbars=1,resizable=1,menubar=0";
                    292:    srchmode=mode;
                    293:    srchflag=1;
1.88      albertel  294:    srch=open("/adm/searchcat?inhibitmenu=yes&launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
1.32      www       295:    srch.focus();
                    296: }
                    297: // ----------------------------------------------------- launch indexer browser
                    298: function groupsearch() {
1.79      www       299:    srchcheck('import');
1.32      www       300: }
                    301: 
                    302: function groupimport() {
1.79      www       303:    idxcheck('import');
1.32      www       304: }
1.73      www       305: 
1.32      www       306: // ------------------------------------------------------- Do srch status check
                    307: function srchcheck(mode) {
                    308:    if (!srch || srch.closed || srchmode!=mode) {
                    309:       srchopen(mode);
                    310:    }
                    311:    srch.focus();
                    312: }
                    313: 
                    314: // -------------------------------------------------------- Do idx status check
                    315: function idxcheck(mode) {
                    316:    if (!idx || idx.closed || idxmode!=mode) {
                    317:       idxopen(mode);
                    318:    }
                    319:    idx.focus();
                    320: }
                    321: 
                    322: 
                    323:     var editbrowser;
                    324:     function openbrowser(formname,elementname,only,omit) {
1.51      www       325:         var url = '$resurl/?';
1.32      www       326:         if (editbrowser == null) {
                    327:             url += 'launch=1&';
                    328:         }
1.88      albertel  329:         url += 'inhibitmenu=yes&';
1.32      www       330:         url += 'catalogmode=interactive&';
                    331:         url += 'mode=edit&';
                    332:         url += 'form=' + formname + '&';
                    333:         if (only != null) {
                    334:             url += 'only=' + only + '&';
                    335:         } 
                    336:         if (omit != null) {
                    337:             url += 'omit=' + omit + '&';
                    338:         }
                    339:         url += 'element=' + elementname + '';
                    340:         var title = 'Browser';
1.82      albertel  341:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.32      www       342:         options += ',width=700,height=600';
                    343:         editbrowser = open(url,title,options,'1');
                    344:         editbrowser.focus();
                    345:     }
                    346: ENDSCRIPT
                    347: }
1.20      www       348: # ------------------------------------------------------- Simple edit processor
                    349: 
1.3       www       350: sub smpedt {
1.22      www       351:    my ($r,$url,$errtext)=@_;
1.8       www       352:    my $buttons=&buttons(2);
1.34      www       353:    my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
                    354:    my $targetmsg='';
1.65      albertel  355:    if ($env{'form.save'}) {
1.34      www       356:        copy($tmpfn,&Apache::lonnet::filelocation('',$url));
                    357:        unlink($tmpfn);
1.35      www       358:        my ($errtext,$fatal)=
1.84      albertel  359: 	   &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
1.60      www       360:        unless ($fatal) {
                    361: 	   $targetmsg='<b>'.&mt('Saved.').'</b><br />';
                    362:        } else {
1.89      bisitz    363: 	   $targetmsg='<b>'.&mt('An error occurred while saving.').'</b><br />';
1.60      www       364:        }
1.34      www       365:    }
1.65      albertel  366:    if ($env{'form.revert'}) {
1.60      www       367:        $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
1.34      www       368:        unlink($tmpfn);
1.35      www       369:        my ($errtext,$fatal)=
1.84      albertel  370: 	   &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
1.34      www       371:    }
                    372:    if (-e $tmpfn) {
                    373:       $targetmsg=
1.49      sakharuk  374:         '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
1.84      albertel  375:       my ($errtext,$fatal)=&LONCAPA::map::mapread($tmpfn,'');
1.34      www       376:    }
1.12      www       377: # ---------------------------------------------------------- Process form input
                    378: 
1.66      albertel  379:    my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
                    380:    my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
1.13      www       381: # ============================================================ Process commands
1.12      www       382: 
1.65      albertel  383:    my $targetdetail=$env{'form.targetdetail'};
                    384:    my $importdetail=$env{'form.curimpdetail'};
1.13      www       385: 
                    386: # ---------------------------------------------------- Importing from groupsort
1.65      albertel  387:    if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
1.13      www       388: 
1.14      www       389:        $importdetail='';
1.65      albertel  390:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.13      www       391: 
                    392:        my $lastsel;
                    393: 
                    394:        if (defined($importselect[-1])) {
                    395: 	   $lastsel=$importselect[-1];
                    396:        } else {
                    397:            $lastsel=$#curimport;
                    398:        }
                    399: 
                    400:        for (my $i=0;$i<=$lastsel;$i++) {
                    401:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    402:            if ($url) {
1.18      www       403:               $importdetail.='&'.$name.'='.$url;
1.13      www       404: 	   }
                    405:        }
                    406: 
1.65      albertel  407:       $importdetail.='&'.$env{'form.importdetail'};
1.13      www       408: 
                    409:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    410:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    411:            if ($url) {
1.18      www       412:               $importdetail.='&'.$name.'='.$url;
1.13      www       413: 	  }
                    414:        }
                    415:        $importdetail=~s/\&+/\&/g;
                    416:        $importdetail=~s/^\&//;
                    417: 
1.14      www       418: # ------------------------------------------------------------------- Clear all
1.65      albertel  419:    } elsif ($env{'form.clear'}) {
1.14      www       420:        $importdetail='';
                    421: # ------------------------------------------------------------ Discard selected
1.65      albertel  422:    } elsif ($env{'form.discard'}) {
1.14      www       423:        $importdetail='';
1.65      albertel  424:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.14      www       425:        foreach (@importselect) {
                    426: 	   $curimport[$_]='';
                    427:        }
                    428:        for (my $i=0;$i<=$#curimport;$i++) {
                    429:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    430:            if ($url) {
1.18      www       431:               $importdetail.='&'.$name.'='.$url;
1.14      www       432: 	   }
                    433:        }
1.17      www       434: # --------------------------------------------------------- Loading another map
1.65      albertel  435:    } elsif ($env{'form.loadmap'}) {
1.17      www       436:        $importdetail='';
1.65      albertel  437:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.17      www       438: 
                    439:        my $lastsel;
                    440: 
                    441:        if (defined($importselect[-1])) {
                    442: 	   $lastsel=$importselect[-1];
                    443:        } else {
                    444:            $lastsel=$#curimport;
                    445:        }
                    446: 
                    447:        for (my $i=0;$i<=$lastsel;$i++) {
                    448:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    449:            if ($url) {
1.18      www       450:               $importdetail.='&'.$name.'='.$url;
1.17      www       451: 	   }
                    452:        }
                    453: 
                    454:        foreach (
1.65      albertel  455:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.17      www       456: 	   my ($name,$url)=split(/\:/,$_);
                    457:            if ($url) {
1.78      www       458:               $importdetail.='&'.&escape($name).'='.
                    459: 		 	         &escape($url);
1.17      www       460: 	  }
                    461:        }
                    462: 
                    463:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    464:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    465:            if ($url) {
1.18      www       466:               $importdetail.='&'.$name.'='.$url;
1.17      www       467: 	  }
                    468:        }
                    469:        $importdetail=~s/\&+/\&/g;
                    470:        $importdetail=~s/^\&//;
                    471: 
1.20      www       472: # ------------------------------------------------ Groupimport/search to target
1.65      albertel  473:    } elsif ($env{'form.importdetail'}) {
1.20      www       474:        my $lastsel;
                    475:        if (defined($targetselect[-1])) {
                    476: 	   $lastsel=$targetselect[-1];
                    477:        } else {
1.84      albertel  478:            $lastsel=$#LONCAPA::map::order+1;
1.20      www       479:        }
1.84      albertel  480:        &LONCAPA::map::pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
                    481:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.20      www       482: # ------------------------------------------------------------------------- Cut
1.65      albertel  483:    } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
1.25      www       484:        $importdetail='';
1.65      albertel  485:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.25      www       486: 
                    487:        my $lastsel;
                    488: 
                    489:        if (defined($importselect[-1])) {
                    490: 	   $lastsel=$importselect[-1];
                    491:        } else {
                    492:            $lastsel=$#curimport;
                    493:        }
                    494: 
                    495:        for (my $i=0;$i<=$lastsel;$i++) {
                    496:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    497:            if ($url) {
                    498:               $importdetail.='&'.$name.'='.$url;
                    499: 	   }
                    500:        }
                    501: 
                    502:        foreach (@targetselect) {
1.84      albertel  503: 	   my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$LONCAPA::map::order[$_-1]]);
1.25      www       504:            if ($url) {
1.78      www       505:               $importdetail.='&'.&escape($name).'='.
                    506: 		 	         &escape($url);
1.25      www       507: 	  }
                    508:        }
                    509: 
                    510:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    511:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    512:            if ($url) {
                    513:               $importdetail.='&'.$name.'='.$url;
                    514: 	  }
                    515:        }
                    516:        $importdetail=~s/\&+/\&/g;
                    517:        $importdetail=~s/^\&//;
                    518: 
1.65      albertel  519:        if ($env{'form.cut'}) {
1.25      www       520:            my @neworder=();
1.84      albertel  521:            for (my $i=0;$i<=$#LONCAPA::map::order;$i++) {
1.25      www       522:                my $include=1;
                    523:                foreach (@targetselect) {
                    524: 		   if ($_-1==$i) { $include=0; }
                    525:                }
1.71      www       526:                if ($include) { 
1.84      albertel  527: 		   $neworder[$#neworder+1]=$LONCAPA::map::order[$i]; 
1.71      www       528: 	       } else {
1.84      albertel  529: 		   &LONCAPA::map::makezombie($LONCAPA::map::order[$i]);
1.71      www       530: 	       }
1.25      www       531:            }
1.84      albertel  532:            @LONCAPA::map::order=@neworder;
                    533:            &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));      
1.25      www       534:        }
                    535: 
1.20      www       536: # ----------------------------------------------------------------------- Paste
1.65      albertel  537:    } elsif ($env{'form.paste'}) {
1.24      www       538:        my $lastsel;
                    539:        if (defined($targetselect[-1])) {
                    540: 	   $lastsel=$targetselect[-1];
                    541:        } else {
1.84      albertel  542:            $lastsel=$#LONCAPA::map::order+1;
1.24      www       543:        }
                    544:        my @newsequence;
1.65      albertel  545:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.24      www       546:        foreach (@importselect) {
                    547:           $newsequence[$#newsequence+1]=$curimport[$_];
                    548:        }
1.84      albertel  549:        &LONCAPA::map::pastetarget($lastsel,@newsequence);
                    550:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39      www       551: # -------------------------------------------------------------------- Move up 
1.65      albertel  552:    } elsif ($env{'form.moveup'}) {
1.39      www       553:        foreach (sort @targetselect) {
                    554:            if ($_-1>0) {
1.84      albertel  555:               my $movethis=$LONCAPA::map::order[$_-1];
                    556:               $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_-2];
                    557:               $LONCAPA::map::order[$_-2]=$movethis;
1.39      www       558: 	  }
                    559:        }
1.84      albertel  560:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39      www       561: # ------------------------------------------------------------------ Move down
1.65      albertel  562:    } elsif ($env{'form.movedown'}) {
1.39      www       563:        foreach (reverse sort @targetselect) {
1.84      albertel  564:            if ($_-1<$#LONCAPA::map::order) {
                    565:               my $movethis=$LONCAPA::map::order[$_-1];
                    566:               $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_];
                    567:               $LONCAPA::map::order[$_]=$movethis;
1.39      www       568: 	   }
                    569:        }
1.84      albertel  570:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39      www       571: # --------------------------------------------------------------------- Rename
1.65      albertel  572:    } elsif ($env{'form.renameres'}) {
1.84      albertel  573:        my $residx=$LONCAPA::map::order[$env{'form.renameidx'}-1];
                    574:        my ($name,@resrest)=split(/\:/,$LONCAPA::map::resources[$residx]);
1.65      albertel  575:        $name=$env{'form.renametitle'};
1.40      www       576:        $name=~s/\:/\&colon\;/g;
1.84      albertel  577:        $LONCAPA::map::resources[$residx]=$name.':'.join(':',@resrest);
                    578:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.13      www       579:    }
1.12      www       580: # ------------------------------------------------------------ Assemble windows
1.20      www       581:    
1.13      www       582:    my $idx=-1;
1.34      www       583:    $importdetail='&'.$importdetail;
                    584:    $importdetail=~s/^\&+/\&/;
1.29      www       585:    my $importwindow=
1.50      sakharuk  586:        '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
1.29      www       587:      join("\n",map {
1.13      www       588:        $idx++;
                    589:        if ($_) { 
1.15      www       590:           my ($name,$url)=split(/\=/,$_);
                    591:           unless ($name) { $name=(split(/\//,$url))[-1]; }
                    592:           unless ($name) { $name='EMPTY'; }
1.78      www       593:           '<option value="'.$idx.'">'.&unescape($name).
1.13      www       594:                                     '</option>';
                    595:       }
                    596:    } split(/\&/,$importdetail));
1.12      www       597: 
1.13      www       598:    $idx=0;
1.39      www       599:    $targetdetail='';
1.29      www       600:    my $targetwindow=       
1.49      sakharuk  601:        '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
1.29      www       602:      join("\n",map { 
1.84      albertel  603:        my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
1.15      www       604:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
                    605:        unless ($name) { $name='EMPTY'; }
1.87      albertel  606:        $name = &LONCAPA::map::qtescape($name);
                    607:        $url  = &LONCAPA::map::qtescape($url);
1.78      www       608:        $targetdetail.='&'.&escape($name).'='.
                    609: 	                  &escape($url);
1.13      www       610:        $idx++;
1.87      albertel  611:        $name = &HTML::Entities::encode($name,'\'"<>&');
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;
1.19      www       648:        if (url) { open(url,'cat'); }
                    649:    }
                    650: 
                    651:    function viewtarget() {
                    652:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34      www       653:                 [document.forms.simpleedit.target.selectedIndex]);
1.19      www       654:    }
                    655: 
                    656:    function viewimport() {
                    657:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34      www       658:                 [document.forms.simpleedit.importsel.selectedIndex]);
1.19      www       659:    }
                    660: 
1.39      www       661:    function renametarget() {
                    662:        var selidx=document.forms.simpleedit.target.selectedIndex;
                    663:        var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
                    664:                 [selidx];
1.41      www       665:        var oldname=unescape((entry.split('='))[0]);
1.47      www       666:        newtitle=prompt('$lt{'nt'}',oldname);
1.39      www       667:        if (newtitle) {
                    668:            document.forms.simpleedit.renameres.value=1;
                    669:            document.forms.simpleedit.renameidx.value=selidx;
                    670:            document.forms.simpleedit.renametitle.value=newtitle;
                    671: 	   document.forms.simpleedit.submit();
                    672:        }
                    673:    }
                    674: 
1.6       www       675: </script>
1.75      albertel  676: ENDJS
                    677: 
1.76      albertel  678:     my $start_page = &Apache::loncommon::start_page(undef,$js).
1.81      albertel  679:         &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
1.76      albertel  680: 					   'Sequence_Simple_Editor_Creation',
1.81      albertel  681: 					   6,'RAT');    
1.75      albertel  682:     my $end_page = &Apache::loncommon::end_page();
                    683: 
                    684:     $r->print(<<ENDSMPHEAD);
                    685: $start_page
1.8       www       686: $buttons
1.7       www       687: <font color=red>$errtext</font>
1.13      www       688: <form name=simpleedit method=post>
1.11      www       689: <input type=hidden name=forcesmp value=1>
1.39      www       690: <input type=hidden name=renameres value=0>
                    691: <input type=hidden name=renametitle value=''>
                    692: <input type=hidden name=renameidx value=0>
1.11      www       693: <table>
1.47      www       694:     <tr><th width="40%">$lt{'ta'}</th>
1.12      www       695: <th>&nbsp;</th>
1.37      www       696: <th width="40%">File: $url</th></tr>
1.12      www       697: <tr><td bgcolor="#FFFFCC">
1.47      www       698: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
                    699: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
1.49      sakharuk  700: $lt{'as'}
1.14      www       701: <hr>
1.15      www       702: <input type=text size=20 name=importmap>
                    703: <input type=button 
                    704: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
1.47      www       705: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
                    706: <input type=submit name="discard" value="$lt{'ds'}">
                    707: <input type=submit name="clear" value="$lt{'ca'}">
                    708: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
1.16      www       709: 
1.12      www       710:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
1.16      www       711: 
                    712: <input type=button onClick=
1.47      www       713: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
1.16      www       714: <input type=button onClick=
1.47      www       715: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
1.74      www       716: <input type=button onClick=
1.80      www       717: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}">
                    718: <input type=button onClick=
                    719: "javascript:impfortarget.value=1;groupopen('$url',1,0);" value="$lt{'reco'}">
1.49      sakharuk  720: $lt{'as'}
1.39      www       721: <hr>
1.47      www       722: <input type=submit name="moveup" value="$lt{'mu'}">
                    723: <input type=submit name="movedown" value="$lt{'md'}">
                    724: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
1.34      www       725: <hr>$targetmsg
1.47      www       726: <input type=submit name="revert" value="$lt{'rv'}">
                    727: <input type=submit name="save" value="$lt{'sa'}">
                    728: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
1.12      www       729: </td></tr>
1.16      www       730: 
1.27      www       731: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12      www       732: $importwindow
                    733: </select>
1.11      www       734: </td>
1.12      www       735: <td bgcolor="#FFFFAA" align="center">
1.49      sakharuk  736: $lt{'cs'}<br>
1.11      www       737: <input type=submit name=cut value='<<<'><p>
1.12      www       738: <hr>
1.49      sakharuk  739: $lt{'ps'}<br>
1.25      www       740: <input type=submit name=copy value='<--'><p>
                    741: <hr>
1.49      sakharuk  742: $lt{'pas'}<br>
1.25      www       743: <input type=submit name=paste value='-->'>
1.11      www       744: </td>
1.27      www       745: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11      www       746: $targetwindow
                    747: </select>
1.12      www       748: </table>
1.13      www       749: <input type=hidden name=importdetail value="">
                    750: <input type=hidden name=curimpdetail value="$importdetail">
1.12      www       751: <input type=hidden name=targetdetail value="$targetdetail">
1.16      www       752: <input type=hidden name=impfortarget value="0">
1.12      www       753: </form>
1.75      albertel  754: $end_page
1.3       www       755: ENDSMPHEAD
                    756: }
                    757: 
1.11      www       758: # ----------------------------------------------------------------- No such dir
1.4       www       759: sub nodir {
                    760:    my ($r,$dir)=@_;
1.86      albertel  761:    $dir=~s{^/home/$LONCAPA::username_re/public_html}{};
1.75      albertel  762:    $r->print(&Apache::loncommon::start_page(undef,undef,
                    763: 					    {'only_body' => 1,
                    764: 					     'bgcolor'   => '#FFFFFF',}).
                    765: 	     "<h1>No such directory: $dir</h1>".
                    766: 	     &Apache::loncommon::end_page());
1.4       www       767: }
                    768: 
1.8       www       769: # ---------------------------------------------------------------- View Handler
                    770: 
                    771: sub viewmap {
1.17      www       772:     my ($r,$url,$adv,$errtext)=@_;
1.75      albertel  773:     $r->print(
                    774: 	      &Apache::loncommon::start_page('Edit Content of a Map').
1.81      albertel  775: 	      &Apache::loncommon::help_open_menu('','',6,'RAT').
1.53      www       776: 	      &buttons($adv));
1.10      www       777:     if ($errtext) {
1.90    ! bisitz    778: 	$r->print('<div class="LC_error">'
        !           779:                  .$errtext
        !           780:                  .'</div>'
        !           781:                  .'<hr />'
        !           782:         );
1.10      www       783:     }
1.26      www       784:     my $idx=0;
1.34      www       785:     $r->print('<h1>'.$url.'</h1>');
1.44      www       786:     if ($adv) {
1.90    ! bisitz    787: 	$r->print('<p class="LC_warning">'
        !           788:                  .&mt('Map contents are not shown in order.')
        !           789:                  .'</p><br />'
        !           790:         );
1.44      www       791:     }
1.90    ! bisitz    792:     $r->print(&Apache::loncommon::start_data_table()
        !           793:              .&Apache::loncommon::start_data_table_header_row()
        !           794:              .'<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:              .&Apache::loncommon::end_data_table_header_row()
        !           800:     );
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.87      albertel  806:             $title= &LONCAPA::map::qtescape($title);
                    807:             $url  = &LONCAPA::map::qtescape($url);
1.15      www       808:             unless ($title) { $title=(split(/\//,$url))[-1] };
1.64      raeburn   809:             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
1.87      albertel  810:             my $resurl = $url;
1.64      raeburn   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/#;
1.90    ! bisitz    818:             $r->print(&Apache::loncommon::start_data_table_row()
        !           819:                      .'<td>'
        !           820:                      .'<img src="'.&Apache::loncommon::icon($resfilepath).'" />'
        !           821:                      .'</td>'
        !           822:                      .'<td>'
        !           823:                      .&HTML::Entities::encode(&LONCAPA::map::qtescape($title))
        !           824:                      .'</td>'
        !           825:                      .'<td>'.$filename.'</td>'
        !           826:                      .'<td>'
        !           827:             );
1.64      raeburn   828:             if ($url) {
1.68      www       829: 		$r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
1.90    ! bisitz    830:             } else {
        !           831:                 $r->print('&nbsp;');
1.64      raeburn   832:             }
                    833:             $r->print('</td><td>');
1.9       www       834:             if ($url) {
1.64      raeburn   835:                $r->print('<a href="'.$cstrurl.'">'.
                    836:                          &mt('Construction space').'</a>');
1.90    ! bisitz    837:             } else {
        !           838:                 $r->print('&nbsp;');
1.9       www       839:             }
1.90    ! bisitz    840:             $r->print('</td>'
        !           841:                      .&Apache::loncommon::end_data_table_row()
        !           842:             );
1.9       www       843:         }
                    844:     }
1.90    ! bisitz    845:     $r->print(&Apache::loncommon::end_data_table());
1.75      albertel  846:     $r->print(&Apache::loncommon::end_page());
1.8       www       847: }
                    848: 
1.3       www       849: # ================================================================ Main Handler
                    850: 
                    851: sub handler {
                    852:   my $r=shift;
1.47      www       853:   &Apache::loncommon::content_type($r,'text/html');
1.3       www       854:   $r->send_http_header;
                    855: 
                    856:   return OK if $r->header_only;
1.65      albertel  857:   my $target = $env{'form.grade_target'};
1.48      albertel  858:   if ($target eq 'meta') {
                    859:       &Apache::loncommon::content_type($r,'text/html');
                    860:       $r->send_http_header;
                    861:       return OK;
                    862:   }
                    863:   
1.3       www       864:   my $url=$r->uri;
                    865:   my $fn=&Apache::lonnet::filelocation('',$url);
                    866: 
1.4       www       867:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
                    868:   unless (-e $dir) {
                    869:       &nodir($r,$dir);
                    870:       return OK;
                    871:   }
1.8       www       872: 
                    873: # ------------------------------------------- Determine which tools can be used
1.3       www       874:   my $adv=0;
                    875: 
1.65      albertel  876:   unless ($env{'form.forcesmp'}) {
                    877:      if ($env{'form.forceadv'}) {
1.3       www       878:         $adv=1;
                    879:      } elsif (my $fh=Apache::File->new($fn)) {
                    880: 	 my $allmap=join('',<$fh>);
                    881:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
                    882:      }
                    883:   }
                    884: 
1.8       www       885:   my $errtext='';
                    886:   my $fatal=0;
                    887: 
                    888: # -------------------------------------------------------------------- Load map
1.84      albertel  889:   ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
1.8       www       890: 
                    891:   if ($fatal==1) { $adv=1; }
                    892: 
                    893: # ----------------------------------- adv==1 now means "graphical MUST be used"
                    894: 
1.65      albertel  895:   if ($env{'form.forceadv'}) {
1.3       www       896:       &ratedt($r,$url);
1.65      albertel  897:   } elsif ($env{'form.forcesmp'}) {
1.22      www       898:       &smpedt($r,$url,$errtext);
1.3       www       899:   } else {
1.17      www       900:       &viewmap($r,$url,$adv,$errtext);
1.3       www       901:   }
1.1       www       902:   return OK;
                    903: }
                    904: 
                    905: 1;
                    906: __END__
                    907: 
                    908: 
                    909: 
                    910: 
                    911: 
                    912: 
                    913: 

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