some fixes

This commit is contained in:
themohooks 2024-10-08 21:42:55 +03:00
parent 0bb61c96f1
commit 9b793811c5
11 changed files with 184 additions and 57 deletions

View file

@ -13,13 +13,16 @@ class GetVehicleInputs
public function __construct() public function __construct()
{ {
$id = explode('/', $_SERVER['REQUEST_URI'])[4]; $id = explode('/', $_SERVER['REQUEST_URI'])[4];
$vehicle = DB::query('SELECT * FROM entities WHERE id=:id', array(':id'=>$id))[0]; $vehicle = DB::query('SELECT * FROM entities WHERE id=:id', array(':id' => $id))[0];
$data = json_decode($vehicle['sampledata'], true); $data = json_decode($vehicle['sampledata'], true);
foreach ($data as $d) { foreach ($data as $d) {
if ($d['important'] === "1") {
$imp = 'required';
}
echo ' echo '
<div class="mb-3"> <div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">'.$d['name'].'</label> <label for="exampleFormControlInput1" class="form-label">' . $d['name'] . '</label>
<input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="Вагон метро"> <input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="'.$d['name'].'" '.$imp.'>
</div>'; </div>';
} }
} }

View file

@ -12,7 +12,7 @@ class Create
private static function create($content, $id) private static function create($content, $id)
{ {
DB::query('INSERT INTO photos_comments VALUES (\'0\', :userid, :postid, :postbody, :time)', array('postid' => $_POST['id'], ':postbody' => $_POST['wtext'], ':userid' => Auth::userid(), ':time' => time())); DB::query('INSERT INTO photos_comments VALUES (\'0\', :userid, :postid, :postbody, :time, :content)', array('postid' => $_POST['id'], ':postbody' => $_POST['wtext'], ':userid' => Auth::userid(), ':time' => time(), ':content'=>''));
} }
public function __construct() public function __construct()
{ {

View file

@ -0,0 +1,38 @@
<?php
namespace App\Controllers\Api\Images\Comments;
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json};
class Delete
{
public function __construct()
{
$postId = explode('/', $_SERVER['REQUEST_URI'])[4];
$data = DB::query('SELECT * FROM photos_comments WHERE id=:id', array(':id' => $postId))[0];
$content = json_decode($data['content'], true);
$postuserid = DB::query('SELECT user_id FROM photos_comments WHERE id=:id', array(':id' => $postId))[0]['user_id'];
if ($postuserid === Auth::userid()) {
$json_arr = $content;
$json_arr['deleted'] = 'true';
$json_str_updated = json_encode($json_arr);
DB::query('UPDATE photos_comments SET content=:c WHERE id=:id', array(':id' => $postId, ':c'=>$json_str_updated));
echo json_encode(
array(
'errorcode' => '0',
'error' => 0,
'postid' => $postId
)
);
} else {
echo json_encode(
array(
'errorcode' => '1',
'error' => 1
)
);
}
}
}

View file

@ -13,19 +13,20 @@ class Load
public function __construct() public function __construct()
{ {
$comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid'=>explode('/', $_SERVER['REQUEST_URI'])[4])); $comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid' => explode('/', $_SERVER['REQUEST_URI'])[4]));
$number = 1; $number = 1;
foreach ($comments as $c) { foreach ($comments as $c) {
$comm = new Comment($c); $comm = new Comment($c);
if ($comm->content('deleted') != 'true') {
if ($number % 2 == 0) { if ($number % 2 == 0) {
$class = 's11'; $class = 's11';
} else { } else {
$class = 's1'; $class = 's1';
}
$comm->class($class);
$number++;
$comm->i();
} }
$comm->class($class);
$number++;
$comm->i();
} }
} }
} }

View file

@ -15,6 +15,7 @@ use \App\Controllers\Api\Images\Favorite as PhotoFavorite;
use \App\Controllers\Api\Images\Stats as PhotoStats; use \App\Controllers\Api\Images\Stats as PhotoStats;
use \App\Controllers\Api\Images\Comments\Create as PhotoComment; use \App\Controllers\Api\Images\Comments\Create as PhotoComment;
use \App\Controllers\Api\Images\Comments\Edit as PhotoCommentEdit; use \App\Controllers\Api\Images\Comments\Edit as PhotoCommentEdit;
use \App\Controllers\Api\Images\Comments\Delete as PhotoCommentDelete;
use \App\Controllers\Api\Images\Comments\Load as PhotoCommentLoad; use \App\Controllers\Api\Images\Comments\Load as PhotoCommentLoad;
use \App\Controllers\Api\Images\Comments\Rate as PhotoCommentVote; use \App\Controllers\Api\Images\Comments\Rate as PhotoCommentVote;
use \App\Controllers\Api\Profile\Update as ProfileUpdate; use \App\Controllers\Api\Profile\Update as ProfileUpdate;
@ -48,6 +49,9 @@ class ApiController
public static function photocommentedit() { public static function photocommentedit() {
return new PhotoCommentEdit(); return new PhotoCommentEdit();
} }
public static function photocommentdelete() {
return new PhotoCommentDelete();
}
public static function photocommentvote() { public static function photocommentvote() {
return new PhotoCommentVote(); return new PhotoCommentVote();
} }

View file

