Logo classes.scriptsphp.org PHP

go to nav bar

HDAcalendar

La classe HDAcalendar permet de créer simplement des calendriers.

La classe HDAcalendar fournit des options avancées pour la création de calendrier. Vous avez la possibilité d' insérer des liens, tous les styles possibles(couleur, police, etc etc). Les calendriers sont multilingues, Anglais et Francais pour l' instant, mais d' autres langues ne sauraient tarder.

Les Méthodes

Exemples

  1. Exemple Simplifié
  2. Spécifier un Titre
  3. Insérer un ou plusieurs liens
  4. Mettre une ou plusieurs dates en Gras
  5. Choisir la langue d' affichage
  6. Inserer des Styles divers
  7. Rollover
  8. Un calendrier COMPLET

La Source

<?php

// Constants which are used in the script

// Use to define all days in the calendars
define('ALL''all');

class 
HDAcalendar extends HDAdate_lang {

        var 
$month;
        var 
$year;
        var 
$Cal;
        var 
$days;
        var 
$tab;
        var 
$LetterDays;
        var 
$bold;
        var 
$YearMonth;
        var 
$title;
        var 
$Tlink;
        var 
$html;


        function 
HDAcalendar($month=''$year='') {

                if(
$month)
                
$this->month $month;
                else
                
$this->month date('n');

                if(
$year)
                
$this->year $year;
                else
                
$this->year date('Y');

                
$this->Cal = array();
                
$this->bold = array();
                
$this->Tlink = array();

                
$this->tab                         = new Style();
                
$this->LetterDays         = new Style();
                
$this->days                 = new Style();
                
$this->links                 = new Style();
                
$this->YearMonth         = new Style();
                
$this->title                 = new Style();
                
$this->html '';

                
// French Language :)
                
parent::Set_lang('fr');
        }


        
/**
        * @return array $Cal
        * @param month
        * @param year
        * @desc build the Month array
        */
        
function Calendar($month$year) {

                if(
$month || $month 12) {
                        
$this->error_log "Le mois $month est invalide ";
                        return 
false;
                }
                if(
$year 1970 || $year 2034) {
                        
$this->error_log "L' année  $year est invalide ";
                        return 
false;
                }

                
$this->month $month;
                
$this->year $year;

                
// Get the first day of month Timestamp
                
$this->timestamp mktime(000$this->month1$this->year);
                
//$this->timestamp = $this->Get_timestamp($year, $month, 1);
                // spaces
                
$add_day1 date('w'$this->timestamp);
                for(
$i=0$i$add_day1$i++) {
                        
$Cal[] = '' ;
                }

                for(
$i=1$i<= date('t'$this->timestamp); $i++) {
                        
$Cal[] = $i;
                }

                
// Days after
                
$count count($Cal);
                
$add_day2 = (ceil($count/6)*6)-$count;

                for(
$i=0$i<$add_day2$i++) {
                        
$Cal[] = '';
                }

                
$C count($Cal);
                if(
$C 42$Cal array_pad($Cal42'');

                return 
$Cal;
        }





        
/**
        * @return string
        * @param current current date
        * @param page
        * @param params :: If you have GET $vars to pass ...
        * @param date format (D)D
        * @desc
        * @access private
        */
        
function Set_link($date$current$page$params=''){

                
//list($Y, $M, $D) = explode('-', $date, 3);

                
$ret  '<a href="'.$page.'?';
                
$ret .= 'date=';
                
$ret .= $this->year;
                
$ret .= '-';
                
$ret .= $this->month;
                
$ret .= '-';
                
$ret .= $current;

                if(
$params$ret .= '&'.$params;
                
$Lin_s $this->return_style2($this->links->S);
                
//$Lin_s = $this->return_style('links');
                
$ret .= '" '.$Lin_s.'>';

                
$ret .= $current.'</a>';

                return 
$ret;

        }

        function 
return_style2($arr) {
                
$T = array();


                foreach(
$arr as $key => $val) {
                        if(
$val !== '')
                        
array_push($T$key.':'.$val.';');
                }
                return (!empty(
$T)) ? 'style="'.implode(''$T).'"' '';
        }
        
/**
        * @return string
        * @param type name of object
        * @param fix the array to foreach
        * @desc return style html attribute
        * @access private
        *
        * @This method is deprecated
        */
        
function return_style($type$date='') {
                
$T = array();
                if(
$date$arr $this->u[$date][$type];
                else 
$arr $this->$type->S;

                foreach(
$arr as $key => $val) {
                        if(
$val !== '')
                        
array_push($T$key.':'.$val.';');
                }
                return (!empty(
$T)) ? 'style="'.implode(''$T).'"' '';
        }

        
/**
        * @return array from a date like 03 or 03-12 or 2003-03-12
        * @param var
        * @desc
        * @access private
        */
        
function return_date_arr($var) {
                
$y date('Y');
                
$m date('m');
                
$T = array();
                
$T explode('-'$var);
                
$count count($T);
                if(
$count === 3){
                        
// ** TODO date like 03 or 2003
                        
$y $T[0];
                        
$m $T[1];
                        
$d $T[2];
                }
                elseif(
$count === 2) {
                        
$m $T[0];
                        
$d $T[1];
                }
                else 
$d $var;

                return array(
$y$m$d);
        }

        
/**
        * @return html
        * @desc return an HTML array
        */
        
function Create_calendar() {

                
$month sprintf('%02d'$this->month);
                
$year $this->year;
                
$YM $year.'-'.$month;




                
$Cal $this->Calendar($month$year);
                if(empty(
$Cal)) return false;

                
// tableau general
                
$Tab_s $this->return_style2($this->tab->S);
                
/*
                echo 'Debug :)<pre>';
                echo print_r($this->$O->tab->S);
                */

                
$ret  "<table $Tab_s>";

                if(
$this->title->text !== '' ) {

                        
$Tit_s $this->return_style2($this->title->S);

                        
$ret .= '<tr>';
                        
$ret .= '<td colspan="7" '.$Tit_s.'>';
                        
$ret .= $this->title->text;
                        
$ret .= '</td>';
                        
$ret .= '</tr>';
                }

                
$ret .= '<tr>';

                
// Days in letters
                
$LD_s $this->return_style2($this->LetterDays->S);

                for(
$i=0$i<7$i++) {
                        
$ret .= '<td '.$LD_s.'>' $this->lg['SD'][$i] . '</td>';
                }

                
$ret .= '</tr>';
                
$ret .= '<tr >';

                
// days in Numbers
                
$Days_s $this->return_style2($this->days->S);

                
// Rollover
                
if(isset($this->days->rollover) && !empty($this->days->rollover))
                
$Days_s .= ' '.$this->days->rollover;

                
$i 1;
                
$cols_nb 7;
                
$Mtmp sprintf('%02d'$this->month);

                foreach(
$Cal as $val) {
                        
$tmp $val;
                        if(
$val === ''$val '&nbsp;';
                        
$end $i%$cols_nb '' '</tr><tr>';
                        
$i++;
                        if(
in_array($val$this->bold))
                        
$val '<b>'.$val.'</b>';

                        
$Dtmp sprintf('%02d'$tmp);

                        if(
array_key_exists($tmp$this->Tlink))
                        
$val $this->Set_link($tmp$val,
                        
$this->Tlink[$tmp]['page'],
                        
$this->Tlink[$tmp]['params']
                        );


                        
$ret .= '<td><div ';
                        if(
$tmp$ret .= $Days_s;
                        
$ret .= '>'$val .'</div></td>'."\n".$end;
                }
                
$ret .= '</tr>';

                
// year & Month
                
$YM_s $this->return_style2($this->YearMonth->S);

                
$ret .= '<td colspan="7" '.$YM_s.'>';
                
$ret .= $this->lg['M'][date('n'$this->timestamp)];
                
$ret .= ' ';
                
$ret .= $year;
                
$ret .= '</td>';
                
$ret .= '</tr>';
                
$ret .= '</table>';

                
$this->html $ret;
        }


        
/************************************
        *                                                                        *
        *                ACCESS PUBLIC                                *
        *                                                                        *
        ************************************/



        /**
        * @return
        * @param days void, optionnal or  can be an int or an array ..
        * @desc add day(s) in bold array
        * @access public
        */

        
function Set_bold($days='') {

                if(
is_array($days)) {
                        foreach(
$days as $val){
                                
array_push($this->bold$val);
                        }
                }
                else {
                        if(
$days === ''$days date('j');
                        
array_push($this->bold $days);
                }
        }


        
/**
        * @return
        * @param date format : (D)D
        * @param page URL destination
        * @param params :: If you have GET $vars to pass ...
        * @desc build link array
        * @acces public
        */
        
function link($date$page$params='') {
                
$T = array();

                if(
$date === ALL) {
                        for(
$i=0$i<31;$i++) {

                                
$T['page']                 = $page;
                                
$T['params']         = $params;
                                
$this->Tlink[$i] = $T;
                        }
                }
                elseif(
is_array($date)) {
                        foreach(
$date as $val) {
                                
$T['page']                 = $page;
                                
$T['params']         = $params;
                                
$this->Tlink[$val] = $T;
                        }
                }
                else {
                        
$T['page']                 = $page;
                        
$T['params']         = $params;
                        
$this->Tlink[$date] = $T;
                }

                
//echo 'Debug<pre>';
                //echo print_r($this->Tlink);
        
}


        
/**
        * @return boolean
        * @desc Output the HTML calendar to browser
        */
        
function Output() {

                
$this->Create_calendar();

                if(
$this->html !== '') {
                        echo 
$this->html;
                        
flush();
                        return 
true;
                }
                else {
                        
$this->error_log .= 'Une erreur est survenue !';
                        return 
false;
                }
        }


// end class


/*
* To put Styles in the calendar..
*
*/

class Style {

        var 
$text;
        var 
$S;
        var 
$rollover;

        
/**
        * @return
        * @desc Class Constructor
        */
        
function Style() {

                
$this->text '';

                
$this->= array();

        }

        function 
Set($txt) {
                
$this->text $txt;
        }

        function 
Set_color($color) {
                
$this->S['color'] = $color;
        }

        function 
Set_font($font) {
                
$this->S['font-family'] = $font;
        }

        function 
Set_size($size) {
                
$this->S['font-size'] = $size;
        }

        function 
Set_weight($weight) {
                
$this->S['font-weight'] = $weight;
        }

        function 
Set_underline() {
                
$this->S['text-decoration'] = 'underline';
        }

        function 
Set_border($border) {
                
$this->S['border'] = $border;
        }

        
// This method could be better !?! :)
        
function Set_background($color_image) {
                
$this->S['background-color'] = $color_image;
        }

        function 
Set_style($style$value) {
                
$this->S[$style] = $value;
        }

        function 
Rollover($color1$color2='') {
                
$this->rollover "
                onmouseover=\"
                javascript:this.style.background='$color1'\"
                onmouseout=\"javascript:this.style.background='$color2'\"
                "
;
        }


}
// end class


?>

Merci de ne pas suivre ce lien emails.

0.0697s | «»
PHP powered