-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathView.ascx.cs
349 lines (277 loc) · 13.1 KB
/
View.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
/*
' Copyright (c) 2014 FryslanWebservices.com
' All rights reserved.
'
' 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.
'
*/
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Users;
using Votations.NSurvey.WebControls;
using Votations.NSurvey.DataAccess;
using Votations.NSurvey.Constants;
using Votations.NSurvey.Data;
using Votations.NSurvey.WebAdmin.NSurveyAdmin;
using Votations.NSurvey.WebAdmin.UserControls;
using System.Web.UI.WebControls;
using Votations.NSurvey.WebAdmin;
using FWS.Modules.SurveyBox.Components;
namespace FWS.Modules.SurveyBox
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The View class displays the content
///
/// Typically your view control would be used to display content or functionality in your module.
///
/// View may be the only control you have in your project depending on the complexity of your module
///
/// Because the control inherits from SurveyBoxModuleBase you have access to any custom properties
/// defined there, as well as properties from DNN such as PortalId, ModuleId, TabId, UserId and many more.
///
/// </summary>
/// -----------------------------------------------------------------------------
public partial class View : SurveyBoxModuleBase, IActionable
{
protected SurveyLayoutData _userSettings;
/// <summary>
/// SurveyID as set in DNN module Settings
/// </summary>
/// <returns>id = SurveyID</returns>
private int SurveyID()
{
object id = base.Settings["SurveyID"];
if (id == null) return -1;
return Convert.ToInt32(id);
}
protected Int64 GetSurveyId()
{
//string sp_surveyid = Convert.ToString(SurveyID());
int sp_surveyid = SurveyID();
return sp_surveyid;
}
/// <summary>
/// UserID as set in DNN module Settings
/// </summary>
/// <returns>id = UserID</returns>
private int UserID()
{
object id = base.Settings["UserID"];
if (id == null) return 0;
return Convert.ToInt32(id);
}
protected String GetSpUserId()
{
string sp_userid = Convert.ToString(UserID());
return sp_userid;
}
protected override void OnInit(EventArgs e)
{
//Jquery CSS files
Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));
//Jquery UI 1.11.4 css:
HtmlGenericControl css = new HtmlGenericControl("link");
css.Attributes.Add("rel", "stylesheet");
css.Attributes.Add("type", "text/css");
css.Attributes.Add("href", ResolveUrl("~/DesktopModules/SurveyBox/Content/themes/base/base.css"));
Page.Header.Controls.Add(css);
//jQuery(necessary for Bootstrap's JavaScript plugins) + answerfieldslideritem, answerfieldcalendar
Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));
HtmlGenericControl javascriptControl = new HtmlGenericControl("script");
//Commented out: conflicting with DNN older versions of Jquery:
//javascriptControl.Attributes.Add("id", "jq311");
//javascriptControl.Attributes.Add("src", ResolveUrl("~/DesktopModules/SurveyBox/Scripts/jquery-3.1.1.min.js"));
//Page.Header.Controls.Add(javascriptControl);
//Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));
//javascriptControl = new HtmlGenericControl("script");
//javascriptControl.Attributes.Add("src", ResolveUrl("~/DesktopModules/SurveyBox/Scripts/jquery-ui-1.12.1.min.js"));
//Page.Header.Controls.Add(javascriptControl);
//Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));
javascriptControl = new HtmlGenericControl("script");
javascriptControl.Attributes.Add("src", ResolveUrl("~/DesktopModules/SurveyBox/Scripts/jquery-ui-i18n.min.js"));
Page.Header.Controls.Add(javascriptControl);
Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
LocalizePage();
if (!IsPostBack)
{
//on initial pageload get SurveyId from DNN module settings; if null int 0 is returned;
SurveyControl.SurveyId = SurveyID();
ModuleSecurity ms = new ModuleSecurity(this.ModuleConfiguration);
if (ms.HasPermission2 && UserID() != 0)
{
ShowSurveyDDL();
SurveyControl.Visible = false;
}
else
{
if(SurveyID() >= 1)
{
SurveyControl.Visible = true;
Votations.NSurvey.SQLServerDAL.SurveyLayout u = new Votations.NSurvey.SQLServerDAL.SurveyLayout();
_userSettings = u.SurveyLayoutGet(SurveyControl.SurveyId);
if (!(_userSettings == null || _userSettings.SurveyLayout.Count == 0))
{
if (!string.IsNullOrEmpty(_userSettings.SurveyLayout[0].SurveyCss))
{
string cssurl = ResolveUrl("Css/" + SurveyControl.SurveyId.ToString() + "/" + _userSettings.SurveyLayout[0].SurveyCss);
defaultCSS.InnerHtml = "@import url(\"" + cssurl + "\");";
}
}
else
{
string alt2css = ResolveUrl("Css/surveymobile.css");
defaultCSS.InnerHtml = "@import url(\"" + alt2css + "\");";
}
}
else
{ //test:
SurveyControl.SurveyId = 0;
SurveyControl.Visible = false;
}
}
}
//Votations.NSurvey.SQLServerDAL.SurveyLayout u = new Votations.NSurvey.SQLServerDAL.SurveyLayout();
////_userSettings = u.SurveyLayoutGet(((PageBase)Page).getSurveyId());
////test set surveyid to 1
//_userSettings = u.SurveyLayoutGet(SurveyControl.SurveyId);
//if (!(_userSettings == null || _userSettings.SurveyLayout.Count == 0))
//{
// if (!string.IsNullOrEmpty(_userSettings.SurveyLayout[0].SurveyCss))
// {
// defaultCSS.InnerHtml = "@import url(\"desktopmodules/surveybox/Css/" + SurveyControl.SurveyId.ToString() + "/" + _userSettings.SurveyLayout[0].SurveyCss + "\")";
// }
//}
//Used if surveyid is taken from DNN module settings
// should depend on module permissions
//SurveyControl.SurveyId = SurveyID();
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException("ErrorDetails:" + exc.StackTrace + "& Inner:" + exc.GetBaseException(), this, exc, true);
}
}
private void ShowSurveyDDL()
{
//show list of surveys from SP based on DNN Module setting UserID
var surveys = new Surveys().GetAssignedSurveysList(Convert.ToInt32(Settings["UserID"]));
if (surveys.Surveys.Count == 1) { InitiateSurvey(surveys.Surveys[0].SurveyId); return; }
//if there are no surveys in SP connected to the UserID, get the SurveyID from DNN module settings; if null int 0 returned
if (surveys.Surveys.Count == 0) { SurveyControl.SurveyId = Convert.ToInt32(Settings["SurveyID"]); return; }
ddlSurveys.Items.Clear();
ddlSurveys.Items.Add(new ListItem("Please Choose Survey", "-1"));
ddlSurveys.AppendDataBoundItems = true;
ddlSurveys.DataSource = surveys.Surveys;
ddlSurveys.DataTextField = "Title";
ddlSurveys.DataValueField = "SurveyId";
ddlSurveys.DataBind();
ddlSurveys.Visible = true;
ChooseSurveyLabel.Visible = true;
}
protected void ddlSurveys_SelectedIndexChanged1(object sender, EventArgs e)
{
if (ddlSurveys.SelectedValue != "-1")
{
//((PageBase)Page).SurveyId = int.Parse(ddlSurveys.SelectedValue);
//SurveyControl.SurveyId = int.Parse(ddlSurveys.SelectedValue);
InitiateSurvey(int.Parse(ddlSurveys.SelectedValue));
}
}
private void InitiateSurvey(int surveyId = -1)
{
if (surveyId > -1 || (ddlSurveys.Visible == true && ddlSurveys.SelectedValue != "-1"))
{
SurveyControl.SurveyId = surveyId > -1 ? surveyId : int.Parse(ddlSurveys.SelectedValue);
}
else return;
ddlSurveys.Visible = false;
ChooseSurveyLabel.Visible = false;
// custom CSS:
Votations.NSurvey.SQLServerDAL.SurveyLayout u = new Votations.NSurvey.SQLServerDAL.SurveyLayout();
_userSettings = u.SurveyLayoutGet(SurveyControl.SurveyId);
if (!(_userSettings == null || _userSettings.SurveyLayout.Count == 0))
{
if (!string.IsNullOrEmpty(_userSettings.SurveyLayout[0].SurveyCss))
{
//defaultCSS.InnerHtml = "@import url(\"desktopmodules/surveybox/Css/" + SurveyControl.SurveyId.ToString() + "/" + _userSettings.SurveyLayout[0].SurveyCss + "\")";
string cssurl = ResolveUrl("Css/" + SurveyControl.SurveyId.ToString() + "/" + _userSettings.SurveyLayout[0].SurveyCss);
defaultCSS.InnerHtml = "@import url(\"" + cssurl + "\");";
}
}
else
{
string alt2css = ResolveUrl("Css/surveymobile.css");
defaultCSS.InnerHtml = "@import url(\"" + alt2css + "\");";
}
SurveyControl.Visible = true;
}
private void LocalizePage()
{
//TakeSurveyTitle.Text = GetPageResource("TakeSurveyTitle");
ChooseSurveyLabel.Text = "Choose a Survey";
}
protected void Page_PreRender(object sender, EventArgs e)
{
Session["DnnPortalIdSessionValue"] = GetPortalId();
Session["DnnUserIdSessionValue"] = GetUserId();
Session["DnnUserNameSessionValue"] = GetUserName();
Session["DnnUserEmailSessionValue"] = GetUserEmail();
//Session["SpSurveyIdSessionValue"] = GetSurveyId();
//Session["SpUserIdSessionValue"] = GetSpUserId();
//Default session timeout = after 20 min. of inactivity session will terminate;
}
public UserInfo _currentUser =
//DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo();
protected String GetPortalId()
{
int PortalID = _currentUser.PortalID;
return PortalID.ToString();
}
protected String GetUserId()
{
int UserID = _currentUser.UserID;
return UserID.ToString();
}
protected String GetUserName()
{
string Username = _currentUser.Username;
return Username;
}
protected String GetUserEmail()
{
string UserEmail = _currentUser.Email;
return UserEmail;
}
public ModuleActionCollection ModuleActions
{
get
{
var actions = new ModuleActionCollection
{
{
GetNextActionID(), Localization.GetString("EditModule", LocalResourceFile), "", "", "",
EditUrl(), false, SecurityAccessLevel.Edit, true, false
}
};
return actions;
}
}
}
}