Welcome to Geeklog, Anonymous Sunday, November 24 2024 @ 08:51 pm EST
Geeklog Forums
Calendar events by topic
richardpitt
I have a customer who wanted only events for a particular topic to show up on the topic pages.
This involved setting the event_type list in _CONF from the topic list in the database. I actually coded it so it would add to the config.php list but then set the list to empty. The problem is that I've had to hack admin/event.php
I could have put the code in lib-custom.php but then it would get executed every page load instead of just when someone was going to add/edit an event. Is there some standard way to do these hacks? Or should I suggest that there be a call to some event-lib-custom at the top for those of us who want to hack it?
Code snippit - added just above the first $event_templates = lines in function editevent:
// customization - richard
$result = DB_query ("SELECT * from {$_TABLES['topics']} WHERE 1 ORDER BY topic") ;
$nrows = DB_numRows ($result) ;
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray ($result) ;
if (($i == 0) && ( empty( $_CONF['event_types'] ))){
// don't put the comma on the first one or we get a blank line
$_CONF['event_types'] .= $A['topic'] ;
} else {
$_CONF['event_types'] .= ',' . $A['topic'] ;
}
}
Then I created a phpblock in lib-custom. The only thing I don't like is pushing the $topic info onto _CONF but this seems to be the easiest way to get this variable into the function. Is there a better way? This is done at the top of lib-custom - outside any functions.
// from lib-common
if( isset( $HTTP_GET_VARS['topic'] ))
{
$topic = COM_applyFilter( $HTTP_GET_VARS['topic'] );
}
else if( isset( $HTTP_POST_VARS['topic'] ))
{
$topic = COM_applyFilter( $HTTP_POST_VARS['topic'] );
}
else
{
$topic = '';
}
$_CONF['topic'] = $topic ;
And finally here is the block - copied originally from COM_print_UpcomingEvents with mods
NOTE: the code here is only down to the end of the main SQL area - add the balance of the function from the original in lib-common
// duplicate of COM_printUpcomingEvents but allows selection by type
function phpblock_printUpcomingEvents( $help='', $title='' )
{
global $_TABLES, $LANG01, $_CONF, $_USER;
// NOTE: not good - had to add topic to the CONF array :(
$topic = $_CONF['topic'] ;
$query = 'SELECT topic FROM '
. "{$_TABLES['topics']} "
. " WHERE tid = '"
. $topic
. "' " ;
$result = DB_query( $query ) ;
$ITEM = DB_fetchArray($result, true) ;
$event_type = $ITEM[0] ;
$range = $_CONF['upcomingeventsrange'];
if( $range == 0 )
{
$range = 14; // fallback: 14 days }
$dateonly = $_CONF['dateonly']; if( empty( $dateonly )) {
$dateonly = '%d-%b'; // fallback: day - abbrev. month name
}
/* if( empty( $title ))
{
$title = DB_getItem( $_TABLES['blocks'], 'title', "name = 'events_block'" ); }
we don't need this title - block provides its own - richard
*/
$title = '' ; if ( $event_type != '' ) {
$title = "For: " . $event_type ;
}
$retval = COM_startBlock( $title, $help,
COM_getBlockTemplate( 'events_block', 'header' ));
if ( $event_type != '' ) {
// include the event_type in the lookup
$eventSql = 'SELECT eid,title,url,datestart,dateend,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon '
. "FROM {$_TABLES['events']} "
. "WHERE dateend >= NOW() AND (TO_DAYS(datestart) - TO_DAYS(NOW()) < $range) "
. "AND event_type = '"
. "$event_type"
. "' "
. 'ORDER BY datestart,timestart';
$personaleventsql = 'SELECT eid,title,url,datestart,dateend,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon '
. "FROM {$_TABLES['personal_events']} "
. "WHERE uid = {$_USER['uid']} AND dateend >= NOW() AND (TO_DAYS(datestart) - TO_DAYS(NOW()) < $range) "
. "AND event_type = '"
. "$event_type"
. "' "
. 'ORDER BY datestart, dateend';
} else {
// don't include the event_type in the lookup
$eventSql = 'SELECT eid,title,url,datestart,dateend,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon '
. "FROM {$_TABLES['events']} "
. "WHERE dateend >= NOW() AND (TO_DAYS(datestart) - TO_DAYS(NOW()) < $range) "
. 'ORDER BY datestart,timestart';
$personaleventsql = 'SELECT eid,title,url,datestart,dateend,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon '
. "FROM {$_TABLES['personal_events']} "
. "WHERE uid = {$_USER['uid']} AND dateend >= NOW() AND (TO_DAYS(datestart) - TO_DAYS(NOW()) < $range) "
. 'ORDER BY datestart, dateend';
}
// followed by all the rest of the code from that block - not copied here in the interests of brevity
Hope this is useful to someone - and I'd appreciate feedback on how to do this any easier or at least without hacking admin/event.php (and not hitting the database uselessly every page load as would happen with the hack in lib-custom) and how not to have to stuff things onto one of the main global arrays ($_CONF in this case) to get info from the URL into a function used in a block.
thanks
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content