Help with todaysCalendar_SSI

Started by kimncris, October 30, 2005, 01:23:16 AM

Previous topic - Next topic

kimncris

Hi

I have been searching and experimenting all day but I just cannot figure this one out.


I am using a modified version of SSI.php called editedSSI.php to include some data on my homepage, but the calendar data is only visible if you are logged-in.

you can log-in to see the 1 event while it lasts (it's on Halloween)
http://www.scgarrison.net/index.php
test account: testmember
password: password
SMF 1.0.5

I cannot for the life of me figure out where to change the code to let guests see the event "titles" even if they get rejected when they try to link.


here is my edited calendar call
(I've called it ssi_comingCalendar)


/****************************************changed**************************************************/

// Show all calendar upcoming calendar events entires for today. (no birthdays birthdays or holidays)
function ssi_comingCalendar($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_holidays']))
echo '


<span style="color: #' . $modSettings['cal_holidaycolor'] . ';">' . $txt['calendar5'] . ' ' .

implode(', ', $context['calendar_holidays']) . '<br /></span>';
if (!empty($context['calendar_birthdays']))
{
echo '
<span style="color: #' . $modSettings['cal_bdaycolor'] . ';">' . $txt['calendar3b'] . '</span> ';
foreach ($context['calendar_birthdays'] as $member)
echo '
<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'],

isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : '';
echo '
';
}*/

if (!empty($context['calendar_events']))
{
echo '
';

foreach ($context['calendar_events'] as $event)
{
/*if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';*/
echo '
<a href="' . $event['href'] . '">' . $event['title'] . '</a>' . (!$event['is_last'] ? '<br><br> '

: '');
}
}
}


/**************************************************end change******************************************/



you will also notice that it takes you directly to the message boards when you sign-in.  IS there any way to prevent this?  I already had to remove the LOGOUT button since I could not overcome the "error verifying referring URL" when trying to logout at the home page.

anyway thanks a million if you know the answer to this puzzle :)

-cris

kimncris

Ive also been trying to get the date to show next to the event, but I wasn't having much luck with the code abovem so I tried modifying the "sss_recentEvents" to do it and that hasn't been working either.

here's my new code (not finished and also not displaying dates)

/*************************edit*****************************/

