Joywork/ajax/getAdvertBudget.php
2026-05-22 21:21:54 +03:00

139 lines
8.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
if (isset($_SESSION['id']) && isset($_POST['user_id'])) {
$post = clearInputData($_POST);
$user_id = intval($post['user_id']);
$role_id = $post['role_id'];
$is_main_badge = ((int)$post['main_badge'] == 1);
$is_agency_summary = ((int)$post['is_agency'] == 1);
$is_office_user = false;
$is_department_user = false;
$user = new \User;
$user->get($user_id);
$user->checkPermissions($_SESSION['id']);
session_write_close();
$is_agency_summary = $is_main_badge && (((int)$post['is_agency'] == 1) || $user->users_admin);
$departments_inst = new Department();
$departments = $departments_inst->getDepartments((int)$user_id);
foreach ($departments as $department) {
if ($department['department_id'] == intval($user->department_id)) {
$is_department_user = true;
}
}
$advert_budgets = new AdvertBudgets();
if ((bool)$is_agency_summary || ($user->agencyId == $user_id)) {
$budgets = $advert_budgets->getAdvertBudgets(null, true);
$budget = $budgets;
} else {
$budgets = $advert_budgets->getAdvertBudgets($user_id);
$budget = $budgets[(int)$user_id];
}
/*echo "<!-- ";
var_export([(bool)$is_agency_summary, (int)$user->agency, (int)$user->users_admin, strpos($_SERVER['HTTP_REFERER'], '/users.php') == false]);
var_export($budgets);
echo " -->";*/
if ($is_main_badge) {
echo "<h3>";
echo "<img src=\"/images/coins.svg\" alt=\"coins\" style=\"vertical-align:bottom;margin-right:3px;height:19px;\" />";
echo "Рекламный бюджет";
echo "</h3>";
echo "<p>Всего: <span>". ((isset($budget['total'])) ? number_format($budget['total'], 0, ',', ' ') : 0) ." руб.</span></p>";
echo "<p>Доступно: <span class=\"". ((isset($budget['balance']) && (int)$budget['balance'] > 0) ? 'is_hight' : 'is_lower') ."\">". ((isset($budget['balance'])) ? number_format($budget['balance'], 0, ',', ' ') : 0) ." руб.</span></p>";
echo "<div class=\"jw__popup advert_budget_details\" style=\"min-width: 420px;\"></div>";
} else {
echo "<div>";
if ($is_agency_summary) {
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет Агентства</h4>";
} else {
if ($is_department_user) {
if ($user->agency)
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет агентства</h4>";
else if ($departments[$user->role_id]['role'] == 'admin_department')
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет Отдела и подчиненных</h4>";
else if ($departments[$user->role_id]['role'] == 'manager_office_menager')
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет менеджера Офиса и подчиненных агентов</h4>";
else if ($departments[$user->role_id]['role'] == 'manager_office')
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет менеджера Отдела и подчиненных агентов</h4>";
else if ($departments[$user->role_id]['role'] == 'agent')
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет агента Отдела</h4>";
else
$is_department_user = !($is_office_user = true);
}
if (!$is_department_user) {
if ($user->agency)
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет агентства</h4>";
else if ($user->manager > 0)
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет менеджера и подчиненных агентов</h4>";
else
echo "<h4 style='margin-bottom: 15px'>Рекламный бюджет агента</h4>";
}
}
$avito = ((isset($budget['avito_available'])) ? number_format($budget['avito_available'], 0, ',', ' ') : 0) ." руб.";
$cian = ((isset($budget['cian_available'])) ? number_format($budget['cian_available'], 0, ',', ' ') : 0) ." руб.";
$domclick = ((isset($budget['domclick_available'])) ? number_format($budget['domclick_available'], 0, ',', ' ') : 0) ." руб.";
$jcat = ((isset($budget['jcat_available'])) ? number_format($budget['jcat_available'], 0, ',', ' ') : 0) ." руб.";
$yandex = ((isset($budget['yandex_available'])) ? number_format($budget['yandex_available'], 0, ',', ' ') : 0) ." руб.";
echo "<dl style='padding: 15px 0 10px 0; border-top: 1px solid #c7c7c7'>";
//var_dump($budget);
if ($budget['avito_unlimited'])
echo "<dd>Avito:</dd>" . "<dt>не огран. (" . ((isset($budget['avito_amount'])) ? number_format($budget['avito_amount'], 0, ',', ' ') : 0) ." руб. из ∞ руб.)</dt>";
else
echo "<dd>Avito:</dd>" . "<dt class=\"". ((isset($budget['avito_available']) && (int)$budget['balance'] > 0) ? 'is_hight' : 'is_lower') ."\">$avito (" . ((isset($budget['avito_amount'])) ? number_format($budget['avito_amount'], 0, ',', ' ') : 0) ." руб. из ". ((isset($budget['avito'])) ? number_format($budget['avito'], 0, ',', ' ') : 0) ." руб.)</dt>";
if ($budget['cian_unlimited'])
echo "<dd>ЦИАН:</dd>" . "<dt>не огран. (" . ((isset($budget['cian_amount'])) ? number_format($budget['cian_amount'], 0, ',', ' ') : 0) ." руб. из ∞ руб.)</dt>";
else
echo "<dd>ЦИАН:</dd>" . "<dt class=\"". ((isset($budget['cian_available']) && (int)$budget['balance'] > 0) ? 'is_hight' : 'is_lower') ."\">$cian (" . ((isset($budget['cian_amount'])) ? number_format($budget['cian_amount'], 0, ',', ' ') : 0) ." руб. из ". ((isset($budget['cian'])) ? number_format($budget['cian'], 0, ',', ' ') : 0) ." руб.)</dt>";
if ($budget['domclick_unlimited'])
echo "<dd>ДомКлик:</dd>" . "<dt>не огран. (" . ((isset($budget['domclick_amount'])) ? number_format($budget['domclick_amount'], 0, ',', ' ') : 0) ." руб. из ∞ руб.)</dt>";
else
echo "<dd>ДомКлик:</dd>" . "<dt class=\"". ((isset($budget['domclick_available']) && (int)$budget['balance'] > 0) ? 'is_hight' : 'is_lower') ."\">$domclick (" . ((isset($budget['domclick_amount'])) ? number_format($budget['domclick_amount'], 0, ',', ' ') : 0) ." руб. из ". ((isset($budget['domclick'])) ? number_format($budget['domclick'], 0, ',', ' ') : 0) ." руб.)</dt>";
if ($budget['jcat_unlimited'])
echo "<dd>JCat:</dd>" . "<dt>не огран. (" . ((isset($budget['jcat_amount'])) ? number_format($budget['jcat_amount'], 0, ',', ' ') : 0) ." руб. из ∞ руб.)</dt>";
else
echo "<dd>JCat:</dd>" . "<dt class=\"". ((isset($budget['jcat_available']) && (int)$budget['balance'] > 0) ? 'is_hight' : 'is_lower') ."\">$jcat (" . ((isset($budget['jcat_amount'])) ? number_format($budget['jcat_amount'], 0, ',', ' ') : 0) ." руб. из ". ((isset($budget['jcat'])) ? number_format($budget['jcat'], 0, ',', ' ') : 0) ." руб.)</dt>";
if ($budget['yandex_unlimited'])
echo "<dd>Я.Недвижимость:</dd>" . "<dt class=\"is_hight\">не огран. (" . ((isset($budget['yandex_amount'])) ? number_format($budget['yandex_amount'], 0, ',', ' ') : 0) ." руб. из ∞ руб.)</dt>";
else
echo "<dd>Я.Недвижимость:</dd>" . "<dt class=\"". ((isset($budget['yandex_available']) && (int)$budget['balance'] > 0) ? 'is_hight' : 'is_lower') ."\">$yandex (" . ((isset($budget['yandex_amount'])) ? number_format($budget['yandex_amount'], 0, ',', ' ') : 0) ." руб. из ". ((isset($budget['yandex'])) ? number_format($budget['yandex'], 0, ',', ' ') : 0) ." руб.)</dt>";
echo "</dl>";
echo "<dl style='padding-top: 15px; border-top: 1px solid #c7c7c7'>";
echo "<dd>Всего:</dd>";
echo "<dt>". ((isset($budget['total'])) ? number_format($budget['total'], 0, ',', ' ') : 0) ." руб.</dt>";
echo "<dd>Списано:</dd>";
echo "<dt>". ((isset($budget['amount'])) ? number_format($budget['amount'], 0, ',', ' ') : 0) ." руб.</dt>";
echo "<dd>Доступно:</dd>";
echo "<dt class=\"". ((isset($budget['balance']) && (int)$budget['balance'] > 0) ? 'is_hight' : 'is_lower') ."\">". ((isset($budget['balance'])) ? number_format($budget['balance'], 0, ',', ' ') : 0) ." руб.</dt>";
echo "</dl>";
echo "</div>";
}
}
?>