Annotation of rat/lonratedt.pm, revision 1.9

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

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