/[drupal]/contributions/modules/rsvp/rsvp.functions.inc
ViewVC logotype

Contents of /contributions/modules/rsvp/rsvp.functions.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Feb 5 23:28:36 2009 UTC (9 months, 3 weeks ago) by ulf1
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.2: +176 -15 lines
File MIME type: text/x-php
*** empty log message ***
<
1 <?php
2
3 // $Id: rsvp.functions.inc,v 1.2 2009/02/05 02:25:27 ulf1 Exp $
4
5 /**
6 * @module rsvp_functions
7 * @package rsvp - A drupal module developed for civicspace - a distribution of drupal.
8 * @description Provides rsvp internal functions that can be called by other rsvp functions
9 * @author Ulf Schenk (ulf@schenkunlimited.net)
10 *
11 */
12
13 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
14
15 /**
16 * RSVP EMAIL ADDRESS USAGE
17 */
18 define('RSVP_EMAIL_SITEADDRESS', 0);
19 define('RSVP_EMAIL_SETTINGS', 1);
20 define('RSVP_EMAIL_CREATOR', 2);
21
22 /**
23 * RSVP ATTENDING OPTIONS (also stored in the database)
24 */
25 define('RSVP_ATT_YES', 'yes');
26 define('RSVP_ATT_NO', 'no');
27 define('RSVP_ATT_MAYBE', 'maybe');
28 define('RSVP_ATT_NONE', 'none');
29 /**
30 * ADDTL. RSVP ATTENDING OPTIONS (only used in memory)
31 */
32 define('RSVP_ATT_ALL', 'all');
33 define('RSVP_ATT_NOTSEND','notsend');
34
35
36 define('RSVP_OPEN_INVITATION', 'open');
37
38
39 /**
40 * RSVP RESPONSE OPTIONS
41 */
42 define('RSVP_RESPONSE_HIDE', 0);
43 define('RSVP_RESPONSE_SHOW', 1);
44 define('RSVP_RESPONSE_SHOWWHENREPLIED', 2);
45
46 /**
47 * RSVP REPLY OPTIONS
48 */
49 define('RSVP_REPLY_HIDE', 0);
50 define('RSVP_REPLY_SHOW', 1);
51
52 /**
53 * RSVP ATTENDEE_VISIBLE OPTIONS
54 */
55 define('RSVP_INVITEE_HIDE', 0);
56 define('RSVP_INVITEE_SHOW', 1);
57 define('RSVP_INVITEE_SHOWRESPONSEWHENREPLIED', 2);
58
59 /**
60 * RSVP SEND OPTIONS
61 */
62 define('RSVP_SEND_NONE', 0);
63 define('RSVP_SEND_INVITEE', 1);
64 define('RSVP_SEND_RESPONDENT', 2);
65 define('RSVP_SEND_ATTENDEE', 3);
66
67 /**
68 * RSVP INVITE OTHER OPTIONS
69 */
70 define('RSVP_INVITE_NONE', 0);
71 define('RSVP_INVITE_INVITEE', 1);
72 define('RSVP_INVITE_RESPONDENT', 2);
73 define('RSVP_INVITE_ATTENDEE', 3);
74
75 /**
76 * RSVP GENERAL OPTIONS
77 */
78 define('RSVP_OPTION_NO', 0);
79 define('RSVP_OPTION_YES', 1);
80
81 /**
82 * RSVP GUESTLIST SHOW/SORT OPTIONS
83 */
84 define('RSVP_GUESTLIST_SORT_ALPHA', 'sa');
85 define('RSVP_GUESTLIST_SORT_DATE', 'sd');
86 define('RSVP_GUESTLIST_SHOW_ALL', 'all');
87 define('RSVP_GUESTLIST_SHOW_PART', 'part');
88
89 /**
90 * PATH WHERE THE USER DEFINED THEMES ARE LOCATED
91 */
92
93 define('RSVP_FILES_THEMES_PATH', 'rsvp/themes');
94 define('RSVP_FILES_ICONS_PATH', 'rsvp/icons');
95 define('RSVP_FILES_BACKGROUNDIMAGE_PATH', 'rsvp/backgrounds');
96 define('RSVP_FILES_IMAGE_PATH', 'rsvp/images');
97
98 define('RSVP_THEMES_PATH', 'themes');
99 define('RSVP_ICONS_PATH', 'icons');
100 define('RSVP_BACKGROUNDIMAGE_PATH', 'backgrounds');
101 define('RSVP_IMAGE_PATH', 'images');
102
103 define('RSVP_THEME_DEFAULT', 'default');
104 define('RSVP_STYLESHEET_DEFAULT', 'default');
105 define('RSVP_ICONSET_DEFAULT', 'flags');
106 define('RSVP_BACKGROUNDIMAGE_DEFAULT', 'none');
107 define('RSVP_IMAGE_DEFAULT', 'none');
108
109 /**
110 * RSVP ACCESS OPTIONS
111 */
112 define('RSVP_ACCESS_VIEW', 'v'); //maintainer, moderator, owner, co-moderator, guest, view by role permission
113 define('RSVP_ACCESS_REPLY', 'r'); //maintainer, moderator, owner, co-moderator, guest
114 define('RSVP_ACCESS_EDIT', 'e'); //maintainer, moderator, owner, co-moderator
115 define('RSVP_ACCESS_CREATE', 'c'); //maintainer, moderator, create permissions
116 define('RSVP_ACCESS_DELETE', 'd'); //maintainer, moderator, owner, co-moderator
117 define('RSVP_ACCESS_MAINTAIN', 'm'); //maintainer
118 define('RSVP_ACCESS_GUEST', 'g'); //maintainer, guest
119 define('RSVP_ACCESS_GUESTONLY', 'o'); //guest
120 define('RSVP_ACCESS_BYROLE', 'b'); //view by role permission
121
122
123 /**
124 * RSVP PERMISSIONS
125 */
126 define('RSVP_PERM_ADMIN', 'administer rsvp');
127 define('RSVP_PERM_MAINTAIN', 'maintain rsvp');
128 define('RSVP_PERM_ONEVENTS', 'rsvp on events');
129 define('RSVP_PERM_ONOWNEVENTS', 'rsvp on own events');
130 define('RSVP_PERM_INVITE_ROLE', 'rsvp invite by role');
131
132
133 /**
134 * RSVP ERRORCODES
135 */
136 define('RSVP_DELETED', true);
137 define('RSVP_ERROR_DELETE_REAL_NAME', -1);
138 define('RSVP_ERROR_DELETE_USER_RECORDS', -2);
139 define('RSVP_ERROR_DELETE_RSVP', -3);
140
141
142
143 /**
144 * Creates a new invitation(rsvp).
145 *
146 * Permission check needs to be done outside.
147 *
148 * @ingroup rsvp_functions
149 * @param $rsvp The rsvp object we want to create.
150 * @return int key id of the rsvp instance or false on failure.
151 */
152
153 function rsvp_function_create_rsvp($rsvp) {
154 global $user;
155
156 $fields[] = 'timestamp';
157 $vals[] = time();
158 $markers[] = "%d";
159
160 $fields[] = 'uid';
161 $vals[] = $user->uid;
162 $markers[] = "%d";
163
164 foreach (array('nid', 'startdate', 'uid_moderator', 'reply_startdate', 'reply_enddate', 'max_guests', 'open_invitation', 'disable_maybe', 'send_privatemsg', 'send_conf_guest', 'send_conf_owner', 'invite_filterformat') as $key) {
165 $fields[] = $key;
166 $vals[] = $rsvp->$key;
167 $markers[] = "%d";
168 }
169
170 foreach (array('name', 'theme', 'stylesheet', 'iconset', 'backgroundimage', 'image', 'rsvp_view_roles', 'response_view_roles', 'invite_text', 'response_blind', 'response_blind_node', 'reply_blind_node', 'attendees_visible', 'list_email', 'allow_invite', 'text_whoiscoming', 'text_yes', 'text_no', 'text_maybe') as $key) {
171 $fields[] = $key;
172 $vals[] = $rsvp->$key;
173 $markers[] = "'%s'";
174 }
175
176 $sql = 'INSERT INTO {rsvp} ('. implode(", ", $fields) .') VALUES ('. implode(", ", $markers) .')';
177 if (db_query($sql, $vals)) {
178 $rsvp->rid = db_last_insert_id('rsvp', 'rid');
179
180 return $rsvp->rid;
181 }
182 else {
183 drupal_set_message(t('There was an error creating the invitation. Please try again'), 'error');
184 return FALSE;
185 }
186 }
187
188
189 /**
190 * Updates an invitation(rsvp)
191 *
192 * Permission check needs to be done outside.
193 *
194 * @ingroup rsvp_functions
195 * @param $rsvp The rsvp object we want to update.
196 * @return boolean true on success.
197 */
198
199 function rsvp_function_update_rsvp($rsvp) {
200
201 $rid = $rsvp->rid;
202
203 if (!$rid) {
204 return false;
205 }
206
207 $fields[] = 'timestamp = %d';
208 $vals[] = time();
209
210 foreach (array('nid', 'uid', 'startdate', 'uid_moderator', 'reply_startdate', 'reply_enddate', 'max_guests', 'open_invitation', 'disable_maybe', 'send_privatemsg', 'send_conf_guest', 'send_conf_owner','invite_filterformat') as $key) {
211 $fields[] = $key ." = %d";
212 $vals[] = $rsvp->$key;
213 }
214
215 foreach (array('name', 'invite_text', 'theme', 'stylesheet', 'iconset', 'backgroundimage', 'image', 'rsvp_view_roles', 'response_view_roles', 'response_blind', 'response_blind_node', 'reply_blind_node', 'attendees_visible', 'list_email', 'allow_invite', 'text_whoiscoming', 'text_yes', 'text_no', 'text_maybe') as $key) {
216 $fields[] = $key ." = '%s'";
217 $vals[] = $rsvp->$key;
218 }
219
220 $vals[] = $rid;
221
222 $sql = 'UPDATE {rsvp} SET '. implode(', ', $fields) .' WHERE rid = %d';
223
224 if (db_query($sql, $vals)) {
225 drupal_set_message(t('Invitation updated.'));
226 return TRUE;
227 }
228 else {
229 drupal_set_message(t('There was an error updating the invitation.'), 'error');
230 return FALSE;
231 }
232 }
233
234 /**
235 * Deletes an invitation(rsvp)
236 *
237 * Permission check needs to be done outside.
238 *
239 * @ingroup rsvp_functions
240 * @param $rid The rid of the rsvp to delete.
241 * @return boolean true on success.
242 */
243 function rsvp_function_delete_rsvp($rid) {
244
245 if (is_null($rid) || !is_numeric($rid)) {
246 drupal_set_message(t('Invitation %rid is not a valid type.', array('%rid' => $rid)), 'error');
247 return RSVP_ERROR_DELETE_RSVP;
248 }
249
250 if (db_query('DELETE FROM {rsvp} WHERE rid = %d', $rid)) {
251 if (db_query('DELETE FROM {rsvp_invite} WHERE rid = %d', $rid)) {
252 return RSVP_DELETED;
253 }
254 else {
255 return RSVP_ERROR_DELETE_USER_RECORDS;
256 }
257 }
258 else {
259 return RSVP_ERROR_DELETE_RSVP;
260 }
261 }
262
263 /**
264 * Retrieves an invitation(rsvp) from the database.
265 *
266 * Permission check needs to be done outside.
267 *
268 * @ingroup rsvp_functions
269 * @param $rid The rid of the rsvp instance.
270 * @return The $rsvp instance or false.
271 */
272 function rsvp_function_load_rsvp($rid) {
273 $rsvp = db_fetch_object(db_query('SELECT * FROM {rsvp} WHERE rid = %d', $rid));
274
275 if ($rsvp == false) {
276 drupal_set_message(t('The invitation you requested (rid=%rid) is invalid or has been deleted.', array('%rid' => $rid)));
277 }
278
279 return $rsvp;
280 }
281
282 /**
283 * Retrieves a node from the database, based on a particular invitation.
284 *
285 * Permission check needs to be done outside.
286 *
287 * @ingroup rsvp_functions
288 * @param $object The rsvp object that you want the node to load for or the $nid (numeric).
289 * @return The $node instance or false.
290 */
291 function rsvp_function_load_node($object) {
292
293 if (is_numeric($object)) {
294 $node = node_load($object);
295 if ($node == false) {
296 drupal_set_message(t('The node you requested (nid=%nid) has been deleted.', array('%nid' => $object)));
297 }
298 }
299 else {
300 //$object is a $rsvp instance
301 $node = node_load($object->nid);
302 if ($node == false) {
303 drupal_set_message(t('The node you requested (nid=%nid) that belongs to invitation (rid=%rid) has been deleted.', array('%rid' => $object->rid, '%nid' => $object->nid)));
304 }
305 }
306
307 return $node;
308 }
309
310 /**
311 * Returns a particular invitation that a user has received.
312 *
313 * @ingroup rsvp_functions
314 * @param $rid The rsvp id of the invitation.
315 * @param $uid The uid of the user. If NULL, use logged in users credentials
316 * @param $print Boolean print drupal message in case of error.
317 * *
318 * @return invite object or false.
319 */
320 function rsvp_function_load_invitation_rid($rid, $uid = NULL, $print = true) {
321
322 $uid = _rsvp_function_check_uid($uid);
323 if (is_null($uid)) {
324 return false;
325 }
326
327 $invite_target = db_fetch_object(db_query('SELECT * FROM {rsvp_invite} u LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE u.uid = %d AND u.rid = %d', $uid, $rid));
328
329 if (($invite_target == false) && ($print == true)) {
330 drupal_set_message(t('The invitation (rid=%rid) that you (uid=%uid) requested is invalid or has been deleted.', array('%rid' => $rid, '%uid' => $uid)));
331 }
332
333 return $invite_target;
334 }
335
336 /**
337 * Checks that the incoming $uid is not anonymous user.
338 *
339 * @ingroup rsvp_functions
340 * @param $uid The uid of the user. If NULL, use logged in users credentials. returns NULL if anonymous.
341 *
342 * @return cleared $uid.
343 */
344 function _rsvp_function_check_uid($uid) {
345 if (is_null($uid) || ($uid == 0)) {
346 if (user_is_anonymous())
347 return NULL;
348
349 global $user;
350 $uid = $user->uid;
351 if ($uid == 0)
352 return NULL;
353 }
354
355 return $uid;
356 }
357
358 /**
359 * Returns an invite by hash value.
360 *
361 * @ingroup rsvp_functions
362 * @param $hash The hash value of the invitee.
363 * @return dbresultset of the requested invite or false.
364 */
365 function rsvp_function_load_invitation_hash($hash) {
366
367
368 $invite_target = db_fetch_object(db_query('SELECT u.*,n.realname FROM {rsvp} r LEFT JOIN {rsvp_invite} u ON r.rid = u.rid LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE u.hash = \'%s\'', $hash));
369 if ($invite_target == false) {
370 drupal_set_message(t('The invitation (hash=%hash) that you requested is invalid or has been deleted.', array('%hash' => $hash)));
371 }
372
373 return $invite_target;
374
375 }
376
377 /**
378 * Returns selective guests for an invitation based on the passed status
379 *
380 * @ingroup rsvp_functions
381 * @param $rid The rid of the rsvp instance.
382 * @param $status const of type (RSVP_ATT_ALL,...)
383 * @param $count Boolean. If true return an interger with the number of found elements. If false return elements.
384 * *
385 * @return dbresultset of the requested attendees.
386 */
387 function rsvp_function_load_guests($rid, $status = RSVP_ATT_ALL, $count = FALSE, $tablesort = ' ORDER BY u.email') {
388
389 if ($status == RSVP_ATT_ALL || !isset($status))
390 $result = db_query('SELECT '. ($count ? 'SUM(totalguests)' : 'u.*,n.realname') .' FROM {rsvp_invite} u LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE rid = %d ' . $tablesort, $rid);
391 else
392 $result = db_query('SELECT '. ($count ? 'SUM(totalguests)' : 'u.*,n.realname') .' FROM {rsvp_invite} u LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE rid = %d AND response=\'%s\'' . $tablesort, $rid, $status);
393
394 if ($result == false) {
395 drupal_set_message(t('The invitation you requested (rid=%rid) is invalid or has been deleted.', array('%rid' => $rid)));
396 }
397
398 return $result;
399 }
400
401 /**
402 * Return totals for each type (RSVP_ATT_ALL,...) for an invitation
403 *
404 * @ingroup rsvp_functions
405 * @param $rid The rid of the rsvp instance.
406 * @return dbresultset of the requested attendees.
407 */
408 function rsvp_function_load_totalguests($rid) {
409 $skip = false;
410 $responses = array(RSVP_ATT_NONE, RSVP_ATT_YES, RSVP_ATT_NO, RSVP_ATT_MAYBE);
411 foreach ($responses as $response) {
412 $total = db_result(db_query('SELECT SUM(totalguests) FROM {rsvp_invite} u WHERE u.rid = %d AND u.response = \'%s\'', $rid, $response));
413
414
415 $totals[$response] = (int) $total;
416 $totals[RSVP_ATT_ALL] += (int) $total;
417
418 }
419 return $totals;
420 }
421
422 /**
423 * Remove a guest from an invitation.
424 *
425 * @ingroup rsvp_functions
426 * @param $hash The hash value of the invitee.
427 * @return boolean true if successful.
428 */
429 function rsvp_function_remove_guest($hash) {
430 return db_query('DELETE FROM {rsvp_invite} WHERE hash = \'%s\'', $hash);
431 }
432
433 /**
434 * Checks if an invitation for a user (by email address) already exists and returns it.
435 *
436 * @ingroup rsvp_functions
437 * @param $rid The id of the rsvp instance.
438 * @param $email The email to check for.
439 * @return boolean false if the email don't exist for the rsvp, or the $invitation object.
440 */
441 function rsvp_function_exists_guest_email($rid, $email) {
442 return db_fetch_object(db_query('SELECT u.*,n.realname FROM {rsvp_invite} u LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE u.rid = %d AND u.email = \'%s\'', $rid, $email));
443 }
444
445 /**
446 * Checks if an invitation for a user (by user id) already exists and returns it.
447 * *
448 * @ingroup rsvp_functions
449 * @param $rid The id of the rsvp instance.
450 * @param $uid The user uid to check for.
451 * @return boolean false if the email don't exist for the rsvp, or the $invitation object.
452 */
453 function rsvp_function_exists_guest_uid($rid, $uid) {
454
455 $uid = _rsvp_function_check_uid($uid);
456 if (is_null($uid)) {
457 return false;
458 }
459
460 return db_fetch_object(db_query('SELECT u.*,n.realname FROM {rsvp_invite} u LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE u.rid = %d AND u.uid = %d', $rid, $uid));
461 }
462
463 /**
464 * Creates a new realname dataset(rsvp).
465 *
466 * Permission check needs to be done outside.
467 *
468 * @ingroup rsvp_functions
469 * @param $invite_target The invite instance you want to create a realname entry for.
470 * @param $realname The real name you want to store.
471 *
472 * @return true or false on failure.
473 */
474
475 function rsvp_function_create_rsvp_realname($invite_target, $realname) {
476 global $user;
477
478 $fields[] = 'realname';
479 $vals[] = $realname;
480 $markers[] = "'%s'";
481
482 $fields[] = 'email';
483 $vals[] = $invite_target->email;
484 $markers[] = "'%s'";
485
486
487 $sql = 'INSERT INTO {rsvp_realname} ('. implode(", ", $fields) .') VALUES ('. implode(", ", $markers) .')';
488 if (db_query($sql, $vals)) {
489 return true;
490 }
491 else {
492 drupal_set_message(t('There was an error creating the realname. Please try again'), 'error');
493 return FALSE;
494 }
495 }
496
497
498 /**
499 * Updates an rsvp_realname
500 *
501 * Permission check needs to be done outside.
502 *
503 * @ingroup rsvp_functions
504 * @param $invite_target The invite instance you want to update the realname entry for.
505 * @param $realname The real name you want to store.
506 * @return boolean true on success.
507 */
508
509 function rsvp_function_update_rsvp_realname($invite_target, $realname) {
510
511 $fields[] = 'realname = \'%s\'';
512 $vals[] = $realname;
513
514 $vals[] = $invite_target->email;
515
516 $sql = 'UPDATE {rsvp_realname} SET '. implode(', ', $fields) .' WHERE email = \'%s\'';
517
518 if (db_query($sql, $vals)) {
519 return TRUE;
520 }
521 else {
522 drupal_set_message(t('There was an error updating the Real name.'), 'error');
523 return FALSE;
524 }
525 }
526
527 /**
528 * Deletes a rsvp_realname
529 *
530 * Permission check needs to be done outside.
531 *
532 * @ingroup rsvp_functions
533 * @param $invite_target The invite instance you want to update the realname entry for.
534 * @return boolean true on success.
535 */
536 function rsvp_function_delete_rsvp_realname($invite_target) {
537
538 if (db_query('DELETE FROM {rsvp_realname} WHERE email = \'%s\'', $invite_target->email)) {
539 return RSVP_DELETED;
540 }
541 else {
542 return RSVP_ERROR_DELETE_REAL_NAME;
543 }
544 }
545
546 /**
547 * Checks if a rsvp_realname for an invite object (by email) already exists and returns it.
548 * *
549 * @ingroup rsvp_functions
550 * @param $invite_target The invite instance you want to update the realname entry for.
551 * @return boolean false if the realname don't exist for the invite object, or the realname object.
552 */
553 function rsvp_function_exists_rsvp_realname($invite_target) {
554
555 return db_fetch_object(db_query('SELECT * FROM {rsvp_realname} WHERE email = \'%s\'', $invite_target->email));
556 }
557
558
559
560
561 /**
562 * Returns a new $rsvp Object with default settings.
563 *
564 * Permission check needs to be done outside.
565 *
566 * @ingroup rsvp_functions
567 */
568
569 function rsvp_function_initialize_default_rsvp() {
570
571 //create a rsvp and use it to set the default values.
572 $rsvp = new stdClass();
573
574 $rsvp->text_yes = variable_get('rsvp_default_text_yes', t('Attend'));
575 $rsvp->text_no = variable_get('rsvp_default_text_no', t('Attend not'));
576 $rsvp->text_maybe = variable_get('rsvp_default_text_maybe', t('Undecided'));
577 $rsvp->text_whoiscoming = variable_get('rsvp_default_text_whoiscoming', t('Responses'));
578 $rsvp->response_blind = variable_get('rsvp_default_response_blind', RSVP_RESPONSE_SHOW);
579 $rsvp->response_blind_node = variable_get('rsvp_default_response_blind_node', RSVP_RESPONSE_HIDE);
580 $rsvp->attendees_visible = variable_get('rsvp_default_attendees_visible', RSVP_INVITEE_HIDE);
581 $rsvp->response_view_roles = variable_get('rsvp_default_response_view_roles', '');
582 $rsvp->rsvp_view_roles = variable_get('rsvp_default_rsvp_view_roles','');
583 $rsvp->reply_blind_node = variable_get('rsvp_default_reply_blind_node', RSVP_REPLY_HIDE);
584 $rsvp->list_email = variable_get('rsvp_default_list_email', RSVP_SEND_NONE);
585 $rsvp->allow_invite = variable_get('rsvp_default_allow_invite', RSVP_INVITE_NONE);
586
587 $rsvp->send_conf_owner = variable_get('rsvp_default_send_conf_owner', RSVP_OPTION_NO);
588 $rsvp->send_conf_guest = variable_get('rsvp_default_send_conf_guest', RSVP_OPTION_NO);
589 $rsvp->send_privatemsg = variable_get('rsvp_default_send_privatemsg', RSVP_OPTION_NO);
590 $rsvp->disable_maybe = variable_get('rsvp_default_disable_maybe', RSVP_OPTION_NO);
591 $rsvp->open_invitation = variable_get('rsvp_default_open_invitation', RSVP_OPTION_NO);
592 $rsvp->max_guests = variable_get('rsvp_default_max_guests', 0);
593 $rsvp->theme = variable_get('rsvp_default_theme', RSVP_THEME_DEFAULT);
594 $rsvp->stylesheet = variable_get('rsvp_default_stylesheet', RSVP_STYLESHEET_DEFAULT);
595 $rsvp->iconset = variable_get('rsvp_default_iconset', RSVP_ICONSET_DEFAULT);
596 $rsvp->backgroundimage = variable_get('rsvp_default_backgroundimage', RSVP_BACKGROUNDIMAGE_DEFAULT);
597 $rsvp->image = variable_get('rsvp_default_image', RSVP_IMAGE_DEFAULT);
598
599 $rsvp->invite_filterformat = FILTER_FORMAT_DEFAULT;
600
601 return $rsvp;
602 }
603
604
605 /**
606 * Internal function
607 *
608 * Adds a number of guests to an invitation(rsvp)
609 *
610 * Permission check needs to be done outside.
611 *
612 * @ingroup rsvp_functions
613 *
614 * @param $rsvp The rsvp instance.
615 * @param $invite_caller The invitation object of the user who adds the guests,
616 * or NULL if the rsvp owner, co_owner or moderator adds the guests,
617 * or const RSVP_OPEN_INVITATION for an open invitation
618 *
619 * @param $guestsarray Stringarray Contains a mix of email addresses and drupal usernames.
620 *
621 * @return array with failed emailaddresses or false
622 */
623 function _rsvp_function_add_guests($rsvp, $invite_caller, $guestsarray) {
624
625 $emails = array();
626
627 // remove duplicates from guestlist array
628 $guestsarray = array_unique($guestsarray);
629
630 $rid = $rsvp->rid;
631
632 if (is_null($invite_caller))
633 $owner_hash = '';
634 elseif ($invite_caller == RSVP_OPEN_INVITATION)
635 $owner_hash = RSVP_OPEN_INVITATION;
636 else
637 $owner_hash = $invite_caller->hash;
638
639
640 foreach ($guestsarray as $key => $value) {
641
642 $list_key = NULL;
643 $invite_hash = NULL;
644
645 // strip whitespace
646 $string = trim($value);
647
648 if (strlen($string)) {
649 // attempt to deal with the string as a drupal username
650 // we do this before dealing it as an e-mail to handle users like
651 // foo@somesite.com
652 $usr = user_load(array('name' => $string));
653 if ($usr === FALSE) {
654 // attempt to find a system user having this string as an e-mail address
655 $usr = user_load(array('mail' => $string));
656 if ($usr === FALSE) {
657 // no user found: carry on dealing with the string as an e-mail address
658 if (valid_email_address($string)) {
659 $invite_target = rsvp_function_exists_guest_email($rid, $string);
660 if (!$invite_target) {
661 // if this e-mail is not in the attendee list,
662 // add it
663 $hash = md5($rid . $string . time());
664 if (db_query('INSERT INTO {rsvp_invite} (rid, inviteehash, email, hash, timestamp, response, comment, totalguests) VALUES (%d, \'%s\', \'%s\', \'%s\', %d, \'%s\', \'%s\', %d)', $rid, $owner_hash, $string, $hash, time(), 'none', '', 1)) {
665 $invite_hash = $hash;
666 $list_key = 'success_add';
667 }
668 }
669 else {
670 // the e-mail is already in the attendee list
671 $invite_hash = $invite_target->hash;
672 $list_key = 'existing';
673 }
674 }
675 else {
676 // the e-mail is invalid
677 $invite_hash = NULL;
678 $list_key = 'invalid';
679 }
680 }
681 }
682
683 if ($usr != FALSE) {
684 // a valid drupal user was found, make sure his/her e-mail isn't already
685 // in the attendees list
686 $invite_target = rsvp_function_exists_guest_uid($rid, $usr->uid);
687 if (!$invite_target) {
688 $hash = md5($rid . $string . time());
689 if (db_query('INSERT INTO {rsvp_invite} (rid, uid, inviteehash, email, hash, timestamp, response, comment, totalguests) VALUES (%d, %d, \'%s\', \'%s\', \'%s\', %d, \'%s\', \'%s\', %d)', $rid, $usr->uid, $owner_hash, $usr->mail, $hash, time(), 'none', '', 1)) {
690 $invite_hash = $hash;
691 $list_key = 'success_add';
692 }
693 }
694 else {
695 // the uid is already in the attendee list
696 $invite_hash = $invite_target->hash;
697 $list_key = 'existing';
698 }
699 }
700
701 if ($invite_hash != NULL) {
702 $invite_target = rsvp_function_load_invitation_hash($invite_hash);
703 $emails[$list_key][] = rsvp_function_getGuestEmail($invite_target);
704 }
705 else {
706 $emails[$list_key][] = $string;
707 }
708 }
709 }
710
711 return $emails;
712 }
713
714
715 /**
716 * Adds a number of guests to an invitation(rsvp) and sends out emails
717 *
718 * Permission check needs to be done outside.
719 *
720 * @ingroup rsvp_functions
721 *
722 * @param $rsvp The rsvp instance.
723 * @param $invite_caller The invitation object of the user who adds the guests,
724 * or NULL if the rsvp owner, co-owner or maintainer adds the guests,
725 * or const RSVP_OPEN_INVITATION for an open invitation
726 * @param $guestsarray Stringarray Contains a mix of email addresses and drupal usernames.
727 * @param $send_rsvp Boolean Also send the invitations or just add the invitees to the invitation.
728
729 * @return array with statusmessages or false
730 *
731 */
732 function rsvp_function_add_guests($rsvp, $invite_caller, $guestsarray, $send_rsvp) {
733
734 $content = '';
735
736 $add_status = _rsvp_function_add_guests($rsvp, $invite_caller, $guestsarray);
737
738 $send_status = array();
739
740 if ($send_rsvp == true) {
741 // send invitations
742 if ($invite_caller == RSVP_OPEN_INVITATION)
743 $invite_caller = NULL; //set $invite_caller back to NULL before sending the invitation.
744
745 $send_status = rsvp_function_send_multiple_invitations($rsvp, $invite_caller);
746 }
747
748 return array_merge($add_status, $send_status);
749 }
750
751 /**
752 * Remove a number of guests from an invitation(rsvp)
753 *
754 * Permission check needs to be done outside.
755 *
756 * @ingroup rsvp_functions
757 *
758 * @param $rsvp The rsvp instance.
759 * @param $guestsarray Stringarray Contains a mix of email addresses, drupal usernames and hashes.
760 *
761 * @return array with failed emailaddresses or false
762 */
763 function _rsvp_function_remove_guests($rsvp, $guestsarray) {
764
765 $emails = array();
766
767 // remove duplicates from guestlist array
768 $guestsarray = array_unique($guestsarray);
769
770 $rid = $rsvp->rid;
771
772 foreach ($guestsarray as $key => $value) {
773
774 $list_key = NULL;
775 $invite_name = NULL;
776
777 // strip whitespace
778 $string = trim($value);
779
780 if (strlen($string)) {
781 // attempt to deal with the string as a drupal username
782 // we do this before dealing it as an e-mail to handle users like
783 // foo@somesite.com
784 $usr = user_load(array('name' => $string));
785 if ($usr === FALSE) {
786 // attempt to find a system user having this string as an e-mail address
787 $usr = user_load(array('mail' => $string));
788 if ($usr === FALSE) {
789 // no user found: carry on dealing with the string as an e-mail address
790 if (valid_email_address($string)) {
791 $invite_target = rsvp_function_exists_guest_email($rid, $string);
792 if ($invite_target) {
793 $invite_name = rsvp_function_getGuestEmail($invite_target);
794 $list_key = 'success_remove';
795 rsvp_function_remove_guest($invite_target->hash);
796 }
797 else {
798 $invite_name = $string;
799 $list_key = 'invalid';
800 }
801 }
802 else {
803 // the e-mail is invalid. Last possibility is that the string is a hash.
804 $invite_target = rsvp_function_load_invitation_hash($string);
805 if ($invite_target) {
806 $invite_name = rsvp_function_getGuestEmail($invite_target);
807 $list_key = 'success_remove';
808 rsvp_function_remove_guest($invite_target->hash);
809 }
810 else {
811 $invite_name = $string;
812 $list_key = 'invalid';
813 }
814 }
815 }
816 }
817
818 if ($usr != FALSE) {
819 // a valid drupal user was found, make sure his/her e-mail is the guest list
820 $invite_target = rsvp_function_exists_guest_uid($rid, $usr->uid);
821 if ($invite_target) {
822 $invite_name = rsvp_function_getGuestEmail($invite_target);
823 $list_key = 'success_remove';
824 rsvp_function_remove_guest($invite_target->hash);
825 }
826 else {
827 $invite_name = $string;
828 $list_key = 'invalid';
829 }
830
831 }
832
833 $emails[$list_key][] = $invite_name;
834
835 }
836 }
837
838 return $emails;
839 }
840
841 /**
842 * Remove a number of guests from an invitation(rsvp)
843 *
844 * Permission check needs to be done outside.
845 *
846 * @ingroup rsvp_functions
847 *
848 * @param $rsvp The rsvp instance.
849 * @param $guestsarray Stringarray Contains a mix of email addresses, drupal usernames and hashes.
850 *
851 * @return array with failed emailaddresses or false
852 */
853 function rsvp_function_remove_guests($rsvp, $guestsarray) {
854
855 $content = '';
856
857 $remove_status = _rsvp_function_remove_guests($rsvp, $guestsarray);
858
859 $content .= theme('rsvp_status', $remove_status);
860 drupal_set_message($content);
861 }
862
863 /**
864 * Sends the invitation to all invitees of an rsvp instance.
865 *
866 * Permission check needs to be done outside.
867 *
868 * @ingroup rsvp_functions
869 *
870 * @param $rsvp The rsvp object.
871 * @param $invite_caller The invite object of the user sending the invitation or NULL (if NULL, moderator sends invitation).
872 * @param $resend True: sends to all guests even when received flag is already set. default: false.
873 *
874 * @return array of status values.
875 */
876 function rsvp_function_send_multiple_invitations($rsvp, $invite_caller = NULL, $resend = FALSE) {
877
878 $status['success_send_invitation'] = array();
879 $status['failed_send_invitation'] = array();
880
881 $invitees = rsvp_function_load_guests($rsvp->rid);
882 while ($one_invite = db_fetch_object($invitees)) {
883 if (!($resend && $one_invite->received) && !($one_invite->invited)) {
884 if (_rsvp_function_send_one_invitation($rsvp, $one_invite, $invite_caller)) {
885 $status['success_send_invitation'][] = rsvp_function_getGuestEmail($one_invite);
886 }
887 else {
888 $status['failed_send_invitation'][] = rsvp_function_getGuestEmail($one_invite);
889 }
890 }
891 }
892 return $status;
893 }
894
895 /**
896 * Sends the invitation to one guest.
897 *
898 * Permission check needs to be done outside.
899 *
900 * @ingroup rsvp_functions
901 *
902 * @param $rsvp The rsvp object.
903 * @param $invite_target The invite object to send the invitation to.
904 * @param $invite_caller The invite object of the user sending the invitation or NULL (if NULL, moderator sends invitation).
905 *
906 * @return array of status values.
907 */
908 function rsvp_function_send_one_invitation($rsvp, $invite_target, $invite_caller = NULL) {
909
910 $status['success_send_invitation'] = array();
911 $status['failed_send_invitation'] = array();
912
913 if (_rsvp_function_send_one_invitation($rsvp, $invite_target, $invite_caller)) {
914 $status['success_send_invitation'][] = rsvp_function_getGuestEmail($invite_target);
915 }
916 else {
917 $status['failed_send_invitation'][] = rsvp_function_getGuestEmail($invite_target);
918 }
919
920 return $status;
921 }
922
923 /**
924 * Internal function
925 *
926 * Sends an invitation to one guest.
927 *
928 * Permission check needs to be done outside.
929 *
930 * @ingroup rsvp_functions
931 * @param $rsvp The rsvp object.
932 * @param $invite_target The invite object to send the invitation to.
933 * @param $invite_caller The invite object of the user sending the invitation or NULL (if NULL, moderator sends invitation).
934 * @return boolean. True if message has been successfully send.
935 */
936 function _rsvp_function_send_one_invitation($rsvp, $invite_target, $invite_caller = NULL) {
937 global $language;
938
939 if (!$invite_caller || is_null($invite_caller)) {
940 global $user;
941 $sender_name = $user->name;
942 $from = rsvp_function_email_getFromField($user->name, $user->mail);
943 }
944 else {
945 $sender_name = $invite_caller->email;
946 $from = rsvp_function_email_getFromField($sender_name, $invite_caller->email);
947 }
948
949 $u = user_load($rsvp->uid);
950 $preferred_language = user_preferred_language($u);
951
952 $to = $invite_target->email;
953
954 $replacements = rsvp_mailer_replacements($rsvp, $invite_target, $sender_name, '', $rsvp->invite_text);
955
956 $ret = drupal_mail('rsvp', 'invitation', $to, $preferred_language, $replacements, $from);
957
958 if ($ret == true) {
959 $fields[] = 'invited = %d';
960 $fields[] = 'timestamp = %d';
961
962 $vals[] = 1;
963 $vals[] = time();
964 $vals[] = $invite_target->hash;
965
966 $sql = 'UPDATE {rsvp_invite} SET '. implode(', ', $fields) .' WHERE hash = \'%s\'';
967
968 db_query($sql, $vals);
969 }
970
971 return $ret;
972 }
973
974 /**
975 * Send a message to selective guests of an invitation.
976 *
977 * Permission check needs to be done outside.
978 *
979 * @ingroup rsvp_functions
980 *
981 * @param $rsvp The rsvp object.
982 * @param $audience Const The audience for the message (RSVP_ATT_ALL,...).
983 * @param $rsvp_mailer_op String One of the mailer operations in rsvp.mailer.inc.
984 * @param $subject String The body you want to send.
985 * @param $body String The subject you want to send.
986 * @param $invite_caller The invitee instance of the person triggering the message or NULL if moderator.
987 *
988 * @return string of formatted recipients, or empty string depending on $confirm.
989 */
990 function rsvp_function_send_message_guests($rsvp, $audience, $rsvp_mailer_op, $subject, $body, $invite_caller = NULL) {
991
992 // check whether the message is sent from a user who's invited
993 // yet allowed to message other attendees
994 if (!$invite_caller || is_null($invite_caller)) {
995 global $user;
996 $sender_name = $user->name;
997 $from = rsvp_function_email_getFromField($user->name, $user->mail);
998 }
999 else {
1000 $sender_name = $invite_caller->email;
1001 $from = rsvp_function_email_getFromField($sender_name, $invite_caller->email);
1002 }
1003
1004 $status['success_send_message'] = array();
1005 $status['failed_send_message'] = array();
1006
1007 $attendees = rsvp_function_load_guests($rsvp->rid);
1008 while ($attendee = db_fetch_object($attendees)) {
1009 $invite = rsvp_function_load_invitation_hash($attendee->hash);
1010
1011 if ($audience == RSVP_ATT_ALL || $invite->response == $audience) {
1012 $inviteuser = user_load($invite->uid);
1013 $to = $attendee->email;
1014
1015 $preferred_language = user_preferred_language($inviteuser);
1016
1017 $replacements = rsvp_mailer_replacements($rsvp, $attendee, $sender_name, $subject, $body);
1018
1019 if (drupal_mail('rsvp', $rsvp_mailer_op, $to, $preferred_language, $replacements, $from)) {
1020 $status['success_send_message'][$invite->email] = rsvp_function_getGuestEmail($invite);
1021 }
1022 else {
1023 $status['failed_send_message'][$invite->email] = rsvp_function_getGuestEmail($invite);
1024 }
1025 }
1026 }
1027
1028 return $status;
1029 }
1030
1031 /**
1032 * Send a message to a particular guest of an invitation.
1033 *
1034 * Permission check needs to be done outside.
1035 *
1036 * @ingroup rsvp_functions
1037 *
1038 * @param $rsvp The rsvp object.
1039 * @param $hash The hashcode of the person we want to send the message to.
1040 * @param $rsvp_mailer_op String One of the mailer operations in rsvp.mailer.inc.
1041 * @param $body String The body you want to send.
1042 * @param $subject String The subject you want to send.
1043 * @param $invite_caller The invitee instance of the person triggering the message or NULL if moderator.
1044 *
1045 * @return string of formatted recipients, or empty string depending on $confirm.
1046 */
1047 function rsvp_function_send_message_guest($rsvp, $hash, $rsvp_mailer_op, $subject, $body, $invite_caller = NULL) {
1048
1049 //get rid of subject
1050
1051 // check whether the message is sent from a user who's invited
1052 // yet allowed to message other attendees
1053 if (!$invite_caller || is_null($invite_caller)) {
1054 global $user;
1055 $sender_name = $user->name;
1056 $from = rsvp_function_email_getFromField($sender_name, $user->mail);
1057 }
1058 else {
1059 $sender_name = $invite_caller->email;
1060 $from = rsvp_function_email_getFromField($sender_name, $invite_caller->email);
1061 }
1062
1063 $status['success_send_message'] = array();
1064 $status['failed_send_message'] = array();
1065
1066 $invite = rsvp_function_load_invitation_hash($hash);
1067
1068 $inviteuser = user_load($invite->uid);
1069 $to = $invite->email;
1070
1071 $preferred_language = user_preferred_language($inviteuser);
1072
1073 $replacements = rsvp_mailer_replacements($rsvp, $invite, $sender_name, $subject, $body);
1074
1075 if (drupal_mail('rsvp', $rsvp_mailer_op, $to, $preferred_language, $replacements, $from)) {
1076 $status['success_send_message'][$invite->email] = rsvp_function_getGuestEmail($invite);
1077 }
1078 else {
1079 $status['failed_send_message'][$invite->email] = rsvp_function_getGuestEmail($invite);
1080 }
1081
1082 return $status;
1083 }
1084
1085 /**
1086 * Send a message to the owner/co-owner of an invitation.
1087 *
1088 * Permission check needs to be done outside.
1089 *
1090 * @ingroup rsvp_functions
1091 *
1092 * @param $rsvp The rsvp object.
1093 * @param $rsvp_mailer_op String One of the mailer operations in rsvp.mailer.inc.
1094 * @param $subject String The subject you want to send.
1095 * @param $body String The body you want to send.
1096 * @param $invite_target The invitee instance of the person triggering the message or NULL if no trigger.
1097 * *
1098 * @return string of formatted recipients, or empty string depending on $confirm.
1099 */
1100 function rsvp_function_send_message_moderator($rsvp, $rsvp_mailer_op, $subject, $body, $invite_target = NULL) {
1101
1102 $owner_user = user_load($rsvp->uid);
1103 if ($rsvp->uid_moderator > 0)
1104 $moderator_user = user_load($rsvp->uid_moderator);
1105 else
1106 $moderator_user = false;
1107
1108 global $user;
1109 $sender_name = $user->name;
1110 $from = rsvp_function_email_getFromField($sender_name, $user->mail);
1111
1112 $status['success_send_message'] = array();
1113 $status['failed_send_message'] = array();
1114
1115
1116 //send to owner
1117 $to = $owner_user->mail;
1118 $preferred_language = user_preferred_language($owner_user);
1119
1120 $replacements = rsvp_mailer_replacements($rsvp, $invite_target, $sender_name, $subject, $body);
1121
1122 if (drupal_mail('rsvp', $rsvp_mailer_op, $to, $preferred_language, $replacements, $from)) {
1123 $status['success_send_message'][$to] = rsvp_function_getGuestEmail($invite_target);
1124 }
1125 else {
1126 $status['failed_send_message'][$to] = rsvp_function_getGuestEmail($invite_target);
1127 }
1128
1129 //send to co-moderator
1130 if ($moderator_user == true) {
1131 $to = $moderator_user->mail;
1132 $preferred_language = user_preferred_language($moderator_user);
1133
1134 if (drupal_mail('rsvp', $rsvp_mailer_op, $to, $preferred_language, $replacements, $from)) {
1135 $status['success_send_message'][$to] = rsvp_function_getGuestEmail($invite_target);
1136 }
1137 else {
1138 $status['failed_send_message'][$to] = rsvp_function_getGuestEmail($invite_target);
1139 }
1140 }
1141
1142 return $status;
1143 }
1144
1145 /**
1146 * Returns the invitations that a user is the owner or co_maintainer of.
1147 *
1148 * Permission check needs to be done outside.
1149 *
1150 * @ingroup rsvp_functions
1151 * @param $nid The nid of the node.Can be one, array of nodes or NULL which means all nodes of the user.
1152 * @param $uid The uid of the user.Can be a user, array of users or NULL which means rsvp for all users.
1153 * @return dbresultset of invitations.
1154 */
1155 function rsvp_function_load_invitations_owner($nid = NULL, $uid = NULL, $tablesort = ' ORDER BY nid') {
1156
1157 $query = 'SELECT r.*, n.title FROM {rsvp} r INNER JOIN {node} n ON r.nid = n.nid '; //r.uid = %d';
1158
1159 if (!is_null($uid) || !is_null($nid)) {
1160 $query .= 'WHERE ';
1161 }
1162
1163 //$query = 'SELECT r.*, n.title FROM {rsvp} r INNER JOIN {node} n ON r.nid = n.nid WHERE r.uid = %d';
1164 if (!is_null($nid)) {
1165 if (is_array($nid)) {
1166 $query .= 'r.nid IN (%s) ';
1167 $nid = implode(', ', $nid);
1168 }
1169 elseif (is_numeric($nid)) {
1170 $query .= 'r.nid = %d ';
1171 }
1172 }
1173
1174 if (!is_null($uid)) {
1175 if (!is_null($nid)) {
1176 $query .= 'AND ';
1177 }
1178
1179 //load if uid is owner or co_moderator.
1180 if (is_array($uid)) {
1181 $query .= '( r.uid IN (%s) ';
1182 $query .= ' OR r.uid_moderator IN (%s) )';
1183 $uid = implode(', ', $uid);
1184 }
1185 elseif (is_numeric($uid)) {
1186 $query .= '( r.uid = %d ';
1187 $query .= ' OR r.uid_moderator = %d )';
1188 }
1189 }
1190
1191 $query .= $tablesort;
1192
1193 if (is_null($nid)) {
1194 return db_query($query, $uid, $uid);
1195 }
1196 else {
1197 return db_query($query, $nid, $uid, $uid);
1198 }
1199
1200 }
1201
1202 /**
1203 * Returns the invitations that a user has received.
1204 * If nid is NULL, return all invitation for the user. Otherwise only invitation of that particluar node
1205 *
1206 * Permission check needs to be done outside.
1207 *
1208 * @ingroup rsvp_functions
1209 * @param $uid The uid of the user.
1210 * @param $nid The nodeid we want to query for. If Null, select for nodes
1211 * @param $count returns only the total number of invitations for a particular uid/nid.
1212 * @return array of events or integer if count=true.
1213 */
1214 function rsvp_function_load_invitations_user($uid = NULL, $nid = NULL, $count = false) {
1215
1216 $uid = _rsvp_function_check_uid($uid);
1217 if (is_null($uid)) {
1218 if ($count)
1219 return 0;
1220 else
1221 return array();
1222 }
1223
1224 $query = 'SELECT '. ($count ? 'COUNT(*)' : 'u.*,r.nid,n.realname') .' FROM {rsvp} r LEFT JOIN {rsvp_invite} u ON r.rid = u.rid LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE u.uid = %d';
1225 if (!is_null($nid)) {
1226 $query .= ' AND r.nid = %d';
1227 }
1228
1229 return db_query($query, $uid, $nid);
1230 }
1231
1232 /**
1233 * Returns the invitations that a registered user has received for a specific event node.
1234 *
1235 * Permission check needs to be done outside.
1236 *
1237 * @ingroup rsvp_functions
1238 * @param $nid The nid of the node.
1239 * @param $uid The uid of the user. If null, return all from all users.
1240 * uid can not be 0, because it would return all invitations from unregistered attendees.
1241 * @return array of event nids.
1242 */
1243 function rsvp_function_load_invitations_node2($nid, $uid = NULL, $count = false) {
1244
1245
1246 $query = 'SELECT '. ($count ? 'COUNT(*)' : 'u.*,n.realname') .' FROM {rsvp} r LEFT JOIN {rsvp_invite} u ON r.rid = u.rid LEFT JOIN {rsvp_realname} n ON u.email = n.email WHERE r.nid = %d';
1247 if (!is_null($uid)) {
1248 if ($uid != 0)
1249 $query .= ' AND u.uid = %d';
1250 else
1251 return array();
1252 }
1253
1254 return db_query($query, $nid, $uid);
1255 }
1256
1257
1258 /**
1259 * Checks to see if a logged in user has been invited to an event.
1260 *
1261 * Permission check needs to be done outside.
1262 *
1263 * @ingroup rsvp_functions
1264 * @param $nid The node id of the event.
1265 * @param $uid The uid of the user. If null, it uses global $user->uid.
1266 * @return boolean. True if user has been invited to the event.
1267 */
1268 function rsvp_function_is_invited($nid, $uid = NULL) {
1269
1270 $uid = _rsvp_function_check_uid($uid);
1271 if (is_null($uid)) {
1272 return false;
1273 }
1274
1275 if (db_result(db_query('SELECT COUNT(*) FROM {rsvp} r LEFT JOIN {rsvp_invite} u ON r.rid = u.rid WHERE r.nid = %d AND u.uid = %d', $nid, $uid)) > 0) {
1276 return TRUE;
1277 }
1278 return FALSE;
1279 }
1280
1281 /**
1282 * Checks to see if responses are visible to other attendees.
1283 *
1284 * Permission check needs to be done outside.
1285 *
1286 * @ingroup rsvp_functions
1287 * @param $rid The rid of the rsvp.
1288 * @return Int. 0:Show responses, 1:Hide responses, 2:Hide responses until replied
1289 *
1290 */
1291
1292 function rsvp_function_is_response_blind($rid) {
1293 $status = db_fetch_object(db_query('SELECT response_blind FROM {rsvp} WHERE rid = %d', $rid));
1294
1295 return $status->response_blind;
1296 }
1297
1298 /**
1299 * Checks to see if a user is the owner of an rsvp.
1300 *
1301 * Permission check needs to be done outside.
1302 *
1303 * @ingroup rsvp_functions
1304 * @param $rid The id of the rsvp.
1305 * @param $uid The uid of the user. If null, it uses global $user->uid.
1306 * @return boolean. True if user is the owner of an rsvp to the event.
1307 */
1308 function rsvp_function_is_owner($rid, $uid = NULL) {
1309
1310 $uid = _rsvp_function_check_uid($uid);
1311 if (is_null($uid)) {
1312 return false;
1313 }
1314
1315 if (db_result(db_query('SELECT COUNT(*) FROM {rsvp} WHERE rid = %d AND uid = %d', $rid, $uid)) > 0) {
1316 return TRUE;
1317 }
1318 return FALSE;
1319 }
1320