Calendário

Publicado por Vinicus S Moraes 20/07/2008

[ Hits: 6.209 ]

Homepage: http://vsmoraes.wordpress.com

Download class.php




Ta aí uma classe pra gerar um calendário...

Informando a classe CSS fica bem bonitinho x). Classe de minha autoria.

  



Esconder código-fonte

<?php
   error_reporting(E_ALL);
   class Calendario {
      private $_dia;
      private $_mes;
      private $_ano;
      private $_class;
      private $_ts = 0;

      public function __construct($data=0, $class="") {
         if ($data == 0) {
            $this->_dia = date("d");
            $this->_mes = date("m");
            $this->_ano = date("Y");
         } else {
            $tmp = explode("/", $data);
            $this->_dia = $tmp[0];
            $this->_mes = $tmp[1];
            $this->_ano = $tmp[2];
         }
         $this->_class = $class;
      } // __construct

      public function __show() {
         printf("<table class=\"%s\" width=\"%s\" height=\"%s\">\n", $this->_class, "100%", "100%");
         $this->__openWeek();
         $this->__printHeader();
         $this->__closeWeek();

         $first = true;
         $numDay = 0;
         $day = $this->__calcNextDate();
         while ($day) {
            if ($numDay == 7) {
               $this->__closeWeek();
               $numDay = 0;
            }
            if ($numDay == 0) {
               $this->__openWeek();
               if ($first) {
                  $numDay = date("w", $this->_ts);
                  $first = false;
                  for ($x = 0; $x<$numDay; $x++) {
                     $this->__addDay(" ");
                  }
               }
            }
            $this->__addDay($day);
            $day = $this->__calcNextDate();
            $numDay++;
         }
         while ($numDay < 7) {
            $this->__addDay(" ");
            $numDay++;
         }
         $this->__closeWeek();
         printf("</table>\n");
      } // __show

      private function __calcNextDate() {
         if ($this->_ts == 0) {
            $ts = mktime(0, 0, 0, $this->_mes, 1, $this->_ano);
         } else {
            $tmp = date("d-m-Y", $this->_ts);
            $tmp = explode("-", $tmp);
            $ts = mktime(0, 0, 0, $tmp[1], ($tmp[0]+1), $tmp[2]);
         }
         $this->_ts = $ts;
         if (date("m",$ts) != $this->_mes) {
            return false;
         } else {
            return date("d", $ts);
         }
      } // __ calcNextDate

      private function __openWeek() {
         printf("<tr class=\"%s\">\n", $this->_class);
      } // __openWeek

      private function __closeWeek() {
         printf("</tr>\n");
      } // __closeWeek

      private function __addDay($day) {
         if ($day == $this->_dia) {
            $class = $this->_class."1";
         } else {
            $class = $this->_class;
         }
         printf("<td class=\"%s\">\n", $class);
         printf("%s\n", $day);
         printf("</td>\n");
      } // __addDay

      private function __printHeader() {
         printf("<th class=\"%s\">\n", $this->_class);
         printf("DOM\n");
         printf("</th>\n");

         printf("<th class=\"%s\">\n", $this->_class);
                        printf("SEG\n");
                        printf("</th>\n");

         printf("<th class=\"%s\">\n", $this->_class);
                        printf("TER\n");
                        printf("</th>\n");

         printf("<th class=\"%s\">\n", $this->_class);
                        printf("QUA\n");
                        printf("</th>\n");
         
         printf("<th class=\"%s\">\n", $this->_class);
         printf("QUI\n");
         printf("</th>\n");

         printf("<th class=\"%s\">\n", $this->_class);
         printf("SEX\n");
         printf("</th>\n");

         printf("<th class=\"%s\">\n", $this->_class);
         printf("SAB\n");
         printf("</th>\n");
      }
   };
?>

Scripts recomendados

Jogo do amor com logs

Jogo puzzle

Banners rotativos simples

Cadcomp 1.0

Crivo de Eratóstenes Simples em PHP


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts