$locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
$this->assign('locDataURL', $locDataURL);
}
- if (count($employer) > 1) {
- $this->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
+ if (count($employer) > 0) {
$this->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $employer));
$orgOptions = array(
$this->addRadio('org_option', ts('options'), $orgOptions);
$this->setDefaults(array('org_option' => 0));
}
- elseif (count($employer) == 1) {
- foreach ($form->_employers as $id => $value) {
- $form->assign('orgId', $id);
- $form->assign('organizationName', $value['name']);
- }
- }
}
$profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW, NULL,
$this->_lineItem = $this->get('lineItem');
$this->_paymentProcessor = $this->get('paymentProcessor');
$this->_params = $this->controller->exportValues('Main');
+
+ if (!empty($this->_params['onbehalf_values'])) {
+ $this->_params['onbehalf'] = (array) json_decode($this->_params['onbehalf_values']);
+ }
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $this->get('amount');
if (isset($this->_params['amount'])) {
// if onbehalf-of-organization
if (!empty($this->_params['onbehalf_profile_id'])) {
// CRM-15182
- if (empty($this->_params['org_option']) && empty($this->_params['organization_id'])) {
- if (!empty($this->_params['onbehalfof_id'])) {
- $this->_params['organization_id'] = $this->_params['onbehalfof_id'];
- }
- else {
- $this->_params['organization_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_params['onbehalf']['organization_name'], 'id', 'display_name');
- }
- }
+ $this->_params['organization_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_params['onbehalf']['organization_name'], 'id', 'display_name');
$this->_params['organization_name'] = $this->_params['onbehalf']['organization_name'];
$addressBlocks = array(
$isCurrentEmployer = FALSE;
$dupeIDs = array();
$orgID = NULL;
- if (!empty($behalfOrganization['organization_id']) && empty($behalfOrganization['org_option'])) {
+ if (!empty($behalfOrganization['organization_id'])) {
$orgID = $behalfOrganization['organization_id'];
unset($behalfOrganization['organization_id']);
$isCurrentEmployer = TRUE;
// organization params in a separate variable, to make sure
// normal behavior is continued. And use that variable to
// process on-behalf-of functionality.
- if (!empty($this->_params['hidden_onbehalf_profile'])) {
+ if (!empty($this->_params['onbehalf_profile_id'])) {
$behalfOrganization = array();
$orgFields = array('organization_name', 'organization_id', 'org_option');
foreach ($orgFields as $fld) {
// If onbehalf-of-organization contribution / signup, add organization
// and it's location.
- if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
+ if (isset($params['onbehalf_profile_id']) && isset($behalfOrganization['organization_name'])) {
$ufFields = array();
foreach ($this->_fields['onbehalf'] as $name => $value) {
$ufFields[$name] = 1;
*/
public $_defaultMemTypeId;
- public $_relatedOrganizationFound;
-
- public $_onBehalfRequired = FALSE;
- public $_onbehalf = FALSE;
public $_paymentProcessors;
public $_membershipTypeValues;
}
// Build payment processor form
- if (empty($_GET['onbehalf'])) {
- CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
- }
+ CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
$config = CRM_Core_Config::singleton();
$this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID));
}
- // Return if we are in an ajax callback
- if ($this->_onbehalf && $this->_snippet) {
- return;
- }
-
$this->applyFilter('__ALL__', 'trim');
$this->add('text', "email-{$this->_bltID}",
ts('Email Address'),
$params['campaign_id'] = $params['contribution_campaign_id'];
}
- if (!empty($params['onbehalfof_id'])) {
- $params['organization_id'] = $params['onbehalfof_id'];
- }
-
$params['currencyID'] = $config->defaultCurrency;
if (!empty($params['priceSetId'])) {
}
$this->_submitValues = array_merge($this->_submitValues, $defaults);
+
+ if (!empty($this->_params['onbehalf_values'])) {
+ $defaults['onbehalf'] = (array) json_decode($this->_params['onbehalf_values']);
+ }
$this->setDefaults($defaults);
$values['entity_id'] = $this->_id;
}
}
- if ($contactID) {
- $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
-
- if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) {
- // renewal case - membership being renewed may or may not be for organization
- if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) {
- // if _membershipContactID belongs to employers list, we can say:
- $form->_relatedOrganizationFound = TRUE;
- }
- }
- elseif (!empty($form->_employers)) {
- // not a renewal case and _employers list is not empty
- $form->_relatedOrganizationFound = TRUE;
- }
-
- if ($params['is_for_organization'] != 2) {
- $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound);
- }
- else {
- $form->assign('onBehalfRequired', $form->_onBehalfRequired);
- }
-
- if (count($form->_employers) == 1) {
- foreach ($form->_employers as $id => $value) {
- $form->_organizationName = $value['name'];
- }
- }
+ $form->addElement('hidden', 'onbehalf_profile_id', $onBehalfProfileId);
+ // TODO: submitted values of on-behalf snippet aren't carried to successive form,
+ // so this is hackish fix for now to carry the submitted on-behalf profile values in json format
+ if (!empty($form->_submitValues['onbehalf'])) {
+ $form->addElement('hidden', 'onbehalf_values', json_encode($form->_submitValues['onbehalf']));
}
if (CRM_Utils_Array::value('is_for_organization', $params)) {
var orgOption = $("input:radio[name=org_option]:checked").val( );
selectCreateOrg(orgOption, false);
+ if ($('#is_for_organization').length) {
+ var type = $('#is_for_organization').is(':checked');
+ $('#is_for_organization').on('change', function() {
+ type = $(this).is(':checked') ? 1 : 0;
+ buildOnBehalfProfile(type);
+ });
+ if (type) {
+ buildOnBehalfProfile(type);
+ }
+ }
+ else if (!snippet) {
+ var type = {/literal}"{$onBehalfRequired}"{literal};
+ buildOnBehalfProfile(type);
+ }
+
+ $("input:radio[name='org_option']").click( function( ) {
+ var orgOption = $(this).val();
+ selectCreateOrg(orgOption, true);
+ });
+
+ var onbehalfof_id = $('#onbehalfof_id');
+ onbehalfof_id.change(function() {
+ setLocationDetails($(this).val());
+ }).change();
+
+ if (onbehalfof_id.length) {
+ setLocationDetails(onbehalfof_id.val());
+ }
+
function resetValues() {
// Don't trip chain-select when clearing values
$('.crm-chain-select-control', "#select_org div").select2('val', '');
if (typeof dataUrl != 'undefined') {CRM.loadPage(dataUrl, {target: '#on-behalf-block'})};
}
- if ($('#is_for_organization').length) {
- $('#is_for_organization').on('change', function() {
- var type = $(this).is(':checked') ? 1 : 0;
- buildOnBehalfProfile(type);
- });
- }
- else if (!snippet) {
- var type = {/literal}"{$onBehalfRequired}"{literal};
- buildOnBehalfProfile(type);
- }
-
- $("input:radio[name='org_option']").click( function( ) {
- var orgOption = $(this).val();
- selectCreateOrg(orgOption, true);
- });
-
- $('#onbehalfof_id').change(function() {
- setLocationDetails($(this).val());
- }).change();
-
function selectCreateOrg( orgOption, reset ) {
if (orgOption == 0) {
$("#onbehalfof_id").show().change();
else if ( orgOption == 1 ) {
$("input#onbehalf_organization_name").show();
$("#onbehalfof_id").hide();
+ reset = true;
}
if ( reset ) {
}
function setLocationDetails(contactID , reset) {
+ resetValues();
+
var submittedCID = {/literal}"{$submittedOnBehalf}"{literal};
var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
if (submittedOnBehalfInfo) {
}
}
- resetValues();
- var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
+ var profileID = {/literal}"{$profileId}"{literal};
+
+ var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + profileID;
$.ajax({
url : locationUrl,
dataType : "json",
{/if}
{else}
{if $prefix}
- {if $n eq 'organization_name'}
- {if !empty($form.onbehalfof_id)}
- {$form.onbehalfof_id.html}
- {/if}
- {if $organizationName}
- <span>
- ( <a id='createNewOrg' href="#" onclick="createNew( ); return false;">{ts}Enter a new organization{/ts}</a> )
- </span>
- {/if}
+ {if $n eq 'organization_name' && !empty($form.onbehalfof_id)}
+ {$form.onbehalfof_id.html}
{/if}
{$form.$prefix.$n.html}
{else}