PDA

Zobacz pełną wersję : Kalendarz pokazuje o 1 dzień mniej niż powinien



xfm
05-04-2007, 20:05
Mam problem z którym borykam się już od jakiegoś czasu i nie potrafie sobie z nim poradzić. Dotyczy on modułu kalendarza wchodzącego do kompletu z komponentem Eventlist ze strony http://www.schlu.net Przeszukiwałem forum autora, ale niestety nie władam biegle j. niemieckim, a w innych miejscach nie ma informacji na temat.
Błąd w działaniu tego kalendarza polega na pokazywaniu jakiegoś wydarzenia zawsze o jeden dzień mniej, czyli jeżeli w komponencie ustawie date np. 8 kwiecień, to kalendarz wyświetla 7 kwiecień. Sam komponent pokazuje dobrze tak samo jak i moduł ostatnich wydarzeń. Dzieje się tak na serwerze który mam postawiony do testów na localhost jak i wykupionym hostingu w nazwa.pl
Liczę na waszą pomoc :)

xfm
05-04-2007, 23:29
Pozwoliłem sobie wkleić kod tego kalendarza, aby było wiadomo o co chodzi.


<?php
/**
* @version 0.8
* @package Eventlist--->Modul
* @copyright (C) 2005 Christoph Lukes / Keith Devens
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*this modified version was originally from Keith Devens
* PHP Calendar (version 2.3), written by Keith Devens
* http://keithdevens.com/software/php_calendar
* see example at http://keithdevens.com/weblog
* License: http://keithdevens.com/software/license
*/
defined( '_VALID_MOS' ) or
die( 'Directly access to file not permited.' );

global $database, $mosConfig_offset, $mosConfig_live_site, $my;

//get switch trigger
$el_mcal = intval( mosGetParam( $_GET, 'el_mcal' ) );

//get Itemid of EL
$database->SetQuery("SELECT id"
. "\nFROM #__menu"
. "\nWHERE link = 'index.php?option=com_eventlist'"
. "\nLIMIT 1");
$Itemid = $database->loadResult();

// Parameters
$minusdays = $params->get( 'minus','2' );
$oldDeletemod = $params->get('oldDeletemod', '0');
$day_name_length = $params->get( 'day_name_length', '2' );
$first_day = $params->get( 'first_day', '1' );
$todayback = trim( $params->get( 'todayback' ));
$todayfontcolor = trim( $params->get( 'todayfontcolor' ));
$Year_length = $params->get( 'Year_length', '1' );
$Month_length = $params->get( 'Month_length', '0' );

//Datensätze löschen die älter als x Tage sind
global $database, $my;

if ($oldDeletemod == 1) {
$database->SetQuery("DELETE FROM #__eventlist_dates"
. "\nWHERE DATE_SUB(NOW(), INTERVAL $minusdays DAY) > dates");
$database->Query();
}

//Datensätze in das Archiv verschieben die älter als $minus Tage sind
if ($oldDeletemod == 2) {
$database->SetQuery("UPDATE #__eventlist_dates SET published= -1"
. "\nWHERE DATE_SUB(NOW(), INTERVAL $minusdays DAY) > dates");
$database->Query();
}

// calendar function
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array(), $todayback, $todayfontcolor, $Year_length, $Month_length){
$first_of_month = gmmktime(0,0,0,$month,1,$year);
#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()
$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_mon th));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$year_length = $Year_length ? $year : substr($year, 2, 3);
$month_length = $Month_length ? substr($month_name,0,3) : $month_name;
$title = htmlentities(ucfirst($month_length)).'&nbsp;'.$year_len gth; #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table class="calendar">'."\n".
'<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr>";
}

// Today
$time = time ();
$today = date( 'j', $time);
$currmonth = date( 'm', $time);
$curryear = date( 'Y', $time);

if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_mon th); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday = 0; #start a new week
$calendar .= "</tr>\n<tr>";
}

if (($day == $today) & ($currmonth == $month) & ($curryear == $year)) {
$istoday = 1;
} else {
$istoday = 0;
}
if ($day < 10) {
$space = '&nbsp;&nbsp;';
} else {
$space = '';
}

