-
Notifications
You must be signed in to change notification settings - Fork 1
/
Manage.ascx.cs
343 lines (282 loc) · 14.9 KB
/
Manage.ascx.cs
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security.Roles;
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace avt.Redirect
{
public partial class Manage : PortalModuleBase
{
private DotNetNuke.Framework.Providers.ProviderConfiguration _providerConfiguration = DotNetNuke.Framework.Providers.ProviderConfiguration.GetProviderConfiguration("data");
private string _connectionString;
private string _providerPath;
private string _objectQualifier;
private string _databaseOwner;
/////////////////////////////////////////////////////////////////////////////////
// EVENT HANDLERS
protected void Page_Init(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false) {
BindData();
}
}
private void BindData()
{
if (!TokenReplacer.IsMyTokensInstalled()) {
lblMyTokensRefUrl.InnerHtml = lblMyTokensParamVal.InnerHtml = lblMyTokensParam.InnerHtml = lblMyTokensRef.InnerHtml = lblMyTokens.InnerHtml = "can contain MyTokens (get it <a href = 'http://www.avatar-soft.ro/Products/MyTokens/tabid/148/Default.aspx'>here</a>)";
} else {
lblMyTokensRefUrl.InnerHtml = lblMyTokensParam.InnerHtml = lblMyTokensRef.InnerHtml = lblMyTokens.InnerHtml = "can contain MyTokens (installed)";
lblMyTokensParamVal.InnerHtml = lblMyTokens.InnerHtml = "both parameter name and value can contain MyTokens (installed)";
}
// clear form
txtUrl.Text = "";
txtUrlRef.Text = "";
cbKeepOnPage.Checked = false;
cbKeepOnPageRef.Checked = false;
cbByRoleLogout.Checked = false;
reqUrl.IsValid = true;
tbReferrer.Text = "";
txtUrlRef.Text = "";
reqUrlRef.IsValid = true;
cbUrlRefMathDomain.Checked = false;
cbKeepOnPageRef.Checked = false;
cbParamRed_Logout.Checked = false;
cbParamRed_KeepOnPage.Checked = false;
tbParamRed_Url.Text = "";
tbParamRed_Name.Text = "";
tbParamRed_Value.Text = "";
reqUrlParam.IsValid = true;
ddParamOp.ClearSelection();
ddParamOp.SelectedIndex = 0;
ddParamType.ClearSelection();
ddParamType.SelectedIndex = 0;
// bind settings
ModuleController modCtrl = new ModuleController();
try {
txtGetParam.Text = modCtrl.GetModuleSettings(ModuleId)["GetParam"].ToString();
} catch {
txtGetParam.Text = "";
}
try {
txtGetParamRefferer.Text = modCtrl.GetModuleSettings(ModuleId)["GetParamRef"].ToString();
} catch {
txtGetParamRefferer.Text = "";
}
try {
txtDefaultUrl.Text = modCtrl.GetModuleSettings(ModuleId)["DefaultUrl"].ToString();
} catch {
txtDefaultUrl.Text = "";
}
try {
cbLogout.Checked = Convert.ToBoolean(modCtrl.GetModuleSettings(ModuleId)["LogoutUser"].ToString());
} catch {
cbLogout.Checked = false;
}
// bind roles DD
ddRoles.ClearSelection();
ddRoles.Items.Clear();
RoleController roleCtrl = new RoleController();
ArrayList roles = roleCtrl.GetPortalRoles(PortalId);
// remove admin role
foreach (RoleInfo rInfo in roles) {
if (rInfo.RoleID == PortalSettings.AdministratorRoleId) {
roles.Remove(rInfo);
break;
}
}
// now, add All Users and Unregistered Users
roles.Insert(0, new RoleInfo() { RoleID = 0, RoleName = "Unregistered Users" });
roles.Insert(0, new RoleInfo() { RoleID = -1, RoleName = "All Users" });
ddRoles.DataTextField = "RoleName";
ddRoles.DataValueField = "RoleID";
ddRoles.DataSource = roles;
ddRoles.DataBind();
// bind redirects table
GetDbConfig();
sqlDataSource.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirects";
sqlDataSource.SelectParameters.Clear();
sqlDataSource.SelectParameters.Add(new Parameter() { Name = "portalId", DefaultValue = PortalId.ToString() });
sqlDataSource.SelectParameters.Add(new Parameter() { Name = "moduleId", DefaultValue = ModuleId.ToString() });
sqlDataSource.DataBind();
vwRedirects.DataBind();
// bind redirects ref table
sqlDataSourceRef.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirectsRef";
sqlDataSourceRef.SelectParameters.Clear();
sqlDataSourceRef.SelectParameters.Add(new Parameter() { Name = "moduleId", DefaultValue = ModuleId.ToString() });
sqlDataSourceRef.DataBind();
vwRedirectsRef.DataBind();
// bind redirects param table
sqlDataSourceParam.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirectsParam";
sqlDataSourceParam.SelectParameters.Clear();
sqlDataSourceParam.SelectParameters.Add(new Parameter() { Name = "moduleId", DefaultValue = ModuleId.ToString() });
sqlDataSourceParam.DataBind();
vwRedirectsParam.DataBind();
RedirectController redirCtrl = new RedirectController();
cbKeepOnPage.Attributes["onclick"] = "ValidatorEnable(document.getElementById('" + reqUrl.ClientID + "'), !this.checked);";
cbKeepOnPageRef.Attributes["onclick"] = "ValidatorEnable(document.getElementById('" + reqUrlRef.ClientID + "'), !this.checked);";
cbParamRed_KeepOnPage.Attributes["onclick"] = "ValidatorEnable(document.getElementById('" + reqUrlParam.ClientID + "'), !this.checked);";
if (Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString()))
cReferrer.InnerHtml = "Current Referrer: " + Request.UrlReferrer.ToString();
else
cReferrer.InnerHtml = "Current Referrer: <i>none</i>";
// set validation groups
txtGetParam.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
txtGetParamRefferer.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
txtDefaultUrl.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
cbLogout.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
cmdSaveSettings.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
tbParamRed_Url.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
cbParamRed_Logout.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
cmdSaveParamAddEditUrl.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
reqUrlParam.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
txtUrlRef.ValidationGroup = ModuleId.ToString() + "avtValidRedirectRef";
cmdUpdateRef.ValidationGroup = ModuleId.ToString() + "avtValidRedirectRef";
reqUrlRef.ValidationGroup = ModuleId.ToString() + "avtValidRedirectRef";
txtUrl.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
cbByRoleLogout.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
cmdUpdate.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
reqUrl.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
}
protected void OnRowCmd(Object Sender, GridViewCommandEventArgs args)
{
RedirectController redirCtrl = new RedirectController();
switch (args.CommandName) {
case "del":
redirCtrl.RemoveRedirect(Convert.ToInt32(args.CommandArgument));
break;
case "priority_up":
redirCtrl.IncreasePriority(Convert.ToInt32(args.CommandArgument));
break;
case "priority_down":
redirCtrl.DecreasePriority(Convert.ToInt32(args.CommandArgument));
break;
}
BindData();
}
protected void OnRowCmdRef(Object Sender, GridViewCommandEventArgs args)
{
RedirectController redirCtrl = new RedirectController();
switch (args.CommandName) {
case "del":
redirCtrl.RemoveRedirectRef(Convert.ToInt32(args.CommandArgument));
break;
}
BindData();
}
protected void OnRowCmdParams(Object Sender, GridViewCommandEventArgs args)
{
RedirectController redirCtrl = new RedirectController();
switch (args.CommandName) {
case "del":
redirCtrl.RemoveRedirectParam(Convert.ToInt32(args.CommandArgument));
break;
case "priority_up":
RedirectInfoParam rinc = redirCtrl.GetRedirectParamById(Convert.ToInt32(args.CommandArgument));
rinc.RedirectPriority++;
rinc.Save();
break;
case "priority_down":
RedirectInfoParam rdec = redirCtrl.GetRedirectParamById(Convert.ToInt32(args.CommandArgument));
rdec.RedirectPriority--;
rdec.Save();
break;
}
BindData();
}
protected void OnSaveAddEditUrl(Object Sender, EventArgs args)
{
//try {
RedirectController rc = new RedirectController();
int roleId = Convert.ToInt32(ddRoles.SelectedValue);
bool bAllUsers = false;
bool bUnregisteredUsers = false;
if (roleId == 0) {
bUnregisteredUsers = true;
} else if (roleId == -1) {
bAllUsers = true;
}
rc.UpdateRedirect(roleId, bAllUsers, bUnregisteredUsers, cbKeepOnPageRef.Checked ? null : txtUrl.Text.Trim(), cbByRoleLogout.Checked, ModuleId);
BindData();
//} catch (Exception) {
// lblMsg.Visible = true;
// lblMsg.InnerHtml = "Error saving redirect!";
// lblMsg.Style["background-color"] = "#FF9999";
// Page.ClientScript.RegisterStartupScript(GetType(), "timeoutSuccessMsg", "<script type='text/javascript'>setTimeout(function() { document.getElementById('" + lblMsg.ClientID + "').style.display = 'none'; }, 6000);</script>");
//}
}
protected void OnSaveRefAddEditUrl(Object Sender, EventArgs args)
{
//try {
RedirectController rc = new RedirectController();
rc.UpdateRedirectRef(tbReferrer.Text.Trim(), cbKeepOnPageRef.Checked ? null : txtUrlRef.Text.Trim(), cbUrlRefMathDomain.Checked, ModuleId);
BindData();
//} catch (Exception) {
// lblMsg.Visible = true;
// lblMsg.InnerHtml = "Error saving redirect!";
// lblMsg.Style["background-color"] = "#FF9999";
// Page.ClientScript.RegisterStartupScript(GetType(), "timeoutSuccessMsg", "<script type='text/javascript'>setTimeout(function() { document.getElementById('" + lblMsg.ClientID + "').style.display = 'none'; }, 6000);</script>");
//}
}
protected void OnSaveParamAddEditUrl(Object Sender, EventArgs args)
{
//try {
RedirectInfoParam rp = new RedirectInfoParam() {
ModuleId = ModuleId,
Param = tbParamRed_Name.Text,
ParamType = (RedirectInfoParam.eParamType)Enum.Parse(typeof(RedirectInfoParam.eParamType), ddParamType.SelectedValue, false),
Operation = (RedirectInfoParam.eOperation)Enum.Parse(typeof(RedirectInfoParam.eOperation), ddParamOp.SelectedValue, false),
Value = tbParamRed_Value.Text,
RedirectUrl = cbParamRed_KeepOnPage.Checked ? null : tbParamRed_Url.Text,
LogoutUser = cbParamRed_Logout.Checked
};
if (rp.Operation == RedirectInfoParam.eOperation.Exists || rp.Operation == RedirectInfoParam.eOperation.NotExists) {
rp.Value = ""; // unary operation
}
rp.Save();
BindData();
//} catch (Exception) {
// lblMsg.Visible = true;
// lblMsg.InnerHtml = "Error saving redirect!";
// lblMsg.Style["background-color"] = "#FF9999";
// Page.ClientScript.RegisterStartupScript(GetType(), "timeoutSuccessMsg", "<script type='text/javascript'>setTimeout(function() { document.getElementById('" + lblMsg.ClientID + "').style.display = 'none'; }, 6000);</script>");
//}
}
protected void OnSaveSettings(Object Sender, EventArgs args)
{
ModuleController modCtrl = new ModuleController();
modCtrl.UpdateModuleSetting(ModuleId, "GetParam", txtGetParam.Text.Trim());
modCtrl.UpdateModuleSetting(ModuleId, "GetParamRef", txtGetParamRefferer.Text.Trim());
modCtrl.UpdateModuleSetting(ModuleId, "DefaultUrl", txtDefaultUrl.Text.Trim());
modCtrl.UpdateModuleSetting(ModuleId, "LogoutUser", cbLogout.Checked.ToString());
}
private void GetDbConfig()
{
// Read the configuration specific information for this provider
DotNetNuke.Framework.Providers.Provider objProvider = (DotNetNuke.Framework.Providers.Provider)_providerConfiguration.Providers[_providerConfiguration.DefaultProvider];
// Read the attributes for this provider
//Get Connection string from web.config
_connectionString = DotNetNuke.Common.Utilities.Config.GetConnectionString();
if (_connectionString == "") {
// Use connection string specified in provider
_connectionString = objProvider.Attributes["connectionString"];
}
_providerPath = objProvider.Attributes["providerPath"];
_objectQualifier = objProvider.Attributes["objectQualifier"];
if (_objectQualifier != "" & _objectQualifier.EndsWith("_") == false) {
_objectQualifier += "_";
}
_databaseOwner = objProvider.Attributes["databaseOwner"];
if (_databaseOwner != "" & _databaseOwner.EndsWith(".") == false) {
_databaseOwner += ".";
}
}
protected string Tokenize(string content)
{
return TokenReplacer.Tokenize(content, ModuleConfiguration, UserInfo, false, false);
}
}
}