Parent Directory
|
Revision Log
|
Revision Graph
*** empty log message ***
| 1 | <?php |
| 2 | // $Id: eventfinder.module |
| 3 | include(drupal_get_path('module', 'eventfinder') .'/eventfinder_themes.inc'); |
| 4 | |
| 5 | /** |
| 6 | * @defgroup ef_ss EventFinder saved search methods |
| 7 | */ |
| 8 | /** |
| 9 | * removes old events from the saved search table |
| 10 | * @ingroup ef_ss |
| 11 | */ |
| 12 | function eventfinder_ss_remove_old_events(){ |
| 13 | $sql = "DELETE FROM {ef_ss_node} WHERE begin < %d"; |
| 14 | db_query(db_prefix_tables($sql), time()); |
| 15 | return TRUE; |
| 16 | } |
| 17 | /** |
| 18 | * checks for new events in the system |
| 19 | * @ingroup ef_ss |
| 20 | * @return date of most recently created event |
| 21 | */ |
| 22 | function eventfinder_check_new_events(){ |
| 23 | $sql = "SELECT MAX(created) latest FROM {node} n " |
| 24 | . "INNER JOIN {event} e ON n.nid = e.nid " |
| 25 | . "WHERE e.event_start > %d"; |
| 26 | $dat = db_query(db_prefix_tables($sql), time()); |
| 27 | $check = db_fetch_object($dat); |
| 28 | return $check->latest; |
| 29 | } |
| 30 | /** |
| 31 | * Checks for saved searches that need to be run based on the date content was created |
| 32 | * @ingroup ef_ss |
| 33 | * @param $created The date of the most recently created event-enabled node type |
| 34 | * created is compared with the time a saved search was last run |
| 35 | * if created is greater than that value, the search needs to be run |
| 36 | * @return dataset of saved searches that need to be run |
| 37 | */ |
| 38 | function eventfinder_get_new_ss($created){ |
| 39 | $dat = db_query(db_prefix_tables('SELECT sid, ss_sql, last_run FROM {ef_saved_searches} WHERE last_run < %d'), $created); |
| 40 | return $dat; |
| 41 | } |
| 42 | /** |
| 43 | * Runs a saved search within the system |
| 44 | * @param $edit A row containing saved search criteria |
| 45 | */ |
| 46 | function eventfinder_ss_get_ev($edit){ |
| 47 | $dat = db_query($edit->ss_sql, time(), $edit->last_run); |
| 48 | eventfinder_get_new_events_alt($edit->ss_sql, $edit->last_run, $edit->sid); |
| 49 | /* while($row = db_fetch_object($dat)){ |
| 50 | print '<pre>'; |
| 51 | var_export($row); |
| 52 | print '</pre>'; |
| 53 | eventfinder_get_new_events_alt($edit->ss_sql, $edit->last_run, $edit->sid); |
| 54 | } |
| 55 | */ |
| 56 | eventfinder_ss_remove_old_events(); |
| 57 | } |
| 58 | /** |
| 59 | * performs saved search and accesses methods for recording results as well as |
| 60 | * sending mailings |
| 61 | * @param $sql The prebuilt SQL statement for a saved search |
| 62 | * @param $dlr DATE LAST RUN, time the saved search was last run |
| 63 | * used to ensure only new events are returned |
| 64 | * @param $sid Saved search ID, used to relate events to searches |
| 65 | */ |
| 66 | function eventfinder_get_new_events_alt($sql, $dlr, $sid){ |
| 67 | $ev_dat = db_query($sql, time(), $dlr); |
| 68 | while($row = db_fetch_array($ev_dat)){ |
| 69 | eventfinder_record_event($sid, $row['nid'], $row['event_start']); // This is an array, not an object |
| 70 | $rows[] = $row; |
| 71 | } |
| 72 | if (count($rows) > 0) { // Only send mail if we have events to report |
| 73 | eventfinder_send_ss_mail($sid, $rows); |
| 74 | } |
| 75 | eventfinder_set_last_run($sid); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * sends saved search email |
| 81 | * @param $sid Saved Search ID |
| 82 | * @param $rows array Array of objects used to send the mailing |
| 83 | */ |
| 84 | function eventfinder_send_ss_mail($sid, $rows){ |
| 85 | $thisuser = eventfinder_ss_get_owner($sid); |
| 86 | if($thisuser->mail != ''){ |
| 87 | foreach ($rows as $row){ |
| 88 | $data = eventfinder_prep_array(object2array(node_load(array('nid' => $row['nid'])))); |
| 89 | $content .= t(variable_get('ef_ss_ev_desc', ''), $data); |
| 90 | } |
| 91 | $body = t(variable_get(ef_ss_body, $content), array('%content' => $content)); |
| 92 | mail($thisuser->mail, variable_get('ef_ss_subj', ''), $body, eventfinder_mail_options()); |
| 93 | } |
| 94 | } |
| 95 | /** |
| 96 | * records events discovered within a saved search |
| 97 | * @param $sid Saved Search ID |
| 98 | * @param $nid Node ID for the event item |
| 99 | * @param $begin Date an event begins |
| 100 | */ |
| 101 | function eventfinder_record_event($sid, $nid, $begin){ |
| 102 | $sql = "INSERT INTO {ef_ss_node} (sid, nid, begin) VALUES (%d, %d, %d)"; |
| 103 | db_query(db_prefix_tables($sql), $sid, $nid, $begin); |
| 104 | return TRUE; |
| 105 | } |
| 106 | /** |
| 107 | * sets the time a saved search was last run |
| 108 | * @param $sid Saved Search ID to update |
| 109 | */ |
| 110 | function eventfinder_set_last_run($sid){ |
| 111 | $sql = "UPDATE {ef_saved_searches} SET last_run = %d WHERE sid = %d"; |
| 112 | db_query(db_prefix_tables($sql), time(), $sid); |
| 113 | return TRUE; |
| 114 | } |
| 115 | /** |
| 116 | * retrieve user info for the owner of a saved search |
| 117 | * @param $sid Saved search ID |
| 118 | * @return user info |
| 119 | */ |
| 120 | function eventfinder_ss_get_owner($sid){ |
| 121 | $sql = "SELECT ss.uid, u.name, u.mail FROM {ef_saved_searches} ss LEFT JOIN users u ON ss.uid = u.uid WHERE sid = %d"; |
| 122 | $dat = db_query(db_prefix_tables($sql), $sid); |
| 123 | return db_fetch_object($dat); |
| 124 | } |
| 125 | /** |
| 126 | * Prepares an array for insertion into content |
| 127 | * @ingroup ef_data |
| 128 | * @param $row Array to prepare |
| 129 | * @return associative array with all keys prefixed with a percent sign |
| 130 | */ |
| 131 | function eventfinder_prep_array($row) { |
| 132 | $new_arr = array(); |
| 133 | foreach ($row as $key => $value) { |
| 134 | $new_arr['%' . $key] = $value; |
| 135 | } |
| 136 | return $new_arr; |
| 137 | } |
| 138 | /** |
| 139 | * @defgroup ef_core Core drupal hooks |
| 140 | */ |
| 141 | /** |
| 142 | * Implementation of hook_cron(). |
| 143 | * @ingroup ef_core |
| 144 | */ |
| 145 | function eventfinder_cron() { |
| 146 | if(variable_get('ef_ss', 0) == 1){ |
| 147 | $new = eventfinder_check_new_events(); |
| 148 | $last_run = eventfinder_get_new_ss($new); |
| 149 | if(db_num_rows($last_run) > 0){ |
| 150 | while($row = db_fetch_object($last_run)){ |
| 151 | $content .= eventfinder_ss_get_ev($row); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | /** |
| 157 | * Implementation of hook_perm |
| 158 | * @ingroup ef_core |
| 159 | * @return permissions for the module |
| 160 | */ |
| 161 | function eventfinder_perm () { |
| 162 | return array('search eventfinder', 'saved searches', 'host event', 'admin eventfinder', 'my events'); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Provides a link to the CSS stylesheet associated with this module. |
| 167 | * @ingroup ef_core |
| 168 | * @return a <style> tag that indicates what file browsers should import |
| 169 | */ |
| 170 | function eventfinder_html_head() { |
| 171 | return '<style type="text/css">@import url(modules/eventfinder/eventfinder.css);</style>'; |
| 172 | } |
| 173 | /** |
| 174 | * Implementation of hook_user |
| 175 | * @ingroup ef_core |
| 176 | */ |
| 177 | function eventfinder_user($op, &$edit, &$user, $category = NULL) { |
| 178 | switch ($op){ |
| 179 | case 'load': |
| 180 | eventfinder_host_reg($user); |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | /** |
| 185 | * Provides the links that should be displayed when viewing events. |
| 186 | * @ingroup ef_core |
| 187 | * @param $type the type of link (for example, 'node', 'page', or 'system') being requested |
| 188 | * @param $node the node that is requesting the link. This is used in conjunction with $type to further determine |
| 189 | * what sort of link to display. |
| 190 | * @param $main unused in this method. |
| 191 | * @return an array of links, or an empty array if no links apply for the criteria passed to this method. |
| 192 | */ |
| 193 | function eventfinder_link($type, $node = NULL, $teaser = FALSE) { |
| 194 | switch ($type) { |
| 195 | case 'node': |
| 196 | if(!$teaser){ |
| 197 | if ((event_enabled_state($node->type) == 'all' || event_enabled_state($node->type) == 'solo') && isset($_SESSION['criteria']) && user_access('seach eventfinder')) { |
| 198 | $links[] = l(t('back to search'), 'eventfinder/search/return'); |
| 199 | } |
| 200 | } |
| 201 | break; |
| 202 | } |
| 203 | return $links ? $links : array(); |
| 204 | } |
| 205 | /** |
| 206 | * Implementation of hook_view(). |
| 207 | * @ingroup ef_core |
| 208 | */ |
| 209 | function eventfinder_nodeapi(&$node, $op, $teaser = NULL, $page = NULL){ |
| 210 | switch ($op) { |
| 211 | case 'load': |
| 212 | if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') { |
| 213 | $object = db_fetch_object(db_query(db_prefix_tables('SELECT count(r.uid) registered FROM {ef_register} r WHERE r.nid = %d'), $node->nid)); |
| 214 | $obj2 = db_fetch_object(db_query(db_prefix_tables('SELECT enable_reg, max_reg FROM {ef_details} d WHERE d.nid = %d'), $node->nid)); |
| 215 | return array('registered_users' => $object->registered, 'enable_reg' => $obj2->enable_reg, 'max_reg' => $obj2->max_reg); |
| 216 | } |
| 217 | break; |
| 218 | case 'view': |
| 219 | // if the node is an event enabled node |
| 220 | if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') { |
| 221 | eventfinder_host_reg(); |
| 222 | if (variable_get('ef_display_opts', 0) == 0) { |
| 223 | $node->body = theme_eventfinder_nodeoptions(eventfinder_options($node->nid)) . $node->body; |
| 224 | } |
| 225 | else if (variable_get('ef_display_opts', 0) == 1) { |
| 226 | $node->body = $node->body . theme_eventfinder_nodeoptions(eventfinder_options($node->nid)); |
| 227 | } |
| 228 | } |
| 229 | break; |
| 230 | case 'form post': |
| 231 | if(user_access('host event')){ |
| 232 | if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') { |
| 233 | $form = form_checkbox (t('Enable Online Registration for this Event'), 'enable_reg', 1, ($node->enable_reg == 1 ? true : false)); |
| 234 | $form .= form_textfield(t('Maximum Number of Online Registrants'), 'max_reg', (is_numeric($node->max_reg) ? $node->max_reg: 0), 3, 3, t('Enter the maximum number of people who can register for this event online. Enter a 0 for unlimited registrations.'), NULL, TRUE); |
| 235 | $form = form_group(t('EventFinder Options'), $form); |
| 236 | } |
| 237 | return $form; |
| 238 | } |
| 239 | break; |
| 240 | case 'insert': |
| 241 | if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') { |
| 242 | global $user; |
| 243 | $fields = array('nid', 'enable_reg', 'max_reg'); |
| 244 | db_query(db_prefix_tables('INSERT INTO {ef_details} (nid, enable_reg, max_reg) VALUES (%d, %d, %d)'), $node->nid, $node->enable_reg, $node->max_reg); |
| 245 | db_query(db_prefix_tables('INSERT INTO {ef_host} (nid, uid, created) VALUES (%d, %d, %d)'), $node->nid, $user->uid, time()); |
| 246 | watchdog('EventFinder', 'New saved search was created by user ' . $user->name); |
| 247 | if(variable_get('ef_mailer_create', 0) == 1 && strlen(variable_get('eventfinder_host_body', '')) > 0){ |
| 248 | eventfinder_host_mail($node->nid); |
| 249 | } |
| 250 | } |
| 251 | break; |
| 252 | case 'update': |
| 253 | if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') { |
| 254 | global $user; |
| 255 | $fields = array('nid', 'enable_reg', 'max_reg'); |
| 256 | // Deleting and inserting new records because of problems caused when |
| 257 | // eventfinder is installed on top of existing event and location installations |
| 258 | db_query(db_prefix_tables('DELETE FROM {ef_details} WHERE nid = %d'), $node->nid); |
| 259 | db_query(db_prefix_tables('DELETE FROM {ef_host} WHERE nid = %d AND uid = %d'), $node->nid, $user->uid); |
| 260 | db_query(db_prefix_tables('INSERT INTO {ef_details} (nid, enable_reg, max_reg) VALUES (%d, %d, %d)'), $node->nid, $node->enable_reg, $node->max_reg); |
| 261 | db_query(db_prefix_tables('INSERT INTO {ef_host} (nid, uid, created) VALUES (%d, %d, %d)'), $node->nid, $user->uid, time()); |
| 262 | if(variable_get('ef_mailer_create', 0) == 1 && strlen(variable_get('eventfinder_host_body', '')) > 0){ |
| 263 | eventfinder_host_mail($node->nid); |
| 264 | } |
| 265 | } |
| 266 | break; |
| 267 | case 'delete': |
| 268 | if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') { |
| 269 | db_query('DELETE FROM {ef_details} WHERE nid = %d', $node->nid); |
| 270 | db_query('DELETE FROM {ef_host} WHERE nid = %d AND uid = %d', $node->nid, $user->uid); |
| 271 | db_query('DELETE FROM {ef_register} WHERE nid = %d', $node->nid); |
| 272 | } |
| 273 | break; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Implementation of hook_help(). |
| 279 | * @ingroup ef_core |
| 280 | */ |
| 281 | function eventfinder_help($section) { |
| 282 | $output = ''; |
| 283 | switch ($section) { |
| 284 | case 'admin/help#eventfinder': |
| 285 | $output = '<p>'. t('EventFinder is a module for accessing event information on your site. It is very useful for communities that have many events. The ability to find events in many ways facilitates bringing community members together in person which makes communities stronger.') .'</p>'; |
| 286 | $output .= '<p>'. t('This module allows the user to seach for events based on event type, category, geographic location and proximity to major metropolitan areas. A user can also register for events, and it is helpful for event hosts to retrieve lists of contacts for events they have created on the site. Users can access lists of events which they have created and registered for. Event allows users to create saved searches, which monitor the system for new events matching criteria they have specified.') .'</p>'; |
| 287 | $output .= t('<p>You can:</p> |
| 288 | <ul> |
| 289 | <li>enable <strong>required</strong> civicrm, event, and location modules at <a href="%admin-modules">administer >> modules</a>.</li> |
| 290 | <li>configure a <strong>required</strong> default registration page through the CiviCRM Administration profile forms by selecting the <strong>Display in Registration Form?</strong> checkbox next to fields you are going to collect.</li> |
| 291 | <li>configure a <strong>required</strong> CiviCRM email profile field to select <strong>Key to Match Contacts?</strong>.</li> |
| 292 | <li>set permission for event searches, saved searches, event hosting, and administration at <a href="%admin-access">administer >> access control</a>.</li> |
| 293 | <li>view eventfinder prerequisites, module configuration, and contact repository settings at <a href="%admin-eventfinder">administer >> eventfinder</a>.</li> |
| 294 | <li>clear registration information or submit feedback about event finder at <a href="%admin-eventfinder">administer >> eventfinder</a>.</li> |
| 295 | <li>configure search settings for event taxonomy, event type, location proximity, state , metropolitan areas at <a href="%admin-settings-eventfinder">administer >> settings >> eventfinder</a>.</li> |
| 296 | <li>configure display, registration, mailer options, and saved search options at <a href="%admin-settings-eventfinder">administer >> settings >> eventfinder</a>.</li> |
| 297 | ', array('%admin-modules' => url('admin/modules'), '%admin-access' => url('admin/access'), '%admin-eventfinder' => url('admin/eventfinder'), '%admin-settings-eventfinder' => url('admin/settings/eventfinder'))) .'</ul>'; |
| 298 | $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%eventfinder">EventFinder page</a>.', array('%eventfinder' => 'http://www.drupal.org/handbook/modules/eventfinder/')) .'</p>'; |
| 299 | return $output; |
| 300 | case 'admin/modules#description': |
| 301 | return t('Lets users search for events based on location and event type.'); |
| 302 | break; |
| 303 | case 'admin/settings/eventfinder': |
| 304 | $output = t("Options on this page control what types of searches are displayed to users looking for events.<br><br>'Enable Event Taxonomy Searches' allows users to search by vocabulary terms associated with event-enabled content.<br><br>'Enable Event Type Searches' enables users to search by event-enabled content types.<br><br>'Enable Location Proximity Searches' enables users to search by proximity to a US zip code.<br><br>'Enable State Searches' enables users to search by state.<br><br>'Enable Major Metropolitan Area Searches' enables users to search by major metropolitan area."); |
| 305 | break; |
| 306 | case 'admin/settings/eventfinder/display_settings': |
| 307 | $output = t("Options on this page control the information presented to users while they use EventFinder.<br><br><strong>'Display EventFinder Options'</strong> controls where registration options appear for users.<br><br><strong>'Search Description'</strong> controls what instructions are presented to users when they perform a search.<br><br><strong>'My Events Description'</strong> controls what instructions are presented to users when they view the My Events page.<br><br><strong>'Host an Event Description'</strong> controls what instructions are presented to users when they view the Host an Event page.<br><br><strong>'Send Message to Registered Users Description'</strong> controls what information is presented to event hosts when they send messages to people registered for events."); |
| 308 | break; |
| 309 | case 'admin/settings/eventfinder/email_settings': |
| 310 | $output = t("Options on this page control what emails get sent from EventFinder."); |
| 311 | break; |
| 312 | case 'eventfinder/register/': |
| 313 | $output = t('You are about to register for an event. Please review the options below to proceed.'); |
| 314 | break; |
| 315 | } |
| 316 | return $output; |
| 317 | } |
| 318 | /** |
| 319 | * Implementation of hook_settings(). |
| 320 | * @ingroup ef_core |
| 321 | */ |
| 322 | function eventfinder_settings() { |
| 323 | $group .= form_checkbox('Enable Event Taxonomy Searches', 'ef_ev_tax', 1, (variable_get('ef_ev_tax', 0) ? true : false)); |
| 324 | $group .= form_checkbox('Enable Event Type Searches', 'ef_ev_type', 1, (variable_get('ef_ev_type', 0) ? true : false)); |
| 325 | $group .= form_checkbox('Enable Location Proximity Searches', 'ef_loc_prox', 1, (variable_get('ef_loc_prox', 0) ? true : false)); |
| 326 | $group .= form_checkbox('Enable State Searches', 'ef_state', 1, (variable_get('ef_state', 0) ? true : false)); |
| 327 | $group .= form_checkbox('Enable Major Metropolitan Area Searches', 'ef_mma', 1, (variable_get('ef_mma', 0) ? true : false)); |
| 328 | $output = form_group('Search Settings', $group); |
| 329 | |
| 330 | return $output; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Email option settings |
| 335 | * @ingroup ef_core |
| 336 | */ |
| 337 | function eventfinder_settings_registration () { |
| 338 | $edit = $_POST['edit']; |
| 339 | $op = $_POST['op']; |
| 340 | |
| 341 | if($op == t('Save Configuration')){ |
| 342 | variable_set('ef_reg_list_desc', $edit['ef_reg_list_desc']); |
| 343 | variable_set('ef_reg_opt', $edit['ef_reg_opt']); |
| 344 | variable_set('ef_reg_store', $edit['ef_reg_store']); |
| 345 | variable_set('ef_contact_source', $edit['ef_contact_source']); |
| 346 | variable_set('ef_civi_contact_form', $edit['ef_civi_contact_form']); |
| 347 | variable_set('ef_civi_reg_group', $edit['ef_civi_reg_group']); |
| 348 | } |
| 349 | |
| 350 | $group = form_textarea('Registration List Description', 'ef_reg_list_desc', variable_get('ef_reg_list_desc', ''), '70', 3, 'Description to appear at the top of the event registration screen.'); |
| 351 | |
| 352 | $opts = array('One click. Users must have an account on the Web site to register.', 'Registration page. Users are taken to a registration page. Allows anonymous registration.'); |
| 353 | $group .= form_item('Instructions', 'These fields are used to control how users register for an event and where registration information is kept. Changing these options after users have begun registering for events requires the registration table to be cleared of all previous registration information. You can clear the registration table ' . l('using the form on this page.', 'admin/eventfinder')); |
| 354 | $group .= form_radios('Registration Workflow', 'ef_reg_opt', variable_get('ef_reg_opt', 0), $opts, 'Select the type of registration to use for EventFinder.'); |
| 355 | |
| 356 | $opts_alt = array('Contact Manager', 'CiviCRM'); |
| 357 | |
| 358 | $repos_options = array(); |
| 359 | $repos_options[''] = 'Please choose...'; |
| 360 | |
| 361 | if(module_exist('contact_manager')){ |
| 362 | $repos_options['contact_manager'] = 'Contact Manager'; |
| 363 | } |
| 364 | if(module_exist('civicrm')){ |
| 365 | $repos_options['civicrm'] = 'CiviCRM'; |
| 366 | } |
| 367 | if(module_exist('civicrm') || module_exist('contact_manager')){ |
| 368 | $group .= form_select('Contact Repository', 'ef_reg_store', variable_get('ef_reg_store', ''), $repos_options, 'Please select where to store EventFinder registration information. This field is only necessary if you have selected the Registration Page option above.'); |
| 369 | } |
| 370 | |
| 371 | // choose group with which to store contact manager registrations |
| 372 | if(module_exist('contact_manager')){ |
| 373 | $dat = db_query(db_prefix_tables('SELECT csid, name FROM {contact_manager_sources} ORDER BY weight')); |
| 374 | while($row = db_fetch_object($dat)){ |
| 375 | $options[$row->csid] = $row->name; |
| 376 | } |
| 377 | $group .= form_select('Contact Manager Source Group', 'ef_contact_source', variable_get('ef_contact_source', ''), $options, 'The contact source for contacts signing up through EventFinder registration. You should probably define a unique group for EventFinder registration so as to avoid contaminating other lists. This field is only necessary if the contacts module is being used for registration information.'); |
| 378 | } |
| 379 | else { |
| 380 | $group .= form_item('Contact Manager Source Group', 'Contact Manager is not enabled. Source groups are unavailable.'); |
| 381 | } |
| 382 | |
| 383 | // civicrm contact options |
| 384 | if (function_exists('civicrm_initialize')) { |
| 385 | civicrm_initialize(TRUE); |
| 386 | $ufGroups = crm_uf_get_profile_groups( ); |
| 387 | $group .= form_select('CiviCRM Contact Form', 'ef_civi_contact_form', variable_get('ef_civi_contact_form', ''), $ufGroups, 'The contact form to use for capturing contact information when a user registers for an event. This field is only necessary if CiviCRM is being used for registration information.'); |
| 388 | $groups = crm_get_groups(); |
| 389 | $i = 0; |
| 390 | while ($i < count($groups) ) { |
| 391 | $group_options[$groups[$i]->id] = $groups[$i]->name; |
| 392 | ++$i; |
| 393 | } |
| 394 | $group .= form_select('Registration Groups', 'ef_civi_reg_group', variable_get('ef_civi_reg_group', ''), $group_options, 'Select the CiviCRM group(s) with which to associate users when they register for events.', 0, TRUE, TRUE); |
| 395 | } |
| 396 | $output .= form_group('Registration Settings', $group); |
| 397 | |
| 398 | $output .= form_submit(t('Save Configuration')); |
| 399 | $output = form($output); |
| 400 | print theme('page', $output); |
| 401 | |
| 402 | } |
| 403 | /** |
| 404 | * Email option settings |
| 405 | * @ingroup ef_core |
| 406 | */ |
| 407 | function eventfinder_settings_email () { |
| 408 | $edit = $_POST['edit']; |
| 409 | $op = $_POST['op']; |
| 410 | |
| 411 | if($op == t('Save Configuration')){ |
| 412 | variable_set('ef_send_html', $edit['ef_send_html']); |
| 413 | variable_set('ef_mailer_create', $edit['ef_mailer_create']); |
| 414 | variable_set('ef_mailer_register', $edit['ef_mailer_register']); |
| 415 | variable_set('ef_email_name', $edit['ef_email_name']); |
| 416 | variable_set('ef_email_addr', $edit['ef_email_addr']); |
| 417 | variable_set('eventfinder_host_subj', $edit['eventfinder_host_subj']); |
| 418 | variable_set('eventfinder_host_body', $edit['eventfinder_host_body']); |
| 419 | variable_set('ef_reg_subj', $edit['ef_reg_subj']); |
| 420 | variable_set('ef_reg_body', $edit['ef_reg_body']); |
| 421 | } |
| 422 | |
| 423 | $group = form_checkbox('Enable EventFinder to send HTML emails', 'ef_send_html', 1, (variable_get('ef_send_html', 0) ? true : false), 'Controls whether eventfinder sends HTML emails to users. Defaults to straight text.'); |
| 424 | $group .= form_checkbox('Enable EventFinder to send a confirmation mail to people who enter events', 'ef_mailer_create', 1, (variable_get('ef_mailer_create', 0) ? true : false), 'This message will be sent out every time a user registers an event-enabled content type.'); |
| 425 | $group .= form_checkbox('Enable registration confirmation email', 'ef_mailer_register', 1, (variable_get('ef_mailer_register', 0) ? true : false), 'This message will be sent out each time a user registers for an event in the system.'); |
| 426 | $group .= form_textfield('Email Name', 'ef_email_name', variable_get('ef_email_name', ''), '70', '255', 'The name to be associated with emails coming from EventFinder', NULL, FALSE); |
| 427 | $group .= form_textfield('Email Address', 'ef_email_addr', variable_get('ef_email_addr', ''), '70', '255', 'The email address for emails coming from EventFinder.', NULL, FALSE); |
| 428 | $group .= form_textfield('Host Email Subject Line', 'eventfinder_host_subj', variable_get('eventfinder_host_subj', ''), '70', '255', 'The subject line of emails to send to users after creating an event.', NULL, FALSE); |
| 429 | $group .= form_textarea('Host Email Body', 'eventfinder_host_body', variable_get('eventfinder_host_body', ''), '70', 5, 'The body of the message to send to event hosts after creating an event. You can dynamically include any fields present in the content types that are event and location enabled by prefixing them with a percent (%) sign. Acceptable variables include %title, %start, %end, $postal_code, %province, %street, and %city.'); |
| 430 | $group .= form_textfield('Register Email Subject Line', 'ef_reg_subj', variable_get('ef_reg_subj', ''), '70', '255', 'The subject line of emails to send to users after registering for an event.', NULL, FALSE); |
| 431 | $group .= form_textarea('Register Email Body', 'ef_reg_body', variable_get('ef_reg_body', ''), '70', 5, 'The body of the message to send to event hosts after registering for an event. You can dynamically include any fields present in the content types that are event and location enabled by prefixing them with a percent (%) sign. Acceptable variables include %title, %start, %end, $postal_code, %province, %street, and %city.'); |
| 432 | $output .= form_group('Email Options', $group); |
| 433 | |
| 434 | $output .= form_submit(t('Save Configuration')); |
| 435 | $output = form($output); |
| 436 | print theme('page', $output); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Saved search settings for eventfinder |
| 441 | * @ingroup ef_core |
| 442 | */ |
| 443 | function eventfinder_settings_saved_searches () { |
| 444 | $edit = $_POST['edit']; |
| 445 | $op = $_POST['op']; |
| 446 | |
| 447 | if($op == t('Save Configuration')){ |
| 448 | |
| 449 | variable_set('ef_ss', $edit['ef_ss']); |
| 450 | variable_set('ef_ss_max', $edit['ef_ss_max']); |
| 451 | variable_set('ef_ss_desc', $edit['ef_ss_desc']); |
| 452 | variable_set('ef_ss_create_desc', $edit['ef_ss_create_desc']); |
| 453 | variable_set('ef_ss_subj', $edit['ef_ss_subj']); |
| 454 | variable_set('ef_ss_body', $edit['ef_ss_body']); |
| 455 | variable_set('ef_ss_ev_desc', $edit['ef_ss_ev_desc']); |
| 456 | |
| 457 | } |
| 458 | |
| 459 | $group = form_checkbox('Enable Saved Searches', 'ef_ss', 1, (variable_get('ef_ss', 0) ? true : false), 'Enables saved searches throughout EventFinder. Overrides all permissions throughout the system. Best to disable it if you have concerns over server performance.'); |
| 460 | $group .= form_textfield ('Maximum Saved Searches per User', 'ef_ss_max', variable_get('ef_ss_max', 5), 5, 2, $description='The maximum number of saved searches a single user can create.'); |
| 461 | $group .= form_textarea('Saved Search Description', 'ef_ss_desc', variable_get('ef_ss_desc', ''), '70', 3, 'Description for the Saved Search page.'); |
| 462 | $group .= form_textarea('Create Saved Search Instructions', 'ef_ss_create_desc', variable_get('ef_ss_create_desc', ''), '70', 3, 'Description for the Saved Search page.'); |
| 463 | $group .= form_textfield('Saved Search Email Subject Line', 'ef_ss_subj', variable_get('ef_ss_subj', ''), '70', 255, 'The subject line of emails to send to users when new events are found.', NULL, FALSE); |
| 464 | $group .= form_textarea('Saved Search Email Body', 'ef_ss_body', variable_get('ef_ss_body', ''), '70', 5, 'The body of the message to send to users when new events are found. Acceptable variables include %content, which represents the text for new events.'); |
| 465 | $group .= form_textarea('Saved Search Event Description', 'ef_ss_ev_desc', variable_get('ef_ss_ev_desc', ''), '70', 5, 'Handles the display of event details within saved search mailings from the system. You can dynamically include any fields present in the content types that are event and location enabled by prefixing them with a percent (%) sign. Acceptable variables include %title, %start, %end, $postal_code, %province, %street, and %city.'); |
| 466 | $output .= form_group('Saved Search Options', $group); |
| 467 | |
| 468 | $output .= form_submit(t('Save Configuration')); |
| 469 | $output = form($output); |
| 470 | print theme('page', $output); |
| 471 | |
| 472 | } |
| 473 | /** |
| 474 | * Display settings for eventfinder |
| 475 | * @ingroup ef_core |
| 476 | */ |
| 477 | function eventfinder_settings_display () { |
| 478 | $edit = $_POST['edit']; |
| 479 | $op = $_POST['op']; |
| 480 | |
| 481 | if($op == t('Save Configuration')){ |
| 482 | variable_set('ef_display_opts', $edit['ef_display_opts']); |
| 483 | variable_set('ef_search_desc', $edit['ef_search_desc']); |
| 484 | variable_set('eventfinder_myevents_desc', $edit['eventfinder_myevents_desc']); |
| 485 | variable_set('eventfinder_host_desc', $edit['eventfinder_host_desc']); |
| 486 | variable_set('ef_message_desc', $edit['ef_message_desc']); |
| 487 | } |
| 488 | |
| 489 | $opts = array('Above Event Details', 'Below Event Details', 'In a Block'); |
| 490 | $group = form_radios('Display EventFinder Options', 'ef_display_opts', variable_get('ef_display_opts', 1), $opts,'Configure where to place EventFinder options.'); |
| 491 | $group .= form_textarea('Search Description', 'ef_search_desc', variable_get('ef_search_desc', ''), '70', 3, 'Description for the main search interface.'); |
| 492 | $group .= form_textarea('My Events Description', 'eventfinder_myevents_desc', variable_get('eventfinder_myevents_desc', ''), '70', 3, 'Description for the My Events page.'); |
| 493 | $group .= form_textarea('Host an Event Description', 'eventfinder_host_desc', variable_get('eventfinder_host_desc', ''), '70', 3, 'Description for the Host an Event page.'); |
| 494 | $group .= form_textarea('Send Message to Registered Users Description', 'ef_message_desc', variable_get('ef_message_desc', ''), '70', 3, 'Description for the Send Message to Registered Users page.'); |
| 495 | $output .= form_group('Display Settings', $group); |
| 496 | $output .= form_submit(t('Save Configuration')); |
| 497 | $output = form($output); |
| 498 | print theme('page', $output); |
| 499 | } |
| 500 | /** |
| 501 | * Implementation of hook_menu(). |
| 502 | * @ingroup ef_core |
| 503 | */ |
| 504 | function eventfinder_menu($may_cache) { |
| 505 | $items = array(); |
| 506 | if ($may_cache) { |
| 507 | |
| 508 | // settings pages |
| 509 | $items[] = array('path' => 'admin/settings/eventfinder/main', |
| 510 | 'title' => t('main settings'), |
| 511 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 512 | 'weight' => -10 |
| 513 | ); |
| 514 | $items[] = array('path' => 'admin/settings/eventfinder/display_settings', |
| 515 | 'title' => t('display settings'), |
| 516 | 'callback' => 'eventfinder_settings_display', |
| 517 | 'access' => user_access('administer site configuration'), |
| 518 | 'type' => MENU_LOCAL_TASK, |
| 519 | 'weight' => -9 |
| 520 | ); |
| 521 | $items[] = array('path' => 'admin/settings/eventfinder/email_settings', |
| 522 | 'title' => t('email options'), |
| 523 | 'callback' => 'eventfinder_settings_email', |
| 524 | 'access' => user_access('administer site configuration'), |
| 525 | 'type' => MENU_LOCAL_TASK, |
| 526 | 'weight' => -8 |
| 527 | ); |
| 528 | $items[] = array('path' => 'admin/settings/eventfinder/registration_settings', |
| 529 | 'title' => t('registration settings'), |
| 530 | 'callback' => 'eventfinder_settings_registration', |
| 531 | 'access' => user_access('administer site configuration'), |
| 532 | 'type' => MENU_LOCAL_TASK, |
| 533 | 'weight' => -7 |
| 534 | ); |
| 535 | $items[] = array('path' => 'admin/settings/eventfinder/saved_searches', |
| 536 | 'title' => t('saved search settings'), |
| 537 | 'callback' => 'eventfinder_settings_saved_searches', |
| 538 | 'access' => user_access('administer site configuration'), |
| 539 | 'type' => MENU_LOCAL_TASK, |
| 540 | 'weight' => -6 |
| 541 | ); |
| 542 | |
| 543 | |
| 544 | if(user_access('search eventfinder')){ |
| 545 | $items[] = array('path' => 'admin/eventfinder', |
| 546 | 'title' => t('eventfinder'), |
| 547 | 'callback' => 'eventfinder_debug', |
| 548 | 'access' => user_access('admin eventfinder') |
| 549 | ); |
| 550 | $items[] = array('path' => 'eventfinder', |
| 551 | 'title' => t('EventFinder'), |
| 552 | 'callback' => 'eventfinder_search_items', |
| 553 | 'access' => user_access('search eventfinder') |
| 554 | ); |
| 555 | $items[] = array('path' => 'eventfinder/search', |
| 556 | 'title' => t('Search Events'), |
| 557 | 'callback' => 'eventfinder_search_items', |
| 558 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 559 | 'weight' => -10); |
| 560 | if(user_access('access content')){ |
| 561 | $items[] = array('path' => 'eventfinder/host', |
| 562 | 'title' => t('Host An Event'), |
| 563 | 'callback' => 'eventfinder_host_event', |
| 564 | 'access' => user_access('host event'), |
| 565 | 'type' => MENU_LOCAL_TASK, |
| 566 | 'weight' => -9); |
| 567 | } |
| 568 | $items[] = array('path' => 'eventfinder/my_events', |
| 569 | 'title' => t('My Events'), |
| 570 | 'callback' => 'eventfinder_my_events', |
| 571 | 'access' => user_access('my events'), |
| 572 | 'type' => MENU_LOCAL_TASK, |
| 573 | 'weight' => -8); |
| 574 | $items[] = array('path' => 'eventfinder/my_events/registered', |
| 575 | 'title' => t('Registered Events'), |
| 576 | 'callback' => 'eventfinder_my_events_registered', |
| 577 | 'access' => user_access('my events'), |
| 578 | 'type' => MENU_LOCAL_TASK, |
| 579 | 'weight' => -10); |
| 580 | $items[] = array('path' => 'eventfinder/my_events/hosted', |
| 581 | 'title' => t('Hosted Events'), |
| 582 | 'callback' => 'eventfinder_my_events_host', |
| 583 | 'access' => user_access('my events'), |
| 584 | 'type' => MENU_LOCAL_TASK, |
| 585 | 'weight' => -9); |
| 586 | if(variable_get('ef_ss', 0) == 1){ |
| 587 | $items[] = array('path' => 'eventfinder/saved_searches', |
| 588 | 'title' => t('Saved Searches'), |
| 589 | 'callback' => 'eventfinder_saved_searches', |
| 590 | 'access' => user_access('saved searches'), |
| 591 | 'type' => MENU_LOCAL_TASK, |
| 592 | 'weight' => -8); |
| 593 | $items[] = array('path' => 'eventfinder/saved_searches/list', |
| 594 | 'title' => t('List Saved Searches'), |
| 595 | 'callback' => 'eventfinder_saved_searches', |
| 596 | 'access' => user_access('saved searches'), |
| 597 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 598 | 'weight' => -10); |
| 599 | $items[] = array('path' => 'eventfinder/saved_searches/create', |
| 600 | 'title' => t('Create New Saved Search'), |
| 601 | 'callback' => 'eventfinder_create_saved_search', |
| 602 | 'access' => user_access('saved searches'), |
| 603 | 'type' => MENU_LOCAL_TASK, |
| 604 | 'weight' => -9); |
| 605 | } |
| 606 | } |
| 607 | $items[] = array('path' => 'eventfinder/saved_searches/delete', |
| 608 | 'callback' => 'eventfinder_saved_search_delete', |
| 609 | 'access' => user_access('search eventfinder'), |
| 610 | 'type' => MENU_CALLBACK |
| 611 | ); |
| 612 | $items[] = array('path' => 'eventfinder/saved_searches/edit', |
| 613 | 'callback' => 'eventfinder_saved_search_edit', |
| 614 | 'access' => user_access('search eventfinder'), |
| 615 | 'type' => MENU_CALLBACK |
| 616 | ); |
| 617 | $items[] = array('path' => 'eventfinder/saved_searches/run', |
| 618 | 'callback' => 'eventfinder_run_saved_search', |
| 619 | 'access' => user_access('search eventfinder'), |
| 620 | 'type' => MENU_CALLBACK |
| 621 | ); |
| 622 | $items[] = array('path' => 'eventfinder/details', |
| 623 | 'title' => t('Event Details'), |
| 624 | 'callback' => 'eventfinder_details', |
| 625 | 'access' => user_access('search eventfinder'), |
| 626 | 'type' => MENU_CALLBACK |
| 627 | ); |
| 628 | $items[] = array('path' => 'eventfinder/register', |
| 629 | 'title' => t('Register'), |
| 630 | 'callback' => 'eventfinder_reg_page', |
| 631 | 'access' => user_access('search eventfinder'), |
| 632 | 'type' => MENU_CALLBACK |
| 633 | ); |
| 634 | $items[] = array('path' => 'eventfinder/mail', |
| 635 | 'title' => t('Send a Message to Registered Persons'), |
| 636 | 'callback' => 'eventfinder_send_mail', |
| 637 | 'access' => user_access('search eventfinder'), |
| 638 | 'type' => MENU_CALLBACK |
| 639 | ); |
| 640 | $items[] = array('path' => 'eventfinder/register/print', |
| 641 | 'title' => t('Registered Attendees'), |
| 642 | 'callback' => 'eventfinder_view_register_list', |
| 643 | 'access' => user_access('search eventfinder'), |
| 644 | 'type' => MENU_CALLBACK |
| 645 | ); |
| 646 | } |
| 647 | drupal_set_html_head(eventfinder_html_head()); |
| 648 | return $items; |
| 649 | } |
| 650 | /** |
| 651 | * Sends an email to users registered for an event |
| 652 | * @ingroup ef_core |
| 653 | */ |
| 654 | function eventfinder_send_mail ($arg1 = FALSE) { |
| 655 | if($arg1){ |
| 656 | $edit = $_POST['edit']; |
| 657 | $op = $_POST['op']; |
| 658 | global $user; |
| 659 | eventfinder_host_reg(); |
| 660 | drupal_set_breadcrumb( |
| 661 | array( |
| 662 | l(t('Home'), ''), |
| 663 | l(t('EventFinder'), 'eventfinder'), |
| 664 | l(t('Event Details'), 'eventfinder/search_events/' . $arg1), |
| 665 | t('Send Message to Registered Users') |
| 666 | ) |
| 667 | ); |
| 668 | drupal_set_title(t('Send Message to Registered Users')); |
| 669 | $error = form_get_errors(); |
| 670 | // get users registered under one click registration |
| 671 | if($op == 'Send Message'){ |
| 672 | if(strlen($edit['ef_mail_subject']) > 0 && strlen($edit['ef_mail_body']) > 0){ |
| 673 | if(variable_get('ef_reg_opt', 0) == 0){ |
| 674 | $dat = db_query(db_prefix_tables('SELECT u.mail FROM {users} u INNER JOIN {ef_register} er ON u.uid = er.uid WHERE er.nid = %d'), $arg1); |
| 675 | while($row = db_fetch_object($dat)){ |
| 676 | mail($row->mail, $edit['ef_mail_subject'], $edit['ef_mail_body'], eventfinder_mail_options()); |
| 677 | } |
| 678 | drupal_set_message('Your message has been sent.'); |
| 679 | drupal_goto('eventfinder/search_events/' . $arg1); |
| 680 | } else if (variable_get('ef_reg_store', 0) == 'contact_manager') {// contact manager integration |
| 681 | |
| 682 | $dat = db_query(db_prefix_tables('SELECT cm.mail FROM {contact_manager} cm INNER JOIN {ef_register} er ON cm.nid = er.uid WHERE er.nid = %d'), $arg1); |
| 683 | while($row = db_fetch_object($dat)){ |
| 684 | mail($row->mail, $edit['ef_mail_subject'], $edit['ef_mail_body'], eventfinder_mail_options()); |
| 685 | } |
| 686 | drupal_set_message('Your message has been sent.'); |
| 687 | drupal_goto('eventfinder/search_events/' . $arg1); |
| 688 | } else if (variable_get('ef_reg_store', 0) == 'civicrm') { // civicrm integration |
| 689 | $dat = db_query(db_prefix_tables('SELECT uid FROM {ef_register} WHERE nid = %d'), $arg1); |
| 690 | while($row = db_fetch_object($dat)){ |
| 691 | $contact = crm_get_contact(array('contact_id' => $row->uid)); |
| 692 | mail($contact->location[1]->email[1]->email, $edit['ef_mail_subject'], $edit['ef_mail_body'], eventfinder_mail_options()); |
| 693 | } |
| 694 | drupal_set_message('Your message has been sent.'); |
| 695 | drupal_goto('eventfinder/search_events/' . $arg1); |
| 696 | } |
| 697 | } else { |
| 698 | if(strlen($edit['ef_mail_subject']) == 0){ |
| 699 | form_set_error('ef_mail_subject', t('You must provide a subject for this message')); |
| 700 | } |
| 701 | if(strlen($edit['ef_mail_body']) == 0){ |
| 702 | form_set_error('ef_mail_body', t('You must provide a body for this message')); |
| 703 | } |
| 704 | } |
| 705 | } else if ($op == 'Cancel'){ |
| 706 | drupal_goto('eventfinder/search_events/' . $arg1); |
| 707 | } |
| 708 | $content .= theme('eventfinder_desc', variable_get('ef_message_desc', '')); |
| 709 | if (variable_get('ef_display_opts', 0) != 2) { |
| 710 | $content .= eventfinder_options($arg1); |
| 711 | } |
| 712 | $output .= form_item('From', $user->mail); |
| 713 | $output .= form_textfield ('Subject', 'ef_mail_subject', $edit['ef_mail_subject'], 40, 255, $error['ef_mail_subject'], NULL, TRUE); |
| 714 | $output .= form_textarea('Body', 'ef_mail_body', $edit['ef_mail_body'], '60', 3, $error['ef_mail_body'], NULL, TRUE); |
| 715 | $output .= form_submit('Send Message'); |
| 716 | $output .= form_submit('Cancel'); |
| 717 | $output = form($output); |
| 718 | $content = $content . $output; |
| 719 | print theme('eventfinder_main', $content); |
| 720 | } |
| 721 | } |
| 722 | /** |
| 723 | * Displays a registraion page |
| 724 | * @ingroup ef_core |
| 725 | * @param $nid the node id for the event for which the user is registering |
| 726 | * @return form for signing up |
| 727 | */ |
| 728 | function eventfinder_reg_page($nid) { |
| 729 | $repos = variable_get('ef_reg_store', 'civicrm'); |
| 730 | if($repos === 'civicrm'){ |
| 731 | eventfinder_reg_page_civi ($nid); |
| 732 | } else { |
| 733 | eventfinder_reg_page_cm ($nid); |
| 734 | } |
| 735 | } |
| 736 | /** |
| 737 | * Displays a registraion page from contact manager |
| 738 | * @ingroup ef_core |
| 739 | * @param $nid the node id for the event for which the user is registering |
| 740 | * @return form for signing up |
| 741 | */ |
| 742 | function eventfinder_reg_page_cm ($nid) { |
| 743 | eventfinder_host_reg(); |
| 744 | $edit = $_POST['edit']; |
| 745 | $op = $_POST['op']; |
| 746 | drupal_set_breadcrumb( |
| 747 | array( |
| 748 | l(t('Home'), ''), |
| 749 | l(t('EventFinder'), 'eventfinder'), |
| 750 | l(t('Event Details'), 'eventfinder/search_events/' . $arg1), |
| 751 | t('Register') |
| 752 | ) |
| 753 | ); |
| 754 | drupal_set_title(t('Register for this event')); |
| 755 | // registers a user under one click regisration |
| 756 | if(variable_get('ef_reg_opt', 0) == 0){ |
| 757 | global $user; |
| 758 | eventfinder_reg_contact($user->uid, $nid); // register the user |
| 759 | drupal_goto('eventfinder/search_events/' . $nid); |
| 760 | } |
| 761 | // handles contact form registration |
| 762 | if($op == 'Cancel'){ |
| 763 | drupal_goto('eventfinder/search_events/' . $nid . '/register/'); |
| 764 | } |
| 765 | if($op == 'Register for this Event'){ |
| 766 | // TODO: Make the verification happen HERE |
| 767 | $check = eventfinder_reg_contact_info($edit, $nid, $edit['mail']); |
| 768 | } |
| 769 | $error = form_get_errors(); |
| 770 | $node = node_load(array('nid' => $nid)); |
| 771 | if($user->contact_nid){ |
| 772 | // get existing contact form information for the user |
| 773 | $get_ucid = node_load(array('nid' => $user->contact_nid)); |
| 774 | } |
| 775 | $i = 0; |
| 776 | if(!$edit){ |
| 777 | $edit = array(); |
| 778 | } |
| 779 | $fields = array_keys($edit); |
| 780 | while ($i < sizeof($fields)) { |
| 781 | $node->{$fields[$i]} = $edit[$fields[$i]]; |
| 782 | // print $field . '<br>'; |
| 783 | $i++; |
| 784 | } |
| 785 | if (variable_get('ef_display_opts', 0) != 2) { |
| 786 | $content .= eventfinder_options($nid); |
| 787 | } |
| 788 | $content .= form_textfield ('Email Address', 'mail', $edit['mail'], '', '', NULL, NULL, TRUE); |
| 789 | $content .= _contact_manager_form($node); |
| 790 | $content .= form_hidden('nid', $nid); |
| 791 | $content .= form_submit('Register for this Event'); |
| 792 | $content .= form_submit('Cancel'); |
| 793 | $content = form($content); |
| 794 | $content = theme('eventfinder_registration_form', $node->title, $content); |
| 795 | print theme('eventfinder_main', $content); |
| 796 | } |
| 797 | /** |
| 798 | * Displays a registraion page from civicrm |
| 799 | * @ingroup ef_core |
| 800 | * @param $nid the node id for the event for which the user is registering |
| 801 | * @return form for signing up |
| 802 | */ |
| 803 | function eventfinder_reg_page_civi ($nid) { |
| 804 | eventfinder_host_reg(); |
| 805 | $edit = $_POST['edit']; |
| 806 | $op = $_POST['op']; |
| 807 | drupal_set_breadcrumb( |
| 808 | array( |
| 809 | l(t('Home'), ''), |
| 810 | l(t('EventFinder'), 'eventfinder'), |
| 811 | l(t('Event Details'), 'eventfinder/search_events/' . $arg1), |
| 812 | t('Register') |
| 813 | ) |
| 814 | ); |
| 815 | drupal_set_title(t('Register for this event')); |
| 816 | // registers a user under one click regisration |
| 817 | if(variable_get('ef_reg_opt', 0) == 0){ |
| 818 | global $user; |
| 819 | eventfinder_reg_contact($user->uid, $nid); // register the user |
| 820 | drupal_goto('eventfinder/search_events/' . $nid); |
| 821 | } |
| 822 | // handles contact form registration |
| 823 | if($op == 'Cancel'){ |
| 824 | drupal_goto('eventfinder/search_events/' . $nid . '/register/'); |
| 825 | } |
| 826 | if($op == 'Register for this Event'){ |
| 827 | // TODO: Make the verification happen HERE |
| 828 | $check = eventfinder_reg_contact_info_civi($edit, $nid, $edit['email']); |
| 829 | } |
| 830 | $error = form_get_errors(); |
| 831 | $node = node_load(array('nid' => $nid)); |
| 832 | if($user->contact_nid){ |
| 833 | // get existing contact form information for the user |
| 834 | $get_ucid = node_load(array('nid' => $user->contact_nid)); |
| 835 | } |
| 836 | $i = 0; |
| 837 | if(!$edit){ |
| 838 | $edit = array(); |
| 839 | } |
| 840 | $fields = array_keys($edit); |
| 841 | while ($i < sizeof($fields)) { |
| 842 | $node->{$fields[$i]} = $edit[$fields[$i]]; |
| 843 | //print $field . '<br>'; |
| 844 | $i++; |
| 845 | } |
| 846 | if (variable_get('ef_display_opts', 0) != 2) { |
| 847 | $content .= eventfinder_options($nid); |
| 848 | } |
| 849 | if (function_exists('civicrm_initialize')) { |
| 850 | civicrm_initialize(TRUE); |
| 851 | $content .= crm_uf_get_profile_html( null, $title, null, true, true ); |
| 852 | } |
| 853 | $content .= form_hidden('nid', $nid); |
| 854 | $content .= form_submit('Register for this Event'); |
| 855 | $content .= form_submit('Cancel'); |
| 856 | $content = form($content); |
| 857 | $content = theme('eventfinder_registration_form', $node->title, $content); |
| 858 | print theme('eventfinder_main', $content); |
| 859 | } |
| 860 | |
| 861 | /** |
| 862 | * Registers someone under Contact Manager |
| 863 | * @ingroup groupname |
| 864 | * @return description of what is returned |
| 865 | */ |
| 866 | function eventfinder_reg_contact_info ($edit, $nid = FALSE, $arg1 = FALSE) { |
| 867 | if($arg1){ |
| 868 | global $user; |
| 869 | // verify the contact info |
| 870 | $node = eventfinder_validate_contact($edit, $arg1); |
| 871 | $error = form_get_errors(); |
| 872 | if (count($error) == 0) { |
| 873 | // check to see if the user is already associated with a contact |
| 874 | if($user->contact_nid > 0 && $user->uid > 0){ |
| 875 | // if so, save changes to contact info and save registration |
| 876 | // print 'adding contact info'; |
| 877 | $node->nid = $user->contact_nid; |
| 878 | node_save($node); |
| 879 | $reg_id = $user->contact_nid; |
| 880 | } // is not, save contact and save registration |
| 881 | else if ($user->contact_nid > 0 && $user->uid > 0) { |
| 882 | $new_nid = node_save($node); |
| 883 | $reg_id = $new_nid; |
| 884 | eventfinder_user_contact($user->uid, $new_nid); |
| 885 | // print 'CREATING NEW CONTACT'; |
| 886 | // TODO: INSERT REG |
| 887 | }// if user is not logged in, save contact info |
| 888 | else { |
| 889 | // print 'ADDING NEW CONTACT WIHTOUT USER ID'; |
| 890 | $check = eventfinder_reg_check_contact($edit['mail']); // checks to see whether there is a contact for this email address |
| 891 | if($check){ |
| 892 | $reg_id = $check; |
| 893 | } else { |
| 894 | $new_nid = node_save($node); |
| 895 | $reg_id = $new_nid; |
| 896 | } |
| 897 | } |
| 898 | // this is where we insert the contact registration |
| 899 | // need to get the nid passed into this function... |
| 900 | // still need to do the insert when a user is not logged in |
| 901 | if($reg_id){ |
| 902 | eventfinder_reg_contact($reg_id, $nid, $arg1); |
| 903 | drupal_set_message(t('You are now registered for this event.')); |
| 904 | drupal_goto('eventfinder/search_events/' . $edit['nid']); |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Registers someone under CiviCRM |
| 912 | * @ingroup groupname |
| 913 | * @return description of what is returned |
| 914 | */ |
| 915 | function eventfinder_reg_contact_info_civi ($edit, $nid = FALSE, $arg1 = FALSE) { |
| 916 | global $user; |
| 917 | if ($user->uid) { |
| 918 | $userID = crm_uf_get_match_id( $user->uid ); |
| 919 | if ($userID) { |
| 920 | civicrm_form_data($edit, $user, $title, false); |
| 921 | $contact = crm_get_contact(array('contact_id' => $userID)); |
| 922 | } |
| 923 | else { |
| 924 | civicrm_register_data($edit, $user, $title, false); |
| 925 | $contact = crm_get_contact(array('email' => $user->mail)); |
| 926 | } |
| 927 | } |
| 928 | else { |
| 929 | $contact = crm_create_contact($edit); |
| 930 | } |
| 931 | if ($contact->id) { |
| 932 | $groups = variable_get('ef_civi_reg_group', array()); |
| 933 | foreach ($groups as $group_id) { |
| 934 | $group = crm_get_groups(array('id' => $group_id)); |
| 935 | $group = $group[0]; |
| 936 | $contact_array = array($contact); |
| 937 | crm_add_group_contacts($group, $contact_array); |
| 938 | } |
| 939 | $act_params = array( |
| 940 | 'entity_table' => 'civicrm_contact', |
| 941 | 'entity_id' => $contact->id, |
| 942 | 'activity_type' => 'Registered For an Event', |
| 943 | 'module' => 'EventFinder', |
| 944 | 'activity_id' => $arg1, |
| 945 | 'activity_summary' => "This personed registered to attend an event - " . $event->title, |
| 946 | 'activity_date' => date('YmdHis') |
| 947 | ); |
| 948 | $activity =& crm_create_activity_history($act_params); |
| 949 | eventfinder_reg_contact($contact->id, $nid, $arg1); |
| 950 | drupal_set_message(t('You are now registered for this event.')); |
| 951 | drupal_goto('eventfinder/search_events/' . $edit['nid']); |
| 952 | } |
| 953 | } |
| 954 | /** |
| 955 | * |
| 956 | * Description goes here |
| 957 | * |
| 958 | * @ingroup groupname |
| 959 | * @return description of what is returned |
| 960 | * |
| 961 | */ |
| 962 | function eventfinder_user_contact($uid, $nid) { |
| 963 | db_query(db_prefix_tables('UPDATE {users} SET contact_nid = %d WHERE uid = %d'), $nid, $uid); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * |
| 968 | * Description goes here |
| 969 | * |
| 970 | * @ingroup groupname |
| 971 | * @return description of what is returned |
| 972 | * |
| 973 | */ |
| 974 | function eventfinder_validate_contact($edit, $arg1) { |
| 975 | global $user; |
| 976 | $reg_check = FALSE; |
| 977 | $node->type = 'contact_manager'; |
| 978 | $node->mail = $arg1; |
| 979 | $node->source = variable_get('ef_contact_source', ''); |
| 980 | $form = _contact_manager_get_form(); |
| 981 | foreach ($form->fields as $field) { |
| 982 | $node->{$field->name} = $edit[$field->name]; |
| 983 | } |
| 984 | if(valid_email_address($node->mail)){ |
| 985 | contact_manager_validate($node, FALSE); |
| 986 | } else { |
| 987 | contact_manager_validate($node); |
| 988 | } |
| 989 | return $node; |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * |
| 994 | * Creates a new contact in the database |
| 995 | * |
| 996 | * @ingroup ef_core |
| 997 | * @param $mail the email address to register |
| 998 | * @return new contact id |
| 999 | * |
| 1000 | */ |
| 1001 | function eventfinder_save_contact_info ($mail) { |
| 1002 | global $user; |
| 1003 | $reg_check = FALSE; |
| 1004 | $node->type = 'contact_manager'; |
| 1005 | $node->mail = $mail; |
| 1006 | $node->source = variable_get('ef_contact_source', ''); |
| 1007 | $form = _contact_manager_get_form(); |
| 1008 | foreach ($form->fields as $field) { |
| 1009 | $node->{$field->name} = $edit[$field->name]; |
| 1010 | } |
| 1011 | // need to check what was returned from contact_manager_validate and handle failure... |
| 1012 | // probably can check session to find errors |
| 1013 | contact_manager_validate($node); |
| 1014 | if (count(form_get_errors()) > 0) { |
| 1015 | drupal_set_message(t('The information you provided is invalid, please correct it below.')); |
| 1016 | } else { |
| 1017 | $new_nid = node_save($node); |
| 1018 | if ($new_nid) { |
| 1019 | drupal_set_message('You are now registered for this event.'); |
| 1020 | $reg_check = TRUE; |
| 1021 | } else { |
| 1022 | drupal_set_message('There was a problem with your registration. Please ensure the form is filled out completely to proceed with registration.', 'error'); |
| 1023 | } |
| 1024 | } |
| 1025 | return $reg_check; |