/
ChangeTemplate.ascx.vb
executable file
·410 lines (332 loc) · 20.3 KB
/
ChangeTemplate.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
401
402
403
404
405
406
407
408
409
410
'
' Property Agent for DotNetNuke - http://www.dotnetnuke.com
' Copyright (c) 2005-2007
' by Ventrian Systems ( support@ventrian.com ) ( http://www.ventrian.com )
'
Imports System.IO
Imports System.Xml
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.UI.UserControls
Namespace Ventrian.PropertyAgent
Partial Public Class ChangeTemplate
Inherits PropertyAgentBase
#Region " Private Methods "
Private Sub BindCrumbs()
Dim crumbs As New ArrayList
Dim objCrumbMain As New CrumbInfo
objCrumbMain.Caption = PropertySettings.MainLabel
objCrumbMain.Url = NavigateURL()
crumbs.Add(objCrumbMain)
Dim objChangeTemplate As New CrumbInfo
objChangeTemplate.Caption = Localization.GetString("ChangeTemplate", LocalResourceFile)
objChangeTemplate.Url = NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=ChangeTemplate")
crumbs.Add(objChangeTemplate)
If (PropertySettings.BreadcrumbPlacement = BreadcrumbType.Portal) Then
For i As Integer = 0 To crumbs.Count - 1
Dim objCrumb As CrumbInfo = crumbs(i)
If (i > 0) Then
Dim objTab As New DotNetNuke.Entities.Tabs.TabInfo
objTab.TabID = -8888 + i
objTab.TabName = objCrumb.Caption
objTab.Url = objCrumb.Url
PortalSettings.ActiveTab.BreadCrumbs.Add(objTab)
End If
Next
End If
If (PropertySettings.BreadcrumbPlacement = BreadcrumbType.Module) Then
rptBreadCrumbs.DataSource = crumbs
rptBreadCrumbs.DataBind()
End If
End Sub
Private Sub BindTemplates()
Dim objTemplateController As New TemplateController
drpTemplate.DataSource = objTemplateController.List(Me.PortalId)
drpTemplate.DataBind()
If (drpTemplate.Items.Count <> 1) Then
drpTemplate.Items.Insert(0, _
New ListItem( _
Localization.GetString("SelectTemplateDropdown", _
Me.LocalResourceFile), "-1"))
End If
End Sub
Private Sub InitializeTemplate()
Dim objCustomFieldController As New CustomFieldController
Dim objPropertyTypeController As New PropertyTypeController
Dim objModuleController As New ModuleController
Dim objTemplateController As New TemplateController
Dim objTemplate As TemplateInfo = objTemplateController.Get(Convert.ToInt32(drpTemplate.SelectedValue))
If Not (objTemplate Is Nothing) Then
If (chkCopyFiles.Checked = False) Then
If (Me.PropertySettings.Template <> "") Then
' Delete existing
' - Delete Files in Portal Directory
Dim _
path As String = Me.PortalSettings.HomeDirectoryMapPath & "PropertyAgent\" & _
Me.ModuleId.ToString() & "\Templates\" & Me.PropertySettings.Template
If (Directory.Exists(path)) Then
Directory.Delete(path, True)
End If
' - Delete Images in Portal Directory
Dim _
images As String = Me.PortalSettings.HomeDirectoryMapPath & "PropertyAgent\" & _
Me.ModuleId.ToString() & "\Images"
If (Directory.Exists(images)) Then
Directory.Delete(images, True)
End If
' - Delete Custom Values / Properties
Dim objPropertyController As New PropertyController
objPropertyController.DeleteByModuleID(Me.ModuleId)
' - Delete Custom Fields
Dim objCustomFieldsToDelete As List(Of CustomFieldInfo) = objCustomFieldController.List(Me.ModuleId, False)
For Each objCustomFieldToDelete As CustomFieldInfo In objCustomFieldsToDelete
objCustomFieldController.Delete(objCustomFieldToDelete.CustomFieldID)
Next
' - Delete Property Types
Dim objPropertyTypesToDelete As List(Of PropertyTypeInfo) = objPropertyTypeController.List(Me.ModuleId, False)
For Each objPropertyTypeToDelete As PropertyTypeInfo In objPropertyTypesToDelete
objPropertyTypeController.Delete(Me.ModuleId, objPropertyTypeToDelete.PropertyTypeID)
Next
End If
End If
' Copy Files to Portal Directory
Dim origin As String = ApplicationMapPath & "\DesktopModules\PropertyAgent\Templates\" & objTemplate.Folder
Dim destination As String = ""
If (Me.PropertySettings.Template <> "") Then
If (chkCopyFiles.Checked) Then
destination = Me.PortalSettings.HomeDirectoryMapPath & "PropertyAgent\" & Me.ModuleId.ToString() & _
"\Templates\" & Me.PropertySettings.Template
Else
destination = Me.PortalSettings.HomeDirectoryMapPath & "PropertyAgent\" & Me.ModuleId.ToString() & _
"\Templates\" & objTemplate.Folder
End If
Else
destination = Me.PortalSettings.HomeDirectoryMapPath & "PropertyAgent\" & Me.ModuleId.ToString() & _
"\Templates\" & objTemplate.Folder
End If
CopyDirectory(origin, destination)
If (chkCopyFiles.Checked = False) Then
' Add Custom Fields
Dim doc As New XmlDocument
doc.Load( _
ApplicationMapPath & "\DesktopModules\PropertyAgent\Templates\" & objTemplate.Folder & _
"\Template.xml")
Dim nodeRoot As XmlNode = doc.DocumentElement
Dim objCustomFields As XmlNodeList = nodeRoot.SelectNodes("CustomFields")
For Each objCustomField As XmlNode In objCustomFields
For Each objCustomFieldEntry As XmlNode In objCustomField.ChildNodes
Dim objCustomFieldInfo As New CustomFieldInfo
objCustomFieldInfo.FieldElementType = FieldElementType.Standard
CBO.InitializeObject(objCustomFieldInfo, GetType(CustomFieldInfo))
objCustomFieldInfo.InheritSecurity = True
For Each objCustomFieldValue As XmlNode In objCustomFieldEntry.ChildNodes
Select Case objCustomFieldValue.Name.ToLower
Case "name"
objCustomFieldInfo.Name = objCustomFieldValue.InnerXml
Case "caption"
objCustomFieldInfo.Caption = objCustomFieldValue.InnerXml
Case "captionhelp"
objCustomFieldInfo.CaptionHelp = objCustomFieldValue.InnerXml
Case "fieldtype"
objCustomFieldInfo.FieldType = _
CType([Enum].Parse(GetType(CustomFieldType), objCustomFieldValue.InnerXml), _
CustomFieldType)
Case "fieldelementtype"
objCustomFieldInfo.FieldElementType = _
CType([Enum].Parse(GetType(FieldElementType), objCustomFieldValue.InnerXml), _
FieldElementType)
Case "fieldelements"
objCustomFieldInfo.FieldElements = objCustomFieldValue.InnerXml
Case "defaultvalue"
objCustomFieldInfo.DefaultValue = objCustomFieldValue.InnerXml
Case "length"
objCustomFieldInfo.Length = Convert.ToInt32(objCustomFieldValue.InnerXml)
Case "required"
objCustomFieldInfo.IsRequired = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "validationtype"
objCustomFieldInfo.ValidationType = _
CType( _
[Enum].Parse(GetType(CustomFieldValidationType), _
objCustomFieldValue.InnerXml), CustomFieldValidationType)
Case "regularexpression"
objCustomFieldInfo.RegularExpression = objCustomFieldValue.InnerXml
Case "searchable"
objCustomFieldInfo.IsSearchable = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "searchtype"
objCustomFieldInfo.SearchType = _
CType([Enum].Parse(GetType(SearchType), objCustomFieldValue.InnerXml), _
SearchType)
Case "fieldelementsfrom"
objCustomFieldInfo.FieldElementsFrom = objCustomFieldValue.InnerXml
Case "fieldelementsto"
objCustomFieldInfo.FieldElementsTo = objCustomFieldValue.InnerXml
Case "sortable"
objCustomFieldInfo.IsSortable = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "featured"
objCustomFieldInfo.IsFeatured = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "listing"
objCustomFieldInfo.IsInListing = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "manager"
objCustomFieldInfo.IsInManager = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "captionhidden"
objCustomFieldInfo.IsCaptionHidden = _
Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "hidden"
objCustomFieldInfo.IsHidden = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "lockdown"
objCustomFieldInfo.IsLockDown = Convert.ToBoolean(objCustomFieldValue.InnerXml)
Case "inheritsecurity"
objCustomFieldInfo.InheritSecurity = Convert.ToBoolean(objCustomFieldValue.InnerXml)
End Select
Next
objCustomFieldInfo.IsPublished = True
objCustomFieldInfo.ModuleID = Me.ModuleId
objCustomFieldInfo.IncludeCount = False
objCustomFieldInfo.HideZeroCount = False
objCustomFieldController.Add(objCustomFieldInfo)
Next
Next
Dim objSettings As XmlNodeList = nodeRoot.SelectNodes("Settings")
For Each objSetting As XmlNode In objSettings
For Each objSettingEntry As XmlNode In objSetting.ChildNodes
Dim name As String = ""
Dim value As String = ""
For Each objSettingValue As XmlNode In objSettingEntry.ChildNodes
Select Case objSettingValue.Name.ToLower
Case "name"
name = objSettingValue.InnerXml
Case "value"
value = objSettingValue.InnerXml
End Select
Next
If _
(name <> Constants.PERMISSION_APPROVE_SETTING Or _
name <> Constants.PERMISSION_AUTO_APPROVE_SETTING Or _
name <> Constants.PERMISSION_DETAIL_URL_SETTING Or _
name <> Constants.PERMISSION_SUBMIT_SETTING Or _
name <> Constants.PERMISSION_VIEW_DETAIL_SETTING Or _
name <> Constants.PERMISSION_LOCKDOWN_SETTING) Then
If (name = Constants.TEMPLATE_OLD_SETTING) Then
objModuleController.UpdateModuleSetting(Me.ModuleId, Constants.TEMPLATE_SETTING, value)
Else
objModuleController.UpdateModuleSetting(Me.ModuleId, name, value)
End If
End If
Next
Next
Dim objPropertyTypes As XmlNodeList = nodeRoot.SelectNodes("PropertyTypes")
AddPropertyTypes(objPropertyTypes, Null.NullInteger)
End If
Response.Redirect(NavigateURL(), True)
End If
End Sub
Private Sub AddPropertyTypes(ByRef objPropertyTypes As XmlNodeList, ByVal parentID As Integer)
Dim objPropertyTypeController As New PropertyTypeController
For Each objPropertyType As XmlNode In objPropertyTypes
For Each objPropertyTypeEntry As XmlNode In objPropertyType.ChildNodes
Dim name As String = ""
Dim description As String = ""
Dim sortOrder As Integer = 0
For Each objPropertyTypeValue As XmlNode In objPropertyTypeEntry.ChildNodes
Select Case objPropertyTypeValue.Name.ToLower
Case "name"
name = objPropertyTypeValue.InnerXml
Case "description"
description = objPropertyTypeValue.InnerXml
Case "sortorder"
sortOrder = Convert.ToInt32(objPropertyTypeValue.InnerXml)
End Select
Next
Dim objPropertyTypeInfo As New PropertyTypeInfo
objPropertyTypeInfo.ParentID = parentID
objPropertyTypeInfo.Name = name
objPropertyTypeInfo.Description = description
objPropertyTypeInfo.SortOrder = sortOrder
objPropertyTypeInfo.ModuleID = ModuleId
objPropertyTypeInfo.IsPublished = True
objPropertyTypeInfo.AllowProperties = True
objPropertyTypeInfo.PropertyTypeID = objPropertyTypeController.Add(objPropertyTypeInfo)
AddPropertyTypes(objPropertyTypeEntry.SelectNodes("PropertyTypes"), objPropertyTypeInfo.PropertyTypeID)
Next
Next
End Sub
Public Sub CopyDirectory(ByVal Origin As String, ByVal Destination As String)
Dim CarpetaActual As DirectoryInfo = New DirectoryInfo(Origin)
Dim Archivo As FileInfo
Dim Carpeta As DirectoryInfo
For Each Archivo In CarpetaActual.GetFiles()
If Not Directory.Exists(Destination) Then Directory.CreateDirectory(Destination)
Try
Dim path As String = IO.Path.Combine(Destination, Archivo.Name)
If (File.Exists(path)) Then
File.Delete(path)
End If
Archivo.CopyTo(path)
Catch
End Try
Next
For Each Carpeta In CarpetaActual.GetDirectories()
Dim subDirectory As String = Path.Combine(Destination, Carpeta.Name)
Try
Directory.CreateDirectory(subDirectory)
Catch
End Try
CopyDirectory(Carpeta.FullName, subDirectory)
Next
End Sub
#End Region
#Region " Event Handlers "
Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Init
Try
BindCrumbs()
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Try
If (Me.PropertySettings.Template = "") Then
CType(dshChangeTemplate, SectionHeadControl).Text = Localization.GetString("SelectTemplate", Me.LocalResourceFile)
lblChangeTemplateHelp.Text = Localization.GetString("SelectTemplateDescription", Me.LocalResourceFile)
cmdCancel.Visible = False
trCopyFiles.Visible = False
Else
CType(dshChangeTemplate, SectionHeadControl).Text = Localization.GetString("ChangeTemplate", Me.LocalResourceFile)
lblChangeTemplateHelp.Text = Localization.GetString("ChangeTemplateDescription", Me.LocalResourceFile)
End If
If (Page.IsPostBack = False) Then
If (Me.PropertySettings.Template <> "") Then
cmdInitTemplate.Attributes.Add("onClick", "javascript:return confirm('" & Localization.GetString("Confirmation", LocalResourceFile) & "');")
End If
cmdInitTemplate.ValidationGroup = "PropertyAgent-" & Me.TabModuleId
valTemplate.ValidationGroup = "PropertyAgent-" & Me.ModuleId
BindTemplates()
End If
cmdInitTemplate.CssClass = PropertySettings.ButtonClass
cmdCancel.CssClass = PropertySettings.ButtonClass
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdInitTemplate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdInitTemplate.Click
Try
If (Page.IsValid) Then
InitializeTemplate()
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdCancel.Click
Try
Response.Redirect(NavigateURL(), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
End Class
End Namespace