TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 17, 2024, 07:28:04 AM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 59
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 33
  • Total: 33

[Non TP Specific] - SMF Calendar Mod Help

Started by ed_m, May 27, 2009, 03:53:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ed_m2


If this falls on dead ears no problem, I'll keep plugging away on my own.

If any coding gurus feel like getting their teeth into this and lending a hand / brain to it that'd be fab.

If you look on the ultrarunner site, you'll see a increasing list of events in the events forum & on the calendar. This is a big plus for the site and I'd like to make more of it by adding some custom fields to the events (race type, distance etc etc) and later adding a custom search of events via these fields.

For now I'm just trying to add two new fields to learn how to do it, here's where I'm at:
- Added two new fields to the events table in the db
- Modified the post/calendar templates in the theme to add input box & drop down for the two new fields
- Modified the post.php & calendar.php source files where the INSERT & MODIFY functions happen to insert some constant data into the db
- Modified the template file to read back the db fields when editing an event

What I need to do next is modify the source files and/or form templates to pass the data from the form to the function that does the inserting/modifying.

I've had a couple of goes at this and failed with some errors.
It seems like I'm close but just missing something.

Once I understand the process I can add various other fields I'd like.



So if any kind coders *cough*JP*cough* has time or interest to collaborate here let me know.
Happy to liase via this thread & share progress/results... or take it offline if preferred.

Thanks for your time anyway!
E.

PS yes i know i need to do 1.1.9 update, i've switched off attachments/avatars for now.

JPDeni

What did you do that didn't work? What errors did you get?

ed_m2

alot to digest here... but i want to give as much info as possible and i've been noting what i've changed and where as i go along.

i had the horrible feeling writing it all down would help me understand why its not working... but alas..

so ok (and thanks) for example in calendar.php i have modifed the INSERT in calendarInsertEvent() as follows:


// Insert the event!
db_query("
INSERT INTO {$db_prefix}calendar
(ID_BOARD, ID_TOPIC, title, ID_MEMBER, startDate, endDate, dist_type, dist_val)
VALUES ($id_board, $id_topic, SUBSTRING('$title', 1, 48), $id_member, '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year)) . "', '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year) + $span * 86400) . "','km',50)", __FILE__, __LINE__);


where dist_type and dist_val are new fields set to 'km' and '50' ... works ok.
i think this is the code called when creating a new event from scratch (not editing an existing event or adding and event to an existing topic).

there are UPDATE statements both in Calendar.php & Post.php I've modified similarly, not quite got to the bottom of which one is called when.

(all this works ok for entering constant values in the db & editing events etc)

I've modified the arguments passed to calendarInsertEvent() to include two new variables:

function calendarInsertEvent($id_board, $id_topic, $title, $id_member, $month, $day, $year, $span, $dist_type, $dist_val)


And in CalendarPost(), comment says it deals with posting/editing/deleting events, added the new values in the same $_POST format as the rest:


// New...
elseif ($_REQUEST['eventid'] == -1)
// EM add extra arguments to pass to insertevent function.
calendarInsertEvent(0, 0, $_POST['evtitle'], $ID_MEMBER, $_POST['month'], $_POST['day'], $_POST['year'], isset($_POST['span']) ? $_POST['span'] : null,$_POST['dist_type'], $_POST['dist_val']);



The insert event has been modifed to:


// Insert the event!
// EM modified to add passed values for extra event fields
db_query("
INSERT INTO {$db_prefix}calendar
(ID_BOARD, ID_TOPIC, title, ID_MEMBER, startDate, endDate, dist_type, dist_val)
VALUES ($id_board, $id_topic, SUBSTRING('$title', 1, 48), $id_member, '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year)) . "', '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year) + $span * 86400) . "', $dist_type, $dist_val)", __FILE__, __LINE__);


And to the Calendar.template.php I've added:


// EM extra event data fields
echo '<tr><td align="right"><b>Distance:</b></td>
<td class="smalltext">

<input type="text" name="dist_val" maxlength="5" size="5">

<select name="dist_type">
  <option value="mile">mile</option>
  <option value="km">km</option>
  <option value="hour">hour</option>
</select>
</td></tr>';


(I hope you follow most of that!)

All this gives a database error:


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 3
File: /home/default/ultrarunner.co.uk/user/htdocs/smf/Sources/Calendar.php
Line: 458


458 is the modified INSERT statement above.... i've just double checked to see i havent lost any brackets but i guess it doesnt like something about the passed variable i'm trying to insert.

answers on a postcard!

JPDeni

Quotei think this is the code called when creating a new event from scratch (not editing an existing event or adding and event to an existing topic).

Right.

It does make it clearer what you're doing and a whole lot easier than me starting from scratch. :)

I would try putting single quotes around your variables:


// Insert the event!
// EM modified to add passed values for extra event fields
db_query("
INSERT INTO {$db_prefix}calendar
(ID_BOARD, ID_TOPIC, title, ID_MEMBER, startDate, endDate, dist_type, dist_val)
VALUES ($id_board, $id_topic, SUBSTRING('$title', 1, 48), $id_member, '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year)) . "', '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year) + $span * 86400) . "', '$dist_type', '$dist_val')", __FILE__, __LINE__);


You really should have any text that's going into the database enclosed in single quotes and it's okay to have numbers enclosed.

I don't know if that will fix it, but that's the first thing I'd do.

ed_m2

ok.. thanks .. yes all the numeric variables don't have single quotes but the date strings do.

will try tomorrow night.
need sleep now.

thank you!

ed_m2

Ok cool this allows a new event to post without crashing, but inserts blanks in the db.


// Insert the event!
// EM modified to add passed values for extra event fields
db_query("
INSERT INTO {$db_prefix}calendar
(ID_BOARD, ID_TOPIC, title, ID_MEMBER, startDate, endDate, dist_type, dist_val)
VALUES ($id_board, $id_topic, SUBSTRING('$title', 1, 48), $id_member, '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year)) . "', '" . strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $day, $year) + $span * 86400) . "', '$dist_type', '$dist_val')", __FILE__, __LINE__);


if i set the variable values explicitly directly above the INSERT it inserts those values ok so... this implies the values aren't being passed from the CalendarPost() function or read from the form with $_POST ?

any suggestions how i can trace these variables through ?

IchBin

This is where debugging comes in. :) You'll need to start echo'ing out variables and testing to see if they are empty before you pass them into your query.

ed_m2

Quote from: IchBinâ„¢ on May 28, 2009, 09:48:35 PM
This is where debugging comes in. :) You'll need to start echo'ing out variables and testing to see if they are empty before you pass them into your query.

hmmm yeh but its not clear to me from the function calls etc where they'll get echo'd..... spose i'll give it a go next time around :-)

i'm far too familiar with debugging embedded c from my day job.. just not php.

JPDeni

Without actually looking at the code :) I would suggest that you echo the $_POST array in whatever the template is that is displayed after a form is submitted. I know there's another command that prints out all the elements of an array, but you can use something like this


foreach ($_POST as $value => $key)
  echo $key . ' -- ' . $value . '<br />';

ed_m2

printr rings a bell ?

printr($_POST)....   later :-)