Somewhat Off-Topic Javascript question

Stephen Lime steve.lime at dnr.state.mn.us
Thu Nov 11 09:21:51 PST 1999


I don't think you can get REMOTE_USER, but you can
use cookies to accomplish something similar. When the user logs in you could set a username cookie and retrieve it when needed.

3.3 gives you the ability to modify just about any mapserver variable via a form. So let's say you can get the username from a cookie, you could do
something like this:

<script language="javascript">
.
.
.
username = ...function to get the cookie...; 
document.mapserver.map:odbc_data:data.value = "shape_" + username;
.
.
.
</script>

in the form you'd have a hidden variable like:

<input type="hidden" name="map:odbc_data:data" value="">

The syntax map:odbc_data:data defines an object in
the mapfile. I used :'s as seperators hoping they
would work ok with javascript for just such an occasion. This is untested though.

I assume then you have some other process 
generating the user shapefiles. 

Without knowing much about the actual app this might be a case where mapscript might be real useful. That is if you could use perl to do the
ODBC/SQL queries. 

Steve 

<<< Kieran Ames <kames at erols.com> 11/11 10:43a >>>
I see in the example advanced templates that JavaScript is being used to
set/validate some of the form variables that are sent to MapServ. I'd
like to capitalize on this (if I can) by defining some layers as a
function of the user's identity.
Example:
My users have to authenticate when they connect to my server. In the cgi
world, their username is available to my Perl scripts as
"$ENV{'REMOTE_USER'}". In my case, $ENV{'REMOTE_USER'}would translate to
"kieran".

Let's say that I include in the HTML template, a form that allows the
user to kick-off a process that retreives data from an external data
source (ODBC) and that I use the shaplib utilities to create the
associated shp, shx and dbf files. I'd want to specify the username
($ENV{'REMOTE_USER'}) as part of the shape file naming conventions so
that one user wouldn't over-write the data created by another.
(In cgi/Perl, I'd say something like $filename = "shape_" .
$ENV{'REMOTE_USER'} and then create  $filename.shp, $filename.dbf . I'd
then have files like shape_kieran.shp, shape_kieran.dbf)

Issues:
1. Can JavaScript access the $ENV{'REMOTE_USER'}variable?
2. The layer I would just have created was not defined in the map file.
How could I accomplish this substitution?
The functional result I'm trying to achieve would be something like
this.....

LAYER
     NAME "ODBC_data"
     DATA shape_$ENV{'REMOTE_USER'} #This would resolve to shape_kieran
     STATUS DEFAULT
     TYPE POINT
     CLASS
          NAME "Point Results"
          COLOR 0 0 0
     END # Class
END # Layer

I might reaching for the sky with this one!
TIA for any thoughts.

Kieran

PS. I've been looking for shapelib utilities that work in an NT world.
Doug Nebert provided me with a wonderful Perl script and I got a friend
of mine to compile the shapelib c code for me. I tried out a revised
version of Doug's script with the resulting executables and got what I
needed! I still need to do some more testing, but thought I'd pass this
info on to the group.

...K





More information about the MapServer-users mailing list