-
Notifications
You must be signed in to change notification settings - Fork 1
/
MasterPage.master.cs
143 lines (116 loc) · 4.37 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
LoginLib login = new LoginLib();
if (login.IsUserLoggedIn())
{
//LogOutBtn.Visible = true;
//LogOutBtn.Enabled = true;
//Must run last for logged in users on every page, meaning before this block closes
//login.CreateNewCookie();
}
else
{
//LogOutBtn.Visible = false;
//LogOutBtn.Enabled = false;
}
rendreMenu(login);
}
public string GetGenericCssLinkHtmlString()
{
string contentIdString = Request.QueryString["content"];
int contentId;
const string noCss = null;
if (string.IsNullOrEmpty(contentIdString)) return noCss;
if (!Int32.TryParse(contentIdString, out contentId)) return noCss;
var parameter = new Dictionary<string, object> {{"@ContentId", contentId}};
string contentTypeId = "" + ManageDB.GetFirstValueFromQuery<int>(@"
SELECT ContentType
FROM DynamicContent
WHERE DynamicContentId=@ContentId
", parameter);
if (string.IsNullOrEmpty(contentTypeId)) return noCss;
return "<link href=\"" + Page.ResolveUrl("~/cms/GenericCss.ashx?contenttype=" + contentTypeId) + "\" id=\"mpGenericCssLink\" rel=\"stylesheet\" type=\"text/css\" />";
}
private void rendreMenu(LoginLib login)
{
rendreAdminMenu(login);
rendreUserMenu(login);
}
private void rendreUserMenu(LoginLib login)
{
if (login.IsUserLoggedIn())
{
MenuItem BrukerMenu = new MenuItem();
BrukerMenu.Text = "Bruker";
Menu.Items.Add(BrukerMenu);
MenuItem MeldUserMenu = new MenuItem();
MeldUserMenu.Text = "Meldinger";
MeldUserMenu.NavigateUrl = "~/User/Meldinger2.aspx";
MenuItem BrukerSokMenu = new MenuItem();
BrukerSokMenu.Text = "Søk i brukere";
BrukerSokMenu.NavigateUrl = "~/User/vennesok.aspx";
MenuItem rootUserMenu = new MenuItem();
rootUserMenu.Text = "Logout";
Menu.Items.Add(rootUserMenu);
BrukerMenu.ChildItems.Add(MeldUserMenu);
BrukerMenu.ChildItems.Add(BrukerSokMenu);
}
else
{
MenuItem ToggleLoginMenuItem = new MenuItem();
ToggleLoginMenuItem.Text = "Login";
ToggleLoginMenuItem.NavigateUrl = "javascript:Toggel('LoginDiv');";
Menu.Items.Add(ToggleLoginMenuItem);
}
}
private void rendreAdminMenu(LoginLib login)
{
if (ManageDB.UserHasPermission(Permissions.Gaymer_View_Admin_Menu, login.GetUserID()))
{
MenuItem rootAdminMenu = new MenuItem();
rootAdminMenu.Text = "Admin";
rootAdminMenu.NavigateUrl = "~/Online/Student/FagListe.aspx";
rootAdminMenu.Selectable = false;
Menu.Items.Add(rootAdminMenu);
MenuItem m;
if (ManageDB.UserHasPermission(Permissions.Gaymer_Manage_Roles, login.GetUserID()))
{
m = new MenuItem();
m.Text = "Roller";
m.NavigateUrl = "~/Admin/Roles.aspx";
rootAdminMenu.ChildItems.Add(m);
}
if (ManageDB.UserHasPermission(Permissions.Gaymer_Manage_Users, login.GetUserID()))
{
m = new MenuItem();
m.Text = "Users";
m.NavigateUrl = "~/Admin/Users.aspx";
rootAdminMenu.ChildItems.Add(m);
}
if (ManageDB.UserHasPermission(Permissions.Gaymer_Manage_Content_Type, login.GetUserID()))
{
m = new MenuItem();
m.Text = "Content types";
m.NavigateUrl = "~/Admin/ListContentTypes.aspx";
rootAdminMenu.ChildItems.Add(m);
}
}
}
protected void Menu_MenuItemClick(object sender, MenuEventArgs e)
{
if (e.Item.Text == "Logout")
{
LoginLib login = new LoginLib();
login.LogOut();
Response.Redirect("/StartPage.aspx");
}
}
}