-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserReport.aspx
More file actions
162 lines (151 loc) · 5.36 KB
/
Copy pathUserReport.aspx
File metadata and controls
162 lines (151 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="Sitecore.Globalization" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="Sitecore.Security.Domains" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="Sitecore.Collections" %>
<%@ Import Namespace="Sitecore.Security.Accounts" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Sitecore.Data.Fields" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>User Report</title>
<style>
body {
font-family: verdana, arial, sans-serif;
}
table.table-style-three {
font-family: verdana, arial, sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #3A3A3A;
border-collapse: collapse;
}
table.table-style-three th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #FFA6A6;
background-color: #D56A6A;
color: #ffffff;
}
table.table-style-three tr:nth-child(even) td {
background-color: #F7CFCF;
}
table.table-style-three td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #FFA6A6;
background-color: #ffffff;
}
</style>
<script language="CS" runat="server">
StringBuilder sb;
DataTable tb;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Sitecore.Context.User.IsAuthenticated == false)
{
Response.Redirect("login.aspx?returnUrl=UserReport.aspx");
}
}
protected void btnGetReport_Click(object sender, EventArgs e)
{
try
{
tb = new DataTable();
tb.Columns.Add("Name");
tb.Columns.Add("Full Name");
tb.Columns.Add("Is Admin");
tb.Columns.Add("Is Active");
tb.Columns.Add("Email");
int rowNumber = 0;
IEnumerable<User> allUsers = Domain.GetDomain("sitecore").GetUsers().OrderByDescending(x=>x.IsAdministrator==true);
foreach (User user in allUsers)
{
rowNumber++;
DataRow itemRow = tb.NewRow();
itemRow["Name"] = user.Name;
itemRow["Full Name"] = user.Profile.FullName;
itemRow["Is Admin"] = user.IsAdministrator;
itemRow["Is Active"] = user.Profile.State;
itemRow["Email"] = user.Profile.Email;
tb.Rows.Add(itemRow);
}
lblCount.Text = "Total users: " + tb.Rows.Count.ToString();
grdLanguageReport.DataSource = tb;
grdLanguageReport.DataBind();
Session.Add("Data", tb);
}
catch (Exception ex)
{
lblCount.Text = ex.ToString();
}
}
protected void ExportToExcel(object sender, EventArgs e)
{
string attachment = "attachment; filename=Report.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
tb = (DataTable)Session["Data"];
foreach (DataColumn dc in tb.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in tb.Rows)
{
tab = "";
for (i = 0; i < tb.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>User Report - Visit Dubai</h2>
<table>
<tr>
<td>
<asp:Button ID="btnGetReport" Text="Get Users" runat="server" OnClick="btnGetReport_Click" />
<asp:Button ID="btnDownload" runat="server" Text="Download Report" OnClick="ExportToExcel" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCount" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="4">
<asp:GridView ID="grdLanguageReport" CssClass="table-style-three" runat="server"></asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>