forked from ericberman/MyFlightbookWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MasterPage.master.cs
260 lines (225 loc) · 9.72 KB
/
MasterPage.master.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
using MyFlightbook;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.UI;
using System.Web.UI.HtmlControls;
/******************************************************
*
* Copyright (c) 2007-2018 MyFlightbook LLC
* Contact myflightbook-at-gmail.com for more information
*
*******************************************************/
public partial class MasterPage : System.Web.UI.MasterPage
{
#region properties
private const string szKeyIsNakedSession = "IsNakedSession";
protected bool IsNaked
{
get { return (Session[szKeyIsNakedSession] != null && (Boolean)Session[szKeyIsNakedSession] == true); }
set { Session[szKeyIsNakedSession] = value; }
}
private const string szKeyIsNightSession = "IsNightSession";
protected bool IsNight
{
get { return (Session[szKeyIsNightSession] != null && (Boolean)Session[szKeyIsNightSession] == true); }
set { Session[szKeyIsNightSession] = value; }
}
/// <summary>
/// Get/set the selected tab, by name.
/// </summary>
public tabID SelectedTab
{
get { return mfbHeader.SelectedTab; }
set
{
TabList t = mfbHeader.TabList;
tabID tidTop = t.TopLevelTab(value);
mfbHeader.SelectedTab = tidTop;
bool fHasSecondaryNav = t.ChildTabList(tidTop).Tabs.Count() > 0;
pnlTopForm.Visible = pnlTopForm.Visible || fHasSecondaryNav; // if sidebar is visible, DEFINITELY want pnlTopForm visible, if sidebar isn't visible, don't necessarily want to make it visible
}
}
/// <summary>
/// Boolean representing whether or not the master page shows its header
/// </summary>
public Boolean HasHeader
{
get { return mfbHeader.Visible; }
set { mfbHeader.Visible = value; }
}
/// <summary>
/// Boolean representing whether or not the master page shows its footer
/// </summary>
public Boolean HasFooter
{
get { return MfbFooter.Visible; }
set { MfbFooter.Visible = value; }
}
/// <summary>
/// Access to the page title
/// </summary>
public String Title
{
get { return Page.Header.Title; }
set { Page.Header.Title = value; }
}
public bool ShowSponsoredAd
{
get { return SponsoredAd1.Visible; }
set { SponsoredAd1.Visible = value; }
}
/// <summary>
/// Print the side-by-side nav at the top?
/// </summary>
public bool SuppressTopNavPrint
{
get { return pnlTopForm.CssClass.Contains("noprint"); }
set
{
HashSet<string> hs = new HashSet<string>(pnlTopForm.CssClass.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
if (value)
hs.Add("noprint");
else
hs.Remove("noprint");
pnlTopForm.CssClass = String.Join(" ", hs);
}
}
public Boolean SuppressMobileViewport { get; set; }
public bool IsIOSORAndroid { get; set; }
public string PrintingCSS
{
get { return cssPrinting.Href; }
set { cssPrinting.Href = value; cssPrinting.Visible = !String.IsNullOrEmpty(value); }
}
#endregion
/// <summary>
/// Adds a meta tag to the header of the page
/// </summary>
/// <param name="szName">The name of the tag</param>
/// <param name="szContent">The value of the tag</param>
public void AddMeta(string szName, string szContent)
{
HtmlMeta m = new HtmlMeta();
Page.Header.Controls.Add(m);
m.Name = szName;
m.Content = szContent;
}
/// <summary>
/// Switches to/from mobile state (overriding default detection) by setting the appropriate session variables.
/// </summary>
/// <param name="fMobile">True for the mobile state</param>
public void SetMobile(Boolean fMobile)
{
if (fMobile)
{
Response.Cookies[MFBConstants.keyClassic].Value = null; // let autodetect do its thing next time...
Request.Cookies[MFBConstants.keyClassic].Value = null;
Session[MFBConstants.keyLite] = Boolean.TrueString; // ...but keep it lite for the session
}
else
{
Response.Cookies[MFBConstants.keyClassic].Value = "yes"; // override autodetect
Request.Cookies[MFBConstants.keyClassic].Value = "yes";
Session[MFBConstants.keyLite] = null; // and hence there should be no need for a session variable.
}
mfbHeader.IsMobile = MfbFooter.IsMobile = fMobile;
}
public Boolean IsMobileSession()
{
return ((Request.IsMobileDevice() && (Request.Cookies[MFBConstants.keyClassic] == null || Request.Cookies[MFBConstants.keyClassic].Value != "yes")) ||
(Session[MFBConstants.keyLite] != null && Session[MFBConstants.keyLite].ToString() == Boolean.TrueString));
}
protected void Page_Init(object sender, EventArgs e)
{
int idBrand = util.GetIntParam(Request, "bid", -1);
if (idBrand >= 0 && idBrand < Enum.GetNames(typeof(BrandID)).Length)
Branding.CurrentBrandID = (BrandID)idBrand;
if (!IsPostBack)
Title = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.DefaultTitle, Branding.CurrentBrand.AppName);
// set the right locale for the requester.
if (Request == null || Request.UserLanguages == null || Request.UserLanguages.Length == 0)
return;
// Set IsIOSOrAndroid here to determine if meta tag should be sent.
if (Request.UserAgent != null)
{
string szUserAgent = Request.UserAgent.ToUpperInvariant();
if (szUserAgent.Contains("IPHONE") || szUserAgent.Contains("IPAD") || szUserAgent.Contains("ANDROID"))
IsIOSORAndroid = true;
}
util.SetCulture(Request.UserLanguages[0]);
}
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/html; charset=utf-8";
if (!IsPostBack)
{
if (ShuntState.IsShunted && String.IsNullOrEmpty(Request["noshunt"]))
Response.Redirect("~/Shunt.aspx");
// if "m=no" is passed in, override mobile detection and force classic view
if (util.GetStringParam(Request, "m") == "no")
SetMobile(false);
bool fResetCookieAccept = util.GetIntParam(Request, "declinecookie", 0) != 0;
bool fCookiesAccepted = Request.Cookies[MFBConstants.keyCookiePrivacy] != null;
if (fResetCookieAccept && fCookiesAccepted)
Response.Cookies[MFBConstants.keyCookiePrivacy].Expires = DateTime.Now.AddDays(-1);
pnlCookies.Visible = !fCookiesAccepted || fResetCookieAccept;
lnkPrivacy.Text = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.PrivacyPolicyHeader, Branding.CurrentBrand.AppName);
lnkAppleIcon.Href = ResolveUrl("~/images/apple-touch-icon.png");
cssMain.Href = "~/Public/stylesheet.css".ToAbsoluteURL(Request).ToString() + "?v=13"; // to enable forced reload
cssMobile.Visible = mfbHeader.IsMobile = MfbFooter.IsMobile = IsMobileSession();
cssMobile.Href = ResolveUrl("~/Public/CSS/MobileSheet.css?v=7");
string szStyle = Branding.CurrentBrand.StyleSheet;
if (szStyle.Length > 0)
{
cssBranded.Href = ResolveUrl(szStyle) + "?v=1";
cssBranded.Visible = true;
}
// Record last page requested by user in application cache so that it can be reported in error reporting
if (Page.User.Identity.IsAuthenticated)
Session[Page.User.Identity.Name + "-LastPage"] = String.Format(CultureInfo.InvariantCulture, "{0}:{1}{2}", Request.IsSecureConnection ? "https" : "http", Request.Url.Host, Request.Url.PathAndQuery);
if (!Page.User.Identity.IsAuthenticated)
ProfileRoles.StopImpersonating();
IsNaked = util.GetIntParam(Request, "naked", 0) != 0 || (Session["IsNaked"] != null && ((bool) Session["IsNaked"]) == true);
if (IsNaked)
pnlCookies.Visible = mfbHeader.Visible = MfbFooter.Visible = SponsoredAd1.Visible = false;
string nightRequest = util.GetStringParam(Request, "night");
if (nightRequest.CompareCurrentCultureIgnoreCase("yes") == 0)
IsNight = true;
else if (nightRequest.CompareCurrentCultureIgnoreCase("no") == 0)
IsNight = false;
cssNight.Visible = IsNight;
bool fIsImpersonating = ProfileRoles.IsImpersonating(Page.User.Identity.Name);
pnlImpersonation.Visible = fIsImpersonating;
if (fIsImpersonating)
{
lblAdmin.Text = ProfileRoles.OriginalAdmin;
lblImpersonated.Text = Page.User.Identity.Name;
}
if (Request.IsLocal)
GoogleAnalytics1.Visible = false;
}
if (IsIOSORAndroid) // set in Page INIT
{
metaFormat.Visible = true;
metaViewport.Visible = !SuppressMobileViewport;
}
}
protected void btnStopImpersonating_Click(object sender, EventArgs e)
{
ProfileRoles.StopImpersonating();
pnlImpersonation.Visible = false;
Response.Redirect("~/Member/Admin.aspx");
}
protected void btnAcceptCookies_Click(object sender, EventArgs e)
{
pnlCookies.Visible = false;
Response.Cookies[MFBConstants.keyCookiePrivacy].Value = "yes";
Response.Cookies[MFBConstants.keyCookiePrivacy].Expires = DateTime.Now.AddYears(100);
}
protected void lnkPrivacy_Click(object sender, EventArgs e)
{
Response.Redirect("~/Public/Privacy.aspx");
}
}