TinyPortal

Development => Block Codes => Topic started by: bloc on September 03, 2005, 11:30:42 AM

Title: SMF Calendar Block
Post by: bloc on September 03, 2005, 11:30:42 AM
Here is simple calendar to be used in a php-block, the code is from http://keithdevens.com/software/php_calendar , slightly modified. It simply displays the date and the days in current month/year. Current day is highlighted. Probably better to turn off "title/frame" in the block as well. :)


global $scripturl;

         $now = mktime();
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: red; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = NULL;
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr>";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr>";
}
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 class=\"smalltext\">$day</td>";
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar."</tr>\n</table>\n";



See screenshot for how it looks.

[attachment deleted by admin]
Title: Re: Calendar in a php-block
Post by: Racenut on September 03, 2005, 12:37:50 PM
Worked like a charmÂÃ,  :) I do agree Bloc that it would be cool to have the mini calendar call info from the forum calendar. To me, it looks better using the frame.

In my opinion, this is the stuff that is going to make TP shine. To me, versitility in a portal is the most important thing. You code guru's keep coming up with more neat stuff  :laugh:
Title: Re: Calendar in a php-block
Post by: Miraenda on September 03, 2005, 03:32:49 PM
Great feature to include, and I think linking it to the forum's calendar would be fantastic, too.  Is this a possibility to have in a future TP version this calendar available and linking to the forum's calendar then? :)
Title: Re: Calendar in a php-block
Post by: ontap on September 03, 2005, 04:09:34 PM

thanks for looking into this bloc, is there anyway of highlighten events or birthdays on the calendar block?
Title: Re: Calendar in a php-block
Post by: IchBin on September 03, 2005, 04:29:10 PM
Currently this Calendar isn't integrated with the SMF one. So having events or birthdays etc. isn't possible.  I imagine that will be another little project that he'll be adding to his list.
Title: Re: Calendar in a php-block
Post by: bloc on September 04, 2005, 08:45:01 AM
Its not difficult to link events, birthdays etc. to it..but I will need to add fetching of the info to the code.

I was thinking perhaps adding some form of "snippet downloading" in tpadmin section at one point..but I archived that one for the time being. A live news part telling what snippets is availabe is more realistic perhaps. Adding of course latest version of TP available too.
Title: Re: Calendar in a php-block
Post by: IchBin on September 04, 2005, 08:13:55 PM
That is an awesome idea Bloc. That would make it so easy for everyone to customize their TP's.
Title: Re: Calendar in a php-block
Post by: bloc on September 05, 2005, 11:04:48 AM
Yes, I am going for this, especially when its so many versions out.
Title: Re: Calendar in a php-block
Post by: borgBOB on September 07, 2005, 07:44:56 AM
Does this calendar adjust to the user selected / or board default theme?
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 11:16:01 AM
I've done a little change in this block.
It doesn't shows info from the smf calendar but now it links month and days to it


$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar."</tr>\n</table>\n";
Title: Re: Calendar in a php-block
Post by: bloc on September 07, 2005, 12:42:03 PM
Great work, pcw. :)
Title: Re: Calendar in a php-block
Post by: Miraenda on September 07, 2005, 01:35:29 PM
I just added pcw's changed version of the calendar to my main TP testing board - http://skewed3.com/

Looks pretty good, thanks a lot to both Bloc and pcw :D
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 02:45:12 PM
using pcw's version i get this when i do the php test:

$now = mktime(); $today = date(\'j\',$now); $year = date(\"Y\",$now); $month = date(\"n\",$now); $days = array($today=>array(NULL,NULL,\'\'.$today.\'\')); $day_name_length = 3; $month_href = $scripturl . \'?action=calendar\'; $first_day = 1; $pn = array();$first_of_month = gmmktime(0,0,0,$month,1,$year);

also i'm using helios so the day that is today doesn't appear to be highlighted, it just doesn't appear to be a link. it would be nice if the border on the day worked so its easier to see! ty :)
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 03:06:32 PM
Search for $days = array($today=>array(NULL,NULL,\'\'.$today.\'\')); in your code and replace it with $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

This will link your "Today" to the smf-calendar.

^^Feel free to modify the style (css)ÂÃ,  ;)

Screenshot for Helios_Multi_TP on my TP
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 04:03:16 PM
okay i see the code, and how it should show a white block behind the text for the day, but here is how it shows up, and here is my code.


$now = mktime();
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $today = date('j',$now);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $year = date("Y",$now);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $month = date("n",$now);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $day_name_length = 3;
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $month_href = $scripturl . '?action=calendar';
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $first_day = 1;
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$titleÂÃ,  ÂÃ, = htmlentities(ucfirst($month_name)).' '.$year;ÂÃ,  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekdayÂÃ,  ÂÃ, = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar."</tr>\n</table>\n";


the code was copied exactly from your original post, and the correction you just suggested was already in place.

as you can see from the below, the current day, the seventh, is only white and barely distinguishable from the other day which are a light-green or light-blue.
screenshot:
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 04:36:45 PM
also, with the above code entered, when i click the PHP-test button, to check for errors, it outputs this code:
$now = mktime(); $today = date(\'j\',$now); $year = date(\"Y\",$now); $month = date(\"n\",$now); $days = array($today=>array(NULL,NULL,\'\'.$today.\'\')); $day_name_length = 3; $month_href = $scripturl . \'?action=calendar\'; $first_day = 1; $pn = array();$first_of_month = gmmktime(0,0,0,$month,1,$year);

The entire $days thing is exactly like what you had in your code, but it still outputs this for some reason. also, the \'.$today.\' part is a hyperlink to http://www.mysite.com/"/'.$scripturl./'?action=calendar;sa=post;month=\'.$month.\';year=\'.$year.\';day=\'.$today.\'\" (http://www.mysite.com/"/'.$scripturl./'?action=calendar;sa=post;month=%5C'.$month.%5C';year=%5C'.$year.%5C';day=%5C'.$today.%5C'%5C") within that specific field for php test.
Title: Re: Calendar in a php-block
Post by: crip on September 07, 2005, 04:52:57 PM
Cool calendar..I like it..thanks guys :)

Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 05:16:49 PM
did u made any changes in u'r Stylesheets (css-file) e.g. background-color for pseudo formats for links?
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 05:30:36 PM
its possible, i have many mods installed.i'll try restoring the css files to their originals
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 05:38:24 PM
i restored the original style.css file that came with helios_multi11_tp and it still shows up like that screenshot.
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 06:06:52 PM
can u give ma a link to u'r TP ?
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 06:09:03 PM
sent in PM :)
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 06:12:40 PM
^^empty your browser cache and try again  ;)

looks like u have cached an old css-file. i can see the white background.
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 06:13:35 PM
wow... thats odd. thanks :)

edit: that was wierd, my entire site went down for a minute or two :X my forum still isn't loading... :\
Title: Re: Calendar in a php-block
Post by: ontap on September 07, 2005, 08:04:27 PM
Quote from: pcw on September 07, 2005, 11:16:01 AM
I've done a little change in this block.
It doesn't shows info from the smf calendar but now it links month and days to it

great the way its links to the calendar but its leaves and error in the error log,

8: Undefined variable: scripturl
File: Themes\default\TPortalBlocks.template.php (eval?)
Line: 58

im guessing its this part of the code thas causing the error??...


href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>

href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a>


anyway to fix it up?.
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 08:18:15 PM
$scripturl is defined in ./Sources/QueryString.php
$scripturl = $boardurl . '/index.php';
that is included on top of ./index.php
require_once($sourcedir . '/QueryString.php');

try to use $boardurl.'/index.php' instead but $scripturl should be defined everytime u call ur forums index.php
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 08:34:33 PM
pcw still having that problem, only with IE though. i'm not sure why, and it causes multiple other errors, including screwing up that box that says PM: 1 and the ones below it. http://www.tinyportal.net/smf/index.php?topic=733.msg5679;topicseen#msg5679

tried emptying offline content, cookies, history, no luck.
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 08:39:29 PM
does the "PM Box Problem" also exists when u turn off the calendar-php-box ?
Title: Re: Calendar in a php-block
Post by: ontap on September 07, 2005, 08:44:17 PM
Quote from: pcw on September 07, 2005, 08:18:15 PM
$scripturl is defined in ./Sources/QueryString.php

try to use $boardurl.'/index.php' instead but $scripturl should be defined everytime u call ur forums index.php

changed it to "$boardurl" and the errors still appear but changed to

smf/index.php?action=tpadmin;sub=blocks
8: Undefined variable: boardurl
File: smf\Themes\default\TPortalBlocks.template.php (eval?)
Line: 58

smf/index.php
8: Undefined variable: boardurl
File: smf\Themes\default\TPortalBlocks.template.php (eval?)
Line: 5

smf/index.php
8: Undefined variable: scripturl
File: smf\Themes\default\TPortalBlocks.template.php (eval?)
Line: 8

is the error in TPortalBlocks.template.php or does something need changin on it?..
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 08:46:57 PM
yeah it has always been like it is in the screenshots. its not a forum issue, its my IE, i believe. it works fine on firefox, and you see it fine on IE, so i dunno...
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 08:48:52 PM
Search for <style type="text/css"><!--
       #navcontainerb ul
       {
                     margin: 4px 0;;
                     padding-left: 0;
                     list-style-type: none;
                     text-align: left;
       }

       #navcontainerb a
       {
                     display: block;
                     padding: 0px;
                     margin: 0px;
                     border: solid 1px transparent;
                     }

       #navcontainerb a:link, #navlistb a:visited
       {
                     text-decoration: none;
       }

       #navcontainerb a:hover
       {
                     background-color: #d0d0d2;
                     border: solid 1px #909090;
                     }
       --></style> 


in your index.php and remove it ;)
it should be right before the code of the "User-Block".
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 08:50:43 PM
the index.php in my root dir? that one doesn't have that code in it.
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 08:54:50 PM
uhm .. ur template-file  ::)

i found this part code ^^ in ur pages source by "view source code" ;)
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 08:56:20 PM
so index.template.php? sry i'm kinda bad at this :P
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 09:00:50 PM
i see that code in the source, but it doesn't say which file its in, and i checked the index.php in my helios_multi11_tp folder, and the index.template.php in same folder. also tried index.php in root dir, and this code did not appear.
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 09:14:25 PM
sorry, i don't have this code in my templates so i can't tell u the right file.

but try tportal.template.php  :coolsmiley:
Title: Re: Calendar in a php-block
Post by: bloc on September 08, 2005, 10:33:13 AM
Its in TPortalBlocks.template.php.

And the "scripturl" error can be solved by adding above the calendar code:

  global $scripturl;


Both $scripturl and $boardurl can made available, but needs to be set as global first, since its not set as that in every template file. $boardurl is the path to your forum folder, but $scripturl is the path to index.php, all laid out for you.
Title: Re: Calendar in a php-block
Post by: ontap on September 08, 2005, 05:47:37 PM

Quote from: Bloc on September 08, 2005, 10:33:13 AM
the "scripturl" error can be solved by adding above the calendar code:

  global $scripturl;


thanks bloc!... error free :)
Title: Re: Calendar in a php-block
Post by: redshark on September 13, 2005, 05:07:23 PM
is it a "final" version of this calendar on a download area ?
Would be great when we have a special area with "working" blocks....i mean

Cheers

ReD
Title: Re: Calendar in a php-block
Post by: bloc on September 13, 2005, 08:35:53 PM
I have plans for this...I want to add working blocks to a list that will be shown in tpadmin, fetched from this site.
Title: Re: Calendar in a php-block
Post by: Moocat on September 14, 2005, 03:02:19 AM
that would definitely be awesome :)
Title: Re: Calendar in a php-block
Post by: redshark on September 14, 2005, 04:53:54 AM
Many thx Bloc  8)
Title: Re: Calendar in a php-block
Post by: Kindred on October 02, 2005, 01:25:11 PM
I actually did a mambo module that calls for a tiny-calendar display that draws from the SMF calendar/datebook...

It's currently full of mambo parameters, but I'll see if I can modify it to be used here...
Title: Re: Calendar in a php-block
Post by: MikeEnIke on October 04, 2005, 04:46:42 AM
I can't seam to get it any skinnier really. I haven't tried profusely but adding 5 pixels to the right bar didnt change much. I haven't delved into the php yet. If you go to my site and check out the other themes you'll see waht i mean.
Title: Re: Calendar in a php-block
Post by: IchBin on October 04, 2005, 05:35:48 AM
I see what you mean Mike. I'll take a look and see if I can figure out what causes that.
Title: Re: Calendar in a php-block
Post by: MikeEnIke on October 04, 2005, 10:58:24 AM
Alright thanks. And umm this is going to sound weird. but "Ich Bin" is that accidental or on purpose that it is German. I just started taking german and that's how you say your age so I think it is I am or something along those lines  :)
Title: Re: Calendar in a php-block
Post by: IchBin on October 04, 2005, 02:19:40 PM
Yes that is exactly what it means. I took German in high school. When I started playing games online with some friends we started playing some WWII games so I picked some thing in German. My name literally translated means I am âââ,¬Å¾Ã,¢. :)
âââ,¬Å¾Ã,¢ = Tactical Massacre. Needless to say, most people call me Itch when talking on ventrilo.
Title: Re: Calendar in a php-block
Post by: Ray on October 04, 2005, 03:00:36 PM
I just call him ICH ;)
Title: Re: Calendar in a php-block
Post by: MikeEnIke on October 04, 2005, 08:14:33 PM
:) This is my first year of German. If I ever happen to talk to you on Ventrillo i will make sure to pronounce Ich correctly :) I feel special for picking it out. haha.
Title: Re: Calendar in a php-block
Post by: IchBin on October 04, 2005, 08:32:29 PM
Haha! I can't tell you how many times I get asked what it means or how to pronounce it. Seems we've had a few German speaking people join the forums lately too.
Title: Re: Calendar in a php-block
Post by: MikeEnIke on October 04, 2005, 08:54:22 PM
Good maybe they can help me past a few test haha. It's good to have a variety of countries. Ahh my forum went bonkers cause it was a double install it was running on (don't ask) and i tried to update and I forgot. So I'm compeletly reinstalling jsut with the same database. PITA but hey gotta get it working.

P.S. Yes I did say bonkers.

Bis Spater.
Title: Re: Calendar in a php-block
Post by: Skhilled on October 30, 2005, 03:22:01 AM
Is there a way to make Sunday the first day of the week?

Nevermind. Went to Keith Devens site and found out.!   ;D
Title: Re: Calendar in a php-block
Post by: Skhilled on November 02, 2005, 01:04:19 PM
i'm using the Neptune_TP theme and would like to know how to change the background of the title "Calendar" to that of the rest of the blocks...a pic is included to illustrate.

Title: Re: Calendar in a php-block
Post by: bloc on November 02, 2005, 01:14:32 PM
thats actually a error...it should be as the calendar is..no background-color in the name. Making it a link does that.
Title: Re: Calendar in a php-block
Post by: Skhilled on November 02, 2005, 02:06:23 PM
Ah, I see... and if I remember correctly there isn't a way to link it directly to the calendar as of yet, right?
Title: Re: Calendar in a php-block
Post by: bloc on November 02, 2005, 02:12:22 PM
No...I am working on that though.
Title: Re: Calendar in a php-block
Post by: Skhilled on November 02, 2005, 02:18:44 PM
I trust you'll succeed as usual!ÂÃ,   ;D
Title: Re: Calendar in a php-block
Post by: elpvn on November 15, 2005, 06:50:41 PM
It's a cool block, but how to resize it to a smaller block ?
Title: Re: Calendar in a php-block
Post by: bloc on November 15, 2005, 07:49:20 PM
Change the class used, so the texts will be smaller.
Title: Re: Calendar in a php-block
Post by: redshark on November 16, 2005, 03:34:21 AM
Is it possible that we can see the "birthdays", "events" and "holy days" in the calender block ? No with all written entrys, but with different colors around the date of the events i mean.

Like : 12 or 25

Most helpful was a link on this color marked date who will link into the "normal" calendar where the events are written in detail.


Thanks for any ideas.....

Cheers

ReD
Title: Re: Calendar in a php-block
Post by: feline on December 30, 2005, 02:56:28 AM
good job Bloc  8)

but .. for better optic use <td align="center" valign="middle"> for the day numbers.
Also, I have add two SSI function to complete this good work  ;)

here my code (part of change):
if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr>";
}
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content))  $content  = $day;
$calendar .= '<td align=\"center\" valign=\"middle\" '.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
}
else $calendar .= "<td align=\"center\" valign=\"middle\" class=\"smalltext\">$day</td>";
}

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Heutige Geburstage</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays(); flush;
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Anstehende Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar(); flush;
  echo '</td></tr>';
}

echo '</table>';


see my added picture ...

Fel


[attachment deleted by admin]
Title: Re: Calendar in a php-block
Post by: ontap on December 30, 2005, 03:41:35 AM
Quote from: feline on December 30, 2005, 02:56:28 AM
good job Bloc  8)

I have add two SSI function to complete this good work  ;)


Edit - Thanks!  :)


global $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';

Title: Re: Calendar in a php-block
Post by: rbh on January 03, 2006, 06:13:05 PM
how would i go about changing a word? where i have circled i want to change events to holidays. the upcoming events in green below that is fine.

this is from my site

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fthestegmanfamily.com%2Fimages%2Fcalendar.jpg&hash=ab2623ebfd935d9bf1eb16f867469ca39d4b2a03)
Title: Re: Calendar in a php-block
Post by: IchBin on January 03, 2006, 07:08:54 PM
I think if you open up index.english.php in the default/languages folder and edit this line.

$txt['calendar4b'] = 'Upcoming Events:';

Make it say what you want. :)
Title: Re: Calendar in a php-block
Post by: rbh on January 03, 2006, 07:35:56 PM
could only find index.english.php in themes/default. is this the one i would edit even if i am not using this theme? i looked through my other theme folders and found nothing.


edit: nevermind, thats the correct one to change. only thing is, it changed the bottom one, not the top. ;) i wanted to change the upcoming events in black, not the one in green, but i will play around and see what happens. thanks IchBin
Title: Re: Calendar in a php-block
Post by: IchBin on January 03, 2006, 09:53:22 PM
Sorry, I wasn't thinking when I posted that.
change the code in your block.

echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td>
Title: Re: Calendar in a php-block
Post by: rbh on January 03, 2006, 10:27:12 PM
thanks IchBin.....that was the fix i needed!
Title: Re: Calendar in a php-block
Post by: rbh on January 19, 2006, 01:26:05 AM
ok, i used this code on another forum and it isn't highlighting the current day. it just shows the current day with a little bigger font and no underline.  this forum is 1.1rc1 tp .75 and just using default theme. any suggestions?
Title: Re: Calendar in a php-block
Post by: Xarcell on January 19, 2006, 03:15:47 AM
Maybe it's a stylesheet issue. Your css file may be missing a class, or whatever you call it.

