TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 29, 2024, 10:03:03 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,106
  • Total Topics: 21,213
  • Online today: 358
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 81
  • Total: 81

SMF Calendar Block

Started by Lesmond, September 03, 2005, 11:30:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

npereira

ok, but it does not link to the SMF calendar?

Crip

I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



ogmios

not sure if this has been talked about already, so please let me know if it has...

in my calendar block, an event that runs for more than one day shows up in the calendar each day it is happening, but the date won't change for the additional days and will only display the date of the first day of the event...

any way to fix? here's my calendar code:

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

smf_loadCalendarInfo();

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

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

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

$day_name_length = 2;

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

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

$day_names = array();                                      #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400)    #January 4, 1970 was a Sunday
    $day_names[$n] = ucfirst(gmstrftime('%A',$t));         #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));

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

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

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

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

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

    if(isset($days[$day]) and is_array($days[$day])){
        @list($link, $classes, $content) = $days[$day];
        if(is_null($content))  $content  = $day;
        $calendar .= '<td '.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#06FE69;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

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

echo $calendar.'</tr>';


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

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

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

        mysql_free_result($query);

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

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

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

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

        mysql_free_result($query);

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



thanks in advance for any help...


jacortina

Quote from: ogmios on August 16, 2007, 03:55:34 PM
any way to fix? here's my calendar code:

What do you want it to say?

When you look at the code, you can see this line:
smf_loadCalendarInfo();

That calls an SMF function (in SSI.php) to load the members of $context['calendar_events'] used in the Events Section. And when you look in the Events section, you can see that when it reads the calenadar table, all it gets for it is the startDate.

ogmios

#334
QuoteWhat do you want it to say?

well, for example, if i had an event that ran on August 17, 18 & 19, the calendar shows the event listing each day, but the date on the calendar always remains at August 17... even if it's the 18th or 19th to us, the calendar only shows the first date (the 17th) with the event title...

when visitors come to the site and look at the calendar, they see an incorrect date and think it's a mistake...

i thought there may be a way to have the date on the calendar update to the current day, rather than display the starting date of the event...


jacortina

Well, this 'should' set the date to the current date if the start date is past. Note that I haven't tested it as I don't have a board that uses multi-date events.

Find (in the Events Section):
        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

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


And replace with:
        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        $cal_date = date("Y", $now) . date("m", $now) .date("d", $now);
        $evt_date = date("Y", $startdate) . date("m", $startdate) .date("d", $startdate);

        if($cal_date > $evt_date)
            $startdate = $now;

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

ogmios

it worked - it's awesome - thank you...

Sandriell

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

This is probably a big change, so I understand if you do not want to support it. Thanks either way!

ogmios

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)

jacortina

Quote from: Sandriell on September 10, 2007, 06:28:00 PM
The mod we are using for repeating events is Repeating Calendar Events v1.2.6

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.