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,973
  • Latest: NonStop
Stats
  • Total Posts: 196,219
  • Total Topics: 21,352
  • Online today: 556
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

Calendar Event Details Block

Started by jpark, August 14, 2007, 01:42:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jpark

you can ignore the first post about ssi changes and put JACortina's code into a php block.  With the date modification, the full code is:


global $user_info, $settings, $scripturl, $db_prefix, $modSettings;

$max_length = 256;

$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);

$result = db_query("
SELECT
cal.ID_EVENT, cal.startDate, cal.endDate, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
cal.ID_BOARD, b.memberGroups, t.ID_FIRST_MSG,
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, m.smileysEnabled, m.ID_MSG, t.locked
FROM {$db_prefix}calendar AS cal
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = cal.ID_MEMBER)
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = cal.ID_TOPIC)
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = cal.ID_BOARD)
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_MSG = t.ID_FIRST_MSG)
WHERE cal.startDate <= '$high_date'
AND cal.endDate >= '$low_date'
AND cal.ID_TOPIC = t.ID_TOPIC
AND (".$user_info['query_see_board']." OR cal.ID_BOARD = 0)
ORDER BY cal.startDate, cal.ID_TOPIC", __FILE__, __LINE__);

$events = array();

if (mysql_num_rows($result) == 0) {
    echo '<h3>No Events Found</h3>';
    return;
}

while ($row = mysql_fetch_assoc($result)) {

    if ($row['ID_BOARD'] != 0) {

    // If we want to limit the length of the post.
    if (!empty($max_length) && strlen($row['body']) > $max_length)
    {
    $row['body'] = substr($row['body'], 0, $max_length);

    // The first space or line break. (<br />, etc.)
    $cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

    if ($cutoff !== false)
    $row['body'] = substr($row['body'], 0, $cutoff);
    $row['body'] .= '...';
        }

    $row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

    // Check that this message icon is there...
    if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
    $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

    censorText($row['subject']);
    censorText($row['body']);
    }

censorText($row['title']);

    $events[] = array(
'title' => $row['title'],
'topic' => $row['ID_TOPIC'],
'msg' => $row['ID_FIRST_MSG'],
'poster' => $row['ID_MEMBER'],
'start_date' => $row['startDate'],
'end_date' => $row['endDate'],
'icon' => $row['ID_BOARD'] == 0 ? '' : '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['ID_BOARD'] == 0 ? $row['title'] : $row['subject'],
'body' => $row['ID_BOARD'] == 0 ? '' : $row['body'],
'href' => $row['ID_BOARD'] == 0 ? ($scripturl . '?action=calendar;year=' . substr($row['startDate'],0,4) . ';month=' . substr($row['startDate'],5,2)) : ($scripturl . '?topic=' . $row['ID_TOPIC'] . '.0')
);
}
mysql_free_result($result);

$ctr = 1;
$tot = count($events);
foreach ($events as $event)
{
    echo '
<div class="smalltext">
<a href="', $event['href'], '">', $event['icon'], ' <b>', $event['subject'], '</b></a>

<div><b>Date: </b>' . date("n/j (D)",strtotime($event['start_date'])) . '';
   if ($event['end_date'] !== $event['start_date']) {
      echo '
        - ' . date("n/j (D)",strtotime($event['end_date'])) . '
       ';
       }
echo '</div>';echo '

<div class="post" style="padding: 0ex 0;">', $event['body'], '</div>
</div>';

if ($ctr < $tot) {
echo '<hr style="margin: 2ex 0;" width="100%" />';
$ctr++;
}
}


I believe the coding would require a board linked to calendar events since it's calling the information from there (icon, title, post body).  You might still consider adding the Custom Post Prefill hack once you dedicate a board to your events so that you can have prefilled Time, Place, Notes in there already.

martinmarinekeeper


jacortina

Actually, the code 'should' also show events which AREN'T linked to a post (giving the event title in place of the topic subject). This won't have the topic icon or any further text, of course.

But it's driven by calendar event entries and will read in the referenced topic, whatever board it's in.

martinmarinekeeper

i got it working but it did need the link to a board or it just said no event

its block two on left

www.marine-keepers.com/forums

chris29

Hi all...
Firstly many thanks for all the help on this forum. I am using the code posted below by jpark (and it works a treat!), but was wondering if there is any way to change the date format from US to UK (ie. 1/22 to 22/1)? Not sure if this is to do with the code or the calendar... Bit of a newbie really!

Thanks, Chris

Quote from: jpark on November 02, 2007, 03:16:25 AM
This was the code I was using (php block).  If someone knows how to call the linked topic to get the topic body, it would help a lot.

global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $txt, $settings, $func;

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:#515151; 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>';

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($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']);
        mysql_free_result($query);


        $query = db_query(
            "SELECT endDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);
        $row = mysql_fetch_assoc($query);
        $enddate = strtotime($row['endDate']);
        mysql_free_result($query);




        echo '<div align="left">';
        echo $event['link'] ;
        echo '<br />';
        echo 'Date: '; echo '' . date("n/j (D)",$startdate) . '';
   if ($enddate !== $startdate)
      {
        echo ' - '; echo '' . date("n/j (D)",$enddate) . '';
      }
        echo '<br /><br />';
        echo '</div>';
    }
}


jpark

You might want to use JACortina's code instead (look at my reply #20)... it is the most updated.  Using that code, you can change the date format by searching this code

date("n/j (D)",strtotime($event['start_date']))

and replacing it with this

date("j/n (D)",strtotime($event['start_date']))

lowercase j is day of month without leading zeros
lowercase n is month without leading zeros
You can find more date formats here: http://us.php.net/date


This website is proudly hosted on Crocweb Cloud Website Hosting.