// Show the upcoming events with dates in ASCENDING order.
function ssi_comingEvents2($max_events = 7, $output_method = 'echo')
{
global $db_prefix, $user_info, $scripturl, $modSettings, $txt, $sc;

// Find all events which are happening in the near future that the member can see.
$request = db_query("
SELECT
cal.ID_EVENT, DAYOFMONTH(cal.eventDate) AS day, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
cal.ID_BOARD, t.ID_FIRST_MSG
FROM {$db_prefix}calendar AS cal, {$db_prefix}boards AS b, {$db_prefix}topics AS t
WHERE cal.eventDate >= '" . strftime('%Y-%m-%d', forum_time(false)) . "'
AND cal.ID_TOPIC = t.ID_TOPIC
AND cal.ID_BOARD = b.ID_BOARD
AND $user_info[query_see_board]
ORDER BY cal.eventDate ASC
LIMIT $max_events", __FILE__, __LINE__);
$return = array();
$duplicates = array();
while ($row = mysql_fetch_assoc($request))
{
// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
if (!empty($duplicates[$row['title'] . $row['ID_TOPIC']]))
continue;

// Censor the title.
censorText($row['title']);

$return[$row['day']][] = array(
'id' => $row['ID_EVENT'],
'title' => $row['title'],
'can_edit' => allowedTo('calendar_edit_any') || ($row['ID_MEMBER'] == $ID_MEMBER && allowedTo('calendar_edit_own')),
'modify_href' => $scripturl . '?action=post;msg=' . $row['ID_FIRST_MSG'] . ';topic=' . $row['ID_TOPIC'] . '.0;calendar;eventid=' . $row['ID_EVENT'] . ';sesc=' . $sc,
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['title'] . '</a>',
'is_last' => false
);

// Let's not show this one again, huh?
$duplicates[$row['title'] . $row['ID_TOPIC']] = true;
}
mysql_free_result($request);

foreach ($return as $mday => $array)
$return[$mday][count($array) - 1]['is_last'] = true;

if ($output_method != 'echo' || empty($return))
return $return;

// Well the output method is echo.
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4'] . '</span> ';
foreach ($return as $mday => $array)
foreach ($array as $event)
{
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';

echo '
<a href="' . $event['href'] . '">' . $event['title'] . $row['day']. '</a>' . (!$event['is_last'] ? ', ' : '');
}
}


/**************************end edit****************************/



you can see the test results here

http://www.scgarrison.net/test/newindex2.php


I got them to diplay in Ascending order at least, but still not dates and I just am not familiar enough with the code to guess the right command to display the date too.  Is it not possible in this SSI command either?  I can see that it is using the date to put them in order....   :-\


anyway thanks again if you know the magic answer.

-cris

kimncris

well I've pretty much given up on the guest being able to view- but it would be nice if it is fairly easy-

but I really would like it to show dates.  I've gotten it to show the "day" but not the month or year

everything I have tried has been mostly like this


$return[$row['day']][] = array(
   
       'id' => $row['ID_EVENT'],
       'title' => $row['title'],
       'date' => $row['day'].



then in the echo I add $event['date'] but all I've been able to get is the day number like I said.  I've tried cal.eventDate,  DAYOFMONTH, Day, but nothing has ever worked.  Is the full date never aquired all at once from the database?  If not is there a way to query this?


thanks again,

-cris

kimncris

#3
well whaddaya know-

I DID get it so guests can at least see the event titles by commenting out the user check and the canedit commands.

Quote/*************************edit  added item*****************************/

// Show the upcoming events with dates in ASCENDING order even to guests.
function ssi_recentEvents2($max_events = 7, $output_method = 'echo')
{


   global $db_prefix, $user_info, $scripturl, $modSettings, $txt, $sc;

   // Find all events which are happening in the near future that the member can see.
   $request = db_query("
      SELECT
         cal.ID_EVENT, DAYOFMONTH(cal.eventDate) AS day, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
         cal.ID_BOARD, t.ID_FIRST_MSG
      FROM {$db_prefix}calendar AS cal, {$db_prefix}boards AS b, {$db_prefix}topics AS t
      WHERE cal.eventDate >= '" . strftime('%Y-%m-%d', forum_time(false)) . "'
         AND cal.ID_TOPIC = t.ID_TOPIC
         AND cal.ID_BOARD = b.ID_BOARD
         /*AND $user_info[query_see_board]*/      
                                           ORDER BY cal.eventDate ASC
      LIMIT $max_events", __FILE__, __LINE__);
   $return = array();
   $duplicates = array();
   while ($row = mysql_fetch_assoc($request))
   {
      // Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
      if (!empty($duplicates[$row['title'] . $row['ID_TOPIC']]))
         continue;

      // Censor the title.
      censorText($row['title']);

      $return[$row['day']][] = array(
         'id' => $row['ID_EVENT'],
         'title' => $row['title'],
                                                               
         /*'can_edit' => allowedTo('calendar_edit_any') || ($row['ID_MEMBER'] == $ID_MEMBER && allowedTo('calendar_edit_own')),*/         

                                                                 'modify_href' => $scripturl . '?action=post;msg=' . $row['ID_FIRST_MSG'] . ';topic=' . $row['ID_TOPIC'] . '.0;calendar;eventid=' . $row['ID_EVENT'] . ';sesc=' . $sc,
         'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
         'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['title'] . '</a>',
         'is_last' => false
      );

      // Let's not show this one again, huh?
      $duplicates[$row['title'] . $row['ID_TOPIC']] = true;
   }
   mysql_free_result($request);

   foreach ($return as $mday => $array)
      $return[$mday][count($array) - 1]['is_last'] = true;

   if ($output_method != 'echo' || empty($return))
      return $return;

   // Well the output method is echo.
/*   echo '
         <span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4'] . '</span> ';*/
   foreach ($return as $mday => $array)
      foreach ($array as $event)
      {
         /*if ($event['can_edit'])
            echo '
            <a href="' . $event['modify_href'] . '" style="color: #AA0000;">Edit</a> ';*/


         echo '
            <a href="' . $event['href'] . '">' . $event['title'] . $event['date']. '<br><br></a>' . (!$event['is_last'] ? ', ' : '');
      }
}


/**************************end edit****************************/


it still does not show the date automatically, but I just told people to put it in thier title (for now)




edit


and I think I've finally done it

heres the code- I made my own new SSI function called dbevents

I'm sure there was a little more elegant way to do this- especially when it comes to displaying the date in  "Day of week - MM/DD/YY" format, but I don't know php at all and this was the only way I could figure out how to do it.

It seems to be working, though- you can check the results here:  http://www.scgarrison.net/index.php


and here's my code. the major changes from ssi_recentEvents are in red.  Please let me know if you see anything funky...



Quote/***************************db events query**********************************/

// Show the upcoming events with dates in ASCENDING order even to guests.
function ssi_dbEvents($max_events = 7, $output_method = 'echo')

{


   global $context,$db_prefix, $user_info, $scripturl, $modSettings, $txt, $sc;

   // Find all events which are happening in the near future that the member can see.
   $request = db_query("
      SELECT
         cal.ID_EVENT, DAYOFMONTH(cal.eventDate) AS day, cal.eventDate, year(cal.eventDate) AS year, MONTH(cal.eventDate) AS month, DAYOFWEEK(cal.eventDate) AS weekday, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
         cal.ID_BOARD, t.ID_FIRST_MSG
      FROM {$db_prefix}calendar AS cal, {$db_prefix}boards AS b, {$db_prefix}topics AS t
      WHERE cal.eventDate >= '" . strftime('%Y-%m-%d', forum_time(false)) . "'
         AND cal.ID_TOPIC = t.ID_TOPIC
         AND cal.ID_BOARD = b.ID_BOARD
         /*AND $user_info[query_see_board]*/
      ORDER BY cal.eventDate ASC
      LIMIT $max_events", __FILE__, __LINE__);

   $return = array();
   $duplicates = array();
   
                     while ($row = mysql_fetch_assoc($request))

                     {

                               //replace day #s with words instead
                               if ($row['weekday'] == "1") {$dayword=Sunday;}
                                   elseif ($row['weekday'] == "2") {$dayword=Monday;}
                                   elseif ($row['weekday'] == "3") {$dayword=Tuesday;}
                                   elseif ($row['weekday'] == "4") {$dayword=Wednesday;}
                                   elseif ($row['weekday'] == "5") {$dayword=Thursday;}
                                   elseif ($row['weekday'] == "6") {$dayword=Friday;}
                                   else {$dayword=Saturday;}

                               //if 2010 or higher chop off the 2000 so the year displays as the last 2 digits otherwise contruct the year as a 0 and the lastdigit
                               if ($row['year'] > 2009) $shortyear = (($row['year'])-2000);
                                   else $shortyear="0";

                                if ($row['year'] < 2010) $lastdigit = (($row['year'])-2000);




      // Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
      if (!empty($duplicates[$row['title'] . $row['ID_TOPIC']]))
         continue;

      // Censor the title.
      censorText($row['title']);


      $return[$row['day']][] = array(
         'id' => $row['ID_EVENT'],
         'title' => $row['title'],
                                                                'day' =>$row['day'],
                                                                'weekday' =>$dayword,
                                                                'month' =>$row['month'],
                                                                'year' =>$shortyear,
                                                                'lastdigit' =>$lastdigit,
                              

                                                                /*'can_edit' => allowedTo('calendar_edit_any') || ($row['ID_MEMBER'] == $ID_MEMBER && allowedTo('calendar_edit_own')),*/
         'modify_href' => $scripturl . '?action=post;msg=' . $row['ID_FIRST_MSG'] . ';topic=' . $row['ID_TOPIC'] . '.0;calendar;eventid=' . $row['ID_EVENT'] . ';sesc=' . $sc,
         'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
         'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['title'] . '</a>',
         'is_last' => false
      );


      // Let's not show this one again, huh?
      $duplicates[$row['title'] . $row['ID_TOPIC']] = true;
   }
   mysql_free_result($request);

   foreach ($return as $mday => $array)
      $return[$mday][count($array) - 1]['is_last'] = true;

   if ($output_method != 'echo' || empty($return))
      return $return;

   // Well the output method is echo.
/*   echo '
         <span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4'] . '</span> ';*/
   foreach ($return as $mday => $array)
      foreach ($array as $event)
      {

                       //only display the items as links if not a guest.

         if ($context['user']['is_guest'])
                                                          {
         echo '<br>
                                                                    ' .$event['weekday'],'&nbsp;'. $event['month'],'/'. $event['day'],'/'. $event['year'], $event['lastdigit'],'<br>'.  $event['title']. '<br><br></a>' . (!$event['is_last'] ? ', ' : '');
                                                          }
                                                               else
                                                          {
                                                     echo '
            <a href="' . $event['href'] . '">' . $event['weekday'],'&nbsp;'.  $event['month'],'/'. $event['day'],'/'. $event['year'], $event['lastdigit'],'<br>'.  $event['title']. '<br><br></a>' . (!$event['is_last'] ? ', ' : '');

                                                          } 
      }
}


/***********************************************************************************/
-cris

Advertisement: