Commit 9c59ab0e authored by Jamie McClelland's avatar Jamie McClelland

adding ability to modify subject line.

parent 22a965a6
...@@ -51,4 +51,13 @@ class CRM_Petitionemail_Upgrader extends CRM_Petitionemail_Upgrader_Base { ...@@ -51,4 +51,13 @@ class CRM_Petitionemail_Upgrader extends CRM_Petitionemail_Upgrader_Base {
if(!$this->executeSqlFile('sql/Petitionemail_1001_upgrade.sql')) return FALSE; if(!$this->executeSqlFile('sql/Petitionemail_1001_upgrade.sql')) return FALSE;
return TRUE; return TRUE;
} }
/**
* Add field to allow user to specify custom subject line.
*/
function upgrade_1002() {
if(!$this->executeSqlFile('sql/Petitionemail_1002_upgrade.sql')) return FALSE;
return TRUE;
}
} }
cj(document).ready( function() { cj(document).ready( function() {
showHideEmailPetition(); showHideEmailPetition();
populateUserMessageFieldOptions(); populateUserFieldOptions();
cj("input#email_petition").click( function() { showHideEmailPetition(); }); cj("input#email_petition").click( function() { showHideEmailPetition(); });
cj("#profile_id").change( function() { populateUserMessageFieldOptions(); }); cj("#profile_id").change( function() { populateUserFieldOptions(); });
}); });
function populateUserMessageFieldOptions() { function populateUserFieldOptions() {
var actProfile = cj("#profile_id").val(); var actProfile = cj("#profile_id").val();
var selected = cj('#message_field').val(); var selected_message = cj('#message_field').val();
var selected_subject = cj('#subject_field').val();
var options = {}; var options = {};
cj('#message_field').empty(); cj('#message_field').empty();
cj('#subject_field').empty();
if(actProfile) { if(actProfile) {
CRM.api("UFField","get",{ "uf_group_id" : actProfile },{ success:function (data) { CRM.api("UFField","get",{ "uf_group_id" : actProfile },{ success:function (data) {
if(data['is_error'] == 0) { if(data['is_error'] == 0) {
cj('#message_field').append('<option value="">--Choose one--</option>'); cj('#message_field').append('<option value="">--Choose one--</option>');
cj('#subject_field').append('<option value="">--Choose one--</option>');
cj.each(data["values"], function(key, value) { cj.each(data["values"], function(key, value) {
cj('#message_field').append('<option value="' + value['field_name'] + '">' + value['label'] + '</option>'); cj('#message_field').append('<option value="' + value['field_name'] + '">' + value['label'] + '</option>');
cj('#subject_field').append('<option value="' + value['field_name'] + '">' + value['label'] + '</option>');
}); });
cj('#message_field').val(selected); cj('#message_field').val(selected_message);
cj('#subject_field').val(selected_subject);
} }
}}); }});
} }
......
...@@ -88,7 +88,9 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) { ...@@ -88,7 +88,9 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) {
if ($survey_id) { if ($survey_id) {
$sql = "SELECT petition_id, $sql = "SELECT petition_id,
default_message, default_message,
subject,
message_field, message_field,
subject_field,
subject subject
FROM civicrm_petition_email FROM civicrm_petition_email
WHERE petition_id = %1"; WHERE petition_id = %1";
...@@ -101,7 +103,9 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) { ...@@ -101,7 +103,9 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) {
return; return;
} }
$message_field = $dao->message_field; $message_field = $dao->message_field;
$subject_field = $dao->subject_field;
$defaults[$message_field] = $dao->default_message; $defaults[$message_field] = $dao->default_message;
$defaults[$subject_field] = $dao->subject;
$form->setDefaults($defaults); $form->setDefaults($defaults);
} }
} }
...@@ -114,6 +118,7 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) { ...@@ -114,6 +118,7 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) {
$sql = "SELECT petition_id, $sql = "SELECT petition_id,
default_message, default_message,
message_field, message_field,
subject_field,
subject, subject,
recipients, recipients,
location_type_id location_type_id
...@@ -128,6 +133,7 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) { ...@@ -128,6 +133,7 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) {
$defaults['recipients'] = $dao->recipients; $defaults['recipients'] = $dao->recipients;
$defaults['default_message'] = $dao->default_message; $defaults['default_message'] = $dao->default_message;
$defaults['message_field'] = $dao->message_field; $defaults['message_field'] = $dao->message_field;
$defaults['subject_field'] = $dao->subject_field;
$defaults['subject'] = $dao->subject; $defaults['subject'] = $dao->subject;
$defaults['location_type_id'] = $dao->location_type_id; $defaults['location_type_id'] = $dao->location_type_id;
...@@ -176,17 +182,17 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) { ...@@ -176,17 +182,17 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) {
$profile_ids[] = $join_value['uf_group_id']; $profile_ids[] = $join_value['uf_group_id'];
} }
} }
$custom_fields = petitionemail_get_textarea_fields($profile_ids); $custom_fields = petitionemail_get_text_fields($profile_ids);
$custom_message_field_options = array(); $custom_field_options = array();
if(count($custom_fields) == 0) { if(count($custom_fields) == 0) {
$custom_message_field_options = array( $custom_field_options = array(
'' => t('- No Text or TextArea fields defined in your profiles -') '' => t('- No Text or TextArea fields defined in your profiles -')
); );
} }
else { else {
$custom_message_field_options = array('' => t('- Select -')); $custom_field_options = array('' => t('- Select -'));
$custom_message_field_options = $custom_message_field_options + $custom_fields; $custom_field_options = $custom_field_options + $custom_fields;
} }
$choose_one = array('0' => ts('--choose one--')); $choose_one = array('0' => ts('--choose one--'));
$group_options = $choose_one + CRM_Core_PseudoConstant::group('Mailing'); $group_options = $choose_one + CRM_Core_PseudoConstant::group('Mailing');
...@@ -219,9 +225,11 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) { ...@@ -219,9 +225,11 @@ function petitionemail_civicrm_buildForm( $formName, &$form ) {
$form->add('select', 'location_type_id', ts('Email'), $location_options); $form->add('select', 'location_type_id', ts('Email'), $location_options);
$form->add('textarea', 'recipients', ts("Send petitions to")); $form->add('textarea', 'recipients', ts("Send petitions to"));
$form->add('select', 'message_field', ts('Custom Message Field'), $form->add('select', 'message_field', ts('Custom Message Field'),
$custom_message_field_options); $custom_field_options);
$form->add('select', 'subject_field', ts('Custom Subject Field'),
$custom_field_options);
$form->add('textarea', 'default_message', ts('Default Message'), 'rows=20'); $form->add('textarea', 'default_message', ts('Default Message'), 'rows=20');
$form->add('text', 'subject', ts('Email Subject Line'), array('size' => 70)); $form->add('text', 'subject', ts('Default Email Subject Line'), array('size' => 70));
$form->add('textarea', 'links', ts('Links to sign the petition'), 'rows=5')->freeze(); $form->add('textarea', 'links', ts('Links to sign the petition'), 'rows=5')->freeze();
...@@ -371,7 +379,7 @@ function petitionemail_civicrm_validateForm($formName, &$fields, &$files, &$form ...@@ -371,7 +379,7 @@ function petitionemail_civicrm_validateForm($formName, &$fields, &$files, &$form
/** /**
* Given an array of profile ids, list all text area fields * Given an array of profile ids, list all text area fields
*/ */
function petitionemail_get_textarea_fields($profile_ids) { function petitionemail_get_text_fields($profile_ids) {
// Now get all fields in this profile // Now get all fields in this profile
$custom_fields = array(); $custom_fields = array();
while(list(,$uf_group_id) = each($profile_ids)) { while(list(,$uf_group_id) = each($profile_ids)) {
...@@ -435,6 +443,7 @@ function petitionemail_civicrm_postProcess( $formName, &$form ) { ...@@ -435,6 +443,7 @@ function petitionemail_civicrm_postProcess( $formName, &$form ) {
$default_message = $form->_submitValues['default_message']; $default_message = $form->_submitValues['default_message'];
$message_field = $form->_submitValues['message_field']; $message_field = $form->_submitValues['message_field'];
$subject_field = $form->_submitValues['subject_field'];
$subject = $form->_submitValues['subject']; $subject = $form->_submitValues['subject'];
$recipients = $form->_submitValues['recipients']; $recipients = $form->_submitValues['recipients'];
$location_type_id = $form->_submitValues['location_type_id']; $location_type_id = $form->_submitValues['location_type_id'];
...@@ -443,6 +452,7 @@ function petitionemail_civicrm_postProcess( $formName, &$form ) { ...@@ -443,6 +452,7 @@ function petitionemail_civicrm_postProcess( $formName, &$form ) {
petition_id, petition_id,
default_message, default_message,
message_field, message_field,
subject_field,
subject, subject,
recipients, recipients,
location_type_id location_type_id
...@@ -452,15 +462,17 @@ function petitionemail_civicrm_postProcess( $formName, &$form ) { ...@@ -452,15 +462,17 @@ function petitionemail_civicrm_postProcess( $formName, &$form ) {
%3, %3,
%4, %4,
%5, %5,
%6 %6,
%7
)"; )";
$params = array( $params = array(
1 => array( $survey_id, 'Integer' ), 1 => array( $survey_id, 'Integer' ),
2 => array( $default_message, 'String' ), 2 => array( $default_message, 'String' ),
3 => array( $message_field, 'String' ), 3 => array( $message_field, 'String' ),
4 => array( $subject, 'String' ), 4 => array( $subject_field, 'String' ),
5 => array( $recipients, 'String' ), 5 => array( $subject, 'String' ),
6 => array( $location_type_id, 'Integer' ), 6 => array( $recipients, 'String' ),
7 => array( $location_type_id, 'Integer' ),
); );
$petitionemail = CRM_Core_DAO::executeQuery( $sql, $params ); $petitionemail = CRM_Core_DAO::executeQuery( $sql, $params );
...@@ -532,6 +544,7 @@ function petitionemail_get_petition_details($petition_id) { ...@@ -532,6 +544,7 @@ function petitionemail_get_petition_details($petition_id) {
$ret = array(); $ret = array();
$sql = "SELECT default_message, $sql = "SELECT default_message,
message_field, message_field,
subject_field,
subject, subject,
location_type_id, location_type_id,
recipients recipients
...@@ -550,6 +563,7 @@ function petitionemail_get_petition_details($petition_id) { ...@@ -550,6 +563,7 @@ function petitionemail_get_petition_details($petition_id) {
$ret['subject'] = $petition_email->subject; $ret['subject'] = $petition_email->subject;
$ret['location_type_id'] = $petition_email->location_type_id; $ret['location_type_id'] = $petition_email->location_type_id;
$ret['message_field'] = $petition_email->message_field; $ret['message_field'] = $petition_email->message_field;
$ret['subject_field'] = $petition_email->subject_field;
$ret['recipients'] = $petition_email->recipients; $ret['recipients'] = $petition_email->recipients;
// Now retrieve the matching fields, if any // Now retrieve the matching fields, if any
...@@ -577,27 +591,46 @@ function petitionemail_process_signature($activity_id) { ...@@ -577,27 +591,46 @@ function petitionemail_process_signature($activity_id) {
return; return;
} }
$default_message = $petition_vars['default_message']; $default_message = $petition_vars['default_message'];
$subject = $petition_vars['subject']; $default_subject = $petition_vars['subject'];
$message_field = $petition_vars['message_field']; $message_field = $petition_vars['message_field'];
$subject_field = $petition_vars['subject_field'];
// Figure out whether to use the user-supplied message or the default // Figure out whether to use the user-supplied message/subject or the default
// message. // message/subject.
$petition_message = NULL; $petition_message = NULL;
$subject = NULL;
// If the petition has specified a message field // If the petition has specified a message field
if(!empty($message_field)) { if(!empty($message_field)) {
// Retrieve the value of the field for this activity // Retrieve the value of the field for this activity
$params = array('id' => $activity_id, $params = array(
'return' => array($message_field, 'activity_type_id')); 'id' => $activity_id,
'return' => $message_field
);
$result = civicrm_api3('Activity', 'getsingle', $params); $result = civicrm_api3('Activity', 'getsingle', $params);
if(!empty($result[$message_field])) { if(!empty($result[$message_field])) {
$petition_message = $result[$message_field]; $petition_message = $result[$message_field];
} }
} }
// If the petition has specified a subject field
// No user supplied message, use the default if(!empty($subject_field)) {
// Retrieve the value of the field for this activity
$params = array(
'id' => $activity_id,
'return' => $subject_field
);
$result = civicrm_api3('Activity', 'getsingle', $params);
if(!empty($result[$subject_field])) {
$subject = $result[$subject_field];
}
}
// No user supplied message/subject, use the default
if(is_null($petition_message)) { if(is_null($petition_message)) {
$petition_message = $default_message; $petition_message = $default_message;
} }
if(is_null($subject)) {
$subject = $default_subject;
}
$activity = civicrm_api3("Activity", "getsingle", array ('id' => $activity_id)); $activity = civicrm_api3("Activity", "getsingle", array ('id' => $activity_id));
$contact_id = $activity['source_contact_id']; $contact_id = $activity['source_contact_id'];
$contact = civicrm_api3("Contact", "getsingle", array ('id' => $contact_id)); $contact = civicrm_api3("Contact", "getsingle", array ('id' => $contact_id));
......
--
-- SQL statements to handle the 1002 upgrade
ALTER TABLE civicrm_petition_email ADD COLUMN `subject_field` varchar(255) DEFAULT NULL COMMENT "The custom field used to store the petition signer's personal subject." AFTER default_message;
...@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_petition_email` ( ...@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_petition_email` (
`location_type_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The location type that should be used when selecting the target email address.', `location_type_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The location type that should be used when selecting the target email address.',
`default_message` text COMMENT 'The default message for the petition', `default_message` text COMMENT 'The default message for the petition',
`message_field` varchar(128) COMMENT 'The name of the custom field used for petition messages.', `message_field` varchar(128) COMMENT 'The name of the custom field used for petition messages.',
`subject_field` varchar(255) DEFAULT NULL COMMENT "The custom field used to store the petition signer's personal subject.",
`subject` varchar(128) DEFAULT NULL COMMENT 'The subject line for outgoing emails.', `subject` varchar(128) DEFAULT NULL COMMENT 'The subject line for outgoing emails.',
`recipients` text COMMENT 'The name and email address of additional targets that should receive a copy of all petitions signed, separated by line breaks.', `recipients` text COMMENT 'The name and email address of additional targets that should receive a copy of all petitions signed, separated by line breaks.',
PRIMARY KEY (`petition_id`), PRIMARY KEY (`petition_id`),
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
<td class="view-value">{$form.subject.html} <td class="view-value">{$form.subject.html}
<div class="description">{ts}Enter the subject line that should appear in the target email.{/ts}</div></td> <div class="description">{ts}Enter the subject line that should appear in the target email.{/ts}</div></td>
</tr> </tr>
<tr class="crm-campaign-survey-form-block-subject_field">
<td class="label">{$form.subject_field.label}</td>
<td class="view-value">{$form.subject_field.html}
<div class="description">{ts}Select a field that will have the signer's custom subject line. Make sure it is included in the Activity Profile you selected.{/ts}</div></td>
</tr>
<tr class="crm-campaign-survey-form-block-default_message"> <tr class="crm-campaign-survey-form-block-default_message">
<td class="label">{$form.default_message.label}</td> <td class="label">{$form.default_message.label}</td>
<td class="view-value">{$form.default_message.html} <td class="view-value">{$form.default_message.html}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment