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

@ -16,10 +16,13 @@ class GetVehicleInputs
$vehicle = DB::query('SELECT * FROM entities WHERE id=:id', array(':id' => $id))[0];
$data = json_decode($vehicle['sampledata'], true);
foreach ($data as $d) {
if ($d['important'] === "1") {
$imp = 'required';
}
echo '
<div class="mb-3">
<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>';
}
}

View file

@ -12,7 +12,7 @@ class Create
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()
{

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

@ -17,7 +17,7 @@ class Load
$number = 1;
foreach ($comments as $c) {
$comm = new Comment($c);
if ($comm->content('deleted') != 'true') {
if ($number % 2 == 0) {
$class = 's11';
} else {
@ -29,3 +29,4 @@ class Load
}
}
}
}

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\Comments\Create as PhotoComment;
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\Rate as PhotoCommentVote;
use \App\Controllers\Api\Profile\Update as ProfileUpdate;
@ -48,6 +49,9 @@ class ApiController
public static function photocommentedit() {
return new PhotoCommentEdit();
}
public static function photocommentdelete() {
return new PhotoCommentDelete();
}
public static function photocommentvote() {
return new PhotoCommentVote();
}

View file

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

View file

@ -14,6 +14,10 @@ class Comment {
public function class($class) {
$this->class = $class;
}
public function content($table) {
$content = json_decode($this->c['content'], true);
return $content[$table];
}
public function i() {
$user = new User($this->c['user_id']);
$content = json_decode($this->c['content'], true);
@ -83,7 +87,7 @@ class Comment {
<div class="dropdown">
<a style="color: #000" class="compl" href="/lk/ticket.php?action=add&amp;wid=3252565">...</a>
<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>
<?php
echo '
@ -107,4 +111,5 @@ class Comment {
}
}

View file

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

View file

@ -3,28 +3,42 @@ function createModal(id, type, value) {
var modal = `
<div id="modal`+id+`" class="modal" style="display: block;">
<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>
<div style="padding:0 11px 11px">
<textarea style=" width: 100%;
height: 200px;" name="wtext" id="bodypost__commedit`+id+`">`+value+`</textarea><br>
<p id="statusSend" style="display: none;">Ошибка</p>
<div class="cmt-submit">
<button type="submit" onclick="editComment('` + id + `', document.getElementById('bodypost__commedit` + id + `').value)" id="sbmt">Отредактировать</button>&ensp;&emsp;Ctrl + Enter
</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.addEventListener("click", function(event) {
if (event.target.classList.contains("close")) {
var modalId = event.target.getAttribute("data-modal-id");
var modalId = event.target.getAttribute("data-close-modal-id");
document.getElementById("modal" + modalId).style.display = "none";
}
var modals = document.querySelectorAll(".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

@ -363,15 +363,21 @@ if ($photo->i('id') !== null) {
<?php
if ($photo->i('moderated') === 1) {
$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">
<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">
<?php
$number = 1;
foreach ($comments as $c) {
$comm = new Comment($c);
if ($comm->content('deleted') != 'true') {
if ($number % 2 == 0) {
$class = 's11';
} else {
@ -381,6 +387,7 @@ if ($photo->i('id') !== null) {
$number++;
$comm->i();
}
}
?>
</div>
<div class="cmt-write s1">