Annotation of rat/lonratedt.pm, revision 1.85

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Edit Handler for RAT Maps
1.5       www         3: #
1.85    ! albertel    4: # $Id: lonratedt.pm,v 1.84 2006/11/02 21:03:28 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.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.1       www       176: 
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.83      albertel  277:    idx=open('$resurl/?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.80      www       285:    idx=open("/adm/groupsort?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;
                    294:    srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
                    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:         }
                    329:         url += 'catalogmode=interactive&';
                    330:         url += 'mode=edit&';
                    331:         url += 'form=' + formname + '&';
                    332:         if (only != null) {
                    333:             url += 'only=' + only + '&';
                    334:         } 
                    335:         if (omit != null) {
                    336:             url += 'omit=' + omit + '&';
                    337:         }
                    338:         url += 'element=' + elementname + '';
                    339:         var title = 'Browser';
1.82      albertel  340:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.32      www       341:         options += ',width=700,height=600';
                    342:         editbrowser = open(url,title,options,'1');
                    343:         editbrowser.focus();
                    344:     }
                    345: ENDSCRIPT
                    346: }
1.20      www       347: # ------------------------------------------------------- Simple edit processor
                    348: 
1.3       www       349: sub smpedt {
1.22      www       350:    my ($r,$url,$errtext)=@_;
1.8       www       351:    my $buttons=&buttons(2);
1.34      www       352:    my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
                    353:    my $targetmsg='';
1.65      albertel  354:    if ($env{'form.save'}) {
1.34      www       355:        copy($tmpfn,&Apache::lonnet::filelocation('',$url));
                    356:        unlink($tmpfn);
1.35      www       357:        my ($errtext,$fatal)=
1.84      albertel  358: 	   &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
1.60      www       359:        unless ($fatal) {
                    360: 	   $targetmsg='<b>'.&mt('Saved.').'</b><br />';
                    361:        } else {
                    362: 	   $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
                    363:        }
1.34      www       364:    }
1.65      albertel  365:    if ($env{'form.revert'}) {
1.60      www       366:        $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
1.34      www       367:        unlink($tmpfn);
1.35      www       368:        my ($errtext,$fatal)=
1.84      albertel  369: 	   &LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$url),'');
1.34      www       370:    }
                    371:    if (-e $tmpfn) {
                    372:       $targetmsg=
1.49      sakharuk  373:         '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
1.84      albertel  374:       my ($errtext,$fatal)=&LONCAPA::map::mapread($tmpfn,'');
1.34      www       375:    }
1.12      www       376: # ---------------------------------------------------------- Process form input
                    377: 
1.66      albertel  378:    my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
                    379:    my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
1.13      www       380: # ============================================================ Process commands
1.12      www       381: 
1.65      albertel  382:    my $targetdetail=$env{'form.targetdetail'};
                    383:    my $importdetail=$env{'form.curimpdetail'};
1.13      www       384: 
                    385: # ---------------------------------------------------- Importing from groupsort
1.65      albertel  386:    if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
1.13      www       387: 
1.14      www       388:        $importdetail='';
1.65      albertel  389:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.13      www       390: 
                    391:        my $lastsel;
                    392: 
                    393:        if (defined($importselect[-1])) {
                    394: 	   $lastsel=$importselect[-1];
                    395:        } else {
                    396:            $lastsel=$#curimport;
                    397:        }
                    398: 
                    399:        for (my $i=0;$i<=$lastsel;$i++) {
                    400:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    401:            if ($url) {
1.18      www       402:               $importdetail.='&'.$name.'='.$url;
1.13      www       403: 	   }
                    404:        }
                    405: 
1.65      albertel  406:       $importdetail.='&'.$env{'form.importdetail'};
1.13      www       407: 
                    408:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    409:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    410:            if ($url) {
1.18      www       411:               $importdetail.='&'.$name.'='.$url;
1.13      www       412: 	  }
                    413:        }
                    414:        $importdetail=~s/\&+/\&/g;
                    415:        $importdetail=~s/^\&//;
                    416: 
