Annotation of rat/lonratedt.pm, revision 1.8

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Edit Handler for RAT Maps
1.5       www         3: #
1.8     ! www         4: # $Id: lonratedt.pm,v 1.7 2002/05/10 15:42:16 www 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.1       www        28: # (TeX Content Handler
                     29: #
                     30: # 05/29/00,05/30 Gerd Kortemeyer)
1.4       www        31: # 7/1,6/30 Gerd Kortemeyer
1.1       www        32: 
                     33: package Apache::lonratedt;
                     34: 
                     35: use strict;
                     36: use Apache::Constants qw(:common);
1.3       www        37: use Apache::lonnet;
1.7       www        38: use Apache::lonratsrv;
1.1       www        39: 
1.8     ! www        40: my @links=();
        !            41: my @resources=();
        !            42: 
        !            43: 
        !            44: # Mapread read maps into global arrays @links and @resources, determines status
        !            45: 
        !            46: sub mapread {
        !            47:     my $fn=shift;
        !            48: 
        !            49:     undef @links;
        !            50:     undef @resources;
        !            51: 
        !            52:     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
        !            53:     if ($errtext) { return ($errtext,2); }
        !            54: 
        !            55:     foreach (split(/\<\&\>/,$outtext)) {
        !            56: 	my ($command,$parms)=split(/\<\:\>/,$_);
        !            57:         my @item=split(/\:/,$parms);
        !            58:         if ($command eq 'objcont') {
        !            59:         }
        !            60:         if ($command eq 'objlinks') {
        !            61: 	    if (defined($links[$item[0]])) {
        !            62: 		return
        !            63:                  ('Map too complex, has branchings. Use advanced editor.',1);
        !            64:             }
        !            65: 	    if ($links[$item[2]]) {
        !            66: 		return
        !            67:                  ('Map too complex, has conditions. Use advanced editor.',1);
        !            68:             }
        !            69: 	    $links[$item[0]]=$item[1];
        !            70: 	}
        !            71: 
        !            72:     }
        !            73:     return $errtext;
        !            74: }
        !            75: 
1.3       www        76: # --------------------------------------------------------- Build up RAT screen
                     77: sub ratedt {
                     78:   my ($r,$url)=@_;
1.1       www        79:   $r->print(<<ENDDOCUMENT);
                     80: 
                     81: <html>
1.2       harris41   82: <head>
                     83: <script language="JavaScript">
                     84:     var flag=0;
                     85: </script>
                     86: </head>
1.1       www        87: <frameset rows="1,50,*" border=0>
                     88: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
                     89: <frame name=code src="/adm/rat/code.html">
                     90: <frame name=mapout src="/adm/rat/map.html">
                     91: </frameset>
                     92: </html>
                     93: 
                     94: ENDDOCUMENT
1.3       www        95: }
                     96: 
1.8     ! www        97: # ---------------------------------------------------------------- Make buttons
        !            98: 
        !            99: sub buttons {
        !           100:     my $adv=shift;
        !           101:     my $output='<form method=post>';     
        !           102:     if ($adv==1) {
        !           103: 	$output.='<input type=submit name=forceadv value="Edit">';
        !           104:     } else {
        !           105:         unless ($adv==2) {
        !           106:            $output.='<input type=submit name=forcesmp value="Simple Edit">';
        !           107:         }
        !           108: 	$output.='<input type=submit name=forceadv value="Advanced Edit">';
        !           109:     }
        !           110:     return $output.'</form><hr>';
        !           111: }
        !           112: 
