Commit 669fc727 authored by Jamie McClelland's avatar Jamie McClelland

add new fields to forms, ensure everything is properly saved.

parent ca7e63e7
......@@ -9,6 +9,7 @@ class CRM_Petitionemail_Upgrader extends CRM_Petitionemail_Upgrader_Base {
/**
* Create civicrm_petition_email table during install
*
*
*/
public function install() {
// Nothing to do. All *_install.sql files installed automatically.
......@@ -24,25 +25,29 @@ class CRM_Petitionemail_Upgrader extends CRM_Petitionemail_Upgrader_Base {
/**
* Add new fields and table allowing for dynamic targets to be selected.
*
*
*/
function upgrade_1001() {
// First create the two new tables
if(!$this->executeSqlFile('sql/Petitionemail_target_install.sql')) return FALSE;
// First create the new table
if(!$this->executeSqlFile('sql/Petitionemail_matching_field_install.sql')) return FALSE;
// Now add the new recipient field
$sql = "ALTER TABLE civicrm_petition_email ADD COLUMN `recipients` text COMMENT 'The name and email address of additional targets that should receive a copy of all petitions signed, separated by line breaks.'";
$dao = CRM_Core_DAO::executeQuery($sql);
// Now transfer the data to the new tables
$sql = "SELECT petition_id, recipient_email, recipient_name FROM civicrm_petition_email";
$dao = CRM_Core_DAO::executeQuery($sql);
while($dao->fetch()) {
$target = '"' . $dao->recipient_name . '" <' . $dao->recipient_email . '>';
$sql = "INSERT INTO civicrm_petition_email_target SET petition_id = %0, target = %1";
$sql = "UPDATE civicrm_petition_email_target SET petition_id = %0, recipients = %1";
$params = array(
0 => array($dao->petition_id, 'Integer'),
1 => array($target, 'String')
);
CRM_Core_DAO::executeQuery($sql, $params);
}
// Now drop/add fields.
if(!$this->executeSqlFile('sql/Petitionemail_1001_upgrade.sql')) return FALSE;
return TRUE;
}
......
cj(document).ready( function() {
showHideEmailPetition();
checkProfileIncludesMessage();
cj("input#email_petition").click( function() { showHideEmailPetition(); });
cj("#profile_id").change( function() { checkProfileIncludesMessage(); });
cj("#user_message").change( function() { checkProfileIncludesMessage(); });
});
function checkProfileIncludesMessage() {
cj("#profileMissingMessage").remove();
var actProfile = cj("#profile_id").val();
cj().crmAPI("UFField","get",{ "sequential" :"1", "uf_group_id" : actProfile },{ success:function (data){
var msgField = cj("#user_message").val();
if (msgField) {
var fieldinfo = cj.inArray(msgField, data["values"])
var matchfield = false;
cj.each(data["values"], function(key, value) {
if (value["field_name"] == "custom_"+msgField) {
matchfield = true;
return true;
}
});
if (!matchfield) {
cj("#user_message").after("<div id='profileMissingMessage' style='background-color: #FF9999; border: 1px solid #CC3333; display: inline-block; font-size: 85%; margin-left: 1ex; padding: 0.5ex; vertical-align: top;'>" + ts("This field is not in the activity profile you selected") + "</div>");
}
}
}
});
}
function showHideEmailPetition() {
if( cj("input#email_petition").attr("checked") ) {
cj("tr.crm-campaign-survey-form-block-recipient").show("fast");
cj("tr.crm-campaign-survey-form-block-recipient_name").show("fast");
cj("tr.crm-campaign-survey-form-block-user_message").show("fast");
cj("tr.crm-campaign-survey-form-block-default_message").show("fast");
cj("tr.crm-campaign-survey-form-block-subjectline").show("fast");
} else {
cj("tr.crm-campaign-survey-form-block-recipient").hide("fast");
cj("tr.crm-campaign-survey-form-block-recipient_name").hide("fast");
cj("tr.crm-campaign-survey-form-block-user_message").hide("fast");
cj("tr.crm-campaign-survey-form-block-default_message").hide("fast");
cj("tr.crm-campaign-survey-form-block-subjectline").hide("fast");
}
}
This diff is collapsed.
......@@ -9,6 +9,9 @@ CREATE TABLE IF NOT EXISTS `civicrm_petition_email` (
`default_message` text COMMENT 'The default message for the petition',
`message_field` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The ID of the custom field used for petition messages.',
`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.',
PRIMARY KEY (`petition_id`),
KEY `petition_id` (`petition_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores recipient and message information for petitions.';
--
-- Table structure for table `civicrm_petition_email_target`
--
CREATE TABLE IF NOT EXISTS `civicrm_petition_email_target` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The unique ID of the target.',
`petition_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The SID of the petition.',
`target` varchar(255) COMMENT 'The name and email address of additional targets that should receive a copy of all petitions signed.',
PRIMARY KEY (`id`),
KEY `petition_id` (`petition_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores the additional targets that should receive a copy of all petitions signed.';
DROP TABLE IF EXISTS `civicrm_petition_email`;
DROP TABLE IF EXISTS `civicrm_petition_email_matching_field`;
DROP TABLE IF EXISTS `civicrm_petition_email_target`;
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