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

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

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


Revision 1.2 - (show annotations) (download) (as text)
Thu Feb 5 02:25:27 2009 UTC (9 months, 3 weeks ago) by ulf1
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.1: +112 -29 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 // $Id: rsvp.blocks.inc,v 1.1 2009/01/17 20:29:02 ulf1 Exp $
3
4 /**
5 * @module rsvp_blocks
6 * @package rsvp - A drupal module developed for civicspace - a distribution of drupal.
7 * @description Provides block functionality
8 * @author Ulf Schenk (ulf@schenkunlimited.net)
9 *
10 */
11
12 // Pre Loading files that will be required in this module
13 foreach (array('functions') as $file) {
14 module_load_include("inc", "rsvp", "rsvp.{$file}");
15 }
16
17
18 /**
19 * Generate HTML for the rsvp blocks
20 * @param op the operation from the URL
21 * @param delta offset
22 * @returns block HTML
23 */
24 function rsvp_block($op = 'list', $delta = 0, $edit = array()) {
25
26 // listing of blocks, such as on the admin/block page
27 if ($op == "list") {
28 $block[0]["info"] = t('RSVP Host toolbox');
29 $block[0]['cache'] = BLOCK_NO_CACHE;
30
31 $block[1]["info"] = t('RSVP Guest toolbox');
32 $block[1]['cache'] = BLOCK_NO_CACHE;
33 $block[2]["info"] = t('RSVP Guest list');
34 $block[2]['cache'] = BLOCK_NO_CACHE;
35 return $block;
36 } else if ($op == 'view') {
37 switch ($delta) {
38 case 0:
39 return rsvp_block_toolbox_host();
40 case 1:
41 return rsvp_block_toolbox_guest();
42 case 2:
43 return rsvp_block_guestlist(variable_get('rsvp_block_d_'. $delta, 0));
44 }
45 } else if ($op == 'configure') {
46 if ($delta == 2) {
47 $form['rsvp_block_d_'. $delta] = array(
48 '#type' => 'radios',
49 '#title' => t('Display'),
50 '#options' => array('1' => t('Overview and Guest list'), '0' => t('Overview only')),
51 '#description' => t("Do you want to display the short form or the lon form of teh guest list?"),
52 '#default_value' => variable_get('rsvp_block_d_'. $delta, 0),
53 );
54
55 }
56 return $form;
57 } else if ($op == 'save') {
58 if ($delta == 2) {
59 variable_set('rsvp_block_d_'. $delta, $edit['rsvp_block_d_'. $delta]);
60 }
61 }
62 }
63
64 function rsvp_block_toolbox_host() {
65
66 $block = array();
67 $is_rsvp = false;
68 $rid = NULL;
69
70 if ( arg(0) =='rsvp') {
71 if ( arg(1) =='email') {
72 $invite_hash = arg(2);
73 $invite_target = rsvp_function_load_invitation_hash($invite_hash);
74 if ($invite_target == true) {
75 $rid = $invite_target->rid;
76 $is_rsvp = true;
77 }
78 }
79 else{
80 $rid = arg(1);
81 $is_rsvp = is_numeric($rid);
82 }
83 }
84
85 if ( $is_rsvp && $rid ) {
86 $connector = new RsvpConnector();
87
88 $rsvp=rsvp_function_load_rsvp($rid);
89 if ($rsvp == false)
90 return $block;
91
92 $perm_edit = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_EDIT, NULL);
93 $perm_export = rsvp_csv_hash_form_access($connector, $rsvp, NULL);
94
95
96 if ($perm_edit == true) {
97 $links[] = l(t('Send a message to guests'), 'rsvp/'. $rsvp->rid .'/message', array('attributes' => array('title' => t('Send message to guests that you invited.'))));
98
99 $links[] = l(t('Remove guests'), 'rsvp/'. $rsvp->rid .'/attendees', array('attributes' => array('title' => t('Remove guests from the invitation.'))));
100 $links[] = l(t('Add guests'), 'rsvp/'. $rsvp->rid .'/attendees', array('attributes' => array('title' => t('Add more guests to the invitation.'))));
101 if ($rsvp->send_conf_owner != RSVP_OPTION_YES)
102 $links[] = l(t('Email me when guests reply'), 'rsvp/'. $rsvp->rid .'/msg_moderator', array('attributes' => array('title' => t('Enable notification messages for the event organizer(host).'))));
103 }
104 if ($perm_export == true)
105 $links[] = l(t('Export guest list'), 'rsvp/'. $rsvp->rid .'/attendees/csv', array('attributes' => array('title' => t('Export guest list into csv format.'))));
106
107 if ($perm_edit == true) {
108 $links[] = l(t('Edit guests replies'), 'rsvp/'. $rsvp->rid .'/attendees', array('attributes' => array('title' => t('Modify guest responses.'))));
109 //$links[] = t('Cancel invitation');
110 $links[] = l(t('Change organizer'), 'rsvp/'. $rsvp->rid .'/owner', array('attributes' => array('title' => t('Modify the event organizer(host).'))));
111 $links[] = l(t('Change options'), 'rsvp/'. $rsvp->rid .'/edit', array('attributes' => array('title' => t('Modify the options of the current invitation.'))));
112 }
113
114 if (count($links) > 0) {
115 $block['content'] = theme('item_list', $links);
116 $block['subject'] = t('Host toolbox');
117 }
118 }
119
120 return $block;
121 }
122
123 function rsvp_block_toolbox_guest() {
124
125 $block = array();
126
127 $invite_hash = arg(2);
128 $is_invite_hash = (arg(0)=='rsvp') && (arg(1)=='email') && isset($invite_hash);
129
130 if ( $is_invite_hash && $invite_hash ) {
131 $connector = new RsvpConnector();
132
133 $invite_target = rsvp_function_load_invitation_hash($invite_hash);
134 if ($invite_target == false)
135 return $block;
136
137 $rsvp=rsvp_function_load_rsvp($invite_target->rid);
138 if ($rsvp == false)
139 return $block;
140
141
142 list($perm_reply, $perm_guest) = rsvp_function_invitation_by_invite_accessarray($connector, $rsvp, $invite_target, NULL, array(RSVP_ACCESS_REPLY, RSVP_ACCESS_GUEST), NULL);
143 $perm_export = rsvp_csv_hash_form_access($connector, $rsvp, $invite_target);
144 $perm_sendmessage = rsvp_hash_sendmessage_access($connector, $invite_target);
145 $perm_addguests = rsvp_attendee_form_access($connector, $rsvp, $invite_target);
146
147 if ($perm_sendmessage == true)
148 $links[] = l(t('Send a message to guests'), 'rsvp/email/'. $invite_target->hash .'/message', array('attributes' => array('title' => t('Send message to guests that you invited.'))));
149
150 if ($perm_addguests == true) {
151 $links[] = l(t('Add guests'), 'rsvp/email/'. $invite_target->hash .'/attendees', array('attributes' => array('title' => t('Add more guests to the invitation.'))));
152 }
153
154 if ($perm_export == true)
155 $links[] = l(t('Export guest list'), 'rsvp/email/'. $invite_target->hash .'/csv', array('attributes' => array('title' => t('Export guest list into csv format.'))));
156
157 if ($perm_guest == true)
158 $links[] = l(t('Change your display name'), 'rsvp/email/'. $invite_target->hash .'/realname', array('attributes' => array('title' => t('Change your name that is being displayed in the guest list.'))));
159
160 if (count($links) > 0) {
161 $block['content'] = theme('item_list', $links);
162 $block['subject'] = t('Your invitation');
163 }
164
165 }
166 return $block;
167 }
168
169
170 function rsvp_block_guestlist($extended_display = false) {
171 $block = array();
172
173 $is_invite_hash = false;
174 $is_rsvp = false;
175 $is_node = false;
176 $uid = NULL;
177 $rid = NULL;
178 $nid = NULL;
179 $content = '';
180
181
182 if(arg(0)=='rsvp') {
183
184 if (arg(1)=='email') {
185 $invite_hash = arg(2);
186 $is_invite_hash = isset($invite_hash);
187 }
188 else {
189 $rid = arg(1);
190 $is_rsvp = is_numeric($rid);
191
192 if (!user_is_anonymous()) {
193 global $user;
194 $uid = $user->uid;
195 }
196 }
197 }
198 elseif(arg(0)=='node') {
199 $nid = arg(1);
200 $is_node = is_numeric($nid);
201 }
202 else {
203 return $block;
204 }
205
206
207 if ( $is_invite_hash ) {
208 $invite_target = rsvp_function_load_invitation_hash($invite_hash);
209 if ($invite_target == false)
210 return $block;
211
212 $rsvp=rsvp_function_load_rsvp($invite_target->rid);
213 if ($rsvp == false)
214 return $block;
215
216 $perm_view = rsvp_function_invitation_by_invite_access($connector, $rsvp, $invite_target, $uid, RSVP_ACCESS_VIEW, NULL);
217 if ($perm_view == true) {
218 $content = rsvp_show_guestlist($rsvp, $invite_target, true, $extended_display);
219
220 $block['content'] = $content;
221 $block['subject'] = t('Guest list');
222 }
223 }
224 elseif ( $is_rsvp ) {
225
226 $rsvp=rsvp_function_load_rsvp($rid);
227 if ($rsvp == false)
228 return $block;
229
230 $perm_view = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, $uid, RSVP_ACCESS_VIEW, NULL);
231 if ($perm_view == true) {
232 $content = rsvp_show_guestlist($rsvp, NULL, true, $extended_display);
233
234 $block['content'] = $content;
235 $block['subject'] = t('Guest list');
236 }
237 }
238 elseif ( $is_node ) {
239 $display = false;
240 //In a first step collect all invitations for the node that a user has view permissions to.
241 $rsvps = rsvp_function_load_invitations_owner($nid, NULL, NULL);
242 while ($rsvp = db_fetch_object($rsvps)) {
243 $perm_view = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_VIEW, NULL);
244
245 if ($perm_view == true) {
246 $content .= rsvp_show_guestlist($rsvp, NULL, true, $extended_display);
247 $display = true;
248 }
249 }
250
251 if ($display == true) {
252 $block['content'] = $content;
253 $block['subject'] = t('Guest list');
254 }
255
256 }
257
258
259
260 return $block;
261 }
262
263

  ViewVC Help
Powered by ViewVC 1.1.2