TinyPortal

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

Title: SMF Calendar Block
Post by: bloc on September 03, 2005, 04: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. :)

Code: [Select]
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, 05:37:50 AM
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, 08:32:49 AM
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, 09:09:34 AM

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, 09:29:10 AM
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, 01: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, 01: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, 04: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, 12: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, 04: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

Code: [Select]
$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, 05:42:03 AM
Great work, pcw. :)
Title: Re: Calendar in a php-block
Post by: Miraenda on September 07, 2005, 06:35:29 AM
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, 07:45:12 AM
using pcw's version i get this when i do the php test:
Code: [Select]
$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, 08:06:32 AM
Search for
Code: [Select]
$days = array($today=>array(NULL,NULL,\'\'.$today.\'\')); in your code and replace it with
Code: [Select]
$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, 09:03:16 AM
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.

Code: [Select]
$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, 09:36:45 AM
also, with the above code entered, when i click the PHP-test button, to check for errors, it outputs this code:
Code: [Select]
$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=\'.$month.\';year=\'.$year.\';day=\'.$today.\'\") within that specific field for php test.
Title: Re: Calendar in a php-block
Post by: crip on September 07, 2005, 09:52:57 AM
Cool calendar..I like it..thanks guys :)

Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 10:16:49 AM
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, 10:30:36 AM
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, 10:38:24 AM
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, 11:06:52 AM
can u give ma a link to u'r TP ?
Title: Re: Calendar in a php-block
Post by: Moocat on September 07, 2005, 11:09:03 AM
sent in PM :)
Title: Re: Calendar in a php-block
Post by: pcw on September 07, 2005, 11:12:40 AM
^^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, 11:13:35 AM
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, 01:04:27 PM
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??...

Code: [Select]
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, 01:18:15 PM
$scripturl is defined in ./Sources/QueryString.php
Code: [Select]
$scripturl = $boardurl . '/index.php';that is included on top of ./index.php
Code: [Select]
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, 01: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, 01: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, 01:44:17 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, 01: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, 01:48:52 PM
Search for
Code: [Select]
<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, 01: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, 01: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, 01: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, 02: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, 02: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, 03:33:13 AM
Its in TPortalBlocks.template.php.

And the "scripturl" error can be solved by adding above the calendar code:
Code: [Select]
  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, 10:47:37 AM

the "scripturl" error can be solved by adding above the calendar code:
Code: [Select]
  global $scripturl;

thanks bloc!... error free :)
Title: Re: Calendar in a php-block
Post by: redshark on September 13, 2005, 10:07:23 AM
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, 01: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 13, 2005, 08:02:19 PM
that would definitely be awesome :)
Title: Re: Calendar in a php-block
Post by: redshark on September 13, 2005, 09:53:54 PM
Many thx Bloc  8)
Title: Re: Calendar in a php-block
Post by: Kindred on October 02, 2005, 06:25:11 AM
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 03, 2005, 09:46:42 PM
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 03, 2005, 10:35:48 PM
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, 03: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, 07:19:40 AM
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, 08:00:36 AM
I just call him ICH ;)
Title: Re: Calendar in a php-block
Post by: MikeEnIke on October 04, 2005, 01: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, 01: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, 01: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 29, 2005, 09:22:01 PM
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, 06:04:19 AM
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, 06:14:32 AM
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, 07:06:23 AM
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, 07:12:22 AM
No...I am working on that though.
Title: Re: Calendar in a php-block
Post by: Skhilled on November 02, 2005, 07:18:44 AM
I trust you'll succeed as usual!   ;D
Title: Re: Calendar in a php-block
Post by: elpvn on November 15, 2005, 11:50:41 AM
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, 12: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 15, 2005, 08:34:21 PM
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 29, 2005, 07:56:28 PM
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):
Code: [Select]
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 29, 2005, 08:41:35 PM
good job Bloc  8)

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


Edit - Thanks!  :)

Code: [Select]
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, 11:13:05 AM
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, 12: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, 12: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, 02:53:22 PM
Sorry, I wasn't thinking when I posted that.
change the code in your block.

