/** * Returns the value for this year * * When a on the first/last week of the year, the year of the week is * calculated according to ISO-8601 * * @param string $format return value format ['int' | 'timestamp' | 'object' | 'array'] * * @return int e.g. 2003 or timestamp * @access public */ function thisYear($format = 'int') { $tmp_cal = new Calendar(); $tmp_cal->setTimestamp($this->thisWeek); $first_dow = $tmp_cal->thisDay('array'); $days_in_week = $tmp_cal->cE->getDaysInWeek($tmp_cal->year, $tmp_cal->month, $tmp_cal->day); $tmp_cal->day += $days_in_week; $last_dow = $tmp_cal->thisDay('array'); if ($first_dow['year'] == $last_dow['year']) { return $first_dow['year']; } if ($last_dow['day'] > floor($days_in_week / 2)) { return $last_dow['year']; } return $first_dow['year']; }
/** * Returns this day * <b>Note:</b> overrides parent method to prevent values * being returned for "Empty" days * @param boolean set to true to return a timestamp * @return int day of month e.g. 11 * @access public */ function thisDay($asTs = false) { if ($this->empty) { return false; } else { return Calendar::thisDay($asTs); } }
function GestionAffichageCalendrier($type = 'calendrier') { $retour = '<div class="' . $type . '">'; $url = $GLOBALS['_BAZAR_']['url']; $db =& $GLOBALS['_BAZAR_']['db']; // Nettoyage de l'url de la query string $chaine_url = $url->getQueryString(); $tab_params = explode('&', $chaine_url); if (count($tab_params) == 0) { $tab_params = explode('&', $chaine_url); } foreach ($tab_params as $param) { $tab_parametre = explode('=', $param); if ($tab_parametre[0] != 'wiki') { $url->removeQueryString($tab_parametre[0]); } } if (!isset($_GET['y'])) { $_GET['y'] = date('Y'); } if (!isset($_GET['m'])) { $_GET['m'] = date('m'); } // Construction Mois en Cours $month = new Calendar_Month_Weekdays($_GET['y'], $_GET['m']); $curStamp = $month->getTimeStamp(); $url->addQueryString('y', date('Y', $curStamp)); $url->addQueryString('m', date('n', $curStamp)); $url->addQueryString('d', date('j', $curStamp)); $cur = str_replace('&', '&', $url->getUrl()); // Gestion de l'affichage des titres des evenements if (isset($_GET['ctt']) && $_GET['ctt'] == '1') { $url->addQueryString('tt', '0'); if (isset($_GET['tt']) && $_GET['tt'] == '0') { $url->addQueryString('tt', '1'); } $tc_lien = str_replace('&', '&', $url->getUrl()); } else { $url->addQueryString('tt', '0'); if (isset($_GET['tt']) && $_GET['tt'] == '0') { $url->addQueryString('tt', '1'); } $url->addQueryString('ctt', '1'); $tc_lien = str_replace('&', '&', $url->getUrl()); } $url->removeQueryString('ctt'); $url->removeQueryString('tt'); $tc_txt = BAZ_AFFICHE_TITRES_COMPLETS; if (isset($_GET['tt']) && $_GET['tt'] == '0') { $tc_txt = BAZ_TRONQUER_TITRES; $url->addQueryString('tt', $_GET['tt']); } // Navigation $prevStamp = $month->prevMonth(true); $url->addQueryString('y', date('Y', $prevStamp)); $url->addQueryString('m', date('n', $prevStamp)); $url->addQueryString('d', date('j', $prevStamp)); $prev = str_replace('&', '&', $url->getUrl()); $nextStamp = $month->nextMonth(true); $url->addQueryString('y', date('Y', $nextStamp)); $url->addQueryString('m', date('n', $nextStamp)); $url->addQueryString('d', date('j', $nextStamp)); $next = str_replace('&', '&', $url->getUrl()); // Suppression du parametre de troncage des titres $url->removeQueryString('tt'); $fr_month = array("1" => BAZ_JANVIER, "2" => BAZ_FEVRIER, "3" => BAZ_MARS, "4" => BAZ_AVRIL, "5" => BAZ_MAI, "6" => BAZ_JUIN, "7" => BAZ_JUILLET, "8" => BAZ_AOUT, "9" => BAZ_SEPTEMBRE, "10" => BAZ_OCTOBRE, "11" => BAZ_NOVEMBRE, "12" => BAZ_DECEMBRE); if ($type == 'calendrier' || $type == 'calendrierjquery' || $type == 'calendrierjquerymini') { $retour .= '<div class="cal_entete">' . "\n"; $retour .= '<span class="cal_navigation">' . "\n"; $retour .= '<a class="cal_precedent_lien" href="' . $prev . '" title="Allez au mois precedent"><img class="cal_precedent_img" src="' . BAZ_CHEMIN . 'presentation/images/cal_precedent.png" alt="<<"/></a>' . "\n"; $retour .= '<a class="cal_mois_courrant" href="' . $cur . '">'; $retour .= $fr_month[date('n', $curStamp)]; $retour .= ' '; $retour .= date('Y', $curStamp); $retour .= '</a>' . "\n"; $retour .= '<a class="cal_suivant_lien" href="' . $next . '" title="Allez au mois suivant"><img class="cal_suivant_img" src="' . BAZ_CHEMIN . 'presentation/images/cal_suivant.png" alt=">>"/></a>' . "\n"; $retour .= '</span>' . "\n"; if ($type == 'calendrier') { $retour .= '<span class="tc_lien">' . '<a href="' . $tc_lien . '">' . $tc_txt . '</a>' . '</span>' . "\n"; } $retour .= '</div>' . "\n"; } // Vue Mois calendrier ou vue applette if (!isset($_GET['id_fiche']) && ($type == 'calendrier' || $type == 'calendrierjquery' || $type == 'calendrierjquerymini')) { // Recherche evenement de la periode selectionnée $ts_jour_fin_mois = $month->nextMonth('timestamp'); $ts_jour_debut_mois = $month->thisMonth('timestamp'); //on recherche toutes les fiches puis on trie sur ceux qui possede une date $tableau_resultat = baz_requete_recherche_fiches('', 'chronologique', $GLOBALS['_BAZAR_']['id_typeannonce'], $GLOBALS['_BAZAR_']['categorie_nature']); $tab_fiches = array(); foreach ($tableau_resultat as $fiche) { $valeurs_fiche = json_decode($fiche[0], true); $valeurs_fiche = array_map('utf8_decode', $valeurs_fiche); //echo $valeurs_fiche['bf_titre'].' du '.$valeurs_fiche['bf_date_debut_evenement'].' au '.$valeurs_fiche['bf_date_fin_evenement'].'<br />'; //echo 'date fin mois : '.date('Y-n-j', $ts_jour_fin_mois).'<br />'; //echo 'date debut mois : '.date('Y-n-j', $ts_jour_debut_mois).'<br />'; if (isset($valeurs_fiche['bf_date_debut_evenement'])) { $dateArr = explode("-", $valeurs_fiche['bf_date_debut_evenement']); $date1Int = mktime(0, 0, 0, $dateArr[1], $dateArr[2], $dateArr[0]); } else { $date1Int = NULL; } if (isset($valeurs_fiche['bf_date_fin_evenement'])) { $dateArr = explode("-", $valeurs_fiche['bf_date_fin_evenement']); $date2Int = mktime(0, 0, 0, $dateArr[1], $dateArr[2], $dateArr[0]); } else { $date2Int = NULL; } //echo ($date1Int < $ts_jour_fin_mois).' = ($date1Int < $ts_jour_fin_mois)'; //echo ($date2Int >= $ts_jour_debut_mois).' = ($date2Int >= $ts_jour_debut_mois)'; if ($date1Int && $date2Int) { $tab_fiches[] = $valeurs_fiche; } } $selection = array(); $evenements = array(); $annee = date('Y', $curStamp); $mois = date('m', $curStamp); $tablo_jours = array(); foreach ($tab_fiches as $val_fiche) { list($annee_debut, $mois_debut, $jour_debut) = explode('-', $val_fiche['bf_date_debut_evenement']); list($annee_fin, $mois_fin, $jour_fin) = explode('-', $val_fiche['bf_date_fin_evenement']); $Calendrier = new Calendar($annee_debut, $mois_debut, $jour_debut); $ts_jour_suivant = $Calendrier->thisDay('timestamp'); $ts_jour_fin = mktime(0, 0, 0, $mois_fin, $jour_fin, $annee_fin); $naviguer = true; while ($naviguer && $ts_jour_suivant <= $ts_jour_fin) { // Si le jours suivant est inferieur a la date de fin du mois courrant, on continue... if ($ts_jour_suivant < $ts_jour_fin_mois) { $cle_j = date('Y-m-d', $ts_jour_suivant); if (!isset($tablo_jours[$cle_j])) { $tablo_jours[$cle_j]['Calendar_Day'] = new Calendar_Day(date('Y', $ts_jour_suivant), date('m', $ts_jour_suivant), date('d', $ts_jour_suivant)); $tablo_jours[$cle_j]['Diary_Event'] = new DiaryEvent($tablo_jours[$cle_j]['Calendar_Day']); } $tablo_jours[$cle_j]['Diary_Event']->setEntry($val_fiche['bf_titre']); $ts_jour_suivant = $Calendrier->nextDay('timestamp'); //echo "ici$ts_jour_suivant-"; $Calendrier->setTimestamp($ts_jour_suivant); //echo "la".$Calendrier->thisDay('timestamp')."-"; } else { $naviguer = false; } } } // Add the decorator to the selection foreach ($tablo_jours as $jour) { $selection[] = $jour['Diary_Event']; } // Affichage Calendrier $month->build($selection); $retour .= '<table>' . "\n" . '<colgroup>' . "\n" . '<col class="cal_lundi"/>' . "\n" . '<col class="cal_mardi"/>' . "\n" . '<col class="cal_mercredi"/>' . "\n" . '<col class="cal_jeudi"/>' . "\n" . '<col class="cal_vendredi"/>' . "\n" . '<col class="cal_samedi"/>' . "\n" . '<col class="cal_dimanche"/>' . "\n" . '</colgroup>' . "\n" . '<thead>' . "\n" . "<tr>" . "\n"; if ($type == 'calendrier' || $type == 'calendrierjquery') { $retour .= "<th> " . BAZ_LUNDI . "</th>\n\t\t\t <th> " . BAZ_MARDI . "</th>\n\t\t\t <th> " . BAZ_MERCREDI . "</th>\n\t\t\t <th> " . BAZ_JEUDI . "</th>\n\t\t\t <th> " . BAZ_VENDREDI . "</th>\n\t\t\t <th> " . BAZ_SAMEDI . "</th>\n\t\t\t <th> " . BAZ_DIMANCHE . "</th>\n\t\t\t </tr>\n\t\t\t " . '</thead>' . "\n" . '<tbody>' . "\n"; } elseif ($type == 'calendrierjquerymini') { $retour .= "<th> " . BAZ_LUNDI_COURT . "</th>\n\t\t\t <th> " . BAZ_MARDI_COURT . "</th>\n\t\t\t <th> " . BAZ_MERCREDI_COURT . "</th>\n\t\t\t <th> " . BAZ_JEUDI_COURT . "</th>\n\t\t\t <th> " . BAZ_VENDREDI_COURT . "</th>\n\t\t\t <th> " . BAZ_SAMEDI_COURT . "</th>\n\t\t\t <th> " . BAZ_DIMANCHE_COURT . "</th>\n\t\t\t </tr>\n\t\t\t " . '</thead>' . "\n" . '<tbody>' . "\n"; } $todayStamp = time(); $today_ymd = date('Ymd', $todayStamp); // Other month : mois while ($day = $month->fetch()) { $dayStamp = $day->thisDay(true); $day_ymd = date('Ymd', $dayStamp); if ($day->isEmpty()) { $class = "cal_autre_mois"; } else { if ($day_ymd < $today_ymd) { $class = "cal_mois_precedent"; } else { if ($day_ymd == $today_ymd) { $class = "cal_jour_courant"; } else { $class = "cal_mois_courant"; } } } $url->addQueryString('y', date('Y', $dayStamp)); $url->addQueryString('m', date('n', $dayStamp)); $url->addQueryString('d', date('j', $dayStamp)); $link = $url->getUrl(); // isFirst() to find start of week if ($day->isFirst()) { $retour .= "<tr>\n"; } if ($type == 'calendrier') { $retour .= "<td class=\"" . $class . "\">" . '<span class="cal_j">' . $day->thisDay() . '</span>' . "\n"; if ($day->isSelected()) { $evenements = $day->getEntry(); $evenements_nbre = count($evenements); $evenemt_xhtml = ''; while ($ligne_evenement = array_pop($evenements)) { $id_fiches = $ligne_evenement->bf_id_fiche; $url->addQueryString('id_fiche', $id_fiches); $link = str_replace('&', '&', $url->getUrl()); if (!isset($_GET['tt']) || isset($_GET['tt']) && $_GET['tt'] == '1') { $titre_taille = strlen($ligne_evenement->bf_titre); $titre = htmlentities($titre_taille > 40 ? substr($ligne_evenement->bf_titre, 0, 40) . '...' : $ligne_evenement->bf_titre, ENT_QUOTES); } else { $titre = htmlentities($ligne_evenement->bf_titre, ENT_QUOTES); } $evenemt_xhtml .= '<li class="tooltip" title="' . htmlentities($ligne_evenement->bf_titre, ENT_QUOTES) . '"><a class="cal_evenemt" href="' . $link . '">' . $titre . '</a></li>' . "\n"; $url->removeQueryString('id_fiches'); } if ($evenements_nbre > 0) { $retour .= '<ul class="cal_evenemt_liste">'; $retour .= $evenemt_xhtml; $retour .= '</ul>'; } } } elseif ($type == 'calendrierjquery' || $type == 'calendrierjquerymini') { if ($day->isSelected()) { $evenements = $day->getEntry(); $evenements_nbre = count($evenements); $evenemt_xhtml = ''; while ($ligne_evenement = array_pop($evenements)) { $id_fiches = $ligne_evenement->bf_id_fiche; $url->addQueryString('id_fiche', $id_fiches); $link = str_replace('&', '&', $url->getUrl()); $titre = htmlentities($ligne_evenement->bf_titre, ENT_QUOTES); $evenemt_xhtml .= '<li> <span class="titre_evenement"><a class="cal_evenemt" href="' . $link . '">' . $titre . '</a></span> </li>'; $url->removeQueryString('id_fiches'); } if ($evenements_nbre > 0) { $retour .= '<td class="' . $class . ' date_avec_evenements">' . $day->thisDay() . ' <div class="evenements"> <ul>'; $retour .= $evenemt_xhtml; $retour .= '</ul> </div>'; } else { $retour .= '<td class="' . $class . '">' . $day->thisDay() . "\n"; } } else { $retour .= '<td class="' . $class . '">' . $day->thisDay() . "\n"; } } elseif ($type == 'calendriermini') { $lien_date = "<td class=\"" . $class . "\">" . $day->thisDay(); if ($day->isSelected()) { $evenements = $day->getEntry(); $id_fiches = array(); while ($ligne_evenement = array_pop($evenements)) { $id_fiches[] = $ligne_evenement->bf_id_fiche; } $url->addQueryString('id_fiches', $id_fiches); $link = str_replace('&', '&', $url->getUrl()); $lien_date = "<td class=\"" . $class . "\"><a href=\"" . $link . "\">" . $day->thisDay() . "</a>\n"; $url->removeQueryString('id_fiches'); } $retour .= $lien_date; } $retour .= "</td>\n"; // isLast() to find end of week if ($day->isLast()) { $retour .= "</tr>\n"; } } $retour .= "</tbody></table>"; } // Vue detail if (isset($_GET['id_fiche'])) { // Ajout d'un titre pour la page avec la date $jours = array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'); $mois = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'); $timestamp = strtotime($_GET['y'] . '/' . $_GET['m'] . '/' . $_GET['d']); $retour .= '<h1>' . $jours[date('w', $timestamp) - 1] . ' ' . $_GET['d'] . ' ' . $mois[$_GET['m'] - 1] . ' ' . $_GET['y'] . '</h1>'; $retour .= baz_voir_fiche(0, $_GET['id_fiche']); // Un lien pour retourner au calendrier $url->removeQueryString('id_fiche'); $url->removeQueryString('y'); $url->removeQueryString('m'); $url->removeQueryString('d'); $url->addQueryString('y', $_GET['y']); $url->addQueryString('m', $_GET['m']); $url->addQueryString('d', $_GET['d']); $retour .= '<div class="retour"><a href="' . str_replace('&', '&', $url->getUrl()) . '">Retour au calendrier</a></div>'; } // Nettoyage de l'url $url->removeQueryString('id_fiche'); $url->removeQueryString('y'); $url->removeQueryString('m'); $url->removeQueryString('d'); return $retour . "\n" . '</div>' . "\n"; }