Look for: class="??" in the code you put in the block around the section that would cover the highlighting part. Make sure that class name is in teh stylesheet  css file you are using. If not, then add it.
Title: Re: Calendar in a php-block
Post by: mandos on February 04, 2006, 09:41:24 PM
any idea why the calendar goes one hour faster than the board time?
(it takes the server time... but i'm in a different timezone)
and can I (somehow) change the name of the dates to different ones (so as to place the greek names in it)??

thanks in advance
Title: Re: Calendar in a php-block
Post by: Xarcell on February 04, 2006, 10:12:49 PM
I actually added this to my stylesheet:


.calendar
{
font-size: xx-small;
font-family: verdana, sans-serif;
}


and changed all the classes in the snippet from:


class="smalltext"


to:


class="calendar"


This way, I don't have to increase teh width of the blocks to get the calendar to fit. Without shrinking everything else that uses the smalltext class funtion.
Title: Re: Calendar in a php-block
Post by: clemenzo on February 18, 2006, 07:03:00 AM
Quote from: mandos on February 04, 2006, 09:41:24 PM
any idea why the calendar goes one hour faster than the board time?
(it takes the server time... but i'm in a different timezone)
and can I (somehow) change the name of the dates to different ones (so as to place the greek names in it)??

thanks in advance

I also like to solve this issue. I think can be fixed by adding a line to pick up DST offset from SMF setting?
Title: Re: Calendar in a php-block
Post by: clemenzo on February 20, 2006, 08:23:24 AM
Anyone can help?
Title: Re: Calendar in a php-block
Post by: AussieBill on March 01, 2006, 10:28:48 AM
Is it possible to make today's birthdays and events bold, like they are on the board index?
Title: Re: Calendar in a php-block
Post by: ontap on March 01, 2006, 10:36:02 AM
Quote from: AussieBill on March 01, 2006, 10:28:48 AM
Is it possible to make today's birthdays and events bold, like they are on the board index?

yup you can change this bit of code for the block...


if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Upcoming Birthdays</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Upcoming Events</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysEvents();
  echo '</td></tr>';
}
Title: Re: Calendar in a php-block
Post by: chraz on March 01, 2006, 11:45:17 PM
When I use this calendar block code with the "Upcoming Events" additions from either feline or OnTap! (both from page 7 or this thread) it causes all the upcoming events to display in the "Linked Events" box above every thread I view, as if all of the events were linked to that thread (obviously they aren't). Disabling the Calendar box or removing the "Upcoming Events" addition to it causes the issue to stop.

I'm using v1.1RC2 and TP 0.8.6

Anybody know how to fix this?
Title: Re: Calendar in a php-block
Post by: AussieBill on March 02, 2006, 06:47:43 AM
Sorry OnTap!, I meant usernames and event titles. If a member is having a birthday today their name is bold in the Upcoming Calendar on the board index page. Likewise, an event occurring today is shown as bold. I was just wondering if we could do that in the Calendar block.
Title: Re: Calendar in a php-block
Post by: clemenzo on March 02, 2006, 04:07:22 PM
Quote from: clemenzo on February 18, 2006, 07:03:00 AM
Quote from: mandos on February 04, 2006, 09:41:24 PM
any idea why the calendar goes one hour faster than the board time?
(it takes the server time... but i'm in a different timezone)
and can I (somehow) change the name of the dates to different ones (so as to place the greek names in it)??

thanks in advance

I also like to solve this issue. I think can be fixed by adding a line to pick up DST offset from SMF setting?

I added a global variable to retrieve the time offset in SMF and add to current system date/time. The first day of week is changed to Sunday and day name is shortened to 2 characters.

global $scripturl, $modSettings;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar."</tr>\n</table>\n";
Title: Re: Calendar in a php-block
Post by: RoarinRow on March 05, 2006, 05:44:23 AM
Very cool, thanks!  I like it and it integrates with the calendar so someone just clicks on a date and a new post opens up to enter an event.   ;)

I may have missed it, but anyway I put the last two codes together.  Now it shows the calendar with the abbreviations with two characters, e.g. 'Mo' for Monday and any upcoming events.  Hope it's right.

global $scripturl, $modSettings;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';




[attachment deleted by admin]
Title: Re: Calendar in a php-block
Post by: daftdate on March 07, 2006, 06:15:08 PM
Ive just set up my calendar and it works like a charm thankyou very very much.  ;D
Title: Re: Calendar in a php-block
Post by: PZsHosting on March 10, 2006, 03:26:16 AM
Quote from: daftdate on March 07, 2006, 06:15:08 PM
Ive just set up my calendar and it works like a charm thankyou very very much.  ;D

Me too. I like that one! Thanks!
Title: Re: Calendar in a php-block
Post by: whoesa on March 14, 2006, 01:50:58 PM
Is it possible to change the colors of the saterday & sundays (red) and the color of today? It is only a bit bigger but still hard to see in Black22 theme.

Thanks
Title: Re: Calendar in a php-block
Post by: jackfolla on March 19, 2006, 01:19:19 PM
I like this calendar very much... I put it in my site (quasar.teoth.it (http://quasar.teoth.it)) but I'd like to see it speaking italian: is it possible?  :D
Title: Re: Calendar in a php-block
Post by: Paulie on March 22, 2006, 02:18:56 PM
I just installed RoarinRow`s version on my kids school pta board, mainly to link all the events that usually happens with schools. I think it`s a very handy addition.
Title: Re: Calendar in a php-block
Post by: ramapoughnative on March 22, 2006, 06:06:44 PM
This Calendar works great! Thanks
Title: Re: Calendar in a php-block
Post by: jackfolla on March 22, 2006, 06:23:47 PM
I'm still wondering if someone knows how to change the language used to show the month and the days of the week in the block...

Thanks in advance... :)
Title: Re: Calendar in a php-block
Post by: kail on March 25, 2006, 05:48:09 PM
I've made some mod. The most important one is that in the calendar the days that had an event are with a gray background and the days that will have an events with a yellow one. Also the Upcoming event list has been rewrited to have not only the name of the event but also the date.


global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array();

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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()

#retrieve this month events, holydays and birthdays
$days_in_month = gmdate('t',$first_of_month);
include_once($sourcedir . '/Calendar.php');
$low_date = $year.'-'.$month.'-01';
$high_date = $year.'-'.$month.'-'.$days_in_month;
$events = calendarEventArray($low_date, $high_date);
$birthdays = calendarBirthdayArray($low_date, $high_date);

#add important days to the days array
foreach($events as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($event['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

foreach($birthdays as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($birth['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

$today_date = $year.'-'.($month<10 ? '0'.$month : $month).'-'.$today;

if(empty($events[$today_date]))
$days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');
else
$days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: yellow; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');


$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#crate notice for the next N days events. N is set in Settings.
if (ssi_todaysCalendar('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['birthdays'])){
echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Birthdays</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
$birthdays = $result['birthdays'];
echo '
<span style="color: #' . $modSettings['cal_bdaycolor'] . ';">' . $txt['calendar3b'] . '</span><br />';
foreach( $birthdays as $member )
echo '
<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', '<br />';
echo '</td></tr>';
}
if(!empty($result['events']))
{
echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Upcomings</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4b'] . '</span><br /> ';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],8).'/'.substr($event['start_date'],5 , 2).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
}
  echo '</td></tr>';
}

echo '</table>';


Quote from: jackfolla on March 22, 2006, 06:23:47 PM
I'm still wondering if someone knows how to change the language used to show the month and the days of the week in the block...

Thanks in advance... :)

To change it you have to add a line to set the strftime function to your location. This link should help you...look bottom. http://www.php.net/manual/en/function.strftime.php
The function to use to set the location is setlocale().
Good Luck.
Title: Re: Calendar in a php-block
Post by: iowamf on March 25, 2006, 07:50:23 PM
Thanks - this is a great snippet.

I hope this does not sound "greedy" as this is already awesome code - but the addition of being able to navigate between months would make this even better ... perhaps little arrows in the top, ie: <-  MONTH ->
Title: Re: Calendar in a php-block
Post by: Xarcell on March 25, 2006, 08:34:59 PM
Quote from: iowamf on March 25, 2006, 07:50:23 PM
Thanks - this is a great snippet.

I hope this does not sound "greedy" as this is already awesome code - but the addition of being able to navigate between months would make this even better ... perhaps little arrows in the top, ie: <-  MONTH ->

I think that would be sweet also...
Title: Re: Calendar in a php-block
Post by: Xarcell on March 29, 2006, 05:38:51 AM
I tweaked this awhile back. I guess now's a good time to post it. I added highlighing for the days, and made it a bit smaller so that it fits more snuggly within small blocks.

I removed the classes because it uses a diffeent font, this way you don't have to   add another class to all your stylesheets per theme. I just wrote it in. Seemed easier that way...


global $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a align="center" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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 style=" font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 style=" font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#ededed'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" style=" font-size: xx-small; font-family: verdana, sans-serif;" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="calendarblock">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" style=" font-size: xx-small; font-family: verdana, sans-serif;" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" style=" font-size: xx-small; font-family: verdana, sans-serif;">';
  ssi_todaysCalendar();
  echo '</td></tr></table>';
}
Title: Re: Calendar in a php-block
Post by: Ray on March 29, 2006, 07:11:31 AM
But sunday is not on the left :(
Title: Re: Calendar in a php-block
Post by: TwinsX2Dad on March 29, 2006, 07:20:36 AM
They want to include Sunday as a WEEKEND day, Ray.

Get with the program!   ;D
Title: Re: Calendar in a php-block
Post by: Blue Steel on March 29, 2006, 09:44:43 AM
lol change $first_day = 1; to = 0 not 1 .. then sunday is the first day of the week (on the left)
Title: Re: Calendar in a php-block
Post by: rbh on March 31, 2006, 06:52:50 PM
well, i have tried multiple things and cant get it to work. what do i change to get the current day to highlight? if i use blocs original code on the first post the day shows up a different color and has a box around it, but when i try and use any of the other redone scripts it doesnt work. here is the script i am currently using.

global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array();

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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()

#retrieve this month events, holydays and birthdays
$days_in_month = gmdate('t',$first_of_month);
include_once($sourcedir . '/Calendar.php');
$low_date = $year.'-'.$month.'-01';
$high_date = $year.'-'.$month.'-'.$days_in_month;
$events = calendarEventArray($low_date, $high_date);
$birthdays = calendarBirthdayArray($low_date, $high_date);

#add important days to the days array
foreach($events as $startdate => $value)
   $days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($event['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');
   
foreach($birthdays as $startdate => $value)
   $days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($birth['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

$today_date = $year.'-'.($month<10 ? '0'.$month : $month).'-'.$today;

if(empty($events[$today_date]))
   $days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 3px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');
else
   $days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: yellow; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');


$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
   $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
   if($weekday == 7){
      $weekday   = 0; #start a new week
      $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
   }
   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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
      if(((($weekday+$first_day) % 7)==0))
      {
         $calendar .= ' style="color:#C00000;"';
      }
      $calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
   }
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#crate notice for the next N days events. N is set in Settings.
if (ssi_todaysCalendar('')) {
   $result = ssi_todaysCalendar('');
   if(!empty($result['birthdays'])){
      echo '<tr><td>
</td><td colspan="5" class="smalltext" align="center">Birthdays</td><td>
</td></tr><td colspan="7" class="smalltext">';
      $birthdays = $result['birthdays'];
      echo '
         <span style="color: #' . $modSettings['cal_bdaycolor'] . ';">' . $txt['calendar3b'] . '</span>
';
      foreach( $birthdays as $member )
         echo '
            <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', '
';
      echo '</td></tr>';   
   }
   if(!empty($result['events']))
   {
      echo '<tr><td>
</td><td colspan="5" class="smalltext" align="center">Upcomings</td><td>
</td></tr><td colspan="7" class="smalltext">';
      echo '
         <span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4b'] . '</span>
 ';
      $events = $result['events'];
      foreach ($events as $event)
      {
         echo '
            '.substr($event['start_date'],8).'/'.substr($event['start_date'],5 , 2).':';
         if ($event['can_edit'])
            echo '
            <a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
         echo '
         ' . $event['link'] . '
';
      }
   }
  echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: dkaye315 on April 14, 2006, 06:11:30 PM
Kept getting parse errors when trying to use the posted code with the latest iteration of events/birthdays addition, however, was able to get it twork using the following:

global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array();

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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()

#retrieve this month events, holydays and birthdays
$days_in_month = gmdate('t',$first_of_month);
include_once($sourcedir . '/Calendar.php');
$low_date = $year.'-'.$month.'-01';
$high_date = $year.'-'.$month.'-'.$days_in_month;
$events = calendarEventArray($low_date, $high_date);
$birthdays = calendarBirthdayArray($low_date, $high_date);

#add important days to the days array
foreach($events as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($event['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

foreach($birthdays as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($birth['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

$today_date = $year.'-'.($month<10 ? '0'.$month : $month).'-'.$today;

if(empty($events[$today_date]))
$days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');
else
$days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: yellow; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');


$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#crate notice for the next N days events. N is set in Settings.
if (ssi_todaysCalendar('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['birthdays'])){
echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Birthdays</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
$birthdays = $result['birthdays'];
echo '
<span style="color: #' . $modSettings['cal_bdaycolor'] . ';">' . $txt['calendar3b'] . '</span><br />';
foreach( $birthdays as $member )
echo '
<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', '<br />';
echo '</td></tr>';
}
if(!empty($result['events']))
{
echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Upcoming</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4b'] . '</span><br /> ';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],8).'/'.substr($event['start_date'],5 , 2).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
}
  echo '</td></tr>';

}

echo '</table>';


In checking the logs, tho, seems it's throwing a similar error for any page element/component loaded:

      8: Undefined variable: event
      File: /var/www/html/ecafe/Themes/default/Display.template.php (eval?)
      Line: 29

      8: Undefined variable: event
      File: /var/www/html/ecafe/Themes/default/Calendar.template.php (eval?)
      Line: 29

      8: Undefined variable: event
      File: /var/www/html/ecafe/Themes/default/BoardIndex.template.php (eval?)
      Line: 29

      8: Undefined variable: event
      File: /var/www/html/ecafe/Themes/default/Display.template.php (eval?)
      Line: 29

As well, noticed that if I tried to make a post to one of the threads, it would throw an error to the effect that I had already made the post?


Based on the above, I'm assuming the error is somewhere in the calendar code?  (From the script - this would be line 29:)

$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($event['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');


If I turn off the calendar block, the errors stop.  I'm not proficient in PHP, so any help would be greatly appreciated.

Thanks!
Title: Re: Calendar in a php-block
Post by: feline on April 15, 2006, 08:55:05 PM
If no event available, the array is empthy.

you must check this befor use.
eg. if (isset $event) { your code }

same as $birthdays

Fel
Title: Re: Calendar in a php-block
Post by: dkaye315 on April 15, 2006, 10:31:24 PM
Feline - thank you kindly for your help.  After tinkering around some more, determined there was something in the code conflicting with what must've already been used somewhere else on the boards (??). When I deleted that version, and cut/pasted RoarinRow's code (and added '$sourcedir' preceding the code), it appears to be flawless.  Knock on wood, a log check doesn't indicate any errors.

Thank you again! :)
Title: Re: Calendar in a php-block
Post by: sdl on April 18, 2006, 09:30:08 AM
Great snippets. Thanks to everyone.  My only addition:  All the calendars were left justified in the fixed-width block for me.  This is easily fixed.

In the code, replace

<table>

with

<center><table>

and

</table>

with </table></center>

...regardless of other code, and the table itself will always be centered.
Title: Re: Calendar in a php-block
Post by: dkaye315 on April 18, 2006, 12:44:27 PM
Quote from: sdl on April 18, 2006, 09:30:08 AM
Great snippets. Thanks to everyone.  My only addition:  All the calendars were left justified in the fixed-width block for me.  This is easily fixed.

In the code, replace

<table>

with

<center><table>

and

</table>

with </table></center>

...regardless of other code, and the table itself will always be centered.
For validation, I think you would want to wrap the center tag in the table code:

<table align=center>

</table>
Title: Re: Calendar in a php-block
Post by: Crip on April 18, 2006, 01:17:17 PM
How to put [Sunday] begining on <-- left?
Title: Re: Calendar in a php-block
Post by: sdl on April 18, 2006, 01:40:41 PM
Quote from: crip on April 18, 2006, 01:17:17 PM
How to put [Sunday] begining on <-- left?

Scroll up Crip, bluesteel gave the answer:

Quotelol change $first_day = 1; to = 0 not 1 .. then sunday is the first day of the week (on the left)

Kaye, thanks for that tip about centering the table. Works perfectly. I set up an examples site so that I could experiment without screwing with my other forums - the final result is there.

Click here to see my test forum. (http://smf.examples.com)  There's a random flash clock that I also use (now above the calendar) and a thread there on how to use it, for anyone interested.
Title: Re: Calendar in a php-block
Post by: elpvn on April 18, 2006, 02:34:00 PM
Your knowledge about PHP is very good, Kaye & sdl
Glad to meet you  :)
Title: Re: Calendar in a php-block
Post by: Crip on April 18, 2006, 03:36:07 PM
Thanks sdl, ;D
i downloaded your FlashClocks. ;)
Title: Re: Calendar in a php-block
Post by: dkaye315 on April 18, 2006, 09:18:07 PM
Hey crip ... here's the code I was able to successfully integrate into a php-block (originally posted by Roarin):


global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: elpvn on April 18, 2006, 10:32:39 PM
Really good, I've put it to my TP now  :)
Thanks
Title: Re: Calendar in a php-block
Post by: Crip on April 18, 2006, 10:58:41 PM
Thanks Kaye ;)
Title: Re: Calendar in a php-block
Post by: thoraxe on May 03, 2006, 08:45:13 PM
Kaye,

I've used your code and it's awesome... However I have some comments/questions:

1) I see "Upcoming Events" twice.  Once comes from your code directly:
if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}


But it also appears that the ssi_todaysCalendar(); is generating it as well.  Is there a way to maybe change that?

2) I changed the period that it checks for events to 60 days, and now it's also listing tons of holidays, too.  Is it possible to make it not list holdays?

3) The formatting of the upcoming events is essentially comma delimited... What I'd really like is for the events to be separated by
... that would be aesome!

My site test bed --> http://www.dgtrials.com/tinyportal/forum/index.php
Title: Re: Calendar in a php-block
Post by: thoraxe on May 03, 2006, 09:21:39 PM
Well.. I half answered my own question.  I created this function, because I didn't know what other implications modifying the original in SSI.php would do:

function ssi_todaysCalendar2($output_method = 'echo')
{
global $context, $modSettings, $txt, $scripturl;

if (!smf_loadCalendarInfo())
return array();

if ($output_method != 'echo')
return array(
'birthdays' => $context['calendar_birthdays'],
'holidays' => $context['calendar_holidays'],
'events' => $context['calendar_events']
);

if (!empty($context['calendar_events']))
{
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4b'] . '</span> ';
echo '<br>';
foreach ($context['calendar_events'] as $event)
{
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . (!$event['is_last'] ? '<br> ' : '');
}
}
}


You can view it in action here:
http://www.dgtrials.com/tinyportal/forum/index.php

Please excuse the colors -- I'm in the middle of developing the theme to match the DGTrials homepage.

So now it more or less does what I want it to do...

Is there a way to override the ssi_todaysCalendar only inside our little php block?
Title: Re: Calendar in a php-block
Post by: dkaye315 on May 04, 2006, 12:15:10 AM
Quote from: thoraxe on May 03, 2006, 08:45:13 PM
Kaye,

I've used your code and it's awesome... However I have some comments/questions:

All the credit for this code goes to those that came before me, including Bloc, and Roarin - I just reposted what had previously been created for us, and made a simple modification. ;)
Title: Re: Calendar in a php-block
Post by: myndcraft on May 04, 2006, 03:58:30 PM
I haven't used this yet, but it looks great. Rather then integrating with the forum calendar, is it possible to create a calendar event that links to some other page?

For example on the same site as my forums I run a Raid Scheduler for my world of warcraft guild

http://denovoforums.org/phpRaid/

It would be great to be able to create a raid there and link it to the phpCalendar on the portal (http://denovoforums.org)
Title: Re: Calendar in a php-block
Post by: thoraxe on May 04, 2006, 04:54:46 PM
the way the calendar works right now you would need to create the raids in the calendar and then modify your website to pull the raid forum for the list.

otherwise you'd need to write some kind of hook that would enable your utility to write to the calendar database.

I'm not sure if theres a way to have an event without a thread... it would be like a holiday then.
Title: Re: Calendar in a php-block
Post by: myndcraft on May 04, 2006, 05:29:50 PM
Quote from: thoraxe on May 04, 2006, 04:54:46 PM
the way the calendar works right now you would need to create the raids in the calendar and then modify your website to pull the raid forum for the list.

otherwise you'd need to write some kind of hook that would enable your utility to write to the calendar database.

I'm not sure if theres a way to have an event without a thread... it would be like a holiday then.

And thus I will wait for someone with far greater knowledge then me and the same desire to do it LOL =)
Title: Re: Calendar in a php-block
Post by: thoraxe on May 04, 2006, 05:53:39 PM
I wish it was that easy... I have such an awesome idea for an events module for SOME portal or CMS, but no one seems to be motivated to do it, even though they all have greater knowledge =)  I wish that I had the time to implement it myself.  My PHP skills are OK, but limited, and everything takes me far longer than it would take someone else who knew what they were doing.

Oh well... the curse of open source I suppose.  If only I had money!
Title: Re: Calendar in a php-block
Post by: rbh on May 14, 2006, 06:28:16 AM
i get these 2 different views of the block from ie and firefox. the first picture is the view from ie, and the second is from firefox. the firefox view is fine other then the little square the circles the date runs out of the block on saturdays, but it doesn't even show in ie. the ie view also doesn't size to match my other blocks. any suggestions to get this block to look the same with ie and ff?

Title: Re: Calendar in a php-block
Post by: Blue Steel on May 15, 2006, 01:52:06 AM
always specify all attributes in each tag.. eg:cellpadding,borderwidth,image size, borders, colours.. each browser makes its own assumptions about what the defaults should be.. and of course they are different in some cases..(no i'm not going to say which is right and which isn't ;P )

I believe once you get in a habbit on never assuming anything then your better off in everything..
Title: Re: Calendar in a php-block
Post by: Xarcell on May 15, 2006, 05:14:13 AM
Ok, noob here...

I tried to place that following code into a php file by itself, to show my calendar & events on my blog site via iframe.

I got this error:

Fatal error: Call to undefined function: ssi_todaysbirthdays() in /home/.abigaildryer/xarcell/xarcell-studios.com/TagWorld/frames/calendar/calendar.php on line 68

Any solutions?
Title: Re: Calendar in a php-block
Post by: RoarinRow on May 15, 2006, 06:05:37 AM
Not sure which code you use, but this one works for me.

global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: Xarcell on May 15, 2006, 06:34:21 AM
http://xarcell-studios.com/TagWorld/frames/calendar/calendar.php
Title: Re: Calendar in a php-block
Post by: RoarinRow on May 15, 2006, 08:36:00 PM
Quote from: Xarcell on May 15, 2006, 06:34:21 AM
http://xarcell-studios.com/TagWorld/frames/calendar/calendar.php

Got this when I click on your link:


Fatal error: Call to undefined function: ssi_todaysbirthdays() in /home/.abigaildryer/xarcell/xarcell-studios.com/TagWorld/frames/calendar/calendar.php on line 70
Title: Re: Calendar in a php-block
Post by: jpark on May 18, 2006, 12:40:15 AM
I get birthdays shown twice in both "Birthdays" and "Upcoming Events".. how do I correct this?  Thanks in advance :D
Title: Re: Calendar in a php-block
Post by: bloc on May 18, 2006, 09:20:32 AM
Hm, not sure..but this snippet rely on SSI function, so it must be that one giving this result. What SMF version are you on?
Title: Re: Calendar in a php-block
Post by: jpark on May 18, 2006, 05:48:11 PM
SMF 1.1 RC2.. yes, i believe the ssi function is calling all three (birthdays, holidays, and events)?
Title: Re: Calendar in a php-block
Post by: True Knight on June 08, 2006, 02:39:58 PM
This is a great snippet...I like all the different versions. However, I would like to request one little tweak...and I just don't know how to do it.

In the calendars that list the Birthdays and Events they list as follows (example for July 4th):



-----Birthdays------
Dude12 (40)

------Events-------
Independence Day                   <----Holiday Listed
Upcoming Birthdays:                 <----Birthdays
Dude12 (40)
Upcoming Events:                    <----Events
*Special Day




Is there anyway to make it list as follows?:



-----Today's Birthdays------    <----I know how to edit this!
Dude12 (40)

------Today's Events-------    <----I know how to edit this!
Independence Day                    <----Holiday
Events:*Special Day                   <----I want the Event listed without "Upcoming" listed




I don't want the birthdays listed in the "events" area and I don't want the events to be preceeded with "Upcoming." I only set my calendar to list "1" day of events!


How can I do this??

Thanks!
Title: Re: Calendar in a php-block
Post by: Xarcell on June 10, 2006, 04:48:37 AM
This has been mentioned several times. It's something that has popped up since RC1 I believe
Title: Re: Calendar in a php-block
Post by: True Knight on June 13, 2006, 04:16:29 AM
I finally came up with a solution!  ;D

I finally found out how to divide up the events from birthdays and holidays so that it displays like this...

_______________
Holiday
Independence Day
_______________
Special Events Today
Fireworks Display
_______________
Birthdays Today
JimDawg (19), Terria67 (27), Bubbaduck (62)


Here is my revised code:

global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: blue; font-weight: bold; border: solid 0px black; background-color: #ffffd0; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#C0B188'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysHolidays();
  echo '</td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysEvents();
  echo '</td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: Ray on June 13, 2006, 05:43:59 AM
Thanks I am using it now -
Title: Re: Calendar in a php-block
Post by: iwyen on June 14, 2006, 07:18:07 AM
Thanks True Knight and all. Got it working :)

How do I add a link to allow posting new events for "today"?
Title: Re: Calendar in a php-block
Post by: Xarcell on June 16, 2006, 04:04:12 AM
@ True Knight

Why did you use "' . $modSettings['cal_eventcolor'] . '" for color? I didn't see anywhere in SMF where you can edit that color. It's also not in the style.css.

Also, I hacked it a bit. Made it more flexiable when changing themes and added tablecell high-lighting. It's also identical in FF & IE now. Has proper border around current day. I reduced the letters of the day of week to 2, so that it fits snug into TP default sidebar width(170px).

* If you want to remove tablecell hight-light, just remove red code: onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"

* If you want to change the color of highlight edit red to class in style.css: onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'">

* If you want to add more letters to day of week edit red: $day_name_length = 2;

global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="windowbg3" style="color: black; font-weight: normal; font-size: x-small; border: solid 1px black; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"windowbg\" style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.className='windowbg3'\" onmouseout=\"this.className = 'windowbg'\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: Xarcell on June 16, 2006, 04:10:05 AM
I'll do one that's even prettier later on, but it'll require added some classes to style.css.
Title: Re: Calendar in a php-block
Post by: RoarinRow on June 16, 2006, 04:38:10 AM
Very cool enhancements  :up:
Title: Re: Calendar in a php-block
Post by: True Knight on June 16, 2006, 12:56:46 PM
I did not do all the coding. All I changed was the Events/Birthdays/Holidays section. All the other coding was borrowed from a previous posters code.

BTW, I tried your revised code and I don't care for it as much as the code I posted. The colors are not as nice. On the code I posted the date is highlighted as a box as you mouseover. Your code only highlights the number itself in red. Also your code is much longer from top to bottom of the calendar, and whenever I mouseover on the Todays Birthday section it does a strange thing...compresses and decompresses from top to bottom. I just pasted your code as is.

I'll keep mine as is, unless something better comes along.
Title: Re: Calendar in a php-block
Post by: Xarcell on June 16, 2006, 10:56:18 PM
That doesn't sound like the code I just posted.
Title: Re: Calendar in a php-block
Post by: URPG on June 18, 2006, 10:12:17 PM
Nice Box! (only tried the last one posted)

Removed the mousover Effect, it looked kind of nervous...

How do i change the first day of week to Monday? It is monday in my SMF1.1RC2 calender!
Title: Re: Calendar in a php-block
Post by: tiochus on June 19, 2006, 06:57:23 AM
Quote from: URPG on June 18, 2006, 10:12:17 PM
How do i change the first day of week to Monday? It is monday in my SMF1.1RC2 calender!
You have to search in the 9th line of code this
$first_day = 0;
And you have to change 0 to 1
$first_day = 1;
And you will have Monday as first day of week.
:up:
Title: Re: Calendar in a php-block
Post by: URPG on June 19, 2006, 07:39:29 AM
Working  :up:

Now, all days are a hyperlink, but not the actual "today" inside the box? Is this a firefox issue or am i missing a line of code?
Title: Re: Calendar in a php-block
Post by: Lalato on June 20, 2006, 05:25:39 PM
Maybe I'm not understanding things so far, but do any of the versions noted in this thread allow you to click on a date to see the events that are happening on that date?  if so, which version?  If not, what are the difficulties involved in doing that (I'm a newbie, but I'm willing to give it a crack despite my lack of programming skill).

Thanks,
--sam
Title: Re: Calendar in a php-block
Post by: URPG on June 20, 2006, 05:33:37 PM
The version I installed displays events and allows you to click a date and visit it in SMF calender... With the small bug that you do not have a link on the "today" date.
Title: Re: Calendar in a php-block
Post by: Lalato on June 20, 2006, 06:20:54 PM
I installed one version where the dates (except "today") were clickable, but clicking on the dates resulted in a *new* post/event entry opening... not a listing of events for that day.

--sam
Title: Re: Calendar in a php-block
Post by: URPG on June 20, 2006, 11:46:45 PM
Uh, yes! The second one posted - that was looking nicer - does make you create an even on clicking a day...  :uglystupid2:
Title: Re: Calendar in a php-block
Post by: Lalato on June 22, 2006, 09:06:09 PM
Just realized that that isn't even an option in the SMF Calendar.  Now don't I have egg on my face.  At any rate...  Roarin's last one allows you to click on the current day.  The one by Xarcell doesn't.  I'm not sure why.  I haven't tried True Knight's yet.

Here's a quick list of what I would love to see in this block.  I'm getting a book on PHP today so I'm sure someone else will be able to do this way before me, but if not, I'll give it a go as my first project.

1.  << and >> links that allow browsing through the months.  This would be a very cool addition to this.

2.  There seems to be a problem with the way it handles the time offset.  Not sure why or how this would be fixed.

3.  Put the date of the event next to it so people don't have to click to see it.

Anyway... that's all I have for now.  Thanks to everyone that has worked on this.  Great Work!  :)

--sam
Title: Re: Calendar in a php-block
Post by: URPG on June 22, 2006, 09:43:12 PM
And making the link's open the calender in Main block instead of instantly creating a new Event should be ... more practial oriented, right?
Title: Re: Calendar in a php-block
Post by: Lalato on June 23, 2006, 03:36:02 AM
Quote from: URPG on June 22, 2006, 09:43:12 PM
And making the link's open the calender in Main block instead of instantly creating a new Event should be ... more practial oriented, right?

Well, now that I realize that there isn't a way to see all of the events for a single day without viewing the whole calendar, my original request doesn't really make sense.  That's why I didn't include.  I think that would require a change to the calendar itself... or a mod for SMF.

--sam
Title: Re: Calendar in a php-block
Post by: URPG on June 23, 2006, 09:08:55 AM
But SMF does somehow pick all the events together that happen in one day and displays them inside the day when you are looking at the calender. Can't you just "pirate" this function to display todays events below the calender Block?  :o
Title: Re: Calendar in a php-block
Post by: Lalato on June 23, 2006, 01:00:02 PM
That's probably true, but as stated previously, I'm very new to PHP so someone else may be able to figure it out way before I do.  ;)

--sam
Title: Re: Calendar in a php-block
Post by: Xarcell on June 23, 2006, 02:28:14 PM
Quote from: URPG on June 23, 2006, 09:08:55 AM
But SMF does somehow pick all the events together that happen in one day and displays them inside the day when you are looking at the calender. Can't you just "pirate" this function to display todays events below the calender Block?  :o

I'm not sure what you mean. It does that....

Are you using one of the later script spost here?
Title: Re: Calendar in a php-block
Post by: URPG on June 23, 2006, 03:21:00 PM
I installed the Code from Reply #127 (Xarcell) but removed the MouseOver/MouseOut effects because it looked to nervous to me.

I am missing a link to "today", the day inside the Box is not a working hyperlink (the Month and the other days are) - using Firefox latest.

I'd like it to open SMF Calender instead of directly trying to make me input a new event when i click a day.

It does not display the events... I got a 8 day event "ZeltCon" and the pre-installed "Flag day" and "Summer Solstice" and "Fathers Day" this Month, some upcoming, some past. Non of those is displayed in the block...

Did i damage it be removing the mouseover effects? I only deleted the mouseover and mouseout tags...

EDIT: This is the code i got in a phpblock / left side:

global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="windowbg3" style="color: black; font-weight: normal; font-size: x-small; border: solid 1px black; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"windowbg\" style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.className='windowbg3'\" onmouseout=\"this.className = 'windowbg'\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg"><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg"><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg"><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: Xarcell on June 24, 2006, 10:15:42 PM
I copied teh script from True kinight, who had fixed the double posting of the birthdays. I didn't realize, that the "current day" was linked.

I dunno what you did to make it not show your events, but here's what I have that works without highlighting. I'm pretty good with HTML/CSS, but not php. So I'm not capiable of fixing the current day issue.

global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="windowbg3" style="color: black; font-weight: normal; font-size: x-small; border: solid 1px black; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"windowbg\" style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\" ><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: URPG on June 24, 2006, 10:20:15 PM
I copied your's, it's exactly doing what my version does (no highlights) except that I have to change first day of the week to Monday again, had changed that too.

As you can see, displaying not a single event this month:
Title: Re: Calendar in a php-block
Post by: Xarcell on June 24, 2006, 11:02:49 PM
I dunno then, because it works on mine...

I redid it and tested it before posting.
Title: Re: Calendar in a php-block
Post by: Xarcell on June 24, 2006, 11:03:22 PM
Try the orignal code by true knight, or the latest by roarwn
Title: Re: Calendar in a php-block
Post by: URPG on June 24, 2006, 11:23:26 PM
What Browser do you use to check it?
Title: Re: Calendar in a php-block
Post by: Xarcell on June 25, 2006, 12:12:30 AM
Works in both IE and FF. They look indentical too...
Title: Re: Calendar in a php-block
Post by: URPG on June 25, 2006, 01:01:01 AM
That is realy strange... looks "free of events" with my "no-highlight + Monday" version as well as your last code simply copy + paste... and there are events on the calender, including a birthday...

*me feels himself going insane*  :uglystupid2:

Will try one of the other versions...

It's getting stranger an stranger... I treid True Knights Version from Reply #124 and it does somehow display events, but it does display a july event in june and none of the june events... 1st to 3rd July displayed as an event "today" when it's clearly 25th of June.

Do those blocks display past events of the month? or upcoming events within the next 30 days or...? and even in TK's version, all days got a hyperlink, all but "today"
Title: Re: Calendar in a php-block
Post by: Xarcell on June 25, 2006, 01:19:25 AM
try this one:

http://www.tinyportal.net/smf/index.php?topic=700.msg41785#msg41785
Title: Re: Calendar in a php-block
Post by: URPG on June 25, 2006, 10:56:00 AM
also working, but displays a next month event "today"...

I did create an artifical event on the 25th (today) named "Test A" and it is displayed today, but still the block is displaying an July 1st to July 3rd event as today (on the 25th, was displaying it on the 24th of June too). Is there something wrong with the handling of multple day events?
Title: Re: Calendar in a php-block
Post by: RoarinRow on June 25, 2006, 03:52:58 PM
Quote from: URPG on June 25, 2006, 10:56:00 AM
also working, but displays a next month event "today"...

I did create an artifical event on the 25th (today) named "Test A" and it is displayed today, but still the block is displaying an July 1st to July 3rd event as today (on the 25th, was displaying it on the 24th of June too). Is there something wrong with the handling of multple day events?

In the Admin Center, check the Calendar setting - Max days in advance on board index.  What is yours set at?  Mine is set at 7 so it will always show me activities a week in advance.  Maybe that's why you're seeing July events today if yours is set to a higher number.
Title: Re: Calendar in a php-block
Post by: Lalato on July 17, 2006, 04:06:40 AM
How about a version that just shows upcoming events without the actually calendar...


--sam
Title: Re: Calendar in a php-block
Post by: Assistance on August 07, 2006, 05:39:07 AM
Quote from: True Knight on June 13, 2006, 04:16:29 AM
I finally came up with a solution!  ;D


I use this one
but i changed $day_name_length = 3;
to 1 :up:
its shweet
Title: Re: Calendar in a php-block
Post by: londonhogfan on August 07, 2006, 04:40:26 PM
If you go into the code and make the <table width="100%"

it will go all the way from side to side.  One of the SSI codes eventsToday isnt usually long enough to make it go 100%.  I think thats what  is causing all the problems.

I combined a couple and and removed the "post" part of the links from the calendar dates so it wouldnt take everyone to a login screen (because I don't allow most people to post calendar events).  I like the results.  Here is what I'm using.


global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}
echo '</table>';
Title: Re: Calendar in a php-block
Post by: RoarinRow on August 07, 2006, 06:12:19 PM
Very cool londonhogfan  :up:
Title: Re: Calendar in a php-block
Post by: Jump1979man on August 07, 2006, 09:30:51 PM
Looks good but everything says "Birthdays today" or "Events Today" etc....even when they are NOT today but just in the future....


Wondering if it could actually highlight the days for these events and birthdays etc...for those dates?
Title: Re: Calendar in a php-block
Post by: londonhogfan on August 07, 2006, 09:42:51 PM
go into admin
Under the FORUM category select Calendar

3rd section down change
"Max days in advance on board index:" to 0
Title: Re: Calendar in a php-block
Post by: Jump1979man on August 07, 2006, 09:46:10 PM
Quote from: londonhogfan on August 07, 2006, 09:42:51 PM
go into admin
Under the FORUM category select Calendar

3rd section down change
"Max days in advance on board index:" to 0
that will only show what is actually today then right?

Is there a way to make it show upcoming things as well?  and highlight these days?
Title: Re: Calendar in a php-block
Post by: EG on August 10, 2006, 07:20:23 PM
excellent code londonhogfan!!  love it!

oooh! I love TP!!! its so good!
Title: Re: Calendar in a php-block
Post by: itsacoaster on August 16, 2006, 02:39:23 AM
Is there a way to include the date of the event below the "upcoming event" as well?

For example, check out the calendar in the lower right (http://lucydotd.com), would it be possible to add "21 August 2006" below it or something?

Or, is this an SMF thing that can't be changed?
Title: Re: Calendar in a php-block
Post by: jpark on August 20, 2006, 06:56:46 PM
A few questions, I hope someone can help me.  How can I set the birthdays so it shows only Today's Birthdays but have the events set so it shows Upcoming Events (for next 2 weeks or so)?  Right now I have it so everything is basically upcoming but for birthdays I would love to be able to have just today's.  If this is not possible, how can I get rid of the age of the person in parenthesis that shows up next to their name?  I am getting some complaints about having their age revealed... :O  I'd appreciate any and all help!
Title: Re: Calendar in a php-block
Post by: G6Cad on August 20, 2006, 07:08:56 PM
I think you have the answer in this very thread if you read through it.
I think i remember this being discussed in here :)
Title: Re: Calendar in a php-block
Post by: JPDeni on August 20, 2006, 07:13:21 PM
One thing that the users can do themselves if they don't want their ages revealed is to remove their year of birth from their profile. It's "legal" to enter 0000 in the year field.
Title: Re: Calendar in a php-block
Post by: jpark on August 20, 2006, 09:25:59 PM
Quote from: Mrs G6 on August 20, 2006, 07:08:56 PM
I think you have the answer in this very thread if you read through it.
I think i remember this being discussed in here :)

Thanks for your reply~  Just finished reading through all the posts.. i did not find the answer to my first question..  I know about setting the "Max days in advance on board index" in Admin which i have set to 30 because I would like upcoming events for a month in advance.  BUT is there a way to keep this and only have TODAY's birthdays show up?  For this, I guess i'm asking if you can have two different "Max days in advance on board index" values.  Or do it some other way through the calendar code.  If someone knows how to do this, I would be so grateful! 

Quote from: itsacoaster on August 16, 2006, 02:39:23 AM
Is there a way to include the date of the event below the "upcoming event" as well?

For example, check out the calendar in the lower right (http://lucydotd.com), would it be possible to add "21 August 2006" below it or something?

Or, is this an SMF thing that can't be changed?
kail's code (http://www.tinyportal.net/smf/index.php?topic=700.msg30584#msg30584) has dates for events show up.  I loved this feature but liked the updates made in recent codes so I am using a different code.  For example, this has "Upcoming Birthdays" twice and holidays are not listed.  If there was a way to combine this code with newer ones, that would be terrific.  I was unsuccessful at my attempts to combine the codes and make them work.  Has anyone tried this?

And the age solution seems like a temporary solution.. there's no way to completely remove the age for everyone?

Thank you all~!
Title: Re: Calendar in a php-block
Post by: jpark on August 20, 2006, 09:34:01 PM
oops, what am i talking about?Ã,  i think the version i'm using now does in fact show the date.Ã,  Try this: global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: blue; font-weight: bold; border: solid 0px black; background-color: #ffffff; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 style=\"padding-right: 4px; font-size: x-small; font-family: trebuchet ms, verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#D0E4FF'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><u><b>BIRTHDAYS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><u><b>SPECIAL DAYS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysHolidays();
  echo '</td></tr>';
}

if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><u><b>EVENTS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
                   }
  echo '</td></tr>';
}

echo '</table>';


I think either i found it or was able to combine codes... either way, see if it works for you~!
Title: Re: Calendar in a php-block
Post by: Gargoyle on August 20, 2006, 09:38:32 PM
Quote from: londonhogfan on August 07, 2006, 04:40:26 PM
If you go into the code and make the <table width="100%"

it will go all the way from side to side.  One of the SSI codes eventsToday isnt usually long enough to make it go 100%.  I think thats what  is causing all the problems.

I combined a couple and and removed the "post" part of the links from the calendar dates so it wouldnt take everyone to a login screen (because I don't allow most people to post calendar events).  I like the results.  Here is what I'm using.


global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #000000;"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}
echo '</table>';


Great code but the events thing was getting me so I removed the  "today" text and I removed the "style color" command... Works awesome now!! Very good work and thanks to all that contributed to this code! I'll paste what I am using below.

global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Holidays</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Special Events</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Birthdays</b></td><td><hr></td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}
echo '</table>';
Title: Re: Calendar in a php-block
Post by: itsacoaster on August 22, 2006, 06:13:00 AM
Quote from: jpark on August 20, 2006, 09:34:01 PM
oops, what am i talking about?  i think the version i'm using now does in fact show the date.  Try this: global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: blue; font-weight: bold; border: solid 0px black; background-color: #ffffff; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 style=\"padding-right: 4px; font-size: x-small; font-family: trebuchet ms, verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#D0E4FF'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><u><b>BIRTHDAYS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><u><b>SPECIAL DAYS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysHolidays();
  echo '</td></tr>';
}

if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><u><b>EVENTS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
                   }
  echo '</td></tr>';
}

echo '</table>';


I think either i found it or was able to combine codes... either way, see if it works for you~!
Umm... wow, that is fantastic!  Thank you so much!
Title: Re: Calendar in a php-block
Post by: rafynet on September 01, 2006, 05:47:01 AM
I've been playing around with the existing code for the calendar block and here are my results so far.
:D

Comments are welcome please.
Title: Re: Calendar in a php-block
Post by: akulion on September 01, 2006, 05:50:29 AM
excellent :D now how about sharin n a live preview
Title: Re: Calendar in a php-block
Post by: RoarinRow on September 01, 2006, 05:56:35 AM
Quote from: akulion on September 01, 2006, 05:50:29 AM
excellent :D now how about sharin n a live preview

and the code would be helpful too   :up:
Title: Re: Calendar in a php-block
Post by: G6Cad on September 01, 2006, 07:17:28 AM
Yes, the code for that would be nice to have to ;)
Title: Re: Calendar in a php-block
Post by: grabman on September 01, 2006, 09:39:43 AM
yeah, very cool!~!  is there live preview anywhere?  or code maybe??
Title: Re: Calendar in a php-block
Post by: akulion on September 01, 2006, 02:32:43 PM
his website is a private special members only site thats why no prview

but it would be really cool if you could share the code with us :)
Title: Re: Calendar in a php-block
Post by: rafynet on September 01, 2006, 03:41:50 PM
ya .. sorry .. my site is private ..
you can look at the block in action now though .. as i made it available to guests ...
you will not see any events as you don't have the access to see them but this preview seems to be working ok .... it's just using current date to count down to ...

(https://www.tinyportal.net/smf/index.php?action=dlattach;topic=700.0;attach=5508;image)

http://www.rafy.net

Instructions to install:
1. unzip attached rcount.zip to /somewhere/on/yoursite/rcount.swf.
2. paste this code to a PHP block.
3. where it says /<change.this>/rcount.swf in 2 places in this code ... put /somewhere/on/yoursite/rcount.swf where you saved rcount.swf
4.  ;) good luck.



global $user_settings;

if($user_settings['birthdate'] == '0001-01-01')
{
?><div align="center" style="color:red; font-size:medium;">YouR birTHDate is <strong>NOT SET</strong> !!! set YOUr biRThdate <a href="http://www.rafy.net/index.php?action=profile;sa=forumProfile"> HERE </a> to C Da CounTDown !</div><?
return;
}

$birthdate = strtotime($user_settings['birthdate']);
$nextbirthdate = date("U",strtotime(date("Y") .'-'. date("m", $birthdate) .'-'. date("d", $birthdate)));
$today = time();

if($nextbirthdate < $today){
$nextbirthdate = date("U",strtotime(date("Y")+1 .'-'. date("m", $birthdate) .'-'. date("d", $birthdate)));
}

//echo date("Y-m-d", $today) . '<br>';
//echo date("Y-m-d", $nextbirthdate) . '<br>';

?>
<div align="center" style="color:#7C5401"><strong>tiME lEFt 2 Ur BirThDay</strong></div>
<div align="center" style="font-size:large;"><? echo date("F jS", $nextbirthdate)?></div>
<div align="center">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="165" height="30" id="rcount" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/<change.this>/rcount.swf?r_year=<? echo date("Y",$nextbirthdate);?>&r_month=<? echo date("m",$nextbirthdate);?>&r_day=<? echo date("d",$nextbirthdate);?>&r_hour=00&r_minute=00" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#f6cf59" /><embed src="/<change.this>/rcount.swf?r_year=<? echo date("Y",$nextbirthdate);?>&r_month=<? echo date("m",$nextbirthdate);?>&r_day=<? echo date("d",$nextbirthdate);?>&r_hour=00&r_minute=00" quality="high" wmode="transparent" bgcolor="#f6cf59" width="165" height="30" name="rcount" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</div>

<hr style="border: 1px solid #7C5401" />

<?php 

global $scripturl$modSettings$sdays;

$now mktime() + $modSettings['time_offset'] * 3600;
$today date('j',$now);
$year date("Y",$now);
if (isset(
$_REQUEST['month'])) {
$month $_REQUEST['month'];
} else {
$month date("n",$now);
}

#create notice for Holidays, Events & Birthdays.

if (ssi_rafy_todaysBirthdays('')) {
echo '<div align="center" class="smalltext" style="font-weight: bold; color: #' $modSettings['cal_bdaycolor'] . ';">Birthdayz</div>';
echo '<span class="smalltext">';
$birthdays split(','ssi_rafy_todaysBirthdays('echo'$month));
echo '</span>';

echo '<hr style="border: 1px solid #7C5401" />';
}

if (
ssi_rafy_todaysEvents('')) {
echo '<div align="center" class="smalltext" style="font-weight: bold; color: #' $modSettings['cal_eventcolor'] . ';">Special Eventz</div>';
echo '<span class="smalltext">';
$events split(','ssi_rafy_todaysEvents('echo'$month));
echo '</span>';

echo '<hr style="border: 1px solid #7C5401" />';
}

if (
ssi_rafy_todaysHolidays('')) {
echo '<div align="center" class="smalltext" style="font-weight: bold; color: #' $modSettings['cal_holidaycolor'] . ';">Holidayz</div>';
echo '<span class="smalltext">';
$holidays split(','ssi_rafy_todaysHolidays('echo'$month));
echo '</span>';

echo '<hr style="border: 1px solid #7C5401" />';
}


//list($eventday, $eventlink) = each($events);
//echo '<hr>';
//foreach($holidays as $ed){
// $event = split('=>', $ed);
// echo $event[0].$event[1];
//}
//echo '<hr>';

$days = array($today=>array(''.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'',NULL,'<span style="font-weight: bold; border: solid 1px white; padding: 0px 0px 0px 0px;">'.$today.'</span>'));

$day_name_length 3;
$month_href $scripturl '?action=calendar&month=' $month;
$first_day 0;
$pn = array('ÂÃ,«Ã‚Ã,«Ã‚Ã,«'=>$scripturl.'?month='.($month-1), 'ÂÃ,»Ã‚Ã,»Ã‚Ã,»'=>$scripturl.'?month='.($month+'1'));

$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_month));
$weekday = ($weekday $first_day) % 7#adjust for $first_day
$title   htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' $p).'</span>   ';
if($n$n '   <span class="smalltext">'.($nl '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' $n).'</span>';

$calendar '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length substr($d,0,$day_name_length) : $d).'</th>';
            
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday 0$calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'#initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month$day++,$weekday++){
$sp1 '';
$sp2 '';
foreach($holidays as $sd) {
$event split('=>'$sd);
if($day == intval($event[0]))
{
$sp1 '<span align="right" style="color: #FFFFFF; background-color: #' $modSettings['cal_holidaycolor'] . '; padding: 0px 0px 0px 0px;" title="'.htmlspecialchars($event[1]).'">';
$sp2 '</span>';
}
}
foreach($events as $sd) {
$event split('=>'$sd);
if($day == intval($event[0]))
{
$sp1 '<span align="right" style="color: #FFFFFF; background-color: #' $modSettings['cal_eventcolor'] . '; padding: 0px 0px 0px 0px;" title="'.htmlspecialchars($event[1]).'">';
$sp2 '</span>';
}
}
foreach($birthdays as $sd) {
$event split('=>'$sd);
if($day == intval($sd))
{
$sp1 '<span align="right" style="color: #FFFFFF; background-color: #' $modSettings['cal_bdaycolor'] . '; padding: 0px 0px 0px 0px;" title="'.htmlspecialchars($event[1]).'">';
$sp2 '</span>';
}
}
if($weekday == 7){
$weekday   0#start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
if(isset($days[$day]) and is_array($days[$day]) and ($month == date("n",$now))){
@list($link$classes$content) = $days[$day];
if(is_null($content))  $content  $day;
$calendar .= '<td'.($classes ' class="'.htmlspecialchars($classes).'">' '>');
$calendar .= ($link '<a href="'.htmlspecialchars($link).'">'.$sp1.$content.$sp2.'</a>' $sp1.$content.$sp2).'</td>';
}
else 
{
$calendar .= "<td style=\"padding-right: 0px; font-size: xx-small; font-family: verdana, sans-serif;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$sp1$day$sp2</a></td>";
}
}
if(
$weekday != 7$calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'#remaining "empty" days
echo $calendar.'</tr>';
echo 
'</table>';

// Show today's birthdays.
function ssi_rafy_todaysBirthdays($output_method 'echo'$month)
{
global $context$scripturl$db_prefix;

if (!smf_loadCalendarInfo() || empty($context['calendar_birthdays']))
return array();

if ($output_method != 'echo')
return $context['calendar_birthdays'];

foreach ($context['calendar_birthdays'] as $member)
{
$query db_query(
"SELECT birthdate
FROM 
{$db_prefix}members 
WHERE ID_MEMBER='"
.$member['id']."'"__FILE____LINE__);

$row mysql_fetch_assoc($query);
$birthdate strtotime($row['birthdate']); 

echo '<div align="center">';
echo '<a href="'$scripturl'?action=calendar;year=' date("Y") . ';month=' date("n",$birthdate) . '"><strong>' date("F jS",$birthdate) . '</strong></a>';
echo '<br />';
echo '<img src="/Themes/rOrb/images/icons/birthday_small.gif" width="13" height="17" align="absmiddle" hspace="5">';
echo '<a href="'$scripturl'?action=profile;u='$member['id'], '">';
echo $member['name'] . (isset($member['age']) ? ' (' $member['age'] . ')' '');
echo '</a>';
// echo (!$member['is_last'] ? '<br>' : '');

echo '</div>';

if(date("n",$birthdate) == $month)
{
$sdays .= date("j",$birthdate).'=>'.$member['name'].'ÂÃ,´s bDay'.',';
}
}
return $sdays;
}

// Show today's events.
function ssi_rafy_todaysEvents($output_method 'echo'$month)
{
global $context$db_prefix;

if (!smf_loadCalendarInfo() || empty($context['calendar_events']))
return array();

if ($output_method != 'echo')
return $context['calendar_events'];

foreach ($context['calendar_events'] as $event)
{
$query db_query(
"SELECT startDate
FROM 
{$db_prefix}calendar 
WHERE ID_EVENT='"
.$event['id']."'"__FILE____LINE__);

$row mysql_fetch_assoc($query);
$startDate strtotime($row['startDate']); 

echo '<div align="center">';
echo '<a href="'$scripturl'?action=calendar;year=' date("Y") . ';month=' date("n",$startDate) . '"><strong>' date("F jS Y",$startDate) . '</strong></a>';
echo '<br />';

if ($event['can_edit'])
echo '<a href="' $event['modify_href'] . '" style="color: #FF0000;">[e]</a> ';
echo $event['link'] ;
// echo (!$event['is_last'] ? '<br>' : '');
echo '</div>';

if(date("n",$startDate) == $month)
{
$sdays .= date("j",$startDate).'=>'.str_replace("'","ÂÃ,´",$event['link']).',';
}
}
return $sdays;
}

// Show today's holidays.
function ssi_rafy_todaysHolidays($output_method 'echo'$month)
{
global $context;

if (!smf_loadCalendarInfo() || empty($context['calendar_holidays']))
return array();

if ($output_method != 'echo')
return $context['calendar_holidays'];


foreach($context['calendar_holidays'] as $holiday) {
$query db_query(
"SELECT eventDate
FROM 
{$db_prefix}smf_calendar_holidays 
WHERE title='"
.str_replace("'","''",$holiday)."' 
AND (eventDate LIKE '"
.date("Y")."%' OR eventDate LIKE '0004%')"__FILE____LINE__);

$row mysql_fetch_assoc($query);
$eventDate strtotime($row['eventDate']); 

echo '<div align="center">';
echo '<a href="'$scripturl'?action=calendar;year=' date("Y") . ';month=' date("n",$eventDate) . '"><strong>' date("F jS",$eventDate) . '</strong></a>';
echo '<br />';
echo $holiday;
echo '</div>';

if(date("n",$eventDate) == $month)
{
$sdays .= date("j",$eventDate).'=>'.str_replace("'","ÂÃ,´",$holiday).',';
}
}
return $sdays;
}

Title: Re: Calendar in a php-block
Post by: Svaha on September 01, 2006, 05:03:58 PM
I like this calendar, at the moment I'm testing a conversion from my xoops 2.2.4 / cbb 3.04 forum and just waiting for the new release of tp.
I wonder if someone could ad a random display of pictures in the head of the calendar like this you can see on my site (on the left)
http://www.alohaspirit.nl/modules/myhome/index.php
Title: Re: Calendar in a php-block
Post by: daftdate on September 01, 2006, 07:06:34 PM
woops for some reason its bringing my birthday up as december the 31st when its actually september 6th is there something im not setting???  :) also how could i get rid of the milliseconds as its driving me crazy.  :o
Title: Re: Calendar in a php-block
Post by: rafynet on September 01, 2006, 09:29:16 PM
hmmm ... the script is getting the birthday from profile setting in tp ... so i'm not sure why this is happening ...
i'll have to look at this later.
as for the miliseconds ... that's the main reason i used the flash movie for the countdown ... I love the milliseconds and you can't turn them off however .. there are other countdown (javascripts) that can be used instead.

Quote from: daftdate on September 01, 2006, 07:06:34 PM
woops for some reason its bringing my birthday up as december the 31st when its actually september 6th is there something im not setting???  :) also how could i get rid of the milliseconds as its driving me crazy.  :o
Title: Re: Calendar in a php-block
Post by: daftdate on September 01, 2006, 10:44:05 PM
yep am looking for a more sedate countdown as the milliseconds makes me dizzy.  :uglystupid2:
Title: Re: Calendar in a php-block
Post by: jpark on September 02, 2006, 04:26:37 PM
Thanks! this is great~!  I just have a few questions:

When i have multiple events/birthdays/holidays on one day, only one of those show up on the calendar mouseover.  How can I get it to list everything going on on that day?

And the next and previous calendar views don't show the events/birthdays/holidays right?  I don't see any days highlighted.  It would be awesome if it showed all of this.. Thanks!
Title: Re: Calendar in a php-block
Post by: Svaha on September 03, 2006, 11:15:13 PM
I took the code from rafynet and put after the global declaration this :

$random_d = rand(1,10);
echo '<img src="http://www.mysiteurl/myimagesdir/'.$random_d.'.JPG" width="85" align="absmiddle">';


You can see the result on my 'practical joke' site : http://www.badmuts.nu

A random image is displayed from the range 1.JPG to 10.JPG, this is taken from myimagesdir

I don't get it to display in the middle, any help?
Thank you.
Title: Re: Calendar in a php-block
Post by: joelgomez on September 06, 2006, 12:22:02 AM
Quote from: Gargoyle on August 20, 2006, 09:38:32 PM
Great code but the events thing was getting me so I removed the  "today" text and I removed the "style color" command... Works awesome now!! Very good work and thanks to all that contributed to this code! I'll paste what I am using below.

Gargoyle, I'm using your version of the Calendar Code, but "today" number appears very simple, just a little bit bigger than the other days. How can I put a color-border (even with different background) around the "todays number"? I've already tried changing the following lines and nothing happened:

         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));
