This repository has been archived by the owner on Feb 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Templates.ascx.vb
402 lines (301 loc) · 17 KB
/
Templates.ascx.vb
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
'***********************************************************************************
' Connect UsersLibrary
'
' Copyright (C) 2013-2014 DNN-Connect Association, Philipp Becker
' http://dnn-connect.org
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; either version 2
' of the License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
'
'***********************************************************************************
Imports DotNetNuke.Entities.Modules
Imports Connect.Libraries.UserManagement
Imports DotNetNuke.Entities.Users
Imports DotNetNuke.Security.Membership
Imports Telerik.Web.UI
Imports DotNetNuke.Security.Roles
Imports DotNetNuke.Entities.Profile
Imports DotNetNuke.UI.Skins.Controls
Imports DotNetNuke.Framework.JavaScriptLibraries
Namespace Connect.Modules.UserManagement.AccountManagement
Partial Class Templates
Inherits ConnectUsersModuleBase
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
JavaScript.RequestRegistration(CommonJs.DnnPlugins)
End Sub
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
LocalizeForm()
If Not Page.IsPostBack Then
BindThemes()
If Settings.Contains("ModuleTheme") Then
Try
SelectTheme(CType(Settings("ModuleTheme"), String))
Catch
End Try
End If
BindSelectedTheme()
VerifyPasswordSettings()
End If
End Sub
Private Sub drpThemes_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpThemes.SelectedIndexChanged
BindSelectedTheme()
End Sub
Private Sub cmdUpdate_Click(sender As Object, e As System.EventArgs) Handles cmdUpdate.Click
Dim blnSucess As Boolean = False
SaveTemplates(blnSucess)
If blnSucess Then
UpdateSettings()
End If
End Sub
Private Sub cmdUpdateExit_Click(sender As Object, e As System.EventArgs) Handles cmdUpdateExit.Click
Dim blnSucess As Boolean = False
SaveTemplates(blnSucess)
If blnSucess Then
UpdateSettings()
End If
Response.Redirect(NavigateURL(TabId))
End Sub
Private Sub cmdDeleteSelected_Click(sender As Object, e As System.EventArgs) Handles cmdDeleteSelected.Click
Try
DeleteTheme()
Catch ex As Exception
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblDeleteThemeError", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
End Try
End Sub
Private Sub SelectTheme(ThemeName As String)
drpThemes.Items.FindByText(ThemeName).Selected = True
End Sub
Private Sub drpLocales_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpLocales.SelectedIndexChanged
BindSelectedTheme()
End Sub
Private Sub cmdCancel_Click(sender As Object, e As System.EventArgs) Handles cmdCancel.Click
Response.Redirect(NavigateURL())
End Sub
Private Sub VerifyPasswordSettings()
If MembershipProvider.Instance().PasswordRetrievalEnabled = False Then
Dim strNote As String = Localization.GetString("lblPasswordRetrievalDisabled", LocalResourceFile)
If MembershipProvider.Instance().RequiresQuestionAndAnswer Then
strNote += Localization.GetString("lblRequiresQuestionAndAnswer", LocalResourceFile)
End If
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, strNote, ModuleMessage.ModuleMessageType.BlueInfo)
End If
End Sub
Private Sub LocalizeForm()
cmdCancel.Text = Localization.GetString("cmdCancel", LocalResourceFile)
cmdUpdate.Text = Localization.GetString("cmdUpdate", LocalResourceFile)
cmdUpdateExit.Text = Localization.GetString("cmdUpdateExit", LocalResourceFile)
cmdCopySelected.Text = Localization.GetString("cmdCopySelected", LocalResourceFile)
cmdDeleteSelected.Text = Localization.GetString("cmdDeleteSelected", LocalResourceFile)
End Sub
Private Sub cmdCopySelected_Click(sender As Object, e As System.EventArgs) Handles cmdCopySelected.Click
pnlTemplateName.Visible = True
End Sub
Private Sub BindThemes()
drpThemes.Items.Clear()
Dim basepath As String = Server.MapPath(Me.TemplateSourceDirectory & "/templates/")
For Each folder As String In System.IO.Directory.GetDirectories(basepath)
Dim foldername As String = folder.Substring(folder.LastIndexOf("\") + 1)
drpThemes.Items.Add(New ListItem(foldername, folder))
Next
End Sub
Private Sub BindSelectedTheme()
cmdDeleteSelected.Visible = (drpThemes.SelectedIndex <> 0)
If Settings.Contains("ModuleTheme") Then
Try
If CType(Settings("ModuleTheme"), String) = drpThemes.SelectedItem.Text Then
chkUseTheme.Checked = True
DotNetNuke.UI.Utilities.ClientAPI.AddButtonConfirm(cmdDeleteSelected, Localization.GetSafeJSString(Localization.GetString("lblThemeInUse", LocalResourceFile)))
Else
chkUseTheme.Checked = False
DotNetNuke.UI.Utilities.ClientAPI.AddButtonConfirm(cmdDeleteSelected, Localization.GetSafeJSString(Localization.GetString("lblConfirmDelete", LocalResourceFile)))
End If
Catch
End Try
Else
DotNetNuke.UI.Utilities.ClientAPI.AddButtonConfirm(cmdDeleteSelected, Localization.GetSafeJSString(Localization.GetString("lblConfirmDelete", LocalResourceFile)))
chkUseTheme.Checked = False
End If
Dim path As String = drpThemes.SelectedValue
For Each file As String In System.IO.Directory.GetFiles(path)
If file.EndsWith(Constants.TemplateName_CreateForm) Then
txtCreateFormTemplate.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_CreateForm, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailAccountCreated) Then
txtEmailAccountCreated.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailAccountCreated, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailAccountData) Then
txtEmailAccountData.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailAccountData, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailAddedToRole) Then
txtEmailAddedToRole.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailAddedToRole, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailRemovedFromRole) Then
txtEmailRemovedFromRole.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailRemovedFromRole, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailRoleStatusChanged) Then
txtEmailRoleStatusChanged.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailRoleStatusChanged, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailPasswordReset) Then
txtEmailPasswordReset.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailPasswordReset, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_ProfileForm) Then
txtProfileFormTemplate.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_ProfileForm, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_AccountForm) Then
txtAccountFormTemplate.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_AccountForm, drpLocales.SelectedValue, True)
End If
Next
End Sub
Private Sub SaveTemplate(SelectedTheme As String, TemplateName As String, Locale As String)
Dim path As String = SelectedTheme & "\" & TemplateName.Replace(Constants.TemplateName_Extension, "." & Locale & Constants.TemplateName_Extension)
If (PortalSettings.DefaultLanguage.ToLower = Locale.ToLower) Or String.IsNullOrEmpty(Locale) Then
path = SelectedTheme & "\" & TemplateName
End If
Dim sw As New System.IO.StreamWriter(path, False)
If TemplateName = Constants.TemplateName_CreateForm Then
sw.Write(txtCreateFormTemplate.Text)
End If
If TemplateName = Constants.TemplateName_EmailAccountCreated Then
sw.Write(txtEmailAccountCreated.Text)
End If
If TemplateName = Constants.TemplateName_EmailAccountData Then
sw.Write(txtEmailAccountData.Text)
End If
If TemplateName = Constants.TemplateName_EmailAddedToRole Then
sw.Write(txtEmailAddedToRole.Text)
End If
If TemplateName = Constants.TemplateName_EmailRemovedFromRole Then
sw.Write(txtEmailRemovedFromRole.Text)
End If
If TemplateName = Constants.TemplateName_EmailRoleStatusChanged Then
sw.Write(txtEmailRoleStatusChanged.Text)
End If
If TemplateName = Constants.TemplateName_EmailPasswordReset Then
sw.Write(txtEmailPasswordReset.Text)
End If
If TemplateName = Constants.TemplateName_AccountForm Then
sw.Write(txtAccountFormTemplate.Text)
End If
If TemplateName = Constants.TemplateName_ProfileForm Then
sw.Write(txtProfileFormTemplate.Text)
End If
sw.Close()
sw.Dispose()
End Sub
Private Sub SaveTemplates(ByRef blnSucess As Boolean)
Dim basepath As String = drpThemes.SelectedValue
If pnlTemplateName.Visible Then
If String.IsNullOrEmpty(txtTemplateName.Text) Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblMustEnterTemplateName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End If
If String.IsNullOrEmpty(txtProfileFormTemplate.Text) Or String.IsNullOrEmpty(txtAccountFormTemplate.Text) Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblMustEnterTemplate", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End If
Dim newpath As String = Server.MapPath(Me.TemplateSourceDirectory & "/templates/") & txtTemplateName.Text
Try
System.IO.Directory.CreateDirectory(newpath)
Catch
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblInvalidFolderName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End Try
Try
For Each file As String In System.IO.Directory.GetFiles(basepath)
Dim destinationpath As String = newpath & "\" & file.Substring(file.LastIndexOf("\") + 1)
System.IO.File.Copy(file, destinationpath)
Next
basepath = newpath
Catch ex As Exception
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblCouldNotCopyTheme", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End Try
pnlTemplateName.Visible = False
BindThemes()
SelectTheme(txtTemplateName.Text)
cmdDeleteSelected.Visible = True
End If
Try
For Each file As String In System.IO.Directory.GetFiles(basepath)
If file.EndsWith(Constants.TemplateName_CreateForm) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_CreateForm, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailAccountCreated) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailAccountCreated, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailAccountData) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailAccountData, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailAddedToRole) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailAddedToRole, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailRemovedFromRole) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailRemovedFromRole, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailRoleStatusChanged) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailRoleStatusChanged, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailPasswordReset) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailPasswordReset, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_AccountForm) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_AccountForm, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_ProfileForm) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_ProfileForm, drpLocales.SelectedValue)
End If
Next
Catch ex As Exception
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblCouldNotWriteTheme", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End Try
blnSucess = True
End Sub
Private Sub UpdateSettings()
Dim ctrl As New ModuleController
ctrl.UpdateTabModuleSetting(TabModuleId, "ModuleTheme", drpThemes.SelectedItem.Text)
End Sub
Private Sub DeleteTheme()
Dim basepath As String = drpThemes.SelectedValue
For Each file As String In System.IO.Directory.GetFiles(basepath)
System.IO.File.Delete(file)
Next
System.IO.Directory.Delete(basepath)
BindThemes()
UpdateSettings()
BindSelectedTheme()
End Sub
Private Sub BindLocales()
Dim dicLocales As Dictionary(Of String, DotNetNuke.Services.Localization.Locale) = LocaleController.Instance().GetLocales(PortalId)
If dicLocales.Count > 1 Then
pnlLocales.Visible = True
End If
For Each objLocale As DotNetNuke.Services.Localization.Locale In dicLocales.Values
Dim item As New ListItem
item.Text = objLocale.Text
item.Value = objLocale.Code
Me.drpLocales.Items.Add(item)
Next
Try
drpLocales.Items(0).Selected = True
Catch
End Try
End Sub
End Class
End Namespace