zebmckey
14-02-2018, 22:45
ho un problema con un piccolo calendario in php.
Praticamente mi restituisce tutti i mesi con 31 giorni. Come posso risolvere e assegnare ad ogni mese la giusta lunghezza?
calendario.inc
<?php
/**
* Calender class
*/
class Calender {
public $year = '';
public $month = '';
public $intToDay = array(
0=>'Sunday',
1=>'Moday',
2=>'Tuesday',
3=>'Wednesday',
4=>'Thursday' ,
5=>'Friday' ,
6=>'Saturday'
);
public $intToMonth = array(
1=>'January',
2=>'February',
3=>'March',
4=>'April' ,
5=>'May' ,
6=>'June' ,
7=>'July',
8=>'August',
9=>'September',
10=>'October',
11=>'November' ,
12=>'December'
);
/**
* constructor function
*/
public function Calender($year) {
$this->year = $year;
}
/**
* get code for
*
* @param int $month
*
*/
public function getCodeForMonth($month) {
$this->month = $month;
$startingDay = date("l", mktime(0, 0, 0, $month, 1, $this->year));
$returnCode = '<table border="1" align="center" style="color:brown"> <tr>';
for ($count = 0; $count < 7; $count++) {
$returnCode .= "<td align=\"center\" style=\"color:red\"><strong>".$this->intToDay[$count]."</strong></td>";
}
$returnCode .= "</tr> <tr>";
for ($count = 0; $count < array_search($startingDay, $this->intToDay); $count++) {
$returnCode .= "<td><br /></td>";
}
for ($counter = 1; $counter <= 31; $counter++, $count++) {
if (($count % 7) == 0) {
$returnCode .= "</tr> <tr>";
}
$returnCode .= "<td align=\"center\">".$counter."</td>";
}
$returnCode .= '</table>';
return $returnCode;
}
public function getCode($month) {
$this->month = $month;
$startingDay = date("l", mktime(0, 0, 0, $month, 1, $this->year));
$returnCode = '<table border="1" align="center" style="color:brown"> <tr>';
for ($count = 0; $count < 7; $count++) {
$returnCode .= "<td width=\"65\" align=\"center\" style=\"color:#000000;background-color:#6779AC\"><strong>".$this->intToDay[$count]."</strong></td>";
}
$returnCode .= "</tr> <tr>";
for ($count = 0; $count < array_search($startingDay, $this->intToDay); $count++) {
$returnCode .= "<td><br /></td>";
}
for ($counter = 1; $counter <= 31; $counter++, $count++) {
if (($count % 7) == 0) {
$returnCode .= "</tr> <tr>";
}
$monthName = $this->intToMonth[$month];
if ( ($month < date('n') || $this->year < date('Y')) )
{
$returnCode .= "<td align=\"center\" style=\"background-color:#ABCED6;\"><span><b>".trim($counter)."</b></span></td>";
}
else {
$returnCode .= "<td align=\"center\" style=\"background-color:#ABCED6;\"><span style=\"cursor:pointer;cursor:hand;background-color:#ABCED6;\" onclick=\"openWindow('$counter-$this->month-$this->year');\"><b>".trim($counter)."</b></span></td>";
}
}
$returnCode .= '</table>';
return $returnCode;
}
}
?>
test.php
<?php
require_once('calender.inc.php');
$calender = new Calender('2018');
for ($i = 0; $i < 12; $i++) {
$month = $i+1;
echo "<center><hr />".$calender->intToMonth[$month]." ".$calender->year."<hr /></center>".$calender->getCodeForMonth($i);
}
?>
<!--table align="center" width="80%" align="center" border="1">
<tr>
<td align="center" style="font-family:verdana;font-size:30">
<strong> <?php echo $calender->intToMonth[$calender->month].' '.$calender->year; ?></strong>
</td>
</tr>
<tr>
<td>
<?php echo $jan; ?>
</td>
</tr>
</table -->
Grazie per il vostro prezioso aiuto
Praticamente mi restituisce tutti i mesi con 31 giorni. Come posso risolvere e assegnare ad ogni mese la giusta lunghezza?
calendario.inc
<?php
/**
* Calender class
*/
class Calender {
public $year = '';
public $month = '';
public $intToDay = array(
0=>'Sunday',
1=>'Moday',
2=>'Tuesday',
3=>'Wednesday',
4=>'Thursday' ,
5=>'Friday' ,
6=>'Saturday'
);
public $intToMonth = array(
1=>'January',
2=>'February',
3=>'March',
4=>'April' ,
5=>'May' ,
6=>'June' ,
7=>'July',
8=>'August',
9=>'September',
10=>'October',
11=>'November' ,
12=>'December'
);
/**
* constructor function
*/
public function Calender($year) {
$this->year = $year;
}
/**
* get code for
*
* @param int $month
*
*/
public function getCodeForMonth($month) {
$this->month = $month;
$startingDay = date("l", mktime(0, 0, 0, $month, 1, $this->year));
$returnCode = '<table border="1" align="center" style="color:brown"> <tr>';
for ($count = 0; $count < 7; $count++) {
$returnCode .= "<td align=\"center\" style=\"color:red\"><strong>".$this->intToDay[$count]."</strong></td>";
}
$returnCode .= "</tr> <tr>";
for ($count = 0; $count < array_search($startingDay, $this->intToDay); $count++) {
$returnCode .= "<td><br /></td>";
}
for ($counter = 1; $counter <= 31; $counter++, $count++) {
if (($count % 7) == 0) {
$returnCode .= "</tr> <tr>";
}
$returnCode .= "<td align=\"center\">".$counter."</td>";
}
$returnCode .= '</table>';
return $returnCode;
}
public function getCode($month) {
$this->month = $month;
$startingDay = date("l", mktime(0, 0, 0, $month, 1, $this->year));
$returnCode = '<table border="1" align="center" style="color:brown"> <tr>';
for ($count = 0; $count < 7; $count++) {
$returnCode .= "<td width=\"65\" align=\"center\" style=\"color:#000000;background-color:#6779AC\"><strong>".$this->intToDay[$count]."</strong></td>";
}
$returnCode .= "</tr> <tr>";
for ($count = 0; $count < array_search($startingDay, $this->intToDay); $count++) {
$returnCode .= "<td><br /></td>";
}
for ($counter = 1; $counter <= 31; $counter++, $count++) {
if (($count % 7) == 0) {
$returnCode .= "</tr> <tr>";
}
$monthName = $this->intToMonth[$month];
if ( ($month < date('n') || $this->year < date('Y')) )
{
$returnCode .= "<td align=\"center\" style=\"background-color:#ABCED6;\"><span><b>".trim($counter)."</b></span></td>";
}
else {
$returnCode .= "<td align=\"center\" style=\"background-color:#ABCED6;\"><span style=\"cursor:pointer;cursor:hand;background-color:#ABCED6;\" onclick=\"openWindow('$counter-$this->month-$this->year');\"><b>".trim($counter)."</b></span></td>";
}
}
$returnCode .= '</table>';
return $returnCode;
}
}
?>
test.php
<?php
require_once('calender.inc.php');
$calender = new Calender('2018');
for ($i = 0; $i < 12; $i++) {
$month = $i+1;
echo "<center><hr />".$calender->intToMonth[$month]." ".$calender->year."<hr /></center>".$calender->getCodeForMonth($i);
}
?>
<!--table align="center" width="80%" align="center" border="1">
<tr>
<td align="center" style="font-family:verdana;font-size:30">
<strong> <?php echo $calender->intToMonth[$calender->month].' '.$calender->year; ?></strong>
</td>
</tr>
<tr>
<td>
<?php echo $jan; ?>
</td>
</tr>
</table -->
Grazie per il vostro prezioso aiuto