1.14      www       417: # ------------------------------------------------------------------- Clear all
1.65      albertel  418:    } elsif ($env{'form.clear'}) {
1.14      www       419:        $importdetail='';
                    420: # ------------------------------------------------------------ Discard selected
1.65      albertel  421:    } elsif ($env{'form.discard'}) {
1.14      www       422:        $importdetail='';
1.65      albertel  423:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.14      www       424:        foreach (@importselect) {
                    425: 	   $curimport[$_]='';
                    426:        }
                    427:        for (my $i=0;$i<=$#curimport;$i++) {
                    428:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    429:            if ($url) {
1.18      www       430:               $importdetail.='&'.$name.'='.$url;
1.14      www       431: 	   }
                    432:        }
1.17      www       433: # --------------------------------------------------------- Loading another map
1.65      albertel  434:    } elsif ($env{'form.loadmap'}) {
1.17      www       435:        $importdetail='';
1.65      albertel  436:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.17      www       437: 
                    438:        my $lastsel;
                    439: 
                    440:        if (defined($importselect[-1])) {
                    441: 	   $lastsel=$importselect[-1];
                    442:        } else {
                    443:            $lastsel=$#curimport;
                    444:        }
                    445: 
                    446:        for (my $i=0;$i<=$lastsel;$i++) {
                    447:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    448:            if ($url) {
1.18      www       449:               $importdetail.='&'.$name.'='.$url;
1.17      www       450: 	   }
                    451:        }
                    452: 
                    453:        foreach (
1.65      albertel  454:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.17      www       455: 	   my ($name,$url)=split(/\:/,$_);
                    456:            if ($url) {
1.78      www       457:               $importdetail.='&'.&escape($name).'='.
                    458: 		 	         &escape($url);
1.17      www       459: 	  }
                    460:        }
                    461: 
                    462:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    463:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    464:            if ($url) {
1.18      www       465:               $importdetail.='&'.$name.'='.$url;
1.17      www       466: 	  }
                    467:        }
                    468:        $importdetail=~s/\&+/\&/g;
                    469:        $importdetail=~s/^\&//;
                    470: 
1.20      www       471: # ------------------------------------------------ Groupimport/search to target
1.65      albertel  472:    } elsif ($env{'form.importdetail'}) {
1.20      www       473:        my $lastsel;
                    474:        if (defined($targetselect[-1])) {
                    475: 	   $lastsel=$targetselect[-1];
                    476:        } else {
1.84      albertel  477:            $lastsel=$#LONCAPA::map::order+1;
1.20      www       478:        }
1.84      albertel  479:        &LONCAPA::map::pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
                    480:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.20      www       481: # ------------------------------------------------------------------------- Cut
1.65      albertel  482:    } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
1.25      www       483:        $importdetail='';
1.65      albertel  484:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.25      www       485: 
                    486:        my $lastsel;
                    487: 
                    488:        if (defined($importselect[-1])) {
                    489: 	   $lastsel=$importselect[-1];
                    490:        } else {
                    491:            $lastsel=$#curimport;
                    492:        }
                    493: 
                    494:        for (my $i=0;$i<=$lastsel;$i++) {
                    495:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    496:            if ($url) {
                    497:               $importdetail.='&'.$name.'='.$url;
                    498: 	   }
                    499:        }
                    500: 
                    501:        foreach (@targetselect) {
1.84      albertel  502: 	   my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$LONCAPA::map::order[$_-1]]);
1.25      www       503:            if ($url) {
1.78      www       504:               $importdetail.='&'.&escape($name).'='.
                    505: 		 	         &escape($url);
1.25      www       506: 	  }
                    507:        }
                    508: 
                    509:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    510:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    511:            if ($url) {
                    512:               $importdetail.='&'.$name.'='.$url;
                    513: 	  }
                    514:        }
                    515:        $importdetail=~s/\&+/\&/g;
                    516:        $importdetail=~s/^\&//;
                    517: 
1.65      albertel  518:        if ($env{'form.cut'}) {
1.25      www       519:            my @neworder=();
1.84      albertel  520:            for (my $i=0;$i<=$#LONCAPA::map::order;$i++) {
1.25      www       521:                my $include=1;
                    522:                foreach (@targetselect) {
                    523: 		   if ($_-1==$i) { $include=0; }
                    524:                }
1.71      www       525:                if ($include) { 
1.84      albertel  526: 		   $neworder[$#neworder+1]=$LONCAPA::map::order[$i]; 
1.71      www       527: 	       } else {
1.84      albertel  528: 		   &LONCAPA::map::makezombie($LONCAPA::map::order[$i]);
1.71      www       529: 	       }
1.25      www       530:            }
1.84      albertel  531:            @LONCAPA::map::order=@neworder;
                    532:            &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));      
1.25      www       533:        }
                    534: 
