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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 728
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 400
  • Total: 400

SMF Calendar Block

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

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

Metorks

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?

jacortina

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

ogmios

Quote from: ogmios on September 15, 2007, 03:35:22 AM
is it possible to anchor my babylon themed 'post event' button (from the smf calendar) to the bottom of my php-block calendar so users could start from there?

ok, i opened calendar.template.php and was able to add part of the 'show button' code to my calendar block to have the 'post event' button show inside my calendar block... but when i click on the button, i get an 'invalid month value' error message...

i realize that there is probably more to getting this to work than just embedding a button, but i'm not sure what (i'm just a beginner)...

interesting thing is that the 'post event' button (in the php calendar block) works when i'm viewing the SMF calendar, but it doesn't work when if i am viewing anything else...

still working on it, but any hints or advice are welcome...

Metorks

Quote from: J.A.Cortina on September 20, 2007, 03:35:29 PM
This code is not really appropriate for that. It specifically takes the Calendar 'look ahead' defined for the forum to display events under the calendar for the current month.

I believe that if you're simply looking to add small month calendars to the calendar page display, there's a mod for that over on the SMF site ('Enhanced Calendar' or something like that).

I'll look into that then.  Thanks!

jacortina

I believe the URL the button takes you to has to be of the form:

'<a href="http://', $scripturl,  '?action=calendar;sa=post;month=', $month, ';year=', $year, ';sesc=', $context['session_id'], '">'

The $month and $year are already set up in the code.

I haven't done anything with the session ID before, but I think the above will put it in place.

ogmios

#345
QuoteThe $month and $year are already set up in the code.

I haven't done anything with the session ID before, but I think the above will put it in place.

absolutely fabulous! thanks! it works great!

i had all of the code there (from calendar.template.php), but the code had the smf code calling up the date & year instead of letting the php-block code do the work... your code was exactly what i needed, except i had to remove the 'http://' part (it was redundant and tried to connect to "http://http://.......")...

all is good now!

(thank you)


dannbass

Now I have a question... what should you need to add if you want to add the events that happen today bold?

In looking at the boardindex.template and this looks like the code...

$event['is_today'] ? '<b>' . $event['title'] . '</b>

but I'm php challenged...

the code that I'm using is, or the part for that matter is...

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

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

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

        mysql_free_result($query);

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


Thanks a lot!

jacortina

Try this.

In that Events Section of the code, Find:
        echo $event['link'] ;

And replace it with:
        if ((date('Y',$now).date('m',$now).date('d',$now)) >= (date('Y',$startdate).date('m',$startdate).date('d',$startdate)))
        {
            echo '<b>',$event['link'], '</b>';
        }
        else
        {
            echo $event['link'] ;
        }


That should bold events which start today or events that run multiple days and already started.

dannbass


dannbass

Now I thought of something else... long time ago here
Kail used this code... if I'm not mistaken,

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

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


to add a highlight to the dates that have an event.

Again, I've been trying to add this to this
global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

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

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

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

$day_name_length = 3;

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

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

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


list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$month_nam = array();
$month_nam['01'] = 'Enero';
$month_nam['02'] = 'Febrero';
$month_nam['03'] = 'Marzo';
$month_nam['04'] = 'Abril';
$month_nam['05'] = 'Mayo';
$month_nam['06'] = 'Junio';
$month_nam['07'] = 'Julio';
$month_nam['08'] = 'Agosto';
$month_nam['09'] = 'Septiembre';
$month_nam['10'] = 'Octubre';
$month_nam['11'] = 'Noviembre';
$month_nam['12'] = 'Diciembre';
$month_name = $month_nam[$month];

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

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span style=" font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span style=" font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

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

if($weekday > 0) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

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

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

if($weekday != 7) $calendar .= '<td style=" font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

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

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

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

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

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

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

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

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

        mysql_free_result($query);

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

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

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

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

        mysql_free_result($query);

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

echo '</table>';


that is almost the perfect calendar block, at least IMHO.

Could you help me out again?
I'm very grateful!!!

This website is proudly hosted on Crocweb Cloud Website Hosting.