This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bacheloroppgaver.js
385 lines (348 loc) · 12.9 KB
/
bacheloroppgaver.js
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
$(document).data ('uid', null);
$(document).data ('userType', "unknown");
var loginDialog = null;
$(document).ready (function () {
$('title').html ('Bacheloroppgaver ved IMT'); // Change title of browser
$.ajax ({ // Check login status
url: 'json/isLoggedIn.php', // Script used to check login status
success: function (data) {
if (data.login) { // A user is not logged in
$('body > section').load ('pages/welcome.html');
updateUI (); // Show appropriate display
} else { // A user is logged in
$(document).data ('userType', data.userType); // Update user type
$(document).data ('uid', data.uid); // Update user id
$('#login a').html ('Logge av'); // Change logon to logoff
$('#login').next().hide(); // Hide the create new user link
updateUI (); // Show appropriate display
}
}
});
//Display student group information
$('#myGroup').click (function() {
//window.alert("test");
$('body > section').load('pages/showStudentGroup.php');
return false;
});
// Display published and reviewed projects
$('#showPublic').click (function() {
$('body > section').load ('pages/availableProjects.php');
return false;
});
// Displays all projects
$('#projectsOverview').click (function()
{
$('body > section').load ('pages/projectsOverview.php');
return false;
});
$('#godkjeningsMote').click (function() { // Show login dialog box
$('body > section').load ('pages/godkjeningMote.php');
// Prevent the link from being followed.
return false;
});
$('#tildeling').click (function() { // Show login dialog box
$('body > section').load ('pages/projectAllocation.php');
// Prevent the link from being followed.
return false;
});
// Displays all information about a single project
// $('.showProjectInfo').click (function()
// {
// $('body > section').load ('pages/showProjectInfo.php?id=' + this.id));
// return false;
// });
$('#login').click (function() { // Show login dialog box
showLoginDialog ();
// Prevent the link from being followed.
return false;
});
$('#login').next().click (function() { // The "Opprett bruker" link, create new external user
showNewExternalUserDialog ();
return false;
});
$('.external').next().children('ul > li:nth-child(1)').click (function() { // External user, list projects
$('body > section').load ('pages/externalUserProjects.php');
return false;
});
$('.external').next().children('ul > li:nth-child(2)').click (function() { // External user, new project
$('body > section').load ('pages/newProject.php');
return false;
});
$('.external').next().children('ul > li:nth-child(3)').click (function() { // External user, my files
$('body > section').load ('pages/externalUserFiles.php');
return false;
});
$('.external').next().children('ul > li:nth-child(4)').click (function() { // External user, edit userinfo
$('body > section').load ('pages/externalUserEditInfo.php');
return false;
});
});
/**
* Show the login dialog, the contents of the dialog is from the file
* dialogs/login.php. The script login(form) will be called to perform
* the login.
*/
function showLoginDialog () {
if ($(document).data ('uid')!=null) { // If a user is logged in
$('#login a').html ('Logge på'); // Change the log off to log in
$('#login').next().show(); // Show the create new user link
$(document).data ('uid', null); // Clear the uid
$(document).data ('userType', null);// Clear the user type
updateUI(); // Update the user interface, set back to initial state
/*Koden over virker ikke som så jeg legger til en linje som fikser loggut*/
$.get('json/logout.php');
return false;
}
if (loginDialog == null) { // If the login dialog has not been previously created
// Create and load the content of the login dialog, then make it a dialog
loginDialog = $('<div></div>').load('dialogs/login.php', function () {
// Run this code when the content of the dialog has loaded
// When the log in button is pressed, run the login method
$('form.login input[type="button"]').click (login);
// Open the login dialog
loginDialog.dialog('open');
}).dialog({
autoOpen: false,
position: [500,200],
width: 350,
title: 'Logg på for å opprette/velge/vurdere bacheloroppgaver'
});
}
// Find the dialog and open it (Note, this doesn't work when creating the dialog on the fly so we need both)
$('.login').parent().dialog('open');
}
/**
* Show the dialog for creating a new external user.
* The content of the dialog is from dialogs/newExternal.php
* The script createNewExternal(form) will be called to handle the form
* data.
*/
function showNewExternalUserDialog () {
// Create a new dialog
var dialog = $('<div></div>').load('dialogs/newExternal.php', function () {
$('.newExternal textarea.tinymce').tinymce({
language : 'nb',
// Location of TinyMCE script
script_url : 'tinymce/jscripts/tiny_mce/tiny_mce_gzip.php',
// General options
theme : "advanced",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,advlist,spellchecker",
// Theme options
theme_advanced_buttons1 : "spellchecker,iespell,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,|,forecolor,backcolor",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
spellchecker_languages : "Norwegian=no,+English=en",
// Example content CSS (should be your site CSS)
content_css : "higstyles.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
//file_browser_callback : 'tinyFileBrowser'
});
}).dialog({
autoOpen: true,
position: [200,100],
width: 550,
title: 'Opprett ny bedriftsbruker for å opprette bacheloroppgaver.',
close: function (event, ui) {
$(this).remove();
}
});
}
/**
* Called from the NewExternal dialog, does basic form validation
* before posting the data to the script json/createNewExternal.php
*/
function createNewExternal (form) {
if (form.altKey!=undefined) // For some reason this method get called twice
return;
if (form.password.value.length<6) { // Password must be at least six characters
alert ("Passordet må være minst 6 tegn.");
form.password.focus;
return;
} else if (form.password.value!=form.password1.value) { // The passwords must match
alert ("De to passordene er ulike.");
form.password.focus;
return;
} else if (form.email.value.length<6) { // We need an email, this is the login name
alert ("Du må oppgi en epost adresse, denne vil være ditt brukernavn på systemet.");
form.email.focus;
return;
}
var data = { // All data from the form
name : form.name.value,
givenname : form.givenname.value,
surename : form.surename.value,
email : form.email.value,
password : form.password.value,
officephone : form.officephone.value,
cellphone : form.cellphone.value,
address : form.address1.value,
address1 : form.address2.value,
postal : form.postal.value,
description : $('.newExternal textarea[name="bedriftsbeskrivelse"]').html() };
$.ajax ({
url : 'json/createNewExternal.php',
type : 'POST',
data : data,
success : function (data) {
if (data.ok) {
$(document).data ('uid', data.uid);
$(document).data ('userType', 'external');
$('.newExternal').parent().dialog('close');
$('.newExternal').parent().remove(); // Remove the dialog from memory
// Change logon to logoff
$('#login a').html ('Logge av');
$('#login').next().hide();
updateUI ();
} else if (data.userExists) {
alert ('Brukernavnet eksisterer allerede. Har du glemt passordet?');
} else
alert (data.error);
}
});
}
/**
* Used to allow the user to insert local (from database) links
* in the tinyMCE editor
*/
function tinyFileBrowser (field_name, url, type, win) {
cmsURL = 'fileLibrary/fileList.php';
if (cmsURL.indexOf("?") < 0) {
//add the type as the only query parameter
cmsURL = cmsURL + "?type=" + type;
} else {
//add the type as an additional query parameter
// (PHP session ID is now included if there is one at all)
cmsURL = cmsURL + "&type=" + type;
}
if (type=='image')
title = 'Velg et bilde';
else
title = 'Velg en fil';
tinyMCE.activeEditor.windowManager.open({ // Open file picker dialog
file : cmsURL,
title : title,
width : 630,
height : 411,
resizable : "no",
inline : "yes",
close_previous : "yes",
popup_css : false
}, {
window : win,
input : field_name
});
return false;
}
/**
* Update the user interface, show the menu options according to
* the type of user logged in.
*/
function updateUI () {
// Hide user spesific menu items
$('nav > section.student').hide();
$('nav > section.student').next().hide()
$('nav > section.external').hide();
$('nav > section.external').next().hide();
$('nav > section.employee').hide();
$('nav > section.employee').next().hide();
if ($(document).data ('userType')=='student') { // If a student is logged in, display student menu
$('nav > section.student').show();
$('nav > section.student').next().show()
} else if ($(document).data ('userType')=='external') { // Show the menu for external users
$('nav > section.external').show();
$('nav > section.external').next().show();
$('body > section').load ('pages/welcomeExternal.html');
} else if ($(document).data ('userType')=='employee') { // Show both employee and external menues
$('nav > section.employee').show();
$('nav > section.employee').next().show();
} else
$('body > section').load ('pages/welcome.html');
}
/**
* This function is called when the user clicks the "Logg inn" button
* in the login dialog.
* This method will check the username/password again HiG users,
* if no match is found here the method loginExternal will be called
* to check if a external user is login in.
*
* @param form a reference to the form with the username/password
*/
function login (form) {
if (form.altKey!=undefined) // For some reason this method get called twice
return;
// Get the username and password from the form
var uname = form.username.value;
var pwd = form.password.value;
$.ajax ({ // Use an Ajax call to check the user credentials
url : 'json/login.php',
data : { 'uname': uname, 'pwd': pwd },
crossDomain : true,
type : 'POST',
dataType : 'json',
success : function (data) {
if (data.login_error) { // If no user matches the username/pwd
// Try login as external (non HiG) user
loginExternal (uname, pwd);
return;
}
// User credentials confirmed, store uid
$(document).data ('uid', data.uid);
// Set userType that has logged in
if (data.employee=='y')
$(document).data ('userType', 'employee');
else
$(document).data ('userType', 'student');
// Hide the login dialog box
$('.login').parent().dialog('close');
// Change logon to logoff
$('#login a').html ('Logge av');
$('#login').next().hide();
// Update the UI to show new options
updateUI ();
}
});
}
/**
* This method will check to see if the given user credentials belong to
* an external (non HiG) user.
*
* If no user with the given credentials is found an error message will
* be displayed in the dialog box.
*
* @param uname the username
* @param pwd the password
*/
function loginExternal (uname, pwd) {
$.ajax ({
// Use a system spesific script to check credentials
url : 'json/externalUserLogin.php',
data : { 'uname' : uname, 'pwd' : pwd },
type : 'POST',
dataType : 'json',
success : function (data) {
if (data.login_error!=undefined) { // If no user matches the credentials
// Show the error message
$('form.login .error').show ();
return;
}
//User credentials confirmed, store the uid
$(document).data ('uid', data.uid);
$(document).data ('userType', 'external');
// Hide the login dialog box
$('.login').parent().dialog('close');
// Change logon to logoff
$('#login a').html ('Logge av');
$('#login').next().hide();
// Update the UI to show new options
updateUI ();
}
});
}