--- rat/lonratedt.pm	2001/05/01 15:23:40	1.2
+++ rat/lonratedt.pm	2001/06/30 14:05:57	1.4
@@ -3,24 +3,17 @@
 # (TeX Content Handler
 #
 # 05/29/00,05/30 Gerd Kortemeyer)
-# 7/1 Gerd Kortemeyer
+# 7/1,6/30 Gerd Kortemeyer
 
 package Apache::lonratedt;
 
 use strict;
 use Apache::Constants qw(:common);
+use Apache::lonnet;
 
-# ================================================================ Main Handler
-
-sub handler {
-  my $r=shift;
-  $r->content_type('text/html');
-  $r->send_http_header;
-
-  return OK if $r->header_only;
-
-  my $url=$r->uri;
-
+# --------------------------------------------------------- Build up RAT screen
+sub ratedt {
+  my ($r,$url)=@_;
   $r->print(<<ENDDOCUMENT);
 
 <html>
@@ -37,6 +30,66 @@ sub handler {
 </html>
 
 ENDDOCUMENT
+}
+
+sub smpedt {
+   my ($r,$fn)=@_;
+   $r->print(<<ENDSMPHEAD);
+<html>
+<body bgcolor='#FFFFFF'>
+<form method=post>
+<input type=submit name=forceadv 
+value="Advanced Map Editing - Resource Assembly Tool"><hr>
+ENDSMPHEAD
+    $r->print(
+      '<input type=submit name=forcesmp value="Store"></form></body></html>');
+}
+
+sub nodir {
+   my ($r,$dir)=@_;
+   $dir=~s/^\/home\/\w+\/public\_html//;
+   $r->print(<<ENDNODIR);
+<html>
+<body bgcolor='#FFFFFF'>
+<h1>No such directory: $dir</h1>
+</body>
+</html>
+ENDNODIR
+}
+
+# ================================================================ Main Handler
+
+sub handler {
+  my $r=shift;
+  $r->content_type('text/html');
+  $r->send_http_header;
+
+  return OK if $r->header_only;
+
+  my $url=$r->uri;
+  my $fn=&Apache::lonnet::filelocation('',$url);
+
+  my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
+  unless (-e $dir) {
+      &nodir($r,$dir);
+      return OK;
+  }
+  my $adv=0;
+
+  unless ($ENV{'form.forcesmp'}) {
+     if ($ENV{'form.forceadv'}) {
+        $adv=1;
+     } elsif (my $fh=Apache::File->new($fn)) {
+	 my $allmap=join('',<$fh>);
+         $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
+     }
+  }
+
+  if ($adv) {
+      &ratedt($r,$url);
+  } else {
+      &smpedt($r,$fn);
+  }
   return OK;
 }