-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·148 lines (126 loc) · 3.82 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
require_once('helpers.php');
date_default_timezone_set("Europe/Moscow");
$is_auth = rand(0, 1);
$user_name = 'Alex'; // укажите здесь ваше имя
$catigories = ["Доски и лыжи", "Крепления", "Ботинки", "Одежда", "Инструменты", "Разное"];
$index = 0;
$num = count($catigories);
$advert = [
[
"name" => "2014 Rossignol District Snowboard",
"category" => "Доски и лыжи",
"price" => "10999",
"gif" => "img/lot-1.jpg"
],
[
"name" => "DC Ply Mens 2016/2017 Snowboard",
"category" => "Доски и лыжи",
"price" => "159999",
"gif" => "img/lot-2.jpg"
],
[
"name" => "Крепления Union Contact Pro 2015 года размер L/XL",
"category" => "Крепления",
"price" => "8000",
"gif" => "img/lot-3.jpg"
],
[
"name" => "Ботинки для сноуборда DC Mutiny Charocal",
"category" => "Ботинки",
"price" => "10999",
"gif" => "img/lot-4.jpg"
],
[
"name" => "Куртка для сноуборда DC Mutiny Charocal",
"category" => "Одежда",
"price" => "7500",
"gif" => "img/lot-5.jpg"
],
[
"name" => "Маска Oakley Canopy",
"category" => "Разное",
"price" => "5400",
"gif" => "img/lot-6.jpg"
],
];
/**
* Форматирует цену
* @param $price
* @return string
*/
function format_price($price) {
return number_format(ceil($price), 0, null, ' ') . '₽';
}
//шаблоны
$content = include_template('index.php', [
'index' => $index,
'num' => $num,
'catigories' => $catigories,
'advert' => $advert
]);
$layout_content = include_template('layout.php', [
'is_auth' => $is_auth,
'user_name' => $user_name,
'content' => $content,
'catigories' => $catigories,
'title' => 'YetiCave - Главная страница',
]);
print($layout_content);
//функция вычисляет оставшееся время
function show_date () {
$ts = time();
$ts_midnight = strtotime('tomorrow');
$new_day = $ts_midnight - $ts;
$hours = floor($new_day / 3600);
$minutes = floor(($new_day % 3600) / 60);
$main_time = $hours .':' . $minutes;
$first_class = "timer--finishing";
$class = "";
if ($hours <= 1) {
return array($main_time, $first_class);
} else {
return array($main_time, $class);
}
}
//подключаемся к Mysql
$link = mysqli_connect("localhost", "root", "password","yeticave");
mysqli_set_charset($link, "utf8");
//проверяем соединение
if (!$link) {
print("Ошибка подключения: " . mysqli_connect_error());
}
else {
print("Соединение установлено");
// выполнение запросов
}
//запрос на категории
$sql = "select * from catigories";
$result = mysqli_query($link, $sql);
if ($result) {
$lots = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
else {
print("Ошибка подключения: " . mysqli_connect_error());
}
//запрос на лоты
$sql = "select * from lots where last_data > now() order by date_create desc";
if ($result) {
$lots = mysqli_fetch_all($result, MYSQLI_ASSOC);
$content = include_template('index.php', [
'index' => $index,
'num' => $num,
'catigories' => $catigories,
'advert' => $advert
]);
}
else {
print("Ошибка подключения: " . mysqli_connect_error());
}
print($layout_content = include_template('layout.php', [
'is_auth' => $is_auth,
'user_name' => $user_name,
'content' => $content,
'catigories' => $catigories,
'title' => 'YetiCave - Главная страница',
]));