-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edit.ascx.cs
218 lines (190 loc) · 10.6 KB
/
Edit.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
// --- 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;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Tabs;
using NBrightCore.common;
using NBrightCore.render;
using NBrightDNN;
using DotNetNuke.Entities.Portals;
using NBrightMod.common;
namespace Nevoweb.DNN.NBrightMod
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The ViewNBrightGen class displays the content
/// </summary>
/// -----------------------------------------------------------------------------
public partial class Edit : Base.NBrightModBase
{
private bool _doSkinRedirect = false;
#region Event Handlers
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// refresh view by clearing all cache, and redirtect back to view
if ((Utils.RequestParam(Context, "refreshview") == "1" || Utils.RequestParam(Context, "version") != "") && Request.ApplicationPath != null)
{
string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
Utils.RemoveCache("dnnsearchindexflag" + ModuleId);
LocalUtils.ClearRazorCache(ModuleId.ToString(""));
LocalUtils.ClearRazorSateliteCache(ModuleId.ToString(""));
// this should be available from DnnUtils, but use direct to save recompile.
DataCache.ClearPortalCache(PortalId, true);
var langparam = "";
if (DnnUtils.GetCultureCodeList().Count() > 1)
{
langparam = "&language=" + Utils.RequestParam(Context, "language");
}
Session["nbrightmodversion"] = Utils.RequestParam(Context, "version");
if (Utils.RequestParam(Context, "version") == "2")
{
// accept verison changes
LocalUtils.DoValidate(ModuleId, "NBrightModDATA");
LocalUtils.DoValidate(ModuleId, "NBrightModHEADER");
}
if (Utils.RequestParam(Context, "version") == "3" || Utils.RequestParam(Context, "version") == "6")
{
LocalUtils.DoVersionDelete(ModuleId, "NBrightModDATA");
LocalUtils.DoVersionDelete(ModuleId, "NBrightModHEADER");
if (Utils.RequestParam(Context, "version") == "3")
{
// don't send email for reset by versioner (version=6)
LocalUtils.VersionSendEmail(ModuleId, "version-email-delete.cshtml");
LocalUtils.VersionAuditLog(ModuleId, AuditCode.Delete);
}
if (Utils.RequestParam(Context, "version") == "6")
{
LocalUtils.VersionAuditLog(ModuleId, AuditCode.Reset);
}
}
if (Utils.RequestParam(Context, "version") == "4")
{
// DECLINE verison changes and send email.
LocalUtils.VersionSendEmail(ModuleId, "version-email-decline.cshtml");
LocalUtils.VersionAuditLog(ModuleId, AuditCode.Decline);
}
if (Utils.RequestParam(Context, "version") == "5")
{
// Request Validation.
LocalUtils.VersionSendEmail(ModuleId, "version-email-new.cshtml");
LocalUtils.VersionAuditLog(ModuleId, AuditCode.Request);
}
Response.Redirect(baseUrl + "?tabid=" + Utils.RequestParam(Context,"TabId") + langparam, true);
}
// clear cache in edit.
LocalUtils.ClearRazorCache(ModuleId.ToString(""));
//check if we have a skinsrc, if not add it and reload. NOTE: Where just asking for a infinate loop here, but DNN7.2 doesn't leave much option.
const string skinSrcAdmin = "?SkinSrc=%2fDesktopModules%2fNBright%2fNBrightData%2fSkins%2fNBrightModAdmin%2fNormal";
if (Utils.RequestParam(Context, "SkinSrc") == "")
{
var itemid = Utils.RequestParam(Context, "itemid");
if (Utils.IsNumeric(itemid))
Response.Redirect(EditUrl("itemid", itemid, Utils.RequestParam(Context, "ctl")) + skinSrcAdmin, false);
else
{
if (Utils.RequestParam(Context, "auditlog") != "")
{
Response.Redirect(EditUrl("auditlog", "1", Utils.RequestParam(Context, "ctl")) + skinSrcAdmin, false);
}
else
{
Response.Redirect(EditUrl(Utils.RequestParam(Context, "ctl")) + skinSrcAdmin, false);
}
}
_doSkinRedirect = true;
Context.ApplicationInstance.CompleteRequest(); // do this to stop iis throwing error
}
LocalUtils.IncludePageHeaders(base.ModuleId.ToString(""), this.Page, "NBrightMod", "edit");
}
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
if (Page.IsPostBack == false && _doSkinRedirect == false)
{
if (Utils.RequestParam(Context, "auditlog") != "")
{
var strOut = LocalUtils.VersionGetAuditLog(base.ModuleId);
var lit = new Literal();
lit.Text = strOut;
phData.Controls.Add(lit);
}
else
{
var settings = LocalUtils.GetSettings(ModuleId.ToString(""));
var objCtrl = new NBrightDataController();
#region "Single Page Edit"
// if we don;t have a editlist.cshtml, then it's a single page edit, so set the flag, otherwise cancel flag.
var oldsinglepageflag = settings.GetXmlPropertyBool("genxml/hidden/singlepageedit");
var listtemplate = LocalUtils.GetTemplateData("editlist.cshtml", Utils.GetCurrentCulture(), settings.ToDictionary());
if (listtemplate == "")
settings.SetXmlProperty("genxml/hidden/singlepageedit", "true");
else
settings.SetXmlProperty("genxml/hidden/singlepageedit", "false");
var newsinglepageflag = settings.GetXmlPropertyBool("genxml/hidden/singlepageedit");
var singlepageitemidtest = settings.GetXmlPropertyInt("genxml/hidden/singlepageitemid");
var nbiTest = objCtrl.Get(Convert.ToInt32(singlepageitemidtest));
if (newsinglepageflag != oldsinglepageflag || nbiTest == null)
{
settings.SetXmlProperty("genxml/hidden/singlepageitemid", "");
if (newsinglepageflag)
{
// check to see if we have existing record, if so use the first.
var l = objCtrl.GetList(PortalSettings.Current.PortalId, ModuleId, "NBrightModDATA");
if (l.Any())
{
var firstnbi = l.First();
settings.SetXmlProperty("genxml/hidden/singlepageitemid", firstnbi.ItemID.ToString(""));
}
}
// change in flag so need to save to DB
objCtrl.Update(settings);
}
// if we have a singlepageedit theme then create/set the record itemid
if (newsinglepageflag)
{
var singlepageitemid = settings.GetXmlProperty("genxml/hidden/singlepageitemid");
if (!Utils.IsNumeric(singlepageitemid)) singlepageitemid = LocalUtils.AddNew(ModuleId.ToString(""), "NBrightModDATA",ModuleKey);
if (Utils.IsNumeric(singlepageitemid))
{
settings.SetXmlProperty("genxml/hidden/singlepageitemid", singlepageitemid);
objCtrl.Update(settings);
}
}
#endregion
var strOut = LocalUtils.RazorTemplRender("editbody.cshtml", ModuleId.ToString(""), settings.GetXmlProperty("genxml/dropdownlist/themefolder") + Utils.GetCurrentCulture(), new NBrightInfo(), Utils.GetCurrentCulture(), true); // debug mode, don;t use cache for edit
var lit = new Literal();
lit.Text = strOut;
phData.Controls.Add(lit);
}
}
}
catch (Exception exc) //Module failed to load
{
//display the error on the template (don;t want to log it here, prefer to deal with errors directly.)
var l = new Literal();
l.Text = exc.ToString();
phData.Controls.Add(l);
}
}
#endregion
}
}