1.20      www       535: # ----------------------------------------------------------------------- Paste
1.65      albertel  536:    } elsif ($env{'form.paste'}) {
1.24      www       537:        my $lastsel;
                    538:        if (defined($targetselect[-1])) {
                    539: 	   $lastsel=$targetselect[-1];
                    540:        } else {
1.84      albertel  541:            $lastsel=$#LONCAPA::map::order+1;
1.24      www       542:        }
                    543:        my @newsequence;
1.65      albertel  544:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.24      www       545:        foreach (@importselect) {
                    546:           $newsequence[$#newsequence+1]=$curimport[$_];
                    547:        }
1.84      albertel  548:        &LONCAPA::map::pastetarget($lastsel,@newsequence);
                    549:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39      www       550: # -------------------------------------------------------------------- Move up 
1.65      albertel  551:    } elsif ($env{'form.moveup'}) {
1.39      www       552:        foreach (sort @targetselect) {
                    553:            if ($_-1>0) {
1.84      albertel  554:               my $movethis=$LONCAPA::map::order[$_-1];
                    555:               $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_-2];
                    556:               $LONCAPA::map::order[$_-2]=$movethis;
1.39      www       557: 	  }
                    558:        }
1.84      albertel  559:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39      www       560: # ------------------------------------------------------------------ Move down
1.65      albertel  561:    } elsif ($env{'form.movedown'}) {
1.39      www       562:        foreach (reverse sort @targetselect) {
1.84      albertel  563:            if ($_-1<$#LONCAPA::map::order) {
                    564:               my $movethis=$LONCAPA::map::order[$_-1];
                    565:               $LONCAPA::map::order[$_-1]=$LONCAPA::map::order[$_];
                    566:               $LONCAPA::map::order[$_]=$movethis;
1.39      www       567: 	   }
                    568:        }
1.84      albertel  569:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.39      www       570: # --------------------------------------------------------------------- Rename
1.65      albertel  571:    } elsif ($env{'form.renameres'}) {
1.84      albertel  572:        my $residx=$LONCAPA::map::order[$env{'form.renameidx'}-1];
                    573:        my ($name,@resrest)=split(/\:/,$LONCAPA::map::resources[$residx]);
1.65      albertel  574:        $name=$env{'form.renametitle'};
1.40      www       575:        $name=~s/\:/\&colon\;/g;
1.84      albertel  576:        $LONCAPA::map::resources[$residx]=$name.':'.join(':',@resrest);
                    577:        &LONCAPA::map::storemap(&Apache::lonnet::filelocation('',$url));
1.13      www       578:    }
1.12      www       579: # ------------------------------------------------------------ Assemble windows
1.20      www       580:    
1.13      www       581:    my $idx=-1;
1.34      www       582:    $importdetail='&'.$importdetail;
                    583:    $importdetail=~s/^\&+/\&/;
