-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLanguageReportV2.aspx
201 lines (184 loc) · 7.05 KB
/
LanguageReportV2.aspx
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<%@ Page Language="C#" AutoEventWireup="true" Debug="true" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.Globalization" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="Sitecore.Collections" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="Sitecore.Data.Managers" %>
<%@ Import Namespace="System.Data" %>
<%-- This is updated version of Language Report --%>
<%-- In this it will fetch all the desendents of the parent item --%>
<%-- It will fetch only for items having any renderings --%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Language 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:hover td {
cursor: pointer;
}
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=LanguageReport.aspx");
}
}
protected void btnGetReport_Click(object sender, EventArgs e)
{
try
{
string path = txtPath.Text;
Database db = Database.GetDatabase("master");
Item parent = db.GetItem(path);
tb = new DataTable();
LanguageCollection languages = LanguageManager.GetLanguages(db);
List<CultureInfo> cultureInfos = new List<CultureInfo>();
tb.Columns.Add("Item ID");
tb.Columns.Add("Item Path");
foreach (Language language in languages)
{
tb.Columns.Add(language.Name);
}
if (parent != null)
{
foreach (Item childItem in parent.Axes.GetDescendants())
{
if (childItem.Fields != null && childItem.Fields["__Renderings"] != null && childItem.Fields["__Renderings"].ToString() != string.Empty)
{
DataRow itemRow = tb.NewRow();
itemRow[0] = childItem.ID;
itemRow[1] = childItem.Paths.Path;
foreach (var itemLanguage in childItem.Languages)
{
var item = db.GetItem(childItem.ID, itemLanguage);
if (item.Versions.Count > 0)
{
if (tb.Columns[itemLanguage.Name] != null)
itemRow[tb.Columns[itemLanguage.Name]] = "1";
}
else
{
if (tb.Columns[itemLanguage.Name] != null)
itemRow[tb.Columns[itemLanguage.Name]] = "0";
}
}
tb.Rows.Add(itemRow);
}
}
}
lblCount.Text = "Total items: " + tb.Rows.Count.ToString();
grdLanguageReport.DataSource = tb;
grdLanguageReport.DataBind();
Session.Add("Data", tb);
}
catch (Exception ex)
{
lblCount.Text = ex.ToString();
}
}
protected void btnDownload_Click(object sender, EventArgs e)
{
try
{
string attachment = "attachment; filename=LanguageReport.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();
}
catch (Exception ex)
{
lblCount.Text = ex.ToString();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>Language Report Tool - Visit Dubai</h2>
<h4>Use this tool to check all available languages for given item.</h4>
<table>
<tr>
<td>Provide Parent Item Path:<asp:TextBox ID="txtPath" Width="700px" runat="server"></asp:TextBox></td>
<td>
<asp:Button ID="btnGetReport" runat="server" Text="Get Language Report" OnClick="btnGetReport_Click" /></td>
<td>
<asp:Button ID="btnDownload" runat="server" Text="Download Report" OnClick="btnDownload_Click" /></td>
</tr>
<tr>
<td>
<asp:Label ID="lblCount" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="grdLanguageReport" CssClass="table-style-three" runat="server"></asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>