/
calendario.php
159 lines (131 loc) · 4.2 KB
/
calendario.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
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calendario</title>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<style type="text/css">
.titulo{
float: left;
font-size: 30pt;
font-family: helvetica;
color: white;
text-align: center;
font-weight: bold;
margin: 0 0 0 250px;
}
.imagen_cerrar{
float: left;
width:50px;
height:50px;
border-style: groove;
border-width: 0px;
margin: 0 0 0 220px;
border-radius: 5px;
}
body{margin:0;
font-family:Lato;
}
ul,li{list-style-type:none;
margin:0;padding:0;}
.calendar{padding: 10px 0px 0px 40px;}
.calendar
.day{background:#ecf0f1;
border-bottom:2px solid #bdc3c7;
float:left;
padding-left: 20px;
margin:1px;
position:relative;
height:100px;
width:100px;}
.day.marked{background:#3498db;
border-color:#2980b9;}
.day .day-number{color:#7f8c8d;
left:5px;
position:absolute;top:5px;}
.day.marked
.day-number{color:white;}.day
.events{color:white;
margin: 22px 7px 5px;
height:78px;
overflow-x:hidden;
overflow-y:hidden;}.day
.events h5{margin:0 0 5px;
overflow:hidden;text-overflow:ellipsis;
white-space:nowrap;width:100%;}.day .events strong,.day .events span{display:block;font-size:8px;}.day .events ul{}.day .events li{}</style>
</head>
<body Background="imagenes\fondo.jpg">
<div class="calendar">
<?php
$mysqli = new mysqli('localhost', 'root', '1234', 'empresalogistica');
if ( $mysqli->connect_errno )
{
die( $mysqli->mysqli_connect_error() );
}
$result = $mysqli->query('SELECT * FROM viaje');
if( !$result )
die( $mysqli->error );
$events = array();
while($row = $result->fetch_assoc())
{
$start_date = new DateTime($row['fecha_partida']);
$end_date = new DateTime($row['fecha_llegada']);
$day = $start_date->format('j');
$events[$day][] = array(
'start_hour' => $start_date->format('G:i a'),
'end_hour' => $end_date->format('G:i a'),
'description' => $row['tipo_carga']
);
}
$datetime = new DateTime();
// mes en texto
$txt_months = array(
'Enero', 'Febrero', 'Marzo',
'Abril', 'Mayo', 'Junio',
'Julio', 'Agosto', 'septiembre',
'Octubre', 'Noviembre', 'Diciembre'
);
$month_txt = $txt_months[$datetime->format('n')-1];
// ultimo dia del mes
$month_days = date('j', strtotime("last day of"));
//cabecera del calendario
echo '<div class="titulo">' . $month_txt . '</div><a href="menu_supervisor.php"><img src="imagenes\cerrar.png" class="imagen_cerrar"/></a><br><br><br>';
foreach(range(1, $month_days) as $day)
{
$marked = false;
$events_list = array();
foreach($events as $event_day => $event)
{
// si el dia del evento coincide lo marcamos y guardamos la informacion
if($event_day == $day)
{
$marked = true;
$events_list = $event;
break;
}
}
echo '
<div class="day' . ($marked ? ' marked' : '') . '">
<strong class="day-number">' . $day . '</strong>
<div class="events"><ul>';
foreach($events_list as $event)
{
echo '<li>
<h5>' . $event['description'] . '</h5>
<div>
<strong>Inicio:</strong>
<span>' . $event['start_hour'] . '</span>
</div>
<div>
<strong>Fin:</strong>
<span>' . $event['end_hour'] . '</span>
</div>
</li>';
}
echo '</ul></div>
</div>';
}
?>
</div>
</body>
</html>