Fix photos

This commit is contained in:
Alan
2026-02-16 22:38:47 +03:00
parent a755a8e5c4
commit b4bc91f545
6 changed files with 43 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
<!-- Хлебные крошки /-->
<ul class="breadcrumb">
<li><a href="/">Главная</a></li>
<li><a href="/repairs/">Акции</a></li>
<li><a href="/repairs/">Автосервис</a></li>
<li>{$post->name|escape}</li>
</ul>
<!-- Хлебные крошки #End /-->

View File

@@ -2,7 +2,7 @@ create table s_repair_photo
(
id int auto_increment
primary key,
action_id int default 0 not null,
repair_id int default 0 not null,
img varchar(100) default '' not null,
position int default 0 not null
)

View File

@@ -80,7 +80,7 @@ class RepairsPostAdmin extends Simpla
$this->design->assign('post', $post);
$this->db->query("SELECT * FROM __repairs_photo WHERE repair_id='" . $post->id . "' ORDER BY position, id DESC");
$this->db->query("SELECT * FROM __repair_photo WHERE repair_id='" . $post->id . "' ORDER BY position, id DESC");
$photos = $this->db->results();
foreach($photos as $ph) $ph->img = Img::get('files/post/' . $ph->img, array('width'=>120, 'height'=>120));
$this->design->assign('repair_photos', $photos);

View File

@@ -0,0 +1,38 @@
<?php
chdir('../..');
require_once('api/Simpla.php');
$simpla = new Simpla();
if(isset($_POST['action']) && $_POST['action'] == 'remove'){
$simpla->db->query("DELETE FROM __repair_photo WHERE id=" . (int)$_POST['id']);
die;
}
if(isset($_POST['action']) && $_POST['action'] == 'reorder'){
foreach($_POST['ids'] as $pos => $id){
$simpla->db->query("UPDATE __repair_photo SET position='$pos' WHERE id='" . (int)$id ."' " );
}
die;
}
$ext = mb_strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1), 'UTF-8');
$name = $_POST['article_id'] . '_' . md5( uniqid( $_POST['article_id'] . rand(1, 10000), true) ) . '.' . $ext;
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/files/post/' . $name);
$simpla->db->query("INSERT INTO __repair_photo SET repair_id='" . (int)$_POST['article_id'] ."', img='$name', position=999 " );
echo $simpla->db->insert_id();
//print_r($_POST); print_r($_FILES);
//echo 3;
//echo json_encode(array('id'=>44, 'img'=>'test'));

View File

@@ -38,7 +38,7 @@
$(function(){
var sxFile = new sxFormFile();
{/literal}
sxFile.init({$post->id}, '/simpla/ajax/file_action.php');
sxFile.init({$post->id}, '/simpla/ajax/file_repair.php');
{literal}
})
</script>

View File

@@ -120,7 +120,7 @@ function translit(str)
<!-- Системное сообщение -->
<div class="message message_success">
<span>{if $message_success == 'added'}Запись добавлена{elseif $message_success == 'updated'}Запись обновлена{/if}</span>
<a class="link" target="_blank" href="../blog/{$post->url}">Открыть запись на сайте</a>
<a class="link" target="_blank" href="../repairs/{$post->url}">Открыть запись на сайте</a>
{if $smarty.get.return}
<a class="button" href="{$smarty.get.return}">Вернуться</a>
{/if}