Title: Re: Calendar in a php-block
Post by: Svaha on September 06, 2006, 10:28:12 AM
Quote from: Svaha on September 03, 2006, 11:15:13 PM
I took the code from rafynet and put after the global declaration this :

$random_d = rand(1,10);
echo '<img src="http://www.mysiteurl/myimagesdir/'.$random_d.'.JPG" width="85" align="absmiddle">';


You can see the result on my 'practical joke' site : http://www.badmuts.nu

A random image is displayed from the range 1.JPG to 10.JPG, this is taken from myimagesdir

I don't get it to display in the middle, any help?
Thank you.

Ok, got it : :)

echo '<div align="center"><br>';
$random_d = rand(1,10);
echo '<img src="http://www.alohaspirit-nl.nl02.members.pcextreme.nl/badmuts/calimages/'.$random_d.'.JPG"width="120">';
echo '</div><br>';
Title: Re: Calendar in a php-block
Post by: LeeD on September 06, 2006, 09:17:33 PM
tryed all these came up with differnt things per browser

im using Gargoyles right now posted about 3 pages back

but again in ie doesnt highlites day but in firefox works fine

was there one specific code that ...

1 will do same in both browsers
2 will fit into a 170 tp block
3 will not bring a member to post by clicking on day but to just view full calender
   like this 1

seems always these php blocks never do same thing in different broswers  :uglystupid2:


ty ahead of time  ;)


code in use on boards
Quoteglobal $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td>
</td><td colspan="5" class="smalltext" align="center">Holidays</td><td>
</td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td>
</td><td colspan="5" class="smalltext" align="center">Special Events</td><td>
</td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td>
</td><td colspan="5" class="smalltext" align="center">Birthdays</td><td>
</td></tr><td colspan="7" class="windowbg" ><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}
echo '</table>';
Title: Re: Calendar in a php-block
Post by: jacortina on September 07, 2006, 12:14:40 AM
This one correctly highlights today's date in both browsers (code given above is flawed; result of mixing single quotes and double quotes). It also lists the Birthday/Event/Holiday dates next to them and includes the member group colors for members having birthdays:


global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2; // Change for more letters

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

/////////////////////////////////////////////////////////////////
//   CALENDAR SECTION
//
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $birthdate = strtotime($row['birthdate']);

        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: whoesa on September 07, 2006, 12:35:58 AM
Quote from: jacortina on September 07, 2006, 12:14:40 AM
This one correctly highlights today's date in both browsers (code given above is flawed; result of mixing single quotes and double quotes). It also lists the Birthday/Event/Holiday dates next to them and includes the member group colors for members having birthdays:


global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2; // Change for more letters

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

/////////////////////////////////////////////////////////////////
//   CALENDAR SECTION
//
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $birthdate = strtotime($row['birthdate']);

        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


I tested it and if someone's birthday is for example on 10 september, it shows 31 dec on the calendar ???
Other than that, it looks very good.
Title: Re: Calendar in a php-block
Post by: jacortina on September 07, 2006, 12:39:31 AM
Odd. I have a 30 day period on showing events and it shows Sep 24, Sep 26 and Oct 2 birthdays just fine on mine.

Is the year properly given in their profile?
Title: Re: Calendar in a php-block
Post by: whoesa on September 07, 2006, 12:52:23 AM
Yes, it is set on 10/09/1966.

Check my site to see if you want.
Title: Re: Calendar in a php-block
Post by: jacortina on September 07, 2006, 12:53:09 AM
Oh. Could be running into this on your configuration:

Quote
Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.

So, all birth dates before Jan 1 1970 will end up being Dec 31 when converted to timestamps.
Title: Re: Calendar in a php-block
Post by: whoesa on September 07, 2006, 12:59:51 AM
Oh i see, so nothing i can do about it lol  :)

Well thx anyway for the code.
Title: Re: Calendar in a php-block
Post by: jacortina on September 07, 2006, 01:01:23 AM
Hold on for a few and I'll fix it (but it DOES highlight current date in IE, right?)
Title: Re: Calendar in a php-block
Post by: whoesa on September 07, 2006, 01:06:00 AM
QuoteHold on for a few and I'll fix it
You can? Cool thx  :)

Quote(but it DOES highlight current date in IE, right?)
Yes, it looks good for me. Mostly using FF though. 
Title: Re: Calendar in a php-block
Post by: jacortina on September 07, 2006, 01:24:23 AM
Try this. Simple change after all. One line out and two lines in. But it's easier to post (and replace when modifying a block) the full code:


global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: whoesa on September 07, 2006, 01:32:09 AM
Yup that did it. :up: Much appriciated, thx!  ;)
Title: Re: Calendar in a php-block
Post by: daftdate on September 07, 2006, 01:56:12 AM
I bet a pound to a pinch thats why rafynets calendar was bringing up my birthday date as decemeber 31 because my birth year is 1965 ok showing my age here.   So would the same fix you use for this calendar work for rafynets calendar? and what lines would i need to change??
Title: Re: Calendar in a php-block
Post by: jacortina on September 07, 2006, 02:06:05 AM
In his ssi_rafy_todaysBirthdays function,

Find:
$birthdate = strtotime($row['birthdate']);


Replace with:
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));


Separates the stored date and rebuilds/gets timestamp using current year for the purpose of getting the month name and day of month text.
Title: Re: Calendar in a php-block
Post by: daftdate on September 07, 2006, 02:10:03 AM
wonderful thank you i have a members birthday coming up next week with an old date so i will let you know how it goes as my birthday was yesterday so cant test it with that one.  :)
Title: Re: Calendar in a php-block
Post by: jacortina on September 07, 2006, 02:11:38 AM
Well, you can always nudge yours up a couple of days, just to see it displayed. ;)
Title: Re: Calendar in a php-block
Post by: daftdate on September 07, 2006, 02:14:16 AM
Yep I just did that as i thought it was soft waiting around and it works like a dream thanx a lot.  ;D
Title: Re: Calendar in a php-block
Post by: JCphotog on September 13, 2006, 06:16:10 PM
This is absolutely wonderful work guys!  It's so attractive! 

I'm curious, is there anyway to set things up so that instead of sending a user to post an event when clicking on a date, that they would be linked directly to the forum calendar so they could see what's happening in the days around that date?

Edit: or even so that only when guests click on a date, they are sent to the calendar, since they can't post events?
Title: Re: Calendar in a php-block
Post by: rebelrose on September 14, 2006, 02:49:14 AM
Could you add a white background to this?
Title: Re: Calendar in a php-block
Post by: jacortina on September 14, 2006, 03:03:47 AM
Quote from: JCphotog on September 13, 2006, 06:16:10 PM
This is absolutely wonderful work guys!  It's so attractive! 

I'm curious, is there anyway to set things up so that instead of sending a user to post an event when clicking on a date, that they would be linked directly to the forum calendar so they could see what's happening in the days around that date?

Edit: or even so that only when guests click on a date, they are sent to the calendar, since they can't post events?

Well, the month name at the top takes you to the full month's calendar.


Quote from: RebelRose on September 14, 2006, 02:49:14 AM
Could you add a white background to this?

It uses the standard background for TP blocks (style comes from it).

But you can get it 'mostly' white by changing:
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

To:
$calendar = '<table style="background:white;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';
Title: Re: Calendar in a php-block
Post by: jpark on September 14, 2006, 03:06:24 AM
jacortina, could you tell me the specific code to just have the membergroup color show up?  i'm using a mix of codes and i'm not sure what to change.  thank you for this feature, it's great!
Title: Re: Calendar in a php-block
Post by: rebelrose on September 14, 2006, 03:17:04 AM
Thank you jacortina you have helped me twice tonight, thanks alot.
Title: Re: Calendar in a php-block
Post by: jacortina on September 14, 2006, 03:19:57 AM
Quote from: jpark on September 14, 2006, 03:06:24 AM
jacortina, could you tell me the specific code to just have the membergroup color show up?  i'm using a mix of codes and i'm not sure what to change.  thank you for this feature, it's great!

Well, not as compact/efficient as it could/should be (loadMemberData takes an array as it's argument), but:


/////////////// holds the user info including color
        global $user_profile;

/////////////// Calls the sub which loads the info
        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

/////////////// Outputs a colored name and age in parentheses as link to profile
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';


Note that this depends on loading the $member array via:
    foreach ($context['calendar_birthdays'] as $member)
Title: Re: Calendar in a php-block
Post by: jpark on September 14, 2006, 03:35:52 AM
ooh, okay... i will try this.  Thanks so much for the quick reply!
Title: Re: Calendar in a php-block
Post by: daftdate on September 17, 2006, 01:05:28 PM
I was just wondering and it may just be me being over enthusiastic here but could we have a similar countdown to the birthday countdown but to an event such as Halloween or Bonfire Night for us in England or maybe the big C word (Christmas) in the same block as the calendar so you would have the countdown for birthday then countdown to specific event then the rest of the calendar?? if I am being over enthusiastic then excuse me as the doctor keeps advising me to take the pills but I don’t always do it.  ;)
Title: Re: Calendar in a php-block
Post by: jpark on September 17, 2006, 10:37:44 PM
any way to get the birthday section viewable only to members?  probably putting an "if member" tag somewhere?  this would be awesome, i appreciate your help~
Title: Re: Calendar in a php-block
Post by: jacortina on September 17, 2006, 10:44:32 PM
Quote from: jpark on September 17, 2006, 10:37:44 PM
any way to get the birthday section viewable only to members?  probably putting an "if member" tag somewhere?  this would be awesome, i appreciate your help~

Basically the check would be:

global $user_info;