1.3       www       113: sub smpedt {
1.8     ! www       114:    my ($r,$errtext)=@_;
        !           115:    my $buttons=&buttons(2);
        !           116: # ----------------------------------------------------- Start simple RAT screen
1.3       www       117:    $r->print(<<ENDSMPHEAD);
                    118: <html>
1.6       www       119: <head>
                    120: <script>
                    121: var srch;
                    122: var srchflag=-1; // 1 means currently open
                    123:                  // 0 means closed (but has been open)
                    124:                  // -1 means never yet opened/defined
                    125: var srchmode='';
                    126: 
                    127: var idx;
                    128: var idxflag=-1; // 1 means currently open
                    129:                  // 0 means closed (but has been open)
                    130:                  // -1 means never yet opened/defined
                    131: var idxmode='';
                    132: 
                    133: // ------------------------------------------------------ Clears indexer window
                    134: function idxclear() {
                    135:   idx.document.clear();
                    136: }
                    137: 
                    138: // ------------------------------------------------------- Clears search window
                    139: function srchclear() {
                    140:   srch.document.clear();
                    141: }
                    142: 
                    143: // ------------------------------------------------------ Closes indexer window
                    144: function idxclose() {
                    145:   if (idx && !idx.closed) {
                    146:     idxflag=0;
                    147:     idx.close();
                    148:   }
                    149: }
                    150: 
                    151: // ------------------------------------------------------- Closes search window
                    152: function srchclose() {
                    153:   if (srch && !srch.closed) {
                    154:     srchflag=0;
                    155:     srch.close();
                    156:   }
                    157: }
                    158: 
                    159: // -------------------------------------------------------- Open indexer window
                    160: function idxopen(mode) {
                    161:    var options="scrollbars=1,resizable=1,menubar=0";
                    162:    idxmode=mode;
                    163:    idxflag=1;
                    164:    idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
                    165:    idx.focus();
                    166: }
                    167: 
                    168: // --------------------------------------------------------- Open search window
                    169: function srchopen(mode) {
                    170:    var options="scrollbars=1,resizable=1,menubar=0";
                    171:    srchmode=mode;
                    172:    srchflag=1;
                    173:    srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
                    174:    srch.focus();
                    175: }
                    176: // ----------------------------------------------------- launch indexer browser
                    177: function groupsearch() {
                    178:    srchcheck('groupsearch');
                    179: }
                    180: 
                    181: function groupimport() {
                    182:    idxcheck('groupimport');
                    183: }
                    184: // ------------------------------------------------------- Do srch status check
                    185: function srchcheck(mode) {
                    186:    if (!srch || srch.closed || srchmode!=mode) {
                    187:       srchopen(mode);
                    188:    }
                    189:    srch.focus();
                    190: }
                    191: 
                    192: // -------------------------------------------------------- Do idx status check
                    193: function idxcheck(mode) {
                    194:    if (!idx || idx.closed || idxmode!=mode) {
                    195:       idxopen(mode);
                    196:    }
                    197:    idx.focus();
                    198: }
                    199: </script>
                    200: </head>                 
1.3       www       201: <body bgcolor='#FFFFFF'>
1.8     ! www       202: $buttons
1.7       www       203: <font color=red>$errtext</font>
1.6       www       204: <a href="javascript:groupsearch()">Group Search</a>
                    205: <a href="javascript:groupimport()">Group Import</a>
                    206: 
1.3       www       207: ENDSMPHEAD
1.8     ! www       208: 
1.3       www       209:     $r->print(
                    210:       '<input type=submit name=forcesmp value="Store"></form></body></html>');
                    211: }
                    212: 
1.4       www       213: sub nodir {
                    214:    my ($r,$dir)=@_;
                    215:    $dir=~s/^\/home\/\w+\/public\_html//;
                    216:    $r->print(<<ENDNODIR);
                    217: <html>
                    218: <body bgcolor='#FFFFFF'>
                    219: <h1>No such directory: $dir</h1>
                    220: </body>
                    221: </html>
                    222: ENDNODIR
                    223: }
                    224: 
1.8     ! www       225: # ---------------------------------------------------------------- View Handler
        !           226: 
        !           227: sub viewmap {
        !           228:     my ($r,$adv)=@_;
        !           229:     $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
        !           230: 
        !           231:     $r->print('</body></html>');
        !           232: }
        !           233: 
1.3       www       234: # ================================================================ Main Handler
                    235: 
                    236: sub handler {
                    237:   my $r=shift;
                    238:   $r->content_type('text/html');
                    239:   $r->send_http_header;
                    240: 
                    241:   return OK if $r->header_only;
                    242: 
                    243:   my $url=$r->uri;
                    244:   my $fn=&Apache::lonnet::filelocation('',$url);
                    245: 
1.4       www       246:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
                    247:   unless (-e $dir) {
                    248:       &nodir($r,$dir);
                    249:       return OK;
                    250:   }
1.8     ! www       251: 
        !           252: # ------------------------------------------- Determine which tools can be used
1.3       www       253:   my $adv=0;
                    254: 
                    255:   unless ($ENV{'form.forcesmp'}) {
                    256:      if ($ENV{'form.forceadv'}) {
                    257:         $adv=1;
                    258:      } elsif (my $fh=Apache::File->new($fn)) {
                    259: 	 my $allmap=join('',<$fh>);
                    260:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
                    261:      }
                    262:   }
                    263: 
1.8     ! www       264:   my $errtext='';
        !           265:   my $fatal=0;
        !           266: 
        !           267: # -------------------------------------------------------------------- Load map
        !           268:   ($errtext,$fatal)=&mapread($fn,$errtext);
        !           269: 
        !           270:   if ($fatal==1) { $adv=1; }
        !           271: 
        !           272: # ----------------------------------- adv==1 now means "graphical MUST be used"
        !           273: 
        !           274:   if ($ENV{'form.forceadv'}) {
1.3       www       275:       &ratedt($r,$url);
1.8     ! www       276:   } elsif ($ENV{'form.forcesmp'}) {
        !           277:       &smpedt($r,$errtext);
1.3       www       278:   } else {
1.8     ! www       279:       &viewmap($r,$adv);
1.3       www       280:   }
1.1       www       281:   return OK;
                    282: }
                    283: 
                    284: 1;
                    285: __END__
                    286: 
                    287: 
                    288: 
                    289: 
                    290: 
                    291: 
                    292: 

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