'StyleSheet' href='/ndk/doc/samplecode/sampleui/ndk_sample.css'> 'Warning: This code has been marked up for HTML
'**************************************************************************

'  Copyright © 1998-2001 Novell, Inc.  All Rights Reserved.

'

'  THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.

'  USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT 

'  ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK.

'  PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER 

'  A ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN 

'  ITS PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET,

'  DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S PRODUCTS.

'  NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S CUSTOMERS WITH 

'  RESPECT TO THIS CODE. 

' 

' Name      : FDIR.BAS

' Description : Web based tool For Listing Directory Information

' Author   : Srivathsa 

' Date      : 12/1/2001

' Usage     : http://<server name>/nsn/fdir.bas

' History:

                                                                     
   12 01 2001   Srivathsa    First code.
   01 06 2006   Ananth       Added NDK guidelines.

'**************************************************************************



Public 'vbKeyword'>Const SCRIPT_NAME = "fdir"


' Main program

'

'vbKeyword'>Sub Main()

    LoginForm
'vbKeyword'>End Sub


' Function to build the URL for foram ACTION

'

'vbKeyword'>Function URI(scriptName, api)

   urlPrefix = Doc.urlPrefix
   'vbKeyword'>If (COMPILE) Then

      URI = urlPrefix + scriptName + ":" + api
   'vbKeyword'>Else

      URI = urlPrefix + scriptName + ".bas:" + api
   'vbKeyword'>End If

'vbKeyword'>End Function


' Form to accept Login parameters

'

'vbKeyword'>Sub LoginForm()


    Doc.Heading "FDIR v1.0"
    Doc.Format 'vbKeyword'>False

    Heading "NDS Login"
    Doc.BeginForm (URI(SCRIPT_NAME, "NDSLogin"))
    
    Doc.BeginTable 1
    Doc.BeginRow
    Doc.DataTable "User ID: ", "", "200", DOC_ALIGN_RIGHT, "", DOC_YELLOW
    Doc.BeginData "", "800", "", "", ""
    Doc.TextEntry "user", "", "", 125, 20
    Doc.EndData
    Doc.EndRow
    Doc.BeginRow
    Doc.DataTable "Password: ", "", "200", DOC_ALIGN_RIGHT, "", DOC_YELLOW
    Doc.BeginData "", "800", "", "", ""
    Doc.PasswordEntry "password", "", "", 50, 20
    Doc.EndData
    Doc.EndRow
    Doc.EndTable
    
    Doc.SubmitButton " OK "
    Doc.ResetButton "Reset"
    Doc.EndForm

'vbKeyword'>End Sub


' Entry for Login to NDS

'

'vbKeyword'>Sub NDSLogin()

    'vbKeyword'>Dim user, password

    
    user = Doc.getVar("user", "")
    password = Doc.getVar("password", "")
    success = Login(user, password)
    'vbKeyword'>If (success) Then

        FDIR
    'vbKeyword'>End If


'vbKeyword'>End Sub

' Function for logging into NDS

'

'vbKeyword'>Function Login(user, password)


    'vbKeyword'>On Error Resume Next

    'vbKeyword'>Set nwdir = CreateObject("UCX:NWDIR")

    ' set the fullname property if the objects are not in default context.

    ' OR ask the users to enter fullname 

    '

    'vbKeyword'>If (nwdir.Login(user, password)) Then

       Login = 'vbKeyword'>True

    'vbKeyword'>Else

       Doc.Print ("Login Failed:   'vbKeyword'>Error (" & Err.Number & ") " &Err.Description)

       Doc.Break
       Login = 'vbKeyword'>False

    'vbKeyword'>End If

    
'vbKeyword'>End Function


'vbKeyword'>Sub FDIR()

    dispMode = 2
    'vbKeyword'>If dispMode = 1 Then

       ShowVolume
    'vbKeyword'>End If

    
    'vbKeyword'>If dispMode = 2 Then

       ShowDirectory
    'vbKeyword'>End If


'vbKeyword'>End Sub


' Routine to display volume information

'

