Unverified Commit d96f1357 authored by Monish Deb's avatar Monish Deb Committed by GitHub
Browse files

Merge pull request #264 from JMAConsulting/4.7-dev

Merge 4.7 to master
parents f9791ee8 d4ca1665
......@@ -328,10 +328,20 @@ WHERE civicrm_contact.id = $id ";
),
'PDFFilename' => '',
);
$defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
foreach ($defaultAddress as $id => $value) {
$sendTemplateParams['from'] = $value;
$emailQuery = "SELECT from_email_address FROM civicrm_grant_program WHERE id = %1";
$defaultAddress = CRM_Core_DAO::singleValueQuery($emailQuery, array(
1 => array($values['grant_program_id'], 'Integer')
));
if (!isset($defaultAddress) || $defaultAddress == '') {
$defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
foreach ($defaultAddress as $id => $value) {
$sendTemplateParams['from'] = $value;
}
} else {
$sendTemplateParams['from'] = $defaultAddress;
}
$sendTemplateParams['toName'] = $displayName;
......
......@@ -110,6 +110,7 @@ class CRM_Grant_BAO_Query {
$query->_element['grant_type_id'] = 1;
$query->_element['grant_status_id'] = 1;
$query->_tables['civicrm_grant'] = 1;
$query->_tables['civicrm_payment'] = 1;
$query->_whereTables['civicrm_grant'] = 1;
}
}
......@@ -297,7 +298,7 @@ class CRM_Grant_BAO_Query {
}
$from .= "$side JOIN civicrm_entity_payment AS temp1 ON (civicrm_grant.id = temp1.entity_id AND temp1.entity_table = 'civicrm_grant')
$side JOIN (SELECT payment_id AS payment_id, entity_id AS entity_id FROM civicrm_entity_payment ORDER BY payment_id DESC) AS temp2 ON temp1.entity_id = temp2.entity_id
$side JOIN civicrm_payment ON (temp2.payment_id = civicrm_payment.id)";
$side JOIN civicrm_payment civicrm_payment2 ON (temp2.payment_id = civicrm_payment2.id)";
break;
......@@ -312,6 +313,11 @@ $side JOIN civicrm_payment ON (temp2.payment_id = civicrm_payment.id)";
case 'grant_program':
$from .= " $side JOIN civicrm_grant_program gp ON (civicrm_grant.grant_program_id = gp.id)";
break;
case 'civicrm_payment':
$from .= " $side JOIN civicrm_entity_payment ep ON (civicrm_grant.id = ep.entity_id AND ep.entity_table = 'civicrm_grant')" .
" $side JOIN civicrm_payment civicrm_payment ON (ep.payment_id = civicrm_payment.id)";
break;
}
return $from;
}
......
......@@ -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,
......
......@@ -85,6 +85,14 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$defaults['is_auto_email'] = 1;
return $defaults;
}
if (!isset($defaults['from_email_address']) || $defaults['from_email_address'] == '') {
// Set to default identity
$defaultEmails =
CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
$defaults['from_email_address'] = array_pop($defaultEmails);
}
return $defaults;
}
......@@ -128,7 +136,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 +192,7 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
}
$values = $this->controller->exportValues($this->_name);
$values['from_email_address'] = htmlspecialchars_decode($values['from_email_address']); // avoid QuickForm's safe value for this field
$domainID = CRM_Core_Config::domainID();
$result = $this->updateGrantProgram($values, $domainID);
......@@ -203,6 +217,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 +227,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);
}
......
......@@ -22,7 +22,7 @@
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing
| see the CiviCRM license FAQ at http://civicrm.org/licensing
+--------------------------------------------------------------------+
*/
......@@ -41,156 +41,156 @@
* This file is for civigrant search
*/
class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
/**
* Are we forced to run a search
*
* @var int
* @access protected
*/
protected $_force;
/**
* name of search button
*
* @var string
* @access protected
*/
/**
* Are we forced to run a search
*
* @var int
* @access protected
*/
protected $_force;
/**
* name of search button
*
* @var string
* @access protected
*/
protected $_searchButtonName;
/**
* name of print button
*
* @var string
* @access protected
*/
protected $_printButtonName;
/**
* name of action button
*
* @var string
* @access protected
*/
/**
* name of print button
*
* @var string
* @access protected
*/
protected $_printButtonName;
/**
* name of action button
*
* @var string
* @access protected
*/
protected $_actionButtonName;
/**
* form values that we will be using
*
* @var array
* @access protected
*/
protected $_formValues;
/**
* form values that we will be using
*
* @var array
* @access protected
*/
protected $_formValues;
/**
* the params that are sent to the query
*
* @var array
* @access protected
*/
*
* @var array
* @access protected
*/
protected $_queryParams;
/**
* have we already done this search
*
* @access protected
* @var boolean
*/
protected $_done;
/**
* have we already done this search
*
* @access protected
* @var boolean
*/
protected $_done;
/**
* are we restricting ourselves to a single contact
*
* @access protected
* @var boolean
*/
* @access protected
* @var boolean
*/
protected $_single = FALSE;
/**
* are we restricting ourselves to a single contact
*
* @access protected
* @var boolean
*/
/**
* are we restricting ourselves to a single contact
*
* @access protected
* @var boolean
*/
protected $_limit = NULL;
/**
* what context are we being invoked from
*
* @access protected
* @var string
*/
protected $_context = NULL;
/**
/**
* what context are we being invoked from
*
* @access protected
* @var string
*/
protected $_context = NULL;
/**
* prefix for the controller
*
*
*/
protected $_prefix = "grant_";
protected $_defaults;
public $_defaults;
/**
* processing needed for buildForm and later
*
* @return void
* @access public
*/
function preProcess() {
/**
* set the button names
*/
/**
* processing needed for buildForm and later
*
* @return void
* @access public
*/
function preProcess() {
/**
* set the button names
*/
$this->_searchButtonName = $this->getButtonName('refresh');
$this->_printButtonName = $this->getButtonName('next', 'print');
$this->_printButtonName = $this->getButtonName('next', 'print');
$this->_actionButtonName = $this->getButtonName('next', 'action');
$this->_done = FALSE;
$this->defaults = array();
/*
* we allow the controller to set force/reset externally, useful when we are being
* driven by the wizard framework
*/
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject);
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
/*
* we allow the controller to set force/reset externally, useful when we are being
* driven by the wizard framework
*/
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject);
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
$this->_download = CRM_Utils_Request::retrieve('download', 'String', $this, FALSE);
$this->_batchId = CRM_Utils_Request::retrieve('bid', 'Positive', $this, FALSE);
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
$this->assign("context", $this->_context);
// get user submitted values
// get it from controller only if form has been submitted, else preProcess has set this
if (!empty($_POST)) {
if (!empty($_POST)) {
$this->_formValues = $this->controller->exportValues($this->_name);
}
}
else {
$this->_formValues = $this->get('formValues');
}
if ($this->_force) {
$this->_formValues = $this->get('formValues');
}
if ($this->_force) {
$this->postProcess();
$this->set('force', 0);
}
$sortID = NULL;
if ($this->get( CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue(
$sortID = NULL;
if ($this->get( CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue(
$this->get(CRM_Utils_Sort::SORT_ID ),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
}
$this->_queryParams = CRM_Grant_BAO_PaymentSearch::convertFormValues($this->_formValues);
$selector = new CRM_Grant_Selector_PaymentSearch(
$selector = new CRM_Grant_Selector_PaymentSearch(
$this->_queryParams,
$this->_action,
NULL,
$this->_single,
$this->_limit,
$this->_context
$this->_context
);
$prefix = NULL;
if ($this->_context == 'user') {
$prefix = $this->_prefix;
......@@ -198,18 +198,18 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
$this->assign("{$prefix}limit", $this->_limit);
$this->assign("{$prefix}single", $this->_single);
$controller = new CRM_Core_Selector_Controller(
$selector ,
$this->get( CRM_Utils_Pager::PAGE_ID ),
$sortID,
CRM_Core_Action::VIEW,
$this,
$selector ,
$this->get( CRM_Utils_Pager::PAGE_ID ),
$sortID,
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::TRANSFER,
$prefix
);
$controller->setEmbedded(TRUE);
$controller->setEmbedded(TRUE);
$controller->moveFromSessionToTemplate();
$this->assign('summary', $this->get('summary'));
$this->assign('summary', $this->get('summary'));
$download = FALSE;
if (CRM_Utils_Array::value('bid', $_GET)) {
$download = TRUE;
......@@ -221,10 +221,10 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
$directory = strstr($config->customFileUploadDir, 'sites');
$config = CRM_Core_Config::singleton();
$file_name = $base_url . '/' . $directory . $this->_download;
$this->assign('download', $file_name);
$this->assign('download', $file_name);
}
}
/**
* Build the form
*
......@@ -235,33 +235,33 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
$paymentStatus = CRM_Core_OptionGroup::values('grant_payment_status');
$this->add('select', 'payment_status_id', ts('Status'),
array('' => ts('- select -')) + $paymentStatus);
$this->addElement('text', 'payment_batch_number', ts('Batch Number'), array('size' => 8, 'maxlength' => 8));
$this->addElement('text', 'payment_number', ts('Payment Number'), array('size' => 10, 'maxlength' => 10));
$this->addDate('payment_created_date_low', ts('From'), FALSE, array('formatType' => 'searchDate'));
$this->addDate('payment_created_date_high', ts('To'), FALSE, array('formatType' => 'searchDate'));
$this->addElement('text', 'payable_to_name', ts('Payee name'), CRM_Core_DAO::getAttribute('CRM_Grant_DAO_GrantPayment', 'payable_to_name'));
$this->add('text', 'amount', ts('Amount'), array('size' => 8, 'maxlength' => 8));
/*
* add form checkboxes for each row. This is needed out here to conform to QF protocol
* of all elements being declared in builQuickForm
*/
$this->add('text', 'amount', ts('Amount'), array('size' => 8, 'maxlength' => 8));
/*
* add form checkboxes for each row. This is needed out here to conform to QF protocol
* of all elements being declared in builQuickForm
*/
$rows = $this->get('rows');
if (is_array($rows)) {
if (!$this->_single) {
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, array( 'onchange' => "toggleTaskAction( true );return toggleCheckboxVals('mark_x_',this);"));
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, array( 'onchange' => "toggleTaskAction( true );return toggleCheckboxVals('mark_x_',this);"));
foreach ($rows as $row) {
$this->addElement('checkbox', CRM_Utils_Array::value('checkbox', $row),
NULL, NULL,
$this->addElement('checkbox', CRM_Utils_Array::value('checkbox', $row),
NULL, NULL,
array('onclick' => " toggleTaskAction( true ); return checkSelectedBox('" . CRM_Utils_Array::value('checkbox', $row) . "');")
);
);
}
}
......@@ -274,48 +274,48 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
if (is_array($permissionedTask) && !CRM_Utils_System::isNull($permissionedTask)) {
$tasks += $permissionedTask;
}
$this->add('select', 'task', ts('Actions:') . ' ', $tasks);
$this->add('submit', $this->_actionButtonName, ts('Go'),
array('class' => 'form-submit',
'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);"));
$this->add('submit', $this->_printButtonName, ts('Print'),
array( 'class' => 'form-submit',
'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);" )
);
// need to perform tasks on all or selected items ? using radio_ts(task selection) for it
$this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
$this->add('select', 'task', ts('Actions:') . ' ', $tasks);
$this->add('submit', $this->_actionButtonName, ts('Go'),
array('class' => 'form-submit',
'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);"));
$this->add('submit', $this->_printButtonName, ts('Print'),
array( 'class' => 'form-submit',
'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);" )
);
// need to perform tasks on all or selected items ? using radio_ts(task selection) for it
$this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
$this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onchange' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );"));
}
//add buttons
$this->addButtons(array(
array (
'type' => 'refresh',
'name' => ts('Search'),
'isDefault' => TRUE)
)
//add buttons
$this->addButtons(array(
array (
'type' => 'refresh',
'name' => ts('Search'),
'isDefault' => TRUE)
)
);
}
/**
* The post processing of the form gets done here.
*
*
* Key things done during post processing are
* - check for reset or next request. if present, skip post procesing.
* - now check if user requested running a saved search, if so, then
* the form values associated with the saved search are used for searching.
* - if user has done a submit with new values the regular post submissing is
* - if user has done a submit with new values the regular post submissing is
* done.
* The processing consists of using a Selector / Controller framework for getting the
* search results.
*
* @param
*
* @return void
* @return void
* @access public
*/
function postProcess() {
......@@ -323,9 +323,9 @@ class CRM_Grant_Form_PaymentSearch extends CRM_Core_Form {
return;
}
$this->_done = TRUE;
$this->_formValues = $this->controller->exportValues($this->_name);
if (!empty($_GET['bid'])) {
$this->_formValues['payment_batch_number'] = $_GET['bid'];