171 lines
4.3 KiB
PHP
171 lines
4.3 KiB
PHP
|
|
<?php
|
|||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|||
|
|
|
|||
|
|
set_time_limit(0);
|
|||
|
|
error_reporting(E_ALL);
|
|||
|
|
ini_set('display_errors', 1);
|
|||
|
|
|
|||
|
|
?>
|
|||
|
|
<!doctype html>
|
|||
|
|
<html>
|
|||
|
|
<head>
|
|||
|
|
<meta charset="utf-8">
|
|||
|
|
<title>Очистка файлов заявок по запросу</title>
|
|||
|
|
</head>
|
|||
|
|
|
|||
|
|
<body>
|
|||
|
|
<?php
|
|||
|
|
|
|||
|
|
$countAll = 0;
|
|||
|
|
$countDel = 0;
|
|||
|
|
|
|||
|
|
$count = 0;
|
|||
|
|
|
|||
|
|
$sum = 0;
|
|||
|
|
|
|||
|
|
$sqlObj = "SELECT DISTINCT `req_id` FROM `funnel_files` WHERE `req_id` > 0 ORDER BY `req_id` ASC";
|
|||
|
|
|
|||
|
|
$rezObj = mysql_query($sqlObj);
|
|||
|
|
|
|||
|
|
while ($obj = mysql_fetch_assoc($rezObj)) {
|
|||
|
|
|
|||
|
|
$userActive = true;
|
|||
|
|
|
|||
|
|
$sqlUser = "SELECT user_id, who_work FROM `requisitions` WHERE `id` = " . $obj['req_id'];
|
|||
|
|
|
|||
|
|
$rezUser = mysql_query($sqlUser);
|
|||
|
|
|
|||
|
|
$user = mysql_fetch_assoc($rezUser);
|
|||
|
|
|
|||
|
|
$userId = $user['who_work'];
|
|||
|
|
|
|||
|
|
if (!$userId) {
|
|||
|
|
$userId = $user['user_id'];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!$userId) {
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$agencyId = User::getAgencyIdForUser($userId);
|
|||
|
|
|
|||
|
|
if ($agencyId) {
|
|||
|
|
$agency = new User();
|
|||
|
|
$agency->get($agencyId);
|
|||
|
|
|
|||
|
|
if ($agency && isset($agency->id_tarif)) {
|
|||
|
|
$tarif = new \Tarif;
|
|||
|
|
$tarif->get($agency->id_tarif);
|
|||
|
|
$date_tarif = strtotime($agency->date_tarif);
|
|||
|
|
$date_end = $date_tarif + $tarif->period * 3600 * 24;
|
|||
|
|
$date_end_f = date("d.m.Y H:i", $date_end);
|
|||
|
|
$dney = ceil(($date_end - time()) / 24 / 3600);
|
|||
|
|
|
|||
|
|
echo " Удаляем файлы агентства " . $agencyId . " <br/>";
|
|||
|
|
echo $dney . " <br/>";;
|
|||
|
|
|
|||
|
|
if ($dney < -60) {
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
echo "Не найдено агентство " . $agencyId . " <br/>";
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
echo "Не найдено агентство для пользователя " . $userId . " <br/>";
|
|||
|
|
|
|||
|
|
$agency = new User();
|
|||
|
|
$agency->get($userId);
|
|||
|
|
|
|||
|
|
if ($agency && isset($agency->id_tarif)) {
|
|||
|
|
$tarif = new \Tarif;
|
|||
|
|
$tarif->get($agency->id_tarif);
|
|||
|
|
$date_tarif = strtotime($agency->date_tarif);
|
|||
|
|
$date_end = $date_tarif + $tarif->period * 3600 * 24;
|
|||
|
|
$date_end_f = date("d.m.Y H:i", $date_end);
|
|||
|
|
$dney = ceil(($date_end - time()) / 24 / 3600);
|
|||
|
|
|
|||
|
|
echo " Удаляем файлы агента " . $userId . " <br/>";
|
|||
|
|
echo $dney . " <br/>";;
|
|||
|
|
|
|||
|
|
if ($dney < -60) {
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
echo "Не найден агент " . $userId . " <br/>";
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!$userActive) {
|
|||
|
|
$countDel++;
|
|||
|
|
echo " Удаляем файлы заявки " . $obj['req_id'] . " <br/>";
|
|||
|
|
|
|||
|
|
$path = $_SERVER['DOCUMENT_ROOT'] . "/upload/funnels/req/" . $obj['req_id'] . "/";
|
|||
|
|
|
|||
|
|
$files = glob($path . '*', GLOB_MARK);
|
|||
|
|
|
|||
|
|
if (count($files) == 0) {
|
|||
|
|
echo "Нет файлов";
|
|||
|
|
} else {
|
|||
|
|
|
|||
|
|
foreach ($files as $file) {
|
|||
|
|
|
|||
|
|
$size = filesize($file);
|
|||
|
|
$sum = $sum + $size;
|
|||
|
|
|
|||
|
|
echo $file . " " . date("d.m.Y H:i:s.", filemtime($file)) . " size: " . formatSizeUnits($size) . "<br/>";
|
|||
|
|
//unlink($file);
|
|||
|
|
|
|||
|
|
$count++;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//удалить запись из таблицы
|
|||
|
|
//$sqlDelete = "DELETE FROM clients_files where req_id > 0 and req_id = " . $obj['req_id'];
|
|||
|
|
//mysql_query($sqlDelete);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$countAll++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
echo "Обработано " . $countAll . " записей <br/>";
|
|||
|
|
echo "Удалено " . $countDel . " записей <br/>";
|
|||
|
|
echo "Удалено " . $count . " файлов <br/>";
|
|||
|
|
echo "Удалено " .formatSizeUnits($sum);
|
|||
|
|
|
|||
|
|
function formatSizeUnits($bytes)
|
|||
|
|
{
|
|||
|
|
if ($bytes >= 1073741824)
|
|||
|
|
{
|
|||
|
|
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes >= 1048576)
|
|||
|
|
{
|
|||
|
|
$bytes = number_format($bytes / 1048576, 2) . ' MB';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes >= 1024)
|
|||
|
|
{
|
|||
|
|
$bytes = number_format($bytes / 1024, 2) . ' kB';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes > 1)
|
|||
|
|
{
|
|||
|
|
$bytes = $bytes . ' bytes';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes == 1)
|
|||
|
|
{
|
|||
|
|
$bytes = $bytes . ' byte';
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
$bytes = '0 bytes';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return $bytes;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
?>
|
|||
|
|
</body>
|
|||
|
|
</html>
|