'vbKeyword'>Sub ShowVolume()


    Heading ("Volume information")
    'vbKeyword'>Set VolObj = CreateObject("UCX:VOLUMEMGR")

    'vbKeyword'>Set Volumes = VolObj.Volumes

    
    Doc.Break
    Doc.Print "<b>'vbKeyword'>Select a volume.</b>"

    Doc.Break
    Volumes.Reset
    'vbKeyword'>While (Volumes.hasmoreelements)

        'vbKeyword'>Set volume = Volumes.Next

        Doc.BeginLink (URI(SCRIPT_NAME, "FDIR?vol=" & volume.Name))
        Doc.Print volume.Name
        Doc.Break
        Doc.EndLink
    'vbKeyword'>Wend


'vbKeyword'>End Sub


' Routine to display directory information

'

'vbKeyword'>Sub ShowDirectory()

    'vbKeyword'>Dim Buf

    
    Buf = ""
    Path = Doc.getVar("path", "")
    
    Heading "Directory Information"
    
    Doc.BeginTag ("center")
    Doc.BeginForm (URI(SCRIPT_NAME, "ShowDirectory"))
    Doc.TextEntry "path", "", "<b><Font Size = '+1'>Enter New Path: </font></b>", 50, 20

    Doc.SubmitButton " OK "
    Doc.EndForm
    Doc.EndTag "center"
    
    'vbKeyword'>Set DirObj = CreateObject("UCX:NWFILEMGR")

    'vbKeyword'>If (Path <> "") Then

        'vbKeyword'>If DirObj.ChangeDir (Path) = False Then

             Doc.Print ("Path 'vbKeyword'>Not Found ")

           Doc.Break
           'vbKeyword'>Exit Sub

         'vbKeyword'>End If

    'vbKeyword'>End If

    
    'vbKeyword'>Set Entry = DirObj.CurrentDir

    'vbKeyword'>Set Files = Entry.getChildren("*.*")

    
    Doc.Break
    Doc.Print '<Font Size = "+1">'

    Doc.Print "<b> Directory 'vbKeyword'>for " & Entry.Name & "</b>"

    Doc.Break
    Doc.Break
    Doc.print "<table cellpadding='4' cellspacing='4'>"

    Doc.print "<tr  align='left'>"

    Doc.print "<th width='200' align='left'><Font Size = '+1'>Name</font></th>"

    Doc.print "<th width='100'align='center'><Font Size = '+1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Size</font></th>"

    Doc.print "<th width='250'align='right'><Font Size = '+1'>Last Modified</font></th>"

    Doc.print"</tr>"
    Doc.print"<tr>"
    Doc.Print "</Font>"
    Files.Reset
    'vbKeyword'>While (Files.hasmoreelements)

        'vbKeyword'>Set file = Files.Next

        'vbKeyword'>If (file.directory = False) Then

           NumberOfFiles = NumberOfFiles + 1
           SizeOfFiles = SizeOfFiles + file.Size
'      image =  "/mc-icons/unknown.gif"

   'vbKeyword'>Else

           NumberOfDir = NumberOfDir + 1
'      image =  "/mc-icons/menu.gif"

   'vbKeyword'>End If

   Doc.print "<tr>"
'   Doc.print "<td width='200' align='left'><img SRC='" &  image & "'> " &  file.name & "</td>"

   Doc.print "<td width='200' align='left'>" &  file.name & "</td>"

   Doc.print " <td width='100' align='right'>" & file.size & "</td>"

   Doc.print " <td width='250' align='right'> " &  file.modifydate & "</td>"

   Doc.print "</tr>"
   Doc.print "<tr>"

    'vbKeyword'>Wend

    Doc.print "</table>"
    Doc.Break
    Doc.Print "Total Number of Files: " & NumberOfFiles
    Doc.Break
    Doc.Print "Total Number of Directories: " & NumberOfDir
    Doc.Break
    
'vbKeyword'>End Sub


' Routine to display heading

'

'vbKeyword'>Sub Heading(Title)


    'vbKeyword'>Set server = CreateObject("UCX:SERVER")

    Doc.Print '<Font Size = "+1" Color = "#0F0FFF">'

    Doc.Print "Directory Listing Tool  v1.0"
    Doc.Break
    Doc.Print "Server Name: " & server.Name
    Doc.Break
    Doc.Print "</Font>"
    Doc.Print "<HR>"
    Doc.BeginTag "center"
    Doc.Print '<Font Size = "+1" Color = "#0F0FFF">' + Title + "</font>"

    Doc.Print
    Doc.Print "</Font>"
    Doc.EndTag "center"
    Doc.Break
'vbKeyword'>End Sub