<?php
/*
stelib_calendar.php - Libreria calendar
Stefano Sangalli
20 novembre 2007
*/
//! ...
/*!
Questo oggetto...
\li ...
\li ...
*/
/**
* La classe TObject contiene le informazioni che legano la risorse (ID_RESOURCE) con il progetto (ID_RECORD) in una certa data.
*/
class TObject {
// Contenuto-Url-Target-Method
}
/**
* La classe TGiorno contiene le informazioni relative ad un dato giorno (parametro date)
* <pre>
* ------------------------------------------------------------------------
* $this->GIORNO["date"] data completa ("Y-m-d")
* $this->GIORNO["Y"] anno a 4 cifre("2006")
* $this->GIORNO["m"] mese a 2 cifre("11")
* $this->GIORNO["M"] mese in 3 lettere("Jan")
* $this->GIORNO["mese"] mese in Italiano("Gennaio")
* $this->GIORNO["d"] giorno 2 cifre("31")
* $this->GIORNO["w"] giorno della settimana numerico (Es: 0=domenica)
* $this->GIORNO["l"] giorno della settimana testuale (Es: Friday)
* $this->GIORNO["it"] giorno della settimana in italiano (Es: Venerdi)
* ------------------------------------------------------------------------
* </pre>
*/
class TGiorno extends TObject {
var $GIORNO;
function TGiorno(
/// Data sulla quale costruire l'oggetto TGiorno.
$date) {
// 0123456789
// 2006-11-08
if (!$date) { $date=date("Y-m-d"); }
$makeTime=mktime(0,0,0,$date[5].$date[6],$date[8].$date[9],$date[0].$date[1].$date[2].$date[3]);
$this->GIORNO=array();
$this->GIORNO["date"] =date("Y-m-d",$makeTime);
$this->GIORNO["Y"] =date("Y",$makeTime);
$this->GIORNO["m"] =date("m",$makeTime);
$this->GIORNO["M"] =date("M",$makeTime);
$this->GIORNO["mese"] =date("mese",$makeTime);
$this->GIORNO["d"] =date("d",$makeTime);
$this->GIORNO["w"] =date("w",$makeTime);
$this->GIORNO["l"] =date("l",$makeTime);
switch ($this->GIORNO["w"]) {
case "0":$this->GIORNO["it"]="Domenica" ;break;
case "1":$this->GIORNO["it"]="Lunedi" ;break;
case "2":$this->GIORNO["it"]="Martedi" ;break;
case "3":$this->GIORNO["it"]="Mercoledi" ;break;
case "4":$this->GIORNO["it"]="Giovedi" ;break;
case "5":$this->GIORNO["it"]="Venerdi" ;break;
case "6":$this->GIORNO["it"]="Sabato" ;break;
}
switch ($this->GIORNO["m"]) {
case "01":$this->GIORNO["mese"]="Gennaio" ;break;
case "02":$this->GIORNO["mese"]="Febbraio" ;break;
case "03":$this->GIORNO["mese"]="Marzo" ;break;
case "04":$this->GIORNO["mese"]="Aprile" ;break;
case "05":$this->GIORNO["mese"]="Maggio" ;break;
case "06":$this->GIORNO["mese"]="Giugno" ;break;
case "07":$this->GIORNO["mese"]="Luglio" ;break;
case "08":$this->GIORNO["mese"]="Agosto" ;break;
case "09":$this->GIORNO["mese"]="Settembre" ;break;
case "10":$this->GIORNO["mese"]="Ottobre" ;break;
case "11":$this->GIORNO["mese"]="Novembre" ;break;
case "12":$this->GIORNO["mese"]="Dicembre" ;break;
}
$this->GIORNO["item"]=new TObject();
return $this->GIORNO;
}
}
/**
* La classe TSettimana contiene i giorni della settimana, numerati da 0 a 6 nel seguente ordine:
* <PRE>
* Giorno TSettimana php mySql
* ----------------------------------
* Lun 0 1 2
* Mar 1 2 3
* Mer 2 3 4
* Gio 3 4 5
* Ven 4 5 6
* Sab 5 6 7
* Dom 6 0 1
* </PRE>
* L'ordine di TSettimana � confrontato con i valori di PHP e MYSQL, per le funzioni:<BR>
* <PRE>
* - php: date("w")<BR>
* - mySql: SELECT GIORNOOFSETTIMANA(date)<BR>
* </PRE>
*/
class TSettimana extends TGiorno{
var $SETTIMANA=array();
var $SETTIMANA_NUMBER="";
function TSettimana (
/// Rappresenta la data dalla quale partire per costruire la settimana.
$date) {
// 0123456789
// 2006-11-08
$day_numeric=date("w",mktime(0,0,0,$date[5].$date[6],$date[8].$date[9],$date[0].$date[1].$date[2].$date[3]));
for ($cont_day=0;$cont_day<=6;$cont_day++) {
$this->SETTIMANA[$cont_day]=new TGiorno(date("Y-m-d",mktime(0,0,0,$date[5].$date[6],($date[8].$date[9])-($day_numeric-$cont_day),$date[0].$date[1].$date[2].$date[3])));
}
$this->SETTIMANA_NUMBER=date("W",mktime(0,0,0,$date[5].$date[6],$date[8].$date[9],$date[0].$date[1].$date[2].$date[3])); /// Numero della settimana dell'anno
return $this->SETTIMANA;
}
}
class TMese extends TSettimana{
var $CALENDAR_NAME="";
var $MESE=array();
var $MESE_NUMBER="";
var $OGGI="";
var $TOT_HO=0;
var $TOT_HS=0;
var $TOT_HF=0;
function TMese(
/// Rappresenta la data dalla quale partire per costruire il mese corrente.
$today) {
// 0123456789
// 2006-11-08
$this->OGGI=$today;
$firstDay=$today;
$firstDay[8]="0";
$firstDay[9]="1";
$day_numeric=date("w",mktime(0,0,0,$firstDay[5].$firstDay[6],$firstDay[8].$firstDay[9],$firstDay[0].$firstDay[1].$firstDay[2].$firstDay[3]));
for ($cont_week=0;$cont_week<5;$cont_week++) {
$lunedi=date("Y-m-d",mktime(0,0,0,$firstDay[5].$firstDay[6],($firstDay[8].$firstDay[9])-($day_numeric-($cont_week*7)),$firstDay[0].$firstDay[1].$firstDay[2].$firstDay[3]));
$this->MESE[$cont_week]=new TSettimana($lunedi);
for ($cont_day=0;$cont_day<=6;$cont_day++) {
$this->MESE->SETTIMANA[$cont_day]=new TGiorno(date("Y-m-d",mktime(0,0,0,$firstDay[5].$firstDay[6],($firstDay[8].$firstDay[9])-($day_numeric-$cont_day),$firstDay[0].$firstDay[1].$firstDay[2].$firstDay[3])));
}
$this->MESE_NUMBER=date("m",mktime(0,0,0,$firstDay[5].$firstDay[6],$firstDay[8].$firstDay[9],$firstDay[0].$firstDay[1].$firstDay[2].$firstDay[3])); /// Numero della settimana dell'anno
}
return $this->MESE;
}
/// Disegna il calendario mensile
function designCalendar(
/// Array con il contenuto degli item
$itemList,
/// Disegna Progress Bar? (default=y)
$progress_bar,
/// Tipo di output: di default html
$type,
/// Nome
$calendar_name,
/// Aggiunge l'icona relativa alla reperibilit� (H24).
$myH24,
/// Aggiunge l'icona relativa alla trasferta (Lodging).
$myLodging,
/// Aggiunge l'icona relativa ai rimborsi (Payback).
$myPayback
) {
if (!$type) { $type="html"; }
switch ($type) {
case "html":
if ($calendar_name) { $this->CALENDAR_NAME=$calendar_name; } else { $this->CALENDAR_NAME="calendar".rand(0,1000); }
// $OGGI_PREV_MESE=date("Y-m-d",mktime(0,0,0,($this->OGGI[5].$this->OGGI[6])-1,$this->OGGI[8].$this->OGGI[9],$this->OGGI[0].$this->OGGI[1].$this->OGGI[2].$this->OGGI[3]));
// $OGGI_NEXT_MESE=date("Y-m-d",mktime(0,0,0,($this->OGGI[5].$this->OGGI[6])+1,$this->OGGI[8].$this->OGGI[9],$this->OGGI[0].$this->OGGI[1].$this->OGGI[2].$this->OGGI[3]));
$OGGI_PREV_MESE=date("Y-m-d",mktime(0,0,0,($this->OGGI[5].$this->OGGI[6]),(01)-1,$this->OGGI[0].$this->OGGI[1].$this->OGGI[2].$this->OGGI[3]));
$OGGI_NEXT_MESE=date("Y-m-d",mktime(0,0,0,($this->OGGI[5].$this->OGGI[6])+1,"01",$this->OGGI[0].$this->OGGI[1].$this->OGGI[2].$this->OGGI[3]));
echo "<a name=\"".$this->CALENDAR_NAME."\" />";
echo "<a href=\"javascript:window.document.forms[0].OGGI.value='".$OGGI_PREV_MESE."';window.document.forms[0].action=window.document.forms[0].action+'#".$this->CALENDAR_NAME."';window.document.forms[0].submit();\" title=\"Previous Month\"><img src=\"images/go_prev_on.gif\" border=\"0\" alt=\"\"></a> ";
echo "<i>SELECTED DATE: ".$this->OGGI."</i>";
echo " <a href=\"javascript:window.document.forms[0].OGGI.value='".$OGGI_NEXT_MESE."';window.document.forms[0].action=window.document.forms[0].action+'#".$this->CALENDAR_NAME."';window.document.forms[0].submit();\" title=\"Next Month\"><img src=\"images/go_next_on.gif\" border=\"0\" alt=\"\"></a>";
echo "<table class=\"calendar\">";
echo "<tr>";
for ($cont_day=0;$cont_day<7;$cont_day++) {
echo "<td class=\"cal_day_title\">";
echo substr($this->MESE[0]->SETTIMANA[$cont_day]->GIORNO["it"],0,3);
echo "</td>";
}
echo "</tr>";
for ($cont_week=0;$cont_week<count($this->MESE);$cont_week++) {
echo "<tr>";
for ($cont_day=0;$cont_day<7;$cont_day++) {
if ($this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["w"]=="0" || $this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["w"]=="6") {
$class="cal_day_festivo";
} else {
$class="cal_day_feriale";
}
// Verifica se � il mese corrente
if (($this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["m"])==$this->MESE_NUMBER) {
$background="";
} else {
$background="background: url('".URL_AXIST."/images/bg_cell.png') repeat left top;";
}
if ($this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["date"]==$this->OGGI) { $border="border: 2px solid #f00;"; } else { $border="border: 1px solid #ccc;"; }
$url_click="javascript:window.document.forms[0].OGGI.value='".$this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["date"]."';window.document.forms[0].action=window.document.forms[0].action+'#".$this->CALENDAR_NAME."';window.document.forms[0].submit();";
echo "<td class=\"".$class."\" style=\"".$background.$border."\" onClick=\"".$url_click."\">";
echo ( $this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["d"]);
### H24 ###
if (isset($myH24)) {
for ($i=1;$i<count($myH24);$i++) {
if ($myH24[$i]["DATE_H24"]==$this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["date"]) {
echo " <img src=\"".URL_AXIST."/images/h24.png\" alt=\"H24(Reperibilità)\" title=\"H24(Reperibilità)\">";
}
}
}
### Lodging ###
if (isset($myLodging)) {
for ($i=1;$i<count($myLodging);$i++) {
if ($myLodging[$i]["DATE_LODGING"]==$this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["date"]) {
echo " <img src=\"".URL_AXIST."/images/lodging.png\" alt=\"Lodging(Trasferta)\" title=\"Lodging(Trasferta)\">";
}
}
}
### Payback ###
if (isset($myPayback)) {
$contatore=0;
for ($i=1;$i<count($myPayback);$i++) {
if ($contatore==0 && $myPayback[$i]["DATE_PAYBACK"]==$this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["date"]) {
echo " <img src=\"".URL_AXIST."/images/payback.png\" alt=\"Payback(Rimborso)\" title=\"Payback(Rimborso)\">";
$contatore++;
}
}
}
echo "<br />";
// PROGRESS BAR
$tot=0.00;
$PBar="";
### ITEM ###
for ($cont_item=1;$cont_item<count($itemList);$cont_item++) {
if ($itemList[$cont_item]["Date"]==$this->MESE[$cont_week]->SETTIMANA[$cont_day]->GIORNO["date"]) {
$this->TOT_HO+=$itemList[$cont_item]["hO"];
$this->TOT_HS+=$itemList[$cont_item]["hS"];
$this->TOT_HF+=$itemList[$cont_item]["hF"];
$tot=$tot+$itemList[$cont_item]["hO"]+$itemList[$cont_item]["hS"]+$itemList[$cont_item]["hF"];
$PBar.="<table border=\"0\" cellspacing=\"1\" cellspadding=\"0\" class=\"progressBar\">";
############################################################
# Riga ordinarie
$PBar.= " <tr>";
for ($cont_hour=1;$cont_hour<=8;$cont_hour++) {
if (intval($tot)>=$cont_hour) {
$color="#".base_convert((255-($cont_hour*25)),10,16).base_convert((255-($cont_hour*25)),10,16)."FF";
} else {
$color="#F0F0FF";
}
$PBar.= "<td style=\"background-color:".$color.";\"></td>";
}
$PBar.= " </tr>";
# Riga STRAordinarie
$PBar.= " <tr>";
for ($cont_hour=1;$cont_hour<=8;$cont_hour++) {
if (intval($tot)>=($cont_hour+8)) {
$color="#FF".base_convert((200-($cont_hour*20)),10,16).base_convert((200-($cont_hour*20)),10,16);
} else {
$color="#FFF0F0";
}
$PBar.= "<td style=\"background-color:".$color.";\"></td>";
}
$PBar.= "</tr>";
$PBar.= "</table>";
############################################################
}
}
if (!$progress_bar==true) { echo "<br />";}
if (intval($tot)) { echo "<a class=\"tot\"> ".$tot."</a>"; }
if ($progress_bar==true) {
echo $PBar;
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
break;
}
}
}
class TAnno extends TMese {
function TAnno(
/// Anno
$year
) {
//
}
}
?>