@ -60,6 +60,7 @@ class Routes
Router::get('/api/photo/checkall', 'ApiController@checkallphotos'); Router::get('/api/photo/checkall', 'ApiController@checkallphotos');
Router::get('/api/photo/comment/rate', 'ApiController@photocommentvote'); Router::get('/api/photo/comment/rate', 'ApiController@photocommentvote');
Router::post('/api/photo/comment/$id/edit', 'ApiController@photocommentedit'); Router::post('/api/photo/comment/$id/edit', 'ApiController@photocommentedit');
Router::post('/api/photo/comment/$id/delete', 'ApiController@photocommentdelete');
if ($user->i('admin') > 0) { if ($user->i('admin') > 0) {
Router::any('/admin', 'AdminController@index'); Router::any('/admin', 'AdminController@index');
Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis'); Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis');

View file

@ -14,6 +14,10 @@ class Comment {
public function class($class) { public function class($class) {
$this->class = $class; $this->class = $class;
} }
public function content($table) {
$content = json_decode($this->c['content'], true);
return $content[$table];
}
public function i() { public function i() {
$user = new User($this->c['user_id']); $user = new User($this->c['user_id']);
$content = json_decode($this->c['content'], true); $content = json_decode($this->c['content'], true);
@ -83,7 +87,7 @@ class Comment {
<div class="dropdown"> <div class="dropdown">
<a style="color: #000" class="compl" href="/lk/ticket.php?action=add&amp;wid=3252565">...</a> <a style="color: #000" class="compl" href="/lk/ticket.php?action=add&amp;wid=3252565">...</a>
<div class="dropdown-content">'; ?> <div class="dropdown-content">'; ?>
<a href="#" onclick="createModal(<?=$this->c['id']?>, 'EDIT_COMMENT', '<?=htmlspecialchars($this->c['body'])?>'); return false;">Редактировать</a><br> <a style="margin-bottom: 10px;" href="#" onclick="createModal(<?=$this->c['id']?>, 'EDIT_COMMENT', '<?=htmlspecialchars($this->c['body'])?>'); return false;">Редактировать</a><br>
<a href="#" onclick="createModal(<?=$this->c['id']?>, 'DELETE_COMMENT'); return false;">Удалить</a> <a href="#" onclick="createModal(<?=$this->c['id']?>, 'DELETE_COMMENT'); return false;">Удалить</a>
<?php <?php
echo ' echo '
@ -105,6 +109,7 @@ class Comment {
</div> </div>
</div>'; </div>';
} }
} }

View file

@ -1,11 +1,11 @@
:root { :root {
--theme-bg-color: #292929; --theme-bg-color: #292929;
--theme-bg-hover-color: #505050; --theme-bg-hover-color: #505050;
--theme-link-color: #3b7dc1; --theme-link-color: #686868;
--theme-link-visited-color: #5b7289; --theme-link-visited-color: #7e7e7e;
--theme-link-hover-bg-color: rgba(70, 135, 200, .15); --theme-link-hover-bg-color: rgba(70, 135, 200, .15);
--theme-link-underline-color: rgba(59, 125, 193, .3); --theme-link-underline-color: rgba(59, 125, 193, .3);
--theme-link-underline-visited-color: rgba(91, 114, 137, .3); --theme-link-underline-visited-color: rgba(68, 68, 68, 0.3);
--theme-preview-hover-bg-color: rgba(41, 90, 140, .7); --theme-preview-hover-bg-color: rgba(167, 167, 167, 0.7);
} }

View file

@ -3,12 +3,11 @@ function createModal(id, type, value) {
var modal = ` var modal = `
<div id="modal`+id+`" class="modal" style="display: block;"> <div id="modal`+id+`" class="modal" style="display: block;">
<div class="modal-content"> <div class="modal-content">
<span data-modal-id="`+id+`" class="close">&times;</span> <span data-close-modal-id="`+id+`" class="close">&times;</span>
<h3><b>Отредактировать комментарий</b></h3> <h3><b>Отредактировать комментарий</b></h3>
<div style="padding:0 11px 11px"> <div style="padding:0 11px 11px">
<textarea style=" width: 100%; <textarea style=" width: 100%;
height: 200px;" name="wtext" id="bodypost__commedit`+id+`">`+value+`</textarea><br> height: 200px;" name="wtext" id="bodypost__commedit`+id+`">`+value+`</textarea><br>
<p id="statusSend" style="display: none;">Ошибка</p>
<div class="cmt-submit"> <div class="cmt-submit">
<button type="submit" onclick="editComment('` + id + `', document.getElementById('bodypost__commedit` + id + `').value)" id="sbmt">Отредактировать</button>&ensp;&emsp;Ctrl + Enter <button type="submit" onclick="editComment('` + id + `', document.getElementById('bodypost__commedit` + id + `').value)" id="sbmt">Отредактировать</button>&ensp;&emsp;Ctrl + Enter
</div> </div>
@ -16,15 +15,30 @@ function createModal(id, type, value) {
</div> </div>
</div>`; </div>`;
} }
if (type === 'DELETE_COMMENT') {
var modal = `
<div id="modal`+id+`" class="modal" style="display: block;">
<div class="modal-content">
<span data-close-modal-id="`+id+`" class="close">&times;</span>
<h3><b>Удалить комментарий</b></h3>
Вы действительно хотите удалить комментарий? Действие необратимо.
<div style="margin-top: 35px;">
<div class="cmt-submit">
<button type="submit" onclick="deleteComment('` + id + `')" id="sbmt">Удалить</button>
<button data-close-modal-id="`+id+`" type="submit" id="sbmt">Отмена</button>
</div>
</div>
</div>
</div>`;
}
document.body.innerHTML += modal; document.body.innerHTML += modal;
} }
document.addEventListener("click", function(event) { document.addEventListener("click", function(event) {
if (event.target.classList.contains("close")) { var modalId = event.target.getAttribute("data-close-modal-id");
var modalId = event.target.getAttribute("data-modal-id"); document.getElementById("modal" + modalId).style.display = "none";
document.getElementById("modal" + modalId).style.display = "none";
}
var modals = document.querySelectorAll(".modal"); var modals = document.querySelectorAll(".modal");
modals.forEach(function(modal) { modals.forEach(function(modal) {
@ -78,3 +92,57 @@ const editComment = (postId, body) => {
}); });
}); });
} }
const deleteComment = (postId) => {
$(document).ready(function() {
$.ajax({
type: "POST",
url: '/api/photo/comment/'+postId+'/delete',
success: function(response) {
var jsonData = JSON.parse(response);
console.log(response);
if (jsonData.errorcode == "1") {
Notify.noty('danger', JSON.stringify(response));
} else {
document.getElementById("modal" + postId).style.display = "none";
Notify.noty('success', 'Успешно удалено!');
const url = window.location.pathname;
const segments = url.split('/');
const id = segments[segments.length - 1];
const commcountElem = document.getElementById('commcount');
let innerHTML = commcountElem.innerHTML;
let match = innerHTML.match(/>(\d+)</);
console.log(match);
if (match) {
let count = parseInt(match[1], 10) - 1;
console.log(count);
let newHTML = innerHTML.replace(match[1], count);
commcountElem.innerHTML = newHTML;
}
$.ajax({
type: "POST",
url: "/api/photo/getcomments/"+id,
processData: false,
async: true,
success: function(r) {
$('#posts').html(r)
},
error: function(r) {
console.log(r)
}
});
}
}
});
});
}

