0
I want to create a filter per month in the calendar.
Code:
<!DOCTYPE HTML>
<html lang="pt-pt">
<head>
<meta charset="UTF-8">
<title>Registo Refeições</title>
<?php
date_default_timezone_set('Europe/Lisbon');
$dates = date('Y/m/d');
$hoje = getdate(strtotime($dates));
$mes = array('', 'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
$ultimoDia = cal_days_in_month(CAL_GREGORIAN,
$hoje['mon'],
$hoje['year']);
$primeiraSemana = (($hoje['wday'] + 1) -
($hoje['mday'] - ((int)($hoje['mday'] / 6) * 7))) % 7;
?>
<style>
td { color: #000000;}
</style>
</head>
<body>
<h1>Estamos em <?= $hoje['year'] ?> de <?= $mes[$hoje["mon"]] ?></h1>
<p><?= sprintf('Hoje é dia <strong>%0d / %0d</strong>.',
$hoje['mday'], $hoje['mon'])
?></p>
<table >
<caption><h1><center><strong><?= $mes[$hoje["mon"]] ?> - <?= $hoje['year'] ?></strong></center></h1></caption>
<tr>
<th bgcolor="silver" align="center">Domingo</th>
<th bgcolor="silver" align="center">Segunda</th>
<th bgcolor="silver" align="center">Terça</th>
<th bgcolor="silver" align="center">Quarta</th>
<th bgcolor="silver" align="center">Quinta</th>
<th bgcolor="silver" align="center">Sexta</th>
<th bgcolor="silver" align="center">Sábado</th>
</tr>
<tr>
<form action="" method="POST">
<?php
for($semana = 0; $semana < $primeiraSemana; ++$semana) {
echo '<td> </td>';
}
for($dia = 1; $dia < $ultimoDia; ++$dia) {
if( $semana > 6 ) {
$semana = 0;
echo '</tr><tr>';
}
echo "<td bgcolor='#F5F5F5' align='center' data-semana=\"$semana\"><center><font size='2px'/>";
echo "<input type='checkbox' name='"; echo "arrachar[$dia][dia]"; echo"' value='$dia'> $dia<center>
<p><input type='checkbox' name='"; echo "arrachar[$dia][OpcaoA]"; echo"' value='Peq. Almoço'> Peq. Almoço
<p><input type='checkbox' name='"; echo "arrachar[$dia][opcaoB]"; echo"' value='Almoço'> Almoço
<p><input type='checkbox' name='"; echo "arrachar[$dia][opcaoB]"; echo"' value='Almoço Dieta'> Almoço (Dieta)
<p><input type='checkbox' name='"; echo "arrachar[$dia][opcaoC]"; echo"' value='Lanche'> Lanche
<p><input type='checkbox' name='"; echo "arrachar[$dia][opcaoD]"; echo"' value='Jantar'> Jantar
<p><input type='checkbox' name='"; echo "arrachar[$dia][opcaoD]"; echo"' value='Jantar Dieta'> Jantar (Dieta)</td>";
++$semana;
}
for(; $semana < 7; ++$semana) {
echo '<td> </td>';
}
?>
<?php
if( !empty( $_POST['dias'] ) ) {
foreach( $_POST['dias'] as $key => $values ) {
echo "<br />Semana $key<br />";
foreach( $values as $dias ) {
echo "$dias<br />";
}
}
}
?>
<input type="submit" name="submit" value="Marcar">
</form>
</tr>
</table>
</body>
I intend to create a combo with the months and when selecting the calendar modifies for the month chosen. In addition to creating the combo, I need to correct my code, since the month of March is 31 days and my calendar is only mounting 30 days.
Yes! But what problem are you bumping into? Everything works, you just failed to create a combo with the months and selecting the calendar modifies for the month chosen?
– Fabiano Monteiro
Yes, this is @Fabiano Monteiro, everything is working even to enter in the database, I lack this
– Bruno
I set up a calendar (input) with Jquery to mount the filter and change the html calendar, but your calendar is mounting days less for the chosen months. I can even answer your question with an added filter, but your code will need revisions for months to come.
– Fabiano Monteiro
So if you can put the code to the filter and indicate where I need to revise my code for the coming months. I appreciate your help
– Bruno
For example. Your code mounts the month of March with 30 days, but the month has 31 days.
– Fabiano Monteiro
I hadn’t noticed that yet, how can I get the calendar to work correctly
– Bruno
Edit your question and add more this problem if anyone can look. When I can, I see here again.
– Fabiano Monteiro
Okay, I’ll edit the question, but when you have a little time to help me I appreciate your help
– Bruno