home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 March
/
PCWK0397.iso
/
novell
/
webserv3
/
nws30.exe
/
DISK1
/
NETBASIC
/
WEB
/
ABSEARCH.BAS
< prev
next >
Wrap
BASIC Source File
|
1996-09-23
|
18KB
|
1,418 lines
' Add all include files and define statements here
#include "BASIC.H"
#include "BTRIEVE.H"
#include "KEY.H"
#include "HTML.H"
#include "ERRORS.H"
#include "ABOOK.H"
Sub BTX:Index:Make
Local( "KeyPos", "KeyLen","KeyFlag" )
Local( "NotUsed", "Reserved3", "XKeyType", "MKey", "ACS" )
KeyPos = LowHigh( Param(1) )
KeyLen = LowHigh( Param(2) )
KeyFlags = LowHigh( Param(3) )
NotUsed = STR:Repeat( DATA:Char(0), 4 )
XKeyType = Param( 4, DATA:Char(0) )
Reserved3 = STR:Repeat( DATA:Char(0), 3 )
MKey = Param( 5, DATA:Char(0) )
ACS = Param( 6, DATA:Char(0) )
KeySpec = KeyPos + KeyLen + KeyFlags + NotUsed + XKeyType
KeySpec = KeySpec + Reserved3 + MKey + ACS
Return( KeySpec )
End Sub
Sub BTX:Record:Make
Local( "FileSpec", "RecLen", "PageSize", "Indexes" )
Local( "Reserved4", "FileFlags", "Reserced2", "PreAlloc" )
RecLen = LowHigh( Param(1) )
PageSize = LowHigh( Param(2,1024) )
Indexes = LowHigh( Param(3,0) )
Reserved4 = STR:Repeat( DATA:Char(0), 4 )
FileFlags = LowHigh( Param(4,0))
Reserved2 = STR:Repeat( DATA:Char(0), 2 )
PreAlloc = LowHigh( Param(5,0) )
FileSpec = RecLen + PageSize + Indexes + Reserved4 + FileFlags
FileSpec = FileSpec + Reserved2 + PreAlloc
Return( FileSpec )
End Sub
Sub CreateHyperLink
Local( "BtvRec")
BtvRec = Param(1)
DOC:Print( "<IMAGE SRC=/images/sball.gif HEIGHT=10 WIDTH=10>", "<A HREF=http://", DOC:Env:Get( "SERVER_NAME" ), "/netbasic/abget.bas", "?Name=" , STR:Trim:All( BtvRec.DISTINGUISHED_NAME), "&theType=DN>", "<FONT size=+1>", STR:Trim:All( BtvRec.SURNAME ), " ", STR:Trim:All( BtvRec.GEN_QUALIFIER ), ", ", STR:Trim:All( BtvRec.GIVEN_NAME ), "</FONT></A> " , STR:Trim:All(BtvRec.TITLE), ", ", STR:Trim:All(BtvRec.DEPARTMENT) ); NewLine
Return
End Sub
Sub GetKeyNumber
If ( Param(1) = "DN" )
Return( 0 )
EndIF
If ( Param(1) = "SN" )
Return( 1 )
EndIF
If ( Param(1) = "GN" )
Return( 2 )
EndIF
If ( Param(1) = "TL" )
Return( 3 )
EndIF
If ( Param(1) = "OU" )
Return( 4 )
EndIf
If ( Param(1) = "EM" )
Return( 5 )
EndIF
If ( Param(1) = "LC" )
Return( 6 )
EndIF
Return( -1 )
End Sub
Sub GetOrgUnit
Local( "BtvRec", "OrgUnit", "OrgUnits", "DotPosition" )
BtvRec = Param(1)
' Skip the user object
DotPosition = STR:Search( ".", BtvRec.DISTINGUISHED_NAME )
If ( DotPosition )
OrgUnit = STR:Sub( BtvRec.DISTINGUISHED_NAME, DotPosition+1 )
OrgUnits = ""
Do While ( TRUE )
DotPosition = STR:Search( ".", OrgUnit )
If ( DotPosition != 0 )
OrgUnits = STR:Sub( OrgUnit, 1, DotPosition-1 )+ "/" + OrgUnits
OrgUnit = STR:Sub( OrgUnit, DotPosition+1 )
Else
Exit
EndIF
EndDO
EndIF
Return (OrgUnits)
End Sub
Sub GetRootObj
Local( "BtvRec", "RootObj", "TmpObj", "DotPosition" )
BtvRec = Param(1)
TmpObj = STR:Trim:All( BtvRec.DISTINGUISHED_NAME )
Do While ( TRUE )
DotPosition = STR:Search( ".", TmpObj )
If ( DotPosition )
TmpObj = STR:Sub( TmpObj, DotPosition+1 )
Else
Exit
EndIF
EndDO
RootObj = STR:Sub( TmpObj, 1, STR:Search( "@", TmpObj ) - 1 ) + "/"
Return (RootObj)
End Sub
Sub GetTypeLessName
'Convert the type distinguished name (DN) to the typeless distinguished name, e.g,
' CN=BOB.OU=Marketing.O=WimpleMakers.C=US is converted into
' BOB.Marketing.WimpleMakers.US
'
Local( "Name", "TypeLessName", "TypeName", "EqualPos" )
TypeName = Param(1)
TypeLessName = ""
EqualPos = STR:Search( "=", TypeName )
If ( EqualPos != 0 )
Name = STR:Sub( TypeName, EqualPos+1 )
Do While ( TRUE )
If ( STR:Search(".", Name) )
TypeLessName = TypeLessName + STR:Sub( Name, 1, STR:Search(".", Name) )
EqualPos = STR:Search( "=", Name )
If ( EqualPos != 0 )
Name = STR:Sub( Name, STR:Search( "=", Name )+1 )
Else
Name =STR:Upper(STR:Sub( Name, STR:Search( ".", Name ) ))
If ( (Name != ".OU") & (Name != ".O") & (Name != ".C" ) )
TypeLessName = TypeLessName + STR:Sub( Name, STR:Search(".", Name) + 1 )
EndIF
Exit
EndIF
Else
TypeLessName = TypeLessName + Name
Exit
EndIF
EndDO
EndIF
Return (TypeLessName)
End Sub
Sub IsMatch
Local( "ReqType","ReqName", "BtvRec" )
ReqType = Param(1)
ReqName = STR:Upper(Param(2))
BtvRec = Param(3)
If ( ReqType = "DN" )
If ( STR:Search( ReqName, STR:Upper(BtvRec.DISTINGUISHED_NAME) ) = 1 )
Return (TRUE)
EndIF
EndIF
If ( ReqType = "SN" )
If ( STR:Search( ReqName, STR:Upper(BtvRec.SURNAME) ) = 1 )
Return (TRUE)
EndIF
EndIF
If ( ReqType = "GN" )
If ( STR:Search( ReqName, STR:Upper(BtvRec.GIVEN_NAME) ) = 1 )
Return (TRUE)
EndIF
EndIF
If ( ReqType = "TL" )
If ( STR:Search( ReqName, STR:Upper(BtvRec.TITLE) ) = 1 )
Return (TRUE)
EndIF
EndIF
If ( ReqType = "EM" )
If ( STR:Search( ReqName, STR:Upper(BtvRec.EMAIL_ADDRESS) ) = 1 )
Return (TRUE)
EndIF
EndIF
If ( ReqType = "OU" )
If ( STR:Search( ReqName, STR:Upper(BtvRec.DEPARTMENT) ) = 1 )
Return (TRUE)
EndIF
EndIF
If ( ReqType = "LC" )
If ( STR:Search( ReqName, STR:Upper(BtvRec.LOCALITY_NAME) ) = 1 )
Return (TRUE)
EndIF
EndIF
Return (FALSE)
End Sub
Sub LowHigh
Local( "HI", "LO" )
' Change the integer byte order and return result as a binary string.
LO = DATA:Char( MATH:Mod( Param(1), 256 ) )
HI = DATA:Char( Param(1) / 256 )
Return( LO + HI )
End Sub
Sub Main
'Declare local variables.
Local( "FileSpec", "Buf", "PadBuf" )
Local( "Handle", "KeyBuf" , "DataBase" )
Local( "FirstRec", "BtvRec" )
Local( "VarList", "sHREF" )
Local( "KeyNumber", "RecCount" )
DOC:Heading( "Address Book" )
DOC:Print( "<BODY BACKGROUND=""/images/image1.gif"">")
DOC:Tag:Begin(DOC_TAG_CENTER)
DOC:Image( "/images/novhead1.gif", "" )
DOC:Tag:End(DOC_TAG_CENTER)
' Check if BTX.NLM is loaded. If not loaded, return an error message.
If ( !NMX:Lib:Load( "BTX" ) )
DOC:Print( "BTX.NLM was not loaded or missing." ); NewLine
DOC:Print( "Please contact your administrator for assistance." );NewLine
DOC:Form:End
Return
EndIf
' Initialize sHREF variable
sHREF = "http://" + DOC:Env:Get( "SERVER_NAME" ) + "/netbasic/abform.bas"
' Get and extract the form variables
VarList = DOC:Var()
ReqName = STR:Trim:All(VarList.Name)
ReqType = VarList.theType
If ( STR:Length(ReqName) = 0 )
DOC:Paragraph;NewLine
DOC:Print( "Record not found. Please re-enter a new search." );NewLine
DOC:Paragraph
DOC:Link:Button(sHREF, "Back to the search page" )
Return
EndIF
' If the request type is distinguished name(DN), then convert the request name to upper case.
' Also, if the type distinguished name is specified, convert it to the typeless distinguished name.
If ( ReqType = "DN" )
ReqName = STR:Upper(ReqName)
If ( STR:Search( "CN", ReqName ) )
ReqName = GetTypeLessName( ReqName )
EndIF
EndIF
' Get a key number according to the request type
KeyNumber = GetKeyNumber( ReqType )
' If key number is not valid, return an error message
If (KeyNumber < 0)
DOC:Paragraph;NewLine
DOC:Print( "Invalid search type or not supported." );NewLine
DOC:Paragraph
DOC:Link:Button(sHREF, "Back to the search page" )
Return
EndIF
' If using btrieve data manager for DOS without btrieve.nlm loaded the
' file paths must include drive letters (A:...Z:) not volumes (SYS:)
FileSpec = BTX:Record:Make( 1536, 2560, 8 )
FileSpec = FileSpec + BTX:Index:Make( KEY1POSITION, MAX_DGNAME, BTX_EXTTYPE_KEY )
FileSpec = FileSpec + BTX:Index:Make( KEY2POSITION, MAX_SURNAME, BTX_DUP+BTX_MOD+BTX_NUL+BTX_EXTTYPE_KEY+BTX_ALT )
FileSpec = FileSpec + BTX:Index:Make( KEY3POSITION, MAX_GIVEN_NAME, BTX_DUP+BTX_MOD+BTX_NUL+BTX_EXTTYPE_KEY+BTX_ALT )
FileSpec = FileSpec + BTX:Index:Make( KEY4POSITION, MAX_TITLE, BTX_DUP+BTX_MOD+BTX_NUL+BTX_EXTTYPE_KEY+BTX_ALT )
FileSpec = FileSpec + BTX:Index:Make( KEY5POSITION, MAX_DEPARTMENT, BTX_DUP+BTX_MOD+BTX_NUL+BTX_EXTTYPE_KEY+BTX_ALT )
FileSpec = FileSpec + BTX:Index:Make( KEY6POSITION, MAX_EMAIL_ADDRESS, BTX_DUP+BTX_MOD+BTX_NUL+BTX_EXTTYPE_KEY+BTX_ALT )
FileSpec = FileSpec + BTX:Index:Make( KEY7POSITION, MAX_LOCALITY_NAME, BTX_DUP+BTX_MOD+BTX_NUL+BTX_EXTTYPE_KEY+BTX_ALT )
' Get and open a btrieve database file from the configuration file.
DataBase = INI:Read( "SYS:\SYSTEM\ABOOK.CFG", "Common", "ExtractFile", "SYS:\SYSTEM\ABOOK.DBF" )
Handle = BTX:Call( "", BTX_OPEN, FileSpec, STR:Length(FileSpec), DataBase, 0 )
If ( SYS:Error:Number != 0 )
DOC:Paragraph;NewLine
DOC:Print( "Can't open database: ", DataBase );NewLine
DOC:Paragraph
DOC:Link:Button(sHREF, "Back to the search page" )
Return
EndIF
' Initialize KeyBuf and padding it with NULLs
PadBuf = STR:Repeat( chr(0),256 )
KeyBuf = ReqName+PadBuf
' Initialize FileSpec with blanks
FileSpec = STR:Repeat( " ", 2560 )
' Get the first record which greater than or equal the key specified in KeyBuf variable
Handle = BTX:Call( Handle, BTX_GET_GE, FileSpec, STR:Length(FileSpec), KeyBuf, KeyNumber )
If ( SYS:Error:Number != 0 )
Handle = BTX:Call( Handle, BTX_CLOSE, FileSpec, STR:Length(FileSpec), DataBase, 0 )
DOC:Paragraph;NewLine
DOC:Print( "<B>", ReqName, "</B> not found." ); NewLine
DOC:Paragraph
DOC:Link:Button(sHREF, "Back to the search page" )
Return
EndIF
' Retrieve and return a btrieve or personal record. If more than one record are found,
' create a HyperText link for each record.
DOC:Tag:Begin( DOC_TAG_PREFMT )
BtvRec = OBJECT:Make( "ERROR", 0 )
RecCount = 0
Do While ( TRUE )
Buf = BTX:Data:Buffer(Handle)
BtvRec = BtvRec + OBJECT:Make( "DISTINGUISHED_NAME", STR:Sub( Buf, KEY1POSITION, MAX_DGNAME ) )
BtvRec = BtvRec + OBJECT:Make( "SURNAME", STR:Sub( Buf, KEY2POSITION, MAX_SURNAME ) )
BtvRec = BtvRec + OBJECT:Make( "GIVEN_NAME", STR:Sub( Buf, KEY3POSITION, MAX_GIVEN_NAME ) )
BtvRec = BtvRec + OBJECT:Make( "TITLE", STR:Sub( Buf, KEY4POSITION, MAX_TITLE ) )
BtvRec = BtvRec + OBJECT:Make( "DEPARTMENT", STR:Sub( Buf, KEY5POSITION, MAX_DEPARTMENT ) )
BtvRec = BtvRec + OBJECT:Make( "EMAIL_ADDRESS", STR:Sub( Buf, KEY6POSITION, MAX_EMAIL_ADDRESS ) )
BtvRec = BtvRec + OBJECT:Make( "LOCALITY_NAME", STR:Sub( Buf, KEY7POSITION, MAX_LOCALITY_NAME ) )
BtvRec = BtvRec + OBJECT:Make( "PHONE_NUMBER", STR:Sub( Buf, FIELD1POSITION, MAX_PHONE_NUMBER ) )
BtvRec = BtvRec + OBJECT:Make( "FAX_NUMBER", STR:Sub( Buf, FIELD2POSITION, MAX_FAX_NUMBER ) )
BtvRec = BtvRec + OBJECT:Make( "DESCRIPTION", STR:Sub( Buf, FIELD3POSITION, MAX_DESCRIPTION ) )
BtvRec = BtvRec + OBJECT:Make( "GEN_QUALIFIER", STR:Sub( Buf, FIELD4POSITION, MAX_GQ ) )
BtvRec = BtvRec + OBJECT:Make( "DELIVERY_OFFICE", STR:Sub( Buf, FIELD5POSITION, MAX_PD_OFFICE ) )
BtvRec = BtvRec + OBJECT:Make( "POSTAL_CODE", STR:Sub( Buf, FIELD6POSITION, MAX_POSTAL_CODE ) )
BtvRec = BtvRec + OBJECT:Make( "PO_BOX", STR:Sub( Buf, FIELD7POSITION, MAX_POBOX ) )
BtvRec = BtvRec + OBJECT:Make( "STATE", STR:Sub( Buf, FIELD8POSITION, MAX_STATE ) )
BtvRec = BtvRec + OBJECT:Make( "ADDRESS", STR:Sub( Buf, FIELD9POSITION, MAX_ADDRESS) )
If ( IsMatch(ReqType, ReqName, BtvRec) )
If ( RecCount = 0 )
FirstRec = BtvRec; RecCount = RecCount+1
Else
If ( RecCount = 1 )
DOC:Print( "<FONT size=+2><B>Last Name, First Name Title, Department:</B></FONT>")
DOC:Print("<HR>")
CreateHyperLink( FirstRec )
EndIF
CreateHyperLink(BtvRec)
RecCount = RecCount + 1
EndIF
Else
Exit
EndIF
'Get the next record
BtvRec = OBJECT:Make( "ERROR", 0 )
Handle = BTX:Call( Handle, BTX_GET_NEXT, FileSpec, STR:Length(FileSpec), Keybuf, KeyNumber )
If ( SYS:Error:Number != 0 )
Exit
EndIF
EndDo
'Close btrieve database file
Handle = BTX:Call( Handle, BTX_CLOSE, FileSpec, STR:Length(FileSpec), DataBase, 0 )
If ( RecCount = 0 )
DOC:Print( "<B>", ReqName, "</B> not found." ); NewLine
EndIf
If ( RecCount = 1 )
DOC:Print( "<FONT size=+2><B>Personal Information:</B></FONT>" );NewLine
'DOC:Link:Button(sHREF, "Back to the search page" )
ReturnRec( FirstRec )
EndIF
If ( RecCount > 1 )
DOC:Paragraph
DOC:Print( "<B><FONT size=+1>Found ", RecCount, " records</FONT></B>" );NewLine
EndIF
DOC:Print( "<HR>" );NewLine
DOC:Paragraph
DOC:Link:Button(sHREF, "Back to the search page" )
DOC:Tag:End( DOC_TAG_PREFMT )
DOC:Form:End
Return
End Sub
Sub ReturnRec
Local( "BtvRec", "NDS_URL" )
Local( "UserObj", "OrgUnit", "RootObj" )
Local( "sHREF", "NDS_Tree", "DGName" )
BtvRec = Param(1)
DOC:Print("<HR>"); NewLine
UserObj = STR:Sub( BtvRec.DISTINGUISHED_NAME, 1, STR:Search( ".", STR:Trim:All(BtvRec.DISTINGUISHED_NAME ))-1 )
NDS_Tree = STR:Sub( BtvRec.DISTINGUISHED_NAME, STR:Search( "@", STR:Trim:All(BtvRec.DISTINGUISHED_NAME ))+1 )
OrgUnit = GetOrgUnit(BtvRec)
RootObj = GetRootObj(BtvRec)
NDS_URL = "/nds/"+STR:Trim:All(NDS_Tree)+"/"+RootObj+OrgUnit+UserObj
DOC:Print("<B>Name:</B> ", "<A HREF=http://", DOC:Env:Get( "SERVER_NAME" ), NDS_URL, ">", "<FONT size=+1>", STR:Trim:All(BtvRec.GIVEN_NAME), " ", STR:Trim:All(BtvRec.SURNAME), ", ", STR:Trim:All(BtvRec.GEN_QUALIFIER), "</FONT></A>" ); NewLine
DOC:Print("<B>Title:</B> ", STR:Trim:All(BtvRec.TITLE) ); NewLine
DOC:Print("<B>Dept:</B> ", STR:Trim:All(BtvRec.DEPARTMENT) ); NewLine
DOC:Print("<B>Description:</B> ", STR:Trim:All(BtvRec.DESCRIPTION) ); NewLine
DOC:Print("<B>E-Mail ID:</B> ", "<A HREF=mailto:", STR:Trim:All(BtvRec.EMAIL_ADDRESS), ">", "<FONT size=+1>", STR:Trim:All(BtvRec.EMAIL_ADDRESS), "</FONT></A>" ); NewLine
DOC:Print("<B>Phone:</B> ", STR:Trim:All(BtvRec.PHONE_NUMBER) ); NewLine
DOC:Print("<B>Fax:</B> ", STR:Trim:All(BtvRec.FAX_NUMBER) ); NewLine
DOC:Print("<B>MailStop:</B> ", STR:Trim:All(BtvRec.DELIVERY_OFFICE)); NewLine; NewLine
DOC:Paragraph
DOC:Print("<FONT size=+1>", "<B>Postal Address</B>", "</FONT>" );NewLine;
DOC:Print("<B>Street:</B> ", STR:Trim:All(BtvRec.ADDRESS) ); NewLine
DOC:Print("<B>P.O. Box:</B> ", STR:Trim:All(BtvRec.PO_BOX) ); NewLine
DOC:Print("<B>City:</B> ", STR:Trim:All(BtvRec.DELIVERY_OFFICE) ); NewLine
DOC:Print("<B>State:</B> ", STR:Trim:All(BtvRec.STATE) );NewLine
DOC:Print("<B>Postal Code:</B> ", STR:Trim:All(BtvRec.POSTAL_CODE) );NewLine
DOC:Print("<B>Locality:</B> ", STR:Trim:All(BtvRec.LOCALITY_NAME) ); NewLine
DOC:Paragraph
DOC:Print("<FONT size=+1>", "<B>Novell Directory Services</B>", "</FONT>" );NewLine;
DOC:Print("<B> Tree Name:</B> ", STR:Trim:All(NDS_Tree) ); NewLine
DGName = STR:Sub( BtvRec.DISTINGUISHED_NAME, 1, STR:Search("@", STR:Trim:All(BtvRec.DISTINGUISHED_NAME))-1 )
DOC:Print("<B>Common Name (CN):</B> ", UserObj ); NewLine
DOC:Print("<B>Distinguished Name:</B> ", DGName );NewLine
Return
End Sub