-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.ascx.cs
More file actions
339 lines (286 loc) · 17.1 KB
/
View.ascx.cs
File metadata and controls
339 lines (286 loc) · 17.1 KB
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
// --- Copyright (c) notice NevoWeb ---
// Copyright (c) 2015 SARL Nevoweb. www.Nevoweb.com. The MIT License (MIT).
// Author: D.C.Lee
// ------------------------------------------------------------------------
// 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.
// ------------------------------------------------------------------------
// This copyright notice may NOT be removed, obscured or modified without written consent from the author.
// --- End copyright notice ---
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Exceptions;
using NBrightCore.common;
using NBrightCore.render;
using NBrightDNN;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security;
using DotNetNuke.Services.Localization;
using NBrightMod.common;
using System.Web.UI;
namespace Nevoweb.DNN.NBrightMod
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The ViewNBrightGen class displays the content
/// </summary>
/// -----------------------------------------------------------------------------
public partial class View : Base.NBrightModBase, IActionable
{
private bool _versionRecordExist = false;
#region Event Handlers
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// check for version records
if (Request.IsAuthenticated && (LocalUtils.VersionUserCanValidate(ModuleId) || LocalUtils.VersionUserMustCreateVersion(ModuleId)))
{
_versionRecordExist = LocalUtils.HasVersion(ModuleId);
}
LocalUtils.IncludePageHeaders(base.ModuleId.ToString(""), this.Page, "NBrightMod","view");
}
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
if (Page.IsPostBack == false)
{
// check we have settings
var settings = LocalUtils.GetSettings(ModuleId.ToString());
if (settings.ModuleId == 0 || settings.GetXmlProperty("genxml/dropdownlist/themefolder") == "")
{
var lit = new Literal();
var rtnValue = Localization.GetString("notheme", "/DesktopModules/NBright/NBrightMod/App_LocalResources/View.ascx.resx", PortalSettings.Current, Utils.GetCurrentCulture(), true);
lit.Text = rtnValue;
phData.Controls.Add(lit);
}
else
{
PageLoad();
}
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void PageLoad()
{
var objCtrl = new NBrightDataController();
var settings = LocalUtils.GetSettings(ModuleId.ToString());
var activatedetail = settings.GetXmlPropertyBool("genxml/checkbox/activatedetail");
var debug = settings.GetXmlPropertyBool("genxml/checkbox/debugmode");
// check for detail page display
var displayview = "view.cshtml";
var eid = Utils.RequestQueryStringParam(Request, "eid");
// check for detail page display
if (Utils.IsNumeric(eid) && activatedetail)
{
var info = objCtrl.Get(Convert.ToInt32(eid), Utils.GetCurrentCulture());
var pagename = info.GetXmlProperty("genxml/lang/genxml/textbox/pagename");
if (pagename == "") pagename = info.GetXmlProperty("genxml/textbox/pagename");
if (pagename == "") pagename = info.GetXmlProperty("genxml/lang/genxml/textbox/title");
if (pagename == "") pagename = info.GetXmlProperty("genxml/textbox/title");
var pagetitle = info.GetXmlProperty("genxml/lang/genxml/textbox/pagetitle");
if (pagetitle == "") pagetitle = info.GetXmlProperty("genxml/textbox/pagetitle");
if (pagetitle == "") pagetitle = info.GetXmlProperty("genxml/lang/genxml/textbox/title");
if (pagetitle == "") pagetitle = info.GetXmlProperty("genxml/textbox/title");
var pagekeywords = info.GetXmlProperty("genxml/lang/genxml/textbox/pagekeywords");
var pagedescription = info.GetXmlProperty("genxml/lang/genxml/textbox/pagedescription");
DotNetNuke.Framework.CDefault tp = (DotNetNuke.Framework.CDefault)this.Page;
if (pagetitle != "") tp.Title = pagetitle;
if (pagedescription != "") tp.Description = pagedescription;
if (pagekeywords != "") tp.KeyWords = pagekeywords;
if (info.GetXmlProperty("genxml/imgs/genxml[1]/hidden/imageurl") != "")
{
tp.Header.Controls.Add(new LiteralControl(String.Format("<meta id=\"ogimage\" property=\"og:image\" content=\"{0}\" />", "https://" + DnnUtils.GetCurrentPortalSettings().DefaultPortalAlias.TrimEnd('/') + "/" + info.GetXmlProperty("genxml/imgs/genxml[1]/hidden/imageurl").TrimStart('/'))));
}
displayview = "viewdetail.cshtml";
}
else
{
eid = ""; // clear for cache key
}
var strOut = "";
var cacheKey = "nbrightmodview-" + PortalSettings.Current.PortalId + "-" + ModuleId + "-" + Utils.GetCurrentCulture() + "-" + eid;
var razorCacheKey = settings.GetXmlProperty("genxml/dropdownlist/themefolder") + Utils.GetCurrentCulture();
if (LocalUtils.VersionUserCanValidate(ModuleId) || LocalUtils.VersionUserMustCreateVersion(ModuleId))
{
// add userid for users with version rights.
cacheKey += "-" + UserId;
razorCacheKey += "-" + UserId;
}
// Set cache using ecomode cookie.
var ecomode = "off";
var ecomodeCookie = HttpContext.Current.Request.Cookies["ecomode"];
if (ecomodeCookie != null) ecomode = ecomodeCookie.Value;
cacheKey += ecomode;
if (!debug) strOut = (String)LocalUtils.GetRazorCache(cacheKey, ModuleId.ToString());
var hasEditAccess = false;
if (UserId > 0) hasEditAccess = DotNetNuke.Security.Permissions.ModulePermissionController.CanEditModuleContent(this.ModuleConfiguration);
if (hasEditAccess) strOut = ""; // don;t use cache in edit mode.
if (String.IsNullOrWhiteSpace(strOut)) // check if we already have razor cache
{
// preprocess razor template to get meta data for data select into cache.
var cachedlist = LocalUtils.RazorPreProcessTempl(displayview, ModuleId.ToString(""), Utils.GetCurrentCulture());
var orderby = "";
if (cachedlist != null && cachedlist.ContainsKey("orderby")) orderby = cachedlist["orderby"];
var filter = "";
if (cachedlist != null && cachedlist.ContainsKey("filter")) filter = cachedlist["filter"];
if (Utils.IsNumeric(eid) && activatedetail)
{
filter = " and NB1.ItemId = '" + eid + "'";
}
// get source moduleid
var sourcemodid = Convert.ToInt32(ModuleId);
if (settings.GUIDKey != settings.GetXmlProperty("genxml/dropdownlist/datasourceref") && settings.GetXmlProperty("genxml/dropdownlist/datasourceref") != "")
{
var sourcesettings = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SETTINGS", settings.GetXmlProperty("genxml/dropdownlist/datasourceref"));
if (sourcesettings == null)
{
// source module may have been removed. so reset it.
settings.SetXmlProperty("genxml/dropdownlist/datasourceref", "");
LocalUtils.UpdateSettings(settings);
}
else
{
sourcemodid = sourcesettings.ModuleId;
}
}
// get data list
var returnLimit = settings.GetXmlPropertyInt("genxml/textbox/returnlimit");
var pageSize = settings.GetXmlPropertyInt("genxml/textbox/pagesize");
var pgnum = Utils.RequestQueryStringParam(Request, "pgnum");
var pageNumber = 0;
if (Utils.IsNumeric(pgnum)) pageNumber = Convert.ToInt32(pgnum);
var l = objCtrl.GetList(PortalSettings.Current.PortalId, sourcemodid, "NBrightModDATA", filter, orderby, returnLimit, pageNumber, pageSize, 0, Utils.GetCurrentCulture());
//if (Request.IsAuthenticated && Session["nbrightmodversion"] != null && Session["nbrightmodversion"].ToString() == "1")
if (Request.IsAuthenticated)
{
// get any version data.
var length = l.Count;
var removeList = new List<int>();
for (int i = 0; i < length; i++)
{
var nbi = l[i];
if (nbi.XrefItemId > 0)
{
if (nbi.GetXmlPropertyBool("genxml/versiondelete"))
{
removeList.Add(nbi.ItemID);
}
else
{
var vnbi = objCtrl.GetData(nbi.XrefItemId, "vNBrightModDATALANG", nbi.Lang, true);
l[i] = vnbi;
}
}
}
// remove deleted record.
for (int i = length - 1; i >= 0; i--)
{
if (removeList.Contains(l[i].ItemID))
{
l.RemoveAt(i);
}
}
// get any "added" version records
var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, ModuleId, "aNBrightModDATA", "", orderby, 0, 0, 0, 0, Utils.GetCurrentCulture());
foreach (var nbi in l2)
{
l.Add(nbi);
}
if (l.Count > 0 && !String.IsNullOrWhiteSpace(orderby))
{
// need to put the sort correct, but must be done at SQL level, because we have dynamic sort defined.
var filter2 = " and ( ";
foreach (var nbi in l)
{
filter2 += " NB1.ItemId = " + nbi.ItemID + " or ";
}
filter2 = filter2.Substring(0, filter2.Length - 3) + ") ";
l = objCtrl.GetList(PortalSettings.Current.PortalId, sourcemodid, "", filter2, orderby, returnLimit, pageNumber, pageSize, 0, Utils.GetCurrentCulture());
}
}
var divclass = "";
if (settings.GetXmlProperty("genxml/textbox/wrapperclass") != "")
{
divclass = "class='" + settings.GetXmlProperty("genxml/textbox/wrapperclass") + "'";
}
strOut = "<div id='" + settings.GetXmlProperty("genxml/hidden/modref") + "' " + divclass + ">";
strOut += LocalUtils.RazorTemplRenderList(displayview, ModuleId.ToString(""), "" , l, Utils.GetCurrentCulture(), debug);
strOut += "</div>";
if (!debug)
{
// save razor compiled output, for performace
LocalUtils.SetRazorCache(cacheKey, strOut,ModuleId.ToString(""));
}
}
if (_versionRecordExist)
{
//inject JS to mark container.
strOut = "<div class='actionMenu'><ul class='dnn_mact' style='left:0;top:0;position:absolute;'><li><a href='javascript:void(0)' style='background-color:#cd1719;'><i class='fa fa-exclamation-circle'></i></a></li></ul></div>" + strOut;
}
var lit = new Literal();
lit.Text = strOut;
phData.Controls.Add(lit);
}
#endregion
#region Optional Interfaces
public ModuleActionCollection ModuleActions
{
get
{
var settings = LocalUtils.GetSettings(ModuleId.ToString());
var actions = new ModuleActionCollection();
if (settings.GUIDKey == settings.GetXmlProperty("genxml/dropdownlist/datasourceref") || settings.GetXmlProperty("genxml/dropdownlist/datasourceref") == "")
{
actions.Add(GetNextActionID(), Localization.GetString("EditModule", this.LocalResourceFile), "", "", "", EditUrl(), false, SecurityAccessLevel.Edit, true, false);
}
if (_versionRecordExist)
{
actions.Add(GetNextActionID(), Localization.GetString("Version1", this.LocalResourceFile), "", "", "translate.gif", EditUrl() + "?version=1", false, SecurityAccessLevel.Edit, true, false);
actions.Add(GetNextActionID(), Localization.GetString("Version0", this.LocalResourceFile), "", "", "translated.gif", EditUrl() + "?version=0", false, SecurityAccessLevel.Edit, true, false);
if (LocalUtils.VersionUserCanValidate(ModuleId))
{
actions.Add(GetNextActionID(), Localization.GetString("Version2", this.LocalResourceFile), "", "", "grant.gif", EditUrl() + "?version=2", false, SecurityAccessLevel.Edit, true, false);
actions.Add(GetNextActionID(), Localization.GetString("Version4", this.LocalResourceFile), "", "", "error-icn.png", EditUrl() + "?version=4", false, SecurityAccessLevel.Edit, true, false);
actions.Add(GetNextActionID(), Localization.GetString("Version3", this.LocalResourceFile), "", "", "delete.gif", EditUrl() + "?version=3", false, SecurityAccessLevel.Edit, true, false);
}
else
{
actions.Add(GetNextActionID(), Localization.GetString("Version5", this.LocalResourceFile), "", "", "icon-validate-success.png", EditUrl() + "?version=5", false, SecurityAccessLevel.Edit, true, false);
if (settings.GetXmlPropertyBool("genxml/versionemailsent"))
{
actions.Add(GetNextActionID(), Localization.GetString("Version3", this.LocalResourceFile), "", "", "delete.gif", EditUrl() + "?version=3", false, SecurityAccessLevel.Edit, true, false);
}
else
{
actions.Add(GetNextActionID(), Localization.GetString("Version6", this.LocalResourceFile), "", "", "delete.gif", EditUrl() + "?version=6", false, SecurityAccessLevel.Edit, true, false);
}
}
}
actions.Add(GetNextActionID(), Localization.GetString("auditreport", this.LocalResourceFile), "", "", "about.gif", EditUrl() + "?auditlog=1", false, SecurityAccessLevel.Edit, true, false);
actions.Add(GetNextActionID(), Localization.GetString("Refresh", this.LocalResourceFile), "", "", "action_refresh.gif", EditUrl() + "?refreshview=1", false, SecurityAccessLevel.Edit, true, false);
actions.Add(GetNextActionID(), Localization.GetString("Tools", this.LocalResourceFile), "", "", "action_source.gif", EditUrl("Tools") , false, SecurityAccessLevel.Admin, true, false);
actions.Add(GetNextActionID(), Localization.GetString("ThemeManager", this.LocalResourceFile), "", "", "manage-icn.png", EditUrl("ThemeManager"), false, SecurityAccessLevel.Host, true, false);
return actions;
}
}
#endregion
}
}