'markup', '#value' => t('

Custom Field Settings


'), ); $default_value = variable_get('civitest_primary_email',''); $form['civitest_primary_email'] = array( '#type' => 'textfield', '#title' => t('Name of the main email field'), '#default_value' => $default_value, '#size' => 20, '#maxlength' => 255, '#description' => t('The name of the main email field') ); $default_value = variable_get('civitest_volunteer_fieldname',''); $form['civitest_volunteer_fieldname'] = array( '#type' => 'textfield', '#title' => t('Name of the CiviCrm Volunteer Sign-Up Field'), '#default_value' => $default_value, '#size' => 20, '#maxlength' => 255, '#description' => t('This is the name of the custom data field in civicrm that is being used to flag to indicate whether or not the contact wants to volunteer for UAS.' ) ); // form processor settings $form['CCRM_form_processor_field_name_heading'] = array( '#type' => 'markup', '#value' => t('

Form Processor Settings


'), ); $default_value = variable_get('CCRM_form_processor_field_name',''); $form['CCRM_form_processor_field_name'] = array( '#type' => 'textfield', '#title' => t('CCRM Form Processor Field Name'), '#default_value' => $default_value, '#size' => 20, '#maxlength' => 255, '#description' => t('This is the name of the hidden field that is placed in the civicrm profile forms. This field holds the name of the callback that is executed whenever a profile form is submitted.'), ); ######################### ### General Request Email ######################### # From Name # From Email # To Email (comma delimited list) # Subject # Message $form['civitest_general_request_email_heading'] = array( '#type' => 'markup', '#value' => t('

General Request Email Settings


'), ); $form['civitest_general_request_email_from_name'] = array( '#type' => 'textfield', '#title' => t('From Name (General Request)'), '#default_value' => variable_get('civitest_general_request_email_from_name', 'UAS-NO-REPLY'), '#size' => 20, '#maxlength' => 255, '#description' => t('This might be UAS-NO-REPLY or whatever'), ); $form['civitest_general_request_email_from_email'] = array( '#type' => 'textfield', '#title' => t('From Email (General Request)'), '#default_value' => variable_get('civitest_general_request_email_from_email', 'uas-no-reply@uas.coop'), '#size' => 20, '#maxlength' => 255, '#description' => t('The email address that will appear in the from field'), ); $form['civitest_general_request_email_to_email'] = array( '#type' => 'textfield', '#title' => t('To Email (General Request)'), '#default_value' => variable_get('civitest_general_request_email_to_email', 'uas-no-reply@uas.coop'), '#size' => 20, '#maxlength' => 255, '#description' => t('A comma delimited list of email addresses that will receive an email upon submission.'), ); $form['civitest_general_request_email_subject'] = array( '#type' => 'textfield', '#title' => t('Subject (General Request)'), '#default_value' => variable_get('civitest_general_request_email_subject', 'enter a subject'), '#size' => 20, '#maxlength' => 255, '#description' => t('The subject of the email'), ); $form['civitest_general_request_email_message'] = array( '#type' => 'textarea', '#title' => t('Message (General Request)'), '#default_value' => variable_get('civitest_general_request_email_message', 'default message'), '#maxlength' => 255, '#description' => t('The message the email recipients will receive'), ); ######################### ### Volunteer Email ######################### # From Name # From Email # To Email (comma delimited list) # Subject # Message $form['civitest_volunteer_email_heading'] = array( '#type' => 'markup', '#value' => t('

Volunteer Email Settings


'), ); $form['civitest_volunteer_email_from_name'] = array( '#type' => 'textfield', '#title' => t('From Name (Volunteer)'), '#default_value' => variable_get('civitest_volunteer_email_from_name', 'UAS-NO_REPLY'), '#size' => 20, '#maxlength' => 255, '#description' => t('This might be UAS-NO-REPLY or whatever'), ); $form['civitest_volunteer_email_from_email'] = array( '#type' => 'textfield', '#title' => t('From Email (Volunteer)'), '#default_value' => variable_get('civitest_volunteer_email_from_email', 'uas-no-reply@uas.coop'), '#size' => 20, '#maxlength' => 255, '#description' => t('The email address that will appear in the from field'), ); $form['civitest_volunteer_email_to_email'] = array( '#type' => 'textfield', '#title' => t('To Email (Volunteer)'), '#default_value' => variable_get('civitest_volunteer_email_to_email', 'uas-no-reply@uas.coop'), '#size' => 20, '#maxlength' => 255, '#description' => t('A comma delimited list of email addresses that will receive an email upon submission.'), ); $form['civitest_volunteer_email_subject'] = array( '#type' => 'textfield', '#title' => t('Subject (Volunteer)'), '#default_value' => variable_get('civitest_volunteer_email_subject', 'enter a subject'), '#size' => 20, '#maxlength' => 255, '#description' => t('The subject of the email'), ); $form['civitest_volunteer_email_message'] = array( '#type' => 'textarea', '#title' => t('Message (Volunteer)'), '#default_value' => variable_get('civitest_volunteer_email_message', 'default message'), '#maxlength' => 255, '#description' => t('The message the email recipients will receive'), ); return $form; } function civitest_civicrm_post( $op, $objectName, $objectId, &$objectRef ) { $handler = CCRM_get_post_handler(); if($handler && function_exists($handler)){ call_user_func($handler, $op, $objectName, $objectId, $objectRef); } } function CCRM_get_post_handler(){ $fieldname = variable_get('CCRM_form_processor_field_name',''); $handler = false; if(($fieldname && isset($_POST[$fieldname]))){ $handler = $_POST[$fieldname]; } return $handler; } function CCRM_clear_post_handler(){ // unset the flag that caused us to be caled as we only want to do this processing one time. // this is really kinda kludgy and i hope that i come up with a better way to do this $CCRM_form_processor_field_name = variable_get('CCRM_form_processor_field_name',''); unset($_POST[$CCRM_form_processor_field_name]); } function CCRM_newsletter_signup_handler($op, $objectName, $objectId, &$objectRef){ civicrm_initialize( true ); if ( $objectName != 'Profile' || ( $op != 'create' && $op != 'edit' ) ) { return; } $email_field_name = variable_get('civitest_primary_email',''); $contact_email = $objectRef[$email_field_name]; newsletter_add_user_to_list($contact_email); newsletter_set_flag_for_contact($contact_email,true); newsletter_send_thank_you_email($contact_email); drupal_set_message( variable_get( 'newsletter_signup_thank_you_msg', t("You were added to the UAS Newsletter email list. Thank you for your interest! Unite!") ) ); CCRM_clear_post_handler(); } function CCRM_getting_to_know_form_handler($op, $objectName, $objectId, &$objectRef){ civicrm_initialize( true ); if ( $objectName != 'Profile' || ( $op != 'create' && $op != 'edit' ) ) { return; } global $user; // get the contact that is associated with this drupal user $contact = get_civicrm_contact_object_via_drupal_id($user->uid); // return if we could not acquire a contact object if(is_a('CRM_Core_Error',$contact)){ drupal_set_message("could not fetch object".print_r($contact,true),'error'); return; } else { // the only thing we are doing at the moment is checking the newsletter subscription property // and either adding or removing the user from the appropriate group $msg = ''; $newsletter_signup_fieldname = variable_get('newsletter_signup_fieldname',''); if(!isset($objectRef[$newsletter_signup_fieldname]) || ( isset($objectRef[$newsletter_signup_fieldname]) && $objectRef[$newsletter_signup_fieldname] == 0 ) ){ newsletter_remove_user_from_list($contact); $msg = t("You were removed from the UAS Newsletter email list. Unite!"); } else if((isset($objectRef[$newsletter_signup_fieldname]) && $objectRef[$newsletter_signup_fieldname] == 1 )){ newsletter_add_user_to_list($contact); $msg = t("You were added to the UAS Newsletter email list. Thank you for your interest! Unite!"); } drupal_set_message($msg); CCRM_clear_post_handler(); } } function &volunteer_set_flag_for_contact($contact,$flag){ $contact = _resolve2contact($contact); $field = variable_get('civitest_volunteer_fieldname',''); $params = array($field => $flag); $contact = crm_update_contact(&$contact, $params); if ( !is_a( $contact, 'CRM_Contact_BAO_Contact' ) ) { $newsletter_admin_email = variable_get('newsletter_admin_email',''); drupal_set_message('could not update contact. please contact the site admin at admin@uas.coop','error'); } return $contact; } function CCRM_volunteer_form_handle($op, $objectName, $objectId, &$objectRef){ civicrm_initialize( true ); if ( $objectName != 'Profile' || ( $op != 'create' && $op != 'edit' ) ) { return; } require_once 'CRM/Utils/Mail.php'; civitest_send_general_request_email($objectRef); civitest_send_volunteer_email($objectRef); $newsletter_signup_fieldname = variable_get('newsletter_signup_fieldname',''); if($newsletter_signup_fieldname && $objectRef[$newsletter_signup_fieldname]){ CCRM_newsletter_signup_handler($op, $objectName, $objectId, $objectRef); } $email_field_name = variable_get('civitest_primary_email',''); $contact_email = $objectRef[$email_field_name]; volunteer_set_flag_for_contact($contact_email,true); CCRM_clear_post_handler(); } function civitest_send_general_request_email(&$objectRef){ $toEmail = variable_get('civitest_general_request_email_to_email',''); $subject = variable_get('civitest_general_request_email_subject',''); $fromName = variable_get('civitest_general_request_email_from_name',''); $fromEmail = variable_get('civitest_general_request_email_from_email',''); $from = CRM_Utils_Mail::encodeAddressHeader( $fromName, $fromEmail ); $from = "From: $from\r\n"; $params = print_r( $objectRef, true ); $message = variable_get('civitest_general_request_email_message','')."\n\n$params"; mail($toEmail,$subject,$message, $from); } function civitest_send_volunteer_email(&$objectRef){ $toEmail = variable_get('civitest_volunteer_email_to_email',''); $subject = variable_get('civitest_volunteer_email_subject',''); $fromName = variable_get('civitest_volunteer_email_from_name',''); $fromEmail = variable_get('civitest_volunteer_email_from_email',''); $from = CRM_Utils_Mail::encodeAddressHeader( $fromName, $fromEmail ); $from = "From: $from\r\n"; $params = print_r( $objectRef, true ); $message = variable_get('civitest_volunteer_email_message','')."\n\n$params"; mail($toEmail,$subject,$message, $from); } ?>