| Project: | volunteer |
| Version: | master |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
When I set up a CiviCRM profile with the required e-mail address, admin >> settings >> volunteer has no complaints. When I set it up another profile that uses only mailing address fields, admin >> settings >> volunteer complains that there is no profile that has the required e-mail field.
However, when I delete the second profile I make, leaving only the profile with the required e-mail field for use by volunteer module, admin >> settings >> volunteer no longer complains. I think there may be a bug in the way volunteer module detects whether or not there exists a CiviCRM profile that has the required e-mail address field.
-Ankur
Here's a copy of an e-mail I wrote that goes into further detail, if you find it helpful:
In integrating volunteer module with CiviCRM, a profile is necessary that has an e-mail field that is required, active, in the registration form, and so forth (the red print that comes out at the top of q=admin/settings/volunteer explain it). So, to this effect, I was provided with some queries to set up the volunteer profile with profile fields as well as query statements to set up the volunteer group (see below, at the end of this message).
However, when I tried to modify the installer to include queries to set up an "Address" profile for integration with location module, volunteer settings started complaining that a profile with the required e-mail field didn't exist.
I thought perhaps my queries to create the 'Address' profile were causing something funny to happen. So, when I removed those from the installer temporarily (these queries take place in the function _install_closing_queries() in install.php), volunteer module stopped complaining after the installation. [Referring to the civicspace installer: code viewable at http://trac.civicspacelabs.com/cgi-bin/trac.cgi/file/trunk/install.php ]
So I thought to myself, maybe my 'Address' profile-building queries were messing something up. So, I figured I'd just take those out of the installer, but not the Volunteer profile, then run the installer and create the 'Address' profile via the interface, do the dump, and put those queries for the 'Address' profile back into the installer. However, as soon as I created my 'Address' profile, volunteer started complaining again about there being no profile with the required e-mail address field.
Once I deleted the 'Address' profile altogether however, and just left the 'Volunteer' profile in, volunteer module settings STOPPED complaining about the lack of a profile with the required e-mail field. To note, the Address profile is set up just to record street, supplemental 1, city, state, postal, and country. My guess is that this is most likely a bug in the way volunteer module tries to detect a profile that has a required e-mail address, but I could be wrong.
-Ankur
--
-- Dumping data for table `civicrm_uf_group`
--
INSERT INTO `civicrm_uf_group` (`domain_id`, `is_active`, `form_type`, `title`, `help_pre`, `help_post`, `weight`) VALUES (1,1,NULL,'CiviCRM Volunteer Profile','','',2);
--
-- Dumping data for table `civicrm_uf_field`
--
INSERT INTO `civicrm_uf_field` (`uf_group_id`, `field_name`, `is_active`, `is_view`, `is_required`, `weight`, `help_post`, `is_registration`, `is_match`, `visibility`, `in_selector`) VALUES (1,'first_name',1,0,1,1,'',1,1
,'User and User Admin Only',1);
INSERT INTO `civicrm_uf_field` (`uf_group_id`, `field_name`, `is_active`, `is_view`, `is_required`, `weight`, `help_post`, `is_registration`, `is_match`, `visibility`, `in_selector`) VALUES (1,'last_name',1,0,1,2,'',1,1,'Public User Pages and Listings',1);
INSERT INTO `civicrm_uf_field` (`uf_group_id`, `field_name`, `is_active`, `is_view`, `is_required`, `weight`, `help_post`, `is_registration`, `is_match`, `visibility`, `in_selector`) VALUES (1,'email',1,0,1,3,'',1,1,'User and User Admin Only',1);
--
-- Dumping data for table `civicrm_custom_group`
--
INSERT INTO `civicrm_group` (`domain_id`, `name`, `title`, `description`, `source`, `saved_search_id`, `is_active`, `visibility`) VALUES (1,'Volunteer_Group','Volunteer Group','For Volunteer Module Usage',NULL,NULL,1,'User and User Admin Only');
INSERT INTO `civicrm_saved_search` (`domain_id`, `query`, `form_values`, `is_active`) VALUES (1,NULL,'a:6:{s:12:\"contact_type\";s:0:\"\";s:5:\"group\";s:0:\"\";s:3:\"tag\";s:0:\"\";s:9:\"sort_name\";s:0:\"\";s:4:\"task\";s:2:\"16\";s:8:\"radio_ts\";s:6:\"ts_all\";}',1);
INSERT INTO `civicrm_group` (`domain_id`, `name`, `title`, `description`, `source`, `saved_search_id`, `is_active`, `visibility`) VALUES (1,'All_CiviCRM_contacts','All CiviCRM contacts','foo',NULL,1,1,'User and User Admin Only');
Comments
#1
I figured out the issue. The loop that searches for a profile with the required e-mail address resets the critical variable to false on each iteration. So, if the loop discovers a profile with a valid email field, it will set the variable
$has_emailto TRUE. However, on a second iteration, if the group being checked for the valid e-mail does not have one, the variable$has_emailis set to FALSE.So, the first disovered valid profile is forgotten and the logic after the iterations are done spits out the error message to the screen that there is no profile with the required e-mail field. Another bug in the code is that we execute, in each iteration,
if ($has_email) {$forms[$id] = $title;
}
We really want the variable
$correct_emailas the condition for this IF-statement. However, we make the same mistake with this variable as well. We set it to FALSE at the beginning of each iteration in the loop where we try to find a profile with the valid e-mail.In anycase, I played around with the variable names and added an extra variable. Patch is attached.
if (module_exist('civicrm')) {civicrm_initialize(TRUE);
$contact_groups = array();
db_set_active('civicrm');
$groups = crm_get_groups(array('is_active' => 1));
db_set_active();
$group_form = '';
if (is_array($groups) && count($groups)) {
foreach ($groups as $group) {
$contact_sources[$group->id] = $group->title;
}
$group_form .= form_select (t('Add/Update contacts to CiviCRM group when volunteering'), 'volunteer_contact_source', variable_get('volunteer_contact_source',''), $contact_sources, t('Select a CiviCRM group for users to be added or updated to as contacts when volunteering for an event. You can <a href="%url">add</a> a volunteer specific group. You can later see a list of all users that volunteered by selecting the chosen group from <a href="%search">this page</a> and clicking Show Group Members.', array('%url' => url('civicrm/group/add'), '%search' => url('civicrm/group'))), 0, FALSE, TRUE);
}
else {
drupal_set_message(t('You need to <a href="%url">define</a> a CiviCRM group for use with volunteer module.', array('%url' => url('civicrm/group/add'))), 'error');
}
// CiviCRM: Get all allowed fields for 'individual' type contact.
$forms = array();
db_set_active('civicrm');
$ufGroups = crm_uf_get_profile_groups();
db_set_active();
if (is_array($ufGroups) && count($ufGroups)) {
foreach ($ufGroups as $id => $title) {
$profile = crm_uf_get_profile_fields($id, TRUE);
$has_email = FALSE;
$correct_email = FALSE;
foreach($profile as $field) {
if ($field['name'] == 'email') {
$has_email = TRUE;
if ($field['is_required'] == 1 && $field['is_match'] == 1) {
$correct_email = TRUE;
}
}
}
if ($has_email) {
$forms[$id] = $title;
}
}
if ($has_email) {
if ($correct_email) {
$group_form .= form_select(t('CiviCRM profile form for volunteers'), 'volunteer_form', variable_get('volunteer_form', ''), $forms, t('Select a CiviCRM Profile form for volunteers. Users will fill out required fields in this form when volunteering for an event. You can <a href="%url">add</a> a volunteer specific profile. The profile needs at least an email field and it needs to be set to "Required", "Display in Registration Form", "Key to Match Contacts", and "Active".', array('%url' => url('civicrm/admin/uf/group'))), 0, FALSE, TRUE);
}
else {
drupal_set_message(t('You need to <a href="%url">define</a> a CiviCRM profile for use with the volunteer module. The profile needs at least an email field and it needs to be set to "Required", "Display in Registration Form", "Key to Match Contacts", and "Active". A profile with an email field could be found, but it does not have the correct settings. ', array('%url' => url('civicrm/admin/uf/group'))), 'error');
}
}
else {
drupal_set_message(t('You need to <a href="%url">define</a> a CiviCRM profile for use with the volunteer module. The profile needs at least an email field and it needs to be set to "Required", "Display in Registration Form", "Key to Match Contacts", and "Active". No profile with an email field could be found.', array('%url' => url('civicrm/admin/uf/group'))), 'error');
}
}
else {
drupal_set_message(t('You need to <a href="%url">define</a> a CiviCRM profile for use with the volunteer module. The profile needs at least an email field and it needs to be set to "Required", "Display in Registration Form", "Key to Match Contacts", and "Active".', array('%url' => url('civicrm/admin/uf/group'))), 'error');
}
$output .= form_group(t('Contact Settings'), $group_form);
}
else {
drupal_set_message(t('You need to enable the CiviCRM module in order to use the volunteer module.'), 'error');
}
#2
Thanks, applied.
#3