Commit cae35899 authored by Stan Dragnev's avatar Stan Dragnev Committed by Monish Deb

refs #202: add a from email option

parent adf8e189
......@@ -116,6 +116,12 @@ class CRM_Grant_DAO_GrantProgram extends CRM_Core_DAO
* @var float
*/
public $remainder_amount;
/**
* FROM identity default for grant program;
*
* @var string
*/
public $from_email_address;
/**
* Financial Type ID
*
......@@ -272,6 +278,13 @@ class CRM_Grant_DAO_GrantProgram extends CRM_Core_DAO
'dataPattern' => '/^\d+(\.\d{2})?$/',
'export' => true,
) ,
'from_email_address' => array(
'name' => 'from_email_address',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('FROM Email Address') ,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
) ,
'financial_type_id' => array(
'name' => 'financial_type_id',
'type' => CRM_Utils_Type::T_INT,
......
......@@ -128,7 +128,12 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$this->add('text', 'remainder_amount', ts('Remainder Amount'),
$attributes['remainder_amount'], FALSE);
$this->addRule('remainder_amount', ts('Please enter a valid amount.'), 'money');
$this->addRule('remainder_amount', ts('Please enter a valid amount.'), 'money');
$this->registerRule('from_identity', 'callback', '_validateIdentity', 'CRM_Grant_Form_GrantProgram');
$this->add('text', 'from_email_address', ts('FROM Email Address'),
$attributes['from_email_address'], FALSE);
$this->addRule('from_email_address', ts('Please follow the proper format for From Email Address'), 'from_identity');
$contributionTypes = CRM_Grant_BAO_GrantProgram::contributionTypes();
$this->add('select', 'financial_type_id', ts('Financial Types'),
......@@ -179,6 +184,7 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
}
$values = $this->controller->exportValues($this->_name);
$values['from_email_address'] = $_POST['from_email_address']; // avoid QuickForm's safe value for this field
$domainID = CRM_Core_Config::domainID();
$result = $this->updateGrantProgram($values, $domainID);
......@@ -203,6 +209,7 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$dao->grant_type_id = $values['grant_type_id'];
$dao->total_amount = $values['total_amount'];
$dao->remainder_amount = $values['remainder_amount'];
$dao->from_email_address = str_replace('"<', '" <', $values['from_email_address']); // apparently we need a space
$dao->financial_type_id = $values['financial_type_id'];
$dao->status_id = CRM_Grant_BAO_GrantProgram::getOptionValueID(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup','grant_program_status','id','name'), $values['status_id']);
$dao->allocation_date = CRM_Utils_Date::processDate($values['allocation_date']);
......@@ -212,6 +219,26 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$dao->grant_program_id = $values['grant_program_id'];
return $dao->save();
}
/**
* Validate FROM identity.
*
* @param $data
* @return bool
*/
static function _validateIdentity($data) {
$formEmail = CRM_Utils_Mail::pluckEmailFromHeader($data);
if (!CRM_Utils_Rule::email($formEmail)) {
return false;
}
$formName = explode('"', $data);
if (empty($formName[1]) || count($formName) != 3) {
return false;
}
return true;
}
}
......@@ -58,11 +58,11 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$this->assign('contributionType', $contributionTypes[$values['financial_type_id']] );
$this->assign('grantProgramAlgorithm', CRM_Grant_BAO_GrantProgram::getOptionName( $values['allocation_algorithm']));
$this->assign('grant_program_id', empty($grantPrograms[$values['grant_program_id']]) ? NULL : $grantPrograms[$values['grant_program_id']]);
$grantTokens = array('label','name','total_amount',
$grantTokens = array('label','name','total_amount','from_email_address',
'remainder_amount', 'allocation_date', 'is_active', 'is_auto_email');
foreach ($grantTokens as $token) {
$this->assign($token, CRM_Utils_Array::value($token, $values));
$this->assign($token, htmlspecialchars(CRM_Utils_Array::value($token, $values)));
}
$this->assign('id', $this->_id);
}
......
......@@ -8,6 +8,17 @@ class CRM_Grantprograms_Upgrader extends CRM_Grantprograms_Upgrader_Base {
// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).
/**
* Add from_email column to grant program table to allow
*
* @return bool
*/
public function upgrade_4601() {
$this->ctx->log->info('Applying update 4601');
CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_grant_program ADD COLUMN from_email_address VARCHAR(255)');
return TRUE;
}
/**
* Example: Run an external SQL script when the module is installed
*
......
......@@ -47,6 +47,12 @@
<td class="label">{$form.remainder_amount.label}</td>
<td class="html-adjust">{$form.remainder_amount.html}</td>
</tr>
<tr class="crm-grant_program-form-block-from_email_address">
<td class="label">{$form.from_email_address.label}</td>
<td class="html-adjust">{$form.from_email_address.html}<br />
<span class="description">{ts}Include double-quotes (&quot;) around the name and angle-brackets (&lt; &gt;) around the email address.<br />EXAMPLE: <em>&quot;Client Services&quot; &lt;clientservices@example.org&gt;</em>{/ts}<span>
</td>
</tr>
<tr class="crm-grant_program-form-block-contribution_type_id">
<td class="label">{$form.financial_type_id.label}</td>
<td class="html-adjust">{$form.financial_type_id.html}</td>
......
......@@ -54,6 +54,8 @@
<tr class="crm-grant-program-view-form-block-grant_type_id"><td class="label">{ts}Grant Type{/ts}</td> <td>{$grantType}</td></tr>
<tr class="crm-grant-program-view-form-block-total_amount"><td class="label">{ts}Total Amount{/ts}</td> <td>{$total_amount|crmMoney}</td></tr>
<tr class="crm-grant-program-view-form-block-remainder_amount"><td class="label">{ts}Remainder Amount{/ts}</td> <td>{$remainder_amount|crmMoney}</td></tr>
<tr class="crm-grant-program-view-form-block-from_email_address"><td class="label">{ts}FROM Email Address{/ts}</td>
<td>{$from_email_address}</td></tr>
<tr class="crm-grant-program-view-form-block-contribution_type_id"><td class="label">{ts}Contribution Type{/ts}</td> <td>{$contributionType}</td></tr>
<tr class="crm-grant-program-view-form-block-status_id"><td class="label">{ts}Grant Status{/ts}</td> <td>{$grantProgramStatus}</td></tr>
<tr class="crm-grant-program-view-form-block-allocation_algorithm"><td class="label">{ts}Allocation Algorithm{/ts}</td> <td>{$grantProgramAlgorithm}</td></tr>
......
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