Welcome to Geeklog Thursday, November 21 2019 @ 05:52 am EST

Geeklog Forums

Calendar events by topic


Status: offline

richardpitt

Forum User
Newbie
Registered: 07/01/04
Posts: 11
Location:49'13'10.32N 122'41'07.83W
While I'm new to hacking Geeklog (and php for that matter) I've been programming and hacking since the days of steam Wink


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:
[code] // 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'] ; } } [/code]

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.
[code]// 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 ; [/code]

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

[code] // 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 Frown $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 [/code]

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

 Quote

All times are EST. The time is now 05:52 am.

  • 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