TinyPortal

Development => Block Codes => Topic started by: ed_m2 on February 21, 2011, 03:32:29 PM

Title: Calendar Block Issue
Post by: ed_m2 on February 21, 2011, 03:32:29 PM

The following code came from this rather long thread a while back:
http://www.tinyportal.net/index.php?topic=700
I've hacked with some formatting & switched a few section out (see code below).

I've just updated the threads to link events for our run session (http://www.covtri.co.uk/index.php?topic=696.0) & swim sessions (http://www.covtri.co.uk/index.php?topic=659.0) in March, both are weekly.
Both appear in the SMF calendar view (http://www.covtri.co.uk/index.php?action=calendar;year=2011;month=2) however the upcoming events block on frontpage & left panel calendar block (both using this code) now show only the run sessions.

Any suggestions ?
(PS pleased to see TP still going strong with all your support!)

Link to my site: http://www.covtri.co.uk
SMF version: 1.1.11
TP version: 1.0b4
Default Forum Language: English
Theme name and version: Custom default
Browser Name and Version: FF?
Mods installed:
1.    Anti-Bot Registration Puzzles
2.    TinyPortal    1.083    
3.    SMF Media Gallery    2.0.5    
4.    SMF Links    2.1.2
Related Error messages: n/a

Code below.

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

// EM disabled:
//echo $calendar.'</tr>';
echo '<table align="center">';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
// EM disabled:
if (0)
{
    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">';

// EM modified:
    echo '<td colspan="7">';

    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><hr>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
//if (!empty($context['calendar_holidays']))
// EM disabled:
if (0)
{
    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 Block Issue
Post by: Lesmond on February 21, 2011, 04:03:48 PM
I just went to your site and I can see all events in there OK

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi56.tinypic.com%2Fxe0pww.jpg&hash=27d2d6fd53f7eb0b361880d23d4ac98b7bd7e381)

PS. I have just added your old post from the old TP site to here, if you wondering why your post count went up ::)
Title: Re: Calendar Block Issue
Post by: ed_m2 on February 21, 2011, 04:09:54 PM
Quote from: Ã,©Lesmond on February 21, 2011, 04:03:48 PM
I just went to your site and I can see all events in there OK

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi56.tinypic.com%2Fxe0pww.jpg&hash=27d2d6fd53f7eb0b361880d23d4ac98b7bd7e381)

PS. I have just added your old post from the old TP site to here, if you wondering why your post count went up ::)

Ha thanks ... you can see the swim session on the 27th Feb, but not the ones on the 6th or 13th March which are linked to the same thread.
(Seems the same with the spin sessions I just added beyond the 3rd of March)
Title: Re: Calendar Block Issue
Post by: ed_m2 on February 22, 2011, 08:40:02 AM

i'm wondering if the query returns a list of events in the order they're attached to threads and then sorted by date.. meaning one thread might get all its events listed and the others get truncated ?

will have to do some print_r on the query results to take a look i think.
Title: Re: Calendar Block Issue
Post by: ed_m2 on February 22, 2011, 11:19:04 AM

just looking further into this...... it uses $context['calendar_events'] for this .. which is failing to return some of the vents i would expect.
Title: Re: Calendar Block Issue
Post by: ZarPrime on February 22, 2011, 03:12:31 PM
ed_m2,

Try the code posted in this message for SMF 1.1.x --> http://www.tinyportal.net/index.php?topic=28911.msg230885#msg230885

You might have to adjust the parameters in the "Program Paramters/Switches Section" to get what you want.  Let us know how it works.

ZarPrime
Title: Re: Calendar Block Issue
Post by: ed_m2 on February 22, 2011, 04:17:29 PM
cheers zar.... thats a nice looking block too.
i've just tried it and have the same issue, so thinking it may be an smf thing.
i'll set up some hidden php articles later to link to & illustrate whats going on better.