Posted on: 10/28/05 12:17pm
By: 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'] ; } }
// get topic from URL so we can select // 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 ;
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
thanks