diff --git a/SQL/paredu_chat.sql b/SQL/paredu_chat.sql index a816e4a..ddd9fe3 100644 --- a/SQL/paredu_chat.sql +++ b/SQL/paredu_chat.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: localhost --- Generation Time: Apr 10, 2021 at 01:57 PM +-- Generation Time: Apr 15, 2021 at 01:55 PM -- Server version: 10.3.27-MariaDB-0+deb10u1 -- PHP Version: 7.3.27-1~deb10u1 @@ -32,7 +32,7 @@ CREATE TABLE `chats` ( `chat_id` int(4) NOT NULL, `chat_user_id` int(3) NOT NULL, `chat_user2_id` int(3) NOT NULL, - `chat_message` text NOT NULL, + `chat_message` text CHARACTER SET utf8 COLLATE utf8_hungarian_ci NOT NULL, `chat_sent_by` int(1) NOT NULL, `chat_date` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; @@ -69,6 +69,19 @@ CREATE TABLE `chats_to` ( -- -------------------------------------------------------- +-- +-- Table structure for table `notifications` +-- + +CREATE TABLE `notifications` ( + `id` int(20) NOT NULL, + `userid` bigint(20) NOT NULL, + `fromuserid` bigint(20) NOT NULL, + `unread` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + -- -- Table structure for table `users` -- @@ -103,6 +116,12 @@ ALTER TABLE `chats_from` ALTER TABLE `chats_to` ADD PRIMARY KEY (`chat_id`); +-- +-- Indexes for table `notifications` +-- +ALTER TABLE `notifications` + ADD PRIMARY KEY (`id`); + -- -- Indexes for table `users` -- @@ -131,6 +150,12 @@ ALTER TABLE `chats_from` ALTER TABLE `chats_to` MODIFY `chat_id` int(4) NOT NULL AUTO_INCREMENT; +-- +-- AUTO_INCREMENT for table `notifications` +-- +ALTER TABLE `notifications` + MODIFY `id` int(20) NOT NULL AUTO_INCREMENT; + -- -- AUTO_INCREMENT for table `users` -- diff --git a/admin/eventupload.php b/admin/eventupload.php index 760ec7d..91363c6 100644 --- a/admin/eventupload.php +++ b/admin/eventupload.php @@ -14,28 +14,28 @@ if($type == 2){ $ownertype = 2; $ownerid = substr($_SESSION["selectedcompany"], 1); - $schjson = json_decode(file_get_contents($url."/API/request.php?type=companies&id=".$ownerid), true); + $schjson = json_decode(file_get_contents($siteurl."/API/request.php?type=companies&id=".$ownerid), true); }else{ $ownertype = 1; $ownerid = substr($_SESSION["selectedschool"], 1); - $schjson = json_decode(file_get_contents($url."/API/request.php?type=schools&id=".$ownerid), true); + $schjson = json_decode(file_get_contents($siteurl."/API/request.php?type=schools&id=".$ownerid), true); } - $json = json_decode(file_get_contents($url."/API/request.php?type=events&ownertype=".$ownertype."&ownerid=".$ownerid), true); - $userjson = json_decode(file_get_contents($url."/API/request.php?type=user&id=".$userid), true); + $json = json_decode(file_get_contents($siteurl."/API/request.php?type=events&ownertype=".$ownertype."&ownerid=".$ownerid), true); + $userjson = json_decode(file_get_contents($siteurl."/API/request.php?type=user&id=".$userid), true); if(!isset($json["response"])){ echo "
"; for($i = count($json)-1; $i>=0; $i--) { if($json[$i]["title"] != ""){ - #echo ''.$json[$i]["title"].'
'.$json[$i]["description"].'
'; - //echo '
'.$json[$i]["title"].'
'.$selschvals["name"].'
'.$json[$i]["description"].'
'; + #echo ''.$json[$i]["title"].'
'.$json[$i]["description"].'
'; + //echo '
'.$json[$i]["title"].'
'.$selschvals["name"].'
'.$json[$i]["description"].'
'; echo '
diff --git a/chat/chat_script.js b/chat/chat_script.js index f743ad6..811bd26 100644 --- a/chat/chat_script.js +++ b/chat/chat_script.js @@ -21,7 +21,7 @@ $(document).ready(function (){ }); let loadMessages= function(user1_id, user2_id){ - chat_history.empty(); + //chat_history.empty(); $.ajax({ url:'php/get_messages.php', method: 'POST', dataType:'json', @@ -31,14 +31,15 @@ $(document).ready(function (){ }, dataType: 'json', success: function(result){ + chat_history.empty(); if(result != ''){ for(let i=0; i
'; + let item='
'+result[i].chat_date+'

'+result[i].chat_message+'

'; chat_history.append(item); } else { - let item='

'+result[i].chat_message+'

'; + let item='
'+result[i].chat_date+'

'+result[i].chat_message+'

'; chat_history.append(item); } } @@ -64,7 +65,7 @@ $(document).ready(function (){ success: function(result){ let parsed= jQuery.parseJSON(result); $(".chat_history_none").remove(); - let item='

'+parsed.message+'

'; + let item='
'+parsed.time+'

'+parsed.message+'

'; chat_history.append(item); }, @@ -75,7 +76,7 @@ $(document).ready(function (){ }); message.val(''); } - let getUsers= function(){ + let getUsers= function(option){ $.ajax({url:'php/get_users.php', method:'POST', dataType: 'json', @@ -84,13 +85,28 @@ $(document).ready(function (){ }, success: function(data){ for(let i=0; i'+data[i].id+'
'; - users.append(item); + if(data[i].unread > 0){ + if(option === 1){ + let item = ''; + $('#user'+data[i].id).replaceWith(item); + }else{ + let item = '
'+data[i].id+'
'; + users.append(item); + } + }else{ + if(option === 1){ + let item = ''; + $('#user'+data[i].id).replaceWith(item); + }else{ + let item = '
'+data[i].id+'
'; + users.append(item); + } + } + } let single_user= $('.users_user'); for(let i=0; i0
-
-

ParEdu Hírek

-

Még tesztelés alatt vagyunk, a befejezéséig a hírek az git oldalon találhatóak

+
+

Chat

+

A beszélgetés megkezdéséhez kattintson az adott felhasználóra

@@ -28,7 +28,7 @@
- + @@ -39,5 +39,11 @@ document.addEventListener('DOMContentLoaded', function() { autosize($('textarea.auto-growth')); }); + + function scrollDown(){ + setTimeout(function(){ + document.querySelectorAll(".chat_history_chat")[0].scrollTop=document.querySelectorAll(".chat_history_chat")[0].scrollHeight; + }, 300); + } \ No newline at end of file diff --git a/chat/php/model.php b/chat/php/model.php index 382d85c..b84d615 100644 --- a/chat/php/model.php +++ b/chat/php/model.php @@ -20,10 +20,10 @@ class Connection { class Model extends Connection { public function getUsers($id){ + include "../../creds.php"; //$sql="SELECT * FROM users WHERE user_id != ?"; - $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://".$_SERVER['HTTP_HOST']."/paredu"; $pdo = $this->connect(); - $pdo->exec('USE paredu'); + $pdo->exec('USE '.$dbname); $sql = "SELECT * FROM `auth` WHERE `id` != ?"; $stmt=$pdo->prepare($sql); $stmt->execute([$id]); @@ -33,20 +33,51 @@ class Model extends Connection { for($i = 0; $iexec('USE '.$dbname."_chat"); + $sql = "SELECT * FROM notifications WHERE userid = ? AND fromuserid = ?; "; + $stmtcheck=$pdo->prepare($sql); + $stmtcheck->execute([$id, $fetch[$i]["id"]]); + $resultcheck = $stmtcheck->fetchAll(); + if($stmtcheck && $stmtcheck->rowCount() > 0){ + $sndarray["unread"] = $resultcheck[0]["unread"]; + }else{ + $sndarray["unread"] = 0; + } + $result[$i] = $sndarray; } return $result; } public function insertChat($id,$user2_id, $message, $time){ + $conn = $this->connect(); + $sql = "SELECT * FROM notifications WHERE userid = ? AND fromuserid = ?; "; + $stmtcheck=$conn->prepare($sql); + $stmtcheck->execute([$user2_id, $id]); + $result = $stmtcheck->fetchAll(); + if($stmtcheck && $stmtcheck->rowCount() > 0){ + $unread = $result[0]["unread"]; + } + + if(isset($unread)){ + $sql = "UPDATE notifications SET unread = ? WHERE userid = ? AND fromuserid = ?;"; + $stmtinsert=$conn->prepare($sql); + $stmtinsert->execute([($unread+1), $user2_id, $id]); + }else{ + $sql="INSERT INTO notifications (userid, fromuserid, unread) VALUES (?, ?, 1);"; + $stmtinsert=$conn->prepare($sql); + $stmtinsert->execute([$user2_id, $id]); + } + $sql="INSERT INTO chats (chat_user_id, chat_user2_id, chat_message, chat_sent_by, chat_date) VALUES(?,?,?,?,?)"; - $stmt=$this->connect()->prepare($sql); + $stmt=$conn->prepare($sql); $stmt->execute([$id,$user2_id, $message, $id, $time]); $result= $stmt->fetchAll(); return $result; @@ -61,8 +92,19 @@ class Model extends Connection { } public function getChats($id1, $id2){ + $conn = $this->connect(); + $sql = "SELECT * FROM notifications WHERE userid = ? AND fromuserid = ?"; + $stmtcheck=$conn->prepare($sql); + $stmtcheck->execute([$id1, $id2]); + $result = $stmtcheck->fetchAll(); + if($stmtcheck->rowCount() > 0){ + $sql = "DELETE FROM notifications WHERE userid = ? AND fromuserid = ?"; + $stmtinsert=$conn->prepare($sql); + $stmtinsert->execute([$id1, $id2]); + } + $sql="SELECT * FROM chats WHERE chat_user_id = ? and chat_user2_id=? OR chat_user_id=? and chat_user2_id=?"; - $stmt=$this->connect()->prepare($sql); + $stmt=$conn->prepare($sql); $stmt->execute([$id1, $id2, $id2, $id1]); $result=$stmt->fetchAll(); return $result; diff --git a/chat/script.js b/chat/script.js deleted file mode 100644 index 8ad251d..0000000 --- a/chat/script.js +++ /dev/null @@ -1,37 +0,0 @@ -$(document).ready( function(){ - - let username_login= $('#user_name'); - let pass_login= $('#pass'); - let login= $('#btn-login'); - let login_message= $('#login_message'); - - let users_id_checked; - - login.click(function(e){ - e.preventDefault(); - $.ajax({ url:"php/get_this_user.php", - dataType: 'json', - data: { - name: username_login.val(), - pass: pass_login.val() - }, - method: 'POST', - success: function(result){ - - if(result =='Please enter a valid info') { - login_message.html(result); - login_message.css({'color': 'red', 'border': '1px solid', 'border-color': 'black', 'background-color': 'black'}); - } - else { - - window.location.href= 'chat.php'; - } - }, - - error: function(result){ - console.log(result); - } - - }) - }) -}); \ No newline at end of file diff --git a/css/chat.css b/css/chat.css index 32e673a..d14b5d4 100644 --- a/css/chat.css +++ b/css/chat.css @@ -1,11 +1,16 @@ +html, body { + margin: 0; +} .chat-container { width: 100%; - height: 500px; } + height: calc(100vh - 70px); + margin: 0; } .chat-container .user_id { display: none; } .chat-container .users { - height: 100%; + max-height: 100%; padding-right: 0; + margin: 0 0 0 0; } .chat-container .users .users_user { justify-content: space-between; @@ -16,7 +21,7 @@ visibility: hidden; pointer-events: none; } .chat-container .users .users_user .users_user_pic { - height: 100; + height: 100%; width: 20%; pointer-events: none; } @@ -29,10 +34,13 @@ background-color: lime; } .chat-container .users .users_user:hover { background-color: #a2c6eb; } + .chat-container .users .users_userold { + display: none; + } .chat-container .chat { display: flex; flex-direction: column; - height: 500px; } + height: 100%; } .chat-container .chat .chat_history { width: 100%; height: 80%; @@ -46,8 +54,8 @@ color: blue; } .chat-container .chat .chat_history .chat_history_user { width: 100%; - height: 70px; - background-color: #455a64; + height: 67px; + background-color: #3949ab; display: flex; justify-content: space-between; } .chat-container .chat .chat_history .chat_history_user .chat_history_user_pic { @@ -57,22 +65,24 @@ -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; - height:100%; + height:70px; width: 70px; - margin-left: 15px; } + margin: 0; + scale: 0.7; } .chat-container .chat .chat_history .chat_history_user .chat_history_user_info { display: flex; justify-content: center; align-items: center; color: white; - font-weight: bold; } + font-weight: bold; + margin-right: 70px; } .chat-container .chat .chat_history .chat_history_user .chat_history_user_id { visibility: hidden; } .chat-container .chat .chat_history .chat_history_chat { display: flex; flex-direction: column; width: 100%; - height: 80%; + height: 100%; overflow-y: scroll; background-color: #fafafa; } .chat-container .chat .chat_history .chat_history_chat .chat_history_chat_sent { @@ -80,28 +90,31 @@ display: flex; flex-direction: column; align-self: flex-end; - background-color: #26a69a; - border-radius: 10px; + background-color: #00ff99; + border-radius: 4px; padding: 5px; margin-top: 5px; - margin-right: 15px;} + margin-right: 15px; + word-wrap: break-word; } .chat-container .chat .chat_history .chat_history_chat .chat_history_chat_received { width: 45%; display: flex; flex-direction: column; align-self: flex-start; - background-color: #26c6da; - border-radius: 10px; + background-color: #56b0ff; + border-radius: 4px; padding: 5px; margin-top: 5px; - margin-left: 15px; } + margin-left: 15px; + word-wrap: break-word; } .chat-container .chat .chat_box { width: 100%; height: 20%; display: flex; justify-content: center; align-items: center; - background-color: #fafafa; } + background-color: #fafafa; + border-top: 1px grey solid; } .chat-container .chat .chat_box form { display: flex; align-items: center; diff --git a/css/style.css b/css/style.css index 1645be1..c520761 100644 --- a/css/style.css +++ b/css/style.css @@ -33,17 +33,18 @@ } section.fullscreencontent { - margin: 50px 0px 0 315px; - margin-left: 315px; + margin: 50px 0px 0 300px; + margin-left: 300px; -moz-transition: 0.5s; -o-transition: 0.5s; -webkit-transition: 0.5s; transition: 0.5s; + display: flex; + flex: 1; } .ls-closed section.fullscreencontent { - margin-left: 15px; -} + margin-left: 0px; } .fixsizeimg42 { height: 42px; diff --git a/event.php b/event.php index 15c6860..5ef492d 100644 --- a/event.php +++ b/event.php @@ -2,8 +2,8 @@ ini_set("allow_url_fopen", 1); $sqldependent = true; include "header.php"; -$json = json_decode(file_get_contents($url."/API/request.php?type=events"), true); -$jsonlang = json_decode(file_get_contents($url."/API/request.php?type=string&subtype=school"), true); +$json = json_decode(file_get_contents($siteurl."/API/request.php?type=events"), true); +$jsonlang = json_decode(file_get_contents($siteurl."/API/request.php?type=string&subtype=school"), true); for($eventid = 0; $eventidquery($viewsql); if ($result == TRUE) { diff --git a/events.php b/events.php index d0fe855..332b943 100644 --- a/events.php +++ b/events.php @@ -8,7 +8,7 @@
=0; $i--) { if($json[$i]["title"] != ""){ @@ -22,7 +22,7 @@ if (!empty($result) && $result->num_rows > 0) { $vals = $result->fetch_assoc(); if($json[$i]["uploadedas_userid"] != ""){ - $userjson = json_decode(file_get_contents($url."/API/request.php?type=user&id=".$json[$i]["ownerid"]), true); + $userjson = json_decode(file_get_contents($siteurl."/API/request.php?type=user&id=".$json[$i]["ownerid"]), true); $ownername = $userjson["name"]; }else{ $ownername = $vals["name"]; @@ -33,7 +33,7 @@ } echo ' -
+ '.$json[$i]["title"].'
'.$ownername.'
'.$json[$i]["description"].'
'; diff --git a/header.php b/header.php index bc19df9..629fc0e 100644 --- a/header.php +++ b/header.php @@ -1,6 +1,9 @@ Futtatás"; + die(); +}else{ + include "creds.php"; +} // Create connection $conn = new mysqli($sqlserver, $sqluser, $sqlpass, $dbname); +$conn->set_charset("utf8"); // Check connection if ($conn->connect_error) { @@ -235,6 +242,25 @@ if((!isset($liteload) && $loggedin == false && $isadmin && $type != 1 && $type ! } } mysqli_free_result($result); + $conn->close(); + $conn = new mysqli($sqlserver, $sqluser, $sqlpass, $dbname."_chat"); + $conn->set_charset("utf8"); + $viewsql = "SELECT * FROM notifications WHERE userid = ".$userid; + $result = $conn->query($viewsql); + $unreadchatmessages = 0; + if ($result == TRUE) { + if (!empty($result) && $result->num_rows > 0) { + while ($row = $result->fetch_assoc()){ + $unreadchatmessages += $row["unread"]; + } + }else{ + $unreadchatmessages = 0; + } + } + mysqli_free_result($result); + $conn->close(); + $conn = new mysqli($sqlserver, $sqluser, $sqlpass, $dbname); + $conn->set_charset("utf8"); }else{ $username = "Vendég"; $type = "0"; @@ -578,10 +604,11 @@ if((!isset($liteload) && $loggedin == false && $isadmin && $type != 1 && $type ! -
  • > - +
  • > + chat Chat + 0){ echo ''.$unreadchatmessages.' új'; }?>
  • @@ -601,6 +628,7 @@ if((!isset($liteload) && $loggedin == false && $isadmin && $type != 1 && $type ! chat Chat + 0){ echo ''.$unreadchatmessages.' új'; }?>
  • MŰVELETEK
  • diff --git a/school.php b/school.php index 5b40818..22ab52d 100644 --- a/school.php +++ b/school.php @@ -4,13 +4,13 @@ $load_leaflet = true; if(!isset($borderless)){ $load_school = true; include "header.php"; $inputid = $_GET["id"]; } if(isset($iscompany)){ - $mjson = json_decode(file_get_contents($url."/API/request.php?type=companies"), true); + $mjson = json_decode(file_get_contents($siteurl."/API/request.php?type=companies"), true); $ownerimgtype = "company"; }else{ - $mjson = json_decode(file_get_contents($url."/API/request.php?type=schools"), true); + $mjson = json_decode(file_get_contents($siteurl."/API/request.php?type=schools"), true); $ownerimgtype = "school"; } -$mjsonlang = json_decode(file_get_contents($url."/API/request.php?type=string&subtype=school"), true); +$mjsonlang = json_decode(file_get_contents($siteurl."/API/request.php?type=string&subtype=school"), true); for($mid = 0; $mid
    -
    ') center center; width: 100%; height: ; background-repeat: no-repeat; background-size: cover;">
    +
    ') center center; width: 100%; height: ; background-repeat: no-repeat; background-size: cover;">
    ".$mjson[$mid]["name"].""; }else{ echo "

    ".$mjson[$mid]["name"]."

    "; }?> diff --git a/schools.php b/schools.php index 74092c7..765d931 100644 --- a/schools.php +++ b/schools.php @@ -1,4 +1,4 @@ - +
    @@ -9,7 +9,7 @@
    Az itt található adatok az intézmények beleegyezése nélkül lettek feltöltve, tesztelés céljából.
    - +
    '.$json[$i]["name"].'
    '.$json[$i]["location"].'
    '.$fulltype.'
    '; diff --git a/setup.php b/setup.php index d2f9fc6..c8fef7d 100755 --- a/setup.php +++ b/setup.php @@ -1,37 +1,53 @@ "; - }else{ - $error = 1; +if (is_dir("images") && is_writable("images")){ + if(!file_exists("images/company")){ + if(mkdir("images/company", 0777) && $error != 1){ + echo "Vállalati fotó könyvtár létrehozva
    "; + }else{ + $error = 1; + } } -} -if(!file_exists("images/user")){ - if(mkdir("images/user", 0777) && $error != 1){ - echo "Felhasználói fotó könyvtár létrehozva
    "; - }else{ - $error = 1; + if(!file_exists("images/user")){ + if(mkdir("images/user", 0777) && $error != 1){ + echo "Felhasználói fotó könyvtár létrehozva
    "; + }else{ + $error = 1; + } } -} -if(!file_exists("images/school")){ - if(mkdir("images/school", 0777) && $error != 1){ - echo "Intézményi fotó könyvtár létrehozva
    "; - }else{ - $error = 1; + if(!file_exists("images/school")){ + if(mkdir("images/school", 0777) && $error != 1){ + echo "Intézményi fotó könyvtár létrehozva
    "; + }else{ + $error = 1; + } } +}else{ + echo "Az 'images' könyvtár vagy nem létezik, vagy nincs írhatónak beállítva."; } -if(!file_exists("creds.php")){ - if(file_put_contents("creds.php", '') && $error != 1){ - echo "Adatbázis konfiguráció létrehozva (creds.php)
    "; - }else{ - $error = 1; + +if (is_writable(__DIR__)){ + if(!file_exists("creds.php")){ + $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . '://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); + if(file_put_contents("creds.php", '') && $error != 1){ + echo "Adatbázis konfiguráció létrehozva (creds.php)
    "; + }else{ + $error = 1; + } } +}else{ + echo "Az gyökérkönyvtár nincs írhatónak beállítva."; } if($error == 1){ - echo "Nincsennek a jogok megfelelően beállítva. A gyökérmappa (".basename(__DIR__) .") legyen 777 jogosultságú."; + echo "Nincsennek a jogok megfelelően beállítva. A gyökérmappa (".basename(__DIR__) .") legyen 777 jogosultságú."; +} + +echo "
    Visszatérés a kezdőlapra"; +}else{ + echo "Már kész a telepítés. Az azonosító adatokat a creds.php fájlban lehet módosítani."; } ?> \ No newline at end of file