Joywork/admin/ajax/domclick-parser.php

177 lines
5.3 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<style>
#domclick-parser {
display: flex;
flex-direction: column;
gap: 16px;
padding: 20px 35px;
background: white;
border: 1px solid #dedede;
margin-top: 20px;
}
#domclick-parser td, #domclick-parser th {
border: 1px solid #ddd;
padding: 8px;
}
#domclick-parser tr:nth-child(even){background-color: #f2f2f2;}
#domclick-parser tr:hover {background-color: #ddd;}
#domclick-parser th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #04AA6D;
color: white;
font-weight: bold;
}
</style>
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
function getParsers($parser_name = [])
{
$items = array();
foreach ($parser_name as $name)
{
$sql = "SELECT
dps.*
FROM
domclick_parser_stats dps
JOIN
(
SELECT
id
FROM domclick_parser_stats
WHERE
`state` = 'Старт'
AND `parser_name` = '{$name}'
ORDER BY `id`
DESC LIMIT 1
) sub
WHERE
dps.id >= sub.id
AND dps.parser_name = '{$name}'
";
$rez = mysql_query($sql);
if (mysql_num_rows($rez) > 0) {
while ($dbObject = mysql_fetch_assoc($rez)) {
$items[$dbObject['parser_name']][] = $dbObject;
}
}
}
return $items;
}
$items = getParsers(['moscow', 'spb', 'others']);
?>
<?php foreach ($items as $key => $item) {
$last_record = $item[count($item) - 1];
$status = 'Завершено';
if ($last_record && !in_array($last_record['state'], ['Завершено с ошибкой', 'Завершено успешно'])) {
$status = 'В процессе';
}
if ($last_record['state'] == 'Завершено с ошибкой') {
$status = 'Завершено с ошибкой';
}
if (!$last_record) {
$status = 'Парсер не был запущен';
}
$name = 'Другие';
if ($key == 'moscow') {
$name = 'Москва';
}
else if ($key == 'spb') {
$name = 'Санкт-Петербург';
}
?>
<div id="parser-<?= $key ?>" class="parser" data-type="<?= $key ?>" style="position: relative;">
<button
style="
position: absolute;
right: 36px;
top: 15px;
border: none;
background: #04AA6D;
font-weight: bold;
cursor: pointer;
color: white;
padding: 10px 20px;
border-radius: 4px;"
id="update-page"
>
Обновить Таблицу
</button>
<div>
<div id="domclick-parser">
<h2><?= $name ?> - <?= $status ?></h2>
<table>
<thead>
<tr>
<th>Действие</th>
<th>Количество Комплексов</th>
<th>Количество Объектов</th>
<th>Дата</th>
</tr>
</thead>
<tbody>
<?php
$colors = [
'Старт' => '#247d00',
'Создано' => '#2226f0',
'Обновлено' => '#2226f0',
'Удалено' => '#f02222',
'Завершено с ошибкой' => '#f02222',
'Завершено успешно' => '#247d00'
];
foreach ($item as $record) { ?>
<tr>
<td style="color: <?= $colors[$record['state']] ?>"><?= $record['state']?></td>
<td ><?= $record['complex_count'] > 0 ? $record['complex_count'] : '-' ?></td>
<td ><?= $record['object_count'] > 0 ? $record['object_count'] : '-' ?></td>
<td ><?= $record['updated_at']?></td>
</tr>
<?php } ?>
<!-- <tr>
<td>Старт</td>
<td>-</td>
<td>-</td>
<td>31.03.2024 16:25</td>
</tr>
<tr>
<td>Обновлено</td>
<td>10</td>
<td>20</td>
<td>31.03.2024 16:25</td>
</tr>
<tr>
<td>Удалено</td>
<td>2</td>
<td>0</td>
<td>30.03.2024 16:25</td>
</tr> -->
</tbody>
</table>
</div>
</div>
</div>
<?php } ?>