-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
67 lines (59 loc) · 1.85 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once('constants.php');
require('helpers.php');
require_once('db_functions.php');
$page_title = 'Интернет-аукцион YetiCave';
// Temporary placeholder -- authorization to be implemented later
$is_auth = rand(0, 1);
$user_name = 'Андрей';
function format_price($lot_price): string
{
$rounded_price = ceil($lot_price);
if ($rounded_price < 1000) {
$displayed_price = $rounded_price;
} else {
$displayed_price = number_format($rounded_price, 0, ',', ' ');
}
return $displayed_price . ' ₽';
}
// Create connection and set encoding
mysqli_report(MYSQLI_REPORT_OFF);
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($conn == false) {
print('Ошибка подключения: ' . mysqli_connect_error());
}
mysqli_set_charset($conn, 'utf8');
// Selecting lots for front page
$sql = "SELECT
yeticave.lots.id,
yeticave.lots.name,
yeticave.lots.img_url,
yeticave.lots.initial_price,
yeticave.categories.name AS category,
yeticave.lots.date_expiry AS date_expiry
FROM
yeticave.lots
INNER JOIN yeticave.categories ON lots.category_id = categories.id
WHERE
lots.winner_id IS NULL
AND lots.date_expiry > NOW()
GROUP BY
lots.id
ORDER BY
lots.date_created DESC";
$result = mysqli_query($conn, $sql);
$lots = mysqli_fetch_all($result, MYSQLI_ASSOC);
// Get names and codes of categories for main content template and for layout template
$categories = get_categories();
// Closing database connection
mysqli_close($conn);
// Preparing content template and layout template
$content = include_template('main.php', ['categories' => $categories, 'lots' => $lots]);
$layout_template = include_template('layout.php', [
'content' => $content,
'page_title' => $page_title,
'is_auth' => $is_auth,
'user_name' => $user_name,
'categories' => $categories
]);
print $layout_template;