if (!$user_info['is_guest']) {
...
...member-only stuff...
...
}
Title: Re: Calendar in a php-block
Post by: Paulie on September 22, 2006, 08:22:02 AM
Anyone know where i can change the colour of the --------Holidays-------- (just under the calendar section) from blue to another colour please? Im using the last code that jacortina put up.
Title: Re: Calendar in a php-block
Post by: jpark on September 22, 2006, 02:38:59 PM
Thanks jacortina fot the above help!
Paulie, you would go to Admin -> Calendar -> then change where it says Holiday Color to the color you want (you can look on this color chart if you need it http://www.immigration-usa.com/html_colors.html)
Title: Re: Calendar in a php-block
Post by: Paulie on September 22, 2006, 02:45:52 PM
Great, thanks for that :)
Title: Re: Calendar in a php-block
Post by: jacortina on September 22, 2006, 02:48:17 PM
Quote from: jpark on September 22, 2006, 02:38:59 PM
Thanks jacortina fot the above help!
Paulie, you would go to Admin -> Calendar -> then change where it says Holiday Color to the color you want (you can look on this color chart if you need it http://www.immigration-usa.com/html_colors.html)

You're welcome.

Note that the above will indeed change the color, but it will also
change the color for Holidays on the Calendar page itself.

If you ONLY want to change the color of the label in the Calendar
block, find in the code given, the line:


echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';


Change
#' . $modSettings['cal_holidaycolor'] . '

To the color you want using hex code or named color
#FF0000
red

(replace the whole substring with either of the above for a red label).
Title: Re: Calendar in a php-block
Post by: Paulie on September 22, 2006, 06:13:35 PM
Looking at the code and assuming that it (the calendar) should be centered in the block. Can you think of any reason why mine isn`t?
Title: Re: Calendar in a php-block
Post by: jacortina on September 22, 2006, 06:41:08 PM
You know, I don' think there's anything actually in the code to tell it to center.

Nor is there anything which EXPLICITLY tells it to use the full width (which would have the effect of centering it, too).

You could try this and see if it helps -

Find:

$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';


Replace with:

$calendar = '<table style="width:100%;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';


See if explicitly making the width of the containing table 100% of its container (the block), works for you. It might end up spreading it out a bit more (assuming the reason it doesn't center is that you have more width than the table 'needs').
Title: Re: Calendar in a php-block
Post by: Paulie on September 22, 2006, 06:49:35 PM
Perfect. That worked a treat, thank you :)
Title: Re: Calendar in a php-block
Post by: truelight5 on October 04, 2006, 07:38:27 PM
I love this mod, and it is installed perfectly on my site, however, I am having something strange happen that was mentioned earlier in this thread but I never saw an answer for this issue.

When the calendar block is on I have a box above every single post that says "Linked Events" and has the "event link" there...but the events are not obviously linked to EVERY post on the forum...lol so there has to be an issue I am missing.

In the Calendar options (for the SMF part) I have the following UNchecked:
Show linked events in topic display:

The software I am running is:

SMF 1.1 RC3 TinyPortal v0.9.5

I would be so thankful for any help you could provide! 

Blessings!
Susie 
Title: Re: Calendar in a php-block
Post by: jacortina on October 04, 2006, 07:54:57 PM
There's 22 pages in this thread and a number of different calendar block versions.

Which one are you using?
Title: Re: Calendar in a php-block
Post by: truelight5 on October 04, 2006, 08:08:26 PM
I am so sorry about that, duh... :idiot2:

This is the code I am currently using:

global $scripturl, $modSettings, $sdays;

$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$year = date("Y",$now);
if (isset($_REQUEST['month'])) {
$month = $_REQUEST['month'];
} else {
$month = date("n",$now);
}

#create notice for Holidays, Events & Birthdays.

if (ssi_rafy_todaysBirthdays('')) {
echo '<div align="center" class="smalltext" style="font-weight: bold;" color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</div>';
echo '<span class="smalltext">';
$birthdays = split(',', ssi_rafy_todaysBirthdays('echo', $month));
echo '</span>';

echo '<hr style="border: 1px solid #7C5401" />';
}

if (ssi_rafy_todaysEvents('')) {
echo '<div align="center" class="smalltext" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Upcoming Events</div>';
echo '<span class="smalltext">';
$events = split(',', ssi_rafy_todaysEvents('echo', $month));
echo '</span>';

echo '<hr style="border: 1px solid #7C5401" />';
}

if (ssi_rafy_todaysHolidays('')) {
echo '<div align="center" class="smalltext" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</div>';
echo '<span class="smalltext">';
$holidays = split(',', ssi_rafy_todaysHolidays('echo', $month));
echo '</span>';

echo '<hr style="border: 1px solid #7C5401" />';
}


//list($eventday, $eventlink) = each($events);
//echo '<hr>';
//foreach($holidays as $ed){
// $event = split('=>', $ed);
// echo $event[0].$event[1];
//}
//echo '<hr>';

$days = array($today=>array(''.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'',NULL,'<span style="font-weight: bold; border: solid 1px white; padding: 0px 0px 0px 0px;">'.$today.'</span>'));

$day_name_length = 1;
$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array('ÂÃ,«Ã‚Ã,«Ã‚Ã,«'=>$scripturl.'?month='.($month-1), 'ÂÃ,»Ã‚Ã,»Ã‚Ã,»'=>$scripturl.'?month='.($month+'1'));

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>   ';
if($n) $n = '   <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';

$calendar = '<table class="smalltext" width="100%">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
$sp1 = '';
$sp2 = '';
foreach($holidays as $sd) {
$event = split('=>', $sd);
if($day == intval($event[0]))
{
$sp1 = '<span align="center" style="color: #FFFFFF; background-color: #' . $modSettings['cal_holidaycolor'] . '; padding: 0px 0px 0px 0px;" title="'.htmlspecialchars($event[1]).'">';
$sp2 = '</span>';
}
}
foreach($events as $sd) {
$event = split('=>', $sd);
if($day == intval($event[0]))
{
$sp1 = '<span align="center" style="color: #FFFFFF; background-color: #' . $modSettings['cal_eventcolor'] . '; padding: 0px 0px 0px 0px;" title="'.htmlspecialchars($event[1]).'">';
$sp2 = '</span>';
}
}
foreach($birthdays as $sd) {
$event = split('=>', $sd);
if($day == intval($sd))
{
$sp1 = '<span align="center" style="color: #FFFFFF; background-color: #' . $modSettings['cal_bdaycolor'] . '; padding: 0px 0px 0px 0px;" title="'.htmlspecialchars($event[1]).'">';
$sp2 = '</span>';
}
}
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}
if(isset($days[$day]) and is_array($days[$day]) and ($month == date("n",$now))){
@list($link, $classes, $content) = $days[$day];
if(is_null($content))  $content  = $day;
$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>');
$calendar .= ($link ? '<a href="'.htmlspecialchars($link).'">'.$sp1.$content.$sp2.'</a>' : $sp1.$content.$sp2).'</td>';
}
else
{
$calendar .= "<td style=\"padding-right: 0px; font-size: x-small; font-family: arial, sans-serif;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$sp1$day$sp2</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';
echo '</table>';

// Show today's birthdays.
function ssi_rafy_todaysBirthdays($output_method = 'echo', $month)
{
global $context, $scripturl, $db_prefix;

if (!smf_loadCalendarInfo() || empty($context['calendar_birthdays']))
return array();

if ($output_method != 'echo')
return $context['calendar_birthdays'];

foreach ($context['calendar_birthdays'] as $member)
{
$query = db_query(
"SELECT birthdate
FROM {$db_prefix}members
WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

$row = mysql_fetch_assoc($query);
$birthdate = strtotime($row['birthdate']);

echo '<div align="center">';
echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("F jS",$birthdate) . '</strong></a>';
echo '<br />';
echo '<img src="/Themes/rOrb/images/icons/birthday_small.gif" width="13" height="17" align="absmiddle" hspace="5">';
echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
echo $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '');
echo '</a>';
// echo (!$member['is_last'] ? '<br>' : '');

echo '</div>';

if(date("n",$birthdate) == $month)
{
$sdays .= date("j",$birthdate).'=>'.$member['name'].'ÂÃ,´s bDay'.',';
}
}
return $sdays;
}

// Show today's events.
function ssi_rafy_todaysEvents($output_method = 'echo', $month)
{
global $context, $db_prefix;

if (!smf_loadCalendarInfo() || empty($context['calendar_events']))
return array();

if ($output_method != 'echo')
return $context['calendar_events'];

foreach ($context['calendar_events'] as $event)
{
$query = db_query(
"SELECT startDate
FROM {$db_prefix}calendar
WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

$row = mysql_fetch_assoc($query);
$startDate = strtotime($row['startDate']);

echo '<div align="center">';
echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startDate) . '"><strong>' . date("F jS Y",$startDate) . '</strong></a>';
echo '<br />';

if ($event['can_edit'])
echo '<a href="' . $event['modify_href'] . '" style="color: #FF0000;">[e]</a> ';
echo $event['link'] ;
// echo (!$event['is_last'] ? '<br>' : '');
echo '</div>';

if(date("n",$startDate) == $month)
{
$sdays .= date("j",$startDate).'=>'.str_replace("'","ÂÃ,´",$event['link']).',';
}
}
return $sdays;
}

// Show today's holidays.
function ssi_rafy_todaysHolidays($output_method = 'echo', $month)
{
global $context;

if (!smf_loadCalendarInfo() || empty($context['calendar_holidays']))
return array();

if ($output_method != 'echo')
return $context['calendar_holidays'];


foreach($context['calendar_holidays'] as $holiday) {
$query = db_query(
"SELECT eventDate
FROM {$db_prefix}smf_calendar_holidays
WHERE title='".str_replace("'","''",$holiday)."'
AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

$row = mysql_fetch_assoc($query);
$eventDate = strtotime($row['eventDate']);

echo '<div align="center">';
echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventDate) . '"><strong>' . date("F jS",$eventDate) . '</strong></a>';
echo '<br />';
echo $holiday;
echo '</div>';

if(date("n",$eventDate) == $month)
{
$sdays .= date("j",$eventDate).'=>'.str_replace("'","ÂÃ,´",$holiday).',';
}
}
return $sdays;
}



Thanks in advance for any help you can offer  ;)
Title: Re: Calendar in a php-block
Post by: jacortina on October 04, 2006, 10:29:34 PM
This wasn't the block I posted (and tweaked), though it has a lot of the same code.

But when I put this in my test site, I can't reproduce the condition you describe. Event link only shows above topic it's linked to and it doesn't even show there when I uncheck 'Show linked events in topic display:'.

Are you using the default theme? Do you mean event links above every post or at top of every topic?
Title: Re: Calendar in a php-block
Post by: truelight5 on October 04, 2006, 10:43:55 PM
No I am using a modified theme...I sent you a PM with the info to access the board in it =o)

Thanks!
Title: Re: Calendar in a php-block
Post by: jacortina on October 05, 2006, 01:34:20 PM
The issue was resolved. And for anybody else who is having an issue where linked events are appearing in every topic, you should check the Display.template.php in the theme you're using. If it retains the original comment, there's a section headed up with:

// Does this topic have some events linked to it?

The 'if' clause following that outputs the table containing events. In this case here, the 'if' clause and the 'foreach' loop a few lines down were referencing $context['calendar_events']. They should be referencing $context['linked_calendar_events']. Changing those two statements to reference the correct array cleared up the problem.
Title: Re: Calendar in a php-block
Post by: truelight5 on October 05, 2006, 05:58:12 PM
And BIG thanks to jacortina for going to my site and helping me figure this out!! I wouldn't have thought to look in the Display file. 


Where is that clapping hands jumping up and down with profuse gratitude smilie??

THANKS again Jacortina!

Blessings!
Susie
Title: Re: Calendar in a php-block
Post by: Giddeaon on October 11, 2006, 04:07:50 AM
Quote from: jacortina on October 05, 2006, 01:34:20 PM
The issue was resolved. And for anybody else who is having an issue where linked events are appearing in every topic, you should check the Display.template.php in the theme you're using. If it retains the original comment, there's a section headed up with:

// Does this topic have some events linked to it?

The 'if' clause following that outputs the table containing events. In this case here, the 'if' clause and the 'foreach' loop a few lines down were referencing $context['calendar_events']. They should be referencing $context['linked_calendar_events']. Changing those two statements to reference the correct array cleared up the problem.

That just fixed an annoying bug that has been plaguing me since I added that calendar block.  Thank you.
Title: Re: Calendar in a php-block
Post by: zeniitti on October 31, 2006, 07:57:24 AM
Here is conversation about changing language of the days etc. to local language: http://www.tinyportal.net/smf/index.php?topic=700.msg30037#msg30037 Any news how to do it? Gave it a little time and space, but I didn't hack it.

Another thing: is it possible to have upcoming weeks event rather than only one day? Would like to have like Next 7 days evetns or something like that.

tnx
Title: Re: Calendar in a php-block
Post by: keith021773 on November 10, 2006, 04:17:37 PM
In the events section of the code.  Is there a way to make it so that when you post you have more days for it to show?  I was wanting it to be able to show for at least one mth.  30 days or so..    For instance when a tv show or a game is coming out it could show it in the events section for 30 days...   I hope this makes sense.   LOL
Title: Re: Calendar in a php-block
Post by: jacortina on November 10, 2006, 04:27:40 PM
Quote from: keith021773 on November 10, 2006, 04:17:37 PM
In the events section of the code.  Is there a way to make it so that when you post you have more days for it to show?  I was wanting it to be able to show for at least one mth.  30 days or so..    For instance when a tv show or a game is coming out it could show it in the events section for 30 days...   I hope this makes sense.   LOL

This is an Admin Setting under Forum/Calendar - Max days in advance on board index:

This is the 'lookahead' for Birthdays, Holidays, and Events.
Title: Re: Calendar in a php-block
Post by: keith021773 on November 10, 2006, 04:43:08 PM
That seems to have fixed it..  Thank you very much!
Title: Re: Calendar in a php-block
Post by: zeniitti on November 22, 2006, 01:55:06 PM
Thanks, discovered that too some days ago :)
Title: Re: Calendar in a php-block
Post by: Malk on November 29, 2006, 12:18:34 PM
Anybody have a script? that can be localized in Ukrainian/Russian ????
Title: Re: Calendar in a php-block
Post by: zeniitti on November 30, 2006, 10:24:56 AM
Quote from: Malk on November 29, 2006, 12:18:34 PM
Anybody have a script? that can be localized in Ukrainian/Russian ????
Or Finnish... :(
Title: Re: Calendar in a php-block
Post by: bloodynightmare on December 28, 2006, 12:01:53 AM
is it possible to modify this code in order to use it as a mini right-PHPblock version of the big one included in every TP theme? maybe highlighting also the brithday dates of the users?
Title: Re: Calendar in a php-block
Post by: JCphotog on January 11, 2007, 02:19:20 AM
This is such a great snippet.  Is this the most current version?
http://www.tinyportal.net/index.php?topic=700.msg66994#msg66994
Title: Re: Calendar in a php-block
Post by: jacortina on January 11, 2007, 04:00:52 AM
Unless you're having centering problems, in which case, apply the change in:

http://www.tinyportal.net/index.php?topic=700.msg72488#msg72488
Title: Re: Calendar in a php-block
Post by: magnastik on January 11, 2007, 11:42:50 AM
Hi!
I would like to know how can i get the birthdays date before de members name, like the events.
In the picture attached you can see my current calendar block setup, but i would like to show users birthdays date.

I tried to edit SSI.php but with no results.
Any help would be appreciated.

Thanx,
MagNastiK
Title: Re: Calendar in a php-block
Post by: bubbel on February 03, 2007, 07:20:35 PM
Thx a lot for this guys!

Working just fine.  :up:
Title: Re: Calendar in a php-block
Post by: soMzE on February 08, 2007, 12:23:54 AM
This a great snippit, really cool!!

But one strange thing i see, valentines day is on Jan 1?  :D
Title: Re: Calendar in a php-block
Post by: jacortina on February 08, 2007, 01:52:12 AM
Find the section that lists holidays (the last section in the block), and find the line:
$eventdate = strtotime($row['eventDate']);

Change it to:
$eventdate = strtotime(date("Y").substr($row['eventDate'], 4));
Title: Re: Calendar in a php-block
Post by: soMzE on February 08, 2007, 02:27:33 AM
Thank you so much J.A.Cortina, that did the job! It's all perfect now  ;D


Title: Re: Calendar in a php-block
Post by: brianjw on February 08, 2007, 03:33:13 AM
Quote from: soMzE on February 08, 2007, 02:27:33 AM
Thank you so much J.A.Cortina, that did the job! It's all perfect now  ;D
I am interested in what code you are using ??? Does this calendar link in with the existing smf calendar that links the holidays/bdays/events/and days to? If not maybe someone can create something exactly like this but with links on holidays/bdays/events/and days !

Brianjw
Title: Re: Calendar in a php-block
Post by: soMzE on February 08, 2007, 03:39:38 AM
Quote from: brianjw on February 08, 2007, 03:33:13 AM
Quote from: soMzE on February 08, 2007, 02:27:33 AM
Thank you so much J.A.Cortina, that did the job! It's all perfect nowÃ,  ;D
I am interested in what code you are using ??? Does this calendar link in with the existing smf calendar that links the holidays/bdays/events/and days to? If not maybe someone can create something exactly like this but with links on holidays/bdays/events/and days !

Brianjw

This is the code i'm using for the calendar snippet:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  #adjust for $first_day
$titleÃ, Ã,  = htmlentities(ucfirst($month_name)).' '.$year;Ã, Ã,  #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table style="width:100%;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  #if the day names should be shown ($day_name_length > 0)
Ã,  Ã,  foreach($day_names as $d)
Ã,  Ã,  $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
Ã,  Ã,  $calendar .= '</tr><tr style="text-align:right;">';
Ã,  Ã,  }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
Ã,  Ã,  if($weekday == 7){
Ã,  Ã,  Ã,  Ã,  $weekdayÃ, Ã,  = 0; #start a new week
Ã,  Ã,  Ã,  Ã,  $calendar .= '</tr><tr style="text-align:right;">';
Ã,  Ã,  Ã,  Ã,  }

Ã,  Ã,  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 class="smalltext" style="padding-right:4px;"><a';
Ã,  Ã,  Ã,  Ã,  if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  $calendar .= ' style="color:#C00000;"';
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//Ã, Ã,  BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
Ã,  Ã,  echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

Ã,  Ã,  foreach ($context['calendar_birthdays'] as $member)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  $query = db_query(
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  "SELECT birthdate
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  FROM {$db_prefix}members
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

Ã,  Ã,  Ã,  Ã,  $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
Ã,  Ã,  Ã,  Ã,  $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
Ã,  Ã,  Ã,  Ã,  mysql_free_result($query);

Ã,  Ã,  Ã,  Ã,  $dummy = array();
Ã,  Ã,  Ã,  Ã,  $dummy[] = $member['id'];
Ã,  Ã,  Ã,  Ã,  loadMemberData($dummy);
Ã,  Ã,  Ã,  Ã,  $profile = &$user_profile[$member['id']];

Ã,  Ã,  Ã,  Ã,  echo '<div align="center">';
Ã,  Ã,  Ã,  Ã,  echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
Ã,  Ã,  Ã,  Ã,  echo ' - ';
Ã,  Ã,  Ã,  Ã,  echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
Ã,  Ã,  Ã,  Ã,  if (!empty($profile['member_group_color']))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  echo '</a>';
Ã,  Ã,  Ã,  Ã,  echo '</div>';
Ã,  Ã,  }
Ã,  Ã,  echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//Ã, Ã,  EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
Ã,  Ã,  echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

Ã,  Ã,  foreach ($context['calendar_events'] as $event)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  $query = db_query(
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  "SELECT startDate
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  FROM {$db_prefix}calendar
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

Ã,  Ã,  Ã,  Ã,  $row = mysql_fetch_assoc($query);
Ã,  Ã,  Ã,  Ã,  $startdate = strtotime($row['startDate']);

Ã,  Ã,  Ã,  Ã,  mysql_free_result($query);

Ã,  Ã,  Ã,  Ã,  echo '<div align="center">';
Ã,  Ã,  Ã,  Ã,  echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
Ã,  Ã,  Ã,  Ã,  echo ' - ';
Ã,  Ã,  Ã,  Ã,  echo $event['link'] ;
Ã,  Ã,  Ã,  Ã,  echo '</div>';
Ã,  Ã,  }
Ã,  Ã,  echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//Ã, Ã,  HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
Ã,  Ã,  echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

Ã,  Ã,  foreach ($context['calendar_holidays'] as $holiday)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  $query = db_query(
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  "SELECT eventDate
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  FROM {$db_prefix}calendar_holidays
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  WHERE title='".str_replace("'","''",$holiday)."'
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

Ã,  Ã,  Ã,  Ã,  $row = mysql_fetch_assoc($query);
Ã,  Ã,  Ã,  Ã,  $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

Ã,  Ã,  Ã,  Ã,  mysql_free_result($query);

Ã,  Ã,  Ã,  Ã,  echo '<div align="center">';
Ã,  Ã,  Ã,  Ã,  echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
Ã,  Ã,  Ã,  Ã,  echo ' - ';
Ã,  Ã,  Ã,  Ã,  echo $holiday;
Ã,  Ã,  Ã,  Ã,  echo '</div>';
Ã,  Ã,  }
Ã,  Ã,  echo '</td></tr>';
}

echo '</table>';


And yes it links to the existing calendar as far as i can seeÃ,  ::)
I can click the links on this block and it directs straightly to the calendar of smf :)

And if i change the colors in the admin section of the calendar it will change as well..


Hope this answers your question :)
Title: Re: Calendar in a php-block
Post by: jacortina on February 08, 2007, 03:41:57 AM
If you look at the picture given by soMzE, The numbers in the small calendar and the dates for the b-days/events/holdays ('Feb 14') are links which will bring up the SMF calandar to that date. The user names (which are membergroup colored) are links to the corresponding profiles.
Title: Re: Calendar in a php-block
Post by: brianjw on February 08, 2007, 11:23:28 PM
Thank you! :D I now use the code soMzE provided me :)
Code (Code soMzE provided me) Select

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table style="width:100%;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


;)
Brianjw
Title: Re: Calendar in a php-block
Post by: clarkkent93 on February 10, 2007, 08:50:35 AM
Quote from: soMzE on February 08, 2007, 03:39:38 AM
Quote from: brianjw on February 08, 2007, 03:33:13 AM
Quote from: soMzE on February 08, 2007, 02:27:33 AM
Thank you so much J.A.Cortina, that did the job! It's all perfect now  ;D
I am interested in what code you are using ??? Does this calendar link in with the existing smf calendar that links the holidays/bdays/events/and days to? If not maybe someone can create something exactly like this but with links on holidays/bdays/events/and days !

Brianjw

This is the code i'm using for the calendar snippet:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table style="width:100%;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


And yes it links to the existing calendar as far as i can see  ::)
I can click the links on this block and it directs straightly to the calendar of smf :)

And if i change the colors in the admin section of the calendar it will change as well..


Hope this answers your question :)

What kind of block is this?

Thanks
Title: Re: Calendar in a php-block
Post by: jacortina on February 10, 2007, 12:52:31 PM
Quote from: clarkkent93 on February 10, 2007, 08:50:35 AM
What kind of block is this?

Thanks

PHP block. Like the threed title says. ;)
Title: Re: Calendar in a php-block
Post by: clarkkent93 on February 10, 2007, 05:30:06 PM
 :uglystupid2:  it's official.  i've lost it!

thanks for your help!

bernard
Title: Re: Calendar in a php-block
Post by: jakemelon on February 12, 2007, 03:49:44 AM
I noticed this snippet only shows events from the upcoming week. Any idea how to change it to list a month worth of events or more?

thanks

jake
Title: Re: Calendar in a php-block
Post by: jacortina on February 12, 2007, 04:10:48 AM
You set that in you Admin Control Panel.

Forum/Calendar -> "Max days in advance on board index:"
Title: Re: Calendar in a php-block
Post by: jakemelon on February 12, 2007, 04:31:58 AM
Nice! thank you!
Title: Re: Calendar in a php-block
Post by: mrbean17 on February 12, 2007, 11:54:41 PM
Quote from: RoarinRow on March 05, 2006, 05:44:23 AM
Very cool, thanks!  I like it and it integrates with the calendar so someone just clicks on a date and a new post opens up to enter an event.   ;)

I may have missed it, but anyway I put the last two codes together.  Now it shows the calendar with the abbreviations with two characters, e.g. 'Mo' for Monday and any upcoming events.  Hope it's right.

global $scripturl, $modSettings;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';




Thanks, this is what I was looking for. Is it possible to bold days on which an event occurs?

Thanks
Title: Re: Calendar in a php-block
Post by: jakemelon on February 13, 2007, 12:06:31 AM
Yea that would be nice, that is beyond me, maybe someone can help. It would be nice to bold or have events highlighted in the calendar itself, otherwise it is kinda useless except for list of events below it (that is what I am using it for).

jake
Title: Re: Calendar in a php-block
Post by: brianjw on February 13, 2007, 12:25:25 AM
I would like to bold my letters too. Does it do this in the calendar part of smf?
If not how to modify this and that code to make it show today to be bold.... ? ???

Brianjw
Title: Re: Calendar in a php-block
Post by: mrbean17 on February 13, 2007, 04:11:54 PM
One more small suggestion ... is it possible to line break after each event so they dont group together?

Thanks
Title: Re: Calendar in a php-block
Post by: mrbean17 on February 14, 2007, 10:33:36 PM
Is it possible to add repeating events?
Title: Re: Calendar in a php-block
Post by: jacortina on February 14, 2007, 10:53:35 PM
Your lack of breaks between events is because the block you're using calls the SSI functions to do the output and that's how SSI does it. There are a number of other blocks given in this thread which do it differently.

And except for yearly 'holiday' type entries, I don't think there's functionality for repeating events. But that's really an SMF matter.
Title: Re: Calendar in a php-block
Post by: mrbean17 on February 14, 2007, 11:45:53 PM
Quote from: J.A.Cortina on February 14, 2007, 10:53:35 PM
Your lack of breaks between events is because the block you're using calls the SSI functions to do the output and that's how SSI does it. There are a number of other blocks given in this thread which do it differently.

And except for yearly 'holiday' type entries, I don't think there's functionality for repeating events. But that's really an SMF matter.

Ok cool, do you happen to have a better one than the one I used here? : http://www.tinyportal.net/index.php?topic=700.msg109987#msg109987
Title: Re: Calendar in a php-block
Post by: jacortina on February 14, 2007, 11:52:39 PM
I adapted and combined earlier submissions into:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: mrbean17 on February 15, 2007, 12:05:25 AM
Quote from: J.A.Cortina on February 14, 2007, 11:52:39 PM
I adapted and combined earlier submissions into:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


NICE! Thank you :)
Title: Re: Calendar in a php-block
Post by: Shadow on February 15, 2007, 01:45:23 AM
Nice code!!!
Title: Re: Calendar in a php-block
Post by: jakemelon on February 15, 2007, 02:19:24 AM
Hi,

What pieces of the code do I need to remove so it only shows Events? like this:

Feb 14 - PINOT's Valentine Event
Feb 17 - Presidents Weekend Celebration
Feb 21 - Le Rendezvous


don't want any holidays or birthdays to ever show up...I tried to remove the two procedures for birthdays and holidays but it stopped working!

thanks

jake
Title: Re: Calendar in a php-block
Post by: jacortina on February 15, 2007, 02:27:31 AM
You may not have removed them correctly (too little or too much).

This is the code above with those two sections removed and it seems to work for me:
global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: Mannie on February 19, 2007, 08:22:15 PM
I like to have that block with the changes to link events to. Only i am a complete idiot when it comes to this. Can anyone help me with this please ? ;)
Title: Re: Calendar in a php-block
Post by: jacortina on February 19, 2007, 11:33:55 PM
Put the code from the message above into a php block (right or left side).

It shows a calendar (days linked to SMF calendar page) and beneath that only Events (not birthdays or holidays).
Title: Re: Calendar in a php-block
Post by: Mannie on February 20, 2007, 06:08:33 AM
Ok , thanks ;)
Title: Re: Calendar in a php-block
Post by: growl on February 20, 2007, 11:01:11 AM
how can i add todays events to tghis code?
Title: Re: Calendar in a php-block
Post by: jacortina on February 20, 2007, 01:39:03 PM
Quote from: growl on February 20, 2007, 11:01:11 AM
how can i add todays events to tghis code?

Not sure I understand. Any events in the 'look-ahead' period you define for the SMF Calendar, including today's, will be listed.
Title: Re: Calendar in a php-block
Post by: growl on February 20, 2007, 02:16:59 PM
ok, let's say, this is the code i want to modify to display todays events only:


if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Today</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("m",$startdate) . '"><strong>' . date("d.m.",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}



how would i have to modify it?
and will i have to add further information before that?
Title: Re: Calendar in a php-block
Post by: carver on February 20, 2007, 04:07:08 PM
Nice job!! you guys never cease to amaze...
Title: Re: Calendar in a php-block
Post by: jacortina on February 20, 2007, 05:32:26 PM
Quote from: growl on February 20, 2007, 02:16:59 PM
how would i have to modify it?
and will i have to add further information before that?

Try:
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Today</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);
        mysql_free_result($query);

        if (date("d.m") == date("d.m.",$startdate)) {
            echo '<div align="center">';
            echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("m",$startdate) . '"><strong>' . date("d.m.",$startdate) . '</strong></a>';
            echo ' - ';
            echo $event['link'] ;
            echo '</div>';
        }
    }
    echo '</td></tr>';
}


Title: Re: Calendar in a php-block
Post by: growl on February 21, 2007, 07:13:39 AM
hi!
sorry, it doesn't show anything, just an empty row with the "Today" caption.#ny other suggestions?
Title: Re: Calendar in a php-block
Post by: jacortina on February 21, 2007, 02:57:25 PM
Could you post the full code of the block that you're using?
Title: Re: Calendar in a php-block
Post by: growl on February 21, 2007, 03:34:05 PM
global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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 Sundays
    $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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';




if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Heute</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);
        mysql_free_result($query);

        if (date("d.m.") == date("d.m.",$startdate)) {
            echo '<div align="center">';
            echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("m",$startdate) . '"><strong>' . date("d.m.",$startdate) . '</strong></a>';
            echo ' - ';
            echo $event['link'] ;
            echo '</div>';
        }
    }
    echo '</td></tr>';
}




/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Ausritte</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("m",$startdate) . '"><strong>' . date("d.m.",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}


/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Jahrestage</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("d.m.",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: jacortina on February 21, 2007, 03:38:33 PM
And in the full 'Events' section under the empty 'Today' part, are there events listed for today?
Title: Re: Calendar in a php-block
Post by: growl on February 21, 2007, 03:51:35 PM
no they are not, the events start with the next day(i.e. the day after today, no matter what today is)
Title: Re: Calendar in a php-block
Post by: jacortina on February 21, 2007, 04:00:20 PM
Hmm. The first thing that makes me think of is time offset.

In your Admin Control PAnel -> Configuration/Features and Options, what is the value for "Overall time offset"? Do you have any personal time offset specified in your own profile?
Title: Re: Calendar in a php-block
Post by: growl on February 21, 2007, 04:02:39 PM
no, the offset is set to 0
Title: Re: Calendar in a php-block
Post by: Dazed on February 21, 2007, 04:04:44 PM
Quote from: J.A.Cortina on February 21, 2007, 04:00:20 PM
Hmm. The first thing that makes me think of is time offset.

In your Admin Control PAnel -> Configuration/Features and Options, what is the value for "Overall time offset"? Do you have any personal time offset specified in your own profile?

Since Growl is saying 0 maybe it needs changed. You were thinking exactly what I was.
Title: Re: Calendar in a php-block
Post by: jacortina on February 21, 2007, 04:07:47 PM
Then the question becomes whether the forum itself is displaying the correct date/time (when a post id made, for instance) and whether the 'grid' part of the calendar is highlighting the correct date.
Title: Re: Calendar in a php-block
Post by: growl on February 22, 2007, 08:26:15 AM
before the script mebntioned above i had this one which diusplayed todays events corrct, but didn't read events dates and the calendar was not clickable, so i'd rather stick to the newer one.
can anybody help me to get the "newer" script to show todays events?

$now = mktime();
$today = date('j',$now);
$days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: blue; border: 1px solid black; background-color: yellow; padding:0px 2px 0px 2px;">'.$today.'</span>'));
$year = date("Y",$now);
$month = date("n",$now);

$day_name_length = 2;
$month_href = NULL;
$first_day = 0;
$pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".



'<caption >'.$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 .= '<td class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</td>';

$calendar .= "</tr>\n<tr>";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week

$calendar .= "</tr>\n<tr>";
}

if(isset($days[$day]) and is_array($days[$day])){

@list($link, $classes, $content) = $days[$day];

if(is_null($content))  $content  = $day;

$calendar .= '<td align=\"center\" valign=\"middle\" '.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').

($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';

}

else $calendar .= "<td align=\"center\" valign=\"middle\" class=\"smalltext\">$day</td>";
}

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days



echo $calendar.'</tr>';

$todaysBirthdays = ssi_todaysBirthdays('array');
$todaysEvents = ssi_todaysEvents('array');
$todaysHolidays = ssi_todaysHolidays('array');

global $context, $scripturl, $modSettings;

if ($todaysEvents || $todaysHolidays || $todaysBirthdays)
{



echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Heute</td><td colspan="2"><hr></td></tr>';



if ($todaysBirthdays)



{

echo '<span style="color: #' . $modSettings['cal_bdaycolor'] . ';">Geburstage: </span>';





foreach ($todaysBirthdays as $member)







echo '

<a href="', $scripturl, '?action=profile;u=', $member['id'], '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : '');

if ($todaysEvents || $todaysHolidays)

echo '<br />';
}

if ($todaysHolidays)

{

echo '<span style="color: #' . $modSettings['cal_holidaycolor'] . ';">Feiertag: </span>';

echo implode(', ', $todaysHolidays);

if ($todaysEvents)

echo '<br />';
        }

if ($todaysEvents)

{

echo '<span style="color: #' . $modSettings['cal_eventcolor'] . ';">Events: </span>';

foreach ($todaysEvents as $event)

echo $event['link'] . (!$event['is_last'] ? ', ' : '');

}

echo '</td></tr>';
}

$today = ssi_todaysCalendar('array');
if ($today)
{

echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center">Zukünftige Ereignisse</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';


if (!empty($today['birthdays']))

{

echo '<span style="color: #' . $modSettings['cal_bdaycolor'] . ';">Geburstage: </span>';

foreach ($today['birthdays'] as $member)

echo '

<a href="'. $scripturl .'?action=profile;u='. $member['id']. '">'. $member['name'] .'', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : '';

if (!empty($today['events']) || !empty($today['holidays']))

echo '<br />';

}

if (!empty($today['events']))

{

echo '<span style="color: #' . $modSettings['cal_eventcolor'] . ';">Events: </span>';
foreach ($today['events'] as $event)

{

echo '
' . $event['link'] . (!$event['is_last'] ? ', ' : '');
}
if (!empty($today['holidays']))

echo '<br />';

}

if (!empty($today['holidays']))
echo '<span style="color: #' . $modSettings['cal_holidaycolor'] . ';">Feiertage: </span>' . implode(', ', $today['holidays']);
echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: whatever on February 22, 2007, 11:18:29 AM
Tres cool  8)

Quote from: J.A.Cortina on February 14, 2007, 11:52:39 PM
I adapted and combined earlier submissions into:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';

Title: Re: Calendar in a php-block
Post by: Sharr76 on February 22, 2007, 12:52:28 PM
This is excellent!! look good on my site

http://www.ndex.org
Title: Re: Calendar in a php-block
Post by: jacortina on February 22, 2007, 03:38:36 PM
Quote from: growl on February 22, 2007, 08:26:15 AM
before the script mebntioned above i had this one which diusplayed todays events corrct, but didn't read events dates and the calendar was not clickable, so i'd rather stick to the newer one.
can anybody help me to get the "newer" script to show todays events?

The thing is, I haven't heard of anybody else who's NOT getting today's events with the newer script. And I can't see why the one script shows entries the other doesn't.

The script you give, uses:
$todaysBirthdays = ssi_todaysBirthdays('array');
$todaysEvents = ssi_todaysEvents('array');
$todaysHolidays = ssi_todaysHolidays('array');


Then:
$today = ssi_todaysCalendar('array');


But a glance at any/all of those functions in SSI.php shows that each of them make use of smf_loadCalendarInfo() to get calendar entries. What's the first statement in my script after the gloabl declarations? smf_loadCalendarInfo().
Title: Re: Calendar in a php-block
Post by: growl on February 22, 2007, 03:48:06 PM
strange this is...

ok, i'll give your script another try, but i am not very confident...
Title: Re: Calendar in a php-block
Post by: growl on February 22, 2007, 03:58:15 PM
unlucky me...
it seems that i have modified my ssi.php earlier to fit the other calendar, but the modified one won't work with the "newer" calendar.
restored the old one and now everything works fine;-)
Title: Re: Calendar in a php-block
Post by: jacortina on February 22, 2007, 04:02:18 PM
Well, that makes more sense, then. ;)
Title: Re: Calendar in a php-block
Post by: francerossina on February 28, 2007, 05:21:24 PM
Quote from: J.A.Cortina on February 14, 2007, 11:52:39 PM
I adapted and combined earlier submissions into:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


Thanks very much :)
I'd like to see only sunday in red and not also saturday. How can I do it?
Furthermore, is there a way to make days on the calendar non clickable by user?
Title: Re: Calendar in a php-block
Post by: brianjw on March 01, 2007, 12:19:42 AM
Nonclickable... If I were you I would get on google and search for calendars. There are many calendars that show the date and everything but do not link anywhere. Half the code of this one was used to make it get and link events to the calendar in SMF ;)
Title: Re: Calendar in a php-block
Post by: mrbean17 on March 06, 2007, 06:58:41 PM
Is it possible to have the current month show all events for the month vs. just the current week?

Looking at the events section, I'm not even sure how its pulling the information back based on a date range...


/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}


Thanks
Title: Re: Calendar in a php-block
Post by: jacortina on March 06, 2007, 07:04:16 PM
You're just going to keep bustin' my chops, eh Mr. Bean? ;)

This uses the standard 'lookahead' set for the SMF calendar events (as noted earlier in this thread; yes, I know, this is page 30!!!).

You set that in you Admin Control Panel.

Forum/Calendar -> "Max days in advance on board index:"

This will still only show upcoming events, but you can set it to 30/31 to have a full month's worth shown.
Title: Re: Calendar in a php-block
Post by: mrbean17 on March 06, 2007, 07:09:39 PM
Awesome, thanks!
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 13, 2007, 11:04:06 AM
Awesome mod!

Just a little question:

How can I do to show weekend (I mean Saturday + Sunday) to the end of the week? In Spain, weeks starts on Monday...
Title: Re: Calendar in a php-block
Post by: jacortina on March 13, 2007, 01:57:32 PM
To start week with Monday, find:
$first_day = 0;

change to:
$first_day = 1;
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 13, 2007, 04:31:11 PM
Thank you! Works perfect! Awesome!  ;) :D
Title: Re: Calendar in a php-block
Post by: SaD333 on March 21, 2007, 04:40:23 PM
spanish calendar?
Title: Re: Calendar in a php-block
Post by: ogmios on March 29, 2007, 01:25:36 PM
is there a way to get the 'post event' button to display at the bottom of the calendar i have showing in my php block?

was this already discussed and i missed it?
Title: Re: Calendar in a php-block
Post by: chep on April 12, 2007, 06:39:42 AM
This calendar kicks ass. Thanks
Title: Re: Calendar in a php-block
Post by: brianjw on April 13, 2007, 12:35:32 AM
This has to do with php I think and a calendar so I figured I might ask this here. *yes it does have to do with TP and blocks*

Is there a way I can make something that is in a marquee that takes all the events (NOT BIRTHDAYS) from the calendar and puts it in the scrolling thingy. Except the scrolling thingy only displays the nearest event and thats it. Only the nearest and only one event. Is this possible?

Brianjw :)
Title: Re: Calendar in a php-block
Post by: Rashka on May 05, 2007, 09:53:44 AM
Hi Guys, i use the code shown on www.ffxi.bruderschaft.de.vu:


global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array();

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$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()

#retrieve this month events, holydays and birthdays
$days_in_month = gmdate('t',$first_of_month);
include_once($sourcedir . '/Calendar.php');
$low_date = $year.'-'.$month.'-01';
$high_date = $year.'-'.$month.'-'.$days_in_month;
$events = calendarEventArray($low_date, $high_date);
$birthdays = calendarBirthdayArray($low_date, $high_date);

#add important days to the days array
foreach($events as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'lightblue').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($event['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

foreach($birthdays as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'lightblue').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($birth['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

$today_date = $year.'-'.($month<10 ? '0'.$month : $month).'-'.$today;

if(empty($events[$today_date]))
$days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');
else
$days[$today] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: lightblue; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>');


$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

#crate notice for the next N days events. N is set in Settings.
if (ssi_todaysCalendar('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['birthdays'])){
echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Geburtstage</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
$birthdays = $result['birthdays'];
echo '
<span style="color: #' . $modSettings['cal_bdaycolor'] . ';">' . $txt['calendar3b'] . '</span><br />';
foreach( $birthdays as $member )
echo '
<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', '<br />';
echo '</td></tr>';
}
if(!empty($result['events']))
{
echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center"><b>Zukünftiges</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4b'] . '</span><br /> ';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],8).'/'.substr($event['start_date'],5 , 2).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
}
  echo '</td></tr>';
}

echo '</table>';


My Events r like this: 06/05: * Linkshell Rennen
My Birthdays r like this: Rashka (26)

1. How can i do the "06/05" Date Format to my birthdays?
2. How can i do the Days shown in "Mo, Tu, We etc." into German "Mo, Di, Mi etc"??

btw, thank u guys for this great thing ;)

regards
Rashka



Title: Re: Calendar in a php-block
Post by: G6Cad on May 05, 2007, 11:15:45 AM
@ Rashka

I think if you read through this long thread, you will have that answer you seek for.
There are numerous posts made with diffrent ways to show things in the block, and in what order, and im almost possitive that your answer is there to.
Title: Re: Calendar in a php-block
Post by: Rashka on May 06, 2007, 11:47:44 AM
For Translate the Months and Days into german, i just found this post: http://www.tinyportal.net/index.php?topic=700.msg30584#msg30584

I'm pretty new on php... so i don't really know what to do.
I've added %a from the link into:
$day_names[$n] = ucfirst(gmstrftime('%A,%a',$t)); #%A means full textual day name
and %B into
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));

But both parts stay in english....
I can't find the written "setlocale()" thing in  my code...

I'm new to php, so pls help me^^

regards
Rashka
Title: Re: Calendar in a php-block
Post by: Rashka on May 11, 2007, 06:02:51 AM
Can noone help me to set the calendar to german?
sorry but I'm really a noob to php ;_;

regards
Rashka
Title: Re: Calendar in a php-block
Post by: jacortina on May 11, 2007, 03:16:58 PM
Changing the Language

All the blocks here (I believe) will get month and day names from the system based on the environment settings for 'locale'. If the server is set up for English, then that's what's going to be given.

Here are two possible ways to address this if you want to present the Calendar in another language.


First Method
Change your locale setting in the script. There are some warnings about this in that this change is process-wide and not thread limited, so can affect other threads running under the same process. You can try to limit this by changing it back as quickly as possible, but I really don't know how it will work. But if you want to try it ...

Find
$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_month));


Replace with
$day_names = array();                                      #generate all the day names according to the current locale
$baselocale = setlocale(LC_TIME, '');
setlocale(LC_TIME, '??-locale-ID-??');
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_month));
setlocale(LC_TIME, $baselocale);


Note the line: "setlocale(LC_TIME, '??-locale-ID-??');". You need to put a value in for that locale ID parameter for the language you want to use. Both the languages available and the correct way to specify them are fully dependent on YOUR host server. Many have aliases set up for languages and you can simply enter 'german', or 'spanish', but others may require things like 'de-DE' or 'de-DE.UTF-8'. If you have SSH access to your host, go there and enter 'locale -a' at the prompt for a list of valid values.


Second Method
Hard code your values so you don't get them from the host's environment.

Find
$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_month));


Replace with
$day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); #specify all the day names
// or if you want week to start on Monday
// $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'); #specify all the day names
//
// 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_month));
$month_names = array();
$month_names['01'] = 'January';
$month_names['02'] = 'February';
     .
     .
     .
$month_names['12'] = 'December';
$month_name = $month_names[$month];



Edit: slight change to last code block.
Title: Re: Calendar in a php-block
Post by: Eleazar on May 12, 2007, 04:33:09 AM
Erm Hi, i've looked through the entire thread and might have missed it but my calender isnt showing the correct 'today'. As in its 12 May 11.30am now but the calender shows 11 May. Any idea how do i fix this ?

Admin -> Features and Options -> Overall time offset at 0.

Using

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 86400; <- Lol i tried changing this.
[/color]
$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 1;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#ff3366;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ff3366' . $modSettings['cal_holidaycolor'] . ';"><color=#ff3366>Holidays</color></td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


thanks in advance :)
Title: Re: Calendar in a php-block
Post by: jacortina on May 12, 2007, 04:50:55 AM
Do you show the User Block (like the top left block on this site)? If not, could you turn it on to check? What does THAT say the current date/time is? Are timestamps on your posts correct?

Actually, that might not make a difference. That line you noted as trying to change uses the mktime() function. That uses the SERVER'S local date time and then applies the forum's time offset. It doesn't take into account the offset YOU specify in your profile.

You can 'try' to change that line to:
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

You also have to add $user_info to the 'global' line.

[Was that value 86400 in the code you were using? That's seconds in a day, but the offsets are in hours, so it should be seconds in an hour or 3600.]
Title: Re: Calendar in a php-block
Post by: Eleazar on May 12, 2007, 08:43:52 AM
I see. Its working now but i cant say for sure at the exact time of midnight. I'll check back :D Thanks
Title: Re: Calendar in a php-block
Post by: fangweile on May 23, 2007, 12:16:35 PM
can I adjust the Width of the calendar?
Title: Re: Calendar in a php-block
Post by: Porky on May 23, 2007, 12:23:09 PM
Quote from: fangweile on May 23, 2007, 12:16:35 PM
can I adjust the Width of the calendar?

Are you talking about the one in a block or the one in SMF?

For the block you can goto the settings in TP and change the widths of a block
And if it is the SMF Calendar just set it up not to display blocks when viewed.
Title: Re: Calendar in a php-block
Post by: fangweile on May 23, 2007, 12:55:48 PM
I am talking about the width of the calendar, I have set my block to 150 pixel and when I try to use the calendar its overlaps in the blocks.
Title: Re: Calendar in a php-block
Post by: jacortina on May 23, 2007, 01:32:01 PM
Which version of the Calendar block are you using (probably easiest to paste the code from the block into a post here)?
Title: Re: Calendar in a php-block
Post by: fangweile on May 24, 2007, 01:42:45 AM
I have used this code:

Quoteglobal $scripturl;

         $now = mktime();
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: red; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = NULL;
         $first_day = 0;
         $pn = array();

   $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_month));
   $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
   $title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
   if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
   $calendar = '<table>'."\n".
      '<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
      $calendar .= "</tr>\n<tr>";
   }

   if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
   for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
      if($weekday == 7){
         $weekday   = 0; #start a new week
         $calendar .= "</tr>\n<tr>";
      }
      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 class=\"smalltext\">$day</td>";
   }
   if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

   echo $calendar."</tr>\n</table>\n";
Title: Re: Calendar in a php-block
Post by: jacortina on May 24, 2007, 01:57:19 AM
Right off, I'd try changing:
         $day_name_length = 3;

To:
         $day_name_length = 2;

As long as you can settle for chopping the day column labels to two letters.
Title: Re: Calendar in a php-block
Post by: fangweile on May 24, 2007, 03:08:54 AM
Its really works, thanks a lot J.A.Cortin :lol:
Title: Re: Calendar in a php-block
Post by: purplegold on May 25, 2007, 05:34:28 PM
Quote from: J.A.Cortina on May 24, 2007, 01:57:19 AM
Right off, I'd try changing:
         $day_name_length = 3;

To:
         $day_name_length = 2;

As long as you can settle for chopping the day column labels to two letters.


Sounds good, it does seem to fix the width with the rest of the block however how can you position the calender in the centre since it looks too far to the left and a whole bunch of empty space on the right.

thanks.
Title: Re: Calendar in a php-block
Post by: jacortina on May 25, 2007, 06:26:54 PM
Try changing:
   $calendar = '<table>'."\n".
      '<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $title).$n."</caption>\n<tr>";


To:
   $calendar = '<table align="center">'."\n".
      '<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $title).$n."</caption>\n<tr>";

Title: Re: Calendar in a php-block
Post by: purplegold on May 25, 2007, 06:33:40 PM
Thanks alot!!!  :coolsmiley:
Title: Re: Calendar in a php-block
Post by: Galious on June 18, 2007, 04:05:10 PM
I'm trying to change language in a server-independent way, so I've done the modifications in the last page. The problem is that now the month name has disappeared. I've revised the code, but I haven't been able to find why.

Any ideas?

I'm using this code:
global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 1;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');                                      #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_month));
$month_nam = array();
$month_nam[01] = 'Enero';
$month_nam[02] = 'Febrero';
$month_nam[03] = 'Marzo';
$month_nam[04] = 'Abril';
$month_nam[05] = 'Mayo';
$month_nam[06] = 'Junio';
$month_nam[07] = 'Julio';
$month_nam[08] = 'Agosto';
$month_nam[09] = 'Septiembre';
$month_nam[10] = 'Octubre';
$month_nam[11] = 'Noviembre';
$month_nam[12] = 'Diciembre';
$month_name = $month_nam[$month];

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Cumpleaños</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("j M",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Eventos</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Vacaciones</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: jacortina on June 19, 2007, 12:37:39 AM
Try changing the months lines to:
$month_nam['01'] = 'Enero';
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
Title: Re: Calendar in a php-block
Post by: Galious on June 19, 2007, 11:26:34 AM
Perfect! It worked for me  :up:
Title: Re: Calendar in a php-block
Post by: itsacoaster on June 22, 2007, 06:32:25 PM
Hey, is there any way to make the weekend days the same color as the weekdays?
Title: Re: Calendar in a php-block
Post by: Osmonicar on June 24, 2007, 04:30:49 PM
For all the Dutch people here the right code:


global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 1;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$day_names = array();                                      #generate all the day names according to the current locale
$baselocale = setlocale(LC_TIME, '');
setlocale(LC_TIME, 'nl-locale-ID-NL');
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_month));


$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Jarigen</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Feestdagen</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


Can it by don that when there is nothing to show in one of the sections to make a small note that there is nothing to show.

One more thing a like to se is a max length for the name, holyday or event text
Title: Re: Calendar in a php-block
Post by: jacortina on June 26, 2007, 03:49:55 PM
Quote from: itsacoaster on June 22, 2007, 06:32:25 PM
Hey, is there any way to make the weekend days the same color as the weekdays?

Try this.

Find:
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }


And comment it out:
//        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
//            {
//            $calendar .= ' style="color:#C00000;"';
//            }
Title: Re: Calendar in a php-block
Post by: itsacoaster on June 26, 2007, 04:01:09 PM
Worked like a charm!  Thanks!
Title: Re: Calendar in a php-block
Post by: npereira on August 10, 2007, 02:58:37 PM
ok, 33 pages long is TOO MUCH... !

Is there a version of the code snippet to highlight and link to days which have events scheduled form the Main Calendar?

Or is this still not possible? Please PM me
Title: Re: Calendar in a php-block
Post by: Crip on August 10, 2007, 03:26:04 PM
The one you need is in the very 1st post by Mr. Bloc
Title: Re: Calendar in a php-block
Post by: npereira on August 10, 2007, 03:59:28 PM
but what bloc type does it need to be?
Title: Re: Calendar in a php-block
Post by: Crip on August 10, 2007, 04:26:50 PM
phpbox
Title: Re: Calendar in a php-block
Post by: npereira on August 10, 2007, 04:40:15 PM
ok, but it does not link to the SMF calendar?
Title: Re: Calendar in a php-block
Post by: Crip on August 10, 2007, 05:11:16 PM
Yup!
Title: Re: Calendar in a php-block
Post by: ogmios on August 16, 2007, 03:55:34 PM
not sure if this has been talked about already, so please let me know if it has...

in my calendar block, an event that runs for more than one day shows up in the calendar each day it is happening, but the date won't change for the additional days and will only display the date of the first day of the event...

any way to fix? here's my calendar code:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table style="width:100%;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#06FE69;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';


/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_eventcolor'] . ';">EVENTS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_holidaycolor'] . ';">HOLIDAYS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}
echo '</table>';



thanks in advance for any help...

Title: Re: Calendar in a php-block
Post by: jacortina on August 17, 2007, 12:45:42 AM
Quote from: ogmios on August 16, 2007, 03:55:34 PM
any way to fix? here's my calendar code:

What do you want it to say?

When you look at the code, you can see this line:
smf_loadCalendarInfo();

That calls an SMF function (in SSI.php) to load the members of $context['calendar_events'] used in the Events Section. And when you look in the Events section, you can see that when it reads the calenadar table, all it gets for it is the startDate.
Title: Re: Calendar in a php-block
Post by: ogmios on August 17, 2007, 01:51:53 AM
QuoteWhat do you want it to say?

well, for example, if i had an event that ran on August 17, 18 & 19, the calendar shows the event listing each day, but the date on the calendar always remains at August 17... even if it's the 18th or 19th to us, the calendar only shows the first date (the 17th) with the event title...

when visitors come to the site and look at the calendar, they see an incorrect date and think it's a mistake...

i thought there may be a way to have the date on the calendar update to the current day, rather than display the starting date of the event...

Title: Re: Calendar in a php-block
Post by: jacortina on August 17, 2007, 02:23:15 AM
Well, this 'should' set the date to the current date if the start date is past. Note that I haven't tested it as I don't have a board that uses multi-date events.

Find (in the Events Section):
        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="left">';


And replace with:
        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        $cal_date = date("Y", $now) . date("m", $now) .date("d", $now);
        $evt_date = date("Y", $startdate) . date("m", $startdate) .date("d", $startdate);

        if($cal_date > $evt_date)
            $startdate = $now;

        echo '<div align="left">';
Title: Re: Calendar in a php-block
Post by: ogmios on August 17, 2007, 01:13:40 PM
it worked - it's awesome - thank you...
Title: Re: Calendar in a php-block
Post by: Sandriell on September 10, 2007, 06:28:00 PM
To expand on ogmios' issue, I also use repeating events.

The code fix you provided does indeed update the displayed date to the current date, which is great for events that run consecutively. We however have a lot of repeating events that occur every Saturday, or every Sunday.

It would be ideal if the date shown was the next date the event was scheduled to repeat.

The mod we are using for repeating events is Repeating Calendar Events v1.2.6 (http://custom.simplemachines.org/mods/index.php?mod=655)

This is probably a big change, so I understand if you do not want to support it. Thanks either way!
Title: Re: Calendar in a php-block
Post by: ogmios on September 15, 2007, 03:35:22 AM
is it possible to anchor my babylon themed 'post event' button (from the smf calendar) to the bottom of my php-block calendar so users could start from there?

(example image attached)
Title: Re: Calendar in a php-block
Post by: jacortina on September 16, 2007, 10:17:54 PM
Quote from: Sandriell on September 10, 2007, 06:28:00 PM
The mod we are using for repeating events is Repeating Calendar Events v1.2.6 (http://custom.simplemachines.org/mods/index.php?mod=655)

This is probably a big change, so I understand if you do not want to support it. Thanks either way!

This code is built on taking SMF-supplied calendar info (that line up top which says "smf_loadCalendarInfo();") and working with what it supplies to the array "$context['calendar_events']". As I don't use the mod you name (and have no need for it), I really don't know how it works and what (if any) array it fills and where it does that.
Title: Re: Calendar in a php-block
Post by: Metorks on September 19, 2007, 08:01:40 AM
Would it be possible to set up two of these block to show the next two months on the side of the current month's calendar?
Title: Re: Calendar in a php-block
Post by: jacortina on September 20, 2007, 03:35:29 PM
This code is not really appropriate for that. It specifically takes the Calendar 'look ahead' defined for the forum to display events under the calendar for the current month.

I believe that if you're simply looking to add small month calendars to the calendar page display, there's a mod for that over on the SMF site ('Enhanced Calendar' or something like that).
Title: Re: Calendar in a php-block
Post by: ogmios on September 20, 2007, 04:50:09 PM
Quote from: ogmios on September 15, 2007, 03:35:22 AM
is it possible to anchor my babylon themed 'post event' button (from the smf calendar) to the bottom of my php-block calendar so users could start from there?

ok, i opened calendar.template.php and was able to add part of the 'show button' code to my calendar block to have the 'post event' button show inside my calendar block... but when i click on the button, i get an 'invalid month value' error message...

i realize that there is probably more to getting this to work than just embedding a button, but i'm not sure what (i'm just a beginner)...

interesting thing is that the 'post event' button (in the php calendar block) works when i'm viewing the SMF calendar, but it doesn't work when if i am viewing anything else...

still working on it, but any hints or advice are welcome...
Title: Re: Calendar in a php-block
Post by: Metorks on September 20, 2007, 05:00:28 PM
Quote from: J.A.Cortina on September 20, 2007, 03:35:29 PM
This code is not really appropriate for that. It specifically takes the Calendar 'look ahead' defined for the forum to display events under the calendar for the current month.

I believe that if you're simply looking to add small month calendars to the calendar page display, there's a mod for that over on the SMF site ('Enhanced Calendar' or something like that).

I'll look into that then.  Thanks!
Title: Re: Calendar in a php-block
Post by: jacortina on September 20, 2007, 05:14:15 PM
I believe the URL the button takes you to has to be of the form:

'<a href="http://', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">'

The $month and $year are already set up in the code.

I haven't done anything with the session ID before, but I think the above will put it in place.
Title: Re: Calendar in a php-block
Post by: ogmios on September 20, 2007, 05:26:28 PM
QuoteThe $month and $year are already set up in the code.

I haven't done anything with the session ID before, but I think the above will put it in place.

absolutely fabulous! thanks! it works great!

i had all of the code there (from calendar.template.php), but the code had the smf code calling up the date & year instead of letting the php-block code do the work... your code was exactly what i needed, except i had to remove the 'http://' part (it was redundant and tried to connect to "http://http://.......")...

all is good now!

(thank you)

Title: Re: Calendar in a php-block
Post by: dannbass on September 20, 2007, 05:32:58 PM
Now I have a question... what should you need to add if you want to add the events that happen today bold?

In looking at the boardindex.template and this looks like the code...

$event['is_today'] ? '<b>' . $event['title'] . '</b>

but I'm php challenged...

the code that I'm using is, or the part for that matter is...

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Audiciones y Eventos</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}


Thanks a lot!
Title: Re: Calendar in a php-block
Post by: jacortina on September 20, 2007, 06:21:03 PM
Try this.

In that Events Section of the code, Find:
        echo $event['link'] ;

And replace it with:
        if ((date('Y',$now).date('m',$now).date('d',$now)) >= (date('Y',$startdate).date('m',$startdate).date('d',$startdate)))
        {
            echo '<b>',$event['link'], '</b>';
        }
        else
        {
            echo $event['link'] ;
        }


That should bold events which start today or events that run multiple days and already started.
Title: Re: Calendar in a php-block
Post by: dannbass on September 20, 2007, 06:33:50 PM
Thanks a lot!!!!!!!!!!!!
Title: Re: Calendar in a php-block
Post by: dannbass on September 20, 2007, 08:27:12 PM
Now I thought of something else... long time ago here (http://www.tinyportal.net/index.php?topic=700.msg30584#msg30584)
Kail used this code... if I'm not mistaken,

foreach($events as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($event['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');

foreach($birthdays as $startdate => $value)
$days[substr($startdate,8)] = array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; background-color: '.(substr($startdate,8)<$today ? 'lightblue' : 'yellow').'; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($birth['start_date'],8).'" target="_self">'.substr($startdate,8).'</a>');


to add a highlight to the dates that have an event.

Again, I've been trying to add this to this
global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 2px 3px 2px 3px; font-size: xx-small; font-family: verdana, sans-serif;"  href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 3;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 1;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');                                      #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_month));
$month_nam = array();
$month_nam['01'] = 'Enero';
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[$month];

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span style=" font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span style=" font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th style=" font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 style="padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Audiciones y Eventos</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
       if ((date('Y',$now).date('m',$now).date('d',$now)) >= (date('Y',$startdate).date('m',$startdate).date('d',$startdate)))
        {
            echo '<b>',$event['link'], '</b>';
        }
        else
        {
            echo $event['link'] ;
        }
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Festividades</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


that is almost the perfect calendar block, at least IMHO.

Could you help me out again?
I'm very grateful!!!
Title: Re: Calendar in a php-block
Post by: ogmios on September 24, 2007, 04:05:26 PM
well, the 'post event' addition worked great, but it disappeared when the holiday that was showing (autumnal equinox) disappeared - the 'post event' button went with it...

i figured the 'post event' button disappeared because the coding for it was listed after the 'holiday' coding... i tried to list the 'post event' button coding after the 'event' coding, but it threw the button to the top of the block (lol)...

so as it is right now, the 'post event' button will only show up if a holiday displays (so i assume)...

any suggestions to have it appear all the time?

code:
global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table style="width:100%;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#06FE69;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';


/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_eventcolor'] . ';">EVENTS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

       $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

$cal_date = date("Y", $now) . date("m", $now) .date("d", $now);
        $evt_date = date("Y", $startdate) . date("m", $startdate) .date("d", $startdate);

        if($cal_date > $evt_date)
            $startdate = $now;

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '">' . date("M j",$startdate) . '</a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}


/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_holidaycolor'] . ';">HOLIDAYS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }


//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br>', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
echo '</td></tr>';
}
echo '</table>';
Title: Re: Calendar in a php-block
Post by: jacortina on September 24, 2007, 04:10:33 PM
Try changing:

//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br>', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
echo '</td></tr>';
}
echo '</table>';


To:
}
//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br>', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
echo '</td></tr>';

echo '</table>';
Title: Re: Calendar in a php-block
Post by: ogmios on September 24, 2007, 04:52:24 PM
QuoteTry changing:
Code:

//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','
', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
echo '</td></tr>';
}
echo '</table>';


To:
Code:

}
//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','
', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
echo '</td></tr>';

echo '</table>';


that threw the button to the top of the block...



Title: Re: Calendar in a php-block
Post by: jacortina on September 24, 2007, 05:19:32 PM
Sorry. didn't note that it was within the table cell and row for the Holidays.

So, replace everything from the 'Holiday Section' Comments down:
/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_holidaycolor'] . ';">HOLIDAYS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }


//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br>', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
echo '</td></tr>';
}
echo '</table>';


With:
/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_holidaycolor'] . ';">HOLIDAYS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
echo '</td></tr>';
    }
}


//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
echo '<tr><td>';
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br>', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
echo '</td></tr>';
echo '</table>';
Title: Re: Calendar in a php-block
Post by: ogmios on September 24, 2007, 05:33:01 PM
well that did something funky (image attached)...
Title: Re: Calendar in a php-block
Post by: jacortina on September 24, 2007, 06:15:01 PM
Brackets and columns and unclosed div. Arrrrrgggghhhh!!!!

Use this block (replace what you have):
global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table style="width:100%;">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#06FE69;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';


/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_eventcolor'] . ';">EVENTS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

       $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

$cal_date = date("Y", $now) . date("m", $now) .date("d", $now);
        $evt_date = date("Y", $startdate) . date("m", $startdate) .date("d", $startdate);

        if($cal_date > $evt_date)
            $startdate = $now;

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '">' . date("M j",$startdate) . '</a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}


/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #ffffff' . $modSettings['cal_holidaycolor'] . ';">HOLIDAYS</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="left">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
echo '</td></tr>';
}


//////////////////////////////////////////////////////////////////
// SHOW CALENDAR BUTTON.
echo '<tr><td colspan="7">';
     echo '<div align="center">';
     echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br>', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
     echo '</div>';
echo '</td></tr>';
echo '</table>';
Title: Re: Calendar in a php-block
Post by: ogmios on September 24, 2007, 06:18:32 PM
 O0   like, coooooooooool man... (it's all good)

thanks!

Title: Re: Calendar in a php-block
Post by: dannbass on September 24, 2007, 10:25:03 PM
Sorry to bump... but could you help me to include the code I was talking about here http://www.tinyportal.net/index.php?topic=700.msg154189#msg154189 (http://www.tinyportal.net/index.php?topic=700.msg154189#msg154189)

Thanks!!!!!
Title: Re: Calendar in a php-block
Post by: jacortina on September 26, 2007, 01:06:55 AM
Quote from: dannbass on September 24, 2007, 10:25:03 PM
Sorry to bump... but could you help me to include the code I was talking about here http://www.tinyportal.net/index.php?topic=700.msg154189#msg154189 (http://www.tinyportal.net/index.php?topic=700.msg154189#msg154189)

Thanks!!!!!

Looking at it and working on it.

Actually looking at pulling a few of the tweaks together into a unified block.

But it'll probably be a couple of days.
Title: Re: Calendar in a php-block
Post by: dannbass on September 26, 2007, 01:09:09 AM
 ;D Thank you!!! We'll have a terrific calendar then!!!
Title: Re: Calendar in a php-block
Post by: Lotti on September 26, 2007, 10:43:19 AM
well i tried this script and it rocks! just few questions: why the month is in my forum language in calendar and in events section is in english (sep for september)?

plus saturday&sunday are highligthed in green that is not so good with the standard theme :)

thanks
Title: Re: Calendar in a php-block
Post by: Lotti on September 30, 2007, 01:48:31 PM
i can't put my calendar block to italian language.. someone can help?
Title: Re: Calendar in a php-block
Post by: dannbass on September 30, 2007, 07:54:41 PM
Just change this part to your language.

$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');                                      #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_month));
$month_nam = array();
$month_nam['01'] = 'Enero';
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[$month];


And for the color...

if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }


Change this part to the color that you want.

Hope it helps!
Title: Re: Calendar in a php-block
Post by: Lotti on September 30, 2007, 08:13:24 PM
thanks danbass. but why set_locale(), doesn't work??
Title: Re: Calendar in a php-block
Post by: dannbass on September 30, 2007, 08:35:52 PM
I'm not sure about it, I just change the $day_names and the $month_nam = array(); and it did the trick, my php is not that good... but I just follow instructions, I read them somewhere in this long thread, somebody asking for a german translation.

Sorry I can't be more helpful.
Title: Re: Calendar in a php-block
Post by: Lotti on September 30, 2007, 08:38:54 PM
yeah, you're right infact i'll do what you posted above, but the script says that is "locale" compatible and infact it uses the right functions to use "locale". i tried to set_locale(LC_TIME,'it_IT') on local and online server, with no result :\
Title: Re: Calendar in a php-block
Post by: dannbass on September 30, 2007, 08:46:37 PM
Ahh I see... sure I should work... but if everything fails... that could be a shortcut.

Anyway, I'm glad it worked!
Title: Re: Calendar in a php-block
Post by: jacortina on October 05, 2007, 03:03:58 AM
OK. Here it is. The latest iteration of my version of the Calendar block.

Plenty of comments in the code and notes about use, but here's a summary.

Numerous options selectable by parameters including:

Highlighting does NOT highlight past days, only days going forward.

Additionally, there's an example section, currently commented out, to show
how to use Non-English Labels, Month and Day names in place.

Also modified to avoid all SQL queries in the block itself (and optimized
usage of SMF functions likely to perform queries).

I've done what testing I can, but no board I admin makes much use of events,
so apart from a couple of dummy entries for the purpose of testing, that part
of the code isn't as well 'shaken down'.

CODE REMOVED - OBSOLETE VERSION

Latest Code at: http://www.tinyportal.net/index.php?topic=700.msg157042#msg157042
Title: Re: Calendar in a php-block
Post by: Rus on October 05, 2007, 05:22:04 AM
Looking great, just one comment

The holidays section is in reverse order.

Other than thanks a lot for some great code.  :)
Title: Re: Calendar in a php-block
Post by: jacortina on October 05, 2007, 05:29:43 AM
Quote from: Rus on October 05, 2007, 05:22:04 AM
Looking great, just one comment

The holidays section is in reverse order.

Other than thanks a lot for some great code.  :)

Interesting.

Holidays are definitely in correct order on the boards I've tested on.

Currently showing:

   Holidays   
Oct 24 - United Nations Day
Oct 31 - Halloween
Title: Re: Calendar in a php-block
Post by: Rus on October 05, 2007, 05:31:00 AM
How odd, its exactly reversed for me
Title: Re: Calendar in a php-block
Post by: jacortina on October 05, 2007, 05:39:09 AM
I'll look into it and see what can be put in place to insure the order.
Title: Re: Calendar in a php-block
Post by: Rus on October 05, 2007, 05:48:25 AM
Thanks, here is my default time format if that helps:

%B %d, %Y, %I:%M:%S %p
Title: Re: Calendar in a php-block
Post by: jacortina on October 05, 2007, 04:25:14 PM
OK. Put in an attempted fix for this indeterminate ordering.

Edited the code in:
http://www.tinyportal.net/index.php?topic=700.msg156369#msg156369
Title: Re: Calendar in a php-block
Post by: dannbass on October 05, 2007, 04:51:01 PM
Thank you so much!!!
I really appreciate all the work that you put here!! I have no words to thank you enough!!!!
Title: Re: Calendar in a php-block
Post by: dannbass on October 05, 2007, 06:58:40 PM
I have a comment and a question... :-\

The comment is that the months, when change the language doesn't work unless you cut the list and put it after this line:
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));

Before that it was messed up, the days didn't align and the month's name didn't appear next to the 2007.

And the question is...
With the previous version I was able to add class="windowbg" so it look more like me theme... is it possible to add classes to this one? specially for the highlighted events and the event listing... I'm sort of php challenged.

Thanks a lot, and if it is not possible I'm still more than happy with the new version!!

Here is how it looked before.
Title: Re: Calendar in a php-block
Post by: jacortina on October 05, 2007, 07:14:54 PM
No, you shouldn't have to do any cutting and pasting like that.

You DO need to remove (or 'neutralize') the comment block lines which surround the non-english langauge area. Everything that appears between the line that starts with "/*******" and the on that ends with "*******/" will be treated as a comment unless you do so. From the internal comments in the code:

Quote// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/')

The line that you give above will NEVER be executed if you remove those '*****' lines (or simply prefix both of them with a "//  ") as that will set the array value which will make it fail the 'if' clause that contains that line.

Coding to allow a 'class' specification for any of the things I'm already building 'style' specifiers for shouldn't present too big of a problem. I'll work on it.
Title: Re: Calendar in a php-block
Post by: dannbass on October 05, 2007, 07:19:14 PM

Quote from: J.A.Cortina on October 05, 2007, 07:14:54 PM
You DO need to remove (or 'neutralize') the comment block lines which surround the non-english langauge area. Everything that appears between the line that starts with "/*******" and the on that ends with "*******/" will be treated as a comment unless you do so. From the internal comments in the code:

It didn't work both times... I removed the lines and everything and didn't worked

Quote from: J.A.Cortina on October 05, 2007, 07:14:54 PM
(or simply prefix both of them with a "//  ") as that will set the array value which will make it fail the 'if' clause that contains that line.

I did that and that was what make the language work. Also had to move the names of the days...

Quote from: J.A.Cortina on October 05, 2007, 07:14:54 PM
Coding to allow a 'class' specification for any of the things I'm already building 'style' specifiers for shouldn't present too big of a problem. I'll work on it.

Thanks a lot!! You are the greatest!!!
Title: Re: Calendar in a php-block
Post by: jacortina on October 05, 2007, 07:34:18 PM
OK. Tracked down the glitch.

Updated the code in the post (back a page).

Please try it now and see if it works as advertised.
Title: Re: Calendar in a php-block
Post by: dannbass on October 05, 2007, 07:41:41 PM
The month came up!!
But the days are messed up

I put the $first_day = 1;
as 1
And removed the '/********...*******/' and it looks like this...
Thanks a lot!!
Title: Re: Calendar in a php-block
Post by: Rus on October 05, 2007, 08:22:21 PM
DOH!

I made a couple changes myself.  Would you be able to let me know what you changed?

I changed the alignment to left for the results of all the searches
Title: Re: Calendar in a php-block
Post by: Rus on October 05, 2007, 08:32:43 PM
Never mind, thanks for the great code.  This time I was able to remember which centers to change and didnt screw it up like I did the first time.  :)
Title: Re: Calendar in a php-block
Post by: Rus on October 10, 2007, 06:07:36 AM
Thanks again for such a great calendar block.  I have it in 3 forums I run now.

I would like to mention that today is the 9th and in Holidays I still have Canadian Thanksgiving which falls on the 8th this year showing up in the block.
Title: Re: Calendar in a php-block
Post by: jacortina on October 10, 2007, 01:42:23 PM
Quote from: Rus on October 10, 2007, 06:07:36 AM
Thanks again for such a great calendar block.  I have it in 3 forums I run now.

I would like to mention that today is the 9th and in Holidays I still have Canadian Thanksgiving which falls on the 8th this year showing up in the block.

Yep. I see that the computation for lowdate for highlighting (the processing for which I made use of to eliminate redundant SQL call) actually went back one day from current forum date. Fixed this in latest code in post to follow.
Title: Re: Calendar in a php-block
Post by: Rus on October 10, 2007, 04:11:44 PM
Thanks
Title: Re: Calendar in a php-block
Post by: jacortina on October 10, 2007, 04:36:51 PM
One more time.

Tracked down dannbass' problem with days when using the Non-Enblish.
Added an alignment parameter for the list entries (hope that helps, Rus).

Biggest enhancement was to allow specification of class to use for just about every element/element type

And again:

Plenty of comments in the code and notes about use, but here's a summary.

Numerous options selectable by parameters including:

Latest:


Highlighting does NOT highlight past days, only days going forward.

Additionally, there's an example section, currently commented out, to show
how to use Non-English Labels, Month and Day names in place.

Also modified to avoid all SQL queries in the block itself (and optimized
usage of SMF functions likely to perform queries).

I've done what testing I can, but no board I admin makes much use of events,
so apart from a couple of dummy entries for the purpose of testing, that part
of the code isn't as well 'shaken down'.

Go to it, guys. Find the bugs and I'll fix them.


/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays = '-------  Birthdays  -------';
$list_label_events = '----------  Events  ----------';
$list_label_hdays = '-------  Holidays  -------';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

// --------------------------------------

if (!isset($class_default)) $class_default = 'smalltext';
if ($class_default == '') $class_default = 'smalltext';

smf_loadCalendarInfo();

//$today = date('j',$now);
$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);

$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$bdays = calendarBirthdayArray($low_date, $high_date);
ksort($bdays);
$events = calendarEventArray($low_date, $high_date, false);
ksort($events);
$holidays = calendarHolidayArray($low_date, $high_date);
ksort($holidays);

$todays_color = '';
if (isset($color_today)) $todays_color = 'color:'.$color_today.'; ';
$todays_bkgrd = '';
if (isset($bkgrd_today)) $todays_bkgrd = 'background-color: '.$bkgrd_today.'; ';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {

        if (!empty($context['calendar_birthdays']))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr><tr><td colspan="7" class="smalltext">';

            $dummy = array();
            foreach ($context['calendar_birthdays'] as $member)
                $dummy[] = $member['id'];

            loadMemberData($dummy);

            $ctr = 0;

            foreach ($context['calendar_birthdays'] as $member)
            {
                $class_to_use = '';
                if (isset($list_entry_class))
                    if (!is_array($list_entry_class)) {
                        $class_to_use = ' class="'.$list_entry_class.'"';
                    }
                    else {
                        $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                    }
                $profile = &$user_profile[$member['id']];
                $birthdate = empty($profile['birthdate']) || $profile['birthdate'] === '0001-01-01' ? '0000-00-00' : (substr($profile['birthdate'], 0, 4) === '0004' ? '0000' . substr($profile['birthdate'], 4) : $profile['birthdate']);

                list ($uyear, $umonth, $uday) = explode('-', $birthdate);
                $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));

                echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                if (!isset($month_nam['12'])) {
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';}
                else {   
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate) . '</strong></a>';}
                echo ' - ';
                echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';

                if ((date('Y',$now).date('m',$now).date('d',$now)) == (date('Y',$birthdate).date('m',$birthdate).date('d',$birthdate)))
                    $member['name'] = '<b>'.$member['name'].'</b>';

                if (!empty($profile['member_group_color'])) {
                    echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';}
                else {
                    echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');}
                echo '</a>';
                echo '</div>';
            }
        echo '</td></tr>';
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($context['calendar_events']))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr><tr><td colspan="7" class="smalltext">';

            $ctr = 0;

            foreach ($context['calendar_events'] as $event)
            {
                $class_to_use = '';
                if (isset($list_entry_class))
                    if (!is_array($list_entry_class)) {
                        $class_to_use = ' class="'.$list_entry_class.'"';
                    }
                    else {
                        $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                    }
                $startdate = strtotime($event['start_date']);

                $cal_date = date("Y", $now) . date("m", $now) .date("d", $now);
                $evt_date = date("Y", $startdate) . date("m", $startdate) .date("d", $startdate);
                if($cal_date > $evt_date)
                    $startdate = $now;

                echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                if (!isset($month_nam['12'])) {
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';}
                else {   
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . substr($month_nam[strftime('%m', $startdate)],0,3) . date(" j",$startdate) . '</strong></a>';}
                echo ' - ';
                if ((date('Y',$now).date('m',$now).date('d',$now)) >= (date('Y',$startdate).date('m',$startdate).date('d',$startdate))) {
                    echo '<b>',$event['link'], '</b>';}
                else {
                    echo $event['link'] ;}
                echo '</div>';
            }
            echo '</td></tr>';
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr><tr><td colspan="7" class="smalltext">';

            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {
                $eventdate = strtotime(date("Y").substr($hDate, 4));

                foreach ($hday as $holiday)
                {
                    $class_to_use = '';
                    if (isset($list_entry_class))
                       if (!is_array($list_entry_class)) {
                            $class_to_use = ' class="'.$list_entry_class.'"';
                        }
                        else {
                            $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                        }
                    echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                    if (!isset($month_nam['12'])) {
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';}
                    else {   
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate) . '</strong></a>';}
                    echo ' - ';
                    echo $holiday;
                    echo '</div>';
                }
            }
            echo '</td></tr>';
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: Rus on October 10, 2007, 04:54:14 PM
I dont know if it was in there before and you just added the alignment thing now because I mentioned it but if you did, thanks for listening.  That is a marvelous feature.  :)
Title: Re: Calendar in a php-block
Post by: jacortina on October 10, 2007, 05:08:24 PM
Quote from: Rus on October 10, 2007, 04:54:14 PM
I dont know if it was in there before and you just added the alignment thing now because I mentioned it but if you did, thanks for listening.  That is a marvelous feature.  :)

No problem. ;)

Fairly easy to add (considering I was tweaking all the places it was used anyway).

And going forward, when providing support for the block, the more people that can use it AS-IS (changing only some variable values rather than the code further down), the easier it'll be on me.  ;D
Title: Re: Calendar in a php-block
Post by: dannbass on October 10, 2007, 05:15:34 PM
THANK YOU!!!!!!!

The language bug is gone, it works perfect!!!! I don't know what to tell you, only that I'm the most grateful and happy TP user ever!!! you are my heroe!!!!

If I have a silly question about the looks I'll ask, and when I have it done I'll post a picture.

Thank you very much!!!
Title: Re: Calendar in a php-block
Post by: dannbass on October 10, 2007, 06:40:35 PM
Ok, I have one question... I included in the <table> a class="bordercolor" just to have the boxes with a division line, but it didn't apply to the listing in the birthdays, events and holidays.  Is there a way to include them in the table so they will have the bordercolor line as well?

Here is how it looks now, which is terrific BTW!!

Thanks a lot again!
Title: Re: Calendar in a php-block
Post by: jacortina on October 11, 2007, 12:32:23 AM
Quote from: dannbass on October 10, 2007, 06:40:35 PMOk, I have one question... I included in the <table> a class="bordercolor" just to have the boxes with a division line, but it didn't apply to the listing in the birthdays, events and holidays.  Is there a way to include them in the table so they will have the bordercolor line as well?

The 'bordercolor' class is actually just a background color (doesn't really specify anything about borders). It works by 'showing through' the spacing between elements. When used in a table, it's what shows between cells in the table.

But...

The code I posted uses a 'stack' of < div >s within a single cell for each of the lists. Therefore, no lines in the listings.

So...

I redid the code with those as individuals cells in their own rows.

AND, I made it an option to use bordercolor as the background (gridlines).

AND allowed specification of line thickness (in pixels). If not using the bordervolor for gridlines, "cellspacing" will be set to '0' (zero).

Look for:
// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 1;       // ONLY when $bordercolor_gridlines = true; Pixel thickness for table "cellspacing"


/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 1;       // ONLY when $bordercolor_gridlines = true; Pixel thickness for table "cellspacing"

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays = '-------  Birthdays  -------';
$list_label_events = '----------  Events  ----------';
$list_label_hdays = '-------  Holidays  -------';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

// --------------------------------------

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="0"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

smf_loadCalendarInfo();

//$today = date('j',$now);
$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);

$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$bdays = calendarBirthdayArray($low_date, $high_date);
ksort($bdays);
$events = calendarEventArray($low_date, $high_date, false);
ksort($events);
$holidays = calendarHolidayArray($low_date, $high_date);
ksort($holidays);

$todays_color = '';
if (isset($color_today)) $todays_color = 'color:'.$color_today.'; ';
$todays_bkgrd = '';
if (isset($bkgrd_today)) $todays_bkgrd = 'background-color: '.$bkgrd_today.'; ';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {

        if (!empty($context['calendar_birthdays']))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
//            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr><tr><td colspan="7" class="smalltext">';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';

            $dummy = array();
            foreach ($context['calendar_birthdays'] as $member)
                $dummy[] = $member['id'];

            loadMemberData($dummy);

            $ctr = 0;

            foreach ($context['calendar_birthdays'] as $member)
            {
                $class_to_use = '';
                if (isset($list_entry_class))
                    if (!is_array($list_entry_class)) {
                        $class_to_use = ' class="'.$list_entry_class.'"';
                    }
                    else {
                        $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                    }
                $profile = &$user_profile[$member['id']];
                $birthdate = empty($profile['birthdate']) || $profile['birthdate'] === '0001-01-01' ? '0000-00-00' : (substr($profile['birthdate'], 0, 4) === '0004' ? '0000' . substr($profile['birthdate'], 4) : $profile['birthdate']);

                list ($uyear, $umonth, $uday) = explode('-', $birthdate);
                $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));

//                echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';

                if (!isset($month_nam['12'])) {
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';}
                else {   
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate) . '</strong></a>';}
                echo ' - ';
                echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';

                if ((date('Y',$now).date('m',$now).date('d',$now)) == (date('Y',$birthdate).date('m',$birthdate).date('d',$birthdate)))
                    $member['name'] = '<b>'.$member['name'].'</b>';

                if (!empty($profile['member_group_color'])) {
                    echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';}
                else {
                    echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');}
                echo '</a>';

                echo '</td></tr>';
//                echo '</div>';
            }
//        echo '</td></tr>';
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($context['calendar_events']))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
//            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr><tr><td colspan="7" class="smalltext">';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';

            $ctr = 0;

            foreach ($context['calendar_events'] as $event)
            {
                $class_to_use = '';
                if (isset($list_entry_class))
                    if (!is_array($list_entry_class)) {
                        $class_to_use = ' class="'.$list_entry_class.'"';
                    }
                    else {
                        $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                    }
                $startdate = strtotime($event['start_date']);

                $cal_date = date("Y", $now) . date("m", $now) .date("d", $now);
                $evt_date = date("Y", $startdate) . date("m", $startdate) .date("d", $startdate);
                if($cal_date > $evt_date)
                    $startdate = $now;

//                echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';

                if (!isset($month_nam['12'])) {
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';}
                else {   
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . substr($month_nam[strftime('%m', $startdate)],0,3) . date(" j",$startdate) . '</strong></a>';}
                echo ' - ';
                if ((date('Y',$now).date('m',$now).date('d',$now)) >= (date('Y',$startdate).date('m',$startdate).date('d',$startdate))) {
                    echo '<b>',$event['link'], '</b>';}
                else {
                    echo $event['link'] ;}
//                echo '</div>';
                echo '</td></tr>';
            }
//            echo '</td></tr>';
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
//            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr><tr><td colspan="7" class="smalltext">';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';

            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {
                $eventdate = strtotime(date("Y").substr($hDate, 4));

                foreach ($hday as $holiday)
                {
                    $class_to_use = '';
                    if (isset($list_entry_class))
                       if (!is_array($list_entry_class)) {
                            $class_to_use = ' class="'.$list_entry_class.'"';
                        }
                        else {
                            $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                        }
//                    echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';

                    if (!isset($month_nam['12'])) {
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';}
                    else {   
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate) . '</strong></a>';}
                    echo ' - ';
                    echo $holiday;
                   
//                    echo '</div>';
                    echo '</td></tr>';
                }
            }
//            echo '</td></tr>';
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: dannbass on October 11, 2007, 01:55:34 AM
Quote from: J.A.Cortina on October 11, 2007, 12:32:23 AM
The 'bordercolor' class is actually just a background color (doesn't really specify anything about borders). It works by 'showing through' the spacing between elements. When used in a table, it's what shows between cells in the table.

The code I posted uses a 'stack' of < div >s within a single cell for each of the lists. Therefore, no lines in the listings.

See I thought that the 'bordercolor' was a border... now I understand why in the other calendar the "today" had a background of the bordercolor's color... I'm learning tons of things!!!

I saw the < div >s and thought about that, but could do much.

We usually have a lot of events coming up and now it looks really nice! Thanks a lot, I'm really grateful!!

Here is how it looks now!
Thank you very much!!!!!
Title: Re: Calendar in a php-block
Post by: stormlrd on October 11, 2007, 02:14:30 AM
JA can i share this at tpm? We've been playing with it over there too.
Title: Re: Calendar in a php-block
Post by: jacortina on October 11, 2007, 02:24:35 AM
Sure. Be my guest.
Title: Re: Calendar in a php-block
Post by: stormlrd on October 11, 2007, 02:30:28 AM
Quote from: J.A.Cortina on October 11, 2007, 02:24:35 AM
Sure. Be my guest.

thanks alot
http://www.tinyportalmedia.com/main/index.php/topic,1214.msg7643/topicseen.html#new
Title: Re: Calendar in a php-block
Post by: hebxi1 on October 18, 2007, 04:58:28 AM
I just wanna say ... wow.  Thanks for all the hard work that went into this.  I am looking forward to a download section for official blocks so that us poor new saps don't have to wade thru 40 pages of posts to know what to look for, but the beauty of this little block was worth the swimming.  A couple of small personal tweaks on formatting and I'm very happy :)
Title: Re: Calendar in a php-block
Post by: Rockferd on October 20, 2007, 08:02:21 AM
I recently installed this and love it.  I have one question though.  I want all the events for the month to appear even after the day is passed.  I attempted this myself, but ended up listing all the holidays for the year.  Any advice would be great.
Title: Re: Calendar in a php-block
Post by: jacortina on October 20, 2007, 06:36:49 PM
'Events'? Or birthdays, events, holidays? And do you want the highlighting available for past events?

It would definitely require coding changes as this block works off of calendar entries which are supplied by the function to list 'Upcoming' (from today's date and days going forward the number of days supplied in the Admin Control Panel). Only the holidays are supplied slightly differently (as can be seen by the effect of your change attempt).
Title: Re: Calendar in a php-block
Post by: Rockferd on October 20, 2007, 06:51:54 PM
I definitely want events for the whole month listed.  If it would be easier to have events holidays, birthdays, and events, then that's perfectly fine too.

EDIT: I think I just found a bug(Or I need to edit a setting I havn't found).  When the block is enabled and I view a topic that is linked to an event, no matter what the calendar settings are the "Linked events" box is displayed above the topic.  If I disable the block, my setting for that not to show takes effect.
Title: Re: Calendar in a php-block
Post by: jacortina on October 30, 2007, 01:25:29 AM
Quote from: Rockferd on October 20, 2007, 06:51:54 PM
EDIT: I think I just found a bug(Or I need to edit a setting I havn't found).  When the block is enabled and I view a topic that is linked to an event, no matter what the calendar settings are the "Linked events" box is displayed above the topic.  If I disable the block, my setting for that not to show takes effect.

This has come up before. Of course, it was WAAAAAYYYY back on page 23 of this thread: http://www.tinyportal.net/index.php?topic=700.msg76885#msg76885
Title: Re: Calendar in a php-block
Post by: jacortina on October 30, 2007, 01:29:21 AM
OK. Some more optimizations. And the addition of 'look-behinds' the ability to show calendar entries which have already passed:

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;


Additionally, multi-day events are now shown in the Events listing in a more conventional way (Oct 29-30 or Oct 30-Nov 2).



/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Set to true to only show b-day, event, holiday list entries - no calendar 'grid'
$entry_list_only = false;

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '_______ Events _______';
$list_label_hdays =  '______ Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now);
$high_date_base = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - ($past_look_behind_period * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

echo '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption>';
$calendar = '';
// $calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

if(!$entry_list_only) {
    echo '<tr>',$calendar,'</tr>'; }

// echo '</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {
                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. (isset($member['color']) ? $member['color'] : '')  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }
            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {
                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }
            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }
            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';


Edit - Added fix listed a couple of posts down. Added Option to show ONLY the entry lists (no calendar grid).
Title: Re: Calendar in a php-block
Post by: Rus on October 30, 2007, 03:40:07 PM
Thanks!  Just installed the update on all 3 of mine.
Title: Re: Calendar in a php-block
Post by: Rus on October 30, 2007, 03:50:34 PM
Uh oh, now I get this error 4 times in the log per page hit with the minical:

8: Undefined index: color
File: /home/bcclique/public_html/forum/Themes/default/Recent.template.php (eval?)
Line: 463
Title: Re: Calendar in a php-block
Post by: jacortina on October 30, 2007, 05:09:25 PM
Only because you have 4 users showing on the birthday list, right?

Replace this chunk (better than having to re-enter your settings).

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {
                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. (isset($member['color']) ? $member['color'] : '')  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }
            }
        }
    }
}

Title: Re: Calendar in a php-block
Post by: Rus on October 30, 2007, 05:25:13 PM
Awesome, thanks for the quick reply.

Yes, I had 4 with a bday coming up, probly why it didnt happen in the other 2 forums then, I thought it might have been theme related.
Title: Re: Calendar in a php-block
Post by: Rockferd on October 30, 2007, 07:02:08 PM
Thank you soo much!  That was exactly what I needed.  Thanks for the link to fix that bug too.  Very appreciated!
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 09:36:49 PM
When using the code found here:
http://www.tinyportal.net/index.php?topic=700.msg157121#msg157121

It lists all my events except those on Sundays???

Tim
Title: Re: Calendar in a php-block
Post by: jacortina on October 31, 2007, 09:49:27 PM
I just re-loaded that code in a block and entered a test event for Nov 4. It shows in the list of events.
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 09:56:22 PM
Did the same here, problem persists. Maybe a SMF setting?
Title: Re: Calendar in a php-block
Post by: jacortina on October 31, 2007, 10:08:07 PM
Well, to check on that, you could try some troubleshooting.

If you make a new phpblock for testing, copy the code to it, and remove all the groups permissions, only you (as Admin) will see it.

Find:
smf_loadCalendarInfo();

And insert these lines just after it:
print ( '<pre>' )  ;
print_r($context['calendar_events']);
print ( '</pre>' )  ;


That will print out the contents of the events (sub)array of the $context array (you really don't ever want to print out the entire $context array) which is loaded by the "smf_loadCalendarInfo()". It'll make the block pretty ugly, which is why you only want it to show to yourself.
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 10:11:19 PM
Same problem here, is showing everything for the 2nd, and 7th but not the 4th
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 10:11:42 PM
is the problem that o am using an article and not a block?
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 10:13:21 PM
solved! i dont know why but when i added a new event on the 4th it listed. but not showing the vents already posted. easy enough i will delete them and start over.
Title: Re: Calendar in a php-block
Post by: jacortina on October 31, 2007, 10:14:48 PM
Are you saying that the array print itself isn't showing the entry information for the 4th?

New ones are showing now?

Are you using a mod for 'repeating events'?
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 10:18:51 PM
Ok, not solved. I put in a test event and it listed. When I deleted the events and reposted them, no luck.

1. The array print is not showing the 4th.
2. New ones are not showing in array other then the "test", even after deleting and reposting.
3. I am using a repeating event mod, but the events are not set to repeat.

Title: Re: Calendar in a php-block
Post by: jacortina on October 31, 2007, 10:25:55 PM
Well, let's try something else.

Get rid of those three lines to print the $context sub-array and find:
ksort($events);

Then print out THAT array:
print ( '<pre>' )  ;
print_r($events);
print ( '</pre>' )  ;


That gets the event list from a different function (and in the latest code, I've done away with the mf_loadCalendarInfo() call altogether; but let's see if that's going to help).
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 10:27:44 PM
lol...nothing listed
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 10:41:16 PM
OK Well i have found a work around.

When I title the event as the original post was titled, it does not list.
If i title it different it does.

example:
original = ZONE A HOST - DFOG (no luck)
now: ZONE A HOST DFOG (good to go)

this is weird but I can live with it...lol
Title: Re: Calendar in a php-block
Post by: jacortina on October 31, 2007, 10:47:42 PM
Quite weird. I was about to have you go in and simply browse your smf_Calendar table as that second function should pull everything in the given date range, whether or not you've selected to display the events on the calendar via Admin settings.

It still 'may' have something to do with the repeating mod if it uses its own storage of events in some way (even if they don't repeat).

And why this all was Sunday stuff first and then...

Color me confused.
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 11:18:54 PM
now that i think about it, my site has been getting database disconnect messages for a bit here. this could have something to do with it. I am working on it with my host.
Title: Re: Calendar in a php-block
Post by: jacortina on November 23, 2007, 04:39:42 PM
Updated lst full code post at -
http://www.tinyportal.net/index.php?topic=700.msg160852#msg160852

- Fix for Member name colors not found.
- Add option to show entry lists ONLY (suppress day 'grid').
Title: Re: Calendar in a php-block
Post by: MinasC on November 24, 2007, 11:27:38 AM
that is a great block mate , thnx a lot for that !

one problem though : it doesn't show my language correctly (greek) as if not utf8 ! the strange thing is that it shows perfect the list labels in greek but not the months and days labels !

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Set to true to only show b-day, event, holiday list entries - no calendar 'grid'
$entry_list_only = false;

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Holidays', 'Events');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Holidays', 'Events');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = true; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = false;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = true;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = true; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = '';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = '';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Î"ενέθλια ______';
$list_label_events = '_____ ΕκδηλώσειÏ, _____';
$list_label_hdays =  '_______ Î"ιορÏ,,έÏ, _______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = true;
$show_events_past = true;
$show_hdays_past = true;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//


$list_label_bdays = '______ Î"ενέθλια ______';  // Change to labels in language of choice
$list_label_events = '_____ ΕκδηλώσειÏ, _____';
$list_label_hdays =  '_______ Î"ιορÏ,,έÏ, _______';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Î"εÏ...Ï,,έρα','ΤρίÏ,,η','ΤεÏ,,άρÏ,,η','ΠέμπÏ,,η','ΠαρασκεÏ...ή','ΣάββαÏ,,ο','ΚÏ...ριακή');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'ΙανοÏ...άριοÏ,';       
$month_nam['02'] = 'ΦεβροÏ...άριοÏ,';
$month_nam['03'] = 'ΜάρÏ,,ιοÏ,';
$month_nam['04'] = 'Î'πρίλιοÏ,';
$month_nam['05'] = 'ΜάιοÏ,';
$month_nam['06'] = 'ΙούνιοÏ,';
$month_nam['07'] = 'ΙούλιοÏ,';
$month_nam['08'] = 'Î'ύγοÏ...σÏ,,οÏ,';
$month_nam['09'] = 'ΣεπÏ,,έμβριοÏ,';
$month_nam['10'] = 'ΟκÏ,,ώβριοÏ,';
$month_nam['11'] = 'ΝοέμβριοÏ,';
$month_nam['12'] = 'Î"εκέμβριοÏ,';
$month_name = $month_nam[date('m',$now)];
//

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = '';
if ($class_default == '') $class_default = '';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now);
$high_date_base = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' :

strftime('%Y-%m-%d', $now - ($past_look_behind_period * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'"

target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.'

href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'"

target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.'

href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'"

target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.'

href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'"

target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

echo '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption>';
$calendar = '';
// $calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;"

abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size:

x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

if(!$entry_list_only) {
    echo '<tr>',$calendar,'</tr>'; }

// echo '</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' .

$list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {
                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) %

count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. (isset($member['color']) ?

$member['color'] : '')  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>'

: '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }
            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' .

$list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {
                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) %

count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) :

(!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }
            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' .

$list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) %

count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }
            }
        }
    }
}
}
// ', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '
if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="smalltext" align="center" valign="middle">';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">' . $txt['calendar23'] . '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';


any ideas why ?
thnx a lot !
Title: Re: Calendar in a php-block
Post by: jacortina on November 24, 2007, 09:11:22 PM
Interesting.

There appears to be a couple of different issues here.

First off is the php function "htmlentities". The conversion it performs (with no arguments) is not suitable for Greek (or any multi-byte character set). You could see what happens if you remove their use:

Find:
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names


Change To:
$title   = $month_name.' '.$year;


Find (about 12 lines elow the first change):
abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';

Change To:
abbr="'.$d.'">'.($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';


The second issue involves the substr function. It seems that when it grabs the first three characters of the month name you supply, it really only grabs one and one-half of the two-byte characters. That's why the initial (correct font) 'N' is appearing (that's the first two bytes) followed by a 'garbage' character.

You could do me a big favor by testing this. There are 4 (and only 4) occurences of the characters:
0,3)

Could you see what happens if you chenge them to:
0,6)

(Note that if this is so, your day name headings in the calendar 'grid' will be half as long as the length you've specified and you'll want to change "substr($d,0,$day_name_length)" to "substr($d,0,$day_name_length*2)" in that second line change up top.)
Title: Re: Calendar in a php-block
Post by: MinasC on November 25, 2007, 03:35:55 AM
i did all the things you said , plus i used capitals for the months and everything worked great as you can see ! all letters restored and months appear with 3 letters !

thnx a lot for the great support !
Title: Re: Calendar in a php-block
Post by: jacortina on November 25, 2007, 03:48:26 AM
Glad to hear it worked.

I'll have to see about having this handled on a parameter basis.
Title: Re: Calendar in a php-block
Post by: MinasC on November 25, 2007, 05:50:56 PM
would it be too much to ask for one more thing ?  :-\

in the events could it show the member who created the event ? it would also be great if instead of the whole event title there was a linitation of the characters  to show so that large event titles don't take 3-4 lines !

thnx in advance !
Title: Re: Calendar in a php-block
Post by: MinasC on December 01, 2007, 11:53:33 AM
something happened again that i cannot explain : while it was showing birthdays , events and holidays just fine until yesterday , now that the month has changed it doesn't show anything , not even xmas ! i didn't change anything , i don't get it !

once again here's my code :

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Set to true to only show b-day, event, holiday list entries - no calendar 'grid'
$entry_list_only = false;

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Holidays', 'Events');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Holidays', 'Events');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = true; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = false;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = true;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = true; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = '';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = '';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Î"ενέθλια ______';
$list_label_events = '_____ ΕκδηλώσειÏ, _____';
$list_label_hdays =  '_______ Î"ιορÏ,,έÏ, _______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = true;
$show_events_past = true;
$show_hdays_past = true;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//


$list_label_bdays = '______ Î"ενέθλια ______';  // Change to labels in language of choice
$list_label_events = '_____ ΕκδηλώσειÏ, _____';
$list_label_hdays =  '_______ Î"ιορÏ,,έÏ, _______';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Î"εÏ...Ï,,έρα','ΤρίÏ,,η','ΤεÏ,,άρÏ,,η','ΠεμπÏ,,η','ΠαρασκεÏ...ή','ΣαββαÏ,,ο','ΚÏ...ριακή');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'ΙÎ'ΝΟΥÎ'ΡΙΟΣ';       
$month_nam['02'] = 'ΦΕÎ'ΡΟΥÎ'ΡΙΟΣ';
$month_nam['03'] = 'ÎœÎ'ΡΤΙΟΣ';
$month_nam['04'] = 'Î'ΠΡΙΛΙΟΣ';
$month_nam['05'] = 'ÎœÎ'ΪΟΣ';
$month_nam['06'] = 'ΙΟΥΝΙΟΣ';
$month_nam['07'] = 'ΙΟΥΛΙΟΣ';
$month_nam['08'] = 'Î'Î¥Î"ΟΥΣΤΟΣ';
$month_nam['09'] = 'ΣΕΠΤΕΜÎ'ΡΙΟΣ';
$month_nam['10'] = 'ΟΚΤΩÎ'ΡΙΟΣ';
$month_nam['11'] = 'ΝΟΕΜÎ'ΡΙΟΣ';
$month_nam['12'] = 'Î"ΕΚΕΜÎ'ΡΙΟΣ';
$month_name = $month_nam[date('m',$now)];
//

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = '';
if ($class_default == '') $class_default = '';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now);
$high_date_base = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' :

strftime('%Y-%m-%d', $now - ($past_look_behind_period * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'"

target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.'

href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'"

target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.'

href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'"

target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.'

href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'"

target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = $month_name.' '.$year;   // note that some locales don't capitalize month and day names

echo '<table '.$table_bkgrd.' align="center">'.'<caption ><b>'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</b></caption>';
$calendar = '';
// $calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;"

abbr="'.$d.'">'.($day_name_length < 4 ? substr($d,0,$day_name_length*2) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size:

x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

if(!$entry_list_only) {
    echo '<tr>',$calendar,'</tr>'; }

// echo '</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' .

$list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {
                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) %

count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,6) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. (isset($member['color']) ?

$member['color'] : '')  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>'

: '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }
            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' .

$list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {
                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) %

count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,6) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) :

(!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,6) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }
            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' .

$list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) %

count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,6) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }
            }
        }
    }
}
}
// ', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '
if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="smalltext" align="center" valign="middle">';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">' . $txt['calendar23'] . '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';


thnx a lot !
Title: Re: Calendar in a php-block
Post by: Zetan on December 01, 2007, 12:07:15 PM
How many events, and how long in advance is the calendar set?
Title: Re: Calendar in a php-block
Post by: MinasC on December 01, 2007, 05:10:59 PM
uuuuhm , where do i find that ?
Title: Re: Calendar in a php-block
Post by: Zetan on December 01, 2007, 05:21:08 PM
Well, how many events posted to the forum calendar?

How many days in advance:

Admin > Forum/Calendar > Calendar Settings > Max days in advance on board index: [ ]


I know from experience that too many events pulled from the calendar, too many days in advance can and does cause no events to be displayed in the SSI Calendar, which is what this snippet uses.

I had mine set to 31 days in advance.. and after too many events.. Blam..


Took me over a week to figure it after posting at SMF for support, ripping my forum code apart and harrasing my host..


Simply reducing the days in advance to 14 days solved it instantly for me..
It may work for you too, and will save you pulling out all your hair for weeks  ;) 
Title: Re: Calendar in a php-block
Post by: MinasC on December 01, 2007, 05:26:56 PM
fool me , i had this set to 7 days , that's why it didn't show xmas , lol ! i don't have many events so 30 days in advance works fine ! i just want the months' events to show in that block !

thnx a lot !
Title: Re: Calendar in a php-block
Post by: MinasC on December 01, 2007, 05:27:55 PM
Quote from: MinasC on November 25, 2007, 05:50:56 PM
in the events could it show the member who created the event ? it would also be great if instead of the whole event title there was a linitation of the characters  to show so that large event titles don't take 3-4 lines !

thnx in advance !

what about that , is it possible ?
Title: Re: Calendar in a php-block
Post by: jacortina on December 01, 2007, 06:12:58 PM
Quote from: ZTN on December 01, 2007, 12:07:15 PM
How many events, and how long in advance is the calendar set?

No, actually, it doesn't. The snippet being used bypasses it and goes directly to the functions that the SSI would call.


Quote from: MinasC on November 25, 2007, 05:50:56 PM
would it be too much to ask for one more thing ?  :-\

in the events could it show the member who created the event ? it would also be great if instead of the whole event title there was a linitation of the characters  to show so that large event titles don't take 3-4 lines !

thnx in advance !

Limiting the output would should be trivial. Try this.

Find:
$link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

Add a line before it to make it:
$event['title'] = (strlen($event['title']) > 50) : substr($event['title'],0,50).'...' : $event['title'];
$link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';


I use 50 as a length here, but I believe that will only yield an output of 25 characters (for YOU as you are using multi-byte characters). You can tweak the value (in both of the two places in that new line) and see what you like.


At this point, pulling the User Name isn't as easy. While the function that gets events DOES get their MEMBER_ID, That list of ID's would have to be collected and the query for their names included.
Title: Re: Calendar in a php-block
Post by: Zetan on December 01, 2007, 06:23:27 PM
Quote from: J.A.Cortina on December 01, 2007, 06:12:58 PM
Quote from: ZTN on December 01, 2007, 12:07:15 PM
How many events, and how long in advance is the calendar set?

No, actually, it doesn't. The snippet being used bypasses it and goes directly to the functions that the SSI would call.


My error..
And reducing the Days In Advance resolved the problem I was having.
Title: Re: Calendar in a php-block
Post by: MinasC on December 02, 2007, 03:04:59 AM
Quote from: ZTN on December 01, 2007, 06:23:27 PM
My error..
And reducing the Days In Advance resolved the problem I was having.

strange , but it resolved mine too !  ???

J.A.Cortina thnx for the support , i will do the change asap ! pitty for the members' names though ! it would look better if it would show who created the event , but one can't have it all , right ?  :-\
Title: Re: Calendar in a php-block
Post by: MinasC on December 02, 2007, 11:29:58 AM
well , before i applied your alteration i tried to create an event with a large title and i found out there is already a restriction of (only a few unfortunately) letters ! so , the good thing is that my fear of members creating events with enormous titles has now no basis , while the bad thing is that i would like more letters to be allowed in the titles of the events (by not allowing posting of the events the only thing a member has to describe the event is the title , and just 20 letters are not enough) ! is there any way to increase that limit ?

not to be misunderstood , your alteration for limiting the letters of the events titles showing in the block is still a go (what is showing in the block and what is the actual event title are two very different things) ! i have to tell you though , with just a few events created by members , one cannot tell who created which (it's not showing the creator's name in the calendar either) and it's a total chaos ! any luck we could give that a try ?

thnx a lot for the support !
Title: Re: Calendar in a php-block
Post by: Rus on December 05, 2007, 11:43:33 PM
I have a user with a birthday in January and its showing before the December birthdays.  Not a big deal, just an aesthetic thing if you wanted to look into it.
Title: Re: Calendar in a php-block
Post by: Xarcell on December 07, 2007, 02:47:21 AM
What you put the member's ame who created in into a "title" of the link? This way you see it on mouseover...
Title: Re: Calendar in a php-block
Post by: jacortina on December 07, 2007, 03:26:06 AM
Quote from: Rus on December 05, 2007, 11:43:33 PM
I have a user with a birthday in January and its showing before the December birthdays.  Not a big deal, just an aesthetic thing if you wanted to look into it.

I believe this comes down to a flaw in the underlying SMF function (which is corrected somewhere upstream for their own list of b-days on the boardindex).

The function calendarBirthdayArray() in Calendar.php has the test:
if ($year_low != $year_high)
$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
else
$age_year = $year_low;


I 'think' they may play some games with the low_date and/or high_date values fed in, but just using the 'real values for those (corresponding to the range of days selected), that test means that the last day of a range that crosses the year boundary will always be assigned the EARLIER year (a birthday on that last date won't be LESS THAN the last date, after all). So, of course it sorts in front of the other birthdays. Holidays (New Years Day, for example) are treated the same. Events, though, have specific year values attached, so they aren't effected the same.

I'm looking into it and I'll try to get to a fix (before the end of the month, when it won't matter again until this time NEXT year ;) ).
Title: Re: Calendar in a php-block
Post by: Rus on December 07, 2007, 05:51:14 AM
Hehe, no worries, it seems to have fixed itself somehow.
Title: Re: Calendar in a php-block
Post by: jacortina on December 08, 2007, 04:07:40 AM
No. There just aren't any birthdays on the 'front edge' of the look-ahead. The next time there is, it'll end up sorted in front of the others. For a day.

I've verified that the SMF routines actually get extra days on either end of the range (one before the start and one after the end) and then filter them out. I'm testing a fix and should have it up in a day or two.
Title: Re: Calendar in a php-block
Post by: jacortina on December 12, 2007, 02:38:36 PM
OK. The code below fixes the sortin issue when crossing the year-end bondary.

Note that you the changes made were only to code below the text:
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)


So if you want to only replace that part (preserving your parameter settings), it's up to you:
/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '_______ Events _______';
$list_label_hdays =  '______ Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

//$low_date_base = strftime('%Y-%m-%d', $now);
//$high_date_base = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {
                if (($startdate >= strftime('%Y-%m-%d', $now)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $now)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $now)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: ninjamask on December 26, 2007, 09:10:01 AM
did you broke "$past_look_behind_period" with that last fix?

its not showing events/bdays/holidays prior to today after applying the fix.
Title: Re: Calendar in a php-block
Post by: michielonline on December 31, 2007, 10:26:17 AM
Is there a possibility to show for example 3 months or a whole year including events on the php article page with this block?

Great mod BTW :)
Title: Re: Calendar in a php-block
Post by: jacortina on January 09, 2008, 07:38:36 PM
Quote from: ninjamask on December 26, 2007, 09:10:01 AM
did you broke "$past_look_behind_period" with that last fix?

its not showing events/bdays/holidays prior to today after applying the fix.

Yes, I broke it. See below for a fixed block.

Quote from: michielonline on December 31, 2007, 10:26:17 AM
Is there a possibility to show for example 3 months or a whole year including events on the php article page with this block?

Great mod BTW :)
Not really, this is really just for a side block. There IS a calendar enhancement mod over on SMF to change the display of the normal calendar page to show smaller calendars for multiple months to the side of the full-sized current month calendar.

Here we go again:
/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '_______ Events _______';
$list_label_hdays =  '______ Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: G6Cad on January 10, 2008, 11:23:43 AM
I think you need your own board here for your codes JA. This thread is getting somewhat REALLY long and more or less impossible to keep up with. I dont know how you manage this, but you do a great job.
If you have any ideas on how to make the theads you hold better viewable , please give us a note  :)
Title: Re: Calendar in a php-block
Post by: barnic on January 11, 2008, 01:41:20 PM
the language of my language is "italian"
but the calendar'view is in english

why?
what can i do?

thanks
Title: Re: Calendar in a php-block
Post by: jacortina on January 11, 2008, 01:54:53 PM
The default language for your server is likely English if it shows that way.

There's a section for you to change to use other languages. Find the code below and make the changes as noted in the code itself (and make sure you remove the lines that it says to remove; the lines with all the asterisks, one that starts with '/***' and one that ends with '***/'):

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)
Title: Re: Calendar in a php-block
Post by: barnic on January 11, 2008, 02:46:51 PM
thankyou
i see the code after my previous message
and i've just modified it

thanks again
bye

Title: Confusing Error that I can't seem to figure out.
Post by: onicat on January 17, 2008, 10:13:29 PM
Quote8: unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 65524 of 65538 bytes

That is the error that I get.

Quoteglobal $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td>
</td><td colspan="5" class="smalltext" align="center">Birthdays</td><td>
</td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td>
</td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td>
</td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';

That is the Calendar Box Code I am using.

http://custom.simplemachines.org/mods/index.php?mod=655

That is the Repeating Calendar mod I am using with SMF and TP.

My website is www.akcommunity.com.

Ok thats I think all the important info upfront. Now for my question. hehe

If you go to the homepage and scroll down, on the left side will be the Calendar block. You will notice that it is not showing the events, just the calendar. But when you click the Calendar tab  up top and scroll down to that same spot. You will notice it is showing the events along with the calendar.

I have tried various calendar scripts...and end up with the same problem, even tried adjusting the amount of days in advance that it will show. I would like to keep it at least at 7 days. Cause as you can see my calendar is rather active. LOL.

Anyway. I am pretty sure that the error is linked to that script some how, cause when I dont use the repeating events, and that script, then I don't get the error...but I also dont get my calendar displayed on the front page.

Any one have any idea's as to how I could fix said problem?

Get the events to show on the front page were they should, and get rid of said error.
Title: Re: Calendar in a php-block
Post by: G6Cad on January 18, 2008, 10:26:17 AM
Please read our posting guide we have for the support forum, also the FAQ and doc section.
Make the proper changes to your first post if you still need help after you have read through what I ask.
Title: Re: Calendar in a php-block
Post by: taliesin on January 24, 2008, 11:36:47 PM
Great code block you've got here.  Tried it and it works perfectly on my site.  If you're wondering what this code block looks like and are hesitant to install without seeing it first, here it is on my site:

http://children.thedow.org (The block is on the right side, 2nd down.)

(Not an advertisement, since it's a site for my kin within a game.  lol.  Not looking for registrations.  Just an opportunity to see the code in action!)  :)
Title: Re: Calendar in a php-block
Post by: Zetan on January 24, 2008, 11:42:38 PM
I have one on my site too.. Not sure why the Th is lined up wrong  ???
Title: Re: Calendar in a php-block
Post by: darkorical on February 11, 2008, 07:15:21 PM
alright I'm not sure if I am confused about weather or not this is supposed to do something but if it is supposed to make the days that have events attached to them clickable links to display the event then mine is not working if it is not supposed to do that then just tell me Im confused and Ill start to beg for that option
Title: Re: Calendar in a php-block
Post by: lOOmis on February 28, 2008, 02:03:01 PM
Great code, been looking for this.....Everything tested out great. Thanks to those who made it possible.
Title: Re: Calendar in a php-block
Post by: iONic on February 28, 2008, 11:07:55 PM
I've been looking around for a Small block calendar that can link to the SMF calendar, or something even better if it exists. Does anyone have a suggestion?

Thanks
Title: Re: Calendar in a php-block
Post by: Ken. on February 28, 2008, 11:11:09 PM
Take a look in the Block Code Snippets Index iONic, you'll find some there.
Title: Re: Calendar in a php-block
Post by: TimUSA on February 29, 2008, 07:08:42 PM
ummm read this thread? the code in here already does what your looking for.
Title: Re: Calendar in a php-block
Post by: iONic on February 29, 2008, 08:16:22 PM
I have downloaded some of the code. So much of the code has one flaw or another, this feature or that and within the 46 pages of posts it is quite overwhelming.  There is a need for a good repository of working code with ample feature explanations.

I am trying many of the codes out and will no doubt find something that is not error prone and suites my needs, but like I said, the process is overwhelming.

Title: Re: Calendar in a php-block
Post by: IchBin on February 29, 2008, 08:42:57 PM
We have plans to change this iONic. Hopefully some sort of package management for Block codes. This way, if anything is changed another package can be made. Download and install would be nice for some block codes.
Title: Re: Calendar in a php-block
Post by: onicat on February 29, 2008, 09:13:15 PM
Cool Thanks for the info. Looks like I am going to have to tough it out for a while longer. Cause I still can't get that error code and display issue to go away. LOL. I have tried various codes as well...
Title: Re: Calendar in a php-block
Post by: TimUSA on February 29, 2008, 09:40:48 PM
Ionic: try this....really the best of the bunch in this thread
http://www.tinyportal.net/index.php?topic=700.msg173249#msg173249
Title: Re: Calendar in a php-block
Post by: onicat on February 29, 2008, 09:50:15 PM
Weird. That one seems to work fine. But now I get a new error. LOL.

8: Undefined index: color
File: /media/mccforum/public_html/Themes/default/TPortal.template.php (main_above sub template - eval?)
Line: 468
Title: Re: Calendar in a php-block
Post by: iONic on February 29, 2008, 11:05:42 PM
Quote from: IchBinâ,,¢ on February 29, 2008, 08:42:57 PM
We have plans to change this iONic. Hopefully some sort of package management for Block codes. This way, if anything is changed another package can be made. Download and install would be nice for some block codes.

Thanks for the promise of a better future here!

Quote from: TimUSAIonic: try this....really the best of the bunch in this thread
http://www.tinyportal.net/index.php?topic=700.msg173249#msg173249

Seems to work nicely, thanks!



Title: Re: Calendar in a php-block
Post by: lOOmis on March 04, 2008, 10:45:16 PM
Does anyone know how to change the width of the calender, number size, text size in order to fill the width of my TP column. I've searched and think I may know but before jumping in I thought I would ask.

Thanks
lOOmis
Title: Re: Calendar in a php-block
Post by: IchBin on March 05, 2008, 03:21:00 PM
It usually teaches you more if you try what you think you may know, and then post when you get stuck. :) Make sure you reference the code you are using so we don't have to ask, because there are a bunch of different snippets in this topic.
Title: Re: Calendar in a php-block
Post by: lOOmis on March 05, 2008, 09:25:49 PM
   $col_width = ' width="16%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="16%"';


This is the only thing I found concerning the column width to spread them out a bit. I changed it to 16 from the default. As far as the text goes. I see references to 'smalltext' and have changed a few to 'mediumtext' but dont see a change. Also changed one font size here......
  $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: medium;"><a class="smalltext"';

But dont see a change...
Title: Re: Calendar in a php-block
Post by: Klabautermann on March 12, 2008, 10:49:47 AM
First off all:

Great Mod!

I used this code, but how is it possible to show all events of a month? I only get the next two events.

If you want to take a look, you can see it here: www.tiny-soldiers.com

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '_______ Events _______';
$list_label_hdays =  '______ Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: Zetan on March 12, 2008, 11:52:40 AM
Admin > Forum/Calendar > Max days in advance on board index: [  ]

Be careful how many days in advance vs number of calendar entries, it can mess with the output in the block.
That shoud increase the days in advance the block displays, if it doesn't, then there might be a part of the code under Events where you can change it.
Title: Re: Calendar in a php-block
Post by: Klabautermann on March 12, 2008, 12:48:40 PM
Ah fine, thanks that works. One more question: How do I change the format of the calender? At the moment the format is the american one, starts the week with Sonday. But it would be better for me here in Germany a weekstart with Monday. How could i do this?

And also, how can I present the events only in one line or with w break between each one so I have a little bit more space between them?
Title: Re: Calendar in a php-block
Post by: kjb0007 on March 17, 2008, 02:52:31 AM
Is there a way to adjust the size of this so it aligns with the rest of the blocks?

here is a screenshot of what I mean:

http://www.fileupyours.com/files/138165/tpblockissue.jpg
Title: Re: Calendar in a php-block
Post by: dannbass on March 17, 2008, 12:54:41 PM
Not actually, you'll need to change the 3 letter name, for a 2 letter name, or just 1 letter because the width comes with the letters... or make the other ones bigger.
Title: Re: Calendar in a php-block
Post by: kjb0007 on March 17, 2008, 09:42:22 PM
Changing the day length to a 2 worked perfectly.. thanks :)
Title: Re: Calendar in a php-block
Post by: ogmios on March 21, 2008, 02:53:03 PM
not sure what i'm missing, but i have "$show_events_past" and "$show_holidays_past" set to "false", but the event and holiday listings in my calendar continually show the previous days' events and holidays... anyway to turn it off?

my code:

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'left';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = false;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = true; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#000066';    // comment out to use default text colors -
$color_saturday = '#000066';  //   can use hex codes with leading '#'
$color_today = 'white';   //   or color names
$bkgrd_today = 'black';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '-------- TINGS A GWAN -------- (todays event in bold)';
$list_label_hdays =  '-------- HOLIDAYS --------';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = false;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = false;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 00 * 0000)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'"><b>'.$title.'</b></a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '">' . $text_start . $text_end . '</a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: JPDeni on March 21, 2008, 04:00:01 PM
You could try changing


$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);


to


$low_date_base = strftime('%Y-%m-%d', $now);

Title: Re: Calendar in a php-block
Post by: ogmios on March 21, 2008, 04:14:14 PM
beauty!

(thanks JP)
Title: Re: Calendar in a php-block
Post by: lOOmis on March 26, 2008, 02:39:04 PM
Would I change the color of the text for Events, Holidays, Birthdays by changing the following code..  $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';

To typing the actual word GREEN or #?????? for the color of the text to change. Am I even looking in the right place?
Title: Re: Calendar in a php-block
Post by: JPDeni on March 26, 2008, 03:19:52 PM
The colors are defined here:


// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];


The default is what you have already set in your admin panel. If you want to change them, use the number. Something like:


// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#FF0000';
$list_label_events_color = '#00FF00';
$list_label_hdays_color = '#0000FF';
Title: Re: Calendar in a php-block
Post by: lOOmis on March 26, 2008, 03:32:39 PM
Great, Thankyou
Title: Re: Calendar in a php-block
Post by: confuzed on March 26, 2008, 09:28:10 PM
I have to say, I really like this :)

I saw something on another forum that I also like, and wondered if they did it with this code or is another TP block code? 

center block showing 7 days  (http://www.texasclan.com/forum/)

thanks
Title: Re: Calendar in a php-block
Post by: G6Cad on March 26, 2008, 09:39:42 PM
That is probably their own work  :)
Title: Re: Calendar in a php-block
Post by: Final60 on March 27, 2008, 02:53:00 PM
Hello
Great Block code here.

It works perfectly in default theme, but when using goldnightv2 theme it displays incorrectly, how can I get it positioned correctly in the block?

Default Calendar: http://www.finalonline.co.uk/mypics/default_cal.jpg

Goldnightv2 Calendar: http://www.finalonline.co.uk/mypics/goldnight_cal.jpg
Title: Re: Calendar in a php-block
Post by: Zetan on March 27, 2008, 03:09:55 PM
You probably need to increase the panel width in the options of that theme.
Title: Re: Calendar in a php-block
Post by: IchBin on March 27, 2008, 03:11:36 PM
Looks to me like Goldnightv2 uses a different font size that is making it push out. I'd need to see it on your site to tell you what needs to be changed.
Title: Re: Calendar in a php-block
Post by: Zetan on March 27, 2008, 03:19:05 PM
Looks like the font size is similar, but the spacing looks wider and the panel narrower.
Title: Re: Calendar in a php-block
Post by: Final60 on March 27, 2008, 03:31:37 PM
Heya
I tried resizing the panel, but it would need the panel to be ALOT bigger to properly encorporate the calendar.

www.dcpryzom.co.uk/forum


global $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 3px 0px 3px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table style="width:50%;">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: IchBin on March 27, 2008, 03:42:55 PM
Change $day_name_length = 3; to 2 instead. That will shorten the width a bit. If you need more you probably need to edit the theme style.css file to adjust the padding.
td, th {
padding:0.1em 0.6em 0.1em 0.1em;
}
Title: Re: Calendar in a php-block
Post by: Final60 on March 27, 2008, 03:48:39 PM
Thank you very much IchBin, that seems to have solved the issue!
regards,

edit: the right and center panels now sit right next to each other, the padding option in the setting (5px) doesnt appear to take effect!
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 29, 2008, 05:57:58 PM
Hello!
Very very long thread... Ang a gigantic work here! :up:
Well, my problem is:
I'm using this code from here http://www.tinyportal.net/index.php?topic=700.msg173249#msg173249 :
/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Holidays', 'Events', 'Birthdays');

// Order to show calendar entry lists
$order_lists = array('Holidays', 'Events', 'Birthdays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = true; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
//$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______Cumpleaños ______';
$list_label_events = '______ Eventos ______';
$list_label_hdays =  '______Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Cumpleaños';  // Change to labels in language of choice
$list_label_events = 'Eventos';
$list_label_hdays = 'Fiestas';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miércoles','Jueves','Viernes','Sábado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.$d.'">'.($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';


My web's in spanish UTF8 (http://www.pajareo.com) and Saturdays days name are not correctly displayed even if I've changed this
abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
into this
abbr="'.$d.'">'.($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
It shows 'S�' instead of correct 'Sá'

If I turn back previous change, it shows 'SÃ'

Where can I find the solution for this?

Thanks in advance for all your great and mighty work here...
Title: Re: Calendar in a php-block
Post by: G6Cad on March 29, 2008, 06:58:38 PM
Set your forum to use English and not English utf8 and see if you have it look the way it should.
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 29, 2008, 10:22:00 PM
Turning into english show many errors, but into spanish (not utf8) shows it good...
Title: Re: Calendar in a php-block
Post by: dannbass on March 29, 2008, 11:08:03 PM
You need to use S&aacute; instead.  Good to see another spanish speaker around here!
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 30, 2008, 05:16:08 AM
"Saludos desde Madrid, España!"  ;)

Yeah, I use that... but when I come back to see again calendar php block, the "&aacute;" has been translated into that "á" ...  :idiot2:
Title: Re: Calendar in a php-block
Post by: JPDeni on March 30, 2008, 05:48:08 AM
&aacute; is the html code for the letter á. When you put &aacute; in an html code (and, after all, the calendar php is merely creating html code), it shows up as á.
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 30, 2008, 07:01:13 PM
Ok, then what can I do to solve the problem?
Title: Re: Calendar in a php-block
Post by: JPDeni on March 30, 2008, 09:22:33 PM
I think you need to tell us exactly what's happening. Put the code back to what it was. Set your language to regular Spanish and not Spanish UTF8. Then, tell us what the result is. I'm not clear as to what your settings are or what your code is or what is happening. If there's still a problem, at least we'll all know where we're starting from.
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 31, 2008, 09:12:43 AM
I think I've already done it, just one page before:

http://www.tinyportal.net/index.php?topic=700.msg185044#msg185044
Title: Re: Calendar in a php-block
Post by: JPDeni on March 31, 2008, 01:42:48 PM
Yes, I saw that. I'm asking you to do it again. It is unclear to me what result went with what code.

Or you don't have to and someone else might come by to help you out.
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 31, 2008, 04:53:00 PM
Ok...
This is the code I'm using with spanis Es-utf8 language selected:
/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Holidays', 'Events', 'Birthdays');

// Order to show calendar entry lists
$order_lists = array('Holidays', 'Events', 'Birthdays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = true; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
//$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______Cumpleaños ______';
$list_label_events = '______ Eventos ______';
$list_label_hdays =  '______Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Cumplea&ntilde;os';  // Change to labels in language of choice
$list_label_events = 'Eventos';
$list_label_hdays = 'Fiestas';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';


And the weekdays shows
Lu Ma Mi Ju Vi SÃ Do

If I change language to spanish (same block code) it shows:
Lu Ma Mi Ju Vi Sá Do
And that's correct, but I need to use spanish utf8 language...
Title: Re: Calendar in a php-block
Post by: JPDeni on March 31, 2008, 05:55:52 PM
QuoteIf I change language to spanish (same block code) it shows:
This is what I needed to know.

You can possibly set the day length to be 8 and define your days as


$day_names = array('Lu','Ma,'Mi','Ju','Vi','S&aacute;','Do');


That might work.
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 31, 2008, 06:11:07 PM
Not working...
This is the code:
/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Holidays', 'Events', 'Birthdays');

// Order to show calendar entry lists
$order_lists = array('Holidays', 'Events', 'Birthdays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = true; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 8;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
//$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______Cumpleaños ______';
$list_label_events = '______ Eventos ______';
$list_label_hdays =  '______Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//


$list_label_bdays = 'Cumplea&ntilde;os';  // Change to labels in language of choice
$list_label_events = 'Eventos';
$list_label_hdays = 'Fiestas';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lu','Ma','Mi','Ju','Vi','S&aacute;','Do');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];


/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';

And this is the result:
Lu Ma Mi Ju Vi S&aacute; Do
Title: Re: Calendar in a php-block
Post by: JPDeni on March 31, 2008, 06:18:34 PM
This is with the Spanish UTF8?
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 31, 2008, 06:22:25 PM
Yes...
Title: Re: Calendar in a php-block
Post by: JPDeni on March 31, 2008, 07:12:42 PM
Sorry. I don't know how to help you. I've given you every idea I had.
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 31, 2008, 09:34:05 PM
Hey, thanks for your time anyway! ;)

Anyone has any idea about what's happening here?
Title: Re: Calendar in a php-block
Post by: ogmios on April 30, 2008, 03:42:56 PM
i'm having a nuance where in Internet Explorer, i'm getting an extra space above the Month (please see attached image)... i'm not sure what to do - i've been up and down the code and couldn't figure out what's causing it... any ideas?

the code:
/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'left';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = false;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = true; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#000066';    // comment out to use default text colors -
$color_saturday = '#000066';  //   can use hex codes with leading '#'
$color_today = 'white';   //   or color names
$bkgrd_today = 'black';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '-------- TINGS A GWAN --------';
$list_label_hdays =  '----------- HOLIDAYS -----------';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = false;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = false;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 00 * 0000)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'"><b>'.$title.'</b></a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '">' . $text_start . $text_end . '</a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
           echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'></br><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
                        echo '<hr/>';
echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: TriumphTalk on May 04, 2008, 02:18:30 PM

I am using the following version of this code. I however have two issues that I cannot resolve.
1.   I want it to be in my Front page blocks so I need it to be a bit larger than what it is now.
2.   It does not seem to show the birthdays below the calendar like the list of events and holidays




/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 

// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'left';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = true;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = true; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#000066';    // comment out to use default text colors -
$color_saturday = '#000066';  //   can use hex codes with leading '#'
$color_today = 'white';   //   or color names
$bkgrd_today = 'black';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '-------- Upcoming Events --------';
$list_label_hdays =  '----------- HOLIDAYS -----------';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = false;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = false;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 00 * 0000)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'"><b>'.$title.'</b></a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '">' . $text_start . $text_end . '</a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
           echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'></br><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
                        echo '<hr/>';
echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: JPDeni on May 04, 2008, 02:59:33 PM
If you want to make it bigger, you could take out all of the references to


class="smalltext"


I'm not sure what the problem is with your birthdays. All the settings seem to be there. The only thing I can think of is that you don't have any birthdays defined for this month.
Title: Re: Calendar in a php-block
Post by: TriumphTalk on May 04, 2008, 03:54:25 PM
Thanks I will try that.

Yes I do have a few birthdays and the showup highlighted on the calendar but not listed below like the events would   
Title: Re: Calendar in a php-block
Post by: Zetan on May 04, 2008, 03:56:56 PM
Do you have the forum calendar set to display birthdays in the Info Center?
They need to be displayed there, then they should display in the block also.
Title: Re: Calendar in a php-block
Post by: TriumphTalk on May 04, 2008, 07:21:31 PM
Quote from: ZTN on May 04, 2008, 03:56:56 PM
Do you have the forum calendar set to display birthdays in the Info Center?
They need to be displayed there, then they should display in the block also.

Ok I had a look but am not sure about this, where would I see it?     
Title: Re: Calendar in a php-block
Post by: Zetan on May 04, 2008, 11:07:07 PM
Actually, after trying it myself with Events (we don't display birthdays) it made no difference whether the Info Center is set to display Events.

There should be no difference here in the example between Birthdays and Events.

All forum calendar options can be found under Calendar in the Admin panel.


One thing I'd like you to check and post, is the most forthcoming Birthday against How Many Days In Advance the forum calendar in the Admin panel is set to.

Mine will display anything up to 14 days in advance.
Title: Re: Calendar in a php-block
Post by: TriumphTalk on May 05, 2008, 04:03:48 AM
I had it set to 7 days but I have now changed it to 14. As you will see I have two birthdays within that period and they show at teh borrom of teh forum?       
Title: Re: Calendar in a php-block
Post by: TriumphTalk on May 05, 2008, 05:11:06 AM
Ok it looks like it has something to do with the code I am using. I tried this code as shown on my attached Test Calendar and it works       


global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';



This is the code I want to use that does not work. Please note that I will have two calendars displayed in different places. This one for my birthdays and a second one for my events. The events one is working 100%  (I am using the same code but just changing the display options in each on)
This is my Birthdays one that will not work       


/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 

// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'left';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = true;

// Show Event list at all / to guests
$show_events = false;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = true; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#000066';    // comment out to use default text colors -
$color_saturday = '#000066';  //   can use hex codes with leading '#'
$color_today = 'white';   //   or color names
$bkgrd_today = 'black';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '-------- Upcoming Events --------';
$list_label_hdays =  '----------- HOLIDAYS -----------';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = false;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = false;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 00 * 0000)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'"><b>'.$title.'</b></a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '">' . $text_start . $text_end . '</a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
           echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'></br><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
                        echo '<hr/>';
echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: magz on May 16, 2008, 12:36:35 AM
Very nice calendar, Im using it right now.

But as I open many topics and clickng the links given, I saw this calendar.
More organized.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg241.imageshack.us%2Fimg241%2F7662%2Fcalendarpv5.jpg&hash=89274287187e39ad72e35afbdc3c42001d4d41cf)

Can somebody share the code for this  ;D

Title: Re: Calendar in a php-block
Post by: Zetan on May 16, 2008, 04:33:36 AM
If that code is anywhere.. it's in this topic. It's the calendar I use, but I have removed Birthdays and Holidays and just use the Events.

You'll have to plough through all the posts like we all do.
Title: Re: Calendar in a php-block
Post by: magz on May 16, 2008, 05:40:05 AM
Hi ZTN,

I saw that calendar from another thread, someone posted his forum link  :buck2:

Anyways I will look for the code later  :D

If im not able to find it, do the honor pls  :laugh:
Title: Re: Calendar in a php-block
Post by: JPDeni on May 16, 2008, 01:30:18 PM
You can contact the owner of the site where you found it, to see where he or she got the code.
Title: Re: Calendar in a php-block
Post by: magz on May 16, 2008, 02:49:03 PM
Hi JPDeni,

As I was searching within this thread, i wasn't able to find the code as what ZTN adviced me.

And unfotunately, I have to read each thread all over again to find out who's the owner of that  forum.  >:D

If your not busy... im pretty sure you know the code...  ;D

Sorry for my poor english  :uglystupid2:

Title: Re: Calendar in a php-block
Post by: JPDeni on May 16, 2008, 03:21:53 PM
Quoteim pretty sure you know the code
No, I don't. The only calendar script I've worked with is the one here in this topic.

It would be a good idea, in the future, when you find something on a site that you would like to use, if you would make note somewhere of the URL of that site so that you can find it again. It doesn't help you now, of course, but there is a calendar script here that you can use.
Title: Re: Calendar in a php-block
Post by: magz on May 16, 2008, 03:42:21 PM
I finally found the site and the owner is ken.  ;D

here is the link
http://www.performanceefx.com/forum/index.php
Title: Re: Calendar in a php-block
Post by: Ken. on May 16, 2008, 04:09:20 PM
Quote from: magz on May 16, 2008, 03:42:21 PM
I finally found the site and the owner is ken.  ;D

here is the link
http://www.performanceefx.com/forum/index.php

That is one of my sites, but I'm not so sure that it is of any help with this question.

magz please note:
I do not do support through PM's or emails so please post your questions to the forum.
... and besides that, the topic link you included in the PM has nothing to do with this topic.
Thanks... Ken.
Title: Re: Calendar in a php-block
Post by: magz on May 16, 2008, 04:18:37 PM
Im sorry, I just got excited when I find  one of your sites. And I was so stupid bceause I have given you the wrong link. Sowee  :(

Ok, I will have to wait until someone gives the code.


Thanks

O0
Title: Re: Calendar in a php-block
Post by: Ken. on May 16, 2008, 05:14:24 PM
magz, this is the calendar code that's in use on my site, it works OK for me but it may or may not work as expected for your site.


I don't remember who wrote this version but it came from this topic.

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2; // Change for more letters

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

/////////////////////////////////////////////////////////////////
//   CALENDAR SECTION
//
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $birthdate = strtotime($row['birthdate']);

        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: magz on May 17, 2008, 01:01:47 AM
I love you Ken.!    :D
Thanks!  :up:
Title: Re: Calendar in a php-block
Post by: Ken. on May 17, 2008, 01:28:40 AM
You are welcome.  :)
Title: Re: Calendar in a php-block
Post by: fangweile on May 23, 2008, 07:10:44 AM
Ow, thanks a lot Ken, thats the code I been looking for. I am using it now. Its really great.
Title: Re: Calendar in a php-block
Post by: Murgen on May 26, 2008, 08:16:20 AM
Ken, I copy/pasted the calendar-block code you posted May 16th but I have a small problem.

From the start:
- 3 birthday announcements: 1st listed as January 1st (and should be May 29th)

Today:
- 4 birthday announcements. 1st and 4th listed as January 1 (and should be May 29th and June 15th).

Have you got a clue what is wrong here? (I'm an oldtimer educated with Basic, Pascal and Modula-2 and virtually no php-knowledge :)  )
Title: Re: Calendar in a php-block
Post by: Ken. on May 26, 2008, 12:28:03 PM
Murgen, as mentioned when the code was posted, my recollection is that it was taken from this topic but I don't remember who wrote it. Your solution may very well be in the topic as well but the only way to know is to read through from the beginning.

That will take some effort to do that of course, but you may also find other codes that you like better as there are several versions posted in this topic.
Title: Re: Calendar in a php-block
Post by: Murgen on May 26, 2008, 03:31:10 PM
Quote from: Ken. on May 26, 2008, 12:28:03 PM
Murgen, as mentioned when the code was posted, my recollection is that it was taken from this topic but I don't remember who wrote it. Your solution may very well be in the topic as well but the only way to know is to read through from the beginning.

That will take some effort to do that of course, but you may also find other codes that you like better as there are several versions posted in this topic.


Yes, but you must agree that digging through 53 pages is a tough job. :(
Title: Re: Calendar in a php-block
Post by: Ken. on May 26, 2008, 03:41:00 PM
True, but look at the potential for learning.  :)
Title: Re: Calendar in a php-block
Post by: Murgen on May 26, 2008, 04:12:22 PM
True, my Master. I have been looking into the script and the b-days settings from the members involved and so far I haven't got a clue. Can't pin the error at the moment. B-day June 1 goes wrong and B-day June 2 is listed the right way. Intriguing little bug.
Title: Problem with calendar-code
Post by: Murgen on June 04, 2008, 11:11:08 AM
Hi all,

I use the calendar script from http://www.tinyportal.net/index.php?topic=700.520 (page 53, post Ken) and I have been looking into it for such a long time my eyes and head hurt. There is a bug with shows in the birthday section. Some birthdays show as January 1st. I tried to figure out if it has to do with leapyears but no luck there. I just can't figure it out. :(

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.e-templars.net%2Fpics%2Fcalendar.JPG&hash=55441ee22e06af0979b6c5d4df6901cee57bfc5a)

The thing is that the other sections do not show the bug. For instance: the wrong birthday entry is June 15th which shows well in the Father's day entry.

I can read php-scripts. It is not easy for me but I can work it out (47 yrs old << Basic, Pascal, Modula-2 generation). The bug shows on several birthdays but the majority shows up the right way. It is not logical and would love some advice where to look and check in the script.

Thank you.
Title: Re: Problem with calendar-code
Post by: Murgen on June 04, 2008, 11:32:43 AM
Fixed!

At page http://www.tinyportal.net/index.php?topic=700.190 J.A. Cortina lists a fixed code! Ken posted the unfixed version of that particular code.

Timestamp problem as documented by my hero J.A. Cortina.
Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.
Title: Re: Problem with calendar-code
Post by: Vivasvan on June 05, 2008, 10:45:53 PM
Hi

I have read through the whole thread.  I have nearly found what I want.  ... I want to use this particular code that i found.  It fits perfect and looks extremely neat.  However there are just a few things I need adding and I cant seem to do it.   

What i need adding to this is really really simple and you code gurus could easily do it.. i have tried.. and its a mess when i do.

1. Date next to event Jun xx  or XX/XX format will do.
2. Upcoming Events is listed twice.. once as a header then again in green before the event.  I just want the date there and dont want it listed twice.
3. Post event link at the bottom below the events listed.
4. I dont want holidays listed etc.. Just events.  It shows dday holiday on todays date 06/06.  I just want events.
5. When someone clicks on a date it would be nice if it goes to the calender smf page and not straight to posting event screen.

Can anyone just do this in the code ive listed below.  I have really been through all this section and found various calenders some do what i want but dont look good on my site and most if not all have the holiday/bdays stuff in them. I just want events.

Here is my site : www.orderofmiddleearth.com

It would be awesome if this could be done.

here is the code im using: global $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a align="center" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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 style=" font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 style=" font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#ededed'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" style=" font-size: xx-small; font-family: verdana, sans-serif;" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="calendarblock">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" style=" font-size: xx-small; font-family: verdana, sans-serif;" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" style=" font-size: xx-small; font-family: verdana, sans-serif;">';
  ssi_todaysCalendar();
  echo '</td></tr></table>';
}


Title: Re: Problem with calendar-code
Post by: JPDeni on June 05, 2008, 11:04:35 PM
Why don't you use the "Calendar in a php block" code?
Title: Re: Problem with calendar-code
Post by: Vivasvan on June 06, 2008, 08:24:08 PM
Hi

Im a bit confused..... i thought i was using it.   :idiot2:

where is the one your refering to....but ive noticed on this thread.... there are two headings....

Problem with calendar-code
then most replys are too  calendar in php block  and i cant find this thread.
Title: Re: Problem with calendar-code
Post by: JPDeni on June 06, 2008, 09:38:29 PM
I think I'm confused, too, then. I didn't realize that the name of the topic was changed. Sorry.

The code looks different than the first code in the topic, though. I've used the code that Bloc wrote with good results.
Title: Re: Problem with calendar-code
Post by: Vivasvan on June 06, 2008, 09:46:30 PM
Hi again...

yes the first code doesnt display the things i wanted in the calender.  The code im using is a few pages into this thread. On page9 at the bottom (Xarcells code) and its the code on the bottom of the page. Its neater and fits perfect.  Its just tweaked from from the first one.

I just wanted these additions to the calendar code im using.

1. Date next to event Jun xx  or XX/XX format will do.
2. Upcoming Events is listed twice.. once as a header then again in green before the event.  I just want the date there and dont want it listed twice.
3. Post event link at the bottom below the events listed.
4. I dont want holidays listed etc.. Just events.  It shows dday holiday on todays date 06/06.  I just want events.
5. When someone clicks on a date it would be nice if it goes to the calender smf page and not straight to posting event screen.

I cant seem to do it.  Someone here must know where the code lines fit in.   Here is the code again

global $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a align="center" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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 style=" font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 style=" font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#ededed'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" style=" font-size: xx-small; font-family: verdana, sans-serif;" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="calendarblock">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" style=" font-size: xx-small; font-family: verdana, sans-serif;" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" style=" font-size: xx-small; font-family: verdana, sans-serif;">';
  ssi_todaysCalendar();
  echo '</td></tr></table>';
}


ps something very strange has happened on the above code.  The calendar was working fine while an event was showing... now today is the first day without an upcoming event... and the calandar box has split!! the calander is right at the bottom of the page.. yet the box title heading is where the calendar was displayed before... on the upper right of the page... whats happened... this code is the only one that does this on my site (www.orderofmiddleearth.com).. all the others work fine.  However this is the best looking of the calendars and i really want to use it...

can anyone help with the things i want? 
Title: Re: Problem with calendar-code
Post by: Xarcell on June 07, 2008, 08:44:59 PM
I looked at the code at the above URL, I don't see any issues. What am I missing?
Title: Re: Problem with calendar-code
Post by: Vivasvan on June 07, 2008, 09:00:25 PM
Hi

That is not your code currently  ;D

I had to take yours out... as if i added it, when there are no events.. it splits it as i was saying.  Currently using another code from another page on this thread.

BUT i really prefer yours.. yours was neater/smaller and 3 letter days etc.  Either way... i just want a post event link on bottom of the calender i currently have... or with your coded version.




Title: Re: Problem with calendar-code
Post by: Vivasvan on June 09, 2008, 09:05:47 PM
so has anyone got an answer for me?

Title: Re: Problem with calendar-code
Post by: Xarcell on June 15, 2008, 10:09:59 PM
Which code do you prefer, and i'll try and make it pretty for ya...
Title: Re: Problem with calendar-code
Post by: Vivasvan on June 16, 2008, 12:24:40 PM
Hi Xarcell

This is the current code im using and im happy with it (i did prefer yours as i stated earlier in the post, but this will do).

global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: blue; font-weight: bold; border: solid 0px black; background-color: #ffffff; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top">'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 style=\"padding-right: 4px; font-size: x-small; font-family: trebuchet ms, verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#D0E4FF'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><u><b>BIRTHDAYS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><u><b>SPECIAL DAYS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysHolidays();
  echo '</td></tr>';
}

if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><u><b>EVENTS</b></u></td><td><hr></td></tr><td colspan="7" class="smalltext">';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
                   }
  echo '</td></tr>';
}

echo '</table>';



I just wanted a post event link at the bottom of the calendar and to make it look neater and smaller like you did on yours.. with 3 days instead of 2.  (currently adding 3 letter days take the width way out of the block).

Thanks
Title: Re: Problem with calendar-code
Post by: Xarcell on June 16, 2008, 05:12:12 PM
Ok, I finished doing all that I could do. I tried doing what you asked, but my php skill is limited.

With the code you supplied me, I dressed it up a bit.

1.| 3 letter days now fit in a default sized block.
2.| Added highlight on current day, using colors from the template style.css.
3.| Replaced the word "Events" with proper text string.
4.| Does not show birthdays & holidays in block. Events only...
5.| Added a "Post event" link at bottom of calendar, but could only get it to show up on calendar page.

global $context, $settings, $options, $txt, $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<a align="center" class="windowbg2" style="color: #999999; font-weight: bold; border: solid 1px black; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" onmouseover="this.className=\'windowbg3\'" onMouseOut="this.className=\'windowbg2\'" href="'.$scripturl.'?action=calendar;sa=post;" target="_self">'.$today.'</a>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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 style="font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = '<span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$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 style="font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}

if($weekday > 0) $calendar .= '<td style="font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}
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 class=\"windowbg\" style=\"font-size: x-small; font-family: verdana, sans-serif;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td style="font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Events.

if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">' , $txt['calendar4'] , '</td><td><hr></td></tr><td colspan="7" class="smalltext">';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
                   }
  echo '</td></tr>';

}

  // Show a little "post event" button?
if ($context['can_post'])
echo '
<tr><td colspan="7" align="center" style="padding-top: 1em; font-size: x-small; font-weight: 600; text-transform: uppercase;"><a href="', $scripturl, '?action=calendar;sa=post;month=', $context['current_month'], ';year=', $context['current_year'], ';sesc=', $context['session_id'], '">' , $txt['calendar23'] , '</a></td></tr>';

echo '</table>';


Given issues 5 & 6, maybe someone else with more knowledge can fix it.
Title: SMF Calendar Bock
Post by: Vivasvan on June 16, 2008, 05:17:12 PM
This looks neat.. very neat.. i think its nearly perfect... i see what you mean regarding the post event Link...

www.bladesofanarion.net have a calander on there site using tp... im still wondering how they did it.. if i ever find out i will post the code on here for all.

How would you make upcoming events smaller and in green? .. where is the code for that.. then i can change and play with it myself.

thank you very much for your time however.
Title: Re: SMF Calendar Bock
Post by: Xarcell on June 16, 2008, 05:41:52 PM
I could put a Post Event link that would show up on all pages, but it wouldn't carry with it the proper permissions. Notice when you click on it on that guys site, you get an "event posting not allowed. That link should only show up if the user has permissions to post an event.

If you want to do it anyway, as he did, then use this block code:

global $context, $settings, $options, $txt, $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<a align="center" class="windowbg2" style="color: #484848; font-weight: bold; border: solid 1px black; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" onmouseover="this.className=\'windowbg3\'" onMouseOut="this.className=\'windowbg2\'" href="'.$scripturl.'?action=calendar;sa=post;" target="_self">'.$today.'</a>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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 style="font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = '<span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$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 style="font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}

if($weekday > 0) $calendar .= '<td style="font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}
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 class=\"windowbg\" style=\"font-size: x-small; font-family: verdana, sans-serif;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td style="font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Events.

if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">' , $txt['calendar4'] , '</td><td><hr></td></tr><td colspan="7" class="smalltext">';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . '<br />';
}
                   }
  echo '</td></tr>';

}

  // Show a little "post event" button?
echo '
<tr><td colspan="7" align="center" style="padding-top: 1em; font-size: x-small; font-weight: 600; text-transform: uppercase;"><a href="', $scripturl, '?action=calendar;sa=post;sesc=', $context['session_id'], '">' , $txt['calendar23'] , '</a></td></tr>';

echo '</table>';


NOTE: I have fixed the current day being linked in the above snippet. I also edited and fixed code in snippet in previous post.
Title: Re: SMF Calendar Block
Post by: Vivasvan on June 16, 2008, 07:26:23 PM
I think this is perfect.. unless you are a member on my site ... it wont allow you to post an event... thats how it works for the blades site..

i think its nearly perfected.. i think this could be the perfect calendar.  it should be put on a sticky.
Title: Re: SMF Calendar Block
Post by: Smoky on June 16, 2008, 08:23:39 PM
you might have to check your user permissions to see if they are allowed to post to the calendar.. ;)
Title: Re: SMF Calendar Block
Post by: Xarcell on June 17, 2008, 05:34:45 AM
I worked on the code a little bit more. I couldn't stand that  * symbol for the admin to edit an event.

So instead I made it so that the admin would click the date of the event to edit. It shows up in red. However, if not logged in or do not have permission to edit, it shows up block & unlinked.

Screenies attached...



global $context, $settings, $options, $txt, $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<a align="center" class="windowbg2" style="color: #999999; font-weight: bold; border: solid 1px black; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" onmouseover="this.className=\'windowbg3\'" onMouseOut="this.className=\'windowbg2\'" href="'.$scripturl.'?action=calendar;sa=post;" target="_self">'.$today.'</a>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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 style="font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = '<span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$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 style="font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}

if($weekday > 0) $calendar .= '<td style="font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}
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 class=\"windowbg\" style=\"font-size: x-small; font-family: verdana, sans-serif;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td style="font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.
if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
  echo '<tr><td colspan="2"><hr></td><td width="30px" colspan="3" class="smalltext" align="center">' , $txt['calendar4'] , '</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext" valign="middle">';
$events = $result['events'];
foreach ($events as $event)
{
if ($event['can_edit']){
echo '
<a href="' . $event['modify_href'] . '" style="color: #c00000;">'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':</a>';
  }
else
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';

echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $event['link'] . '</span><br />';

}
                   }
  echo '</td></tr>';

}

  // Show a little "post event" button?
echo '
<tr><td colspan="7" align="center" style="padding-top: 1em; font-size: x-small; font-weight: 600; text-transform: uppercase;"><a href="', $scripturl, '?action=calendar;sa=post;sesc=', $context['session_id'], '">' , $txt['calendar23'] , '</a></td></tr>';

echo '</table>';


Title: Re: SMF Calendar Block
Post by: onicat on June 26, 2008, 01:52:37 PM
Question.
Is there a way to show the date of the event, instead of the date of the post below the calendar on the block?

Very nice script though. I do like.
Title: Re: SMF Calendar Block
Post by: Xarcell on June 26, 2008, 06:30:07 PM
I thought it showed the first day of the event? Not the date of the post.

Title: Re: SMF Calendar Block
Post by: Crip on June 26, 2008, 06:42:36 PM
This was the 1st ever block code snippet for TP..
Title: Re: SMF Calendar Block
Post by: onicat on June 26, 2008, 11:48:31 PM
What about repeating events. Is there a way to write it so that it shows the current date of the event?

Oh I am not saying its a bad code. Hell I do love it very much. I am just wondering if there were any other ways it could be moded...as I am not a coder myself. I figure the least I could do is through out idea's. LOL.
Title: Re: SMF Calendar Block
Post by: Xarcell on June 27, 2008, 04:23:07 AM
I think someone wrote one that has repeated events. You will need to browse his whole thread to find it.
Title: Re: SMF Calendar Block
Post by: FragaCampos on July 02, 2008, 01:25:25 AM
I confess i didn't read all the 56 posts...
i installed the Xarcell's code and i liked it a lot. I just took out the "Post Event" link, since it suits me that way.
Still, i would like to know how to edit the code so that when someone clicks one of the days, can be redirected to the SMF calendar instead of going to the add event post.

Thanks a lot.
Title: Re: SMF Calendar Block
Post by: ksimpson on July 02, 2008, 02:30:50 PM
Is there a way to make this grab more than 7 days worth of events? looking at either 2 weeks or a month right now...

Thanks
Title: Re: SMF Calendar Block
Post by: Ken. on July 02, 2008, 03:17:56 PM
Quote from: Kris Simpson on July 02, 2008, 02:30:50 PM
Is there a way to make this grab more than 7 days worth of events? looking at either 2 weeks or a month right now...

Thanks

Without knowing what version you are using its not possible to say for sure, however AFAIK most (or all) of the versions posted can be edited for the number of days that will be called into your display.
Take a look close to the top in your code and you should see a place to set the number of days.
Title: Re: SMF Calendar Block
Post by: ksimpson on July 02, 2008, 03:34:32 PM
Thanks for your help Ken, but I cannot find it in the version i am using... it could well be by inexperience, or tiredness though!

The version featured at the top of this page (56) (http://www.tinyportal.net/index.php?topic=700.msg197351#msg197351) is the one i have used.

Thanks again...
Title: Re: SMF Calendar Block
Post by: Ken. on July 02, 2008, 03:43:36 PM
Actually the info I posted was wrong, sorry.


Try this:
Admin>Forum>Calendar>Max days in advance on board index:>... set the number of days you need.


See if that works a little better.  :)
Title: Re: SMF Calendar Block
Post by: ksimpson on July 02, 2008, 03:44:45 PM
thanks mate, incidentally i found that about 30secs ago too!

Thanks again for your help
Title: Re: SMF Calendar Block
Post by: Ken. on July 02, 2008, 03:46:35 PM
Good deal, sorry for the misdirection.
Title: Re: SMF Calendar Block
Post by: fangweile on July 05, 2008, 02:12:13 AM
Hello there,

I use this calendar code in my forum and it is working fine last time
http://www.tinyportal.net/index.php?topic=700.msg193364#msg193364


But now displays the wrong date and holiday

Holidays   
Dec 31 - Independence Day

Any idea whats going on.
Title: Re: SMF Calendar Block
Post by: alhaudhie on August 26, 2008, 06:35:39 PM
cai i remove calendar date. I want to show only birthday and event.

This is the code thats im using now...

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'left';

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 0;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = true;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = true;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays = '----  Maulud Halaqian  ---';
$list_label_events = '---------  Acara ----------';
$list_label_hdays = '-------  Cuti Umum  -------';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Maulud Halaqian';  // Change to labels in language of choice
$list_label_events = 'Acara';
$list_label_hdays = 'Cuti Umim';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

// --------------------------------------

if (!isset($class_default)) $class_default = 'smalltext';
if ($class_default == '') $class_default = 'smalltext';

smf_loadCalendarInfo();

//$today = date('j',$now);
$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);

$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$bdays = calendarBirthdayArray($low_date, $high_date);
ksort($bdays);
$events = calendarEventArray($low_date, $high_date, false);
ksort($events);
$holidays = calendarHolidayArray($low_date, $high_date);
ksort($holidays);

$todays_color = '';
if (isset($color_today)) $todays_color = 'color:'.$color_today.'; ';
$todays_bkgrd = '';
if (isset($bkgrd_today)) $todays_bkgrd = 'background-color: '.$bkgrd_today.'; ';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';



                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (($startdate > $nowdate) && (substr($startdate,5,2) == substr($nowdate,5,2))) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {

        if (!empty($context['calendar_birthdays']))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr><tr><td colspan="7" class="smalltext">';

            $dummy = array();
            foreach ($context['calendar_birthdays'] as $member)
                $dummy[] = $member['id'];

            loadMemberData($dummy);

            $ctr = 0;

            foreach ($context['calendar_birthdays'] as $member)
            {
                $class_to_use = '';
                if (isset($list_entry_class))
                    if (!is_array($list_entry_class)) {
                        $class_to_use = ' class="'.$list_entry_class.'"';
                    }
                    else {
                        $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                    }
                $profile = &$user_profile[$member['id']];
                $birthdate = empty($profile['birthdate']) || $profile['birthdate'] === '0001-01-01' ? '0000-00-00' : (substr($profile['birthdate'], 0, 4) === '0004' ? '0000' . substr($profile['birthdate'], 4) : $profile['birthdate']);

                list ($uyear, $umonth, $uday) = explode('-', $birthdate);
                $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));

                echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                if (!isset($month_nam['12'])) {
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';}
                else {   
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate) . '</strong></a>';}
                echo ' - ';
                echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';

                if ((date('Y',$now).date('m',$now).date('d',$now)) == (date('Y',$birthdate).date('m',$birthdate).date('d',$birthdate)))
                    $member['name'] = '<b>'.$member['name'].'</b>';

                if (!empty($profile['member_group_color'])) {
                    echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';}
                else {
                    echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');}
                echo '</a>';
                echo '</div>';
            }
        echo '</td></tr>';
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($context['calendar_events']))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr><tr><td colspan="7" class="smalltext">';

            $ctr = 0;

            foreach ($context['calendar_events'] as $event)
            {
                $class_to_use = '';
                if (isset($list_entry_class))
                    if (!is_array($list_entry_class)) {
                        $class_to_use = ' class="'.$list_entry_class.'"';
                    }
                    else {
                        $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                    }
                $startdate = strtotime($event['start_date']);

                $cal_date = date("Y", $now) . date("m", $now) .date("d", $now);
                $evt_date = date("Y", $startdate) . date("m", $startdate) .date("d", $startdate);
                if($cal_date > $evt_date)
                    $startdate = $now;

                echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                if (!isset($month_nam['12'])) {
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';}
                else {   
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . substr($month_nam[strftime('%m', $startdate)],0,3) . date(" j",$startdate) . '</strong></a>';}
                echo ' - ';
                if ((date('Y',$now).date('m',$now).date('d',$now)) >= (date('Y',$startdate).date('m',$startdate).date('d',$startdate))) {
                    echo '<b>',$event['link'], '</b>';}
                else {
                    echo $event['link'] ;}
                echo '</div>';
            }
            echo '</td></tr>';
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            $class_to_use = '';
            if (isset($list_label_class)) $class_to_use = ' class="'.$list_label_class.'"';
            echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr><tr><td colspan="7" class="smalltext">';

            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {
                $eventdate = strtotime(date("Y").substr($hDate, 4));

                foreach ($hday as $holiday)
                {
                    $class_to_use = '';
                    if (isset($list_entry_class))
                       if (!is_array($list_entry_class)) {
                            $class_to_use = ' class="'.$list_entry_class.'"';
                        }
                        else {
                            $class_to_use = ' class="'.$list_entry_class[($ctr++) % 2].'"';
                        }
                    echo '<div'.$class_to_use.' align="'.$align_list_entries.'">';
                    if (!isset($month_nam['12'])) {
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';}
                    else {   
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate) . '</strong></a>';}
                    echo ' - ';
                    echo $holiday;
                    echo '</div>';
                }
            }
            echo '</td></tr>';
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: SMF Calendar Block
Post by: pbarney on August 28, 2008, 04:45:45 PM
Okay, I supposed I could try to digest 57 pages of posts on this, but maybe it would be better to ask:

Which post contains the latest code for the calendar? Is the first post edited to include the latest? Or should I take the code from the last post in the thread?

If it's in the first post, including a date for the last revision in the code would be superb!

Thanks for doing all the hard work!

Peter
Title: Re: SMF Calendar Block
Post by: pbarney on September 10, 2008, 05:12:22 PM
Anyone?
Title: Re: SMF Calendar Block
Post by: G6Cad on September 10, 2008, 06:07:30 PM
Is there any reason you cant do the work your self going through the topic and try the code ?
We have to do it the same way to be able to answer your question, and with the time limit we have on our hands will not make this happend as we are not the ones wanting it on our forum.
The best way to get what you want is to start going through the code, i would start backwards and go back from there.

All the code work in this topic, they are just changed over and over again to suite diffrent needs.
Title: Re: SMF Calendar Block
Post by: pbarney on September 10, 2008, 07:35:57 PM
Quote from: G6 on September 10, 2008, 06:07:30 PM
Is there any reason you cant do the work your self going through the topic and try the code ?

No, not really. I was just hoping that someone had the latest codebase handy, or could confirm if the first post in the thread was kept updated with the latest.

I hate to sound like a punk who asks basic questions without checking the FAQ... just thought there might be a "definitive version" in there somewhere.

Thanks for responding!
Title: Re: SMF Calendar Block
Post by: misjka on September 20, 2008, 10:32:25 AM
Hi!

I've used this excellent script on several on my SMF/TP sites, and so far I think it's brilliant  :D!

BUT, now I have turned into an issue: The events that turn up in this block is shown to every member of the forum, regardless if they have membergroup access to the linked forum post or not  :-\

Since the posts in this topic are vast, I haven't had the time to browse through it to see if anyone else has pointed this issue out before... Sorry about that  :-\

BUT, could this issue be corrected?
Title: Re: SMF Calendar Block
Post by: JPDeni on September 20, 2008, 03:04:08 PM
I don't know. I'd have to see which code you're using.
Title: Re: SMF Calendar Block
Post by: misjka on September 20, 2008, 05:48:24 PM
This one:

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '_______ Events _______';
$list_label_hdays =  '______ Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: SMF Calendar Block
Post by: JPDeni on September 20, 2008, 07:15:19 PM
I wasn't sure how the events were generated in the code. It looks like the come from an existing SMF subroutine calendarEventArray. In looking at that subroutine, it appears that it does check to see if the user can view the board where the topic is.

Are you sure this is happening?
Title: Re: SMF Calendar Block
Post by: misjka on September 20, 2008, 08:18:47 PM
Yes, in the php block any member may view the events... But as they click on the event links, the forum says the thread cannot not be viewed due to permission restrictions.....
Title: Re: SMF Calendar Block
Post by: JPDeni on September 21, 2008, 02:27:57 AM
I'm not sure what the problem is. When I first read your question, I figured I'd need to add the check for the user's permission, but it's already there. I wouldn't know how else to do it.
Title: Re: SMF Calendar Block
Post by: misjka on September 21, 2008, 07:55:36 AM
OK; sorry to hear that  :-\...

I might add, although I guess you've figured it out on your self, that the events do not show up in the calendar - only in the calendar block...
Title: Re: SMF Calendar Block
Post by: ogmios on October 08, 2008, 06:34:47 PM
is it possible to give the calendar a fixed height?

whereas if there are too many events, birthdays or holidays, it will display only what will fit... then if there aren't enough listings to fill the height, there would just be extra space...

this would help in the design of the front page on my website so that my blocks all line up nice a neat and don't fluctuate in size, etc....
Title: Re: SMF Calendar Block
Post by: alhaudhie on October 16, 2008, 03:12:08 AM
How can i only show Event and Birthday in block without the calendar date?
Title: Re: SMF Calendar Block
Post by: onicat on November 06, 2008, 11:49:57 PM
I notice that when I post an event to say November 8th. And I post it today (november 6th) it will display like this. "Nov 7-6 - "event title""
Is there anyway to remove that 6?

Also I have alot of repeating events on my calendar. Is there a way to get it to post the current date of the event, not the first date of the event?
Title: Re: SMF Calendar Block
Post by: fangweile on December 10, 2008, 01:34:35 AM
Hello there,

there is something wrong with my calendar block.
It  display a wrong date of holiday.

See attached file:

Hope someone could help, thanks in advance

Title: Re: SMF Calendar Block
Post by: G6Cad on December 10, 2008, 05:46:28 AM
A question for SMF to answer, the calendarblock just fetch the SMF calendar functions, so if you have issues with them, you need to ask on SMF how to fix it.
Title: Re: SMF Calendar Block
Post by: fangweile on December 10, 2008, 10:40:22 AM
If you go directly to the calendar
action=calendar
The date of the holiday is just right.
I use Ken's code btw
http://www.tinyportal.net/index.php/topic,700.msg193364.html#msg193364

Any idea?
Title: Re: SMF Calendar Block
Post by: G6Cad on December 10, 2008, 12:25:24 PM
Allready gave you the reply to that question, the code is fetching the same settings as you have in the smf calendar.
You have to ask on SMF
Title: Re: SMF Calendar Block
Post by: IchBin on December 10, 2008, 02:50:35 PM
G6, the holiday shows correct in the Calendar. This code snippet does not display that information right. The code snippet needs to be fixed.
Title: Re: SMF Calendar Block
Post by: Ken. on December 10, 2008, 04:19:38 PM
Don't know what the problem might be but for my display the dates show correctly.
Title: Re: SMF Calendar Block
Post by: IchBin on December 10, 2008, 04:28:10 PM
Ken, can you look at your database in the calendar_holidays table, and tell me what the eventDate column says for Christmas?
Title: Re: SMF Calendar Block
Post by: G6Cad on December 10, 2008, 04:38:03 PM
I have this code on my testsite, and it fetch the calendar options and my hollidays are correct to  ???
Title: Re: SMF Calendar Block
Post by: Ken. on December 10, 2008, 04:57:13 PM
Quote from: IchBinâ,,¢ on December 10, 2008, 04:28:10 PM
Ken, can you look at your database in the calendar_holidays table, and tell me what the eventDate column says for Christmas?

Is this what you need?
Title: Re: SMF Calendar Block
Post by: IchBin on December 10, 2008, 04:59:17 PM
Yes, that is it. Not sure why, I suppose it could be a PHP version difference or something. But my server, as well as fangweile's server does not parse the date properly. Mine is the same date format as yours. But if I change the 0004 to 2004 then the date displays properly. Can't figure it out. Not sure of another way to make it work though...
Title: Re: SMF Calendar Block
Post by: Ken. on December 10, 2008, 05:06:20 PM
Is it too complicated to have the snippet look at the PHP versions and adjust for the differences?
Having seen many discussions about versions of myPHPAdmin and the problems trying to get some code to work the same with different versions I take it the the answer is that it cannot be easily done?
Title: Re: SMF Calendar Block
Post by: Jakki on December 12, 2008, 01:06:20 AM
Quote from: IchBinâ,,¢ on December 10, 2008, 04:59:17 PM
Yes, that is it. Not sure why, I suppose it could be a PHP version difference or something. But my server, as well as fangweile's server does not parse the date properly. Mine is the same date format as yours. But if I change the 0004 to 2004 then the date displays properly. Can't figure it out. Not sure of another way to make it work though...

I was trying use Ken's snippet also, and found that Christmas was going to fall on Dec. 31st, but then I followed your advise IchBin and went into the database php admin and changed the 0004 to 2004 and it works. Thanks.
Title: Re: SMF Calendar Block
Post by: fangweile on December 12, 2008, 01:44:14 AM
I try to change  0004 to 2004 also but still display December 31, New years also falls in  wrong date, Dec. 31.

Here is my php version:
PHP Version 5.2.8 http://www.php.net/ChangeLog-5.php#5.2.8
Mysql version 5.0.76 Enterprise

Title: Re: SMF Calendar Block
Post by: mrtrc266 on December 15, 2008, 05:58:43 AM
Hello everyone, I'm hoping to get some help here. I created a PHP Block and used this Calendar Code and I love it...exaclty what 'm lookin for.

Only one thing, I don't see the B-Days section and I have a B-Day coming up in 5 days and I get this error...

8: Undefined variable: bdays

In my theme I have it set to show birthdays 7 days in advance.

Everything else shows up fine.

Anyone have any ideas? Does something need to be added to the language file?

Thanks in advance for any help.


Title: Re: SMF Calendar Block
Post by: IchBin on December 15, 2008, 05:18:05 PM
Are you using the code in the first post of this topic?
Title: Re: SMF Calendar Block
Post by: mrtrc266 on December 16, 2008, 05:52:01 AM
Quote from: IchBinâ,,¢ on December 15, 2008, 05:18:05 PM
Are you using the code in the first post of this topic?

I'm using this code

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                 
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;         

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  'Upcoming Birthdays';
$list_label_events = 'Upcoming Events';
$list_label_hdays =  'Upcoming Holidays';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//   
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//   
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }


if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';
Title: Re: SMF Calendar Block
Post by: Smoothbrain on January 07, 2009, 05:12:39 PM
Quote from: IchBinâ,,¢ on December 10, 2008, 04:28:10 PM
Ken, can you look at your database in the calendar_holidays table, and tell me what the eventDate column says for Christmas?

Hi I am having the same problem mentioned.  I am a n00b so could you please direct me as to where I might find this table to change it?  Thanks heaps.
Title: Re: SMF Calendar Block
Post by: Smoothbrain on January 07, 2009, 05:28:20 PM
Quote from: Smoothbrain on January 07, 2009, 05:12:39 PM
Quote from: IchBinâ,,¢ on December 10, 2008, 04:28:10 PM
Ken, can you look at your database in the calendar_holidays table, and tell me what the eventDate column says for Christmas?

Hi I am having the same problem mentioned.  I am a n00b so could you please direct me as to where I might find this table to change it?  Thanks heaps.


Well I found it but I don't think changing it worked.  I did wind up changing all the holidays (the ones with a constant date were messed up but the ones that change date had the 2, go figure)  I am exploring some other files now to see if i can track down what is going oin, more later.
Title: Re: SMF Calendar Block
Post by: Smoothbrain on January 07, 2009, 06:46:46 PM
Ok figured a couple things out that may or may not help others. 

There were several instances of incorrect dates (as mentioned above for the Christmas example) in my calendar_holiday and calendar db. You need to correct all of them.

In addition if you are listing moonphases the moonphase db is off but I was unsure what to put as correcting the 0000-00-00 to 2000-00-00 or 2000-01-01 did not fix said problem. You can either turn off moonphases or take out the listing from your block.

If you have repeating even mod and have the date older then today's date it will show that date in your block.  I just edited my repeat event as a workaround as I couldn't really figure out how to get it to show the "next" future date in the block.

Hope this helps.
Title: Re: SMF Calendar Block
Post by: Herr Inoddorell on January 08, 2009, 11:49:02 PM
Hi to all, I'm using this Code:

/******************************************************************************************
*                                                                                         *
* 'Mini' Calendar in phpblock -                                                           *
*                                                                                         *
* Program Parameters/Switches can be specified to change what is displayed and how.       *
*   If highlighting is turned on, only the types of entries which are selected to         *
*   be shown will be highlighted (and have to be shown to guests for guests to see        *
*   highlights). If option of linking the day numbers to calendar event posting form      *
*   is chosen ($date_links_to_posting = true), SMF permissions are in effect and only     *
*   those allowed to post events to the calendar will have this link in effect. For       *
*   $date_links_to_posting = false, and for those not permitted to post events, day       *
*   numbers will link to the full SMF Calendar page. Additionally, if option to show      *
*   a separate 'Post Event' button is chosen ($show_post_event_button = true), it will    *
*   only show for those permitted to post events to the calendar.                         *
*                                                                                         *
* Look for 'NON-ENGLISH' to see section for changing language. This is actually more      *
*   correctly referred to as 'language other than server default' as this Calendar will   *
*   use the server's default LOCALE language for Month and Day names unless overides      *
*   are specified in the code section labeled 'NON-ENGLISH  LABELS, MONTH & DAY NAMES',   *
*   below.                                                                                *
*                                                                                         *
* Once a given day is highlighted, the highlight will not be supplanted. That means       *
*   you may want to modify the order in which highlights are applied in order to set      *
*   desired 'precedence' (i.e. if b-days highlights are applied first, once a given       *
*   day is highlighted with b-day color, it will not be changed to be highlighted         *
*   with event color if an event occurs on the same day; you need to choose an order      *
*   of precedence and sequence the highlighting accordingly by changing the sequence      *
*   of sections in the $order_hilites array. Highlighting will be done in the given       *
*   order.                                                                                *
*                                                                                         *
* Also, if you want the individual B-day/Event/Holiday sections to be ordered in a        *
*   different sequence, you need to change the sequence of entries in the $order_lists    *
*   array.                                                                                *
*                                                                                         *
* Examples of highlighting can be seen in the section 'Highlight colors & backgrounds'    *
*   below. As given, highlighting is done by applying the admin specified calendar        *
*   entry color to the date, bolded, on the default background. Commented example given   *
*   of using bold white on a background box of the admin specified calendar entry color.  *
*                                                                                         *
******************************************************************************************/
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $sourcedir;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Program Paramters/Switches Section
//

// use forum's date/time
//$now = mktime() + $modSettings['time_offset'] * 3600;                                
// include user's time offset to forum date/time
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);

// Order to do highlightling - earlier have precedence
$order_hilites = array('Birthdays', 'Events', 'Holidays');

// Order to show calendar entry lists
$order_lists = array('Birthdays', 'Events', 'Holidays');

// Alignment of calendar entry lists
// $align_list_entries = 'left';
$align_list_entries = 'center';

// Use 'bordercolor' class for 'gridlines' (table background)
$bordercolor_gridlines = false; // Will 'show through' between table cells to act as 'grid lines'
$gridlines_thickness = 2;       // Pixel thickness for table "cellspacing" - only used w/ $bordercolor_gridlines = true;

// Letters to show on calendar for names of each of the days
$day_name_length = 2;

// Selection for first day of the week: 0-Sunday; 1-Monday
$first_day = 1;

// Show B-Day list at all / to guests
$show_bdays = true;
$show_bdays_to_guests = false;

// Show Event list at all / to guests
$show_events = true;
$show_events_to_guests = false;

// Show Holiday list at all / to guests
$show_hdays = true;
$show_hdays_to_guests = true;

// If true, calendar date numbers link to calendar event posting form
//    if not, links to full calendar page
$date_links_to_posting = false;

// Adds 'Post Event' button to bottom of block
$show_post_event_button = false; 

// Highlight events, b-days, holidays (only if they're selected to show at all)
$show_hilites = true;        

$color_sunday = '#D00000';    // comment out to use default text colors -
$color_saturday = '#D00000';  //   can use hex codes with leading '#'
$color_today = 'steelblue';   //   or color names
$bkgrd_today = 'white';

// Default class to use when no other class specified
$class_default = '';
// $class_default = 'smalltext';
// $class_default = 'windowbg2';

// Class to use for column top day names
// $class_day_names = 'titlebg';  // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class to use for 'Today' highlight
$class_today = 'windowbg2';

// Text Labels to use for calendar entry lists
$list_label_bdays =  '______ Birthdays ______';
$list_label_events = '_______ Events _______';
$list_label_hdays =  '______ Holidays ______';

// Colors for text labels on calendar entry lists
$list_label_bdays_color = '#'.$modSettings['cal_bdaycolor'];
$list_label_events_color = '#'.$modSettings['cal_eventcolor'];
$list_label_hdays_color = '#'.$modSettings['cal_holidaycolor'];

// Choose to show 'look-behind' for the various entry types
$show_bdays_past = false;
$show_events_past = false;
$show_hdays_past = false;

// For any of the above chosen, days prior to today to display -
//    use '0' (zero) to use beginning of current month
$past_look_behind_period = 0;

// Class for 'cells' holding text labels on calendar entry lists
// $list_label_class = 'titlebg'; // Ex.: titlebg, catbg, catbg2, catbg3, windowbg, windowbg2, windowbg3

// Class for 'cells' holding calendar entry lists
//   use regular variable for all same class
//   use two-member array to alternate between the two
$list_entry_class = '';
// $list_entry_class = 'windowbg';
// $list_entry_class = array('windowbg2','windowbg3');

///////////////////////////////
//   Highlight colors & backgrounds
//
//   Admin-specified birthday color: $modSettings['cal_bdaycolor']
//   Admin-specified event color:    $modSettings['cal_eventcolor']
//   Admin-specified holiday color:  $modSettings['cal_holidaycolor']

// Highlight bold white on backgound of forum's defined color for date entry type
//
// $hilite_bday_color = 'white';
// $hilite_bday_bkgrd = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bold = true;
// $hilite_bday_class = '';
//
// $hilite_event_color = 'white';
// $hilite_event_bkgrd = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bold = true;
// $hilite_event_class = '';
//
// $hilite_hday_color = 'white';
// $hilite_hday_bkgrd = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bold = true;
// $hilite_hday_class = '';
////////////////////////////////

// Highlight bolded color for date entry type on default backgound
//
$hilite_bday_color = '#'.$modSettings['cal_bdaycolor'];
// $hilite_bday_bkgrd = '';
$hilite_bday_bold = true;
// $hilite_bday_class = 'windowbg3';
//
$hilite_event_color = '#'.$modSettings['cal_eventcolor'];
// $hilite_event_bkgrd = '';
$hilite_event_bold = true;
// $hilite_event_class = 'windowbg3';
//
$hilite_hday_color = '#'.$modSettings['cal_holidaycolor'];
// $hilite_hday_bkgrd = '';
$hilite_hday_bold = true;
// $hilite_hday_class = 'windowbg3';
////////////////////////////////

/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (start)
//
// Non-English Labels, Month and Day Names
//
// To use Month and Day names other than the default on your server,
//   remove the two asterisk '*******' lines (the first starts with '/***'
//   and the second ends '***/') and supply the List Section Labels and the
//   Month and Day names to use per instructions below.
//

/**********************************************************
$list_label_bdays = 'Birthdays';  // Change to labels in language of choice
$list_label_events = 'Events';
$list_label_hdays = 'Holidays';

//
// specify all the day names in desired language
//   if you specify "$first_day = 1;" above, first entry below must be for Monday; e.g:
//      when $first_day = 0;  then $day_names = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//      when $first_day = 1;  then $day_names = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
//  
$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');

//
// specify the month names in desired language
//  
$month_nam = array();
$month_nam['01'] = 'Enero';       
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[date('m',$now)];
//
**********************************************************/
/////////////////////////////////////////////// NON-ENGLISH  LABELS, MONTH & DAY NAMES (end)

//
//  Program Paramters/Switches Section - End
//    (modify below at your own risk!!!)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

$hi_bday_color = '';
if (isset($hilite_bday_color)) $hi_bday_color = 'color:'.$hilite_bday_color.'; ';
$hi_bday_bkgrd = '';
if (isset($hilite_bday_bkgrd)) $hi_bday_bkgrd = 'background-color: '.$hilite_bday_bkgrd.'; ';
$hi_bday_fontwt = '';
if (isset($hilite_bday_bold) && $hilite_bday_bold) $hi_bday_fontwt = 'font-weight:bold; ';

$hi_event_color = '';
if (isset($hilite_event_color)) $hi_event_color = 'color:'.$hilite_event_color.'; ';
$hi_event_bkgrd = '';
if (isset($hilite_event_bkgrd)) $hi_event_bkgrd = 'background-color: '.$hilite_event_bkgrd.'; ';
$hi_event_fontwt = '';
if (isset($hilite_event_bold) && $hilite_event_bold) $hi_event_fontwt = 'font-weight:bold; ';

$hi_hday_color = '';
if (isset($hilite_hday_color)) $hi_hday_color = 'color:'.$hilite_hday_color.'; ';
$hi_hday_bkgrd = '';
if (isset($hilite_hday_bkgrd)) $hi_hday_bkgrd = 'background-color: '.$hilite_hday_bkgrd.'; ';
$hi_hday_fontwt = '';
if (isset($hilite_hday_bold) && $hilite_hday_bold) $hi_hday_fontwt = 'font-weight:bold; ';

if (!isset($class_default)) $class_default = 'windowbg';
if ($class_default == '') $class_default = 'windowbg';

$table_bkgrd = 'class="'.$class_default.'" cellspacing="1"';
if ($bordercolor_gridlines) $table_bkgrd = 'class="bordercolor" cellspacing="'.$gridlines_thickness.'"';

$today = strftime('%d', $now);
$year = date('Y',$now);
$month = date('n',$now);
$nowdate = strftime('%Y-%m-%d', $now);

$month_href = $scripturl . '?action=calendar;year='.$year.';month='.$month;

require_once($sourcedir . '/Calendar.php');

$low_date_base = strftime('%Y-%m-%d', $now - 24 * 3600);
$high_date_base = strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600);

$low_date = ($show_bdays_past || $show_events_past || $show_hdays_past) ? ( ($past_look_behind_period == 0) ? date('Y',$now).'-'.date('m',$now).'-01' : strftime('%Y-%m-%d', $now - (($past_look_behind_period + 1) * 24 * 3600)) ) : $low_date_base;
$high_date = $high_date_base;

$low_date_ts = strtotime($low_date);

if ($show_bdays) {
    $bdays = $show_bdays_past ? calendarBirthdayArray($low_date, $high_date) : calendarBirthdayArray($low_date_base, $high_date);
    ksort($bdays); }

if ($show_events) {
    $events = $show_events_past ? calendarEventArray($low_date, $high_date, false) : calendarEventArray($low_date_base, $high_date, false);
    ksort($events); }

if ($show_hdays) {
    $holidays = $show_hdays_past ? calendarHolidayArray($low_date, $high_date) : calendarHolidayArray($low_date_base, $high_date);
    ksort($holidays); }

$todays_color = isset($color_today) ?'color:'.$color_today.'; ' : '';
$todays_bkgrd = isset($bkgrd_today) ?'background-color:'.$bkgrd_today.'; ' : '';

$stub = '<a class="smalltext" style="'.$todays_color.'font-weight:bold; border:solid 1px black; '.$todays_bkgrd.'padding: 0px 2px 0px 2px;"';

// Highlighted 'Today' Box
if ($date_links_to_posting && allowedTo('calendar_post')) {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.date('j',$now).'</a>'));}
else {
    $days = array($today=>array(NULL,$class_today,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.date('j',$now).'</a>'));}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (start)
//
if ($show_hilites) {
    foreach($order_hilites as $hilite_to_do){
        $flag = strtoupper(substr($hilite_to_do,0,1));

///////////////////////////////////////////////// B-Day Highlighting
        if ($flag == 'B') {
            if ($show_bdays) {
                if ($show_bdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_bday_color . $hi_bday_bkgrd . $hi_bday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_bday_class)) $hilite_bday_class = $class_default;
                    if ($hilite_bday_class == '') $hilite_bday_class = $class_default;
                    foreach($bdays as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_bday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////// Event Highlighting
        if ($flag == 'E') {
            if ($show_events) {
                if ($show_events_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_event_color . $hi_event_bkgrd . $hi_event_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_event_class)) $hilite_event_class = $class_default;
                    if ($hilite_event_class == '') $hilite_event_class = $class_default;
                    foreach($events as $startdate => $value)
                        if(!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_event_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////// Holiday Highlighting
        if ($flag == 'H') {
            if ($show_hdays) {
                if ($show_hdays_to_guests or !$user_info['is_guest']) {
                    $stub = '<a class="smalltext" style="'. $hi_hday_color . $hi_hday_bkgrd . $hi_hday_fontwt .'padding: 0px 2px 0px 2px;"';
                    if (!isset($hilite_hday_class)) $hilite_hday_class = $class_default;
                    if ($hilite_hday_class == '') $hilite_hday_class = $class_default;
                    foreach($holidays as $startdate => $value)
                        if (!isset($days[substr($startdate,8)]) or !is_array($days[substr($startdate,8)])) {
                            if (substr($startdate,0,7) == substr($nowdate,0,7)) {
                                if ($date_links_to_posting && allowedTo('calendar_post')) {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.substr($startdate,8).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                                else {
                                    $days[substr($startdate,8)] = array(NULL,$hilite_hday_class,$stub.' href="'.htmlspecialchars($month_href).'" target="_self">'.sprintf('%d',substr($startdate,8)).'</a>');}
                            }
                        }
                }
            }
        }
////////////////////////////////////////////////////////////////////
    }
}

////////////////////////////////////////////////////////////////////////////// HIGHLIGHTING (end)

$first_of_month = gmmktime(0,0,0,$month,1,$year);
list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));

if (!isset($month_nam['12'])) {
    $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_month));
}

$weekday = ($weekday + 7 - $first_day) % 7;                // adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

$calendar = '<table '.$table_bkgrd.' align="center">'.'<caption >'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).'</caption><tr>';

if (!isset($class_day_names)) $class_day_names = $class_default;
if ($class_day_names == '') $class_day_names = $class_default;
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="'.$class_day_names.'" align="center" valign="middle" style="padding-left: 0px; padding-right: 0px;font-size: x-small;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="'.$class_default.'" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    $daynow = sprintf('%02d',$day);
    $col_width = ' width="14%"';
    if ( ((($weekday+$first_day) % 7) == 0) || ((($weekday+$first_day) % 7) == 0) ) $col_width = ' width="15%"';

    if(isset($days[$daynow]) and is_array($days[$daynow])){
        @list($link, $classes, $content) = $days[$daynow];
        if(is_null($content))  $content  = $daynow;
        $calendar .= '<td'.$col_width.' align="center" valign="middle" '.($classes ? ' class="'.htmlspecialchars($classes).'" style="padding: 0px 0px 0px 0px;font-size: x-small;">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td'.$col_width.' class="'.$class_default.'" align="center" valign="middle" style="padding: 0px 0px 0px 0px;font-size: x-small;"><a class="smalltext"';
        if (((($weekday+$first_day) % 7) == 0) && isset($color_sunday))
            $calendar .= ' style="color:'.$color_sunday.';"';
        if (((($weekday+$first_day) % 7) == 6) && isset($color_saturday))
            $calendar .= ' style="color:'.$color_saturday.';"';
        if ($date_links_to_posting && allowedTo('calendar_post')) {
            $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';}
        else {
            $calendar .= ' href="'.htmlspecialchars($month_href).'" target="_self">'.$day.'</a></td>';}
        }
    }

if($weekday != 7) $calendar .= '<td class="'.$class_default.'" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

foreach($order_lists as $list_to_do){
    $flag = strtoupper(substr($list_to_do,0,1));

if (!isset($align_list_entries)) $align_list_entries = 'center';
if (isset($align_list_entries))
    if ($align_list_entries <> 'left') $align_list_entries = 'center';

if (!isset($list_label_class)) $list_label_class = $class_default;
if ($list_label_class == '') $list_label_class = $class_default;

if (!isset($list_entry_class)) $list_entry_class = $class_default;
if ($list_entry_class == '') $list_entry_class = $class_default;

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if(($flag == 'B') and $show_bdays) {
    if($show_bdays_to_guests or !$user_info['is_guest']) {
        if (!empty($bdays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_bdays_color . ';">'.$list_label_bdays.'</td></tr>';
            $ctr = 0;

            foreach($bdays as $startdate => $bday_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($bday_date as $member)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $birthdate = strtotime($startdate);
                    $text_start = !isset($month_nam['12']) ? date("M j",$birthdate) : substr($month_nam[strftime('%m', $birthdate)],0,3) . date(" j",$birthdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" title="' . $txt[92] . ' ' . $member['name'] . '">' . '<font color="'. $member['color']  .'">' . ( ($nowdate == $startdate) ? '<b>' : '') . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . ( ($nowdate == $startdate) ? '</b>' : '') . '</font>' . '</a>';
                    echo '</td></tr>';
                }

            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if(($flag == 'E') and $show_events) {
    if($show_events_to_guests or !$user_info['is_guest']) {

        if (!empty($events))
        {
            $events_printed = array();
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_events_color . ';">'.$list_label_events.'</td></tr>';
            $ctr = 0;

            foreach ($events as $startdate => $evt_date)
            {

                if (($startdate >= strftime('%Y-%m-%d', $low_date_ts)) && ($startdate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))

                foreach ($evt_date as $event)
                {
                    if (!in_array($event['id'],$events_printed)) {
                        $events_printed[] = $event['id'];
                        $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';

                        $evt_start = strtotime($event['start_date']);
                        $evt_end = strtotime($event['end_date']);
                        $text_start = !isset($month_nam['12']) ? date("M j",$evt_start) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start);
                        $text_end = ($event['start_date'] == $event['end_date'] ? '' : '-'. (substr($event['start_date'],5,2) == substr($event['end_date'],5,2) ? date("j",$evt_end) : (!isset($month_nam['12']) ? date("M j",$evt_end) : substr($month_nam[strftime('%m', $evt_start)],0,3) . date(" j",$evt_start))));

                        $link = $event['topic'] == 0 ? $event['title'] : '<a href="' . $scripturl . '?topic=' . $event['topic'] . '.0' . '">' . $event['title'] . '</a>';

                        echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . $text_end . '</strong></a>';
                        echo ' - ';
                        echo  ( ($nowdate >= $event['start_date']) && ($event['end_date'] >= $nowdate) ) ? '<b>'.$link.'</b>' : $link  ;
                        echo '</td></tr>';
                   }
                }


            }
        }
    }
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if(($flag == 'H') and $show_hdays) {
    if($show_hdays_to_guests or !$user_info['is_guest']) {

        if (!empty($holidays))
        {
            echo '<tr'. (isset($list_label_class) ? ' class="'.$list_label_class.'"' : '') .'><td colspan="7" class="smalltext" align="center" style="font-weight: bold; color: ' . $list_label_hdays_color . ';">'.$list_label_hdays.'</td></tr>';
            $ctr = 0;

            foreach ($holidays as $hDate => $hday)
            {

                if (($hDate >= strftime('%Y-%m-%d', $low_date_ts)) && ($hDate <= strftime('%Y-%m-%d', $now + $modSettings['cal_days_for_index'] * 24 * 3600)))
                {
                $eventdate = strtotime(date("Y").substr($hDate, 4));
                foreach ($hday as $holiday)
                {
                    $class_to_use = isset($list_entry_class) ? ( !is_array($list_entry_class) ? ' class="'.$list_entry_class.'"' : ' class="'.$list_entry_class[($ctr++) % count($list_entry_class)].'"') : '';
                    $text_start = !isset($month_nam['12']) ? date("M j",$eventdate) : substr($month_nam[strftime('%m', $eventdate)],0,3) . date(" j",$eventdate);

                    echo '<tr'.$class_to_use.'><td colspan="7" class="smalltext" style="padding: 0px 0px 0px 0px;" width="100%" align="'.$align_list_entries.'">';
                    echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . substr($startdate,5,2) . '"><strong>' . $text_start . '</strong></a>';
                    echo ' - ';
                    echo $holiday;
                    echo '</td></tr>';
                }

                }

            }
        }
    }
}
}

if ($show_post_event_button) {
        if (allowedTo('calendar_post')) {
            echo '<tr><td colspan="7" class="'.$class_default.'" align="center" valign="middle">';
            echo '<hr/ >';
            echo '<a href="', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">','<br />', create_button('calendarpe.gif', 'calendar23', 'calendar23', 'align="middle"'), '</a>';
            echo '</td></tr>';
    }
}

echo '</table>';


What I want to do is to add it the "POST EVENT" button and to see it at the end of the Block. Can someone tell me how to do it?

Thanks in advance!

Cheers!  :laugh:

PS: Sorry for my english  :D.
Title: Re: SMF Calendar Block
Post by: IchBin on January 09, 2009, 02:00:12 AM
What you're asking for is not really related to the block code snippet. You're asking for this snippet to be included in another customization from the sounds of it. You'd be better off requesting this in the requests board.
Title: Re: SMF Calendar Block
Post by: Herr Inoddorell on January 09, 2009, 03:06:20 AM
Quote from: IchBin™ on January 09, 2009, 02:00:12 AM
What you're asking for is not really related to the block code snippet. You're asking for this snippet to be included in another customization from the sounds of it. You'd be better off requesting this in the requests board.

Oh, I'm sorry, I'm a little newbie here. I'm going to ask about it in the Request board. Thanks anyway ;).
Title: Re: SMF Calendar Block
Post by: MinasC on January 25, 2009, 01:44:54 PM
hello there

i am using this block since my forum was 1.1.3. now i upgraded into 1.1.7 and changed the collation of my database (through smf admin) into utf-8. that caused the block (actually all tp blocks) to appear in ... chinese-like (ÃŽââ,¬ÂÃƒÅ½Ã,µÃŽÃ,¯Ãââ,¬Å¾ÃƒÅ½Ã,µ σÏââ,¬Å¾ÃƒÅ½Ã,·ÃŽÃ,½ ΈÎÃ,ºÃŽÃ,¸ÃŽÃ,µÃÆ’ÃŽÃ,·). i need to say that i had translated the block into greek. is there any way to make it show in greek again?

thnx in advance.
Title: Re: SMF Calendar Block
Post by: G6Cad on January 25, 2009, 02:39:31 PM
You will have to update your TP language files to utf8 greek aswell,

Seems we dont have that available though i know there are a translation package made.

Send a PM to agridoc and ask if he can provide you with the correct language files for tp.
he should have the package available here to IMHO but it seems it's not  :-\
Title: Re: SMF Calendar Block
Post by: MinasC on January 25, 2009, 03:26:55 PM
it's not a matter of tp language files. the only letters not showing correctly are those i translated inside the code of the block (e.g. translated the dyas and months from english to greek). i had to re-translate them in order to appear correctly. oh, and my database didn't transform into utf-8 even though i did so through smf admin maintenance.  i checked it through php admin. i don't know why... strange...
Title: Re: SMF Calendar Block
Post by: Yahmez on March 22, 2009, 01:41:36 AM
I found this code in the SMF forum
It works great for me and is linked to the SMF calendar
/*
Calender DIN1031 Version 08-11-2008-1
This is a customizable calendar php block
It will show a calendar, and add the Today Events, Holidays and Birthdays.
Normal it's programmed and tested for SMF 1.1.X
I don't use any SSI.php, because all data that needed is loaded.
*/
global $scripturl, $modSettings, $sourcedir, $txt;

//With that you can start the calander on a other day
//-1 = Start on Saturaday, 0 = Start on Sunday, 1 = Start on Monday, 2 = Start on Thusday...
$first_day = 0;

//How long should the day, if the number higher 3 than the complete dayname will be shown
$day_name_length = 0; //0 is short day name 1 is full day name :)

//The background color of days with Events, birthdays or holidays, you can use css colors
$color_background_items_mixed = 'lightblue';
$color_background_items_event = 'lightblue';
$color_background_items_birthday = 'lightblue';
$color_background_items_holiday = 'lightblue';

//The textcolor of days with Events, birthdays or holidays, you can use css colors
$color_text_items_mixed = 'steelblue';
$color_text_items_event = 'steelblue';
$color_text_items_birthday = 'steelblue';
$color_text_items_holiday = 'steelblue';

//The Color of the todays background / text
$color_background_today = 'white';
$color_text_today = 'green';

//The Textcolor for the standard days
$color_text = 'steelblue';

//The Textcolor for the Sundays
$color_text_sunday = '#C00000';

//If you have a diffrent calender you can change the link to it here
$month_href = $scripturl . '?action=calendar';

//What should the callendar show?
$show_events = 1; //0 No, 1 Yes
$show_birthdays = 1; //0 No, 1 Yes
$show_holidays = 1; //0 No, 1 Yes
//Show the single events and items of the day :)
$show_today = 1; //0 No, 1 Yes

//Okay please don't do anything here if you not now what you do
/**************************************************************/
// You can't do anything if the calendar is off!
if (empty($modSettings['cal_enabled']))
   fatal_lang_error('calendar_off', false);

$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$year = date("Y",$now);
$month = date("n",$now);
$monthtxt = ucfirst(strftime("%B",$now));
$days = array();
$pn = array();

$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()
*/

//retrieve this month events, holydays and birthdays
$days_in_month = gmdate('t',$first_of_month);
include_once($sourcedir . '/Calendar.php');
$low_date = $year.'-'.$month.'-01';
$high_date = $year.'-'.$month.'-'.$days_in_month;
$can_post_calendar = allowedTo('calendar_post');
$calendarDataToday = array('events' => array(), 'birthdays' => array(), 'holidays' => array());
$todayDate = date("Y-m-d", time());

//add important days to the days array
if(!empty($show_events)) {
   $events = calendarEventArray($low_date, $high_date);
   foreach($events as $startdate => $event) {
      //This insert the today events if they exist
      if($todayDate == $startdate)
         $calendarDataToday['events'] = $event;
      $cday = (int) substr($startdate,8,2);
      //We must select between create or only show!
      $href_calendar = $can_post_calendar && $cday >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$cday : $scripturl.'?action=calendar';
      $days[$cday] = '<a class="smalltext" style="color: '.$color_text_items_event.'; font-weight: bold; background-color: '.$color_background_items_event.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$cday.'</a>';
   }
}
//Add holidays into the day array?
if(!empty($show_birthdays)) {
   $birthdays = calendarBirthdayArray($low_date, $high_date);
   foreach($birthdays as $startdate => $birth) {
      //This insert the today events if they exist
      if($todayDate == $startdate)
         $calendarDataToday['birthdays'] = $birth;
      $cday = (int) substr($startdate,8,2);
      //We must select between create or only show!
      $href_calendar = $can_post_calendar && $cday >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$cday : $scripturl.'?action=calendar';
      //Mixed color?
      $text_color = !empty($days[$cday]) ? $color_text_items_mixed : $color_text_items_birthday;
      $background_color = !empty($days[$cday]) ? $color_background_items_mixed : $color_background_items_birthday;
      $days[$cday] = '<a class="smalltext" style="color: '.$text_color.'; font-weight: bold; background-color: '.$background_color.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$cday.'</a>';
   }
}
//Add holidays into the day array?
if(!empty($show_holidays)) {
   $holidays = calendarHolidayArray($low_date, $high_date);
   foreach($holidays as $startdate => $holiday) {
      //This insert the today events if they exist
      if($todayDate == $startdate)
         $calendarDataToday['holidays'] = $holiday;
      $cday = (int) substr($startdate,8,2);
      //We must select between create or only show!
      $text_color = !empty($days[$cday]) ? $color_text_items_mixed : $color_text_items_holiday;
      $background_color = !empty($days[$cday]) ? $color_background_items_mixed : $color_background_items_holiday;
      $href_calendar = $can_post_calendar && $cday >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$cday : $scripturl.'?action=calendar';
      $days[$cday] = '<a class="smalltext" style="color: '.$text_color.'; font-weight: bold; background-color: '.$background_color.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$cday.'</a>';
   }
}

//So Todays it's an diffrent color :D
$href_calendar = $can_post_calendar ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today : $scripturl.'?action=calendar';
$days[$today] = '<a class="smalltext" style="color: '.$color_text_today.'; font-weight: bold; border: solid 1px black; background-color: '.$color_background_today.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$today.'</a>';

//Wellcome to the smf way of Day building with existing Language strings :D
$day_names = $txt['days'];
$day_names_short = $txt['days_short'];
//So lets see $firstday = 0 means sunday this is the first day :)
//if there is a higher number than i need to resort them
//negativ values can also be used :)
if(!empty($first_day)) {
   if($first_day < 0)
      $first_day = 7-(abs($first_day)%7);
   else
      $first_day = ($first_day%7);
}
if(!empty($first_day)) {
   $old = $day_names;
   $old_s = $day_names_short;
   $day_names = array();
   $day_names_short = array();
//Create the new day order :)
   for($n=0; $n<7; $n++) {
      $c = (($first_day+$n)%7);
      $day_names[$n] = $old[$c];
      $day_names_short[$n] = $old_s[$c];
   }
}

list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; //adjust for $first_day
$title = $monthtxt.' '.$year;  //This is the SMF Text string, so it should be corrected for ut8 or iso

/* Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03 */
$calendar = '
<table>
   <caption>'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title)."</caption>
   <tr>";

//Put out the Daynames :)
foreach($day_names as $k => $d)
   $calendar .= '
      <th class="smalltext" abbr="'.$d.'">'.(!empty($day_name_length) ? $d : $day_names_short[$k]).'</th>';
$calendar .= "
   </tr>
   <tr style=\"text-align:right;\">";

if($weekday > 0) $calendar .= '
      <td class="smalltext" colspan="'.$weekday.'"> </td>'; //initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
   if($weekday == 7){
      $weekday   = 0; //start a new week
      $calendar .= "
   </tr>
   <tr style=\"text-align:right;\">";
   }
   if(isset($days[$day])){
      $calendar .= '
      <td>'.$days[$day].'</td>';
   }
   else
   {
      $href_calendar = $can_post_calendar && $day >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day : $scripturl.'?action=calendar';
      $calendar .= "
      <td class=\"smalltext\" style=\"padding-right:4px;\"><a";
      if(((($weekday+$first_day) % 7)==0))
      {
         $calendar .= ' style="color:'.$color_text_sunday.';"';
      }
      $calendar .= " href=\"".$href_calendar."\" target=\"_self\">$day</a></td>";
   }
}
if($weekday != 7) $calendar .= '
      <td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; //remaining "empty" days

echo $calendar.'
   </tr>';


if (!empty($show_today) && (!empty($calendarDataToday['events']) || !empty($calendarDataToday['birthdays']) || !empty($calendarDataToday['holidays']))) {

   if(!empty($calendarDataToday['holidays'])){
      echo '
   <tr><td>
      <hr />
   </td>
   <td colspan="5" class="smalltext" align="center" style="color: ' . $color_text_items_holiday . ';">
      <b>Holidays</b>
   </td><td>
      <hr />
   </td>
   </tr>
   <td colspan="7" class="smalltext">';
      foreach( $calendarDataToday['holidays'] as $holiday )
         echo '
            ', $holiday['name'], '<br />';
      echo '
      </td></tr>';   
   }

   if(!empty($calendarDataToday['birthdays'])){
      echo '
   <tr><td>
      <hr />
   </td>
   <td colspan="5" class="smalltext" align="center" style="color: ' . $color_text_items_birthday . ';">
      <b>Birthdays</b>
   </td><td>
      <hr />
   </td></tr>
      <td colspan="7" class="smalltext">';
      foreach( $calendarDataToday['birthdays'] as $member )
         echo '
            <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', '<br />';
      echo '
   </td></tr>';   
   }

   if(!empty($calendarDataToday['events']))
   {
      echo '
      <tr><td>
         <hr />
      </td>
      <td colspan="5" class="smalltext" align="center" style="color: ' . $color_text_items_event . ';">
         <b>Events</b>
      </td><td>
         <hr />
      </td></tr>
      <td colspan="7" class="smalltext">';
      foreach ($calendarDataToday['events'] as $event)
      {
         if ($event['can_edit'])
            echo '
            <a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
         echo '
         ' . $event['link'] . '<br />';
      }
   }
  echo '
     </td></tr>';
}

echo '
</table>';
Title: Re: SMF Calendar Block
Post by: Cero on April 19, 2009, 07:03:22 AM
Quote from: Ken. on December 10, 2008, 04:19:38 PM
Don't know what the problem might be but for my display the dates show correctly.

Ken, I think I found the problem...

Look for:
$eventdate = strtotime($row['eventDate']);

And replace with:
$eventdate = strtotime(date("Y").substr($row['eventDate'], 4));


I had the same problem and I believe this fixed it.  Be sure to edit your recurring dates back to the year 0004 from 2004 if you changed them.  Changing the year to 2004 simply changes the date from a recurring date to a static date with a year of 2004.

I have attached the edited code.
Title: Re: SMF Calendar Block
Post by: Phil Serna on September 18, 2009, 03:01:49 AM
Quote from: Ken on May 16, 2008, 05:14:24 PM
magz, this is the calendar code that's in use on my site, it works OK for me but it may or may not work as expected for your site.


I don't remember who wrote this version but it came from this topic.

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2; // Change for more letters

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$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_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

/////////////////////////////////////////////////////////////////
//   CALENDAR SECTION
//
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    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 class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $birthdate = strtotime($row['birthdate']);

        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';


thank u! something that i was looking for!
Title: Re: SMF Calendar Block
Post by: onicat on April 11, 2010, 09:03:34 PM
I was wondering if there was a version of this code that works with SMF 2.0?
Since I have updated my test site, the Calendar Code doesn't work. I am thinking maybe this has something to do with the fact that there is not a recent version of Repeating Calendar Events for SMF.

Does anybody have any idea's or suggestions?
Title: Re: SMF Calendar Block
Post by: ZarPrime on April 12, 2010, 09:13:16 PM
Are you using TinyPortal?  What version?  In fact, so that we understand everything we need to about your site, Please Read and Follow the Posting Guidelines and be sure to use the posting template at the bottom of that post (http://www.tinyportal.net/index.php/topic,581).

ZarPrime
Title: Re: SMF Calendar Block
Post by: othg_weasel on April 13, 2010, 04:37:09 PM
Quote from: ZarPrime on April 12, 2010, 09:13:16 PM
Are you using TinyPortal?  What version?  In fact, so that we understand everything we need to about your site, Please Read and Follow the Posting Guidelines and be sure to use the posting template at the bottom of that post (http://www.tinyportal.net/index.php/topic,581).

ZarPrime

If your using smf 2.0 rc3 and tp 1.0 b5-1 this code should work thanks to BlueSteel. It also pulls up coming events.

global $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 0px 0px 0px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';
Title: Re: SMF Calendar Block
Post by: mariusfv on May 30, 2010, 02:45:48 PM
For TP 0.98 don't matter what calendar script i use...the used time is server time and always behind  5 hours...due the server time...
And is linked to smf calendar that work ok...and show time corectly... always.
Solutions ?
Title: Re: SMF Calendar Block
Post by: ZarPrime on May 30, 2010, 04:45:13 PM
mariusfv,

Each of your members, in the "Look and Layout" preferences of their profile, has the ability to auto detect the "Time Offset:" for their local computer from the server tme.

ZarPrime
Title: Re: SMF Calendar Block
Post by: mariusfv on May 30, 2010, 05:13:24 PM
Yes...but in Block the date it change after 5 hours !(server time) i test this with my account ....and when my time is 12.30(night) the date must change in block but it change only after 5 hours....try clear coookie...log out etc....so in block is problem....it change only after 5 hours....server time...
Title: Re: SMF Calendar Block
Post by: pvcblue on May 30, 2010, 09:45:06 PM
Quote from: mariusfv on May 30, 2010, 05:13:24 PM
Yes...but in Block the date it change after 5 hours !(server time) i test this with my account ....and when my time is 12.30(night) the date must change in block but it change only after 5 hours....try clear coookie...log out etc....so in block is problem....it change only after 5 hours....server time...

Have you tried setting your server time to your time in the Admin>Features and Options>Overall time offset   ???
Title: Re: SMF Calendar Block
Post by: ZarPrime on May 31, 2010, 05:58:20 AM
mariusfv,

Please post the exact code you are using here so that one of us can try it on one of our test forums.  Please use the bbc code tags (#) to post the code.

ZarPrime
Title: Re: SMF Calendar Block
Post by: mariusfv on May 31, 2010, 08:34:40 PM
Edit:
Problem Solved !

In Overall time offset +8 solve the problem(that was difference between server time and forum time) !

10x for information !
Title: Re: SMF Calendar Block
Post by: Smythe on January 22, 2013, 04:24:03 AM
Listed below is the code that I am using...

I would like to have the calendar block NOT show the holidays.... just events ...that's it.... I know how to remove the birthdays.... for the life of me I can't get the holidays out of there...thanks in advance ( also if you know how i could get it to show one event per line vs. all of them in a row separated by comas.... that would be great too....)

global $scripturl;
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 0px 0px 0px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$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_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #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="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
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 class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';
Title: Re: SMF Calendar Block
Post by: IchBin on January 22, 2013, 05:31:11 AM
This is the section for events that you can comment out or remove:
if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}


To change the output of the birthdays you have to add some code. This isn't tested, so let me know if there's any problems.
Find this:
if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}


Replace with this:
$birthdayList = ssi_todaysBirthdays('array');

if ($birthdayList) {
foreach ($birthdayList as $member)
echo '
<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">' . $member['name'] . '</span>' . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? '<br />' : '');
}
Title: Re: SMF Calendar Block
Post by: Smythe on January 23, 2013, 12:50:45 AM
I think maybe I didn't explain my request enuff....

NO Birthdays...
NO Holidays

ONLY Events...

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Ftantalusls.com%2Fthemes%2Fostara1%2Fimages%2FFAQ%2FCalendar.png&hash=27650d26bfb038c545b07781e8299ce0b5af66e9)

Would like Ground Hogs Day and Valentines Day to go away....

also would like to have the "Upcoming Events" displayed once... I think I got that one but then would like to have the events listed one per line

test event 1
test event 2
test event 3

vs test event 1, test event 2, test event 3... etc

thanks for the quick response on my prior request...
Title: Re: SMF Calendar Block
Post by: ZarPrime on January 23, 2013, 04:36:31 AM
All of these are valid ssi calls ...


The last one is a combination of all 3 of the first.  If you only want the events then just use the third one.  The ssi functions, when using the default echo, will display each one right after the other one in a single line.  If you want each event to be on a separate line, you will have to use array rather than echo and write the code with a line break accordingly.

ZarPrime
Title: Re: SMF Calendar Block
Post by: Smythe on January 23, 2013, 01:18:05 PM
Sorry to be a pain... I am not sure how to write the code for the array for calendar events..

I would greatly appreciate it if someone much smarter then I would lend a hand....lol ... smf 2.0.2

Thanks so much for the help thus far... it is greatly appreciated
Title: Re: SMF Calendar Block
Post by: ZarPrime on January 24, 2013, 12:07:17 AM
Smythe,

I don't really have time to work on this right now but I have a solution.  Why don't you try the code that I put in this post --> http://www.tinyportal.net/index.php?topic=32717.msg262975#msg262975

Normally it's much easier to help someone if they have followed our Posting Guidelines (http://www.tinyportal.net/index.php?topic=581) to tell us about their site so that we know what versions of SMF and TinyPortal they are using but you didn't do that.  Therefore, I have to assume that you are using SMF 2.x and TinyPortal 1.0 Final.  If that is the case, the code in that post will work for you though you might have to adjust the parameters.

In the future, if you would be so kind, please give us the information we need to help you when asking for support.  This is the information we will need ...


[b]Link to my forum:[/b] http://www.yourdomain.com/forum/
[b]SMF version:[/b] SMF ver. here
[b]TP version:[/b] TP ver. here
[b]Default Forum Language:[/b] Your Default Forum Language here
[b]Theme name and version:[/b] Theme name here
[b]Browser Name and Version: [/b] Browser name/version here
[b]Mods installed:[/b] Mods listed here
[b]Related Error messages:[/b] Error message here


ZarPrime
Title: Re: SMF Calendar Block
Post by: Smythe on January 24, 2013, 01:41:47 AM
Thank you for your assistance... the post you linked worked fine... edited a few things ...appreciate the help.

Is there a way to enlarge the calendar portion ?? after that I wont ask any more ... I swear.... lol

Thanks again your efforts are greatly appreciated
Title: Re: SMF Calendar Block
Post by: ZarPrime on January 24, 2013, 01:53:04 AM
Hmmm, I'm not sure what you mean.  There is a couple of places in the code where the "font-size:" is "x-small" and you might be able to play with that to see if you can make it slightly bigger.  However, if you make it too big, it might not fit very well in the left panel.  Depends on how big your left panel is I guess.  This is the same mini-calendar that we use on our FrontPage here and it looks pretty good like it is, IMHO.

ZarPrime
Title: Re: SMF Calendar Block
Post by: ZarPrime on January 24, 2013, 01:58:26 AM
I just changed the font-size  on the mini-calendar on our FP from x-small to small and it made it a little bigger so I guess that would be OK.

ZarPrime

ZP edit:  OK, I just changed it again from small to medium and it still looks OK but again, it depends on the width of your left panel whether it will fit or not.
Title: Re: SMF Calendar Block
Post by: ZarPrime on January 24, 2013, 02:04:35 AM
OK, I just changed the font size on the mini-calendar on our FP to medium as I said in my last post.  Is this what you are talking about?

ZarPrime
Title: Re: SMF Calendar Block
Post by: Smythe on January 25, 2013, 02:18:56 AM
Link to my forum: http://www.tantalusls.com
SMF version: 2.0.2
TP version: 1.0
Default Forum Language: UTF8 ... English
Theme name and version: Ostara 1
Browser Name and Version: IE & Firefox
Mods installed: A Bunch... to much to list but should be N/A

Sorry to be a pain.... but I figured I would go about this the correct way this time...

Using the same Block here.... is there a way to make the BG transparent... no grid for the calendar with the just the numbers showing.... also the Highlighted colors for the Events makes them almost impossible to read.... how could I go about changing the Text color.

...........

Would it be possible to make just an event block that works the same as the event section ... no calendar ... just the events. I looked around and the one I did find had the date format kinda off... I like the way the date is here on the block you linked me to earlier....

I am trying to have examples of both block ... with calendar and without.... with color and transparent....
Title: Re: SMF Calendar Block
Post by: ZarPrime on January 25, 2013, 09:02:29 AM
Quote from: Smythe on January 25, 2013, 02:18:56 AM
Sorry to be a pain.... but I figured I would go about this the correct way this time...

Thank you.  It makes it so much easier to see what you are trying to do when we can actually see it in action on your site.  You're using quite an interesting theme, lot's of transparency.  It's not too difficult on these first two so let's look at those first.  First of all, make a copy of the code you are currently using in the block and stick it into a text file on your computer so that you can revert to it in case you make a mistake.  Likewise, save a copy of the css file I mention below where editing is needed for the same reason in case you don't like the result.

Quote from: Smythe on January 25, 2013, 02:18:56 AM
is there a way to make the BG transparent... no grid for the calendar with the just the numbers showing....

The BG for this code uses a class in the index.css for the theme around line 418 in the file http://testls.sytes.net/Themes/ostara1/css/index.css?fin20 and removing that BG color will actually make the backgrounds transparent.  However, doing this may make other locations on the site take on that transpanency as well so you will want to check the site to make sure it's what you want to use.

Code (Find This) Select
/* Alternating backgrounds for posts, and several other sections of the forum. */
.windowbg, #preview_body, .windowbg a:link, .windowbg a:visited
{
color: #000000;
background: #bbd7ff;
}


Code (Change to This) Select
/* Alternating backgrounds for posts, and several other sections of the forum. */
.windowbg, #preview_body, .windowbg a:link, .windowbg a:visited
{
color: #000000;
}

   
Quote from: Smythe on January 25, 2013, 02:18:56 AM
also the Highlighted colors for the Events makes them almost impossible to read.... how could I go about changing the Text color.

Again, Event, Holiday, and Birthday colors in SMF 2.x are also controlled by the same index.css file for the theme noted above around line 560.  So, if you want to change that yellow color to something like a dull red color which looks pretty good

Code (Find This) Select
.event
{
color: #FF9;
}


Code (Change to This) Select
.event {
    color: #E4341B;
}


Quote from: Smythe on January 25, 2013, 02:18:56 AM
Would it be possible to make just an event block that works the same as the event section ... no calendar ... just the events. I looked around and the one I did find had the date format kinda off... I like the way the date is here on the block you linked me to earlier....

Well, yeah, you could do this by commenting out the parts of the code that renders the actual calendar part.  However, be aware that clicking the links in the calendar actually take your members to the actual SMF calendar for that month whereas clicking the link in the actual event below the calendar will take your member to the topic where the event is discussed.  For instance, clicking the "30" in the January calendar will take you to that SMF calendar and clicking the "Primary Fight: Ifrit" link will take you to that topic (http://www.tantalusls.com/index.php?topic=36.0).  If removing the calendar rendering is something you really want to do, try commenting out the code for the block that renders the calendar yourself and see if you can figure it out.  If you can't figure it out, let me know and I will take a further look at it.

Why do I want you to try doing this yourself?  Well, because our job here is not really to do things for people but to show them how to do it themselves.  In the process, hopefully, we can teach you something about php, which is ultimately our goal. ;)

ZarPrime
Title: Re: SMF Calendar Block
Post by: Kerry on August 26, 2013, 12:21:40 PM
Is there a smaller font size than "smalltext" so that the calendar will fit in the normal sized left block?
For example: http://www.comcom121.org/csgforum/index.php?action=forum (http://www.comcom121.org/csgforum/index.php?action=forum) I have to scroll horizontally to see all the days.

Kerry
Title: Re: SMF Calendar Block
Post by: ZarPrime on August 26, 2013, 02:29:34 PM
Kerry,

Could you post the code you are using in the block on your site?  Please use the code tags (#) to attach the code, like this ...

[code]
Code here
[/code]


Thanks,
ZarPrime