File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.112: download - view: text, annotated - select for diffs
Fri Jan 15 19:13:04 2016 UTC (8 years, 3 months ago) by damieng
Branches: MAIN
CVS tags: version_2_12_X, HEAD
fixed layout issues in advanced RAT, replaced frameset by iframes

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

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