Code: [Select]
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, 03:27:12 PM
thanks IchBin.....that was the fix i needed!
Title: Re: Calendar in a php-block
Post by: rbh on January 18, 2006, 06:26:05 PM
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 18, 2006, 08:15:47 PM
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, 02: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, 03:12:49 PM
I actually added this to my stylesheet:

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

and changed all the classes in the snippet from:

Code: [Select]
class="smalltext"

to:

Code: [Select]
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, 12:03:00 AM
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, 01:23:24 AM
Anyone can help?
Title: Re: Calendar in a php-block
Post by: AussieBill on March 01, 2006, 03: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, 03:36:02 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...

Code: [Select]
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, 04: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 01, 2006, 11:47:43 PM
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, 09:07:22 AM
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.

Code: [Select]
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 04, 2006, 10:44:23 PM
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.

Code: [Select]
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, 11:15:08 AM
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 09, 2006, 08:26:16 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, 06:50:58 AM
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, 06:19:19 AM
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, 07:18:56 AM
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, 11:06:44 AM
This Calendar works great! Thanks
Title: Re: Calendar in a php-block
Post by: jackfolla on March 22, 2006, 11:23:47 AM
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, 10:48:09 AM
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.


Code: [Select]
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>';

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, 12: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, 01:34:59 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 28, 2006, 09:38:51 PM
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...

Code: [Select]
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 28, 2006, 11:11:31 PM
But sunday is not on the left :(
Title: Re: Calendar in a php-block
Post by: TwinsX2Dad on March 28, 2006, 11:20:36 PM
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, 01: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, 10:52:50 AM
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).'[/url]');
   
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).'[/url]');

$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.'[/url]');
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.'[/url]');


$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.'[/url]' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'[/url]' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $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.'[/url]' : $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[/url]</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'] . ')' : '', '[/url]', '
';
      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;">*[/url] ';
         echo '
         ' . $event['link'] . '
';
      }
   }
  echo '</td></tr>';
}

echo '</table>';
Title: Re: Calendar in a php-block
Post by: dkaye315 on April 14, 2006, 11:11:30 AM
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:

Code: [Select]
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:)

Code: [Select]
$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, 01: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, 03: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, 02: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, 05:44:27 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:

Code: [Select]
<table align=center>

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

Scroll up Crip, bluesteel gave the answer:

Quote
lol 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, 07:34:00 AM
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, 08:36:07 AM
Thanks sdl, ;D
i downloaded your FlashClocks. ;)
Title: Re: Calendar in a php-block
Post by: dkaye315 on April 18, 2006, 02:18:07 PM
Hey crip ... here's the code I was able to successfully integrate into a php-block (originally posted by Roarin):

Code: [Select]
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, 03: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, 03:58:41 PM
Thanks Kaye ;)
Title: Re: Calendar in a php-block
Post by: thoraxe on May 03, 2006, 01: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:
Code: [Select]
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, 02: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:

Code: [Select]
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 03, 2006, 05:15:10 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, 08:58:30 AM
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, 09:54:46 AM
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, 10:29:50 AM
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, 10:53:39 AM
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 13, 2006, 11:28:16 PM
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 14, 2006, 06:52:06 PM
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 14, 2006, 10:14:13 PM
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 14, 2006, 11:05:37 PM
Not sure which code you use, but this one works for me.

Code: [Select]
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 14, 2006, 11:34:21 PM
http://xarcell-studios.com/TagWorld/frames/calendar/calendar.php
Title: Re: Calendar in a php-block
Post by: RoarinRow on May 15, 2006, 01:36:00 PM
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 17, 2006, 05:40:15 PM
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, 02: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, 10:48:11 AM
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, 07:39:58 AM
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 09, 2006, 09:48:37 PM
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 12, 2006, 09:16:29 PM
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:

Code: [Select]
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 12, 2006, 10:43:59 PM
Thanks I am using it now -
Title: Re: Calendar in a php-block
Post by: iwyen on June 14, 2006, 12: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 15, 2006, 09:04:12 PM
@ 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;