if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content)) $content = $day;

$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
}
else //$calendar .= "<td>$day</td>";
$calendar .= '<td>'.($istoday && $todayback? '<span style="background-color:'. $todayback. '; font-weight:bold; color:'. $todayfontcolor. '; ">'.$space.$day.'</span>' : $space.$day).'</td>';
}
if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days
return $calendar."</tr>\n</table>\n";
}
//set now
$time = time();
// Strip Requested URL
$pos1 = strpos ($_SERVER['REQUEST_URI'], 'index.php?');
$pos2 = strpos ($_SERVER['REQUEST_URI'], '&el_mcal');
$pos3 = $pos2 - $pos1;
if ($pos2) {
$request_link = substr ($_SERVER['REQUEST_URI'], $pos1, $pos3);
} else {
$request_link = strstr ($_SERVER['REQUEST_URI'], 'index.php?');
}
if ($request_link == '') {
$request_link = 'index.php?';
}
// Get Relative Month ID
if ( !$el_mcal ) {
$emx = 0;
} else {
$emx = $el_mcal;
}
$next_midx = $emx + 1;
$prev_midx = $emx - 1;
$month = date( 'm', $time) + $emx;
$year = date( 'Y', $time);
$today = date('j',$time);
//Get eventdates
$query = "SELECT DAYOFMONTH(a.dates) AS created_day, a.id, a.catsid, a.dates, a.times, YEAR(a.dates) AS created_year, MONTH(a.dates) AS created_month"
. "\n FROM #__eventlist_dates AS a"
. "\nLEFT JOIN #__eventlist_categories AS c ON c.id = a.catsid"
. "\nWHERE a.published = 1"
. "\nAND c.access <= ".$my->gid
. "\n GROUP BY created_year DESC, created_month DESC, created_day DESC"
;

$database->setQuery( $query );
$events = $database->loadObjectList();
$days = array();
foreach ( $events as $event ) {
if (($year == $event->created_year) && ($month == $event->created_month)) {
$created_month = mosFormatDate ( $event->dates.' '.$event->times, "%m" );
$month_name = mosFormatDate ( $event->dates.' '.$event->times, "%B" );
$created_year = mosFormatDate ( $event->dates.' '.$event->times, "%Y" );
$tmptime = $event->dates.' '.$event->times;
if ( $tmptime && ereg( "([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $tmptime, $regs ) ) {
$tmptime = mktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] );
$tmptime = $tmptime + ($mosConfig_offset*60*60) ;
}
$created_day = date ( 'j', $tmptime );
//$link = sefRelToAbs( 'index.php?option=com_eventlist&Itemid='.$Itemid.'&func=details&did='.$event->id.'&el_mcal='.$emx );
$link = sefRelToAbs( 'index.php?option=com_eventlist&Itemid='.$Itemid.'&func=dayview&day='.$event->dates.'&el_mcal='.$emx );
$day = array ($created_day => array($link));
$days = $days + $day;
}
}

//Create Links
$prev_link = $mosConfig_live_site.'/'.$request_link. '&el_mcal='.$prev_midx ;
$next_link = $mosConfig_live_site.'/'.$request_link. '&el_mcal='.$next_midx ;
//Month Names
$first_of_month = gmmktime(0,0,0,$month-1,1,$year);
list($tmp, $year, $prev_month, $weekday) = explode(',',gmstrftime('%m,%Y,%b,%w',$first_of_mon th));

$first_of_month = gmmktime(0,0,0,$month+1,1,$year);
list($tmp, $year, $next_month, $weekday) = explode(',',gmstrftime('%m,%Y,%b,%w',$first_of_mon th));
//Creating switching links
$pn = array( $prev_month=>$prev_link, $next_month=>$next_link);
//Output
echo "<div align=center>";
echo generate_calendar(date('Y', $time), $month, $days, $day_name_length, NULL, $first_day, $pn, $todayback, $todayfontcolor, $Year_length, $Month_length);
echo "</div>";
?>