Compare commits
No commits in common. "93bab0b3c54df05b5ffd572e4aa19aa0a6b31b2a" and "0e5f580c74883f876fdcee5c7870c58168ae8893" have entirely different histories.
93bab0b3c5
...
0e5f580c74
@ -48,22 +48,6 @@ h1 {
|
|||||||
height: 60px;
|
height: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
p.commentText{
|
|
||||||
display: inline-block;
|
|
||||||
padding-right: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.commentLikeNumber{
|
|
||||||
display: inline-block;
|
|
||||||
padding-right: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
img.commentLike{
|
|
||||||
width: 15px;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
=======
|
|
||||||
.image-preview ._list {
|
.image-preview ._list {
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
}
|
}
|
||||||
@ -83,4 +67,3 @@ img.commentLike{
|
|||||||
height: 80px;
|
height: 80px;
|
||||||
padding: 0 10px 6px;
|
padding: 0 10px 6px;
|
||||||
}
|
}
|
||||||
>>>>>>> 0e5f580c74883f876fdcee5c7870c58168ae8893
|
|
||||||
|
324
js/functions.js
324
js/functions.js
@ -28,91 +28,16 @@ fetch(url,
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//LocalLike Objekt erstellen
|
// submit kommentar nicht seite neu laden
|
||||||
|
|
||||||
let localLikes = {}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
|
|
||||||
// submit kommentar nicht seite neu laden
|
|
||||||
|
|
||||||
$("#kommentarform").submit(function(e) {
|
$("#kommentarform").submit(function(e) {
|
||||||
console.log("Submitted")
|
console.log("Submitted")
|
||||||
e.preventDefault(); // avoid to execute the actual submit of the form.
|
e.preventDefault(); // avoid to execute the actual submit of the form.
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//LocalStorage erstellen oder auslesen
|
|
||||||
|
|
||||||
if(localStorage.getItem('localLikes')){
|
|
||||||
//likes auslesen
|
|
||||||
|
|
||||||
localLikes = JSON.parse(localStorage.getItem('localLikes'))
|
|
||||||
|
|
||||||
console.log("Stored local Likes:")
|
|
||||||
console.log(localLikes)
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
//LocalLikes leer
|
|
||||||
|
|
||||||
localLikes = {
|
|
||||||
ideen: [],
|
|
||||||
kommentare: []
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("New Local Likes created")
|
|
||||||
console.log(localLikes)
|
|
||||||
|
|
||||||
localStorage.setItem('localLikes',JSON.stringify(localLikes));
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// idee laden
|
||||||
|
|
||||||
//LocalStorage Anpassen (Likes hinzufügen oder entfernen)
|
|
||||||
|
|
||||||
|
|
||||||
function chageLocalStorrage(typ, id, addRemove){
|
|
||||||
|
|
||||||
if(typ =="idee"){
|
|
||||||
|
|
||||||
if(addRemove == "add" && !localLikes.ideen.includes(id)){
|
|
||||||
localLikes.ideen.push(id);
|
|
||||||
console.log("like added");
|
|
||||||
console.log(localLikes);
|
|
||||||
}else if(addRemove == "remove" && localLikes.ideen.includes(id)){
|
|
||||||
let index = localLikes.ideen.indexOf(id);
|
|
||||||
localLikes.ideen.splice(index, 1);
|
|
||||||
console.log("like removed");
|
|
||||||
console.log(localLikes);
|
|
||||||
}
|
|
||||||
|
|
||||||
}else if(typ == "kommentar"){
|
|
||||||
|
|
||||||
if(addRemove == "add"){
|
|
||||||
localLikes.kommentare.push(id);
|
|
||||||
}else if(addRemove == "remove"){
|
|
||||||
let index = localLikes.kommentare.indexOf(id);
|
|
||||||
localLikes.kommentare.splice(index, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.setItem('localLikes',JSON.stringify(localLikes));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// IDEE ANZEIGEN
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -135,7 +60,7 @@ function ideeAnzeigen(data) {
|
|||||||
let likesErstellen = document.createElement("p");
|
let likesErstellen = document.createElement("p");
|
||||||
let likes = document.createTextNode(data.likes + " Likes");
|
let likes = document.createTextNode(data.likes + " Likes");
|
||||||
likesErstellen.appendChild(likes);
|
likesErstellen.appendChild(likes);
|
||||||
likesErstellen.classList.add("likeDisplay");
|
likesErstellen.classList.add("loeschen");
|
||||||
document.getElementById('idee').appendChild(likesErstellen);
|
document.getElementById('idee').appendChild(likesErstellen);
|
||||||
|
|
||||||
let bild = document.createElement("img");
|
let bild = document.createElement("img");
|
||||||
@ -146,38 +71,20 @@ function ideeAnzeigen(data) {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
|
|
||||||
let ideeLike = document.createElement("img");
|
|
||||||
ideeLike.classList.add("herz");
|
|
||||||
|
|
||||||
|
|
||||||
//check if user has liked Idea before,load proper image and set class
|
let herz = document.createElement("img");
|
||||||
|
herz.src= "../images/herz-0.png";
|
||||||
|
herz.classList.add("herz");
|
||||||
|
herz.classList.add("loeschen");
|
||||||
|
document.getElementById('idee').appendChild(herz);
|
||||||
|
herz.addEventListener('click', function() {
|
||||||
|
herz.src= "../images/herz-1.png";
|
||||||
|
|
||||||
if(localLikes.ideen.includes(data.id)){
|
$.post('system/addLike.php/?id=' + data.id, {}).done(function(response){
|
||||||
ideeLike.src= "../images/herz-1.png";
|
$("#mypar").html(response.amount);
|
||||||
ideeLike.classList.add("liked");
|
|
||||||
}else{
|
|
||||||
ideeLike.src= "../images/herz-0.png";
|
|
||||||
ideeLike.classList.add("unliked");
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('idee').appendChild(ideeLike);
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ideeLike.addEventListener('click', function() {
|
|
||||||
|
|
||||||
if(localLikes.ideen.includes(data.id)){
|
|
||||||
ideeLike.src= "../images/herz-0.png";
|
|
||||||
ideeLike.classList.add("unliked");
|
|
||||||
ideeLike.classList.remove("liked");
|
|
||||||
removeLike("idee", data.id)
|
|
||||||
}else{
|
|
||||||
|
|
||||||
ideeLike.src= "../images/herz-1.png";
|
|
||||||
ideeLike.classList.add("liked");
|
|
||||||
ideeLike.classList.remove("unliked");
|
|
||||||
addLike("idee", data.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -196,82 +103,6 @@ function ideeAnzeigen(data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Like Hinzufügen
|
|
||||||
|
|
||||||
function addLike(typ, id, element){
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(typ == "idee"){
|
|
||||||
|
|
||||||
//increment likes in DB
|
|
||||||
$.post('system/addLike.php/?typ=idee&id=' + id, {}).done(function(response){
|
|
||||||
|
|
||||||
|
|
||||||
//neue Likes anzeigen
|
|
||||||
|
|
||||||
$("p.likeDisplay").html(response + " Likes")
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
//add like in LocalStorage
|
|
||||||
chageLocalStorrage("idee", id, "add")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}else if(typ == "kommentar"){
|
|
||||||
$.post('system/addLike.php/?typ=kommentar&id=' + id, {}).done(function(response){
|
|
||||||
|
|
||||||
|
|
||||||
element.prev().html(response + " Likes")
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
//add like in LocalStorage
|
|
||||||
chageLocalStorrage("kommentar", id, "add")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeLike(typ, id, element){
|
|
||||||
|
|
||||||
//decrement likes in DB
|
|
||||||
|
|
||||||
if(typ == "idee"){
|
|
||||||
$.post('system/removeLike.php/?typ=idee&id=' + id, {}).done(function(response){
|
|
||||||
|
|
||||||
|
|
||||||
$("p.likeDisplay").html(response + " Likes")
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
chageLocalStorrage("idee", id, "remove")
|
|
||||||
|
|
||||||
}else if(typ == "kommentar"){
|
|
||||||
$.post('system/removeLike.php/?typ=kommentar&id=' + id, {}).done(function(response){
|
|
||||||
|
|
||||||
|
|
||||||
element.prev().html(response + " Likes")
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
chageLocalStorrage("kommentar", id, "remove")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// kommentar formular likesErstellen
|
// kommentar formular likesErstellen
|
||||||
|
|
||||||
function kommentarErstellen(idee_id) {
|
function kommentarErstellen(idee_id) {
|
||||||
@ -280,7 +111,7 @@ function kommentarErstellen(idee_id) {
|
|||||||
|
|
||||||
let formular = document.createElement("form");
|
let formular = document.createElement("form");
|
||||||
formular.classList.add("formular");
|
formular.classList.add("formular");
|
||||||
formular.setAttribute("action", "../system/kommentarSpeichern.php");
|
formular.setAttribute("action", "https://751068-4.web.fhgr.ch/system/kommentarSpeichern.php");
|
||||||
formular.setAttribute("method", "post");
|
formular.setAttribute("method", "post");
|
||||||
formular.setAttribute("id", "kommentarform");
|
formular.setAttribute("id", "kommentarform");
|
||||||
document.getElementById("idee").appendChild(formular);
|
document.getElementById("idee").appendChild(formular);
|
||||||
@ -312,7 +143,7 @@ function kommentarErstellen(idee_id) {
|
|||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/system/kommentarSpeichern.php",
|
url: "https://751068-4.web.fhgr.ch/system/kommentarSpeichern.php",
|
||||||
data: form.serialize(),
|
data: form.serialize(),
|
||||||
})
|
})
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -322,6 +153,27 @@ function kommentarErstellen(idee_id) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* function installWidgetPreviewMultiple(widget, list) {
|
||||||
|
widget.onChange(function(fileGroup) {
|
||||||
|
list.empty()
|
||||||
|
if (fileGroup) {
|
||||||
|
$.when.apply(null, fileGroup.files()).done(function() {
|
||||||
|
$.each(arguments, function(i, fileInfo) {
|
||||||
|
var src = fileInfo.cdnUrl + '-/scale_crop/160x160/center/'
|
||||||
|
|
||||||
|
list.append($('<div/>', {class: '_item'}).append([$('<img/>', {src: src}), fileInfo.name]))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
$(function() {
|
||||||
|
$('.image-preview').each(function() {
|
||||||
|
installWidgetPreviewMultiple(uploadcare.MultipleWidget($(this).children('input')), $(this).children('._list'))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Idee formular erstellen
|
// Idee formular erstellen
|
||||||
@ -332,7 +184,7 @@ function formularErstellen(koordianten) {
|
|||||||
|
|
||||||
let formular = document.createElement("form");
|
let formular = document.createElement("form");
|
||||||
formular.classList.add("formular");
|
formular.classList.add("formular");
|
||||||
formular.setAttribute("action", "../system/ideeSpeichern.php");
|
formular.setAttribute("action", "https://751068-4.web.fhgr.ch/system/ideeSpeichern.php");
|
||||||
formular.setAttribute("method", "post");
|
formular.setAttribute("method", "post");
|
||||||
formular.setAttribute("id", "form");
|
formular.setAttribute("id", "form");
|
||||||
document.getElementById("idee").appendChild(formular);
|
document.getElementById("idee").appendChild(formular);
|
||||||
@ -396,87 +248,29 @@ function formularErstellen(koordianten) {
|
|||||||
|
|
||||||
function kommentareAnzeigen(idee_id){
|
function kommentareAnzeigen(idee_id){
|
||||||
|
|
||||||
|
document.getElementById("kommentare_container").innerHTML = "";
|
||||||
|
|
||||||
$.post("./system/alleKommentareHolen.php/?id=" + idee_id, {}).done(function(comments){
|
let url = "system/alleKommentareHolen.php/?id=" + idee_id;
|
||||||
|
fetch(url)
|
||||||
let k = document.createElement("h3");
|
.then((response) => {
|
||||||
let k_text = document.createTextNode("Kommentare:");
|
return response.json();
|
||||||
k.appendChild(k_text);
|
})
|
||||||
document.getElementById('kommentare_container').appendChild(k);
|
.then((data) => {
|
||||||
|
let k = document.createElement("h3");
|
||||||
|
let k_text = document.createTextNode("Kommentare:");
|
||||||
let commentArray = JSON.parse(comments);
|
k.appendChild(k_text);
|
||||||
|
k.classList.add("loeschen")
|
||||||
|
document.getElementById('kommentare_container').appendChild(k);
|
||||||
for (var i = 0; i < commentArray.length; i++) {
|
|
||||||
|
|
||||||
|
|
||||||
let thisComment = commentArray[i];
|
|
||||||
|
|
||||||
|
|
||||||
let kommentarContainer = $("<div>").addClass("comment");
|
|
||||||
|
|
||||||
|
|
||||||
let kommentarText = $("<p>").addClass("commentText");
|
|
||||||
kommentarText.text(thisComment.k_text);
|
|
||||||
kommentarText.appendTo(kommentarContainer);
|
|
||||||
|
|
||||||
let kommentarLikeNumber = $("<p>").text(thisComment.k_likes + " Likes").addClass("commentLikeNumber");
|
|
||||||
kommentarLikeNumber.appendTo(kommentarContainer);
|
|
||||||
|
|
||||||
let kommentarLikeButton = $("<img>").addClass("unliked commentLike")
|
|
||||||
|
|
||||||
|
|
||||||
if(localLikes.kommentare.includes(thisComment.k_id)){
|
|
||||||
kommentarLikeButton.attr("src", "../images/herz-1.png");
|
|
||||||
kommentarLikeButton.addClass("liked");
|
|
||||||
}else{
|
|
||||||
kommentarLikeButton.attr("src", "../images/herz-0.png");
|
|
||||||
kommentarLikeButton.addClass("unliked");
|
|
||||||
}
|
|
||||||
|
|
||||||
kommentarLikeButton.appendTo(kommentarContainer);
|
|
||||||
|
|
||||||
kommentarContainer.appendTo($("#kommentare_container"));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
kommentarLikeButton.click( function() {
|
|
||||||
|
|
||||||
if(localLikes.kommentare.includes(thisComment.k_id)){
|
|
||||||
kommentarLikeButton.attr("src", "../images/herz-0.png");
|
|
||||||
kommentarLikeButton.addClass("unliked");
|
|
||||||
kommentarLikeButton.removeClass("liked");
|
|
||||||
removeLike("kommentar", thisComment.k_id, $(this))
|
|
||||||
}else{
|
|
||||||
|
|
||||||
kommentarLikeButton.attr("src", "../images/herz-1.png");
|
|
||||||
kommentarLikeButton.addClass("liked");
|
|
||||||
kommentarLikeButton.removeClass("unliked");
|
|
||||||
addLike("kommentar", thisComment.k_id, $(this))
|
|
||||||
|
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
let kommentarErstellen = document.createElement("p");
|
||||||
|
let kommentar = document.createTextNode(data[i].k_text);
|
||||||
|
kommentarErstellen.appendChild(kommentar);
|
||||||
|
kommentarErstellen.classList.add("loeschen");
|
||||||
|
document.getElementById('kommentare_container').appendChild(kommentarErstellen);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
});
|
console.log('Error!: ' + error.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
let kommentarErstellen = document.createElement("p");
|
|
||||||
let kommentar = document.createTextNode(commentArray[i].k_text);
|
|
||||||
kommentarErstellen.appendChild(kommentar);
|
|
||||||
kommentarErstellen.classList.add("comment");
|
|
||||||
document.getElementById('kommentare_container').appendChild(kommentarErstellen);
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,39 +7,17 @@ require_once('data.php');
|
|||||||
$db = dbVerbindungErzeugen();
|
$db = dbVerbindungErzeugen();
|
||||||
|
|
||||||
$id = $_GET["id"];
|
$id = $_GET["id"];
|
||||||
$typ = $_GET["typ"];
|
$sql = "SELECT likes FROM idee WHERE id = $id";
|
||||||
|
|
||||||
if ($typ == "idee") {
|
|
||||||
$sql = "SELECT likes FROM idee WHERE id = $id";
|
|
||||||
$resultat = $db->query($sql);
|
$resultat = $db->query($sql);
|
||||||
$likeCount = $resultat ->fetchColumn();
|
$likeCount = $resultat ->fetchColumn();
|
||||||
$likeCount += 1;
|
$likeCount += 1;
|
||||||
|
|
||||||
|
|
||||||
|
echo ($likeCount);
|
||||||
|
|
||||||
$sql = "UPDATE idee SET likes=? WHERE id=?";
|
$sql = "UPDATE idee SET likes=? WHERE id=?";
|
||||||
$stmt = $db->prepare($sql);
|
$stmt = $db->prepare($sql);
|
||||||
$stmt->execute(array($likeCount, $id));
|
$stmt->execute(array($likeCount, $id));
|
||||||
|
|
||||||
} elseif ($typ == "kommentar"){
|
|
||||||
|
|
||||||
$sql = "SELECT k_likes FROM kommentar WHERE k_id = $id";
|
|
||||||
$resultat = $db->query($sql);
|
|
||||||
$likeCount = $resultat ->fetchColumn();
|
|
||||||
$likeCount += 1;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$sql = "UPDATE kommentar SET k_likes=? WHERE k_id=?";
|
|
||||||
$stmt = $db->prepare($sql);
|
|
||||||
$stmt->execute(array($likeCount, $id));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
echo ($likeCount);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -23,7 +23,7 @@ $stmt->execute(array($titel, $inhalt, $lat, $lng));
|
|||||||
|
|
||||||
echo $db->lastInsertId();
|
echo $db->lastInsertId();
|
||||||
|
|
||||||
header("Location: /");
|
header("Location: https://751068-4.web.fhgr.ch/");
|
||||||
die();
|
die();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once('data.php');
|
|
||||||
?>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$db = dbVerbindungErzeugen();
|
|
||||||
|
|
||||||
$id = $_GET["id"];
|
|
||||||
$typ = $_GET["typ"];
|
|
||||||
|
|
||||||
if ($typ == "idee") {
|
|
||||||
$sql = "SELECT likes FROM idee WHERE id = $id";
|
|
||||||
$resultat = $db->query($sql);
|
|
||||||
$likeCount = $resultat ->fetchColumn();
|
|
||||||
|
|
||||||
if ($likeCount > 0){
|
|
||||||
$likeCount -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
echo ($likeCount);
|
|
||||||
|
|
||||||
$sql = "UPDATE idee SET likes=? WHERE id=?";
|
|
||||||
$stmt = $db->prepare($sql);
|
|
||||||
$stmt->execute(array($likeCount, $id));
|
|
||||||
|
|
||||||
} elseif ($typ == "kommentar"){
|
|
||||||
|
|
||||||
$sql = "SELECT k_likes FROM kommentar WHERE k_id = $id";
|
|
||||||
$resultat = $db->query($sql);
|
|
||||||
$likeCount = $resultat ->fetchColumn();
|
|
||||||
$likeCount -= 1;
|
|
||||||
|
|
||||||
|
|
||||||
echo ($likeCount);
|
|
||||||
|
|
||||||
$sql = "UPDATE kommentar SET k_likes=? WHERE k_id=?";
|
|
||||||
$stmt = $db->prepare($sql);
|
|
||||||
$stmt->execute(array($likeCount, $id));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
Loading…
x
Reference in New Issue
Block a user