View file

@ -37,20 +37,20 @@ if (isset($_POST['create'])) {
<h1><b>Создание модели</b></h1> <h1><b>Создание модели</b></h1>
<label>Сущность</label> <label>Сущность</label>
<select id="entitySelect" class="form-select" aria-label="Default select example"> <select id="entitySelect" class="form-select" aria-label="Default select example">
<option selected disabled>Выберите сущность</option> <option selected disabled>Выберите сущность</option>
<?php <?php
$datad = DB::query('SELECT * FROM entities'); $datad = DB::query('SELECT * FROM entities');
foreach ($datad as $d) { foreach ($datad as $d) {
echo '<option value="'.$d['id'].'" style="background-color: '.$d['color'].'">'.$d['title'].'</option>'; echo '<option value="' . $d['id'] . '" style="background-color: ' . $d['color'] . '">' . $d['title'] . '</option>';
} }
?> ?>
</select> </select>
<form action="/admin?type=EntityCreate" method="post" name="form" id="form" enctype="multipart/form-data" style="display:inline-block; min-width:500px;"> <form action="/admin?type=EntityCreate" method="post" name="form" id="form" enctype="multipart/form-data" style="display:inline-block; min-width:500px;">
<button id="addButton" type="submit" name="create" class="btn btn-primary mt-5">Добавить модель</button> <button id="addButton" type="submit" name="create" class="btn btn-primary mt-5">Добавить модель</button>
@ -58,28 +58,28 @@ if (isset($_POST['create'])) {
<script> <script>
document.getElementById('entitySelect').addEventListener('change', function() { document.getElementById('entitySelect').addEventListener('change', function() {
const selectedValue = this.value; const selectedValue = this.value;
if (selectedValue) { if (selectedValue) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open('GET', "/api/admin/getvehicleinputs/"+selectedValue, true); xhr.open('GET', "/api/admin/getvehicleinputs/" + selectedValue, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
document.getElementById('form').innerHTML = '';
document.getElementById('form').innerHTML = '<button id="addButton" type="submit" name="create" class="btn btn-primary mt-5">Добавить модель</button>';
document.getElementById('form').insertAdjacentHTML('afterbegin', xhr.responseText); xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
} else { if (xhr.status === 200) {
console.error('Ошибка при загрузке данных:', xhr.statusText); document.getElementById('form').innerHTML = '';
document.getElementById('form').innerHTML = '<button id="addButton" type="submit" name="create" class="btn btn-primary mt-5">Добавить модель</button>';
document.getElementById('form').insertAdjacentHTML('afterbegin', xhr.responseText);
} else {
console.error('Ошибка при загрузке данных:', xhr.statusText);
}
} }
} };
};
xhr.send();
xhr.send(); }
} });
});
</script> </script>

View file

@ -363,15 +363,21 @@ if ($photo->i('id') !== null) {
<?php <?php
if ($photo->i('moderated') === 1) { if ($photo->i('moderated') === 1) {
$comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid' => $id)); $comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid' => $id));
$commcount = 0;
foreach ($comments as $c) {
if (json_decode($c['content'], true)['deleted'] != 'true') {
$commcount++;
}
}
?> ?>
<div class="p0" id="pp-item-comments"> <div class="p0" id="pp-item-comments">
<h4 class="pp-item-header">Комментарии<span style="font-weight:normal"> <span style="color:#aaa">&middot;</span> <?= count($comments) ?></span></h4> <h4 class="pp-item-header">Комментарии<span id="commcount" style="font-weight:normal"> <span style="color:#aaa">&middot;</span> <?= $commcount ?></span></h4>
<div id="posts"> <div id="posts">
<?php <?php
$number = 1; $number = 1;
foreach ($comments as $c) { foreach ($comments as $c) {
$comm = new Comment($c); $comm = new Comment($c);
if ($comm->content('deleted') != 'true') {
if ($number % 2 == 0) { if ($number % 2 == 0) {
$class = 's11'; $class = 's11';
} else { } else {
@ -380,6 +386,7 @@ if ($photo->i('id') !== null) {
$comm->class($class); $comm->class($class);
$number++; $number++;
$comm->i(); $comm->i();
}
} }
?> ?>
</div> </div>