home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / ASP / WAB / search.asp < prev    next >
Encoding:
Text File  |  1999-03-11  |  4.9 KB  |  148 lines

  1. <html>
  2.  
  3. <head>
  4. <meta name="GENERATOR" content="Microsoft FrontPage 3.0">
  5. <title>Searching in the Active Directory</title>
  6. </head>
  7.  
  8. <body>
  9. <%
  10.   ADsDomain = Session("ADsDomain")
  11.   'Session may time out
  12.   If ADsDomain = "" then
  13.     ADsDomain = Application("ADsDomain")
  14.   End if
  15.  
  16.   userName = Request.Form("userName")
  17.   Set con = CreateObject("ADODB.Connection")
  18.   Set com =   CreateObject("ADODB.Command")
  19.   domainPath = "LDAP://" & ADsDomain
  20.     
  21.   'Open the ADSI Connection.
  22.   con.Provider = "ADsDSOObject"
  23.  
  24.   'Credentials  
  25.    con.Properties("User ID") = Application("UserID")
  26.    con.Properties("Password") = Application("Password")
  27.  
  28.  
  29.  
  30.  
  31.    con.Open "Active Directory Provider"
  32.    Set Com.ActiveConnection = con
  33.  
  34.    
  35.    Com.CommandText = "<" & domainPath & ">;(&(anr=" & userName & ")(|(objectCategory=organizationalPerson)(objectCategory=group)));ADsPath,name,telephoneNumber,title,physicalDeliveryOfficeName,department,objectCategory;subtree"
  36.   
  37.  
  38.    Com.Properties("Page Size") = 64
  39.    Com.Properties("Timeout") = 30 'seconds
  40.    Com.Properties("Cache Results") = False
  41.    
  42.       
  43.  
  44. %>
  45.  
  46. <p><img src="banner.gif" width="232" height="52" alt="banner.gif (3494 bytes)">
  47.         <a href="default.asp"><img src="search.gif"
  48. width="39" height="39" alt="search.gif (1222 bytes)" border="0"></a></p>
  49.  
  50. <p><strong><small><font face="Verdana" color="#0080C0">Search for:  </font><font
  51. face="Verdana" color="#800080"> </font><font face="Verdana" color="#8080C0"><% Response.Write userName%></font><font
  52. face="Verdana" color="#0080C0">     </font></small></strong></p>
  53. <%
  54.   
  55.    '--- TIME BEGIN
  56.    t = Timer
  57.    Set rs = Com.Execute
  58.    elapse = Timer - t
  59.    '--- TIME END
  60.    On Error Resume Next 
  61.    counter = 0
  62. %>
  63.  
  64. <table border="0" width="814" cellpadding="1" cellspacing="1">
  65.   <tr>
  66.     <td width="395" bgcolor="#000080"><p align="center"><font face="Verdana" color="#FFFFFF"><small><strong>Name</strong></small></font></td>
  67.     <td width="178" bgcolor="#000080"><small><p align="center"><font face="Verdana"
  68.     color="#FFFFFF"><strong>Phone</strong></font></small></td>
  69.     <td width="286" bgcolor="#000080"><font face="Verdana" color="#FFFFFF"><small><strong><p
  70.     align="center">Title</strong></small></font></td>
  71.     <td width="286" bgcolor="#000080"><small><p align="center"><font face="Verdana"
  72.     color="#FFFFFF"><strong>Office</strong></font></small></td>
  73.     <td width="371" bgcolor="#000080"><font face="Verdana" color="#FFFFFF"><small><strong><p
  74.     align="center">Department</strong></small></font></td>
  75.   </tr>
  76. <% While Not rs.EOF %>
  77.   <tr>
  78.     <td width="395"><% 
  79.      'Increment the counter 
  80.      counter = counter + 1 
  81.      'Alternate background color for enhancing the appearance 
  82.       md = counter mod 2 
  83.       if ( md = 0 ) then 
  84.          bkColor = "#C9C9C9"
  85.       else
  86.          bkColor = "#E8E8E8"
  87.       end if 
  88.  
  89.       '-- Find the object category
  90.       sCat = rs.Fields("objectCategory").Value
  91.       idx = InStr( 1, sCat, "=Person" )
  92.       if ( idx > 0 ) then
  93.           bPerson = True
  94.       else
  95.           bPerson = False
  96.       end if 
  97.    %>
  98. </td>
  99.   </tr>
  100.   <tr>
  101.     <td width="395" bgcolor="<%Response.Write bkColor%>"><a
  102.     href="<% if bPerson then                Response.Write "person.asp?anr="              else               Response.Write "group.asp?anr="             end if            %> <%Response.Write rs.Fields("AdsPath")%>"><small><font
  103.     face="Verdana"><% Response.Write rs.Fields("Name").Value %></font></small></td>
  104.     <td width="178" bgcolor="<%Response.Write bkColor%>"><small><font face="Verdana"><small><% if ( bPerson )then Response.Write rs.Fields("telephoneNumber").Value else Response.Write "(Group)" end if %></small></font></small></td>
  105.     <td width="286" bgcolor="<%Response.Write bkColor%>"><small><small><font face="Verdana"><% Response.Write rs.Fields("title").Value %></font></small></small></td>
  106.     <td width="286" bgcolor="<%Response.Write bkColor%>"><small><small><font face="Verdana"><% Response.Write rs.Fields("physicalDeliveryOfficeName").Value %></font></small></small></td>
  107.     <td width="371" bgcolor="<%Response.Write bkColor%>"><small><small><font face="Verdana"><% Response.Write rs.Fields("department").Value %></font></small></small></td>
  108.   </tr>
  109. <% 
  110.      rs.MoveNext
  111.      Wend
  112.   %>
  113. </table>
  114. <small><font face="Verdana"><%
  115.   if ( counter > 0 ) then
  116.     Response.Write counter & " object(s) found"
  117.   else
  118.     Response.Write "No object is found"
  119.   end if 
  120.   Set con = nothing
  121.   Set com = nothing
  122. %>
  123.  
  124. </font></small></a>
  125.  
  126.  
  127. <p></p>
  128. <p></p>
  129.  
  130.  
  131.  
  132. <small><small><font face="Verdana">
  133. <%
  134.   Response.Write "Query was executed in: " & elapse & " second(s)"
  135.   Response.Write "<br>"
  136.   elapse = Timer - t
  137.   Response.Write "Total Time (Execute, Enumeration and Rendering): " & elapse & " second(s)"
  138. %>
  139.  
  140. </font></small></small>
  141.  
  142.  
  143.  
  144.  
  145.  
  146. </body>
  147. </html>
  148.