1.29      www       584:    my $importwindow=
1.50      sakharuk  585:        '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
1.29      www       586:      join("\n",map {
1.13      www       587:        $idx++;
                    588:        if ($_) { 
1.15      www       589:           my ($name,$url)=split(/\=/,$_);
                    590:           unless ($name) { $name=(split(/\//,$url))[-1]; }
                    591:           unless ($name) { $name='EMPTY'; }
1.78      www       592:           '<option value="'.$idx.'">'.&unescape($name).
1.13      www       593:                                     '</option>';
                    594:       }
                    595:    } split(/\&/,$importdetail));
1.12      www       596: 
1.13      www       597:    $idx=0;
1.39      www       598:    $targetdetail='';
1.29      www       599:    my $targetwindow=       
1.49      sakharuk  600:        '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
1.29      www       601:      join("\n",map { 
1.84      albertel  602:        my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
1.15      www       603:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
                    604:        unless ($name) { $name='EMPTY'; }
1.78      www       605:        $targetdetail.='&'.&escape($name).'='.
                    606: 	                  &escape($url);
1.13      www       607:        $idx++;
1.37      www       608:        $name=~s/\&colon;/\:/g;
1.20      www       609:        '<option value="'.$idx.'">'.$name.'</option>';
1.84      albertel  610:    } @LONCAPA::map::order);
1.11      www       611: 
1.8       www       612: # ----------------------------------------------------- Start simple RAT screen
1.32      www       613:    my $editscript=&editscript('simple');
1.75      albertel  614: 
1.47      www       615:    my %lt=&Apache::lonlocal::texthash(
                    616: 				      'sa' => 'Save',
                    617: 				      'nt' => 'New Title',
                    618: 				      'se' => 'Search',
                    619: 				      'im' => 'Import',
1.80      www       620:                                       'bk' => 'Import Bookmarks',
1.47      www       621: 				      'vi' => 'View',
                    622: 				      'lm' => 'Load Map',
                    623: 				      'ds' => 'Discard Selected',
                    624: 				      'ca' => 'Clear All',
                    625: 				      'ta' => 'Temporary Assembly Workspace',
                    626: 				      'rv' => 'Revert to Last Saved',
                    627:                                       'sa' => 'Save',
                    628:                                       'mu' => 'Move Up',
                    629:                                       'md' => 'Move Down',
                    630:                                       're' => 'Rename',
1.49      sakharuk  631:                                       'as' => 'after selected',
                    632:                                       'cs' => 'Cut selected',
                    633:                                       'ps' => 'Copy selected',
                    634:                                       'pas' => 'Paste after selected',
1.74      www       635:                                       'reco' => 'Recover Deleted'
1.47      www       636: 				      );
1.75      albertel  637:    my $js=<<ENDJS;
1.77      albertel  638: <script type="text/javascript">
1.15      www       639: 
1.32      www       640:    $editscript
1.19      www       641: 
                    642:    function openview(entry) {
                    643:        var url=unescape((entry.split('='))[1]);
1.20      www       644:        var parts=new Array;
                    645:        parts=url.split('&colon;');
                    646:        url=parts.join(':');
1.19      www       647:        if (url) { open(url,'cat'); }
                    648:    }
                    649: 
                    650:    function viewtarget() {
                    651:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34      www       652:                 [document.forms.simpleedit.target.selectedIndex]);
1.19      www       653:    }
                    654: 
                    655:    function viewimport() {
                    656:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34      www       657:                 [document.forms.simpleedit.importsel.selectedIndex]);
1.19      www       658:    }
                    659: 
1.39      www       660:    function renametarget() {
                    661:        var selidx=document.forms.simpleedit.target.selectedIndex;
                    662:        var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
                    663:                 [selidx];
1.41      www       664:        var oldname=unescape((entry.split('='))[0]);
                    665:        var nameparts=oldname.split('&colon;');
                    666:        oldname=unescape(nameparts.join(':'));
                    667:        nameparts=oldname.split('&#34;');
                    668:        oldname=unescape(nameparts.join('"'));
                    669:        nameparts=oldname.split('&#39;');
                    670:        oldname=unescape(nameparts.join("'"));
1.47      www       671:        newtitle=prompt('$lt{'nt'}',oldname);
1.39      www       672:        if (newtitle) {
                    673:            document.forms.simpleedit.renameres.value=1;
                    674:            document.forms.simpleedit.renameidx.value=selidx;
                    675:            document.forms.simpleedit.renametitle.value=newtitle;
                    676: 	   document.forms.simpleedit.submit();
                    677:        }
                    678:    }
                    679: 
1.6       www       680: </script>
1.75      albertel  681: ENDJS
                    682: 
1.76      albertel  683:     my $start_page = &Apache::loncommon::start_page(undef,$js).
1.81      albertel  684:         &Apache::loncommon::help_open_menu('Sequence_Simple_Editor_Creation',
1.76      albertel  685: 					   'Sequence_Simple_Editor_Creation',
1.81      albertel  686: 					   6,'RAT');    
1.75      albertel  687:     my $end_page = &Apache::loncommon::end_page();
                    688: 
                    689:     $r->print(<<ENDSMPHEAD);
                    690: $start_page
1.8       www       691: $buttons
1.7       www       692: <font color=red>$errtext</font>
1.13      www       693: <form name=simpleedit method=post>
1.11      www       694: <input type=hidden name=forcesmp value=1>
1.39      www       695: <input type=hidden name=renameres value=0>
                    696: <input type=hidden name=renametitle value=''>
                    697: <input type=hidden name=renameidx value=0>
1.11      www       698: <table>
1.47      www       699:     <tr><th width="40%">$lt{'ta'}</th>
1.12      www       700: <th>&nbsp;</th>
1.37      www       701: <th width="40%">File: $url</th></tr>
1.12      www       702: <tr><td bgcolor="#FFFFCC">
1.47      www       703: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
                    704: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
1.49      sakharuk  705: $lt{'as'}
1.14      www       706: <hr>
1.15      www       707: <input type=text size=20 name=importmap>
                    708: <input type=button 
                    709: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
1.47      www       710: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
                    711: <input type=submit name="discard" value="$lt{'ds'}">
                    712: <input type=submit name="clear" value="$lt{'ca'}">
                    713: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
1.16      www       714: 
1.12      www       715:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
1.16      www       716: 
                    717: <input type=button onClick=
1.47      www       718: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
1.16      www       719: <input type=button onClick=
1.47      www       720: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
1.74      www       721: <input type=button onClick=
1.80      www       722: "javascript:impfortarget.value=1;groupopen(0,1,1);" value="$lt{'bk'}">
                    723: <input type=button onClick=
                    724: "javascript:impfortarget.value=1;groupopen('$url',1,0);" value="$lt{'reco'}">
1.49      sakharuk  725: $lt{'as'}
1.39      www       726: <hr>
1.47      www       727: <input type=submit name="moveup" value="$lt{'mu'}">
                    728: <input type=submit name="movedown" value="$lt{'md'}">
                    729: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
1.34      www       730: <hr>$targetmsg
1.47      www       731: <input type=submit name="revert" value="$lt{'rv'}">
                    732: <input type=submit name="save" value="$lt{'sa'}">
                    733: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
1.12      www       734: </td></tr>
1.16      www       735: 
1.27      www       736: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12      www       737: $importwindow
                    738: </select>
1.11      www       739: </td>
1.12      www       740: <td bgcolor="#FFFFAA" align="center">
1.49      sakharuk  741: $lt{'cs'}<br>
1.11      www       742: <input type=submit name=cut value='<<<'><p>
1.12      www       743: <hr>
1.49      sakharuk  744: $lt{'ps'}<br>
1.25      www       745: <input type=submit name=copy value='<--'><p>
                    746: <hr>
1.49      sakharuk  747: $lt{'pas'}<br>
1.25      www       748: <input type=submit name=paste value='-->'>
1.11      www       749: </td>
1.27      www       750: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11      www       751: $targetwindow
                    752: </select>
1.12      www       753: </table>
1.13      www       754: <input type=hidden name=importdetail value="">
                    755: <input type=hidden name=curimpdetail value="$importdetail">
1.12      www       756: <input type=hidden name=targetdetail value="$targetdetail">
1.16      www       757: <input type=hidden name=impfortarget value="0">
1.12      www       758: </form>
1.75      albertel  759: $end_page
1.3       www       760: ENDSMPHEAD
                    761: }
                    762: 