Code: [Select]
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 15, 2006, 09:10:05 PM
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 15, 2006, 09:38:10 PM
Very cool enhancements  :up:
Title: Re: Calendar in a php-block
Post by: True Knight on June 16, 2006, 05:56:46 AM
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, 03: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, 03: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 18, 2006, 11:57:23 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
Code: [Select]
$first_day = 0;And you have to change 0 to 1
Code: [Select]
$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, 12: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, 10:25:39 AM
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, 10:33:37 AM
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, 11:20:54 AM
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, 04: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, 02: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, 02: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 22, 2006, 08:36:02 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, 02: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, 06:00:02 AM
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, 07:28:14 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, 08:21:00 AM
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:

Code: [Select]
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, 03: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.

Code: [Select]
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, 03: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, 04: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, 04: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, 04:23:26 PM
What Browser do you use to check it?
Title: Re: Calendar in a php-block
Post by: Xarcell on June 24, 2006, 05:12:30 PM
Works in both IE and FF. They look indentical too...
Title: Re: Calendar in a php-block
Post by: URPG on June 24, 2006, 06:01:01 PM
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 24, 2006, 06:19:25 PM
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, 03: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, 08:52:58 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 16, 2006, 09:06:40 PM
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 06, 2006, 10:39:07 PM
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, 09:40:26 AM
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.

Code: [Select]
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, 11:12:19 AM
Very cool londonhogfan  :up:
Title: Re: Calendar in a php-block
Post by: Jump1979man on August 07, 2006, 02: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, 02: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, 02:46:10 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, 12: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 15, 2006, 07:39:23 PM
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, 11:56:46 AM
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, 12: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, 12: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, 02:25:59 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! 

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, 02: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:
Code: [Select]
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, 02:38:32 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.

Code: [Select]
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.

Code: [Select]
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 21, 2006, 11:13:00 PM
oops, what am i talking about?  i think the version i'm using now does in fact show the date.  Try this:
Code: [Select]
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 August 31, 2006, 10:47:01 PM
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 August 31, 2006, 10:50:29 PM
excellent :D now how about sharin n a live preview
Title: Re: Calendar in a php-block
Post by: RoarinRow on August 31, 2006, 10:56:35 PM
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, 12: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, 02: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, 07:32:43 AM
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, 08:41:50 AM
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.

Code: [Select]

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, 10:03:58 AM
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, 12: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, 02: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.

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, 03: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, 09:26:37 AM
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, 04:15:13 PM
I took the code from rafynet and put after the global declaration this :

Code: [Select]
$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 05, 2006, 05:22:02 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.'[/url]'));
Title: Re: Calendar in a php-block
Post by: Svaha on September 06, 2006, 03:28:12 AM
I took the code from rafynet and put after the global declaration this :

Code: [Select]
$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 : :)

Code: [Select]
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, 02: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
Quote
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.'[/url]'));

         $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.'[/url]' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'[/url]' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $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.'[/url]' : $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[/url]</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 06, 2006, 05:14:40 PM
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:

Code: [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; // 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 06, 2006, 05:35:58 PM
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:

Code: [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; // 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 06, 2006, 05:39:31 PM
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 06, 2006, 05:52:23 PM
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 06, 2006, 05:53:09 PM
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 06, 2006, 05:59:51 PM
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 06, 2006, 06:01:23 PM
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 06, 2006, 06:06:00 PM
Quote
Hold 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 06, 2006, 06:24:23 PM
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:

Code: [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>'.'<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 06, 2006, 06:32:09 PM
Yup that did it. :up: Much appriciated, thx!  ;)
Title: Re: Calendar in a php-block
Post by: daftdate on September 06, 2006, 06:56:12 PM
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 06, 2006, 07:06:05 PM
In his ssi_rafy_todaysBirthdays function,

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

Replace with:
Code: [Select]
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 06, 2006, 07:10:03 PM
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 06, 2006, 07:11:38 PM
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 06, 2006, 07:14:16 PM
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, 11:16:10 AM
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 13, 2006, 07:49:14 PM
Could you add a white background to this?
Title: Re: Calendar in a php-block
Post by: jacortina on September 13, 2006, 08:03:47 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.


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:
Code: [Select]
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';
To:
Code: [Select]
$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 13, 2006, 08:06:24 PM
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 13, 2006, 08:17:04 PM
Thank you jacortina you have helped me twice tonight, thanks alot.
Title: Re: Calendar in a php-block
Post by: jacortina on September 13, 2006, 08:19:57 PM
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:

Code: [Select]
/////////////// 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 13, 2006, 08:35:52 PM
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, 06:05:28 AM
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, 03: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, 03:44:32 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, 01: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, 07:38:59 AM
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, 07:45:52 AM
Great, thanks for that :)
Title: Re: Calendar in a php-block
Post by: jacortina on September 22, 2006, 07:48:17 AM
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:

Code: [Select]
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, 11:13:35 AM
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, 11:41:08 AM
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:
Code: [Select]
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

Replace with:
Code: [Select]
$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, 11:49:35 AM
Perfect. That worked a treat, thank you :)
Title: Re: Calendar in a php-block
Post by: truelight5 on October 04, 2006, 12: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, 12: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, 01:08:26 PM
I am so sorry about that, duh... :idiot2:

This is the code I am currently using:

Code: [Select]
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, 03: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, 03: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, 06:34:20 AM
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, 10:58:12 AM
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 10, 2006, 09:07:50 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, 12: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, 09:17:37 AM
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, 09:27:40 AM
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, 09:43:08 AM
That seems to have fixed it..  Thank you very much!
Title: Re: Calendar in a php-block
Post by: zeniitti on November 22, 2006, 06:55:06 AM
Thanks, discovered that too some days ago :)
Title: Re: Calendar in a php-block
Post by: Malk on November 29, 2006, 05:18:34 AM
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, 03:24:56 AM
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 27, 2006, 05:01:53 PM
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 10, 2007, 07:19:20 PM
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 10, 2007, 09:00:52 PM
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, 04: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, 12: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 07, 2007, 05:23:54 PM
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 07, 2007, 06:52:12 PM
Find the section that lists holidays (the last section in the block), and find the line:
Code: [Select]
$eventdate = strtotime($row['eventDate']);
Change it to:
Code: [Select]
$eventdate = strtotime(date("Y").substr($row['eventDate'], 4));
Title: Re: Calendar in a php-block
Post by: soMzE on February 07, 2007, 07:27:33 PM
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 07, 2007, 08:33:13 PM
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 07, 2007, 08:39:38 PM
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:

Code: [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>';

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 07, 2007, 08:41:57 PM
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, 04: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, 01:50:35 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:

Code: [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>';

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, 05:52:31 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, 10:30:06 AM
 :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 11, 2007, 08:49:44 PM
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 11, 2007, 09:10:48 PM
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 11, 2007, 09:31:58 PM
Nice! thank you!
Title: Re: Calendar in a php-block
Post by: mrbean17 on February 12, 2007, 04:54:41 PM
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.

Code: [Select]
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 12, 2007, 05:06:31 PM
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 12, 2007, 05:25:25 PM
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, 09:11:54 AM
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, 03:33:36 PM
Is it possible to add repeating events?
Title: Re: Calendar in a php-block
Post by: jacortina on February 14, 2007, 03: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, 04:45:53 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, 04:52:39 PM
I adapted and combined earlier submissions into:

Code: [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 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 14, 2007, 05:05:25 PM
I adapted and combined earlier submissions into:

Code: [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 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 14, 2007, 06:45:23 PM
Nice code!!!
Title: Re: Calendar in a php-block
Post by: jakemelon on February 14, 2007, 07:19:24 PM
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 14, 2007, 07:27:31 PM
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:
Code: [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 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, 01: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, 04: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 19, 2007, 11:08:33 PM
Ok , thanks ;)
Title: Re: Calendar in a php-block
Post by: growl on February 20, 2007, 04: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, 06:39:03 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, 07:16:59 AM
ok, let's say, this is the code i want to modify to display todays events only:


Code: [Select]
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, 09:07:08 AM
Nice job!! you guys never cease to amaze...
Title: Re: Calendar in a php-block
Post by: jacortina on February 20, 2007, 10:32:26 AM
how would i have to modify it?
and will i have to add further information before that?

Try:
Code: [Select]
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, 12: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, 07:57:25 AM
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, 08:34:05 AM
Code: [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 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, 08:38:33 AM
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, 08:51:35 AM
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, 09:00:20 AM
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, 09:02:39 AM
no, the offset is set to 0
Title: Re: Calendar in a php-block
Post by: Dazed on February 21, 2007, 09:04:44 AM
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, 09:07:47 AM
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, 01: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?

Code: [Select]
$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, 04:18:29 AM
Tres cool  8)

I adapted and combined earlier submissions into:

Code: [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 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, 05:52:28 AM
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, 08:38:36 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:
Code: [Select]
$todaysBirthdays = ssi_todaysBirthdays('array');
$todaysEvents = ssi_todaysEvents('array');
$todaysHolidays = ssi_todaysHolidays('array');

Then:
Code: [Select]
$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, 08:48:06 AM
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, 08:58:15 AM
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, 09:02:18 AM
Well, that makes more sense, then. ;)
Title: Re: Calendar in a php-block
Post by: francerossina on February 28, 2007, 10:21:24 AM
I adapted and combined earlier submissions into:

Code: [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 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 February 28, 2007, 05:19:42 PM
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, 11:58:41 AM
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...

Code: [Select]
/////////////////////////////////////////////////////////////////
//   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, 12: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, 12:09:39 PM
Awesome, thanks!
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 13, 2007, 05: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, 07:57:32 AM
To start week with Monday, find:
Code: [Select]
$first_day = 0;
change to:
Code: [Select]
$first_day = 1;
Title: Re: Calendar in a php-block
Post by: 3nd3r on March 13, 2007, 10:31:11 AM
Thank you! Works perfect! Awesome!  ;) :D
Title: Re: Calendar in a php-block
Post by: SaD333 on March 21, 2007, 10:40:23 AM
spanish calendar?
Title: Re: Calendar in a php-block
Post by: ogmios on March 29, 2007, 06:25:36 AM
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 11, 2007, 11:39:42 PM
This calendar kicks ass. Thanks
Title: Re: Calendar in a php-block
Post by: brianjw on April 12, 2007, 05:35:32 PM
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, 02:53:44 AM
Hi Guys, i use the code shown on www.ffxi.bruderschaft.de.vu:

Code: [Select]
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, 04: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, 04: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:
Code: [Select]
$day_names[$n] = ucfirst(gmstrftime('%A,%a',$t)); #%A means full textual day nameand %B into
Code: [Select]
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 10, 2007, 11:02:51 PM
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, 08:16:58 AM
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
Code: [Select]
$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
Code: [Select]
$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
Code: [Select]
$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
Code: [Select]
$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 11, 2007, 09:33:09 PM
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

Code: [Select]
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 11, 2007, 09:50:55 PM
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:
Code: [Select]
$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, 01: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, 05:16:35 AM
can I adjust the Width of the calendar?
Title: Re: Calendar in a php-block
Post by: Porky on May 23, 2007, 05:23:09 AM
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, 05:55:48 AM
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, 06:32:01 AM
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 23, 2007, 06:42:45 PM
I have used this code:

Quote
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.'[/url]' : $p).'</span> ';
   if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'[/url]' : $n).'</span>';
   $calendar = '<table>'."\n".
      '<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $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.'[/url]' : $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 23, 2007, 06:57:19 PM
Right off, I'd try changing:
Code: [Select]
         $day_name_length = 3;
To:
Code: [Select]
         $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 23, 2007, 08:08:54 PM
Its really works, thanks a lot J.A.Cortin :lol:
Title: Re: Calendar in a php-block
Post by: purplegold on May 25, 2007, 10:34:28 AM
Right off, I'd try changing:
Code: [Select]
         $day_name_length = 3;
To:
Code: [Select]
         $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, 11:26:54 AM
Try changing:
Code: [Select]
   $calendar = '<table>'."\n".
      '<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $title).$n."</caption>\n<tr>";

To:
Code: [Select]
   $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, 11:33:40 AM
Thanks alot!!!  :coolsmiley:
Title: Re: Calendar in a php-block
Post by: Galious on June 18, 2007, 09:05:10 AM
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:
Code: [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 = 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 18, 2007, 05:37:39 PM
Try changing the months lines to:
Code: [Select]
$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, 04:26:34 AM
Perfect! It worked for me  :up:
Title: Re: Calendar in a php-block
Post by: itsacoaster on June 22, 2007, 11:32:25 AM
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, 09:30:49 AM
For all the Dutch people here the right code:

Code: [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 = 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, 08:49:55 AM
Hey, is there any way to make the weekend days the same color as the weekdays?

Try this.

Find:
Code: [Select]
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }

And comment it out:
Code: [Select]
//        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, 09:01:09 AM
Worked like a charm!  Thanks!
Title: Re: Calendar in a php-block
Post by: npereira on August 10, 2007, 07:58:37 AM
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, 08:26:04 AM
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, 08:59:28 AM
but what bloc type does it need to be?
Title: Re: Calendar in a php-block
Post by: Crip on August 10, 2007, 09:26:50 AM
phpbox
Title: Re: Calendar in a php-block
Post by: npereira on August 10, 2007, 09:40:15 AM
ok, but it does not link to the SMF calendar?
Title: Re: Calendar in a php-block
Post by: Crip on August 10, 2007, 10:11:16 AM
Yup!
Title: Re: Calendar in a php-block
Post by: ogmios on August 16, 2007, 08:55:34 AM
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:

Code: [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;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 16, 2007, 05:45:42 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:
Code: [Select]
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 16, 2007, 06:51:53 PM
Quote
What 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 16, 2007, 07:23:15 PM
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):
Code: [Select]
        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="left">';

And replace with:
Code: [Select]
        $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, 06:13:40 AM
it worked - it's awesome - thank you...
Title: Re: Calendar in a php-block
Post by: Sandriell on September 10, 2007, 11:28:00 AM
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 14, 2007, 08:35:22 PM
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, 03:17:54 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, 01: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, 08:35:29 AM
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, 09:50:09 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, 10:00:28 AM
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, 10:14:15 AM
I believe the URL the button takes you to has to be of the form:

Code: [Select]
'<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, 10:26:28 AM
Quote
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.

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, 10:32:58 AM
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...

Code: [Select]
$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...

Code: [Select]
/////////////////////////////////////////////////////////////////
//   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, 11:21:03 AM
Try this.

In that Events Section of the code, Find:
Code: [Select]
        echo $event['link'] ;
And replace it with:
Code: [Select]
        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, 11:33:50 AM
Thanks a lot!!!!!!!!!!!!
Title: Re: Calendar in a php-block
Post by: dannbass on September 20, 2007, 01: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,

Code: [Select]
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
Code: [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: 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, 09:05:26 AM
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:
Code: [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;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, 09:10:33 AM
Try changing:
Code: [Select]
//////////////////////////////////////////////////////////////////
// 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:
Code: [Select]
}
//////////////////////////////////////////////////////////////////
// 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, 09:52:24 AM
Quote
Try 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"'), '[/url]';
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"'), '[/url]';
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, 10:19:32 AM
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:
Code: [Select]
/////////////////////////////////////////////////////////////////
//   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:
Code: [Select]
/////////////////////////////////////////////////////////////////
//   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, 10:33:01 AM
well that did something funky (image attached)...
Title: Re: Calendar in a php-block
Post by: jacortina on September 24, 2007, 11:15:01 AM
Brackets and columns and unclosed div. Arrrrrgggghhhh!!!!

Use this block (replace what you have):
Code: [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;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, 11:18:32 AM
 O0   like, coooooooooool man... (it's all good)

thanks!

Title: Re: Calendar in a php-block
Post by: dannbass on September 24, 2007, 03: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 25, 2007, 06:06:55 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 25, 2007, 06:09:09 PM
 ;D Thank you!!! We'll have a terrific calendar then!!!
Title: Re: Calendar in a php-block
Post by: Lotti on September 26, 2007, 03: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, 06:48:31 AM
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, 12:54:41 PM
Just change this part to your language.

Code: [Select]
$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...

Code: [Select]
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, 01: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, 01: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, 01: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, 01: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 04, 2007, 08:03:58 PM
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: [Select]
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 04, 2007, 10:22:04 PM
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 04, 2007, 10:29:43 PM
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 04, 2007, 10:31:00 PM
How odd, its exactly reversed for me
Title: Re: Calendar in a php-block
Post by: jacortina on October 04, 2007, 10:39:09 PM
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 04, 2007, 10:48:25 PM
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, 09:25:14 AM
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, 09:51:01 AM
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, 11:58:40 AM
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:
Code: [Select]
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, 12: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, 12:19:14 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

(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...

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, 12: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, 12:41:41 PM
The month came up!!
But the days are messed up

I put the
Code: [Select]
$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, 01: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, 01: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 09, 2007, 11:07:36 PM
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, 06:42:23 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, 09:11:44 AM
Thanks
Title: Re: Calendar in a php-block
Post by: jacortina on October 10, 2007, 09:36:51 AM
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.


Code: [Select]
/******************************************************************************************
*                                                                                         *
* '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, 09:54:14 AM
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, 10:08:24 AM
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, 10:15:34 AM
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, 11:40:35 AM
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 10, 2007, 05:32:23 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?

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"


Code: [Select]
/******************************************************************************************
*                                                                                         *
* '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 10, 2007, 06:55:34 PM
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 10, 2007, 07:14:30 PM
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 10, 2007, 07:24:35 PM
Sure. Be my guest.
Title: Re: Calendar in a php-block
Post by: stormlrd on October 10, 2007, 07:30:28 PM
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 17, 2007, 09:58:28 PM
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, 01: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, 11:36:49 AM
'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, 11:51:54 AM
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 29, 2007, 07:25:29 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 29, 2007, 07:29:21 PM
OK. Some more optimizations. And the addition of 'look-behinds' the ability to show calendar entries which have already passed:

Code: [Select]
// 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).



Code: [Select]
/******************************************************************************************
*                                                                                         *
* '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, 09:40:07 AM
Thanks!  Just installed the update on all 3 of mine.
Title: Re: Calendar in a php-block
Post by: Rus on October 30, 2007, 09:50:34 AM
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, 11:09:25 AM
Only because you have 4 users showing on the birthday list, right?

Replace this chunk (better than having to re-enter your settings).

Code: [Select]
/////////////////////////////////////////////////////////////////
//   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, 11:25:13 AM
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, 01: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, 03: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, 03: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, 03: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, 04: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:
Code: [Select]
smf_loadCalendarInfo();
And insert these lines just after it:
Code: [Select]
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, 04: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, 04: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, 04: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, 04: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, 04: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, 04:25:55 PM
Well, let's try something else.

Get rid of those three lines to print the $context sub-array and find:
Code: [Select]
ksort($events);
Then print out THAT array:
Code: [Select]
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, 04:27:44 PM
lol...nothing listed
Title: Re: Calendar in a php-block
Post by: TimUSA on October 31, 2007, 04: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, 04: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, 05: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, 09:39:42 AM
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, 04: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 !

Code: [Select]
/******************************************************************************************
*                                                                                         *
* '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, 02: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:
Code: [Select]
$title   = htmlentities(ucfirst($month_name)).' '.$year;   // note that some locales don't capitalize month and day names

Change To:
Code: [Select]
$title   = $month_name.' '.$year;

Find (about 12 lines elow the first change):
Code: [Select]
abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
Change To:
Code: [Select]
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:
Code: [Select]
0,3)
Could you see what happens if you chenge them to:
Code: [Select]
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 24, 2007, 08:35:55 PM
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 24, 2007, 08:48:26 PM
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, 10:50:56 AM
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, 04: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 :

Code: [Select]
/******************************************************************************************
*                                                                                         *
* '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); }