forked from DNNCommunity/DNN.Events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventEditLocations.ascx.cs
424 lines (373 loc) · 15.8 KB
/
EventEditLocations.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Web.UI.WebControls;
using DNNtc;
using Components;
using DotNetNuke.Common;
using DotNetNuke.Common.Lists;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
namespace DotNetNuke.Modules.Events
{
[DNNtc.ModuleControlProperties("Locations", "Edit Event Locations", DNNtc.ControlType.View, "https://github.com/DNNCommunity/DNN.Events/wiki", true, true)]
public partial class EventEditLocations : EventBase
{
#region Event Handlers
private void Page_Load(object sender, EventArgs e)
{
LocalizeAll();
if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) || IsLocationEditor())
{ }
else
{
Response.Redirect(GetSocialNavigateUrl(), true);
}
// Set the selected theme
SetTheme(pnlEventsModuleLocations);
if (!Page.IsPostBack)
{
BindData();
BindCountry();
BindRegion();
}
}
#endregion
#region Web Form Designer Generated Code
//This call is required by the Web Form Designer.
[DebuggerStepThrough]
private void InitializeComponent()
{ }
private void Page_Init(object sender, EventArgs e)
{
//CODEGEN: This method call is required by the Web Form Designer
//Do not modify it using the code editor.
InitializeComponent();
//Add the external Validation.js to the Page
const string csname = "ExtValidationScriptFile";
var cstype = MethodBase.GetCurrentMethod().GetType();
var cstext = "<script src=\"" + ResolveUrl("~/DesktopModules/Events/Scripts/Validation.js") +
"\" type=\"text/javascript\"></script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered(csname))
{
Page.ClientScript.RegisterClientScriptBlock(cstype, csname, cstext, false);
}
}
#endregion
#region Private Area
private readonly EventLocationController _objCtlLocation = new EventLocationController();
private EventLocationInfo _objLocation = new EventLocationInfo();
private ArrayList _colLocations;
#endregion
#region Helper Routines
private void LocalizeAll()
{
GrdLocations.Columns[3].HeaderText = Localization.GetString("plLocationName", LocalResourceFile);
GrdLocations.Columns[4].HeaderText = Localization.GetString("plMapURL", LocalResourceFile);
}
private void BindData()
{
//Grid
var i = 0;
_colLocations = _objCtlLocation.EventsLocationList(PortalId);
GrdLocations.DataSource = _colLocations;
GrdLocations.DataBind();
if (GrdLocations.Items.Count > 0)
{
GrdLocations.Visible = true;
for (i = 0; i <= GrdLocations.Items.Count - 1; i++)
{
((ImageButton) GrdLocations.Items[i].FindControl("DeleteButton")).Attributes.Add(
"onclick",
"javascript:return confirm('" +
Localization.GetString(
"AreYouSureYouWishToDelete.Text",
LocalResourceFile) +
"');");
}
}
}
private void BindCountry()
{
var ctlEntry = new ListController();
var entryCollection = ctlEntry.GetListEntryInfoItems("Country");
cboCountry.DataSource = entryCollection;
cboCountry.DataBind();
cboCountry.Items.Insert(
0,
new ListItem("<" + Localization.GetString("Not_Specified", Localization.SharedResourceFile) + ">",
""));
if (!Page.IsPostBack)
{
cboCountry.SelectedIndex = 0;
}
}
private void BindRegion()
{
var ctlEntry = new ListController();
var countryCode = Convert.ToString(cboCountry.SelectedItem.Value);
var listKey = "Country." + countryCode; // listKey in format "Country.US:Region"
var entryCollection = ctlEntry.GetListEntryInfoItems("Region", listKey);
if (entryCollection.Any())
{
txtRegion.Visible = false;
cboRegion.Visible = true;
cboRegion.Items.Clear();
cboRegion.DataSource = entryCollection;
cboRegion.DataBind();
cboRegion.Items.Insert(
0,
new ListItem(
"<" + Localization.GetString("Not_Specified", Localization.SharedResourceFile) + ">", ""));
if (countryCode.ToLower() == "us")
{
lblRegionCap.Text = Localization.GetString("plState.Text", LocalResourceFile);
lblRegionCap.HelpText = Localization.GetString("plState.Help", LocalResourceFile);
lblPostalCodeCap.Text = Localization.GetString("plZipCode.Text", LocalResourceFile);
lblPostalCodeCap.HelpText = Localization.GetString("plZipCode.Help", LocalResourceFile);
}
else
{
lblRegionCap.Text = Localization.GetString("plRegion.Text", LocalResourceFile);
lblRegionCap.HelpText = Localization.GetString("plRegion.Help", LocalResourceFile);
lblPostalCodeCap.Text = Localization.GetString("plPostalCode.Text", LocalResourceFile);
lblPostalCodeCap.HelpText =
Localization.GetString("plPostalCode.Help", LocalResourceFile);
}
}
else
{
txtRegion.Visible = true;
cboRegion.Visible = false;
lblRegionCap.Text = Localization.GetString("plRegion.Text", LocalResourceFile);
lblRegionCap.HelpText = Localization.GetString("plRegion.Help", LocalResourceFile);
lblPostalCodeCap.Text = Localization.GetString("plPostalCode.Text", LocalResourceFile);
lblPostalCodeCap.HelpText = Localization.GetString("plPostalCode.Help", LocalResourceFile);
}
}
private string PutHTTPInFront(string myURL)
{
if (myURL.ToLower().StartsWith("http://") || myURL.ToLower().StartsWith("https://"))
{
return myURL;
}
if (myURL.Trim() == string.Empty)
{
return "";
}
return Globals.AddHTTP(myURL);
}
protected void cmdUpdate_Click(object sender, EventArgs e)
{
try
{
SaveLocation(Convert.ToInt32(ViewState["Location"]));
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
BindData();
}
public void cmdAdd_Click(object sender, EventArgs e)
{
try
{
SaveLocation(0);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
BindData();
}
private void SaveLocation(int locationID)
{
// Only Update if the Entered Data is Valid
if (Page.IsValid && !string.IsNullOrEmpty(txtLocationName.Text))
{
var objLocation = new EventLocationInfo();
var objSecurity = new PortalSecurity();
var locationName = "";
var mapURL = "";
var street = "";
var postalCode = "";
var city = "";
string region = null;
string country = null;
// Filter text for non-admins
if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName))
{
locationName = txtLocationName.Text;
mapURL = PutHTTPInFront(txtMapURL.Text);
street = txtStreet.Text;
postalCode = txtPostalCode.Text;
city = txtCity.Text;
if (cboRegion.SelectedIndex > 0)
{
region = cboRegion.SelectedItem.Text;
}
else
{
region = txtRegion.Text;
}
if (cboCountry.SelectedIndex > 0)
{
country = Convert.ToString(cboCountry.SelectedItem.Text);
}
}
else
{
locationName =
objSecurity.InputFilter(txtLocationName.Text, PortalSecurity.FilterFlag.NoScripting);
mapURL = objSecurity.InputFilter(PutHTTPInFront(txtMapURL.Text),
PortalSecurity.FilterFlag.NoScripting);
street = objSecurity.InputFilter(txtStreet.Text, PortalSecurity.FilterFlag.NoScripting);
postalCode =
objSecurity.InputFilter(txtPostalCode.Text, PortalSecurity.FilterFlag.NoScripting);
city = objSecurity.InputFilter(txtCity.Text, PortalSecurity.FilterFlag.NoScripting);
if (cboRegion.SelectedIndex > 0)
{
region = objSecurity.InputFilter(cboRegion.SelectedItem.Text,
PortalSecurity.FilterFlag.NoScripting);
}
else
{
region = objSecurity.InputFilter(txtRegion.Text, PortalSecurity.FilterFlag.NoScripting);
}
if (cboCountry.SelectedIndex > 0)
{
country = objSecurity.InputFilter(Convert.ToString(cboCountry.SelectedItem.Text),
PortalSecurity.FilterFlag.NoScripting);
}
}
//bind text values to object
objLocation.Location = locationID;
objLocation.PortalID = PortalId;
objLocation.LocationName = locationName;
objLocation.MapURL = mapURL;
objLocation.Street = street;
objLocation.PostalCode = postalCode;
objLocation.City = city;
objLocation.Region = region;
objLocation.Country = country;
_objCtlLocation.EventsLocationSave(objLocation);
//Back to normal (add) mode
txtLocationName.Text = "";
txtMapURL.Text = "";
txtStreet.Text = "";
txtPostalCode.Text = "";
txtCity.Text = "";
txtRegion.Text = "";
cboRegion.ClearSelection();
cboCountry.ClearSelection();
ViewState.Remove("Location");
cmdUpdate.Visible = false;
}
}
protected void OnCountryIndexChanged(object sender, EventArgs e)
{
try
{
BindRegion();
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
#endregion
#region Control Events
public void GrdLocations_DeleteCommand(object source, DataGridCommandEventArgs e)
{
var location = 0;
location = Convert.ToInt32(GrdLocations.DataKeys[e.Item.ItemIndex]);
_objCtlLocation.EventsLocationDelete(location, PortalId);
BindData();
//Back to normal (add) mode
txtLocationName.Text = "";
txtMapURL.Text = "";
txtStreet.Text = "";
txtPostalCode.Text = "";
txtCity.Text = "";
txtRegion.Text = "";
cboRegion.ClearSelection();
cboCountry.ClearSelection();
ViewState.Remove("Location");
cmdUpdate.Visible = false;
}
public void GrdLocations_ItemCommand(object source, DataGridCommandEventArgs e)
{
switch (e.CommandName)
{
case "Select":
int location = Convert.ToInt16(GrdLocations.DataKeys[e.Item.ItemIndex]);
_objLocation = _objCtlLocation.EventsLocationGet(location, PortalId);
// Clear selections.
cboCountry.ClearSelection();
cboRegion.ClearSelection();
txtRegion.Text = string.Empty;
// Fill fields.
txtLocationName.Text = _objLocation.LocationName;
txtMapURL.Text = _objLocation.MapURL;
txtStreet.Text = _objLocation.Street;
txtPostalCode.Text = _objLocation.PostalCode;
txtCity.Text = _objLocation.City;
if (cboCountry.Items.FindByText(_objLocation.Country) != null)
{
cboCountry.Items.FindByText(_objLocation.Country).Selected = true;
}
BindRegion();
if (cboRegion.Items.FindByText(_objLocation.Region) != null)
{
cboRegion.Items.FindByText(_objLocation.Region).Selected = true;
}
else
{
txtRegion.Text = _objLocation.Region;
}
ViewState.Add("Location", _objLocation.Location.ToString());
BindData();
//We can update
cmdUpdate.Visible = true;
break;
}
}
protected void returnButton_Click(object sender, EventArgs e)
{
try
{
Response.Redirect(GetSocialNavigateUrl(), true);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
#endregion
}
}