· 10 years ago · Jan 17, 2016, 07:21 AM
1// this loads the navbar
2$('#navigation').load('./assets/includes/navbar.html');
3//loads the footer
4$('#footer').load('./assets/includes/footer.html');
5//function that makes the searchbar appear and disappear
6$(function(){
7 // cahce some dom
8 var $searchIcon = $('#search-icon');
9 var $searchinput = $('#search');
10 // search icon effect
11 $searchIcon.on('click', function(){
12 $searchinput.animate({width:'toggle'},350);
13
14 });
15 // When you press a button in the search bar
16 $searchinput.on('keydown',function(){
17 // query the request that someone just entered
18 console.log(this.value);
19 });
20});
21//functuon that destroys the PHP session when called
22function logout(){
23 $.ajax({type: "GET",url: "../assets/php/logout.php"});
24 //send the user back to the login page once the session has been destroyed
25 window.location.replace("index.php");
26};
27//function sem tæmir formið að öllu leiti sé þess óskað
28function wipeForm () {
29 //reset the main form
30 $('#data')[0].reset();
31 //delete everything from the tagContainer
32 $('#tagContainer').empty();
33 //fix the innerHTML of the fileselector
34 $('#chosenFile')[0].innerHTML = "Enginn skrá valinn";
35 //remove the done class from the file selector
36 $('#chosenFile').removeClass('done');
37 //empty the array of tags
38 tagArray = [];
39}
40//
41//
42//Here is code for addProject.php
43//
44//
45//This if statement prevents an undefined error on pages where the allTags array is unused, also I can define it as something returned by PHP
46if (typeof allTags === 'undefined') {
47 allTags = new Array();
48}
49/*This function takes activates once a file has
50been selected, then it takes the name of the file
51selected and tells the user the name of the file
52then it also makes the color of the div blue, in
53order to indicate that the file has been selected*/
54$('#fileToUpload').change(function(e){
55 //grab the correct textbox
56 var outputTextbox = $('#chosenFile');
57 var text = e.target.value;
58 //split the array of text
59 var arr = text.split('\\');
60 //takes the last index of the array
61 text = arr[arr.length - 1];
62 //sets the innerHTML to the name of the file
63 outputTextbox[0].innerHTML = text;
64 //changes some styles
65 outputTextbox.css("color", "white");
66 outputTextbox.css("background-color", "#303c74");
67});
68//the jQueryUI autocomplete function
69$( "#tagMaker" ).autocomplete({
70 //Select the correct sourceArray for the autocomplete function
71 source: allTags
72});
73// define varibles
74var tagArray = new Array();
75/*this function contains all functionality associated with the front-side of
76tags. It generates a div based on the input from the user and adds a cancel
77button as well as an eventlistener that runs a function that removes the tag,
78both from the final array and from the user interface*/
79var textBoxToggled = function(){
80 //grab the box that contains all the tags
81 var box = $('#tagContainer');
82 //grab the text from the input
83 var tag = $('#tagMaker').val();
84 //some input validations
85 //if the tag is empty, alert the user
86 if (tag == "") {
87 swal("Tagið má ekki vera tómt");
88 //exit from the function
89 return;
90 };
91 //if the tag is already in the array, alert the user
92 if ($.inArray(tag, tagArray) > -1) {
93 swal("Bara er hægt að nota hvert tag einu sinni");
94 return;//kill the function
95 };
96 //add the tag to the tagArray
97 tagArray.push(tag);
98 //create the elements for the div and the delete button
99 var deletr = document.createElement("div");
100 var thing = document.createElement("span");
101 //put the element in the main container
102 box.append(thing);
103 //put the tag inside the tagContainer
104 thing.innerHTML = tag;
105 //add the appropriate class to the tag
106 thing.className = "chosenTag";
107 //add the appropriate tags to the cancel button
108 deletr.className = "fa fa-times deleteTag";
109 //add an eventlistener to the x element
110 deletr.addEventListener("click", deleteThing);
111 //put the delete element inside of the tag container
112 thing.appendChild(deletr);
113 //empty the textbox
114 document.getElementById('tagMaker').value = "";
115 $('#tagMaker').focus(); // put focus back on the textbox
116 //remove the added tag from the source array of the autocomplete dropdown
117 allTags.splice($.inArray(tag, allTags), 1);
118};
119//this runs the function if either enter or the "add" button is pressed
120$("#confirmTag").click(textBoxToggled); // if the add button is pressed
121$('#tagMaker').keypress(function(e){ // if enter is presed whilest over the text box.
122 if(e.which == 13){//run the function also if enter is pressed
123 textBoxToggled();
124 };
125});
126//function that removed the relevant tag if the X button is pressed
127function deleteThing () {
128 var soonGone = this.closest('.chosenTag');//selects the closes parent element with the .chosenTag class, in this case it will be the relevant tag
129 console.log(soonGone);
130 var toBeRemoved = soonGone.textContent;//this selects the text from the same tag
131 console.log(toBeRemoved);
132 tagArray.splice($.inArray(toBeRemoved, tagArray), 1);//remove the tag from the array that will be sent via Ajax
133 allTags.push(toBeRemoved);//add the removed tag back to the dropdown
134 soonGone.remove();//remove the closest tag
135 console.log("lala");
136}
137/*This function runs if the correct button is submitted, the function
138takes all the information from the form, sends it via AJAX to a PHP file
139after preforming some validation checks*/
140$("#submitUpload").click(function(){
141 //Here are some checks that make sure that all the inputs are filled and alerts the user if he missed any inputs
142 var checkName = $('#name').val();
143 var checkDescription = $('#description').val();
144 var checkFile = $('#fileToUpload').val();
145 var checkSubject = $('#subject').val();
146 var checkGrades = $('#allGrades :checkbox:checked');
147 //brutal if statment that checks if any information is missing from any inputs
148 if (!checkName || !checkDescription || !checkFile || checkSubject == "Veldu fag sem hentar!" || checkGrades.length <= 0 || tagArray.length <= 0) {
149 //make the soon-to-be-returned text as an array
150 var subText = new Array();
151 //add the first constant to an array
152 subText.push("Það vantar ")
153 //this could be a switch, but fuck switch statements
154 //several if statments that check if the info is missing from each individual input
155 //if the name is empty
156 if (!checkName) {
157 //add to the array
158 subText.push("nafn");
159 };
160 //if the desciption is empty
161 if (!checkDescription) {
162 //add to the array
163 subText.push("lýsingu");
164 };
165 //if the file is empty
166 if (!checkFile) {
167 //add to the array
168 subText.push("skrá");
169 };
170 //if the subject is still the default
171 if (checkSubject == "Veldu fag sem hentar!") {
172 //add to the array
173 subText.push("eitthvað fag");
174 };
175 //if the grade array is less than or equal to 0
176 if (checkGrades.length <= 0) {
177 //add to the array
178 subText.push("eitthvern bekk");
179 };
180 //if the tagArray is less than or equal to 0
181 if (tagArray.length <= 0) {
182 //add to the array
183 subText.push("eitthvað tag");
184 };
185 //define the seperator variable
186 var comma = ", ";
187 //make a new array to insert the mixed array into
188 var realArray = new Array();
189 //loop that runs as long as the array is long
190 for (var i = 0; i < subText.length; i++) {
191 //add the current index of the old array to the new one
192 realArray.push(subText[i]);
193 //if the length of the array is more than two, add commas in between
194 if (subText.length > 2) {
195 //if the loop is not at the first, second last or last index of the array, add a comma to the array
196 if (i != 0 && i != subText.length -2 && i != subText.length -1) {
197 realArray.push(comma);
198 };
199 //add an "og" to the second to last index of the array
200 if (i == subText.length -2) {
201 realArray.push(" og ");
202 };
203 };
204
205 };
206 //console.log(realArray);
207 //alert the user if something is missing.
208 swal("Það vantar eitthvað", realArray.join(""), "error");
209 }
210 //checks passed, do stuff and things
211 else{
212 /*make the users confirm that they indeed want to upload the file
213 if they do, send the all of the form data to a PHP file via AJAX and
214 if that is completed successfully send the tags, along with the ID of
215 the upload to a different PHP file to be inserted seperately. The reason
216 for this seperation is that we were having issues with uploading files and
217 data at the same time so that we decided to send all the info from the
218 form into a PHP document and then add the tags seperately*/
219 swal({
220 //all this stuff is for the sweetalert plugin
221 title: "Viss ?",
222 text: "Ertu viss um að þú viljir senda verkefnið inn?",
223 type: "warning",
224 showCancelButton: true,
225 confirmButtonColor: "#20E82E",
226 confirmButtonText: "Já, Senda inn",
227 cancelButtonText: "Nei, Ekki senda",
228 closeOnConfirm: false,
229 closeOnCancel: false
230 },
231 //this is what happens if the user confirms the selection
232 function(isConfirm){
233 if (isConfirm) {
234 //take all the available formdata from the form
235 //this is unable to take in the tags, so they will be inserted later
236 //the actual ajax
237 var formData = new FormData($("form#data")[0]);
238 var tagsToSend = tagArray;
239 wipeForm();
240 $.ajax({
241 url: "assets/php/upload.php",//target the correct file
242 type: 'POST',//use POST for this
243 data: formData,//define the date that will be sent
244 success: function (data) {//if the ajax is successful, do this
245 //this is a different Ajax query that sends the information about the tags to the database
246 //it only runs if the other function is successful
247 var uploadID = data;
248 $.ajax({
249 url: 'assets/php/addTagToUpload.php',//target the correct file
250 type: 'POST',//use POST
251 data: {//the data array that will be sent to the PHP
252 id:uploadID,
253 tags:tagsToSend
254 },
255 success: function(tagData) {//if successful
256 console.log(tagData);
257 swal("Sent!", "Verkefni þitt hefur verið sent!", "success");
258
259 }
260 });
261 },
262 cache: false,//don't cache
263 contentType: false,//don't use a specific content type
264 processData: false//don't process the data specially
265 });
266 }
267 else {
268 swal("Hætt við", "Verkefnið var ekki sent", "error");
269 }
270 });
271 return false;//don't return anything
272 }
273});
274//
275//
276//Code for addProject.php is now done
277//
278//
279
280//
281//
282//Code for editProject.php
283//
284//
285/*this is for preventing undefined variables
286because this is a function that requires data
287returned from PHP*/
288if (typeof sendIdOverToJS === 'undefined') {
289 sendIdOverToJS = null;
290}
291//is the user reject the changes, do this
292$('#rejectChanges').click(function () {
293 //tell the user
294 swal("Breytingum hafnað", "", "error");
295 //wait 1500ms then redirect the user
296 setTimeout(function() {
297 //redirect backwards
298 if(document.referrer.indexOf(window.location.hostname) != -1){
299 parent.history.back();
300 return false;
301 }
302 }, 1500);
303});
304//if the user decites to delete the project, this runs
305$('#deleteProject').on('click', function() {
306 //tell the user to confirm the selection
307 swal({
308 title: "Eru viss um að þú viljir gera þetta?",
309 text: "Það er ekki hægt að endurheimta eydd verkefni",
310 type: "warning",
311 showCancelButton: true,
312 confirmButtonColor: "#303c74",
313 confirmButtonText: "Já, ég vill eyða verkefninu",
314 closeOnConfirm: false
315 //this happens if the user presses yes
316 }, function() {
317 $.ajax({
318 url: 'assets/php/deleteUpload.php',//target the correct file
319 type: 'POST',
320 data: {id:sendIdOverToJS},//send the id of the upload
321 success: function(data) {
322 //tell the user that the project has been removed
323 swal("Eytt!", "Verkefninu þÃnu hefur verið eytt", "success");
324 setTimeout(function() {
325 window.location.href = "index.php";
326 }, 1500);
327 }
328 });
329 });
330});
331/*this sends data to a PHP document over AJAX
332in order to update the information of the upload*/
333var grades = new Array();
334$('#acceptChanges').click(function() {
335 var name = $('#name').val();
336 var description = $('#description').val();
337 var subject = $('#subject').val();
338 $.each($("input[name='grades[]']:checked"), function() {
339 grades.push($(this).val());
340 });
341 $.ajax({
342 url: 'assets/php/editProject.php',
343 type: 'POST',
344 data: {
345 id:sendIdOverToJS,
346 name:name,
347 description:description,
348 subject:subject,
349 grades:grades,
350 tags:tagArray
351 },
352 success: function(data) {
353 console.log(data);
354 swal("Breytingar mótteknar", "", "success");
355 setTimeout(function() {
356 // Whatever you want to do after the wait
357 if(document.referrer.indexOf(window.location.hostname) != -1){
358 parent.history.back();
359 return false;
360 }
361 }, 1500);
362 }
363 });
364});
365//adds the delete function to the click event of the premade tags
366$('.chosenTag').each(function () {
367 this.addEventListener("click", deleteThing);
368});
369//remove the currenty selected tags from the autocomplete list
370allTags = $.grep(allTags, function(value) {
371 return $.inArray(value, tagArray) < 0;
372});
373//set the source of the autocomplete list
374$( "#tagMaker" ).autocomplete({
375 source: allTags
376});
377//
378//
379//Here the code for editProject.php ends
380//
381//
382
383//
384//
385//Here the code for editSchool.php starts
386//
387//
388// fetch the school intel through ajax
389var getSchoolInfo = function(){
390 $.ajax({
391 url: "assets/php/getSchoolIntel.php",
392 type: "GET",
393 success: function(data){
394 // work with the intel from the php file.
395 var info = JSON.parse(data);
396 // put the content in the right place
397 if ($('#city').length) {//check if city exists
398 $('#name')[0].value = info['name'];
399 $('#city')[0].value = info['city'];
400 $('#address')[0].value = info['address'];
401 $('#postCode')[0].value = info['postCode'];
402 }
403 else{
404 return;
405 }
406 }
407 });
408}
409// send new intel to be updated
410var UpdateInfo = function(){
411 // get the info
412 var name = $('#name')[0].value;
413 var city = $('#city')[0].value;
414 var address = $('#address')[0].value;
415 var postcode = $('#postCode')[0].value;
416 $.ajax({
417 url: "assets/php/updateSchoolInfo.php",
418 type: "POST",
419 data: {
420 name: name,
421 city: city,
422 address: address,
423 postCode: postcode
424 },
425 success: function(data){
426 console.log(data);
427 getSchoolInfo();
428 }
429 });
430};
431$('#submitChanges').on('click',function(){
432 UpdateInfo();
433})
434getSchoolInfo();
435
436//
437//
438//Here the code for editSchool.php ends
439//
440//
441
442//
443//
444//Here the code for user.php starts
445//
446//
447/*Block of code that takes care of showing and hiding the tabs*/
448$('.tabs .tab-links a').on('click', function(e) {
449 var currentAttrValue = $(this).attr('href');
450 // Show the selected tabs and hide the ones that aren't
451 $('.tabs ' + currentAttrValue).show().siblings().hide();
452 // Change/remove current tab to active
453 $(this).parent('li').addClass('active').siblings().removeClass('active');
454 e.preventDefault();
455});
456//
457//
458//Here the code for user.php ends
459//
460//
461
462//
463//
464//Here the code for userSettings.php
465//
466//
467//checks if the new passwords match, and if they do sends it to the PHP
468//don't even try to modify this to pass on a bad password, the PHP also preformes validation checks
469$('#confirmPassChange').click(function() {
470 //take in the three variables
471 console.log("clicked");
472 var oldPass = $('#oldPass').val();
473 var newPass0 = $('#newPass0').val();
474 var newPass1 = $('#newPass1').val();
475 //if one of the fields has not been set, alert the user
476 if (!newPass0 || !newPass1 || !oldPass) {
477 swal("Þú þarft að filla à alla reitina", "", "error");
478 //return prevents the rest of the code from executing
479 return;
480 };
481 //if the passwords match, run the ajax
482 if (newPass0 == newPass1) {
483 $.ajax({
484 //targets the file
485 url: 'assets/php/changePass.php',
486 //use post
487 type: 'POST',
488 //send over the data
489 data: {
490 oldPass:oldPass,
491 newPass1:newPass1,
492 newPass0:newPass0
493 },
494 //if successful....
495 success: function(data) {
496 //console.log(data);
497 //if successful
498 //console.log(data);
499 if (data=="success") {swal("Lykilorðinu hefur verið breytt", "Notaðu það þegar þú skráir þig inn næst", "success");};
500 //if the old pass was wrong
501 if (data=="nofit") {swal("Gamla lykilorðið var ekki rétt", "Þvà hefur ekki verið breytt", "error");};
502 //reset the password form
503 }
504 });
505 };
506 //if the password do not match
507 if (newPass0 != newPass1){
508 //alert the user
509 swal("Lykilorðin eru ekki eins", "", "error");
510 }
511});
512//this code sends stuff to the PHP document
513//make the arrays out of relevant scope for debugging purposes
514var grades = new Array();
515var subjects = new Array();
516//keep it in a document.ready function
517$(document).ready(function() {
518 //on the click of the button
519 $('#submitUserChanges').on('click', function() {
520 //set the variables
521 var name = $('#name').val();
522 var address = $('#address').val();
523 var email = $('#email').val();
524 var phone = $('#phone').val();
525 //load the info for grades and subjects into arrays
526 $.each($("input[name='grade']:checked"), function() {
527 grades.push($(this).val());
528 });
529 $.each($("input[name='subjects']:checked"), function() {
530 subjects.push($(this).val());
531 });
532 //the ajax function
533 $.ajax({
534 url: 'assets/php/editUser.php',
535 type: 'POST',
536 data: {
537 name:name,
538 address:address,
539 email:email,
540 phone:phone,
541 grades:grades,
542 subjects:subjects
543 },
544 success: function(data) {
545 console.log(data);
546 swal("Breytingar mótteknar", "", "success");
547 }
548 });
549 });
550});
551//
552//
553//Here userSettings.php ends
554//
555//
556
557//
558//
559//Here is code for project.php
560//
561//
562/*if the download link is pressed, send the appropriate date over to a PHP file*/
563$('#download').on('click', function() {
564 //get the ID of the correct file
565 var id = $('#download').val();
566 document.location = "assets/php/download.php?id="+id;
567});
568//same delete function as before
569$('#deleteProject').on('click', function() {
570 //Make the user confirm his selection
571 swal({
572 title: "Eru viss um að þú viljir gera þetta?",
573 text: "Það er ekki hægt að endurheimta eydd verkefni",
574 type: "warning",
575 showCancelButton: true,
576 confirmButtonColor: "#303c74",
577 confirmButtonText: "Já, ég vill eyða verkefninu",
578 closeOnConfirm: false
579 //if the user confirms his selection, do this
580 }, function() {
581 //get the ID of the upload
582 var id = $('#download').val();
583 //send it over to the PHP document
584 $.ajax({
585 url: 'assets/php/deleteUpload.php',
586 type: 'POST',
587 data: {id:id},
588 success: function(data) {
589 //tell the user that his project was deleted successfully
590 swal("Eytt!", "Verkefninu þÃnu hefur verið eytt", "success");
591 setTimeout(function() {
592 window.location.href = "index.php";
593 }, 1500);
594 }
595 });
596 });
597});
598//if the download element is not present, the projectID should not be undefined
599var projectID = 0;
600if ($('#download').length) {
601 projectID = $('#download').val();
602}
603else{
604 projectID = 1;
605}
606$('#commentButton').on('click',function(){
607 var userinput = $('.commentInput')[0];
608 userinputvalue = userinput.value;
609 // add the comment to table
610 if (userinputvalue != "") {
611 $.ajax({
612 url: 'assets/php/addComment.php',
613 type: 'POST',
614 data: {
615 uploadID:projectID,
616 content:userinputvalue
617 },
618 success: function(data) {
619 // clear the input fields
620 userinput.value = null;
621 console.log(userinputvalue);
622 // reload ajax
623 loadComments();
624 }
625 });
626 }else{
627 swal('Villa',"vinsamlegast hafðu athugasemdina ekki tóma");
628 }
629})
630// load ajax
631var deleteComment = function(e){
632 var deleteid = e.target.id;
633 swal({
634 //all this stuff is for the sweetalert plugin
635 title: "Viss ?",
636 text: "Ertu viss um að þú viljir eyða commenti?",
637 type: "warning",
638 showCancelButton: true,
639 confirmButtonColor: "#20E82E",
640 confirmButtonText: "Já, Eyða",
641 cancelButtonText: "Nei, Ekki Eyða",
642 closeOnConfirm: false,
643 closeOnCancel: false
644 },
645 //this is what happens if the user confirms the selection
646 function(isConfirm){
647 if (isConfirm) {
648 $.ajax({
649 url: 'assets/php/deleteComment.php',
650 type: 'POST',
651 data: {
652 id: deleteid
653 },
654 success: function(data){
655 console.log(data);
656 loadComments();
657 swal("commenti eytt","commenti þÃnu hefur verið eytt samkvæmt beiðni", "success");
658 }
659 });
660 }
661 else {
662 swal("Hætt við", "commenti var ekki eytt", "error");
663 }
664 });
665
666}
667var loadComments = function(){
668 $('.commentOutercontainer').remove();
669 $.ajax({
670 url: 'assets/php/fetchComment.php',
671 type: 'POST',
672 data: {
673 projectID:projectID
674 },
675 success: function(data){
676 var thing = JSON.parse(data);
677 thing = thing;
678 for (var i = 0; i < thing.length; i++) {
679 var outerContainer = $('<div class="commentOutercontainer"></div>').appendTo($('#main'));
680 var uppercontainer = $('<div class="upperCommentContent"></div>').appendTo(outerContainer);
681 var time = $('<span class="commentTime">'+thing[i].time+'</span>').appendTo(uppercontainer);
682 var container = $('<span><span>').appendTo(uppercontainer);
683 if (thing[i].owner == '1') {
684 // if the user that requsted the comments is the owner.
685 // a comment delete button is added.
686 var bin = $('<i class="fa fa-trash-o deleteComment" id="'+thing[i].ID+'"></i>').appendTo(container);
687 }
688 else{
689 // if the user that requested the comments is not the owner
690 };
691 var user = $('<a href="user.php?id='+thing[i].userID+'"><span class="commentUser">'+thing[i].name+'</span></a>').appendTo(container);
692 var content = $('<span class="commentContent">'+thing[i].content+'</span>').appendTo(outerContainer);
693 };
694 $('.deleteComment').on('click',function(e){
695 deleteComment(e);
696 })
697 }
698 });
699}
700loadComments();
701
702// functions for emailing teachers invites start
703var emailArray = new Array();
704/*this function contains all functionality associated with the front-side of
705tags. It generates a div based on the input from the user and adds a cancel
706button as well as an eventlistener that runs a function that removes the tag,
707both from the final array and from the user interface*/
708var emailToggled = function(){
709 //grab the box that contains all the tags
710 var box = $('#tagContainer');
711 //grab the text from the input
712 var tag = $('#keys').val();
713 //some input validations
714 //if the tag is empty, alert the user
715 if (tag == "") {
716 swal("Tölvupóstfangið má ekki vera tómt");
717 //exit from the function
718 return;
719 };
720 //if the tag is already in the array, alert the user
721 if ($.inArray(tag, emailArray) > -1) {
722 swal("Bara er hægt að nota hvert tölvupóstfang einu sinni");
723 return;//kill the function
724 };
725 //add the tag to the emailArray
726 emailArray.push(tag);
727 //create the elements for the div and the delete button
728 var deletr = document.createElement("div");
729 var thing = document.createElement("span");
730 //put the element in the main container
731 box.append(thing);
732 //put the tag inside the tagContainer
733 thing.innerHTML = tag;
734 //add the appropriate class to the tag
735 thing.className = "chosenTag";
736 //add the appropriate tags to the cancel button
737 deletr.className = "fa fa-times deleteTag";
738 //add an eventlistener to the x element
739 deletr.addEventListener("click", deleteEmail);
740 //put the delete element inside of the tag container
741 thing.appendChild(deletr);
742 //empty the textbox
743 document.getElementById('keys').value = "";
744 $('#keys').focus(); // put focus back on the textbox
745};
746
747//this runs the function if either enter or the "add" button is pressed
748$("#createtag").click(emailToggled); // if the add button is pressed
749$('#keys').keypress(function(e){ // if enter is presed whilest over the text box.
750 if(e.which == 13){//run the function also if enter is pressed
751 emailToggled();
752 };
753});
754//function that removed the relevant tag if the X button is pressed
755function deleteEmail () {
756 var soonGone = this.closest('.chosenTag');//selects the closes parent element with the .chosenTag class, in this case it will be the relevant tag
757 var toBeRemoved = soonGone.textContent;//this selects the text from the same tag
758 emailArray.splice($.inArray(toBeRemoved, emailArray), 1);//remove the tag from the array that will be sent via Ajax
759 soonGone.remove();//remove the closest tag
760}
761$('#createKeys').on('click',function(data){
762 $.ajax({
763 url: "assets/php/genKeys.php",
764 type: "POST",
765 data:{
766 count: emailArray
767 },
768 success: function(data){
769 console.log(data);
770 swal('Tölvupóstar hafa verið sendir.','Allir tölvupóstar hafa verið sendir','success');
771 wipeFormEmails();
772 }
773 });
774})
775function wipeFormEmails () {
776 //delete everything from the tagContainer
777 $('#tagContainer').empty();
778 //empty the array of tags
779 emailArray = [];
780}
781//
782//
783//
784//Beware, starting to move front.php into this disgusting thing
785//
786//
787//
788 var loadprojects = function(data){
789 for (var i = 0; i < data.length; i++) {
790 var tempjQuerySelector = null;
791 var datadump = $('#datadump');
792 var outercontainer = $('<div class="col-md-6 col-xs-12"></div>').appendTo(datadump);
793
794 var uploadBox = $('<div class="col-md-12 uploadBox"></div>').appendTo(outercontainer);
795
796 var flexContLeft = $('<div class="flexContLeft"></div>').appendTo(uploadBox);
797
798 var flexContRight = $('<div class="flexContRight"></div>').appendTo(uploadBox);
799
800 // flex contain right elements
801 var usernamespan = $('<a class="frontUser" href="user.php?id=' + data[i].userID + '">'+data[i].username+'</a>').appendTo(flexContRight);
802 var subjectnamespan = $('<a class="frontSubject" href="subject.php?subject=' + data[i].subjectname + '"><span>'+data[i].subjectname+'</span></a>').appendTo(flexContRight);
803 var timespan = $('<span>'+data[i].time+'</span>').appendTo(flexContRight);
804 var starred = checkVoteAndBookmark (data[i].ID);
805 var arr = starred.split(' ');
806 var numOfVotes = arr[1];
807
808 if (arr[0] == "f") {
809 var makeStar = $('<div><i class="fa fa-star-o fa-2x voter"> <span class="numOfVotes">' + numOfVotes + '</span><span class="hiddenID">' + data[i].ID + '</span></i></div>');
810 makeStar.appendTo(flexContRight);
811 };
812 if (arr[0] == "t") {
813 var makeStar = $('<div><i class="fa fa-star fa-2x voter"> <span class="numOfVotes">' + numOfVotes + '</span><span class="hiddenID">' + data[i].ID + '</span></i></div>');
814 makeStar.appendTo(flexContRight);
815 };
816
817 if (arr[2] == "f") {
818 var makeMark = $('<div class="bookClass"><i class="fa fa-bookmark-o fa-2x bookmark"><span class="hiddenID">' + data[i].ID + '</span></i></div>');
819 makeMark.appendTo(uploadBox);
820 };
821 if (arr[2] == "t") {
822 var makeMark = $('<div class="bookClass"><i class="fa fa-bookmark fa-2x bookmark"><span class="hiddenID">' + data[i].ID + '</span></i></div>');
823 makeMark.appendTo(uploadBox);
824 };
825 // flex contain left elements
826 var title = $('<a href="project.php?id='+data[i].ID+'"><h2 class="returnedResaultsHeaderTitle">'+data[i].name+'</h2></a>').appendTo(flexContLeft);
827 var description = $('<span class="description">'+data[i].description+'</span>').appendTo(flexContLeft);
828 if (i == data.length -1) {
829 $('body').addClass('loaded');
830 setTimeout(function() {
831 $('body').removeAttr('style');
832 }, 700);
833 };
834 if (data.length == 0 && numbofbulk == 1) {
835 $('body').addClass('loaded');
836 $('body').removeAttr('style');
837 };
838 };
839 }
840function checkVoteAndBookmark(ID) {
841 return $.ajax({
842 type: "GET",
843 url: "assets/php/checkVote.php?id="+ID,
844 async: false
845 }).responseText;
846 }
847 function vote(ID, toReturn) {
848 $.ajax({
849 url: 'assets/php/vote.php',
850 type: 'POST',
851 data: {id:ID},
852 success: function(data) {
853 toReturn(data);
854 }
855 });
856 };
857
858 function addBookmark(ID, toReturn) {
859 $.ajax({
860 url: 'assets/php/bookmark.php',
861 type: 'POST',
862 data: {id:ID},
863 success: function(data) {
864 toReturn(data);
865 }
866 });
867 };
868//
869// end.
870
871(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
872(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
873m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
874})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
875ga('create', 'UA-59531056-2', 'auto');
876ga('send', 'pageview');