mirror of
https://github.com/claradex/nativegallery.git
synced 2024-12-22 08:30:56 +03:00
some fixes
This commit is contained in:
parent
0bb61c96f1
commit
9b793811c5
11 changed files with 184 additions and 57 deletions
|
@ -13,13 +13,16 @@ class GetVehicleInputs
|
|||
public function __construct()
|
||||
{
|
||||
$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);
|
||||
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="Вагон метро">
|
||||
<label for="exampleFormControlInput1" class="form-label">' . $d['name'] . '</label>
|
||||
<input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="'.$d['name'].'" '.$imp.'>
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
38
app/Controllers/Api/Images/Comments/Delete.php
Normal file
38
app/Controllers/Api/Images/Comments/Delete.php
Normal 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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,19 +13,20 @@ class Load
|
|||
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;
|
||||
foreach ($comments as $c) {
|
||||
$comm = new Comment($c);
|
||||
|
||||
if ($number % 2 == 0) {
|
||||
$class = 's11';
|
||||
} else {
|
||||
$class = 's1';
|
||||
if ($comm->content('deleted') != 'true') {
|
||||
if ($number % 2 == 0) {
|
||||
$class = 's11';
|
||||
} else {
|
||||
$class = 's1';
|
||||
}
|
||||
$comm->class($class);
|
||||
$number++;
|
||||
$comm->i();
|
||||
}
|
||||
$comm->class($class);
|
||||
$number++;
|
||||
$comm->i();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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&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 '
|
||||
|
@ -105,6 +109,7 @@ class Comment {
|
|||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -3,12 +3,11 @@ 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">×</span>
|
||||
<span data-close-modal-id="`+id+`" class="close">×</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>  Ctrl + Enter
|
||||
</div>
|
||||
|
@ -16,15 +15,30 @@ function createModal(id, type, value) {
|
|||
</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">×</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");
|
||||
document.getElementById("modal" + modalId).style.display = "none";
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -37,20 +37,20 @@ if (isset($_POST['create'])) {
|
|||
<h1><b>Создание модели</b></h1>
|
||||
<label>Сущность</label>
|
||||
<select id="entitySelect" class="form-select" aria-label="Default select example">
|
||||
<option selected disabled>Выберите сущность</option>
|
||||
<?php
|
||||
$datad = DB::query('SELECT * FROM entities');
|
||||
foreach ($datad as $d) {
|
||||
echo '<option value="'.$d['id'].'" style="background-color: '.$d['color'].'">'.$d['title'].'</option>';
|
||||
}
|
||||
?>
|
||||
<option selected disabled>Выберите сущность</option>
|
||||
<?php
|
||||
$datad = DB::query('SELECT * FROM entities');
|
||||
foreach ($datad as $d) {
|
||||
echo '<option value="' . $d['id'] . '" style="background-color: ' . $d['color'] . '">' . $d['title'] . '</option>';
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
</select>
|
||||
<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>
|
||||
|
||||
|
||||
|
@ -58,28 +58,28 @@ if (isset($_POST['create'])) {
|
|||
|
||||
|
||||
<script>
|
||||
document.getElementById('entitySelect').addEventListener('change', function() {
|
||||
const selectedValue = this.value;
|
||||
document.getElementById('entitySelect').addEventListener('change', function() {
|
||||
const selectedValue = this.value;
|
||||
|
||||
if (selectedValue) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
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>';
|
||||
if (selectedValue) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', "/api/admin/getvehicleinputs/" + selectedValue, true);
|
||||
|
||||
document.getElementById('form').insertAdjacentHTML('afterbegin', xhr.responseText);
|
||||
|
||||
} else {
|
||||
console.error('Ошибка при загрузке данных:', xhr.statusText);
|
||||
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);
|
||||
|
||||
} else {
|
||||
console.error('Ошибка при загрузке данных:', xhr.statusText);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
});
|
||||
</script>
|
|
@ -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">·</span> <?= count($comments) ?></span></h4>
|
||||
<h4 class="pp-item-header">Комментарии<span id="commcount" style="font-weight:normal"> <span style="color:#aaa">·</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 {
|
||||
|
@ -380,6 +386,7 @@ if ($photo->i('id') !== null) {
|
|||
$comm->class($class);
|
||||
$number++;
|
||||
$comm->i();
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue