File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.100: download - view: text, annotated - select for diffs
Fri Aug 20 08:13:38 2010 UTC (13 years, 8 months ago) by wenzelju
Branches: MAIN
CVS tags: HEAD
Added wishlist-import in RAT.

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

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