| 1 |
<?php
|
| 2 |
// $Id: rsvp.api.inc,v 1.1 2009/01/17 20:29:02 ulf1 Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @module rsvp_api
|
| 6 |
* @package rsvp - A drupal module developed for civicspace - a distribution of drupal.
|
| 7 |
* @description Provides rsvp api functionality that can be called by other modules
|
| 8 |
* @author Ulf Schenk (ulf@schenkunlimited.net)
|
| 9 |
*
|
| 10 |
*/
|
| 11 |
|
| 12 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
| 13 |
|
| 14 |
// Pre Loading files that will be required in this module
|
| 15 |
foreach (array('functions') as $file) {
|
| 16 |
module_load_include("inc", "rsvp", "rsvp.{$file}");
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Creates an invitation with the default settings.
|
| 21 |
* The function requires the correct user permissions.
|
| 22 |
*
|
| 23 |
* @ingroup rsvp_api
|
| 24 |
*
|
| 25 |
* @param $nid The Id of the node you want to create an invitation for.
|
| 26 |
* @param $invite text String The invitation message you want to use.
|
| 27 |
* @param $startdate unixdate The startdate you want to write your invitation for (only required if the event has multiple startdates)
|
| 28 |
*
|
| 29 |
* @return rid (id of the rsvp) or false.
|
| 30 |
*/
|
| 31 |
function rsvp_api_create_invitation($nid, $invite_text, $startdate) {
|
| 32 |
|
| 33 |
$node = node_load($nid);
|
| 34 |
if ($node == false)
|
| 35 |
return false;
|
| 36 |
|
| 37 |
$connector = new RsvpConnector();
|
| 38 |
|
| 39 |
|
| 40 |
if ($connector->is_event_enabled($node->type)) {
|
| 41 |
|
| 42 |
$perm_create = _rsvp_rsvp_by_node_access($connector, $node, RSVP_ACCESS_CREATE);
|
| 43 |
if ($perm_create == true) {
|
| 44 |
$do_create = true;
|
| 45 |
$rsvp = rsvp_function_initialize_default_rsvp();
|
| 46 |
$rsvp->nid = $nid;
|
| 47 |
$rsvp->name = $node->title;
|
| 48 |
$rsvp->invite_text = $invite_text;
|
| 49 |
|
| 50 |
//set $rsvp->startdate
|
| 51 |
if ($connector->hasMultipleDatesPerField()) {
|
| 52 |
$field = _rsvp_getField($node->type);
|
| 53 |
$count = $connector->get_datecount($node, $field);
|
| 54 |
if ($count = 1) {
|
| 55 |
//if count = 1 ignore parameter startdate completely because there is only one startdate
|
| 56 |
$rsvp->startdate = $connector->get_startdate($node, $field, 0);
|
| 57 |
}
|
| 58 |
else {
|
| 59 |
$do_create = false;
|
| 60 |
//iterate through all specified startdates (in case of repeating dates)
|
| 61 |
for ($i = 0; $i < $count; $i++) {
|
| 62 |
$key = $connector->get_startdate($node, $field, $i);
|
| 63 |
|
| 64 |
if ($key == $startdate) {
|
| 65 |
$rsvp->startdate = $key;
|
| 66 |
$do_create = true;
|
| 67 |
break;
|
| 68 |
}
|
| 69 |
}
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
if (do_create == true) {
|
| 74 |
$rid = rsvp_function_create_rsvp($rsvp);
|
| 75 |
if ($rid != false) {
|
| 76 |
drupal_set_message(t('New invitation %rsvp_name(%rid) has been created successfully.'), array('%rsvp_name' => $rsvp->name, '%rid' => $rid));
|
| 77 |
watchdog('action', 'Successfully created invitation %rsvp_name(%rid) for node %nid.', array('%rsvp_name' => $rsvp->name, '%rid' => $rid, '%nid' => $nid));
|
| 78 |
return $rid;
|
| 79 |
}
|
| 80 |
}
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
| 84 |
return false;
|
| 85 |
}
|
| 86 |
|
| 87 |
|
| 88 |
/**
|
| 89 |
* Removes invitation(s).
|
| 90 |
* The function requires the correct user permissions.
|
| 91 |
*
|
| 92 |
* @ingroup rsvp_api
|
| 93 |
*
|
| 94 |
* @param $rid The Id of the rsvp you want to remove or NULL.
|
| 95 |
* @param $nid The Id of the node you want to remove all invitations for or NULL.
|
| 96 |
*
|
| 97 |
* @return true or false.
|
| 98 |
*/
|
| 99 |
function rsvp_api_remove_invitation($rid, $nid) {
|
| 100 |
|
| 101 |
if(!isnull($rid)) {
|
| 102 |
$rsvp = rsvp_load($rid);
|
| 103 |
if ($rsvp == false)
|
| 104 |
return false;
|
| 105 |
|
| 106 |
$perm_del = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_DELETE);
|
| 107 |
if ($perm_del == true) {
|
| 108 |
$success = $rsvp_function_delete_rsvp($rid);
|
| 109 |
if ($success == true) {
|
| 110 |
drupal_set_message(t('Invitation %rsvp_name(%rid) has been removed successfully.'), array('%rsvp_name' => $rsvp->name, '%rid' => $rsvp->rid));
|
| 111 |
watchdog('action', 'Removed invitation %rsvp_name(%rid) successfully.', array('%rsvp_name' => $rsvp->name, '%rid' => $rsvp->rid));
|
| 112 |
return true;
|
| 113 |
}
|
| 114 |
}
|
| 115 |
}
|
| 116 |
elseif(!isnull($nid)) {
|
| 117 |
$node = node_load($nid);
|
| 118 |
if ($node == false)
|
| 119 |
return false;
|
| 120 |
|
| 121 |
$connector = new RsvpConnector();
|
| 122 |
|
| 123 |
if ($connector->is_event_enabled($node->type)) {
|
| 124 |
|
| 125 |
//find the invitation for a specific node
|
| 126 |
$list = _rsvp_get_node_invites($node->nid);
|
| 127 |
|
| 128 |
while ($rsvp = db_fetch_object($list)) {
|
| 129 |
|
| 130 |
$perm_del = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_DELETE);
|
| 131 |
if ($perm_del == true) {
|
| 132 |
$success = $rsvp_function_delete_rsvp($rsvp->rid);
|
| 133 |
if ($success == true) {
|
| 134 |
drupal_set_message(t('Invitation %rsvp_name(%rid) has been removed successfully.'), array('%rsvp_name' => $rsvp->name, '%rid' => $rsvp->rid));
|
| 135 |
watchdog('action', 'Removed invitation %rsvp_name(%rid) successfully.', array('%rsvp_name' => $rsvp->name, '%rid' => $rsvp->rid));
|
| 136 |
}
|
| 137 |
}
|
| 138 |
}
|
| 139 |
}
|
| 140 |
return true;
|
| 141 |
}
|
| 142 |
}
|
| 143 |
|
| 144 |
/**
|
| 145 |
* Adds a number of guests to an invitation(rsvp) and sends out the invitations
|
| 146 |
*
|
| 147 |
* The function requires the correct user permissions.
|
| 148 |
*
|
| 149 |
* @ingroup rsvp_api
|
| 150 |
*
|
| 151 |
* @param $rid The Id of the rsvp instance.
|
| 152 |
* @param $hash The hash of the invitation object of the user who adds the invitees,
|
| 153 |
* or NULL if the rsvp owner adds the invitees.
|
| 154 |
* @param $guestsarray Stringarray Contains a mix of email addresses and drupal usernames.
|
| 155 |
* @param $send_rsvp Boolean Also send the invitations or just add the guests to the invitation.
|
| 156 |
*/
|
| 157 |
function rsvp_api_add_guests($rid, $hash, $guestsarray, $send_rsvp) {
|
| 158 |
|
| 159 |
$invite = NULL;
|
| 160 |
|
| 161 |
if(!isnull($rid)) {
|
| 162 |
$rsvp = rsvp_function_load_rsvp($rid);
|
| 163 |
if ($rsvp == false)
|
| 164 |
return false;
|
| 165 |
}
|
| 166 |
|
| 167 |
if(!isnull($hash)) {
|
| 168 |
$invite = rsvp_function_load_invitation_hash($hash);
|
| 169 |
if ($invite == false)
|
| 170 |
return false;
|
| 171 |
}
|
| 172 |
|
| 173 |
$connector = new RsvpConnector();
|
| 174 |
$perm_add = rsvp_add_guests_access($connector, $rsvp, $invite);
|
| 175 |
if ($perm_add == true) {
|
| 176 |
rsvp_function_add_invitees($rsvp, $invite, $guestsarray, $send_rsvp, $is_moderator);
|
| 177 |
watchdog('action', 'Added invitees to invitation %rsvp_name(%rid) successfully.', array('%rsvp_name' => $rsvp->name, '%rid' => $rsvp->rid));
|
| 178 |
}
|
| 179 |
}
|
| 180 |
|
| 181 |
|
| 182 |
/**
|
| 183 |
* Remove a number of guests from an invitation(rsvp).
|
| 184 |
*
|
| 185 |
* The function requires the correct user permissions.
|
| 186 |
*
|
| 187 |
* @ingroup rsvp_api
|
| 188 |
*
|
| 189 |
* @param $rid The Id of the rsvp instance.
|
| 190 |
* @param $hash_caller The hash of the invitation object of the user who adds the invitees,
|
| 191 |
* or NULL if the moderator adds the invitees.
|
| 192 |
* @param $guestsarray Stringarray Contains a mix of email addresses, drupal usernames and hashes.
|
| 193 |
*/
|
| 194 |
function rsvp_api_remove_guests($rid, $hash_caller, $guestsarray) {
|
| 195 |
|
| 196 |
if(!isnull($rid)) {
|
| 197 |
$rsvp = rsvp_function_load_rsvp($rid);
|
| 198 |
if ($rsvp == false)
|
| 199 |
return false;
|
| 200 |
}
|
| 201 |
|
| 202 |
$connector = new RsvpConnector();
|
| 203 |
$perm_remove = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_DELETE);
|
| 204 |
if ($perm_remove == true) {
|
| 205 |
rsvp_function_remove_guests($rsvp, $guestsarray);
|
| 206 |
watchdog('action', 'Removed invitees from invitation %rsvp_name(%rid) successfully.', array('%rsvp_name' => $rsvp->name, '%rid' => $rsvp->rid));
|
| 207 |
}
|
| 208 |
}
|
| 209 |
|
| 210 |
|
| 211 |
/**
|
| 212 |
* Sends the invitation to all invitees of an rsvp instance.
|
| 213 |
*
|
| 214 |
* The function requires the correct user permissions.
|
| 215 |
*
|
| 216 |
* @ingroup rsvp_api
|
| 217 |
*
|
| 218 |
* @param $rid The Id of the rsvp instance.
|
| 219 |
* @param $hash_caller The hash of the invitation object of the user sending the invitation or NULL (if NULL, moderator sends invitation).
|
| 220 |
* @param $resend If true, sends to all guests even when received flag is already set. default: false.
|
| 221 |
*
|
| 222 |
*/
|
| 223 |
function rsvp_api_send_invitations($rid, $hash_caller = NULL, $resend = FALSE) {
|
| 224 |
|
| 225 |
$invite_caller = NULL;
|
| 226 |
|
| 227 |
if(!isnull($rid)) {
|
| 228 |
$rsvp = rsvp_function_load_rsvp($rid);
|
| 229 |
if ($rsvp == false)
|
| 230 |
return false;
|
| 231 |
}
|
| 232 |
|
| 233 |
if(!isnull($hash_caller)) {
|
| 234 |
$invite_caller = rsvp_function_load_invitation_hash($hash_caller);
|
| 235 |
if ($invite_caller == false)
|
| 236 |
return false;
|
| 237 |
}
|
| 238 |
|
| 239 |
$connector = new RsvpConnector();
|
| 240 |
|
| 241 |
$perm_edit = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_EDIT);
|
| 242 |
if ($perm_edit == false)
|
| 243 |
return false;
|
| 244 |
|
| 245 |
rsvp_function_send_multiple_invitations($rsvp, $invite_caller, $resend);
|
| 246 |
}
|
| 247 |
|
| 248 |
/**
|
| 249 |
* Send a message to selective guests of an invitation.
|
| 250 |
*
|
| 251 |
* The function requires the correct user permissions.
|
| 252 |
*
|
| 253 |
* @ingroup rsvp_functions
|
| 254 |
*
|
| 255 |
* @param $rid The Id of the rsvp instance.
|
| 256 |
* @param $audience Const The audience for the message (RSVP_ATT_ALL,...).
|
| 257 |
* @param $rsvp_mailer_op String One of the mailer operations in rsvp.mailer.inc.
|
| 258 |
* @param $subject String The subject you want to send.
|
| 259 |
* @param $body String The body you want to send.
|
| 260 |
* @param $hash_caller The invitee hashcode of the person triggering the message or NULL if moderator.
|
| 261 |
*
|
| 262 |
* @return string of formatted recipients, or empty string depending on $confirm.
|
| 263 |
*/
|
| 264 |
function rsvp_api_send_message($rid, $audience, $rsvp_mailer_op, $subject, $body, $hash_caller = NULL) {
|
| 265 |
|
| 266 |
$invite_caller = NULL;
|
| 267 |
|
| 268 |
if(!isnull($rid)) {
|
| 269 |
$rsvp = rsvp_function_load_rsvp($rid);
|
| 270 |
if ($rsvp == false)
|
| 271 |
return false;
|
| 272 |
}
|
| 273 |
|
| 274 |
if(!isnull($hash_caller)) {
|
| 275 |
$invite_caller = rsvp_function_load_invitation_hash($hash_caller);
|
| 276 |
if ($invite_caller == false)
|
| 277 |
return false;
|
| 278 |
}
|
| 279 |
|
| 280 |
$connector = new RsvpConnector();
|
| 281 |
$perm_edit = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_EDIT);
|
| 282 |
if ($perm_edit == false)
|
| 283 |
return false;
|
| 284 |
|
| 285 |
rsvp_function_send_message_guests($rsvp, $audience, $rsvp_mailer_op, $subject, $body, $invite_caller);
|
| 286 |
|
| 287 |
}
|