- $r = q("SELECT * FROM `item` WHERE `verb` = '%s' AND `deleted` = 0
- AND `contact-id` = %d AND ( `parent` = '%s' OR `parent-uri` = '%s') LIMIT 1",
- dbesc($activity),
- intval($contact['id']),
- dbesc($item_id),
- dbesc($item_id)
+ // See if we've been passed a return path to redirect to
+ $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
+
+ $verbs = " '".dbesc($activity)."' ";
+
+ // event participation are essentially radio toggles. If you make a subsequent choice,
+ // we need to eradicate your first choice.
+ if($activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE) {
+ $verbs = " '" . dbesc(ACTIVITY_ATTEND) . "','" . dbesc(ACTIVITY_ATTENDNO) . "','" . dbesc(ACTIVITY_ATTENDMAYBE) . "' ";
+ }
+
+ $r = q("SELECT `id`, `guid` FROM `item` WHERE `verb` IN ( $verbs ) AND `deleted` = 0
+ AND `contact-id` = %d AND `uid` = %d
+ AND (`parent` = '%s' OR `parent-uri` = '%s' OR `thr-parent` = '%s') LIMIT 1",
+ intval($contact['id']), intval($owner_uid),
+ dbesc($item_id), dbesc($item_id), dbesc($item['uri'])