-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
73 lines (64 loc) · 2.07 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
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
require_once('helpers.php');
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = mysqli_connect("127.0.0.1", "root", '', "doingsdone");
mysqli_set_charset($con, "utf8");
if ($con === false) {
print("Ошибка подключения: " . mysqli_connect_error());
}
else {
$sql = 'SELECT id, name FROM projects WHERE user_id = 1';
$result = mysqli_query($con, $sql);
if ($result) {
$projects = mysqli_fetch_all ($result, MYSQLI_ASSOC);
}
else {
$error = mysqli_error($con);
print("Ошибка MySQL: " . $error);
}
$sql = 'SELECT id, name, done, end_date, created_at, project_id FROM tasks WHERE user_id = 1';
$result = mysqli_query($con, $sql);
if ($result) {
$tasks = mysqli_fetch_all ($result, MYSQLI_ASSOC);
$show_complete_tasks = rand(0, 1);
$page_content = include_template('main.php', [
'show_complete_tasks' => $show_complete_tasks,
'projects' => $projects,
'tasks' => $tasks
]);
}
else {
$error = mysqli_error($con);
print("Ошибка MySQL: " . $error);
}
}
function project_count($tasks, $project){
$count = 0;
foreach($tasks as $task){
if ($project['id'] === $task['project_id']){
$count = $count + 1;
}
}
return $count;
}
function is_soon_expire($end_date, $start_date){
if ($end_date === null) {
return false;
}
$secs_in_hour = 3600;
$start_time = strtotime($end_date);
$end_time = strtotime($start_date);
$ts_diff = $end_time - $start_time;
$hours_until_end = floor($ts_diff / $secs_in_hour);
return $hours_until_end <= 24;
}
$layout_content = include_template('layout.php', [
'content' => $page_content,
'username' => 'Константин',
'title' => 'Дела в порядке'
]);
print($layout_content);
?>