First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
190
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Address.php
Normal file
190
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Address.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for address section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Address extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Location block no
|
||||
*/
|
||||
private $_locBlockNo;
|
||||
|
||||
/**
|
||||
* Do we want to parse street address.
|
||||
*/
|
||||
public $_parseStreetAddress;
|
||||
|
||||
/**
|
||||
* Store address values
|
||||
*/
|
||||
public $_values;
|
||||
|
||||
/**
|
||||
* Form action
|
||||
*/
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* Address id
|
||||
*/
|
||||
public $_addressId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* Since we are using same class / code to generate multiple instances
|
||||
* of address block, we need to generate unique form name for each,
|
||||
* hence calling parent constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
|
||||
$name = "Address_{$locBlockNo}";
|
||||
|
||||
parent::__construct(NULL, CRM_Core_Action::NONE, 'post', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', $this, TRUE, NULL, $_REQUEST);
|
||||
$this->assign('blockId', $this->_locBlockNo);
|
||||
|
||||
$addressSequence = CRM_Core_BAO_Address::addressSequence();
|
||||
$this->assign('addressSequence', $addressSequence);
|
||||
|
||||
$this->_values = array();
|
||||
$this->_addressId = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, NULL, $_REQUEST);
|
||||
|
||||
$this->_action = CRM_Core_Action::ADD;
|
||||
if ($this->_addressId) {
|
||||
$params = array('id' => $this->_addressId);
|
||||
$address = CRM_Core_BAO_Address::getValues($params, FALSE, 'id');
|
||||
$this->_values['address'][$this->_locBlockNo] = array_pop($address);
|
||||
$this->_action = CRM_Core_Action::UPDATE;
|
||||
}
|
||||
else {
|
||||
$this->_addressId = 0;
|
||||
}
|
||||
|
||||
$this->assign('action', $this->_action);
|
||||
$this->assign('addressId', $this->_addressId);
|
||||
|
||||
// parse street address, CRM-5450
|
||||
$this->_parseStreetAddress = $this->get('parseStreetAddress');
|
||||
if (!isset($this->_parseStreetAddress)) {
|
||||
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options'
|
||||
);
|
||||
$this->_parseStreetAddress = FALSE;
|
||||
if (!empty($addressOptions['street_address']) && !empty($addressOptions['street_address_parsing'])) {
|
||||
$this->_parseStreetAddress = TRUE;
|
||||
}
|
||||
$this->set('parseStreetAddress', $this->_parseStreetAddress);
|
||||
}
|
||||
$this->assign('parseStreetAddress', $this->_parseStreetAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for an address object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Contact_Form_Edit_Address::buildQuickForm($this, $this->_locBlockNo, TRUE, TRUE);
|
||||
$this->addFormRule(array('CRM_Contact_Form_Edit_Address', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $this->_values;
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
//set address block defaults
|
||||
if (!empty($defaults['address'])) {
|
||||
CRM_Contact_Form_Edit_Address::setDefaultValues($defaults, $this);
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
|
||||
if ($this->_locBlockNo == 1) {
|
||||
$address['is_primary'] = TRUE;
|
||||
$address['location_type_id'] = $locationType->id;
|
||||
}
|
||||
|
||||
$address['country_id'] = $config->defaultContactCountry;
|
||||
$address['state_province_id'] = $config->defaultContactStateProvince;
|
||||
$defaults['address'][$this->_locBlockNo] = $address;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save address
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
|
||||
// process shared contact address.
|
||||
CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']);
|
||||
|
||||
if ($this->_parseStreetAddress) {
|
||||
CRM_Contact_Form_Contact::parseAddress($params);
|
||||
}
|
||||
|
||||
if ($this->_addressId > 0) {
|
||||
$params['address'][$this->_locBlockNo]['id'] = $this->_addressId;
|
||||
}
|
||||
|
||||
// save address changes
|
||||
$address = CRM_Core_BAO_Address::create($params, TRUE);
|
||||
|
||||
$this->log();
|
||||
$this->ajaxResponse['addressId'] = $address[0]->id;
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for communication preferences inline edit section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_CommunicationPreferences extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements for communication preferences.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Contact_Form_Edit_CommunicationPreferences::buildQuickForm($this);
|
||||
$this->addFormRule(array('CRM_Contact_Form_Edit_CommunicationPreferences', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
if (!empty($defaults['preferred_language'])) {
|
||||
$languages = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
|
||||
$defaults['preferred_language'] = CRM_Utils_Array::key($defaults['preferred_language'], $languages);
|
||||
}
|
||||
|
||||
// CRM-7119: set preferred_language to default if unset
|
||||
if (empty($defaults['preferred_language'])) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$defaults['preferred_language'] = $config->lcMessages;
|
||||
}
|
||||
|
||||
// CRM-19135: where CRM_Core_BAO_Contact::getValues() set label as a default value instead of reserved 'value',
|
||||
// the code is to ensure we always set default to value instead of label
|
||||
if (!empty($defaults['preferred_mail_format'])) {
|
||||
$defaults['preferred_mail_format'] = array_search($defaults['preferred_mail_format'], CRM_Core_SelectValues::pmf());
|
||||
}
|
||||
|
||||
if (empty($defaults['communication_style_id'])) {
|
||||
$defaults['communication_style_id'] = array_pop(CRM_Core_OptionGroup::values('communication_style', TRUE, NULL, NULL, 'AND is_default = 1'));
|
||||
}
|
||||
|
||||
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
|
||||
$name = "{$greeting}_display";
|
||||
$this->assign($name, CRM_Utils_Array::value($name, $defaults));
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save communication preferences
|
||||
|
||||
// this is a chekbox, so mark false if we dont get a POST value
|
||||
$params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE);
|
||||
$params['contact_type'] = $this->_contactType;
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
if (!isset($params['preferred_communication_method'])) {
|
||||
$params['preferred_communication_method'] = 'null';
|
||||
}
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for contact info section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_ContactInfo extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
// Build contact type specific fields
|
||||
$class = 'CRM_Contact_Form_Edit_' . $this->_contactType;
|
||||
$class::buildQuickForm($this, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return parent::setDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save contact info
|
||||
$params['contact_type'] = $this->_contactType;
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
// Saving current employer affects relationship tab, and possibly related memberships and contributions
|
||||
$this->ajaxResponse['updateTabs'] = array(
|
||||
'#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId),
|
||||
);
|
||||
if (CRM_Core_Permission::access('CiviContribute')) {
|
||||
$this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
|
||||
}
|
||||
if (CRM_Core_Permission::access('CiviMember')) {
|
||||
$this->ajaxResponse['updateTabs']['#tab_member'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
|
||||
}
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for contact name section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_ContactName extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
// Build contact type specific fields
|
||||
$class = 'CRM_Contact_Form_Edit_' . $this->_contactType;
|
||||
$class::buildQuickForm($this, 1);
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_ContactName', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
* @param CRM_Contact_Form_Inline_ContactName $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors, $form) {
|
||||
if (empty($fields['first_name']) && empty($fields['last_name'])
|
||||
&& empty($fields['organization_name'])
|
||||
&& empty($fields['household_name'])) {
|
||||
$emails = civicrm_api3('Email', 'getcount', array('contact_id' => $form->_contactId));
|
||||
if (!$emails) {
|
||||
$errorField = $form->_contactType == 'Individual' ? 'last' : strtolower($form->_contactType);
|
||||
$errors[$errorField . '_name'] = ts('Contact with no email must have a name.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save contact info
|
||||
$params['contact_type'] = $this->_contactType;
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
105
sites/all/modules/civicrm/CRM/Contact/Form/Inline/CustomData.php
Normal file
105
sites/all/modules/civicrm/CRM/Contact/Form/Inline/CustomData.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for custom data section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_CustomData extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Custom group id.
|
||||
*
|
||||
* @int
|
||||
*/
|
||||
public $_groupID;
|
||||
|
||||
/**
|
||||
* Entity type of the table id.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entityType;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE, NULL, $_REQUEST);
|
||||
$this->assign('customGroupId', $this->_groupID);
|
||||
$customRecId = CRM_Utils_Request::retrieve('customRecId', 'Positive', $this, FALSE, 1, $_REQUEST);
|
||||
$cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE, 1, $_REQUEST);
|
||||
$subType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',');
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, $cgcount,
|
||||
$this->_contactType, $this->_contactId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for custom data.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// Process / save custom data
|
||||
// Get the form values and groupTree
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
CRM_Core_BAO_CustomValueTable::postProcess($params,
|
||||
'civicrm_contact',
|
||||
$this->_contactId,
|
||||
$this->_entityType
|
||||
);
|
||||
|
||||
$this->log();
|
||||
|
||||
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for demographics section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Demographics extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Contact_Form_Edit_Demographics::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save demographics
|
||||
if (empty($params['is_deceased'])) {
|
||||
$params['is_deceased'] = FALSE;
|
||||
$params['deceased_date'] = NULL;
|
||||
}
|
||||
|
||||
$params['contact_type'] = 'Individual';
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
204
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Email.php
Normal file
204
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Email.php
Normal file
|
@ -0,0 +1,204 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Email object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Email extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Email addresses of the contact that is been viewed.
|
||||
*/
|
||||
private $_emails = array();
|
||||
|
||||
/**
|
||||
* No of email blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Whether this contact has a first/last/organization/household name
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $contactHasName;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing email addresses
|
||||
$email = new CRM_Core_BAO_Email();
|
||||
$email->contact_id = $this->_contactId;
|
||||
|
||||
$this->_emails = CRM_Core_BAO_Block::retrieveBlock($email, NULL);
|
||||
|
||||
// Check if this contact has a first/last/organization/household name
|
||||
if ($this->_contactType == 'Individual') {
|
||||
$this->contactHasName = (bool) (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'last_name')
|
||||
|| CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'first_name'));
|
||||
}
|
||||
else {
|
||||
$this->contactHasName = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, strtolower($this->_contactType) . '_name');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for an email object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_emails) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_emails);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_Email::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_Email', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
* @param CRM_Contact_Form_Inline_Email $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors, $form) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['email']) && is_array($fields['email'])) {
|
||||
foreach ($fields['email'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["email[1][is_primary]"] = ts('One email should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["email[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one email can be marked as primary.');
|
||||
}
|
||||
}
|
||||
if (!$hasData && !$form->contactHasName) {
|
||||
$errors["email[1][email]"] = ts('Contact with no name must have an email.');
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_emails)) {
|
||||
foreach ($this->_emails as $id => $value) {
|
||||
$defaults['email'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['email'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save emails
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['email']['isIdSet'] = TRUE;
|
||||
foreach ($this->_emails as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['email'][$count])) {
|
||||
$params['email'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('email', $params);
|
||||
|
||||
// If contact has no name, set primary email as display name
|
||||
// TODO: This should be handled in the BAO for the benefit of the api, etc.
|
||||
if (!$this->contactHasName) {
|
||||
foreach ($params['email'] as $email) {
|
||||
if ($email['is_primary']) {
|
||||
CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'display_name', $email['email']);
|
||||
CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'sort_name', $email['email']);
|
||||
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactname-content');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/IM.php
Normal file
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/IM.php
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an IM object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_IM extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Ims of the contact that is been viewed.
|
||||
*/
|
||||
private $_ims = array();
|
||||
|
||||
/**
|
||||
* No of im blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing ims
|
||||
$im = new CRM_Core_BAO_IM();
|
||||
$im->contact_id = $this->_contactId;
|
||||
|
||||
$this->_ims = CRM_Core_BAO_Block::retrieveBlock($im, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for im object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_ims) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_ims);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_IM::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_IM', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['im']) && is_array($fields['im'])) {
|
||||
foreach ($fields['im'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
if (!$primaryID && !empty($blockValues['im'])) {
|
||||
$primaryID = $blockValues['im'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["im[1][is_primary]"] = ts('One IM should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["im[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one IM can be marked as primary.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_ims)) {
|
||||
foreach ($this->_ims as $id => $value) {
|
||||
$defaults['im'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['im'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save IMs
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['im']['isIdSet'] = TRUE;
|
||||
foreach ($this->_ims as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['im'][$count])) {
|
||||
$params['im'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('im', $params);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
99
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Lock.php
Normal file
99
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Lock.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auxiliary class to provide support for locking (and ignoring locks on) contact records.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Lock {
|
||||
|
||||
/**
|
||||
* This function provides the HTML form elements.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
* @param int $contactID
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $contactID) {
|
||||
// We provide a value for oplock_ts to client, but JS uses it carefully
|
||||
// -- i.e. when loading the first inline form, JS copies oplock_ts to a
|
||||
// global value, and that global value is used for future form submissions.
|
||||
// Any time a form is submitted, the value will be updated. This
|
||||
// handles cases like:
|
||||
// - V1:open V1.phone:open V1.email:open V1.email:submit V1.phone:submit
|
||||
// - V1:open E1:open E1:submit V1.email:open V1.email:submit
|
||||
// - V1:open V1.email:open E1:open E1:submit V1.email:submit V1:lock
|
||||
$timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
|
||||
$form->addElement('hidden', 'oplock_ts', $timestamps['modified_date'], array('id' => 'oplock_ts'));
|
||||
$form->addFormRule(array('CRM_Contact_Form_Inline_Lock', 'formRule'), $contactID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that oplock_ts hasn't changed in the underlying DB.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $contactID = NULL) {
|
||||
$errors = array();
|
||||
|
||||
$timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
|
||||
if ($fields['oplock_ts'] != $timestamps['modified_date']) {
|
||||
// Inline buttons generated via JS
|
||||
$open = sprintf("<div class='update_oplock_ts' data:update_oplock_ts='%s'>", $timestamps['modified_date']);
|
||||
$close = "</div>";
|
||||
$errors['oplock_ts'] = $open . ts('This record was modified by another user!') . $close;
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return any post-save data.
|
||||
*
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return array
|
||||
* extra options to return in JSON
|
||||
*/
|
||||
public static function getResponse($contactID) {
|
||||
$timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
|
||||
return array('oplock_ts' => $timestamps['modified_date']);
|
||||
}
|
||||
|
||||
}
|
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/OpenID.php
Normal file
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/OpenID.php
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an OpenID object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_OpenID extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Ims of the contact that is been viewed.
|
||||
*/
|
||||
private $_openids = array();
|
||||
|
||||
/**
|
||||
* No of openid blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing openids
|
||||
$openid = new CRM_Core_BAO_OpenID();
|
||||
$openid->contact_id = $this->_contactId;
|
||||
|
||||
$this->_openids = CRM_Core_BAO_Block::retrieveBlock($openid, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for openID object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_openids) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_openids);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_OpenID::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_OpenID', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['openid']) && is_array($fields['openid'])) {
|
||||
foreach ($fields['openid'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
if (!$primaryID && !empty($blockValues['openid'])) {
|
||||
$primaryID = $blockValues['openid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["openid[1][is_primary]"] = ts('One OpenID should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["openid[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one OpenID can be marked as primary.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_openids)) {
|
||||
foreach ($this->_openids as $id => $value) {
|
||||
$defaults['openid'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['openid'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save openID
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['openid']['isIdSet'] = TRUE;
|
||||
foreach ($this->_openids as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['openid'][$count])) {
|
||||
$params['openid'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('openid', $params);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
174
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Phone.php
Normal file
174
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Phone.php
Normal file
|
@ -0,0 +1,174 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Phone object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Phone extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Phones of the contact that is been viewed
|
||||
*/
|
||||
private $_phones = array();
|
||||
|
||||
/**
|
||||
* No of phone blocks for inline edit
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing phones
|
||||
$phone = new CRM_Core_BAO_Phone();
|
||||
$phone->contact_id = $this->_contactId;
|
||||
|
||||
$this->_phones = CRM_Core_BAO_Block::retrieveBlock($phone, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for phone object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_phones) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_phones);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_Phone::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_Phone', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['phone']) && is_array($fields['phone'])) {
|
||||
$primaryID = NULL;
|
||||
foreach ($fields['phone'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
if (!$primaryID && !empty($blockValues['phone'])) {
|
||||
$primaryID = $blockValues['phone'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["phone[1][is_primary]"] = ts('One phone should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["phone[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one phone can be marked as primary.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_phones)) {
|
||||
foreach ($this->_phones as $id => $value) {
|
||||
$defaults['phone'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['phone'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save phones
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['phone']['isIdSet'] = TRUE;
|
||||
foreach ($this->_phones as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['phone'][$count])) {
|
||||
$params['phone'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('phone', $params);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
131
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Website.php
Normal file
131
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Website.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Website object,
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Website extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Websitess of the contact that is been viewed.
|
||||
*/
|
||||
private $_websites = array();
|
||||
|
||||
/**
|
||||
* No of website blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing websites
|
||||
$params = array('contact_id' => $this->_contactId);
|
||||
$values = array();
|
||||
$this->_websites = CRM_Core_BAO_Website::getValues($params, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for website object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_websites) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_websites);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_Website::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_websites)) {
|
||||
foreach ($this->_websites as $id => $value) {
|
||||
$defaults['website'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// set the default website type
|
||||
$defaults['website'][1]['website_type_id'] = key(CRM_Core_OptionGroup::values('website_type',
|
||||
FALSE, FALSE, FALSE, ' AND is_default = 1'
|
||||
));
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
foreach ($this->_websites as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['website'][$count])) {
|
||||
$params['website'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
// Process / save websites
|
||||
CRM_Core_BAO_Website::create($params['website'], $this->_contactId, TRUE);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue