/
View.ascx.cs
266 lines (237 loc) · 12.5 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
/*
' Copyright (c) 2014 Plugghest.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.UI;
using System.Web.UI.WebControls;
using Plugghest.Modules.DisplayCourse.Components;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Utilities;
using Plugghest.Modules.PlugghestControls;
using Plugghest.Base2;
namespace Plugghest.Modules.DisplayCourse
{
/// -----------------------------------------------------------------------------
/// <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 DisplayCourseModuleBase 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 : PortalModuleBase, IActionable
{
public string CultureCode;
public int CourseId;
public CourseContainer cc;
public bool InCreationLanguage;
public bool IsAuthorized;
public int Edit;
public int Translate;
public int DisplayInfo;
protected void Page_Load(object sender, EventArgs e)
{
try
{
string coursePageName = ((DotNetNuke.Framework.CDefault)this.Page).Title;
coursePageName = coursePageName.Replace("C", "");
CourseId = Convert.ToInt32(coursePageName);
CultureCode = (Page as DotNetNuke.Framework.PageBase).PageCulture.Name;
BaseHandler bh = new BaseHandler();
cc = new CourseContainer(CultureCode, CourseId);
if (cc.TheCourse.IsDeleted)
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(Convert.ToInt32(Localization.GetString("TabCourseDeleted.Text", LocalResourceFile))));
InCreationLanguage = (cc.TheCourse.CreatedInCultureCode == CultureCode);
IsAuthorized = ((this.UserId != -1 && cc.TheCourse.WhoCanEdit == EWhoCanEdit.Anyone) || cc.TheCourse.CreatedByUserId == this.UserId || (UserInfo.IsInRole("Administator")));
Edit = !string.IsNullOrEmpty(Page.Request.QueryString["edit"]) ? Convert.ToInt16(Page.Request.QueryString["edit"]) : -1;
Translate = !string.IsNullOrEmpty(Page.Request.QueryString["translate"]) ? Convert.ToInt16(Page.Request.QueryString["translate"]) : -1;
DisplayInfo = !string.IsNullOrEmpty(Page.Request.QueryString["info"]) ? Convert.ToInt16(Page.Request.QueryString["info"]) : -1;
bool editOrTranslateMode = (Edit > -1 || Translate > -1) && UserId > -1;
#region hide/display controls
hlDisplayInfo.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "info=0");
if (DisplayInfo == 0)
{
pnlDisplayInfo.Visible = false;
pnlHideDisplayInfo.Visible = true;
hlHideDisplayInfo.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "");
}
if (!InCreationLanguage && UserId > -1 && Translate == -1)
{
pnlToCreationLanguage.Visible = true;
hlToCreationLanguage.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "language=" + cc.TheCourse.CreatedInCultureCode);
pnlTranslatePlugg.Visible = true;
hlTranslatePlugg.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "translate=0");
}
if (InCreationLanguage && UserId > -1 && Edit == -1)
{
pnlEditPlugg.Visible = true;
hlEditPlugg.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "edit=0");
}
if (!InCreationLanguage && UserId > -1 && Translate > -1)
{
pnlExitTranslateMode.Visible = true;
hlExitTranslateMode.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "");
}
if (InCreationLanguage && UserId > -1 && Edit > -1)
{
pnlExitEditMode.Visible = true;
hlExitEditMode.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "");
}
if (Edit == 0)
{
plEditPluggs.Visible = true;
hlEditPluggs.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(133, "", "c=" + CourseId); //"/PAndC/Edit-CP/c/" + CourseId;
}
cc.LoadPluggs();
if (cc.ThePluggs.Count == 0)
{
lblNoPluggs.Visible = true;
lnkBeginCourse.Enabled = false;
}
else
{
PluggContainer pc = new PluggContainer(CultureCode, cc.ThePluggs[0].PluggId);
lnkBeginCourse.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(pc.ThePlugg.TabId, "", "cp=" + cc.ThePluggs[0].CoursePluggId);
}
#endregion
phComponents.Controls.Clear();
int controlOrder = 1;
if (DisplayInfo == 0)
{
DisplayCourseInfo ucDCI = (DisplayCourseInfo)this.LoadControl("/DesktopModules/DisplayCourse/DisplayCourseInfo.ascx");
if (ucDCI != null)
{
ucDCI.LocalResourceFile = "/DesktopModules/DisplayCourse/App_LocalResources/DisplayCourseInfo.ascx";
phComponents.Controls.Add(ucDCI);
}
}
if (editOrTranslateMode)
{
string ComponentHead = "<hr /><h3>" + Localization.GetString("Subject", LocalResourceFile) + "</h3>";
phComponents.Controls.Add(new LiteralControl(ComponentHead));
}
LoadSubject(controlOrder);
controlOrder++;
if (editOrTranslateMode)
{
string ComponentHead = "<hr /><h3>" + Localization.GetString("Title", LocalResourceFile) + "</h3>";
phComponents.Controls.Add(new LiteralControl(ComponentHead));
EditTitleAndDescription(controlOrder, ETextItemType.CourseTitle);
controlOrder++;
ComponentHead = "<hr /><h3>" + Localization.GetString("Description", LocalResourceFile) + "</h3>";
phComponents.Controls.Add(new LiteralControl(ComponentHead));
EditTitleAndDescription(controlOrder, ETextItemType.CourseDescription );
controlOrder++;
}
if (editOrTranslateMode)
{
string ComponentHead = "<hr /><h3>" + Localization.GetString("Content", LocalResourceFile) + "</h3>";
phComponents.Controls.Add(new LiteralControl(ComponentHead));
}
LoadRichRich(controlOrder);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void LoadSubject(int controlOrder)
{
SubjectControl ucS = (SubjectControl)this.LoadControl("/DesktopModules/PlugghestControls/SubjectControl.ascx");
if (ucS != null)
{
ucS.SubjectCase = ESubjectCase.Course;
ucS.ControlOrder = controlOrder;
ucS.CultureCode = CultureCode;
ucS.SubjectId = cc.TheCourse.SubjectId;
ucS.ItemId = CourseId;
ucS.Case = EControlCase.View;
if (InCreationLanguage & UserId > -1 & Edit > -1)
ucS.Case = EControlCase.ViewAllowEdit;
if (InCreationLanguage & IsAuthorized & Edit == controlOrder)
ucS.Case = EControlCase.Edit;
ucS.LocalResourceFile = "/DesktopModules/PlugghestControls/App_LocalResources/SubjectControl.ascx";
phComponents.Controls.Add(ucS);
}
}
private void EditTitleAndDescription(int controlOrder, ETextItemType textItemType)
{
PureTextControl ucL = (PureTextControl)this.LoadControl("/DesktopModules/PlugghestControls/PureTextControl.ascx");
if (ucL != null)
{
ucL.ModuleConfiguration = this.ModuleConfiguration;
ucL.ItemId = CourseId;
ucL.CultureCode = CultureCode;
ucL.CreatedInCultureCode = cc.TheCourse.CreatedInCultureCode;
ucL.ControlOrder = controlOrder;
ucL.ItemType = textItemType;
ucL.Case = EControlCase.View;
if (InCreationLanguage && IsAuthorized && Edit > -1)
ucL.Case = EControlCase.ViewAllowEdit;
if (InCreationLanguage && IsAuthorized && Edit == controlOrder)
ucL.Case = EControlCase.Edit;
if (!InCreationLanguage && UserId > -1 && Translate > -1)
ucL.Case = EControlCase.ViewAllowTranslate;
if (!InCreationLanguage && UserId > -1 && Translate == controlOrder)
ucL.Case = EControlCase.Translate;
ucL.LocalResourceFile = "/DesktopModules/PlugghestControls/App_LocalResources/PureTextControl.ascx";
phComponents.Controls.Add(ucL);
}
}
private void LoadRichRich(int controlOrder)
{
RichRichControl ucRR = (RichRichControl)this.LoadControl("/DesktopModules/PlugghestControls/RichRichControl.ascx");
if ((ucRR != null))
{
ucRR.ModuleConfiguration = this.ModuleConfiguration;
ucRR.ItemId = CourseId;
ucRR.CultureCode = CultureCode;
ucRR.CreatedInCultureCode = cc.TheCourse.CreatedInCultureCode;
ucRR.ControlOrder = controlOrder;
ucRR.ItemType = ETextItemType.CourseRichRichText;
ucRR.Case = EControlCase.View;
if (InCreationLanguage && IsAuthorized && Edit > -1)
ucRR.Case = EControlCase.ViewAllowEdit;
if (InCreationLanguage && IsAuthorized && Edit == controlOrder)
ucRR.Case = EControlCase.Edit;
if (!InCreationLanguage && UserId > -1 && Translate > -1)
ucRR.Case = EControlCase.ViewAllowTranslate;
if (!InCreationLanguage && UserId > -1 && Translate == controlOrder)
ucRR.Case = EControlCase.Translate;
ucRR.LocalResourceFile = "/DesktopModules/PlugghestControls/App_LocalResources/RichRichControl.ascx";
phComponents.Controls.Add(ucRR);
}
}
public ModuleActionCollection ModuleActions
{
get
{
var actions = new ModuleActionCollection
{
{
GetNextActionID(), Localization.GetString("EditModule", LocalResourceFile), "", "", "",
EditUrl(), false, SecurityAccessLevel.Edit, true, false
}
};
return actions;
}
}
}
}