Mesačný kalendár

Trieda vytvorí mesačný kalendár podľa zadaných parametrov:
- $month: mesiac (povinné, od 1 do 12)
- $year: rok (povinné, od 1980 do 2050)
- $langCode: kód použitého jazyka (voliteľné, cz, sk, default = sk)
class kalendar {
var $month;
var $year;
var $langCode = '';
var $lang = array(
'cz' => array(
'month_error_numeric' => 'Měsíc musí být číslo!',
'month_error' => 'Měsíc musí být číslo od 1 do 12',
'year_error_numeric' => 'Rok musí být číslo!',
'year_error' => 'Rok musí být číslo od 1980 do 2050',
'days' => array( 1 => 'Po', 'Út', 'St', 'Čt', 'Pá', 'So', 'Ne' ),
'months'=> array( 1 => 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec' ),
),
'sk' => array(
'month_error_numeric' => 'Mesiac musí byť číslo!',
'month_error' => 'Mesiac musí byť číslo od 1 do 12',
'year_error_numeric' => 'Rok musí byť číslo!',
'year_error' => 'Rok musí byť číslo od 1980 do 2050',
'days' => array( 1 => 'Po', 'Ut', 'St', 'Št', 'Pi', 'So', 'Ne' ),
'months'=> array( 1 => 'január', 'február', 'marec', 'apríl', 'máj', 'jún', 'júl', 'august', 'september', 'október', 'november', 'december' ),
),
);
function kalendar( $month, $year, $langCode = 'sk' ) {
$this->month = $month;
$this->year = $year;
$this->langCode = $langCode;
}
function countDays() {
return cal_days_in_month( CAL_GREGORIAN, $this->month, $this->year );
}
function lastDay() {
$orderEN = date( 'w', mktime( 0, 0, 0, $this->month, 1, $this->year ) );
return ( $orderEN == 0 ) ? 7 : $orderEN;
}
function day( $row, $sloupec, $lastDay, $countDays ) {
if( $sloupec == 1 )
return $this->lang[$this->langCode]['days'][$row];
$chcivratit = ( $sloupec-2 )*7 + $row - $lastDay + 1;
if( $chcivratit < 1 || $chcivratit > $countDays )
return ' ';
else
return $chcivratit;
}
function write() {
// Validate input values: month, year
if( !is_numeric( $this->month ) ) {
echo $this->lang[$this->langCode]['month_error_numeric'];
return;
}
if( !is_numeric( $this->year ) ) {
echo $this->lang[$this->langCode]['year_error_numeric'];
return;
}
if( $this->month < 1 || $this->month > 12 ) {
echo $this->lang[$this->langCode]['month_error'];
return;
}
if( $this->year < 1980 || $this->year > 2050 ) {
echo $this->lang[$this->langCode]['year_error'];
return;
}
$countDays = $this->countDays( $this->month, $this->year );
$lastDay = $this->lastDay( $this->month, $this->year );
$columns = date( 'W', mktime( 0, 0, 0, $this->month, $countDays-7, $this->year ) ) - date( 'W', mktime(0, 0, 0, $this->month, 1+7, $this->year ) ) + 4;
echo '<table width="'.( $columns * 30 ).'" cellpadding="0" cellspacing="0">'."\n";
echo '<tr><td class="calendar_header" colspan="'.$columns.'" width="'.( $columns * 30 ).'">'.$this->lang[$this->langCode]['months'][$this->month].' '.$this->year.'</td></tr>'."\n";
for( $row = 1; $row <= 7; $row++ ) {
echo '<tr>';
for( $sloupec = 1; $sloupec <= $columns; $sloupec++ )
echo '<td>'.$this->day( $row, $sloupec, $lastDay, $countDays ).'</td>';
echo "</tr>\n";
}
echo '</table>';
}
}
Volanie triedy
$kalendar = new kalendar( '12', '2007' );
$kalendar->write();
| Žiadne dokumenty ani odkazy k tejto stránke. | ||
Generátor typoscriptu
Vytvára typoscript pre bežné použitie. Generátor je jednoduchý na obsluhu, stačí vyplniť zopár položiek formulára.