';
$stats = [];
if ($query = mysql_query($sql)) {
while ($stat = mysql_fetch_assoc($query)) {
$stats[] = $stat;
}
$num = 0;
$targets = array_merge($PROMO_TARGETS, $ZIPAL_TARGETS);
$columns = array_column($stats, 'publish_start_date');
array_multisort($columns, SORT_DESC, $stats);
foreach ($stats as $stat) {
$num++;
$targetName = $targets[$stat['destination']];
if (in_array($stat['destination'], array_keys($PROMO_TARGETS)))
$stat['type'] = 'promotion';
else
$stat['type'] = 'regular';
if (!$stat['fio']) {
if ($stat['middle_name']) {
$stat['fio'] = $stat['last_name'] . " " . $stat['first_name'] . " " . $stat['middle_name'];
} else {
$stat['fio'] = $stat['last_name'] . " " . $stat['first_name'];
}
}
if ($stat['agency']) {
$master = "Агентство " . $stat['fio'];
} else if ($stat['manager']) {
$master = "Менеджер " . $stat['fio'];
} else {
$master = "Агент " . $stat['fio'];
}
$dateTime = strtotime($time_zone, strtotime($stat['publish_start_date']));
$dateFromRow = date('d', $dateTime) . ' ' . getRusMonth(date('m', $dateTime)) . ' ' . date('Y', $dateTime);
if (!$targetName)
$targetName = $stat['destination'];
$item = '
';
$item .= '';
$item .= '
' .date('H:i:s', $dateTime) . '';
$item .= '
';
if ($stat['type'] == 'promotion')
$item .= '
Продвижение от ' . trim($targetName) . '';
else
$item .= '
Выставлено ' . ((strpos($targetName, 'Фид') !== false) ? 'в ' : 'на ') . trim($targetName) . '';
$info = [];
if ($stat['days_count'] == 5000)
$info[] = ', бессрочно' ;
else if ($stat['days_count'] > 0)
$info[] = ' срок ' . declOfNum($stat['days_count'], ['%d день', '%d дня', '%d дней']) . ' (до ' . date('d.m.Y', strtotime($stat['publish_end_date'])) . ')';
$price_string = 'бесплатно';
if ($stat['type'] == 'promotion' && ($_SESSION['users_admin'] || $_SESSION['agency'])) {
if ($stat['price'] > 0)
$price_string = (((float)$stat['price'] < 1) ? declOfNum((float)$stat['price'] * 100, ['%d копейка', '%d копейки', '%d копеек']) : declOfNum((float)$stat['price'], ['%s рубль', '%s рубля', '%s рублей']));
else
$price_string = 'бесплатно';
$info[] = ' сумма
' . $price_string . ' ' .
'
';
} else if ($stat['type'] == 'regular' && ($_SESSION['users_admin'] || $_SESSION['agency'])) {
if ($stat['price'] > 0)
$price_string = (((float)$stat['price'] < 1) ? declOfNum((float)$stat['price'] * 100, ['%d копейка', '%d копейки', '%d копеек']) : declOfNum((float)$stat['price'], ['%s рубль', '%s рубля', '%s рублей']));
else
$price_string = 'бесплатно';
$info[] = ' сумма
' . $price_string . ' ' .
'
';
} else {
$info[] = ' сумма ' . (((float)$stat['price'] < 1) ? declOfNum((float)$stat['price'] * 100, ['%d копейка', '%d копейки', '%d копеек']) : declOfNum((float)$stat['price'], ['%s рубль', '%s рубля', '%s рублей']));
}
if ($stat['unpublish_user_id']) {
$user = mysql_fetch_assoc(mysql_query("SELECT agency, manager, fio, last_name, first_name, middle_name FROM users WHERE id=$stat[unpublish_user_id]"));
$master = '-';
if ($user) {
if (!$user['fio']) {
if ($user['middle_name']) {
$user['fio'] = $user['last_name'] . " " . $user['first_name'] . " " . $user['middle_name'];
} else {
$user['fio'] = $user['last_name'] . " " . $user['first_name'];
}
}
if ($user['agency'])
$master = "Агентство $user[fio]";
else if ($user['manager'])
$master = "Менеджер $user[fio]";
else
$master = "Агент $user[fio]";
}
$info[] = ' снято с публикации ' . date('d.m.Y H:i:s', strtotime($time_zone, strtotime($stat['updated_at']))) . ' пользователем ' . $master;
} else {
if ($stat['unpublish_user_id'] == '0')
$info[] = ' снято с публикации автоматически ' . date('d.m.Y H:i:s', strtotime($time_zone, strtotime($stat['publish_end_date'])));
}
$item .= implode(', ', $info);
$item .= '
';
$item .= '
';
$item .= '';
$date_key = date('Y-m-d', strtotime($stat['publish_start_date']));
$stats_items[$date_key]['items'][] = $item;
$stats_items[$date_key]['total'] += (float)$stat['price'];
$totalSum += (float)$stat['price'];
}
}
if (!empty($stats_items)) {
$key = 1000;
foreach ($stats_items as $stat_date => $stat_data) {
echo '
';
}
}
$totalSumText = $totalSum < 1 ? declOfNum($totalSum * 100, array('%d копейка', '%d копейки', '%d копеек')) : declOfNum($totalSum, array('%s рубль', '%s рубля', '%s рублей'));
echo '';
echo '