1.11      www       763: # ----------------------------------------------------------------- No such dir
1.4       www       764: sub nodir {
                    765:    my ($r,$dir)=@_;
1.75      albertel  766:    $dir=~s{^/home/\w+/public_html}{};
                    767:    $r->print(&Apache::loncommon::start_page(undef,undef,
                    768: 					    {'only_body' => 1,
                    769: 					     'bgcolor'   => '#FFFFFF',}).
                    770: 	     "<h1>No such directory: $dir</h1>".
                    771: 	     &Apache::loncommon::end_page());
1.4       www       772: }
                    773: 
1.8       www       774: # ---------------------------------------------------------------- View Handler
                    775: 
                    776: sub viewmap {
1.17      www       777:     my ($r,$url,$adv,$errtext)=@_;
1.75      albertel  778:     $r->print(
                    779: 	      &Apache::loncommon::start_page('Edit Content of a Map').
1.81      albertel  780: 	      &Apache::loncommon::help_open_menu('','',6,'RAT').
1.53      www       781: 	      &buttons($adv));
1.10      www       782:     if ($errtext) {
1.53      www       783: 	$r->print($errtext.'<hr />');
1.10      www       784:     }
1.26      www       785:     my $idx=0;
1.34      www       786:     $r->print('<h1>'.$url.'</h1>');
1.44      www       787:     if ($adv) {
1.47      www       788: 	$r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.44      www       789:     }
1.64      raeburn   790:     $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
                    791:                '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
                    792:                '<th>'.&mt('Title in map').'</th>'.
                    793:                '<th>'.&mt('Filename of resource').'</th>'.
                    794:                '<th>'.&mt('Link to published resource').'</th>'.
                    795:                '<th>'.&mt('Link to resource in Construction Space').'</th>'.
                    796:                '</tr>');
                    797:     my @backgroundColors = ("#FFFFFF", "#F6F6F6");
