Hide
Siafoo – the intersection of pastebin, help desk, version control, and social networking Join Siafoo Now or Learn More

User Directory using SharePoint Data Zoom Extension for Active Directory Atom Feed 0

In Brief This script provides a searchable rolodex of Active Directory users. The SharePoint Data Zoom Extension for Active Directory is required.
# 's
  1## Get search inputs
2#set( $firstName = $form.get_item("firstName") )
3#set( $lastName = $form.get_item("lastName") )
4#set( $department = $form.get_item("department") )
5#set( $rolodex = $form.get_item("rolodex") )
6
7## Get paging attributes
8#set( $pageIndex = $Strings.ConvertToInt($form.get_item("pageIndex"), 0) )
9#set( $pageSize = $Strings.ConvertToInt($form.get_item("pageSize"), 15) )
10
11## Add filter terms
12#if( !$Strings.IsNullOrEmpty($rolodex) )
13
14 #if( $rolodex == "All" )
15 #set( $adFilter = "" )
16 #else
17 #set( $adFilter = "$!{adFilter}(sn=${rolodex}*)" )
18 #end
19#else
20
21 #if( !$Strings.IsNullOrEmpty($firstName) )
22 #set( $adFilter = "$!{adFilter}(givenName=*${firstName}*)" )
23 #end
24
25 #if( !$Strings.IsNullOrEmpty($lastName) )
26 #set( $adFilter = "$!{adFilter}(sn=*${lastName}*)" )
27 #end
28
29 #if( !$Strings.IsNullOrEmpty($department) )
30 #set( $adFilter = "$!{adFilter}(department=*${department}*)" )
31 #end
32#end
33
34<script>
35<!--
36
37function applySearch()
38{
39 document.getElementById("pageIndex").value = "0";
40 document.getElementById("rolodex").value = "";
41 theForm.submit();
42}
43
44function setPageSize()
45{
46 document.getElementById("pageIndex").value = "0";
47 theForm.submit();
48}
49
50function gotoPageIndex(pageIndex)
51{
52 document.getElementById("pageIndex").value = pageIndex;
53 theForm.submit();
54}
55
56function gotoRolodex(rolodex)
57{
58 document.getElementById("pageIndex").value = "0";
59 document.getElementById("rolodex").value = rolodex;
60 theForm.submit();
61}
62
63-->
64</script>
65
66<div style="padding:10px;">
67
68<span class="ms-linksectionheader"><h3 class="ms-standardheader">Search</h3></span>
69<blockquote style="margin:10px">
70
71<!-- Search area -->
72<input type="hidden" name="pageIndex" value="$!{pageIndex}" />
73<input type="hidden" name="rolodex" value="$!{rolodex}" />
74<table cellpadding="2" cellspacing="0">
75 <tr>
76 <td>First Name:</td>
77 <td>Last Name:</td>
78 <td>Department:</td>
79 </tr>
80 <tr>
81 <td><input type="text" name="firstName" value="$!{firstName}" /></td>
82 <td><input type="text" name="lastName" value="$!{lastName}" /></td>
83 <td><input type="text" name="department" value="$!{department}" /></td>
84 </tr>
85 <tr>
86 <td>
87 <a title="Find Employee" href="javascript:applySearch();">
88 <img title="Go Search" alt="Find Employee" src="/_layouts/images/gosearch.gif" style="border-width:0px;" />
89 </a>
90 </td>
91 </tr>
92</table>
93</blockquote>
94
95<span class="ms-linksectionheader"><h3 class="ms-standardheader">Rolodex</h3></span>
96<blockquote style="margin:10px">
97
98<!-- Rollidex -->
99<table cellpadding="2" cellspacing="2">
100 <tr>
101 #foreach($index in [0..10])
102 <td class="ms-vb"><a href="javascript:gotoRolodex('$index');">$index</a></td>
103 #end
104
105 #foreach($index in ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"])
106 <td class="ms-vb"><a href="javascript:gotoRolodex('$index');">$index</a></td>
107 #end
108
109 <td class="ms-vb"><a href="javascript:gotoRolodex('All');">All</a></td>
110 <tr>
111</table>
112</blockquote>
113
114
115#if($adFilter)
116
117## Setup Active Directory variables
118#set( $adProperties =["samAccountName", "givenName", "sN", "mail", "department", "manager", "telephoneNumber", "mobile"] )
119
120#set( $adPropertyTitles = ["Account Name", "First Name", "Last Name", "E-Mail", "Department", "Manager", "Phone", "Mobile"] )
121
122## Add person, user check to AD filter
123#set( $adFilter = "(&(objectClass=person)(objectClass=user)$!{adFilter})" )
124
125## Get the matching entries
126#set( $dataTable = $ActiveDirectory.GetDirectoryEntries($adFilter, $pageIndex, $pageSize, $adProperties) )
127
128## Get the result data
129#set( $firstItemNumber = $pageIndex * $pageSize + 1 )
130#set( $lastItemNumber = $firstItemNumber + $dataTable.Rows.Count - 1 )
131#set( $prevPageIndex = $pageIndex - 1 )
132#set( $nextPageIndex = $pageIndex + 1 )
133
134<!-- Toolbar -->
135<table class="ms-menutoolbar" cellpadding="5" cellspacing="0" border="0" width="100%" >
136 <tr>
137 <td class="ms-toolbar"></td>
138
139 <td width="99%" class="ms-toolbar" nowrap><IMG SRC="/_layouts/images/blank.gif" width=1 height=18 alt=""></td>
140
141 <td class="ms-toolbar" nowrap="true">
142 <table cellpadding="0" cellspacing="0" border="0">
143 <tr>
144 #if( $pageIndex > 0 )
145 <td><img src="/_layouts/images/prev.gif" border="0" alt="Previous Page" onclick="gotoPageIndex($prevPageIndex);" /></td>
146 #end
147
148 <td class="ms-listheaderlabel" nowrap>&nbsp;${firstItemNumber}-${lastItemNumber}&nbsp;</td>
149
150 #if( $dataTable.Rows.Count == $pageSize )
151 <td><img src="/_layouts/1033/images/next.gif" border="0" alt="Next Page" onclick="gotoPageIndex($nextPageIndex);" /></td>
152 #end
153 </tr>
154 </table>
155 </td>
156
157 <td class=ms-separator>|</td>
158
159 <td class="ms-toolbar" nowrap="true">Show &nbsp;&nbsp;</td>
160 <td class="ms-toolbar" nowrap="true">
161 <select name="pageSize" onchange="setPageSize();">
162 <option value="5" #if($pageSize == 5) selected #end>5</option>
163 <option value="10"#if($pageSize == 10) selected #end>10</option>
164 <option value="15"#if($pageSize == 15) selected #end>15</option>
165 <option value="50"#if($pageSize == 50) selected #end>50</option>
166 <option value="100"#if($pageSize == 100) selected #end>100</option>
167 </select>
168 </td>
169
170 <td>&nbsp;&nbsp;&nbsp;</td>
171 </tr>
172</table>
173
174<!-- Results area -->
175#foreach($dataRow in $dataTable.Rows)
176 #beforeall
177 <table class="ms-listviewtable" cellpadding="8" cellspacing="0" width="100%" border="0">
178 <tr class="ms-viewheadertr">
179 #foreach($adPropertyTitle in $adPropertyTitles )
180 <th class="ms-vh2-nofilter">$adPropertyTitle</th>
181 #end
182 </tr>
183 #odd
184 <tr class="">
185 #even
186 <tr class="ms-alternating">
187 #each
188 #foreach($adProperty in $adProperties)
189
190 #if( $adProperty == "samAccountName" )
191 <td class="ms-vb2"><a href="$serverVariables.get_item("PATH_INFO")?samAccountName=$dataRow.get_item($adProperty)">$dataRow.get_item($adProperty)</a></td>
192 #else
193 <td class="ms-vb2">$dataRow.get_item($adProperty)</td>
194 #end
195 #end
196 #after
197 </tr>
198 #afterall
199 </table>
200 #nodata
201 No rows found
202#end
203
204#end
205
206<div>

This script provides a searchable rolodex of Active Directory users. The SharePoint Data Zoom Extension for Active Directory is required.