First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
175
sites/all/modules/civicrm/CRM/Pledge/Form/Payment.php
Normal file
175
sites/all/modules/civicrm/CRM/Pledge/Form/Payment.php
Normal file
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a pledge payment.
|
||||
*/
|
||||
class CRM_Pledge_Form_Payment extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The id of the pledge payment that we are proceessing.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_id;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// check for edit permission
|
||||
if (!CRM_Core_Permission::check('edit pledges')) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
|
||||
$this->_id = CRM_Utils_Request::retrieve('ppId', 'Positive', $this);
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Edit Scheduled Pledge Payment'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
* the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if ($this->_id) {
|
||||
$params['id'] = $this->_id;
|
||||
CRM_Pledge_BAO_PledgePayment::retrieve($params, $defaults);
|
||||
list($defaults['scheduled_date']) = CRM_Utils_Date::setDateDefaults($defaults['scheduled_date']);
|
||||
if (isset($defaults['contribution_id'])) {
|
||||
$this->assign('pledgePayment', TRUE);
|
||||
}
|
||||
$status = CRM_Core_PseudoConstant::getName('CRM_Pledge_BAO_Pledge', 'status_id', $defaults['status_id']);
|
||||
$this->assign('status', $status);
|
||||
}
|
||||
$defaults['option_type'] = 1;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// add various dates
|
||||
$this->addDate('scheduled_date', ts('Scheduled Date'), TRUE);
|
||||
|
||||
$this->addMoney('scheduled_amount',
|
||||
ts('Scheduled Amount'), TRUE,
|
||||
array('readonly' => TRUE),
|
||||
TRUE,
|
||||
'currency',
|
||||
NULL,
|
||||
TRUE
|
||||
);
|
||||
|
||||
$optionTypes = array(
|
||||
'1' => ts('Adjust Pledge Payment Schedule?'),
|
||||
'2' => ts('Adjust Total Pledge Amount?'),
|
||||
);
|
||||
$element = $this->addRadio('option_type',
|
||||
NULL,
|
||||
$optionTypes,
|
||||
array(), '<br/>'
|
||||
);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$formValues = $this->controller->exportValues($this->_name);
|
||||
$params = array();
|
||||
$formValues['scheduled_date'] = CRM_Utils_Date::processDate($formValues['scheduled_date']);
|
||||
$params['scheduled_date'] = CRM_Utils_Date::format($formValues['scheduled_date']);
|
||||
$params['currency'] = CRM_Utils_Array::value('currency', $formValues);
|
||||
$now = date('Ymd');
|
||||
|
||||
if (CRM_Utils_Date::overdue(CRM_Utils_Date::customFormat($params['scheduled_date'], '%Y%m%d'), $now)) {
|
||||
$params['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_Pledge', 'status_id', 'Overdue');
|
||||
}
|
||||
else {
|
||||
$params['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_Pledge', 'status_id', 'Pending');
|
||||
}
|
||||
|
||||
$params['id'] = $this->_id;
|
||||
$pledgeId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $params['id'], 'pledge_id');
|
||||
|
||||
CRM_Pledge_BAO_PledgePayment::add($params);
|
||||
$adjustTotalAmount = FALSE;
|
||||
if (CRM_Utils_Array::value('option_type', $formValues) == 2) {
|
||||
$adjustTotalAmount = TRUE;
|
||||
}
|
||||
|
||||
$pledgeScheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
|
||||
$params['id'],
|
||||
'scheduled_amount',
|
||||
'id'
|
||||
);
|
||||
|
||||
$oldestPaymentAmount = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId, 2);
|
||||
if (($oldestPaymentAmount['count'] != 1) && ($oldestPaymentAmount['id'] == $params['id'])) {
|
||||
$oldestPaymentAmount = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId);
|
||||
}
|
||||
if (($formValues['scheduled_amount'] - $pledgeScheduledAmount) >= $oldestPaymentAmount['amount']) {
|
||||
$adjustTotalAmount = TRUE;
|
||||
}
|
||||
// update pledge status
|
||||
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId,
|
||||
array($params['id']),
|
||||
$params['status_id'],
|
||||
NULL,
|
||||
$formValues['scheduled_amount'],
|
||||
$adjustTotalAmount
|
||||
);
|
||||
|
||||
$statusMsg = ts('Pledge Payment Schedule has been updated.');
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
|
||||
}
|
||||
|
||||
}
|
645
sites/all/modules/civicrm/CRM/Pledge/Form/Pledge.php
Normal file
645
sites/all/modules/civicrm/CRM/Pledge/Form/Pledge.php
Normal file
|
@ -0,0 +1,645 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a pledge
|
||||
*/
|
||||
class CRM_Pledge_Form_Pledge extends CRM_Core_Form {
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* The id of the pledge that we are proceessing.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_id;
|
||||
|
||||
/**
|
||||
* The id of the contact associated with this pledge.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_contactID;
|
||||
|
||||
/**
|
||||
* The Pledge values if an existing pledge.
|
||||
*/
|
||||
public $_values;
|
||||
|
||||
/**
|
||||
* The Pledge frequency Units.
|
||||
*/
|
||||
public $_freqUnits;
|
||||
|
||||
/**
|
||||
* Is current pledge pending.
|
||||
*/
|
||||
public $_isPending = FALSE;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String',
|
||||
$this, FALSE, 'add'
|
||||
);
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
|
||||
// check for action permissions.
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviPledge', $this->_action)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
|
||||
$this->assign('action', $this->_action);
|
||||
$this->assign('context', $this->_context);
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->userDisplayName = $this->userEmail = NULL;
|
||||
if ($this->_contactID) {
|
||||
list($this->userDisplayName,
|
||||
$this->userEmail
|
||||
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
|
||||
$this->assign('displayName', $this->userDisplayName);
|
||||
}
|
||||
|
||||
$this->setPageTitle(ts('Pledge'));
|
||||
|
||||
// build custom data
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Pledge', $this->_id);
|
||||
$this->_values = array();
|
||||
// current pledge id
|
||||
if ($this->_id) {
|
||||
// get the contribution id
|
||||
$this->_contributionID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
|
||||
$this->_id, 'contribution_id', 'pledge_id'
|
||||
);
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Pledge_BAO_Pledge::getValues($params, $this->_values);
|
||||
|
||||
$this->_isPending = (CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($this->_id, CRM_Utils_Array::value('status_id', $this->_values))) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
// get the pledge frequency units.
|
||||
$this->_freqUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
|
||||
|
||||
$this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
* The default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $this->_values;
|
||||
|
||||
$fields = array();
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
if (!empty($defaults['is_test'])) {
|
||||
$this->assign('is_test', TRUE);
|
||||
}
|
||||
|
||||
if ($this->_id) {
|
||||
$startDate = CRM_Utils_Array::value('start_date', $this->_values);
|
||||
$createDate = CRM_Utils_Array::value('create_date', $this->_values);
|
||||
list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($startDate);
|
||||
list($defaults['create_date']) = CRM_Utils_Date::setDateDefaults($createDate);
|
||||
|
||||
if ($ackDate = CRM_Utils_Array::value('acknowledge_date', $this->_values)) {
|
||||
list($defaults['acknowledge_date']) = CRM_Utils_Date::setDateDefaults($ackDate);
|
||||
}
|
||||
|
||||
// check is this pledge pending.
|
||||
// fix the display of the monetary value, CRM-4038.
|
||||
if ($this->_isPending) {
|
||||
$defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments'];
|
||||
$defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], NULL, '%a');
|
||||
}
|
||||
else {
|
||||
$this->assign('start_date', $startDate);
|
||||
$this->assign('create_date', $createDate);
|
||||
}
|
||||
// fix the display of the monetary value, CRM-4038
|
||||
if (isset($this->_values['amount'])) {
|
||||
$defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], NULL, '%a');
|
||||
}
|
||||
$this->assign('amount', $this->_values['amount']);
|
||||
$this->assign('installments', $defaults['installments']);
|
||||
}
|
||||
else {
|
||||
// default values.
|
||||
list($now) = CRM_Utils_Date::setDateDefaults();
|
||||
$defaults['create_date'] = $now;
|
||||
$defaults['start_date'] = $now;
|
||||
$defaults['installments'] = 12;
|
||||
$defaults['frequency_interval'] = 1;
|
||||
$defaults['frequency_day'] = 1;
|
||||
$defaults['initial_reminder_day'] = 5;
|
||||
$defaults['max_reminders'] = 1;
|
||||
$defaults['additional_reminder_day'] = 5;
|
||||
$defaults['frequency_unit'] = array_search('month', $this->_freqUnits);
|
||||
$defaults['financial_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::financialType());
|
||||
}
|
||||
|
||||
$pledgeStatus = CRM_Pledge_BAO_Pledge::buildOptions('status_id');
|
||||
$pledgeStatusNames = CRM_Core_OptionGroup::values('pledge_status',
|
||||
FALSE, FALSE, FALSE, NULL, 'name', TRUE
|
||||
);
|
||||
// get default status label (pending)
|
||||
$defaultPledgeStatus = CRM_Utils_Array::value(array_search('Pending', $pledgeStatusNames),
|
||||
$pledgeStatus
|
||||
);
|
||||
|
||||
// assign status.
|
||||
$this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values),
|
||||
$pledgeStatus,
|
||||
$defaultPledgeStatus
|
||||
));
|
||||
|
||||
if (isset($this->userEmail)) {
|
||||
$this->assign('email', $this->userEmail);
|
||||
}
|
||||
|
||||
// custom data set defaults
|
||||
$defaults += CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_context == 'standalone') {
|
||||
$this->addEntityRef('contact_id', ts('Contact'), array(
|
||||
'create' => TRUE,
|
||||
'api' => array('extra' => array('email')),
|
||||
), TRUE);
|
||||
}
|
||||
|
||||
$showAdditionalInfo = FALSE;
|
||||
$this->_formType = CRM_Utils_Array::value('formType', $_GET);
|
||||
|
||||
$defaults = array();
|
||||
|
||||
$paneNames = array(
|
||||
'Payment Reminders' => 'PaymentReminders',
|
||||
);
|
||||
foreach ($paneNames as $name => $type) {
|
||||
$urlParams = "snippet=4&formType={$type}";
|
||||
$allPanes[$name] = array(
|
||||
'url' => CRM_Utils_System::url('civicrm/contact/view/pledge', $urlParams),
|
||||
'open' => 'false',
|
||||
'id' => $type,
|
||||
);
|
||||
// see if we need to include this paneName in the current form
|
||||
if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) ||
|
||||
CRM_Utils_Array::value("hidden_{$type}", $defaults)
|
||||
) {
|
||||
$showAdditionalInfo = TRUE;
|
||||
$allPanes[$name]['open'] = 'true';
|
||||
}
|
||||
$fnName = "build{$type}";
|
||||
CRM_Contribute_Form_AdditionalInfo::$fnName($this);
|
||||
}
|
||||
|
||||
$this->assign('allPanes', $allPanes);
|
||||
$this->assign('showAdditionalInfo', $showAdditionalInfo);
|
||||
|
||||
if ($this->_formType) {
|
||||
$this->assign('formType', $this->_formType);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
// pledge fields.
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Pledge_DAO_Pledge');
|
||||
|
||||
$this->assign('isPending', $this->_isPending);
|
||||
|
||||
$js = array(
|
||||
'onblur' => "calculatedPaymentAmount( );",
|
||||
'onkeyup' => "calculatedPaymentAmount( );",
|
||||
);
|
||||
|
||||
$currencyFreeze = FALSE;
|
||||
if ($this->_id &&
|
||||
!$this->_isPending
|
||||
) {
|
||||
$currencyFreeze = TRUE;
|
||||
}
|
||||
|
||||
$element = $this->addMoney('amount', ts('Total Pledge Amount'), TRUE,
|
||||
array_merge($attributes['pledge_amount'], $js), TRUE,
|
||||
'currency', NULL, $currencyFreeze
|
||||
);
|
||||
|
||||
if ($this->_id &&
|
||||
!$this->_isPending
|
||||
) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
$element = &$this->add('text', 'installments', ts('To be paid in'),
|
||||
array_merge($attributes['installments'], $js), TRUE
|
||||
);
|
||||
$this->addRule('installments', ts('Please enter a valid number of installments.'), 'positiveInteger');
|
||||
if ($this->_id &&
|
||||
!$this->_isPending
|
||||
) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
$element = &$this->add('text', 'frequency_interval', ts('every'),
|
||||
$attributes['pledge_frequency_interval'], TRUE
|
||||
);
|
||||
$this->addRule('frequency_interval', ts('Please enter a number for frequency (e.g. every "3" months).'), 'positiveInteger');
|
||||
if ($this->_id &&
|
||||
!$this->_isPending
|
||||
) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
// Fix frequency unit display for use with frequency_interval
|
||||
$freqUnitsDisplay = array();
|
||||
foreach ($this->_freqUnits as $val => $label) {
|
||||
$freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
|
||||
}
|
||||
$element = &$this->add('select', 'frequency_unit',
|
||||
ts('Frequency'),
|
||||
array('' => ts('- select -')) + $freqUnitsDisplay,
|
||||
TRUE
|
||||
);
|
||||
|
||||
if ($this->_id &&
|
||||
!$this->_isPending
|
||||
) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
$element = &$this->add('text', 'frequency_day', ts('Payments are due on the'), $attributes['frequency_day'], TRUE);
|
||||
$this->addRule('frequency_day', ts('Please enter a valid payment due day.'), 'positiveInteger');
|
||||
if ($this->_id &&
|
||||
!$this->_isPending
|
||||
) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
$this->add('text', 'eachPaymentAmount', ts('each'), array(
|
||||
'size' => 10,
|
||||
'style' => "background-color:#EBECE4",
|
||||
0 => 'READONLY', // WTF, preserved because its inexplicable
|
||||
));
|
||||
|
||||
// add various dates
|
||||
if (!$this->_id || $this->_isPending) {
|
||||
$this->addDate('create_date', ts('Pledge Made'), TRUE);
|
||||
$this->addDate('start_date', ts('Payments Start'), TRUE);
|
||||
}
|
||||
|
||||
if (!empty($this->_values['currency'])) {
|
||||
$this->assign('currency', $this->_values['currency']);
|
||||
}
|
||||
elseif (!empty($this->_submitValues['currency'])) {
|
||||
$this->assign('currency', $this->_submitValues['currency']);
|
||||
}
|
||||
|
||||
if ($this->_id &&
|
||||
!$this->_isPending
|
||||
) {
|
||||
$eachPaymentAmount = $this->_values['original_installment_amount'];
|
||||
$this->assign('eachPaymentAmount', $eachPaymentAmount);
|
||||
$this->assign('hideCalender', TRUE);
|
||||
}
|
||||
|
||||
if (CRM_Utils_Array::value('status_id', $this->_values) !=
|
||||
CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_Pledge', 'status_id', 'Cancelled')
|
||||
) {
|
||||
|
||||
$this->addElement('checkbox', 'is_acknowledge', ts('Send Acknowledgment?'), NULL,
|
||||
array('onclick' => "showHideByValue( 'is_acknowledge', '', 'acknowledgeDate', 'table-row', 'radio', true); showHideByValue( 'is_acknowledge', '', 'fromEmail', 'table-row', 'radio', false );")
|
||||
);
|
||||
|
||||
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
|
||||
}
|
||||
|
||||
$this->addDate('acknowledge_date', ts('Acknowledgment Date'));
|
||||
|
||||
$this->add('select', 'financial_type_id',
|
||||
ts('Financial Type'),
|
||||
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(),
|
||||
TRUE
|
||||
);
|
||||
|
||||
// CRM-7362 --add campaigns.
|
||||
CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
|
||||
|
||||
$pageIds = array();
|
||||
CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgeBlock', 'entity_table',
|
||||
'civicrm_contribution_page', $pageIds, array('entity_id')
|
||||
);
|
||||
$pages = CRM_Contribute_PseudoConstant::contributionPage();
|
||||
$pledgePages = array();
|
||||
foreach ($pageIds as $key => $value) {
|
||||
$pledgePages[$value['entity_id']] = $pages[$value['entity_id']];
|
||||
}
|
||||
$ele = $this->add('select', 'contribution_page_id', ts('Self-service Payments Page'),
|
||||
array('' => ts('- select -')) + $pledgePages
|
||||
);
|
||||
|
||||
$mailingInfo = Civi::settings()->get('mailing_backend');
|
||||
$this->assign('outBound_option', $mailingInfo['outBound_option']);
|
||||
|
||||
// build custom data
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
|
||||
// make this form an upload since we dont know if the custom data injected dynamically
|
||||
// is of type file etc $uploadNames = $this->get( 'uploadNames' );
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'js' => array('onclick' => "return verify( );"),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and New'),
|
||||
'js' => array('onclick' => "return verify( );"),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->addFormRule(array('CRM_Pledge_Form_Pledge', 'formRule'), $this);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::VIEW) {
|
||||
$this->freeze();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param $self
|
||||
*
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
|
||||
if ($fields['amount'] <= 0) {
|
||||
$errors['amount'] = ts('Total Pledge Amount should be greater than zero.');
|
||||
}
|
||||
if ($fields['installments'] <= 0) {
|
||||
$errors['installments'] = ts('Installments should be greater than zero.');
|
||||
}
|
||||
|
||||
if ($fields['frequency_unit'] != 'week') {
|
||||
if ($fields['frequency_day'] > 31 || $fields['frequency_day'] == 0) {
|
||||
$errors['frequency_day'] = ts('Please enter a valid frequency day ie. 1 through 31.');
|
||||
}
|
||||
}
|
||||
elseif ($fields['frequency_unit'] == 'week') {
|
||||
if ($fields['frequency_day'] > 7 || $fields['frequency_day'] == 0) {
|
||||
$errors['frequency_day'] = ts('Please enter a valid frequency day ie. 1 through 7.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
CRM_Pledge_BAO_Pledge::deletePledge($this->_id);
|
||||
return;
|
||||
}
|
||||
|
||||
// get the submitted form values.
|
||||
$formValues = $this->controller->exportValues($this->_name);
|
||||
|
||||
// set the contact, when contact is selected
|
||||
if (!empty($formValues['contact_id'])) {
|
||||
$this->_contactID = $formValues['contact_id'];
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$fields = array(
|
||||
'frequency_unit',
|
||||
'frequency_interval',
|
||||
'frequency_day',
|
||||
'installments',
|
||||
'financial_type_id',
|
||||
'initial_reminder_day',
|
||||
'max_reminders',
|
||||
'additional_reminder_day',
|
||||
'contribution_page_id',
|
||||
'campaign_id',
|
||||
);
|
||||
foreach ($fields as $f) {
|
||||
$params[$f] = CRM_Utils_Array::value($f, $formValues);
|
||||
}
|
||||
|
||||
// format amount
|
||||
$params['amount'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('amount', $formValues));
|
||||
$params['currency'] = CRM_Utils_Array::value('currency', $formValues);
|
||||
$params['original_installment_amount'] = ($params['amount'] / $params['installments']);
|
||||
|
||||
$dates = array('create_date', 'start_date', 'acknowledge_date', 'cancel_date');
|
||||
foreach ($dates as $d) {
|
||||
if ($this->_id && (!$this->_isPending) && !empty($this->_values[$d])) {
|
||||
if ($d == 'start_date') {
|
||||
$params['scheduled_date'] = CRM_Utils_Date::processDate($this->_values[$d]);
|
||||
}
|
||||
$params[$d] = CRM_Utils_Date::processDate($this->_values[$d]);
|
||||
}
|
||||
elseif (!empty($formValues[$d]) && !CRM_Utils_System::isNull($formValues[$d])) {
|
||||
if ($d == 'start_date') {
|
||||
$params['scheduled_date'] = CRM_Utils_Date::processDate($formValues[$d]);
|
||||
}
|
||||
$params[$d] = CRM_Utils_Date::processDate($formValues[$d]);
|
||||
}
|
||||
else {
|
||||
$params[$d] = 'null';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($formValues['is_acknowledge'])) {
|
||||
$params['acknowledge_date'] = date('Y-m-d');
|
||||
}
|
||||
|
||||
// assign id only in update mode
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$params['id'] = $this->_id;
|
||||
}
|
||||
|
||||
$params['contact_id'] = $this->_contactID;
|
||||
|
||||
// format custom data
|
||||
if (!empty($formValues['hidden_custom'])) {
|
||||
$params['hidden_custom'] = 1;
|
||||
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Pledge');
|
||||
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues,
|
||||
$this->_id,
|
||||
'Pledge'
|
||||
);
|
||||
}
|
||||
|
||||
// handle pending pledge.
|
||||
$params['is_pledge_pending'] = $this->_isPending;
|
||||
|
||||
// create pledge record.
|
||||
$pledge = CRM_Pledge_BAO_Pledge::create($params);
|
||||
|
||||
$statusMsg = NULL;
|
||||
|
||||
if ($pledge->id) {
|
||||
// set the status msg.
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$statusMsg = ts('Pledge has been recorded and the payment schedule has been created.<br />');
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$statusMsg = ts('Pledge has been updated.<br />');
|
||||
}
|
||||
}
|
||||
|
||||
// handle Acknowledgment.
|
||||
if (!empty($formValues['is_acknowledge']) && $pledge->id) {
|
||||
|
||||
// calculate scheduled amount.
|
||||
$params['scheduled_amount'] = round($params['amount'] / $params['installments']);
|
||||
$params['total_pledge_amount'] = $params['amount'];
|
||||
// get some required pledge values in params.
|
||||
$params['id'] = $pledge->id;
|
||||
$params['acknowledge_date'] = $pledge->acknowledge_date;
|
||||
$params['is_test'] = $pledge->is_test;
|
||||
$params['currency'] = $pledge->currency;
|
||||
// retrieve 'from email id' for acknowledgement
|
||||
$params['from_email_id'] = $formValues['from_email_address'];
|
||||
|
||||
$this->paymentId = NULL;
|
||||
// send Acknowledgment mail.
|
||||
CRM_Pledge_BAO_Pledge::sendAcknowledgment($this, $params);
|
||||
|
||||
if (!isset($this->userEmail)) {
|
||||
list($this->userDisplayName,
|
||||
$this->userEmail
|
||||
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
|
||||
}
|
||||
|
||||
$statusMsg .= ' ' . ts("An acknowledgment email has been sent to %1.<br />", array(1 => $this->userEmail));
|
||||
|
||||
// build the payment urls.
|
||||
if ($this->paymentId) {
|
||||
$urlParams = "reset=1&action=add&cid={$this->_contactID}&ppid={$this->paymentId}&context=pledge";
|
||||
$contribURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
|
||||
$urlParams .= "&mode=live";
|
||||
$creditURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
|
||||
|
||||
// check if we can process credit card payment.
|
||||
$processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE,
|
||||
"billing_mode IN ( 1, 3 )"
|
||||
);
|
||||
if (count($processors) > 0) {
|
||||
$statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a> OR <a href='%2'>submit a credit card payment</a>.", array(
|
||||
1 => $contribURL,
|
||||
2 => $creditURL,
|
||||
));
|
||||
}
|
||||
else {
|
||||
$statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a>.", array(1 => $contribURL));
|
||||
}
|
||||
}
|
||||
}
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Payment Due'), 'info');
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($this->_context == 'standalone') {
|
||||
if ($buttonName == $this->getButtonName('upload', 'new')) {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/add',
|
||||
'reset=1&action=add&context=standalone'
|
||||
));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
|
||||
"reset=1&cid={$this->_contactID}&selectedChild=pledge"
|
||||
));
|
||||
}
|
||||
}
|
||||
elseif ($buttonName == $this->getButtonName('upload', 'new')) {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/pledge',
|
||||
"reset=1&action=add&context=pledge&cid={$this->_contactID}"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
143
sites/all/modules/civicrm/CRM/Pledge/Form/PledgeView.php
Normal file
143
sites/all/modules/civicrm/CRM/Pledge/Form/PledgeView.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Pledge
|
||||
*/
|
||||
class CRM_Pledge_Form_PledgeView extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
$values = $ids = array();
|
||||
$params = array('id' => $this->get('id'));
|
||||
CRM_Pledge_BAO_Pledge::getValues($params,
|
||||
$values,
|
||||
$ids
|
||||
);
|
||||
|
||||
$values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
|
||||
|
||||
if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
|
||||
$sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
|
||||
$dao = new CRM_Core_DAO();
|
||||
$dao->query($sql);
|
||||
if ($dao->fetch()) {
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$values[honor_contact_id]");
|
||||
$values["honor_display"] = "<A href = $url>" . $dao->display_name . "</A>";
|
||||
}
|
||||
$honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
|
||||
$values['honor_type'] = $honor[$values['honor_type_id']];
|
||||
}
|
||||
|
||||
// handle custom data.
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', NULL, $params['id']);
|
||||
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $params['id']);
|
||||
|
||||
if (!empty($values['contribution_page_id'])) {
|
||||
$values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
|
||||
}
|
||||
|
||||
$values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType());
|
||||
|
||||
if ($values['status_id']) {
|
||||
$values['pledge_status'] = CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_Pledge', 'status_id', $values['status_id']);
|
||||
}
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view/pledge',
|
||||
"action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
|
||||
$recentOther = array();
|
||||
if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
|
||||
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge',
|
||||
"action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
|
||||
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge',
|
||||
"action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
|
||||
$displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
|
||||
$this->assign('displayName', $displayName);
|
||||
|
||||
$title = $displayName .
|
||||
' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) .
|
||||
' - ' . $values['financial_type'] . ')';
|
||||
|
||||
// add Pledge to Recent Items
|
||||
CRM_Utils_Recent::add($title,
|
||||
$url,
|
||||
$values['id'],
|
||||
'Pledge',
|
||||
$values['contact_id'],
|
||||
NULL,
|
||||
$recentOther
|
||||
);
|
||||
|
||||
// Check if this is default domain contact CRM-10482
|
||||
if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
|
||||
$displayName .= ' (' . ts('default organization') . ')';
|
||||
}
|
||||
// omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
|
||||
CRM_Utils_System::setTitle(ts('View Pledge by') . ' ' . $displayName);
|
||||
|
||||
// do check for campaigns
|
||||
if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
|
||||
$values['campaign'] = $campaigns[$campaignId];
|
||||
}
|
||||
|
||||
$this->assign($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Done'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
415
sites/all/modules/civicrm/CRM/Pledge/Form/Search.php
Normal file
415
sites/all/modules/civicrm/CRM/Pledge/Form/Search.php
Normal file
|
@ -0,0 +1,415 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is for Pledge search
|
||||
*/
|
||||
class CRM_Pledge_Form_Search extends CRM_Core_Form_Search {
|
||||
|
||||
/**
|
||||
* The params that are sent to the query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_queryParams;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_limit = NULL;
|
||||
|
||||
/**
|
||||
* Prefix for the controller.
|
||||
*/
|
||||
protected $_prefix = "pledge_";
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
$this->_searchButtonName = $this->getButtonName('refresh');
|
||||
$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');
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $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) && !$this->controller->isModal()) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
else {
|
||||
$this->_formValues = $this->get('formValues');
|
||||
}
|
||||
|
||||
if (empty($this->_formValues)) {
|
||||
if (isset($this->_ssID)) {
|
||||
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_force) {
|
||||
$this->postProcess();
|
||||
$this->set('force', 0);
|
||||
}
|
||||
|
||||
$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->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
$selector = new CRM_Pledge_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'user') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$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,
|
||||
CRM_Core_Selector_Controller::TRANSFER,
|
||||
$prefix
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->moveFromSessionToTemplate();
|
||||
|
||||
$this->assign('summary', $this->get('summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->addSortNameField();
|
||||
|
||||
CRM_Pledge_BAO_Query::buildSearchForm($this);
|
||||
|
||||
$rows = $this->get('rows');
|
||||
if (is_array($rows)) {
|
||||
if (!$this->_single) {
|
||||
$this->addRowSelectors($rows);
|
||||
}
|
||||
|
||||
$permission = CRM_Core_Permission::getPermission();
|
||||
|
||||
$this->addTaskMenu(CRM_Pledge_Task::permissionedTaskTitles($permission));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is on.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithEmail() {
|
||||
return ts('Pledger Name or Email');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is off.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithOutEmail() {
|
||||
return ts('Pledger Name');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* done.
|
||||
* The processing consists of using a Selector / Controller framework for getting the
|
||||
* search results.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_done = TRUE;
|
||||
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
|
||||
$this->fixFormValues();
|
||||
|
||||
// We don't show test records in summaries or dashboards
|
||||
if (empty($this->_formValues['pledge_test']) && $this->_force) {
|
||||
$this->_formValues["pledge_test"] = 0;
|
||||
}
|
||||
|
||||
foreach (array('pledge_amount_low', 'pledge_amount_high') as $f) {
|
||||
if (isset($this->_formValues[$f])) {
|
||||
$this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->_ssID) && empty($_POST)) {
|
||||
// if we are editing / running a saved search and the form has not been posted
|
||||
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
|
||||
}
|
||||
|
||||
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
|
||||
$this->set('formValues', $this->_formValues);
|
||||
$this->set('queryParams', $this->_queryParams);
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->_actionButtonName) {
|
||||
// check actionName and if next, then do not repeat a search, since we are going to the next page
|
||||
|
||||
// hack, make sure we reset the task values
|
||||
$stateMachine = $this->controller->getStateMachine();
|
||||
$formName = $stateMachine->getTaskFormName();
|
||||
$this->controller->resetPage($formName);
|
||||
return;
|
||||
}
|
||||
|
||||
$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->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
|
||||
$selector = new CRM_Pledge_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$selector->setKey($this->controller->_key);
|
||||
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'user') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$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,
|
||||
CRM_Core_Selector_Controller::SESSION,
|
||||
$prefix
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
|
||||
$query = &$selector->getQuery();
|
||||
if ($this->_context == 'user') {
|
||||
$query->setSkipPermission(TRUE);
|
||||
}
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* add the rules (mainly global rules) for form.
|
||||
* All local rules are added near the element
|
||||
*
|
||||
* @see valid_date
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Pledge_Form_Search', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
$errors = array();
|
||||
|
||||
if (!empty($errors)) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$defaults = $this->_formValues;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function fixFormValues() {
|
||||
if (!$this->_force) {
|
||||
return;
|
||||
}
|
||||
|
||||
// set pledge payment related fields
|
||||
$status = CRM_Utils_Request::retrieve('status', 'String');
|
||||
if ($status) {
|
||||
$this->_formValues['pledge_payment_status_id'] = array($status => 1);
|
||||
$this->_defaults['pledge_payment_status_id'] = array($status => 1);
|
||||
}
|
||||
|
||||
$fromDate = CRM_Utils_Request::retrieve('start', 'Date');
|
||||
if ($fromDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($fromDate);
|
||||
$this->_formValues['pledge_payment_date_low'] = $date;
|
||||
$this->_defaults['pledge_payment_date_low'] = $date;
|
||||
}
|
||||
|
||||
$toDate = CRM_Utils_Request::retrieve('end', 'Date');
|
||||
if ($toDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($toDate);
|
||||
$this->_formValues['pledge_payment_date_high'] = $date;
|
||||
$this->_defaults['pledge_payment_date_high'] = $date;
|
||||
}
|
||||
|
||||
// set pledge related fields
|
||||
$pledgeStatus = CRM_Utils_Request::retrieve('pstatus', 'String');
|
||||
|
||||
if ($pledgeStatus) {
|
||||
$statusValues = CRM_Pledge_BAO_Pledge::buildOptions('status_id');
|
||||
|
||||
// we need set all statuses except Cancelled
|
||||
unset($statusValues[$pledgeStatus]);
|
||||
|
||||
$statuses = array();
|
||||
foreach ($statusValues as $statusId => $value) {
|
||||
$statuses[$statusId] = 1;
|
||||
}
|
||||
|
||||
$this->_formValues['pledge_status_id'] = $statuses;
|
||||
$this->_defaults['pledge_status_id'] = $statuses;
|
||||
}
|
||||
|
||||
$pledgeFromDate = CRM_Utils_Request::retrieve('pstart', 'Date');
|
||||
if ($pledgeFromDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($pledgeFromDate);
|
||||
$this->_formValues['pledge_create_date_low'] = $this->_defaults['pledge_create_date_low'] = $date;
|
||||
}
|
||||
|
||||
$pledgeToDate = CRM_Utils_Request::retrieve('pend', 'Date');
|
||||
if ($pledgeToDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($pledgeToDate);
|
||||
$this->_formValues['pledge_create_date_high'] = $this->_defaults['pledge_create_date_high'] = $date;
|
||||
}
|
||||
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
if ($cid) {
|
||||
$cid = CRM_Utils_Type::escape($cid, 'Integer');
|
||||
if ($cid > 0) {
|
||||
$this->_formValues['contact_id'] = $cid;
|
||||
list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
|
||||
$this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid,
|
||||
'sort_name'
|
||||
);
|
||||
// also assign individual mode to the template
|
||||
$this->_single = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getFormValues() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Find Pledges');
|
||||
}
|
||||
|
||||
}
|
168
sites/all/modules/civicrm/CRM/Pledge/Form/Task.php
Normal file
168
sites/all/modules/civicrm/CRM/Pledge/Form/Task.php
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates task actions for CiviEvent.
|
||||
*/
|
||||
class CRM_Pledge_Form_Task extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The task being performed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_componentClause = NULL;
|
||||
|
||||
/**
|
||||
* The array that holds all the component ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_componentIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the pledge ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_pledgeIds;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
self::preProcessCommon($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common pre-processing.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param bool $useTable
|
||||
*/
|
||||
public static function preProcessCommon(&$form, $useTable = FALSE) {
|
||||
$form->_pledgeIds = array();
|
||||
|
||||
$values = $form->controller->exportValues('Search');
|
||||
|
||||
$form->_task = $values['task'];
|
||||
$pledgeTasks = CRM_Pledge_Task::tasks();
|
||||
$form->assign('taskName', $pledgeTasks[$form->_task]);
|
||||
|
||||
$ids = array();
|
||||
if ($values['radio_ts'] == 'ts_sel') {
|
||||
foreach ($values as $name => $value) {
|
||||
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
|
||||
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$queryParams = $form->get('queryParams');
|
||||
$sortOrder = NULL;
|
||||
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
|
||||
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
|
||||
}
|
||||
$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
|
||||
CRM_Contact_BAO_Query::MODE_PLEDGE
|
||||
);
|
||||
$query->_distinctComponentClause = ' civicrm_pledge.id';
|
||||
$query->_groupByComponentClause = ' GROUP BY civicrm_pledge.id ';
|
||||
|
||||
$result = $query->searchQuery(0, 0, $sortOrder);
|
||||
while ($result->fetch()) {
|
||||
$ids[] = $result->pledge_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($ids)) {
|
||||
$form->_componentClause = ' civicrm_pledge.id IN ( ' . implode(',', $ids) . ' ) ';
|
||||
$form->assign('totalSelectedPledges', count($ids));
|
||||
}
|
||||
|
||||
$form->_pledgeIds = $form->_componentIds = $ids;
|
||||
|
||||
// set the context for redirection for any task actions
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
|
||||
$urlParams = 'force=1';
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$urlParams .= "&qfKey=$qfKey";
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/search', $urlParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the signer id, compute the contact id
|
||||
* since its used for things like send email
|
||||
*/
|
||||
public function setContactIDs() {
|
||||
$this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_pledgeIds,
|
||||
'civicrm_pledge'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple shell that derived classes can call to add buttons to
|
||||
* the form with a customized title for the main Submit
|
||||
*
|
||||
* @param string $title
|
||||
* Title of the main button.
|
||||
* @param string $nextType
|
||||
* @param string $backType
|
||||
* @param bool $submitOnce
|
||||
*/
|
||||
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => $nextType,
|
||||
'name' => $title,
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => $backType,
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
91
sites/all/modules/civicrm/CRM/Pledge/Form/Task/Delete.php
Normal file
91
sites/all/modules/civicrm/CRM/Pledge/Form/Task/Delete.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to delete a group of
|
||||
* participations. This class provides functionality for the actual
|
||||
* deletion.
|
||||
*/
|
||||
class CRM_Pledge_Form_Task_Delete extends CRM_Pledge_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. deleting one
|
||||
* specific pledge?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
//check for delete
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addDefaultButtons(ts('Delete Pledges'), 'done');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$deleted = $failed = 0;
|
||||
foreach ($this->_pledgeIds as $pledgeId) {
|
||||
if (CRM_Pledge_BAO_Pledge::deletePledge($pledgeId)) {
|
||||
$deleted++;
|
||||
}
|
||||
else {
|
||||
$failed++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
$msg = ts('%count pledge deleted.', array('plural' => '%count pledges deleted.', 'count' => $deleted));
|
||||
CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
|
||||
}
|
||||
|
||||
if ($failed) {
|
||||
CRM_Core_Session::setStatus(ts('1 could not be deleted.', array('plural' => '%count could not be deleted.', 'count' => $failed)), ts('Error'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
94
sites/all/modules/civicrm/CRM/Pledge/Form/Task/Print.php
Normal file
94
sites/all/modules/civicrm/CRM/Pledge/Form/Task/Print.php
Normal file
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Pledge_Form_Task_Print extends CRM_Pledge_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preprocess();
|
||||
|
||||
// set print view, so that print templates are called
|
||||
$this->controller->setPrint(1);
|
||||
|
||||
// get the formatted params
|
||||
$queryParams = $this->get('queryParams');
|
||||
|
||||
$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)
|
||||
);
|
||||
}
|
||||
|
||||
$selector = new CRM_Pledge_Selector_Search($queryParams, $this->_action, $this->_componentClause);
|
||||
$controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object - it consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// just need to add a javacript to popup the window for printing
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Print Pledge List'),
|
||||
'js' => array('onclick' => 'window.print()'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// redirect to the main search page after printing is over
|
||||
}
|
||||
|
||||
}
|
59
sites/all/modules/civicrm/CRM/Pledge/Form/Task/Result.php
Normal file
59
sites/all/modules/civicrm/CRM/Pledge/Form/Task/Result.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for displaying results.
|
||||
*/
|
||||
class CRM_Pledge_Form_Task_Result extends CRM_Pledge_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Pledge_Form_Task_SearchTaskHookSample extends CRM_Pledge_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$rows = array();
|
||||
// display name and pledge details of all selected contacts
|
||||
$pledgeIDs = implode(',', $this->_pledgeIds);
|
||||
|
||||
$query = "
|
||||
SELECT plg.amount as amount,
|
||||
plg.create_date as create_date,
|
||||
ct.display_name as display_name
|
||||
FROM civicrm_pledge plg
|
||||
INNER JOIN civicrm_contact ct ON ( plg.contact_id = ct.id )
|
||||
WHERE plg.id IN ( $pledgeIDs )";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$rows[] = array(
|
||||
'display_name' => $dao->display_name,
|
||||
'amount' => $dao->amount,
|
||||
'create_date' => CRM_Utils_Date::customFormat($dao->create_date),
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue