First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,442 @@
<?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 is used to build address block.
*/
class CRM_Contact_Form_Edit_Address {
/**
* Build form for address input fields.
*
* @param CRM_Core_Form $form
* @param int $addressBlockCount
* The index of the address array (if multiple addresses on a page).
* @param bool $sharing
* False, if we want to skip the address sharing features.
* @param bool $inlineEdit
* True when edit used in inline edit.
*/
public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE) {
// passing this via the session is AWFUL. we need to fix this
if (!$addressBlockCount) {
$blockId = ($form->get('Address_Block_Count')) ? $form->get('Address_Block_Count') : 1;
}
else {
$blockId = $addressBlockCount;
}
$config = CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->applyFilter('__ALL__', 'trim');
$js = array();
if (!$inlineEdit) {
$js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL);
}
//make location type required for inline edit
$form->addField("address[$blockId][location_type_id]", array('entity' => 'address', 'class' => 'eight', 'option_url' => NULL) + $js, $inlineEdit);
if (!$inlineEdit) {
$js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
}
$form->addField(
"address[$blockId][is_primary]", array(
'entity' => 'address',
'label' => ts('Primary location for this contact'),
'text' => ts('Primary location for this contact')) + $js);
if (!$inlineEdit) {
$js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
}
$form->addField(
"address[$blockId][is_billing]", array(
'entity' => 'address',
'label' => ts('Billing location for this contact'),
'text' => ts('Billing location for this contact')) + $js);
// hidden element to store master address id
$form->addField("address[$blockId][master_id]", array('entity' => 'address', 'type' => 'hidden'));
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'address_options', TRUE, NULL, TRUE
);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = array(
'address_name',
'street_address',
'supplemental_address_1',
'supplemental_address_2',
'supplemental_address_3',
'city',
'postal_code',
'postal_code_suffix',
'country_id',
'state_province_id',
'county_id',
'geo_code_1',
'geo_code_2',
'street_number',
'street_name',
'street_unit',
);
foreach ($elements as $name) {
//Remove id from name, to allow comparison against enabled addressOtions.
$nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
// Skip fields which are not enabled in the address options.
if (empty($addressOptions[$nameWithoutID])) {
$continue = TRUE;
//Don't skip street parsed fields when parsing is enabled.
if (in_array($nameWithoutID, array(
'street_number',
'street_name',
'street_unit',
)) && !empty($addressOptions['street_address_parsing'])
) {
$continue = FALSE;
}
if ($continue) {
continue;
}
}
if ($name == 'address_name') {
$name = 'name';
}
$params = array('entity' => 'address');
if ($name == 'postal_code_suffix') {
$params['label'] = ts('Suffix');
}
$form->addField("address[$blockId][$name]", $params);
}
$entityId = NULL;
if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
$entityId = $form->_values['address'][$blockId]['id'];
}
// CRM-11665 geocode override option
$geoCode = FALSE;
if (!empty($config->geocodeMethod)) {
$geoCode = TRUE;
$form->addElement('checkbox',
"address[$blockId][manual_geo_code]",
ts('Override automatic geocoding')
);
}
$form->assign('geoCode', $geoCode);
// Process any address custom data -
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $entityId);
if (isset($groupTree) && is_array($groupTree)) {
// use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
// make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
foreach ($groupTree as $id => $group) {
foreach ($group['fields'] as $fldId => $field) {
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
$groupTree[$id]['fields'][$fldId]['element_name'] = "address[$blockId][{$field['element_name']}]";
}
}
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
// since we change element name for address custom data, we need to format the setdefault values
$addressDefaults = array();
foreach ($defaults as $key => $val) {
if (empty($val)) {
continue;
}
// inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
// this works for all types custom data
$keyValues = explode('[', str_replace(']', '', $key));
$addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
}
$form->setDefaults($addressDefaults);
// we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
// And we can't set it to 'address_' because we want to set it in a slightly different format.
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
// during contact editing : if no address is filled
// required custom data must not produce 'required' form rule error
// more handling done in formRule func
CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
$template = CRM_Core_Smarty::singleton();
$tplGroupTree = $template->get_template_vars('address_groupTree');
$tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;
$form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
// unset the temp smarty var that got created
$form->assign('dnc_groupTree', NULL);
}
// address custom data processing ends ..
if ($sharing) {
// shared address
$form->addElement('checkbox', "address[$blockId][use_shared_address]", NULL, ts('Use another contact\'s address'));
// Override the default profile links to add address form
$profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array(
'new_individual',
'new_organization',
'new_household',
), 'shared_address');
$form->addEntityRef("address[$blockId][master_contact_id]", ts('Share With'), array('create' => $profileLinks));
}
}
/**
* Check for correct state / country mapping.
*
* @param array $fields
* @param array $files
* @param CRM_Core_Form $self
*
* @return array|bool
* if no errors
*/
public static function formRule($fields, $files = array(), $self = NULL) {
$errors = array();
$customDataRequiredFields = array();
if ($self && property_exists($self, '_addressRequireOmission')) {
$customDataRequiredFields = explode(',', $self->_addressRequireOmission);
}
if (!empty($fields['address']) && is_array($fields['address'])) {
foreach ($fields['address'] as $instance => $addressValues) {
if (CRM_Utils_System::isNull($addressValues)) {
// DETACH 'required' form rule error to
// custom data only if address data not exists upon submission
if (!empty($customDataRequiredFields)) {
foreach ($customDataRequiredFields as $customElementName) {
$elementName = "address[$instance][$customElementName]";
if ($self->getElementError($elementName)) {
// set element error to none
$self->setElementError($elementName, NULL);
}
}
}
continue;
}
// DETACH 'required' form rule error to
// custom data if address data not exists upon submission
// or if master address is selected
if (!empty($customDataRequiredFields) && (!CRM_Core_BAO_Address::dataExists($addressValues) || !empty($addressValues['master_id']))) {
foreach ($customDataRequiredFields as $customElementName) {
$elementName = "address[$instance][$customElementName]";
if ($self->getElementError($elementName)) {
// set element error to none
$self->setElementError($elementName, NULL);
}
}
}
if (!empty($addressValues['use_shared_address']) && empty($addressValues['master_id'])) {
$errors["address[$instance][use_shared_address]"] = ts('Please select valid shared contact or a contact with valid address.');
}
}
}
return empty($errors) ? TRUE : $errors;
}
/**
* Set default values for address block.
*
* @param array $defaults
* Defaults associated array.
* @param CRM_Core_Form $form
* Form object.
*/
public static function setDefaultValues(&$defaults, &$form) {
$addressValues = array();
if (isset($defaults['address']) && is_array($defaults['address']) &&
!CRM_Utils_System::isNull($defaults['address'])
) {
// start of contact shared adddress defaults
$sharedAddresses = array();
$masterAddress = array();
// get contact name of shared contact names
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
foreach ($defaults['address'] as $key => $addressValue) {
if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
$master_cid = $shareAddressContactNames[$addressValue['master_id']]['contact_id'];
$sharedAddresses[$key]['shared_address_display'] = array(
'address' => $addressValue['display'],
'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
'options' => CRM_Core_BAO_Address::getValues(array(
'entity_id' => $master_cid,
'contact_id' => $master_cid,
)),
'master_id' => $addressValue['master_id'],
);
$defaults['address'][$key]['master_contact_id'] = $master_cid;
}
else {
$defaults['address'][$key]['use_shared_address'] = 0;
}
//check if any address is shared by any other contacts
$masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']);
}
$form->assign('sharedAddresses', $sharedAddresses);
$form->assign('masterAddress', $masterAddress);
// end of shared address defaults
// start of parse address functionality
// build street address, CRM-5450.
if ($form->_parseStreetAddress) {
$parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
foreach ($defaults['address'] as $cnt => & $address) {
$streetAddress = NULL;
foreach (array(
'street_number',
'street_number_suffix',
'street_name',
'street_unit',
) as $fld) {
if (in_array($fld, array(
'street_name',
'street_unit',
))) {
$streetAddress .= ' ';
}
// CRM-17619 - if the street number suffix begins with a number, add a space
$numsuffix = CRM_Utils_Array::value($fld, $address);
if ($fld === 'street_number_suffix' && !empty($numsuffix)) {
if (ctype_digit(substr($numsuffix, 0, 1))) {
$streetAddress .= ' ';
}
}
$streetAddress .= CRM_Utils_Array::value($fld, $address);
}
$streetAddress = trim($streetAddress);
if (!empty($streetAddress)) {
$address['street_address'] = $streetAddress;
}
if (isset($address['street_number'])) {
// CRM-17619 - if the street number suffix begins with a number, add a space
$thesuffix = CRM_Utils_Array::value('street_number_suffix', $address);
if ($thesuffix) {
if (ctype_digit(substr($thesuffix, 0, 1))) {
$address['street_number'] .= " ";
}
}
$address['street_number'] .= $thesuffix;
}
// build array for set default.
foreach ($parseFields as $field) {
$addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
}
// don't load fields, use js to populate.
foreach (array('street_number', 'street_name', 'street_unit') as $f) {
if (isset($address[$f])) {
unset($address[$f]);
}
}
}
$form->assign('allAddressFieldValues', json_encode($addressValues));
//hack to handle show/hide address fields.
$parsedAddress = array();
if ($form->_contactId && !empty($_POST['address']) && is_array($_POST['address'])
) {
foreach ($_POST['address'] as $cnt => $values) {
$showField = 'streetAddress';
foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
if (!empty($values[$fld])) {
$showField = 'addressElements';
break;
}
}
$parsedAddress[$cnt] = $showField;
}
}
$form->assign('showHideAddressFields', $parsedAddress);
$form->assign('loadShowHideAddressFields', empty($parsedAddress) ? FALSE : TRUE);
}
// end of parse address functionality
}
}
/**
* Store required custom data info.
*
* @param CRM_Core_Form $form
* @param array $groupTree
*/
public static function storeRequiredCustomDataInfo(&$form, $groupTree) {
if (in_array(CRM_Utils_System::getClassName($form), array('CRM_Contact_Form_Contact', 'CRM_Contact_Form_Inline_Address'))) {
$requireOmission = NULL;
foreach ($groupTree as $csId => $csVal) {
// only process Address entity fields
if ($csVal['extends'] != 'Address') {
continue;
}
foreach ($csVal['fields'] as $cdId => $cdVal) {
if ($cdVal['is_required']) {
$elementName = $cdVal['element_name'];
if (in_array($elementName, $form->_required)) {
// store the omitted rule for a element, to be used later on
$requireOmission .= $cdVal['element_custom_name'] . ',';
}
}
}
}
$form->_addressRequireOmission = rtrim($requireOmission, ',');
}
}
}

View file

@ -0,0 +1,240 @@
<?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 Communication Preferences object.
*/
class CRM_Contact_Form_Edit_CommunicationPreferences {
/**
* Greetings.
*
* @var array
*/
static $greetings = array();
/**
* Build the form object elements for Communication Preferences object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
*/
public static function buildQuickForm(&$form) {
// since the pcm - preferred communication method is logically
// grouped hence we'll use groups of HTML_QuickForm
// checkboxes for DO NOT phone, email, mail
// we take labels from SelectValues
$privacy = $commPreff = $commPreference = array();
$privacyOptions = CRM_Core_SelectValues::privacy();
// we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
unset($privacyOptions['is_opt_out']);
foreach ($privacyOptions as $name => $label) {
$privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
}
$form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;<br/>');
// preferred communication method
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
foreach ($comm as $value => $title) {
$commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
}
$form->addField('preferred_communication_method', array('entity' => 'contact', 'type' => 'CheckBoxGroup'));
$form->addField('preferred_language', array('entity' => 'contact'));
if (!empty($privacyOptions)) {
$commPreference['privacy'] = $privacyOptions;
}
if (!empty($comm)) {
$commPreference['preferred_communication_method'] = $comm;
}
//using for display purpose.
$form->assign('commPreference', $commPreference);
$form->addField('preferred_mail_format', array('entity' => 'contact', 'label' => ts('Email Format')));
$form->addField('is_opt_out', array('entity' => 'contact', 'label' => ts('NO BULK EMAILS (User Opt Out)')));
$form->addField('communication_style_id', array('entity' => 'contact', 'type' => 'RadioGroup'));
//check contact type and build filter clause accordingly for greeting types, CRM-4575
$greetings = self::getGreetingFields($form->_contactType);
foreach ($greetings as $greeting => $fields) {
$filter = array(
'contact_type' => $form->_contactType,
'greeting_type' => $greeting,
);
//add addressee in Contact form
$greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
if (!empty($greetingTokens)) {
$form->addElement('select', $fields['field'], $fields['label'],
array(
'' => ts('- select -'),
) + $greetingTokens
);
//custom addressee
$form->addElement('text', $fields['customField'], $fields['customLabel'],
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']
);
}
}
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param CRM_Contact_Form_Edit_CommunicationPreferences $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
//CRM-4575
$greetings = self::getGreetingFields($self->_contactType);
foreach ($greetings as $greeting => $details) {
$customizedValue = CRM_Core_PseudoConstant::getKey('CRM_Contact_BAO_Contact', $details['field'], 'Customized');
if (CRM_Utils_Array::value($details['field'], $fields) == $customizedValue && empty($fields[$details['customField']])) {
$errors[$details['customField']] = ts('Custom %1 is a required field if %1 is of type Customized.',
array(1 => $details['label'])
);
}
}
if (array_key_exists('preferred_mail_format', $fields) && empty($fields['preferred_mail_format'])) {
$errors['preferred_mail_format'] = ts('Please select an email format preferred by this contact.');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Set default values for the form.
*
* @param CRM_Core_Form $form
* @param array $defaults
*/
public static function setDefaultValues(&$form, &$defaults) {
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;
}
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'));
}
// CRM-17778 -- set preferred_mail_format to default if unset
if (empty($defaults['preferred_mail_format'])) {
$defaults['preferred_mail_format'] = 'Both';
}
else {
$defaults['preferred_mail_format'] = array_search($defaults['preferred_mail_format'], CRM_Core_SelectValues::pmf());
}
//set default from greeting types CRM-4575, CRM-9739
if ($form->_action & CRM_Core_Action::ADD) {
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
if (empty($defaults[$greeting . '_id'])) {
if ($defaultGreetingTypeId = CRM_Contact_BAO_Contact_Utils::defaultGreeting($form->_contactType, $greeting)
) {
$defaults[$greeting . '_id'] = $defaultGreetingTypeId;
}
}
}
}
else {
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
$name = "{$greeting}_display";
$form->assign($name, CRM_Utils_Array::value($name, $defaults));
}
}
}
/**
* Set array of greeting fields.
*
* @param string $contactType
*/
public static function getGreetingFields($contactType) {
if (empty(self::$greetings[$contactType])) {
self::$greetings[$contactType] = array();
$js = array(
'onfocus' => "if (!this.value) { this.value='Dear ';} else return false",
'onblur' => "if ( this.value == 'Dear') { this.value='';} else return false",
);
self::$greetings[$contactType] = array(
'addressee' => array(
'field' => 'addressee_id',
'customField' => 'addressee_custom',
'label' => ts('Addressee'),
'customLabel' => ts('Custom Addressee'),
'js' => NULL,
),
'email_greeting' => array(
'field' => 'email_greeting_id',
'customField' => 'email_greeting_custom',
'label' => ts('Email Greeting'),
'customLabel' => ts('Custom Email Greeting'),
'js' => $js,
),
'postal_greeting' => array(
'field' => 'postal_greeting_id',
'customField' => 'postal_greeting_custom',
'label' => ts('Postal Greeting'),
'customLabel' => ts('Custom Postal Greeting'),
'js' => $js,
),
);
}
return self::$greetings[$contactType];
}
}

View file

@ -0,0 +1,108 @@
<?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 Demographics object.
*/
class CRM_Contact_Form_Edit_CustomData {
/**
* Build all the data structures needed to build the form.
*
* @param CRM_Core_Form $form
*/
public static function preProcess(&$form) {
$form->_type = CRM_Utils_Request::retrieve('type', 'String');
$form->_subType = CRM_Utils_Request::retrieve('subType', 'String');
//build the custom data as other blocks.
//$form->assign( "addBlock", false );
if ($form->_type) {
$form->_addBlockName = 'CustomData';
$form->assign("addBlock", TRUE);
$form->assign("blockName", $form->_addBlockName);
}
CRM_Custom_Form_CustomData::preProcess($form, NULL, $form->_subType, NULL,
($form->_type) ? $form->_type : $form->_contactType
);
//assign group tree after build.
$form->assign('groupTree', $form->_groupTree);
}
/**
* Build the form object elements for CustomData object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
*/
public static function buildQuickForm(&$form) {
if (!empty($form->_submitValues)) {
if ($customValueCount = CRM_Utils_Array::value('hidden_custom_group_count', $form->_submitValues)) {
if (is_array($customValueCount)) {
if (array_key_exists(0, $customValueCount)) {
unset($customValueCount[0]);
}
$form->_customValueCount = $customValueCount;
$form->assign('customValueCount', $customValueCount);
}
}
}
CRM_Custom_Form_CustomData::buildQuickForm($form);
//build custom data.
$contactSubType = NULL;
if (!empty($_POST["hidden_custom"]) && !empty($_POST['contact_sub_type'])) {
$contactSubType = $_POST['contact_sub_type'];
}
else {
$contactSubType = CRM_Utils_Array::value('contact_sub_type', $form->_values);
}
$form->assign('contactType', $form->_contactType);
$form->assign('contactSubType', $contactSubType);
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @param CRM_Core_Form $form
* @param array $defaults
*/
public static function setDefaultValues(&$form, &$defaults) {
$defaults += CRM_Custom_Form_CustomData::setDefaultValues($form);
}
}

View file

@ -0,0 +1,65 @@
<?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 Demographics object.
*/
class CRM_Contact_Form_Edit_Demographics {
/**
* Build the form object elements for Demographics object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
*/
public static function buildQuickForm(&$form) {
$form->addField('gender_id', array('entity' => 'contact', 'type' => 'Radio', 'allowClear' => TRUE));
$form->addField('birth_date', array('entity' => 'contact'), FALSE, FALSE);
$form->addField('is_deceased', array('entity' => 'contact', 'label' => ts('Contact is Deceased'), 'onclick' => "showDeceasedDate()"));
$form->addField('deceased_date', array('entity' => 'contact'), FALSE, FALSE);
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @param CRM_Core_Form $form
* @param array $defaults
*/
public static function setDefaultValues(&$form, &$defaults) {
}
}

View file

@ -0,0 +1,118 @@
<?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_Edit_Email {
/**
* Build the form object elements for an email object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
// passing this via the session is AWFUL. we need to fix this
if (!$blockCount) {
$blockId = ($form->get('Email_Block_Count')) ? $form->get('Email_Block_Count') : 1;
}
else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Email box
$form->addField("email[$blockId][email]", array('entity' => 'email'));
$form->addRule("email[$blockId][email]", ts('Email is not valid.'), 'email');
if (isset($form->_contactType) || $blockEdit) {
//Block type
$form->addField("email[$blockId][location_type_id]", array('entity' => 'email', 'placeholder' => NULL, 'class' => 'eight', 'option_url' => NULL));
//TODO: Refactor on_hold field to select.
$multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
//On-hold select
if ($multipleBulk) {
$holdOptions = array(
0 => ts('- select -'),
1 => ts('On Hold Bounce'),
2 => ts('On Hold Opt Out'),
);
$form->addElement('select', "email[$blockId][on_hold]", '', $holdOptions);
}
else {
$form->addField("email[$blockId][on_hold]", array('entity' => 'email', 'type' => 'advcheckbox'));
}
//Bulkmail checkbox
$form->assign('multipleBulk', $multipleBulk);
if ($multipleBulk) {
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
$form->addElement('advcheckbox', "email[$blockId][is_bulkmail]", NULL, '', $js);
}
else {
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "email[$blockId][is_bulkmail]", '', '', '1', $js);
}
//is_Primary radio
$js = array('id' => "Email_" . $blockId . "_IsPrimary");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js);
if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
$form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'),
array('rows' => 2, 'cols' => 40)
);
$form->add('wysiwyg', "email[$blockId][signature_html]", ts('Signature (HTML)'),
array('rows' => 2, 'cols' => 40)
);
}
}
}
}

View file

@ -0,0 +1,101 @@
<?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 to the Contact Form class.
*
* Does this by implementing a small set of static methods.
*/
class CRM_Contact_Form_Edit_Household {
/**
* This function provides the HTML form elements that are specific to the Household Contact Type.
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
// household_name
$form->addField('household_name');
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addField('nick_name');
$form->addField('contact_source', array('label' => ts('Source')));
}
if (!$inlineEditMode) {
$form->addField('external_identifier', array('label' => ts('External ID')));
$form->addRule('external_identifier',
ts('External ID already exists in Database.'),
'objectExists',
array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
);
}
}
/**
* Add rule for household.
*
* @param array $fields
* Array of form values.
* @param array $files
* Unused.
* @param int $contactID
*
* @return array|bool
* $error
*/
public static function formRule($fields, $files, $contactID = NULL) {
$errors = array();
$primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
// make sure that household name is set
if (empty($fields['household_name'])) {
$errors['household_name'] = 'Household Name should be set.';
}
//check for duplicate - dedupe rules
CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Household');
return empty($errors) ? TRUE : $errors;
}
}

View file

@ -0,0 +1,74 @@
<?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_Edit_IM {
/**
* Build the form object elements for an IM object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
if (!$blockCount) {
$blockId = ($form->get('IM_Block_Count')) ? $form->get('IM_Block_Count') : 1;
}
else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//IM provider select
$form->addField("im[$blockId][provider_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL));
//Block type select
$form->addField("im[$blockId][location_type_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL, 'option_url' => NULL));
//IM box
$form->addField("im[$blockId][name]", array('entity' => 'im'));
//is_Primary radio
$js = array('id' => 'IM_' . $blockId . '_IsPrimary');
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "im[$blockId][is_primary]", '', '', '1', $js);
}
}

View file

@ -0,0 +1,145 @@
<?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 to the Contact Form class.
*
* Does this by implementing a small set of static methods.
*/
class CRM_Contact_Form_Edit_Individual {
/**
* This function provides the HTML form elements that are specific to the Individual Contact Type.
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
$nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_edit_options', TRUE, NULL,
FALSE, 'name', TRUE, 'AND v.filter = 2'
);
// Use names instead of labels to build form.
$nameFields = array_keys($nameFields);
// Fixme: dear god why? these come out in a format that is NOT the name of the fields.
foreach ($nameFields as &$fix) {
$fix = str_replace(' ', '_', strtolower($fix));
if ($fix == 'prefix' || $fix == 'suffix') {
// God, why god?
$fix .= '_id';
}
}
foreach ($nameFields as $name) {
$props = array();
if ($name == 'prefix_id' || $name == 'suffix_id') {
//override prefix/suffix label name as Prefix/Suffix respectively and adjust select size
$props = array('class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ? ts('Prefix') : ts('Suffix'));
}
$form->addField($name, $props);
}
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addField('nick_name');
// job title
// override the size for UI to look better
$form->addField('job_title', array('size' => '30'));
//Current Employer Element
$props = array(
'api' => array('params' => array('contact_type' => 'Organization')),
'create' => TRUE,
);
$form->addField('employer_id', $props);
$form->addField('contact_source', array('class' => 'big'));
}
if (!$inlineEditMode) {
$checkSimilar = Civi::settings()->get('contact_ajax_check_similar');
if ($checkSimilar == NULL) {
$checkSimilar = 0;
}
$form->assign('checkSimilar', $checkSimilar);
//External Identifier Element
$form->addField('external_identifier', array('label' => 'External ID'));
$form->addRule('external_identifier',
ts('External ID already exists in Database.'),
'objectExists',
array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
);
CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
}
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param int $contactID
*
* @return bool
* TRUE if no errors, else array of errors.
*/
public static function formRule($fields, $files, $contactID = NULL) {
$errors = array();
$primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
// make sure that firstName and lastName or a primary OpenID is set
if (!$primaryID && (empty($fields['first_name']) || empty($fields['last_name']))) {
$errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
}
//check for duplicate - dedupe rules
CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
return empty($errors) ? TRUE : $errors;
}
}

View file

@ -0,0 +1,75 @@
<?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_Edit_Lock {
/**
* Build the form object.
*
* @param CRM_Core_Form $form
* Form object.
*/
public static function buildQuickForm(&$form) {
$form->addField('modified_date', array('type' => 'hidden', 'id' => 'modified_date', 'label' => ''));
}
/**
* Ensure that modified_date has not 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['modified_date'] != $timestamps['modified_date']) {
// Inline buttons generated via JS
$open = sprintf("<span id='update_modified_date' data:latest_modified_date='%s'>", $timestamps['modified_date']);
$close = "</span>";
$errors['modified_date'] = $open . ts('This record was modified by another user!') . $close;
}
return empty($errors) ? TRUE : $errors;
}
}

View file

@ -0,0 +1,46 @@
<?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
*/
class CRM_Contact_Form_Edit_Notes {
/**
* Build form elements.
*
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
$form->applyFilter('__ALL__', 'trim');
$form->addField('subject', array('entity' => 'note', 'size' => '60'));
$form->addField('note', array('entity' => 'note', 'rows' => 3));
}
}

View file

@ -0,0 +1,75 @@
<?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_Edit_OpenID {
/**
* Build the form object elements for an open id object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
if (!$blockCount) {
$blockId = ($form->get('OpenID_Block_Count')) ? $form->get('OpenID_Block_Count') : 1;
}
else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
$form->addElement('text', "openid[$blockId][openid]", ts('OpenID'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OpenID', 'openid')
);
$form->addRule("openid[$blockId][openid]", ts('OpenID is not a valid URL.'), 'url');
//Block type
$form->addElement('select', "openid[$blockId][location_type_id]", '', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'));
//is_Primary radio
$js = array('id' => "OpenID_" . $blockId . "_IsPrimary");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "openid[$blockId][is_primary]", '', '', '1', $js);
}
}

View file

@ -0,0 +1,103 @@
<?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 to the Contact Form class.
*
* Does this by implementing a small set of static methods.
*/
class CRM_Contact_Form_Edit_Organization {
/**
* This function provides the HTML form elements that are specific to the Organization Contact Type.
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
// Organization_name
$form->addField('organization_name');
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// legal_name
$form->addField('legal_name');
// nick_name
$form->addField('nick_name');
// sic_code
$form->addField('sic_code');
$form->addField('contact_source');
}
if (!$inlineEditMode) {
$form->addField('external_identifier', array('label' => ts('External ID')));
$form->addRule('external_identifier',
ts('External ID already exists in Database.'),
'objectExists',
array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
);
}
}
/**
* @param $fields
* @param $files
* @param int $contactID
*
* @return array|bool
*/
public static function formRule($fields, $files, $contactID = NULL) {
$errors = array();
$primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
// make sure that organization name is set
if (empty($fields['organization_name'])) {
$errors['organization_name'] = 'Organization Name should be set.';
}
//check for duplicate - dedupe rules
CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Organization');
// add code to make sure that the uniqueness criteria is satisfied
return empty($errors) ? TRUE : $errors;
}
}

View file

@ -0,0 +1,86 @@
<?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 a phone object.
*/
class CRM_Contact_Form_Edit_Phone {
/**
* Build the form object elements for a phone object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $addressBlockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $addressBlockCount = NULL, $blockEdit = FALSE) {
// passing this via the session is AWFUL. we need to fix this
if (!$addressBlockCount) {
$blockId = ($form->get('Phone_Block_Count')) ? $form->get('Phone_Block_Count') : 1;
}
else {
$blockId = $addressBlockCount;
}
$form->applyFilter('__ALL__', 'trim');
//phone type select
$form->addField("phone[$blockId][phone_type_id]", array(
'entity' => 'phone',
'class' => 'eight',
'placeholder' => NULL,
));
//main phone number with crm_phone class
$form->addField("phone[$blockId][phone]", array('entity' => 'phone', 'class' => 'crm_phone twelve'));
$form->addField("phone[$blockId][phone_ext]", array('entity' => 'phone'));
if (isset($form->_contactType) || $blockEdit) {
//Block type select
$form->addField("phone[$blockId][location_type_id]", array(
'entity' => 'phone',
'class' => 'eight',
'placeholder' => NULL,
'option_url' => NULL,
));
//is_Primary radio
$js = array('id' => 'Phone_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
$form->addElement('radio', "phone[$blockId][is_primary]", '', '', '1', $js);
}
// TODO: set this up as a group, we need a valid phone_type_id if we have a phone number
// $form->addRule( "location[$locationId][phone][$locationId][phone]", ts('Phone number is not valid.'), 'phone' );
}
}

View file

@ -0,0 +1,235 @@
<?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
*/
class CRM_Contact_Form_Edit_TagsAndGroups {
/**
* Constant to determine which forms we are generating.
*
* Used by both profile and edit contact
*/
const GROUP = 1, TAG = 2, ALL = 3;
/**
* Build form elements.
*
* @param CRM_Core_Form $form
* The form object that we are operating on.
* @param int $contactId
* Contact id.
* @param int $type
* What components are we interested in.
* @param bool $visibility
* Visibility of the field.
* @param null $isRequired
* @param string $groupName
* If used for building group block.
* @param string $tagName
* If used for building tag block.
* @param string $fieldName
* This is used in batch profile(i.e to build multiple blocks).
*
* @param string $groupElementType
*
*/
public static function buildQuickForm(
&$form,
$contactId = 0,
$type = self::ALL,
$visibility = FALSE,
$isRequired = NULL,
$groupName = 'Group(s)',
$tagName = 'Tag(s)',
$fieldName = NULL,
$groupElementType = 'checkbox'
) {
if (!isset($form->_tagGroup)) {
$form->_tagGroup = array();
}
// NYSS 5670
if (!$contactId && !empty($form->_contactId)) {
$contactId = $form->_contactId;
}
$type = (int) $type;
if ($type & self::GROUP) {
$fName = 'group';
if ($fieldName) {
$fName = $fieldName;
}
$groupID = isset($form->_grid) ? $form->_grid : NULL;
if ($groupID && $visibility) {
$ids = array($groupID => $groupID);
}
else {
if ($visibility) {
$group = CRM_Core_PseudoConstant::allGroup();
}
else {
$group = CRM_Core_PseudoConstant::group();
}
$ids = $group;
}
if ($groupID || !empty($group)) {
$groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids);
$attributes['skiplabel'] = TRUE;
$elements = array();
$groupsOptions = array();
foreach ($groups as $id => $group) {
// make sure that this group has public visibility
if ($visibility &&
$group['visibility'] == 'User and User Admin Only'
) {
continue;
}
if ($groupElementType == 'select') {
$groupsOptions[$id] = $group['title'];
}
else {
$form->_tagGroup[$fName][$id]['description'] = $group['description'];
$elements[] = &$form->addElement('advcheckbox', $id, NULL, $group['title'], $attributes);
}
}
if ($groupElementType == 'select' && !empty($groupsOptions)) {
$form->add('select', $fName, $groupName, $groupsOptions, FALSE,
array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2 twenty')
);
$form->assign('groupCount', count($groupsOptions));
}
if ($groupElementType == 'checkbox' && !empty($elements)) {
$form->addGroup($elements, $fName, $groupName, '&nbsp;<br />');
$form->assign('groupCount', count($elements));
if ($isRequired) {
$form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required');
}
}
$form->assign('groupElementType', $groupElementType);
}
}
if ($type & self::TAG) {
$tags = CRM_Core_BAO_Tag::getColorTags('civicrm_contact');
if (!empty($tags)) {
$form->add('select2', 'tag', ts('Tag(s)'), $tags, FALSE, array('class' => 'huge', 'placeholder' => ts('- select -'), 'multiple' => TRUE));
}
// build tag widget
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE);
}
$form->assign('tagGroup', $form->_tagGroup);
}
/**
* Set defaults for relevant form elements.
*
* @param int $id
* The contact id.
* @param array $defaults
* The defaults array to store the values in.
* @param int $type
* What components are we interested in.
* @param string $fieldName
* This is used in batch profile(i.e to build multiple blocks).
*
* @param string $groupElementType
*/
public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldName = NULL, $groupElementType = 'checkbox') {
$type = (int ) $type;
if ($type & self::GROUP) {
$fName = 'group';
if ($fieldName) {
$fName = $fieldName;
}
$contactGroup = CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', NULL, FALSE, TRUE);
if ($contactGroup) {
foreach ($contactGroup as $group) {
if ($groupElementType == 'select') {
$defaults[$fName][] = $group['group_id'];
}
else {
$defaults[$fName . '[' . $group['group_id'] . ']'] = 1;
}
}
}
}
if ($type & self::TAG) {
$defaults['tag'] = implode(',', CRM_Core_BAO_EntityTag::getTag($id, 'civicrm_contact'));
}
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @param CRM_Core_Form $form
* @param array $defaults
*/
public static function setDefaultValues(&$form, &$defaults) {
$contactEditOptions = $form->get('contactEditOptions');
if ($form->_action & CRM_Core_Action::ADD) {
if (array_key_exists('TagsAndGroups', $contactEditOptions)) {
// set group and tag defaults if any
if ($form->_gid) {
$defaults['group'][$form->_gid] = 1;
}
if ($form->_tid) {
$defaults['tag'][$form->_tid] = 1;
}
}
}
else {
if (array_key_exists('TagsAndGroups', $contactEditOptions)) {
// set the group and tag ids
$groupElementType = 'checkbox';
if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
$groupElementType = 'select';
}
self::setDefaults($form->_contactId, $defaults, self::ALL, NULL, $groupElementType);
}
}
}
}

View file

@ -0,0 +1,66 @@
<?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_Edit_Website {
/**
* Build the form object elements for an Website object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
*/
public static function buildQuickForm(&$form, $blockCount = NULL) {
if (!$blockCount) {
$blockId = ($form->get('Website_Block_Count')) ? $form->get('Website_Block_Count') : 1;
}
else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Website type select
$form->addField("website[$blockId][website_type_id]", array('entity' => 'website', 'class' => 'eight'));
//Website box
$form->addField("website[$blockId][url]", array('entity' => 'website'));
$form->addRule("website[$blockId][url]", ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
}
}