PHP Classes

File: examples/calendar.php

Recommend this page to a friend!
  Classes of William Sant Ana   Tables for the Shell   examples/calendar.php   Download  
File: examples/calendar.php
Role: Example script
Content type: text/plain
Description: Example of printing a year calendar on the console
Class: Tables for the Shell
Output tables of data rendered as text characters
Author: By
Last change:
Date: 10 years ago
Size: 1,590 bytes
 

Contents

Class file image Download
<?php

include dirname(__FILE__) . DIRECTORY_SEPARATOR . '../tableForShell.php';
$tableForShell = new TableForShell();
//$tableForShell->setDelay(0.1);

foreach (range(1, 12) as $mes) {
   
$dia = 1;
   
$ano = date('Y');
   
$mktime = mktime(0,0,0,$mes,1,$ano);
   
$diaSemanaInicial = date("w", $mktime);


   
$tableForShell->header(
        array(
            array(
sprintf("%s %04s", date('F', $mktime), $ano), 76, 'C')
        ),
        array(
            array(
'Sun', 10, 'C'),
            array(
'Mon', 10, 'C'),
            array(
'Tue', 10, 'C'),
            array(
'Wed', 10, 'C'),
            array(
'Thu', 10, 'C'),
            array(
'Fri', 10, 'C'),
            array(
'Sat', 10, 'C'),
        )
    );

   
$begin = false;
   
$end = false;
    foreach (
range(0, 5) as $linhas) {
        foreach (
range(0, 6) as $colunas) {
            if (
$linhas == 0 && $colunas == $diaSemanaInicial) {
               
$begin = true;
               
$end = false;
            }
            if (
$dia > date('t', mktime(0,0,0,$mes))) {
               
$end = true;
            }
            if (
$begin && !$end) {
               
$tableForShell->cell($dia, 10, 'C');
               
$dia++;
            }
            else {
               
$tableForShell->cell('', 10, 'C');
            }
        }
        if (
$end) break;
       
$tableForShell->newline();
    }
   
$tableForShell->newline();
   
$tableForShell->footer(array(array('-', 76, 'C')));
   
$tableForShell->enter();
   
$tableForShell->enter();
   
$tableForShell->enter();
}