File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.7: download - view: text, annotated - select for diffs
Fri May 10 15:42:16 2002 UTC (21 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Reads maps now.

    1: # The LearningOnline Network with CAPA
    2: # Edit Handler for RAT Maps
    3: #
    4: # $Id: lonratedt.pm,v 1.7 2002/05/10 15:42:16 www 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: # (TeX Content Handler
   29: #
   30: # 05/29/00,05/30 Gerd Kortemeyer)
   31: # 7/1,6/30 Gerd Kortemeyer
   32: 
   33: package Apache::lonratedt;
   34: 
   35: use strict;
   36: use Apache::Constants qw(:common);
   37: use Apache::lonnet;
   38: use Apache::lonratsrv;
   39: 
   40: # --------------------------------------------------------- Build up RAT screen
   41: sub ratedt {
   42:   my ($r,$url)=@_;
   43:   $r->print(<<ENDDOCUMENT);
   44: 
   45: <html>
   46: <head>
   47: <script language="JavaScript">
   48:     var flag=0;
   49: </script>
   50: </head>
   51: <frameset rows="1,50,*" border=0>
   52: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
   53: <frame name=code src="/adm/rat/code.html">
   54: <frame name=mapout src="/adm/rat/map.html">
   55: </frameset>
   56: </html>
   57: 
   58: ENDDOCUMENT
   59: }
   60: 
   61: sub smpedt {
   62:    my ($r,$fn)=@_;
   63:    my $errtext='';
   64:    my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,$errtext);
   65:    my @loadelements=split(/\<\&\>/,$outtext);
   66:    $r->print(<<ENDSMPHEAD);
   67: <html>
   68: <head>
   69: <script>
   70: var srch;
   71: var srchflag=-1; // 1 means currently open
   72:                  // 0 means closed (but has been open)
   73:                  // -1 means never yet opened/defined
   74: var srchmode='';
   75: 
   76: var idx;
   77: var idxflag=-1; // 1 means currently open
   78:                  // 0 means closed (but has been open)
   79:                  // -1 means never yet opened/defined
   80: var idxmode='';
   81: 
   82: // ------------------------------------------------------ Clears indexer window
   83: function idxclear() {
   84:   idx.document.clear();
   85: }
   86: 
   87: // ------------------------------------------------------- Clears search window
   88: function srchclear() {
   89:   srch.document.clear();
   90: }
   91: 
   92: // ------------------------------------------------------ Closes indexer window
   93: function idxclose() {
   94:   if (idx && !idx.closed) {
   95:     idxflag=0;
   96:     idx.close();
   97:   }
   98: }
   99: 
  100: // ------------------------------------------------------- Closes search window
  101: function srchclose() {
  102:   if (srch && !srch.closed) {
  103:     srchflag=0;
  104:     srch.close();
  105:   }
  106: }
  107: 
  108: // -------------------------------------------------------- Open indexer window
  109: function idxopen(mode) {
  110:    var options="scrollbars=1,resizable=1,menubar=0";
  111:    idxmode=mode;
  112:    idxflag=1;
  113:    idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
  114:    idx.focus();
  115: }
  116: 
  117: // --------------------------------------------------------- Open search window
  118: function srchopen(mode) {
  119:    var options="scrollbars=1,resizable=1,menubar=0";
  120:    srchmode=mode;
  121:    srchflag=1;
  122:    srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
  123:    srch.focus();
  124: }
  125: // ----------------------------------------------------- launch indexer browser
  126: function groupsearch() {
  127:    srchcheck('groupsearch');
  128: }
  129: 
  130: function groupimport() {
  131:    idxcheck('groupimport');
  132: }
  133: // ------------------------------------------------------- Do srch status check
  134: function srchcheck(mode) {
  135:    if (!srch || srch.closed || srchmode!=mode) {
  136:       srchopen(mode);
  137:    }
  138:    srch.focus();
  139: }
  140: 
  141: // -------------------------------------------------------- Do idx status check
  142: function idxcheck(mode) {
  143:    if (!idx || idx.closed || idxmode!=mode) {
  144:       idxopen(mode);
  145:    }
  146:    idx.focus();
  147: }
  148: </script>
  149: </head>                 
  150: <body bgcolor='#FFFFFF'>
  151: <form method=post>
  152: <input type=submit name=forceadv 
  153: value="Advanced Map Editing - Graphical Resource Assembly Tool"><hr>
  154: <font color=red>$errtext</font>
  155: <a href="javascript:groupsearch()">Group Search</a>
  156: <a href="javascript:groupimport()">Group Import</a>
  157: 
  158: ENDSMPHEAD
  159:     $r->print('<pre>');
  160:    foreach (@loadelements) { $r->print($_."\n") }
  161: 			     $r->print('</pre>');
  162:     $r->print(
  163:       '<input type=submit name=forcesmp value="Store"></form></body></html>');
  164: }
  165: 
  166: sub nodir {
  167:    my ($r,$dir)=@_;
  168:    $dir=~s/^\/home\/\w+\/public\_html//;
  169:    $r->print(<<ENDNODIR);
  170: <html>
  171: <body bgcolor='#FFFFFF'>
  172: <h1>No such directory: $dir</h1>
  173: </body>
  174: </html>
  175: ENDNODIR
  176: }
  177: 
  178: # ================================================================ Main Handler
  179: 
  180: sub handler {
  181:   my $r=shift;
  182:   $r->content_type('text/html');
  183:   $r->send_http_header;
  184: 
  185:   return OK if $r->header_only;
  186: 
  187:   my $url=$r->uri;
  188:   my $fn=&Apache::lonnet::filelocation('',$url);
  189: 
  190:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
  191:   unless (-e $dir) {
  192:       &nodir($r,$dir);
  193:       return OK;
  194:   }
  195:   my $adv=0;
  196: 
  197:   unless ($ENV{'form.forcesmp'}) {
  198:      if ($ENV{'form.forceadv'}) {
  199:         $adv=1;
  200:      } elsif (my $fh=Apache::File->new($fn)) {
  201: 	 my $allmap=join('',<$fh>);
  202:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
  203:      }
  204:   }
  205: 
  206:   if ($adv) {
  207:       &ratedt($r,$url);
  208:   } else {
  209:       &smpedt($r,$fn);
  210:   }
  211:   return OK;
  212: }
  213: 
  214: 1;
  215: __END__
  216: 
  217: 
  218: 
  219: 
  220: 
  221: 
  222: 

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