-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.html
185 lines (177 loc) · 6.79 KB
/
Account.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Account - Timetable System</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap">
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
font-family: 'Roboto', sans-serif;
background-color: #e6e6e6;
color: #333;
}
.header {
background-color: #003366;
color: white;
text-align: center;
padding: 20px;
}
.content {
text-align: center;
padding: 20px;
}
button, select, input[type="file"], input[type="checkbox"], input[type="text"] {
padding: 10px;
font-size: 16px;
margin: 5px;
cursor: pointer;
}
.account-info {
background-color: #007bff;
color: white;
padding: 10px;
margin: 20px auto;
width: 80%;
border-radius: 10px;
text-align: left;
}
img.profile-pic {
width: 100px;
height: 100px;
border-radius: 50%;
}
.user-list {
text-align: left;
background-color: #f8f9fa;
color: #333;
margin-top: 20px;
padding: 10px;
border-radius: 5px;
width: 80%;
margin-left: auto;
margin-right: auto;
}
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #003366;
color: white;
}
td input[type="text"] {
width: 100%;
box-sizing: border-box; /* Makes sure the padding and border are included in the width */
}
td button {
width: 100%;
}
</style>
</head>
<body>
<div class="header">
<h1>My Account - Timetable System</h1>
</div>
<div class="content">
<button onclick="showAccountDetails('William')">Student Account</button>
<button onclick="showAccountDetails('Professor Smith')">Tutor Account</button>
<button onclick="showAccountDetails('Administrator')">Admin Account</button>
<div id="accountDetails" class="account-info"></div>
</div>
<script>
const accounts = {
"William": {
name: "William",
email: "[email protected]",
role: "Student",
modules: ["Maths Lecture", "Operating Systems"],
profilePic: "path/to/default.jpg"
},
"Professor Smith": {
name: "Professor Smith",
email: "[email protected]",
role: "Tutor",
modules: ["Maths Lecture", "Operating Systems"],
profilePic: "path/to/default.jpg"
},
"Administrator": {
name: "Administrator",
email: "[email protected]",
role: "Admin",
privileges: {
"Manage Accounts": true,
"Set Timetables": false,
"Modify Courses": true
},
profilePic: "path/to/default.jpg",
users: ["William", "Professor Smith"]
}
};
function showAccountDetails(userName) {
const details = accounts[userName];
const accountDiv = document.getElementById('accountDetails');
accountDiv.innerHTML = `<img src="${details.profilePic}" alt="Profile Picture" class="profile-pic">`;
accountDiv.innerHTML += `<input type="file" onchange="uploadProfilePic(this.files)">`;
accountDiv.innerHTML += `<h2>${details.role} Account</h2>`;
accountDiv.innerHTML += `<p>Name: ${details.name}</p>`;
accountDiv.innerHTML += `<p>Email: ${details.email}</p>`;
if (details.role === 'Student' || details.role === 'Tutor') {
let coursesHeader = details.role === 'Student' ? "Enrolled Courses" : "Assigned Classes";
accountDiv.innerHTML += `<h3>${coursesHeader}:</h3><ul>`;
details.modules.forEach(module => {
accountDiv.innerHTML += `<li>${module}</li>`;
});
accountDiv.innerHTML += `</ul>`;
} else if (details.role === 'Admin') {
accountDiv.innerHTML += `<h3>Privileges:</h3><ul>`;
Object.keys(details.privileges).forEach(privilege => {
let isChecked = details.privileges[privilege] ? 'checked' : '';
accountDiv.innerHTML += `<li><input type="checkbox" ${isChecked} onchange="togglePrivilege('${privilege}', this.checked)"> ${privilege}</li>`;
});
accountDiv.innerHTML += `</ul>`;
showUserManagement();
}
}
function uploadProfilePic(files) {
const fileReader = new FileReader();
fileReader.onload = function () {
const img = document.querySelector('.profile-pic');
img.src = fileReader.result;
};
fileReader.readAsDataURL(files[0]);
}
function togglePrivilege(privilege, isEnabled) {
console.log(`Privilege ${privilege} has been ${isEnabled ? 'enabled' : 'disabled'}.`);
}
function showUserManagement() {
const adminDetails = accounts["Administrator"];
const accountDiv = document.getElementById('accountDetails');
accountDiv.innerHTML += `<div class="user-list"><strong>User Management:</strong><br>`;
accountDiv.innerHTML += `<table><tr><th>Name</th><th>Role</th><th>Modules</th><th>Actions</th></tr>`;
adminDetails.users.forEach(userName => {
let user = accounts[userName];
let modulesEditable = `<input type="text" value="${user.modules.join(', ')}" id="${userName}-modules">`;
accountDiv.innerHTML += `<tr><td>${user.name}</td><td>${user.role}</td><td>${modulesEditable}</td><td><button onclick="updateModules('${userName}')">Update</button></td></tr>`;
});
accountDiv.innerHTML += `</table></div>`;
}
function updateModules(userName) {
const newModules = document.getElementById(`${userName}-modules`).value.split(',').map(item => item.trim());
accounts[userName].modules = newModules;
console.log(`Modules for ${userName} updated to: ${newModules.join(', ')}`);
alert(`Modules for ${userName} have been updated.`);
showAccountDetails(userName);
}
</script>
</body>
</html>