Accueil > > > PHP 5 CLASSE CALENDRIER QUI RENVOIE LA DATE CLIQUÉE DANS 1 ÉLÉMENT HTML CHOISI
PHP 5 CLASSE CALENDRIER QUI RENVOIE LA DATE CLIQUÉE DANS 1 ÉLÉMENT HTML CHOISI
Information sur la source
Description
1 nouvelle classe de calendrier:
Fonctionnalités :
- alimente par GET la date selectionnée dans le text box ou n'importe quel autre élément de votre choix .
- possibilité d'afficher le calendrier:
soit dans la page courante :la page ne se referme pas après selection de la date
soit dans dans 1 popup ouvrante: la popup se referme après slection de la date
sur 1 mois navigable, sur un nombre de mois précis à partir d'une mois précis ou du mois en cours.
- possibilité d'utiliser ses apparences favorites avec les styles css définis par l'utilisateur
Fonctionnalités supplémentaires:
Mise à jour:
Ajout des itérateurs et des accesseurs de tableaux.
La version à jour est dans le ZIP
Source
- <?php
-
- define ('MSG_WRONG_STYLE_TYPE','Style non paramètrable');
-
- /**
- * class myIterator implements Iterator,Countable,Seekableiterator,ArrayAccess
- */
- class myIterator implements Iterator,Countable,Seekableiterator,ArrayAccess
- {
- /**
- * property protected array $oItems:
- *
- * desc: tableau d'éléments .
- */
- protected $oItems=null;
-
- /**
- * property protected int $ipos
- *
- * desc: indice itérative de Position relative
- */
- protected $iPos=0;
-
- /**
- * property protected int $iMin
- *
- * desc: indice minimale de bornage
- */
- protected $iMin=0;
-
- /**
- * property protected int $iLimit
- *
- * desc: nombre limite d'occurences bornées
- */
- protected $iLimit;
-
- /**
- * property int $iOffset
- *
- * desc: Indice itérative de Position absolue
- */
- protected $iOffset=0;
-
- /**
- * public function constructor
- *
- * param int $iMin
- * param int $iLimit
- */
- public function __construct($iMin,$iLimit)
- {
- $this->oItems=array();
- $this->iLimit=$iLimit;
- $this->iMin=$iMin;
- }
-
- /**
- * public function add
- *
- * desc: empile le tableau passé en paramètres sur la pile existante statique
- *
- * param int $iMin
- * param int $iLimit
- */
- public function add($array)
- {
- $this->oItems[]=$array;
- }
-
- /**
- * public function setLimit
- *
- * desc: Définit un bornage $it => indice de départ , $l => longueur de la plage en occurences
- *
- * param int $it
- * param int $l
- */
- public function setLimit($it,$l)
- {
- if (is_int($it)&&is_int($l))
- {
- if ($l>0)
- {
- $this->iMin=$it;
- $this->iLimit=$l;
- $this->iOffset=$it;
- }
- }
- }
-
- /**
- * public function current
- *
- * desc: Methode itérative interface iterator
- */
- public function current()
- {
- if ($this->valid())
- return current($this->oItems);
- }
-
- /**
- * public function valid
- *
- * desc: Methode itérative interface iterator
- */
- public function valid()
- {
- return ( $this->iOffset >= $this->iMin && $this->iPos < ($this->iLimit) ) ;
-
- }
-
- /**
- * public function next
- *
- * desc: Methode itérative interface iterator
- */
- public function next()
- {
- $this->iPos++;
- $this->iOffset++;
- return next($this->oItems);
-
- }
-
- /**
- * public function key
- *
- * desc: Methode itérative interface iterator
- */
- public function key()
- {
- if ($this->valid())
- return key($this->oItems);
- }
-
- /**
- * public function rewind
- *
- * desc: Methode itérative interface iterator
- */
- public function rewind()
- {
- reset ($this->oItems);
- $position = 0;
- while($position < $this->iMin)
- {
- next($this->oItems);
- $position++;
- }
- $this->iPos=0;
- $this->iOffset=$this->iMin;
- if (!$this->valid())
- throw new Exception('Invalid seek position');
-
- }
-
- /**
- * public function count
- *
- * desc: Methode de comptage interface countable
- */
- public function count()
- {
- return count($this->oItems);
- }
-
- /**
- * public function seek
- *
- * desc: Methode itérative interface seekableIterator
- */
- public function seek($index)
- {
- $this->rewind();
- $position = $this->iMin;
- while($position < $index && $this->valid())
- {
- $this->next();
- $position++;
- }
- if (!$this->valid())
- {
- throw new Exception('Invalid seek position');
- }
- }
-
- /**
- * public function OffsetExists
- *
- * desc: Methode d' acces aux tableaux, interface arrayAccess
- *
- * param $iOffset int
- */
- public function OffsetExists($iOffset)
- {
- if ($iOffset < $this->iLimit && $iOffset >= $this->iMin)
- return true;
- else return false;
- }
-
- /**
- * public function OffsetGet
- *
- * desc: Methode itérative interface arrayAccess
- */
- public function OffsetGet($iOffset)
- {
- if ($this->OffsetExists($iOffset))
- return $this->oItems[$iOffset];
- }
-
- /**
- * public function OffsetSet
- * desc: Methode itérative interface arrayAccess
- */
- public function OffsetSet($iOffset,$val)
- {
-
- }
-
- public function OffsetUnset($iOffset)
- {
-
- }
-
- }
-
-
- /**
- * class monthIterator extends myIterator
- */
- class monthIterator extends myIterator
- {
- /**
- * property int $startmonth
- * indice minimale du bornage au mois
- */
- private $startmonth;
-
- /**
- * property int $startyear
- * indice minimale du bornage à l'année
- */
- private $startyear;
-
- /**
- * property int $iM
- * indice de position du mois
- */
- private $iM;
-
- /**
- * property int $iM
- * indice de position de l'année
- */
- private $iY;
-
- /**
- * public function __construct
- * Constructeur.
- *
- * @param string $start au format mm/yyyy
- * @param int $period en mois
- */
- public function __construct($start,$period=100)
- {
- if (substr($start,2,1)!=='/')
- throw new Exception('Paramètre Invalide pour constructeur format mm/yyyy');
-
- $expl=explode('/',$start);
-
- if( ((int)$expl[0]) <= 12 && ((int)$expl[0]) > 0 )
- $this->startmonth=(int)$expl[0];
- else throw new Exception('Format du mois invalide') ;
-
- if ( ((int)$expl[1]) >= 1000 && ((int)$expl[1]) < 9999 )
- $this->startyear=(int)$expl[1];
- else throw new Exception('Format année invalide');
-
- parent::__construct(0,$period);
- }
-
- /**
- * public function
- *
- * desc: Getter
- * param: mixed $prop
- * return object
- */
- public function __get ($prop)
- {
- if (isset($this->$prop))
- return $this->$prop;
- }
-
- /**
- * public Function nextM
- *
- * desc: positionne les indices iM et iY (mois et année) de l'iterateur.
- */
- public function NextM()
- {
- if( $this->iM < 12)
- {
- $this->iM++;
- }
- else
- {
- $this->iM = 1;
- $this->iY++;
- }
- }
-
- /**
- * public Function next
- *
- * desc: methode iterative.
- */
- public function next()
- {
- parent::next();
- $this->NextM();
- }
-
- /**
- * public Function rewind
- *
- * desc: methode iterative.
- */
- public function rewind()
- {
- parent::rewind();
- $this->iM = $this->startmonth;
- $this->iY = $this->startyear;
- }
- }
-
- /**
- * Class calendar
- */
- class calendar
- {
- /**
- * property $monthIterator
- * object monthIterator
- */
- private $monthIterator;
-
- /**
- * function Constructor
- *
- * param string $start format 'mm/yyyy'
- * param int $period
- *
- */
- public function __construct ($start,$period)
- {
- $this->monthIterator=new monthIterator($start,$period);
- $i=$this->monthIterator->iMin;
- $this->monthIterator->rewind();
- while ( $i < $this->monthIterator->iLimit)
- {
- $this->monthIterator->add(self::createmonth($this->monthIterator->iM,$this->monthIterator->iY));
- $this->monthIterator->NextM();
- $i++;
- }
- }
-
- /**
- * Function
- * desc: Getter
- * param: mixed $prop
- * return: property object
- */
- public function __get($prop)
- {
- if (isset($this->$prop))
- return $this->$prop;
- else return false;
- }
-
- /**
- * function getCurrentMonth
- *
- * desc:renvoit le mois et l'année en cours
- *
- * return string format ('mm/yyyy')
- */
- public function getCurrentMonth()
- {
- return (($this->monthIterator->iM<10)?'0'.$this->monthIterator->iM.'/'.$this->monthIterator->iY:$this->monthIterator->iM.'/'.$this->monthIterator->iY);
- }
-
- public function getNextM($mode)
- {
- switch ($mode)
- {
- case 'M':
- return(date('m',mktime(0, 0, 0, $this->monthIterator->iM+1, 1, $this->monthIterator->iY)));
- break;
- case 'Y':
- return(date('Y',mktime(0, 0, 0, $this->monthIterator->iM+1, 1, $this->monthIterator->iY)));
- break;
- }
- }
-
- public function getPrevM($mode)
- {
- switch ($mode)
- {
- case 'M':
- return (date('m',mktime(0, 0, 0, $this->monthIterator->iM-1, 1, $this->monthIterator->iY)));
- break;
- case 'Y':
- return(date('Y',mktime(0, 0, 0, $this->monthIterator->iM-1, 1, $this->monthIterator->iY)));
- break;
- }
- }
- /**
- * Static function
- *
- * desc: Methode de fabrication de calendrier de type tableau au mois
- *
- * param int $month
- * param int $year
- * return array
- */
- public static function createmonth($month,$year)
- {
- // jour de la semaine du premier du mois
- $fom = date ("w",mktime(0, 0, 0, $month, 1, $year));
- $day=1;
- $start=false;
- //combien de jours dans le mois?
- $max=date('t',mktime(0, 0, 0, $month, 1, $year));
- //formatage en chaine
- if ($month < 10)
- $month = '0'.$month;
- //init
- $d=0 ;
- //Le calendrier va occuper 6 lignes(semaines) de 7 colonnes(jours) pour le mois au maximum
- for ( $i=0 ; $i < 6 ; $i++ )
- {
- for ( $j=0 ; $j < 7 ;$j++ )
- {
- //début du comptage au 1er du mois pour la premiere semaine
- if ($i==0)
- {
- if ($fom == $d)
- {
- $start=true;
- $day=1;
- }
- }
- if ($day < $max+1)
- {
- if ($start ===true)
- {
- if ($day<10)
- $cal[$j][]='0'.$day;
- else
- $cal[$j][]=$day;
- $day++;
- }
- else
- $cal[$j][]='';
- }
- else
- $cal[$j][]='';
- $d++;
- }
- }
- return $cal;
- }
- }
-
- /**
- * class htmlCalendar extends calendar
- */
- class htmlCalendar extends calendar
- {
- /**
- * private property string domTextBoxId
- *
- * desc : l'id de la text box
- */
- private $domTextBoxId;
-
- /**
- * proprerty array settable
- *
- * desc : les propriétés modifiables
- */
- private $settable=array('cssHeader',
- 'cssSunday',
- 'cssWeekday',
- 'cssToday',
- 'cssLink',
- 'cssFooter',
- 'MonthByMonth',
- 'tdWidth',
- 'tdHeight',
- 'target');
- /**
- * proprerty array style
- *
- * desc: le tableau des propriétés de style
- */
- private $style=array();
-
- /**
- * proprerty string html
- *
- * desc: la chaine html stockant le calendrier au format html
- */
- private $html;
-
- /**
- * public function __set
- *
- * desc: Setter
- *
- * param:string $type
- * param string $strVal
- */
- public function __set($type,$strVal)
- {
- if (in_array($type,$this->settable))
- {
- $this->style[$type]=$strVal;
- }
- else throw new Exception (MSG_WRONG_STYLE_TYPE);
- }
-
- /**
- * public function __construct
- *
- * desc: Initialisation et constrcution des objets parents
- */
- public function __construct($boxId=null,$month=null,$year=null,$period=1)
- {
- $this->domTextBoxId=$boxId;
- $this->MonthByMonth=false;
- $m=isset($month)?(int)$month:(int)date('m');
- $y=isset($year)?(int)$year:(int)date('Y');
- if ($m<10)
- $m='0'.$m;
- parent::__construct($m.'/'.$y,$period);
- }
-
- /**
- * public function __get
- *
- * desc: Getter
- *
- * param: mixed $prop
- * return: mixed value
- */
- public function __get($prop)
- {
- if (parent::__get($prop))
- return parent::__get($prop);
- if (array_key_exists($prop,$this->style))
- return $this->style[$prop];
- }
-
- /**
- * public function getHtml
- *
- * desc: Construit et récupére le tableau en chaine html
- *
- * return: string
- */
- public function getHtml()
- {
- $tdW=$this->tdWidth;
- $tdH=$this->tdHeight;
- $this->html='';
-
-
- //Le calendrier va occuper 5 lignes(semaines) de 7 colonnes(jours) pour le mois au maximum
- foreach ($this->monthIterator as $key=>$month)
- {
- $MONTH=date('M',mktime(0, 0, 0, $this->monthIterator->iM, 1, $this->monthIterator->iY));
- if ($this->MonthByMonth!==false)
- {
- $prevm=$this->getPrevM('M');
- $prevy=$this->getPrevM('Y');
- $nextm=$this->getNextM('M');
- $nexty=$this->getNextM('Y');
- $chooseMonth='<a class="'.$this->cssLink.'" href="?month='.$prevm.'&year='.$prevy.'"> << </a> '.$MONTH.' '.$this->monthIterator->iY.' <a class="'.$this->cssLink.'" href="?month='.$nextm.'&year='.$nexty.'&box='.$this->domTextBoxId.'"> >> </a>';
- }
- else $chooseMonth=' '.$MONTH.' '.$this->monthIterator->iY.' ';
- $this->html.= '
- <table border="0" cellpadding="0" cellspacing="0" >
- <!--DWLayoutTable-->
- <tr>
- <td width="'.$tdW.'" height="'.$tdH.'" valign="middle" align="center" class="'.$this->cssHeader.'">D</td>
- <td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">L</td>
- <td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">M</td>
- <td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">M</td>
- <td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">J</td>
- <td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">V</td>
- <td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">S</td>
- </tr>';
- for ($j=0;$j<6;$j++)
- {
- $this->html.='<tr>';
- for ($k=0;$k<7;$k++)
- {
- $class=$this->cssWeekday;
- $title ='click to select in the box';
- if ($k==0)
- $class=$this->cssSunday;
-
- if ( ($month[$k][$j] == (int)date('d')) and ($this->monthIterator->iM== (int)date('m')) and ($this->monthIterator->iY == (int)date('Y')) )
- {
- $class = $this->cssToday;
- }
-
- if ($this->target=='opener')
- $close='self.close();';
- else $close='';
-
- if ($this->monthIterator->iM < 10)
- $mth='0'.$this->monthIterator->iM;
- else $mth=$this->monthIterator->iM;
-
- if($month[$k][$j]!='')
- $this->html.= '<td width="'.$tdW.'" height="'.$tdH.'" valign="middle" align="center" class="'.$class.'"><a href = "#" class="'.$this->cssLink.'" onclick="'.$this->target.'.document.getElementById(\''.$this->domTextBoxId.'\').value=\''.$month[$k][$j].'/'.$mth.'/'.$this->monthIterator->iY.'\';'.$close.' " '.$title.'>'.(int)$month[$k][$j].'</td>';
- else
- $this->html.= '<td width="'.$tdW.'" height="'.$tdH.'" valign="middle" align="center" class="'.$class.'"><a href = "#" class="'.$this->cssLink.'" onclick="'.$this->target.'.document.getElementById(\''.$this->domTextBoxId.'\').value=\''.$month[$k][$j].'/'.$mth.'/'.$this->monthIterator->iY.'\';'.$close.' " '.$title.'>'.$month[$k][$j].'</td>';
- }
- $this->html.= '</tr>';
- }
- $this->html.= '</tr></table><table border="0" cellpadding="0" cellspacing="0" ><tr><td class="'.$this->cssFooter.'">'.$chooseMonth.'</td></tr></table>';
- }
- return $this->html;
- }
- }
-
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>calendrier</title>
- <style>
- td.formtdcalendar {
-
- font-family: verdana;
- font-size: 11px;
- font-style:normal;
- font-weight:100;
- color: #330099;
- background-color: #FFFFFF;
- }
-
- td.cal_dimanche {
-
- font-family: verdana;
- font-size: 11px;
- text-transform: lowercase;
- color: red;
- text-decoration: none;
- text-align: center;
- vertical-align: middle;
- background: yellow;
- }
- td.formtdtoday {
- font-family:Geneva, Arial, Helvetica, sans-serif;
- font-size: 11px;
- font-style:normal;
- font-weight:bold;
- text-align:center;
- color: #FF0000;
- background-color: #A60001;
- background-image:url(./ricerca_box3.gif);
- }
- td.footer {
- font-family: verdana;
- font-size: 11px;
- text-transform: lowercase;
- color: #330099;
- text-decoration: none;
- text-align: center;
- vertical-align: middle;
- background: #FFFFFF;
- }
- td.date_today {
- font-family: verdana;
- font-size: 11px;
- text-transform: lowercase;
- color: #FFFFFF;
- text-decoration: none;
- text-align: center;
- vertical-align: middle;
- background: #FF0000;
- }
- td.headertd {
- font-family: Arial;
- font-size: 11px;
- font-weight: bold;
- color: #F5F5F5;
- background-color: #003366;
- font-style: italic;
- text-decoration: blink;
- border-top-width: 1px;
- border-right-width: 1px;
- border-bottom-width: 1px;
- border-left-width: 1px;
- border-top-style: solid;
- border-right-style: solid;
- border-bottom-style: solid;
- border-left-style: solid;
- border-color: #363636 #F5F5F5 #F5F5F5 #363636 ;
- background-image:url(header.gif);
- }
- a.fld:hover {
- text-decoration:none;
- color:#633363;
- font-style: italic;
- }
- a.fld:link {
- text-decoration:none;
- color:#633363;
- font-style: italic;
- }
- a.fld:visited {
- text-decoration:none;
- color:#633363;
- font-style: italic;
- }
- a.fld:active {
- text-decoration:none;
- color:#633363;
- font-style: italic;
- }
- </style>
- </head>
- <body>
- <input type="text" id="box" value=""/>
- <?php
- $calendar = isset($_GET['month'])?new htmlCalendar('box',$_GET['month'],$_GET['year']):new htmlCalendar('box');
- $calendar->cssHeader='headertd';
- $calendar->cssWeekday='formtdcalendar';
- $calendar->cssSunday='cal_dimanche';
- $calendar->cssToday='date_today';
- $calendar->cssLink='fld';
- $calendar->cssFooter='footer';
- $calendar->tdWidth='20';
- $calendar->target='window';
- echo $calendar->getHtml();
- ?>
- </body>
- </html>
<?php
define ('MSG_WRONG_STYLE_TYPE','Style non paramètrable');
/**
* class myIterator implements Iterator,Countable,Seekableiterator,ArrayAccess
*/
class myIterator implements Iterator,Countable,Seekableiterator,ArrayAccess
{
/**
* property protected array $oItems:
*
* desc: tableau d'éléments .
*/
protected $oItems=null;
/**
* property protected int $ipos
*
* desc: indice itérative de Position relative
*/
protected $iPos=0;
/**
* property protected int $iMin
*
* desc: indice minimale de bornage
*/
protected $iMin=0;
/**
* property protected int $iLimit
*
* desc: nombre limite d'occurences bornées
*/
protected $iLimit;
/**
* property int $iOffset
*
* desc: Indice itérative de Position absolue
*/
protected $iOffset=0;
/**
* public function constructor
*
* param int $iMin
* param int $iLimit
*/
public function __construct($iMin,$iLimit)
{
$this->oItems=array();
$this->iLimit=$iLimit;
$this->iMin=$iMin;
}
/**
* public function add
*
* desc: empile le tableau passé en paramètres sur la pile existante statique
*
* param int $iMin
* param int $iLimit
*/
public function add($array)
{
$this->oItems[]=$array;
}
/**
* public function setLimit
*
* desc: Définit un bornage $it => indice de départ , $l => longueur de la plage en occurences
*
* param int $it
* param int $l
*/
public function setLimit($it,$l)
{
if (is_int($it)&&is_int($l))
{
if ($l>0)
{
$this->iMin=$it;
$this->iLimit=$l;
$this->iOffset=$it;
}
}
}
/**
* public function current
*
* desc: Methode itérative interface iterator
*/
public function current()
{
if ($this->valid())
return current($this->oItems);
}
/**
* public function valid
*
* desc: Methode itérative interface iterator
*/
public function valid()
{
return ( $this->iOffset >= $this->iMin && $this->iPos < ($this->iLimit) ) ;
}
/**
* public function next
*
* desc: Methode itérative interface iterator
*/
public function next()
{
$this->iPos++;
$this->iOffset++;
return next($this->oItems);
}
/**
* public function key
*
* desc: Methode itérative interface iterator
*/
public function key()
{
if ($this->valid())
return key($this->oItems);
}
/**
* public function rewind
*
* desc: Methode itérative interface iterator
*/
public function rewind()
{
reset ($this->oItems);
$position = 0;
while($position < $this->iMin)
{
next($this->oItems);
$position++;
}
$this->iPos=0;
$this->iOffset=$this->iMin;
if (!$this->valid())
throw new Exception('Invalid seek position');
}
/**
* public function count
*
* desc: Methode de comptage interface countable
*/
public function count()
{
return count($this->oItems);
}
/**
* public function seek
*
* desc: Methode itérative interface seekableIterator
*/
public function seek($index)
{
$this->rewind();
$position = $this->iMin;
while($position < $index && $this->valid())
{
$this->next();
$position++;
}
if (!$this->valid())
{
throw new Exception('Invalid seek position');
}
}
/**
* public function OffsetExists
*
* desc: Methode d' acces aux tableaux, interface arrayAccess
*
* param $iOffset int
*/
public function OffsetExists($iOffset)
{
if ($iOffset < $this->iLimit && $iOffset >= $this->iMin)
return true;
else return false;
}
/**
* public function OffsetGet
*
* desc: Methode itérative interface arrayAccess
*/
public function OffsetGet($iOffset)
{
if ($this->OffsetExists($iOffset))
return $this->oItems[$iOffset];
}
/**
* public function OffsetSet
* desc: Methode itérative interface arrayAccess
*/
public function OffsetSet($iOffset,$val)
{
}
public function OffsetUnset($iOffset)
{
}
}
/**
* class monthIterator extends myIterator
*/
class monthIterator extends myIterator
{
/**
* property int $startmonth
* indice minimale du bornage au mois
*/
private $startmonth;
/**
* property int $startyear
* indice minimale du bornage à l'année
*/
private $startyear;
/**
* property int $iM
* indice de position du mois
*/
private $iM;
/**
* property int $iM
* indice de position de l'année
*/
private $iY;
/**
* public function __construct
* Constructeur.
*
* @param string $start au format mm/yyyy
* @param int $period en mois
*/
public function __construct($start,$period=100)
{
if (substr($start,2,1)!=='/')
throw new Exception('Paramètre Invalide pour constructeur format mm/yyyy');
$expl=explode('/',$start);
if( ((int)$expl[0]) <= 12 && ((int)$expl[0]) > 0 )
$this->startmonth=(int)$expl[0];
else throw new Exception('Format du mois invalide') ;
if ( ((int)$expl[1]) >= 1000 && ((int)$expl[1]) < 9999 )
$this->startyear=(int)$expl[1];
else throw new Exception('Format année invalide');
parent::__construct(0,$period);
}
/**
* public function
*
* desc: Getter
* param: mixed $prop
* return object
*/
public function __get ($prop)
{
if (isset($this->$prop))
return $this->$prop;
}
/**
* public Function nextM
*
* desc: positionne les indices iM et iY (mois et année) de l'iterateur.
*/
public function NextM()
{
if( $this->iM < 12)
{
$this->iM++;
}
else
{
$this->iM = 1;
$this->iY++;
}
}
/**
* public Function next
*
* desc: methode iterative.
*/
public function next()
{
parent::next();
$this->NextM();
}
/**
* public Function rewind
*
* desc: methode iterative.
*/
public function rewind()
{
parent::rewind();
$this->iM = $this->startmonth;
$this->iY = $this->startyear;
}
}
/**
* Class calendar
*/
class calendar
{
/**
* property $monthIterator
* object monthIterator
*/
private $monthIterator;
/**
* function Constructor
*
* param string $start format 'mm/yyyy'
* param int $period
*
*/
public function __construct ($start,$period)
{
$this->monthIterator=new monthIterator($start,$period);
$i=$this->monthIterator->iMin;
$this->monthIterator->rewind();
while ( $i < $this->monthIterator->iLimit)
{
$this->monthIterator->add(self::createmonth($this->monthIterator->iM,$this->monthIterator->iY));
$this->monthIterator->NextM();
$i++;
}
}
/**
* Function
* desc: Getter
* param: mixed $prop
* return: property object
*/
public function __get($prop)
{
if (isset($this->$prop))
return $this->$prop;
else return false;
}
/**
* function getCurrentMonth
*
* desc:renvoit le mois et l'année en cours
*
* return string format ('mm/yyyy')
*/
public function getCurrentMonth()
{
return (($this->monthIterator->iM<10)?'0'.$this->monthIterator->iM.'/'.$this->monthIterator->iY:$this->monthIterator->iM.'/'.$this->monthIterator->iY);
}
public function getNextM($mode)
{
switch ($mode)
{
case 'M':
return(date('m',mktime(0, 0, 0, $this->monthIterator->iM+1, 1, $this->monthIterator->iY)));
break;
case 'Y':
return(date('Y',mktime(0, 0, 0, $this->monthIterator->iM+1, 1, $this->monthIterator->iY)));
break;
}
}
public function getPrevM($mode)
{
switch ($mode)
{
case 'M':
return (date('m',mktime(0, 0, 0, $this->monthIterator->iM-1, 1, $this->monthIterator->iY)));
break;
case 'Y':
return(date('Y',mktime(0, 0, 0, $this->monthIterator->iM-1, 1, $this->monthIterator->iY)));
break;
}
}
/**
* Static function
*
* desc: Methode de fabrication de calendrier de type tableau au mois
*
* param int $month
* param int $year
* return array
*/
public static function createmonth($month,$year)
{
// jour de la semaine du premier du mois
$fom = date ("w",mktime(0, 0, 0, $month, 1, $year));
$day=1;
$start=false;
//combien de jours dans le mois?
$max=date('t',mktime(0, 0, 0, $month, 1, $year));
//formatage en chaine
if ($month < 10)
$month = '0'.$month;
//init
$d=0 ;
//Le calendrier va occuper 6 lignes(semaines) de 7 colonnes(jours) pour le mois au maximum
for ( $i=0 ; $i < 6 ; $i++ )
{
for ( $j=0 ; $j < 7 ;$j++ )
{
//début du comptage au 1er du mois pour la premiere semaine
if ($i==0)
{
if ($fom == $d)
{
$start=true;
$day=1;
}
}
if ($day < $max+1)
{
if ($start ===true)
{
if ($day<10)
$cal[$j][]='0'.$day;
else
$cal[$j][]=$day;
$day++;
}
else
$cal[$j][]='';
}
else
$cal[$j][]='';
$d++;
}
}
return $cal;
}
}
/**
* class htmlCalendar extends calendar
*/
class htmlCalendar extends calendar
{
/**
* private property string domTextBoxId
*
* desc : l'id de la text box
*/
private $domTextBoxId;
/**
* proprerty array settable
*
* desc : les propriétés modifiables
*/
private $settable=array('cssHeader',
'cssSunday',
'cssWeekday',
'cssToday',
'cssLink',
'cssFooter',
'MonthByMonth',
'tdWidth',
'tdHeight',
'target');
/**
* proprerty array style
*
* desc: le tableau des propriétés de style
*/
private $style=array();
/**
* proprerty string html
*
* desc: la chaine html stockant le calendrier au format html
*/
private $html;
/**
* public function __set
*
* desc: Setter
*
* param:string $type
* param string $strVal
*/
public function __set($type,$strVal)
{
if (in_array($type,$this->settable))
{
$this->style[$type]=$strVal;
}
else throw new Exception (MSG_WRONG_STYLE_TYPE);
}
/**
* public function __construct
*
* desc: Initialisation et constrcution des objets parents
*/
public function __construct($boxId=null,$month=null,$year=null,$period=1)
{
$this->domTextBoxId=$boxId;
$this->MonthByMonth=false;
$m=isset($month)?(int)$month:(int)date('m');
$y=isset($year)?(int)$year:(int)date('Y');
if ($m<10)
$m='0'.$m;
parent::__construct($m.'/'.$y,$period);
}
/**
* public function __get
*
* desc: Getter
*
* param: mixed $prop
* return: mixed value
*/
public function __get($prop)
{
if (parent::__get($prop))
return parent::__get($prop);
if (array_key_exists($prop,$this->style))
return $this->style[$prop];
}
/**
* public function getHtml
*
* desc: Construit et récupére le tableau en chaine html
*
* return: string
*/
public function getHtml()
{
$tdW=$this->tdWidth;
$tdH=$this->tdHeight;
$this->html='';
//Le calendrier va occuper 5 lignes(semaines) de 7 colonnes(jours) pour le mois au maximum
foreach ($this->monthIterator as $key=>$month)
{
$MONTH=date('M',mktime(0, 0, 0, $this->monthIterator->iM, 1, $this->monthIterator->iY));
if ($this->MonthByMonth!==false)
{
$prevm=$this->getPrevM('M');
$prevy=$this->getPrevM('Y');
$nextm=$this->getNextM('M');
$nexty=$this->getNextM('Y');
$chooseMonth='<a class="'.$this->cssLink.'" href="?month='.$prevm.'&year='.$prevy.'"> << </a> '.$MONTH.' '.$this->monthIterator->iY.' <a class="'.$this->cssLink.'" href="?month='.$nextm.'&year='.$nexty.'&box='.$this->domTextBoxId.'"> >> </a>';
}
else $chooseMonth=' '.$MONTH.' '.$this->monthIterator->iY.' ';
$this->html.= '
<table border="0" cellpadding="0" cellspacing="0" >
<!--DWLayoutTable-->
<tr>
<td width="'.$tdW.'" height="'.$tdH.'" valign="middle" align="center" class="'.$this->cssHeader.'">D</td>
<td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">L</td>
<td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">M</td>
<td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">M</td>
<td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">J</td>
<td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">V</td>
<td width="'.$tdW.'" valign="middle" align="center" class="'.$this->cssHeader.'">S</td>
</tr>';
for ($j=0;$j<6;$j++)
{
$this->html.='<tr>';
for ($k=0;$k<7;$k++)
{
$class=$this->cssWeekday;
$title ='click to select in the box';
if ($k==0)
$class=$this->cssSunday;
if ( ($month[$k][$j] == (int)date('d')) and ($this->monthIterator->iM== (int)date('m')) and ($this->monthIterator->iY == (int)date('Y')) )
{
$class = $this->cssToday;
}
if ($this->target=='opener')
$close='self.close();';
else $close='';
if ($this->monthIterator->iM < 10)
$mth='0'.$this->monthIterator->iM;
else $mth=$this->monthIterator->iM;
if($month[$k][$j]!='')
$this->html.= '<td width="'.$tdW.'" height="'.$tdH.'" valign="middle" align="center" class="'.$class.'"><a href = "#" class="'.$this->cssLink.'" onclick="'.$this->target.'.document.getElementById(\''.$this->domTextBoxId.'\').value=\''.$month[$k][$j].'/'.$mth.'/'.$this->monthIterator->iY.'\';'.$close.' " '.$title.'>'.(int)$month[$k][$j].'</td>';
else
$this->html.= '<td width="'.$tdW.'" height="'.$tdH.'" valign="middle" align="center" class="'.$class.'"><a href = "#" class="'.$this->cssLink.'" onclick="'.$this->target.'.document.getElementById(\''.$this->domTextBoxId.'\').value=\''.$month[$k][$j].'/'.$mth.'/'.$this->monthIterator->iY.'\';'.$close.' " '.$title.'>'.$month[$k][$j].'</td>';
}
$this->html.= '</tr>';
}
$this->html.= '</tr></table><table border="0" cellpadding="0" cellspacing="0" ><tr><td class="'.$this->cssFooter.'">'.$chooseMonth.'</td></tr></table>';
}
return $this->html;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>calendrier</title>
<style>
td.formtdcalendar {
font-family: verdana;
font-size: 11px;
font-style:normal;
font-weight:100;
color: #330099;
background-color: #FFFFFF;
}
td.cal_dimanche {
font-family: verdana;
font-size: 11px;
text-transform: lowercase;
color: red;
text-decoration: none;
text-align: center;
vertical-align: middle;
background: yellow;
}
td.formtdtoday {
font-family:Geneva, Arial, Helvetica, sans-serif;
font-size: 11px;
font-style:normal;
font-weight:bold;
text-align:center;
color: #FF0000;
background-color: #A60001;
background-image:url(./ricerca_box3.gif);
}
td.footer {
font-family: verdana;
font-size: 11px;
text-transform: lowercase;
color: #330099;
text-decoration: none;
text-align: center;
vertical-align: middle;
background: #FFFFFF;
}
td.date_today {
font-family: verdana;
font-size: 11px;
text-transform: lowercase;
color: #FFFFFF;
text-decoration: none;
text-align: center;
vertical-align: middle;
background: #FF0000;
}
td.headertd {
font-family: Arial;
font-size: 11px;
font-weight: bold;
color: #F5F5F5;
background-color: #003366;
font-style: italic;
text-decoration: blink;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-color: #363636 #F5F5F5 #F5F5F5 #363636 ;
background-image:url(header.gif);
}
a.fld:hover {
text-decoration:none;
color:#633363;
font-style: italic;
}
a.fld:link {
text-decoration:none;
color:#633363;
font-style: italic;
}
a.fld:visited {
text-decoration:none;
color:#633363;
font-style: italic;
}
a.fld:active {
text-decoration:none;
color:#633363;
font-style: italic;
}
</style>
</head>
<body>
<input type="text" id="box" value=""/>
<?php
$calendar = isset($_GET['month'])?new htmlCalendar('box',$_GET['month'],$_GET['year']):new htmlCalendar('box');
$calendar->cssHeader='headertd';
$calendar->cssWeekday='formtdcalendar';
$calendar->cssSunday='cal_dimanche';
$calendar->cssToday='date_today';
$calendar->cssLink='fld';
$calendar->cssFooter='footer';
$calendar->tdWidth='20';
$calendar->target='window';
echo $calendar->getHtml();
?>
</body>
</html>
Conclusion
Ajout de classe itérateurs et arrayaccess.
Refonte de la classe principale ajout de classe spécialisée Html.
Gestion des plages de périodes.
Plus plein d'autres possibilités.
Historique
- 16 mai 2007 21:57:13 :
- oubli
- 16 mai 2007 23:06:41 :
- exemple ajouté + zip
- 27 mai 2007 17:23:49 :
- Ajout de classe itérateurs et arrayaccess.
Refonte de la classe principale ajout de classe spécialisée Html.
Gestion des plages de périodes.
Plus plein d'autres possibilités.
- 27 mai 2007 18:04:21 :
- exemple modifié
- 27 mai 2007 20:32:27 :
- MAJ des exemples.
- 28 mai 2007 23:21:43 :
- Bugs HTML corrigés
Ajout des jours fériés.
- 30 mai 2007 21:46:50 :
- manquait paques
- 31 mai 2007 23:32:17 :
- arrangement
- 25 juillet 2007 20:13:29 :
- Ajout screenshot et modification categorie =>date/heure
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|