1.84      albertel  798:     foreach (&LONCAPA::map::attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9       www       799: 	if (defined($_)) {
1.26      www       800:             $idx++;
1.62      albertel  801: 	    my ($title,$url,$cond)=split(/\:/,$_);
                    802: 	    if ($cond eq 'cond') { next; }
1.9       www       803:             $title=~s/\&colon\;/\:/g;
                    804:             $url=~s/\&colon\;/\:/g;
1.15      www       805:             unless ($title) { $title=(split(/\//,$url))[-1] };
1.64      raeburn   806:             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
1.85    ! albertel  807:             my $resurl = &LONCAPA::map::qtescape($url);
1.64      raeburn   808:             my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
                    809:             my $filename; 
                    810:             if ($resurl =~ m#/([^/]+)$#) {
                    811:                 $filename = $1;
                    812:             }
                    813:             my $cstrurl = $resurl;
                    814:             $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
                    815:             my $bgcol = $idx%2; 
                    816:             $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
                    817:                       '<img src="'.&Apache::loncommon::icon($resfilepath).
1.85    ! albertel  818:                       '" /></td><td>'.&LONCAPA::map::qtescape($title).
1.64      raeburn   819:                       '</td><td>'.$filename.'</td><td>');
                    820:             if ($url) {
1.68      www       821: 		$r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
1.64      raeburn   822:             }
                    823:             $r->print('</td><td>');
1.9       www       824:             if ($url) {
1.64      raeburn   825:                $r->print('<a href="'.$cstrurl.'">'.
                    826:                          &mt('Construction space').'</a>');
1.9       www       827:             }
1.64      raeburn   828:             $r->print('</td></tr>'."\n");
1.9       www       829:         }
                    830:     }
1.64      raeburn   831:     $r->print('</table>');
1.75      albertel  832:     $r->print(&Apache::loncommon::end_page());
1.8       www       833: }
                    834: 
1.3       www       835: # ================================================================ Main Handler
                    836: 
                    837: sub handler {
                    838:   my $r=shift;
1.47      www       839:   &Apache::loncommon::content_type($r,'text/html');
1.3       www       840:   $r->send_http_header;
                    841: 
                    842:   return OK if $r->header_only;
1.65      albertel  843:   my $target = $env{'form.grade_target'};
1.48      albertel  844:   if ($target eq 'meta') {
                    845:       &Apache::loncommon::content_type($r,'text/html');
                    846:       $r->send_http_header;
                    847:       return OK;
                    848:   }
                    849:   
1.3       www       850:   my $url=$r->uri;
                    851:   my $fn=&Apache::lonnet::filelocation('',$url);
                    852: 
1.4       www       853:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
                    854:   unless (-e $dir) {
                    855:       &nodir($r,$dir);
                    856:       return OK;
                    857:   }
1.8       www       858: 
                    859: # ------------------------------------------- Determine which tools can be used
1.3       www       860:   my $adv=0;
                    861: 
1.65      albertel  862:   unless ($env{'form.forcesmp'}) {
                    863:      if ($env{'form.forceadv'}) {
1.3       www       864:         $adv=1;
                    865:      } elsif (my $fh=Apache::File->new($fn)) {
                    866: 	 my $allmap=join('',<$fh>);
                    867:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
                    868:      }
                    869:   }
                    870: 
1.8       www       871:   my $errtext='';
                    872:   my $fatal=0;
                    873: 
                    874: # -------------------------------------------------------------------- Load map
1.84      albertel  875:   ($errtext,$fatal)=&LONCAPA::map::mapread($fn,$errtext);
1.8       www       876: 
                    877:   if ($fatal==1) { $adv=1; }
                    878: 
                    879: # ----------------------------------- adv==1 now means "graphical MUST be used"
                    880: 
1.65      albertel  881:   if ($env{'form.forceadv'}) {
1.3       www       882:       &ratedt($r,$url);
1.65      albertel  883:   } elsif ($env{'form.forcesmp'}) {
1.22      www       884:       &smpedt($r,$url,$errtext);
1.3       www       885:   } else {
1.17      www       886:       &viewmap($r,$url,$adv,$errtext);
1.3       www       887:   }
1.1       www       888:   return OK;
                    889: }
                    890: 
                    891: 1;
                    892: __END__
                    893: 
                    894: 
                    895: 
                    896: 
                    897: 
                    898: 
                    899: 

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