<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
public $_contactId;
/**
- * the default group id passed in via the url
+ * The default group id passed in via the url
*
* @var int
*/
public $_gid;
/**
- * the default tag id passed in via the url
+ * The default tag id passed in via the url
*
* @var int
*/
public $_tid;
/**
- * name of de-dupe button
+ * Name of de-dupe button
*
* @var string
- * @access protected
*/
protected $_dedupeButtonName;
/**
- * name of optional save duplicate button
+ * Name of optional save duplicate button
*
* @var string
- * @access protected
*/
protected $_duplicateButtonName;
public $_parseStreetAddress;
/**
- * check contact has a subtype or not
+ * Check contact has a subtype or not
*/
public $_isContactSubType;
public $_preEditValues;
/**
- * build all the data structures needed to build the form
+ * Build all the data structures needed to build the form
*
* @return void
- * @access public
*/
- function preProcess() {
+ public function preProcess() {
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
$this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
$returnProperities = array('id', 'contact_type', 'contact_sub_type', 'modified_date');
CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities);
- if (!CRM_Utils_Array::value('id', $defaults)) {
+ if (empty($defaults['id'])) {
CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)));
}
'address_options'
);
$this->_parseStreetAddress = FALSE;
- if (CRM_Utils_Array::value('street_address', $addressOptions) &&
- CRM_Utils_Array::value('street_address_parsing', $addressOptions)
- ) {
+ if (!empty($addressOptions['street_address']) && !empty($addressOptions['street_address_parsing'])) {
$this->_parseStreetAddress = TRUE;
}
$this->set('parseStreetAddress', $this->_parseStreetAddress);
CRM_Contact_Form_Location::preProcess($this);
// retain the multiple count custom fields value
- if(CRM_Utils_Array::value('hidden_custom', $_POST)) {
+ if (!empty($_POST['hidden_custom'])) {
$customGroupCount = CRM_Utils_Array::value('hidden_custom_group_count', $_POST);
if ($contactSubType = CRM_Utils_Array::value( 'contact_sub_type', $_POST)) {
else {
$contactSubType = $this->_contactSubType;
// need contact sub type to build related grouptree array during post process
- if (CRM_Utils_Array::value('contact_sub_type', $_POST)) {
+ if (!empty($_POST['contact_sub_type'])) {
$contactSubType = $_POST['contact_sub_type'];
}
//only custom data has preprocess hence directly call it
}
/**
- * This function sets the default values for the form. Note that in edit/view mode
+ * Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
- * @access public
*
- * @return None
+ * @return void
*/
- function setDefaultValues() {
+ public function setDefaultValues() {
$defaults = $this->_values;
$params = array();
}
}
else {
- $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
- $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
-
foreach ($defaults['email'] as $dontCare => & $val) {
if (isset($val['signature_text'])) {
$val['signature_text_hidden'] = $val['signature_text'];
}
}
- if (CRM_Utils_Array::value('contact_sub_type', $defaults)) {
+ if (!empty($defaults['contact_sub_type'])) {
$defaults['contact_sub_type'] = $this->_oldSubtypes;
}
}
- $this->assign('currentEmployer', CRM_Utils_Array::value('current_employer_id', $defaults));
-
// set defaults for blocks ( custom data, address, communication preference, notes, tags and groups )
foreach ($this->_editOptions as $name => $label) {
if (!in_array($name, array('Address', 'Notes'))) {
//set address block defaults
CRM_Contact_Form_Edit_Address::setDefaultValues( $defaults, $this );
- if (CRM_Utils_Array::value('image_URL', $defaults)) {
+
+ if (!empty($defaults['image_URL'])) {
list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($defaults['image_URL']));
list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
$this->assign('imageWidth', $imageWidth);
}
/**
- * do the set default related to location type id,
+ * Do the set default related to location type id,
* primary location, default country
*
*/
- function blockSetDefaults(&$defaults) {
+ public function blockSetDefaults(&$defaults) {
$locationTypeKeys = array_filter(array_keys(CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id')), 'is_int');
sort($locationTypeKeys);
$defIMProviderId = key(CRM_Core_OptionGroup::values('instant_messenger_service',
FALSE, FALSE, FALSE, ' AND is_default = 1'
));
+ $defWebsiteTypeId = key(CRM_Core_OptionGroup::values('website_type',
+ FALSE, FALSE, FALSE, ' AND is_default = 1'
+ ));
$allBlocks = $this->_blocks;
if (array_key_exists('Address', $this->_editOptions)) {
if ($name == 'phone' && $defPhoneTypeId) {
$defaults[$name][$instance]['phone_type_id'] = $defPhoneTypeId;
}
+ //set default website type.
+ if ($name == 'website' && $defWebsiteTypeId) {
+ $defaults[$name][$instance]['website_type_id'] = $defWebsiteTypeId;
+ }
//set default im provider.
if ($name == 'im' && $defIMProviderId) {
$defaults[$name][1]['is_primary'] = TRUE;
}
}
-
- // set defaults for country-state widget
- if (CRM_Utils_Array::value('address', $defaults) && is_array($defaults['address'])) {
- foreach ($defaults['address'] as $blockId => $values) {
- CRM_Contact_Form_Edit_Address::fixStateSelect($this,
- "address[$blockId][country_id]",
- "address[$blockId][state_province_id]",
- "address[$blockId][county_id]",
- CRM_Utils_Array::value('country_id',
- $values, $config->defaultContactCountry
- ),
- CRM_Utils_Array::value('state_province_id',
- $values, $config->defaultContactStateProvince
- )
- );
- }
- }
}
/**
* This function is used to add the rules (mainly global rules) for form.
* All local rules are added near the element
*
- * @return None
- * @access public
+ * @return void
* @see valid_date
*/
- function addRules() {
+ public function addRules() {
// skip adding formRules when custom data is build
if ($this->_addBlockName || ($this->_action & CRM_Core_Action::DELETE)) {
return;
}
/**
- * global validation rules for the form
+ * 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 int $contactId contact id if doing update.
+ * @param array $fields posted values of the form
+ * @param array $errors list of errors to be posted back to the form
+ * @param int $contactId contact id if doing update.
*
- * @return $primaryID email/openId
- * @static
- * @access public
+ * @return bool $primaryID email/openId@static
*/
- static function formRule($fields, &$errors, $contactId = NULL) {
+ public static function formRule($fields, &$errors, $contactId = NULL) {
$config = CRM_Core_Config::singleton();
// validations.
foreach ($blocks as $name => $label) {
$hasData = $hasPrimary = array();
$name = strtolower($name);
- if (CRM_Utils_Array::value($name, $fields) && is_array($fields[$name])) {
+ if (!empty($fields[$name]) && is_array($fields[$name])) {
foreach ($fields[$name] as $instance => $blockValues) {
$dataExists = self::blockDataExists($blockValues);
}
$hasData[] = $instance;
- if (CRM_Utils_Array::value('is_primary', $blockValues)) {
+ if (!empty($blockValues['is_primary'])) {
$hasPrimary[] = $instance;
if (!$primaryID &&
in_array($name, array(
- 'email', 'openid')) &&
- CRM_Utils_Array::value($name, $blockValues)
- ) {
+ 'email', 'openid')) && !empty($blockValues[$name])) {
$primaryID = $blockValues[$name];
}
}
- if (!CRM_Utils_Array::value('location_type_id', $blockValues)) {
+ if (empty($blockValues['location_type_id'])) {
$errors["{$name}[$instance][location_type_id]"] = ts('The Location Type should be set if there is %1 information.', array(1 => $label));
}
}
- if ($name == 'openid' && CRM_Utils_Array::value($name, $blockValues)) {
+ if ($name == 'openid' && !empty($blockValues[$name])) {
$oid = new CRM_Core_DAO_OpenID();
$oid->openid = $openIds[$instance] = CRM_Utils_Array::value($name, $blockValues);
$cid = isset($contactId) ? $contactId : 0;
foreach ($fields['address'] as $cnt => $address) {
if ($streetNumber = CRM_Utils_Array::value('street_number', $address)) {
$parsedAddress = CRM_Core_BAO_Address::parseStreetAddress($address['street_number']);
- if (!CRM_Utils_Array::value('street_number', $parsedAddress)) {
+ if (empty($parsedAddress['street_number'])) {
$invalidStreetNumbers[] = $cnt;
}
}
}
/**
- * Function to actually build the form
+ * Build the form object
*
- * @return None
- * @access public
+ * @return void
*/
public function buildQuickForm() {
//load form for child blocks
CRM_Core_Action::DELETE,
array(
'id' => $this->_contactId,
- )
+ ),
+ ts('more'),
+ FALSE,
+ 'contact.image.delete',
+ 'Contact',
+ $this->_contactId
);
$this->assign('deleteURL', $deleteURL);
}
}
// subtype is a common field. lets keep it here
- $subtypes = CRM_Contact_BAO_ContactType::subTypePairs($this->_contactType);
+ $subtypes = CRM_Contact_BAO_Contact::buildOptions('contact_sub_type', 'create', array('contact_type' => $this->_contactType));
if (!empty($subtypes)) {
$sel = $this->add('select', 'contact_sub_type', ts('Contact Type'),
$subtypes, FALSE,
array(
'id' => 'contact_sub_type',
'multiple' => 'multiple',
- 'title' => '- ' . ts('select') . ' -',
- 'class' => $buildCustomData,
+ 'class' => $buildCustomData . ' crm-select2',
)
);
}
// build tags and groups
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($this, 0, CRM_Contact_Form_Edit_TagsAndGroups::ALL,
- FALSE, NULL, 'Group(s)', 'Tag(s)', NULL, 'crmasmSelect');
+ FALSE, NULL, 'Group(s)', 'Tag(s)', NULL, 'select');
// build location blocks.
CRM_Contact_Form_Edit_Lock::buildQuickForm($this);
'subName' => 'view',
'isDefault' => TRUE,
),
- array(
+ );
+ if (CRM_Core_Permission::check('add contacts')) {
+ $buttons[] = array(
'type' => 'upload',
'name' => ts('Save and New'),
'spacing' => ' ',
'subName' => 'new',
- ),
- array(
- 'type' => 'cancel',
- 'name' => ts('Cancel'),
- ),
+ );
+ }
+ $buttons[] = array(
+ 'type' => 'cancel',
+ 'name' => ts('Cancel'),
);
- if (CRM_Utils_Array::value('contact_sub_type', $this->_values)) {
+ if (!empty($this->_values['contact_sub_type'])) {
$this->_oldSubtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR,
trim($this->_values['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR)
);
/**
* Form submission of new/edit contact is processed.
*
- * @access public
*
- * @return None
+ * @return void
*/
public function postProcess() {
// check if dedupe button, if so return.
CRM_Contact_BAO_Contact_Optimizer::edit( $params, $this->_preEditValues );
- if (CRM_Utils_Array::value('image_URL', $params)) {
+ if (!empty($params['image_URL'])) {
CRM_Contact_BAO_Contact::processImageParams($params);
}
- if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params))
- && CRM_Utils_Array::value('current_employer', $params)
- ) {
+ if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && !empty($params['current_employer'])) {
$params['current_employer'] = $params['current_employer_id'];
}
}
//make deceased date null when is_deceased = false
- if ($this->_contactType == 'Individual' &&
- CRM_Utils_Array::value('Demographics', $this->_editOptions) &&
- !CRM_Utils_Array::value('is_deceased', $params)
- ) {
+ if ($this->_contactType == 'Individual' && !empty($this->_editOptions['Demographics']) && empty($params['is_deceased'])) {
$params['is_deceased'] = FALSE;
$params['deceased_date'] = NULL;
}
unset($params['group']);
}
- if (CRM_Utils_Array::value('contact_id', $params) && ($this->_action & CRM_Core_Action::UPDATE)) {
+ if (!empty($params['contact_id']) && ($this->_action & CRM_Core_Action::UPDATE)) {
// figure out which all groups are intended to be removed
$contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added');
if (is_array($contactGroupList)) {
foreach ($contactGroupList as $key) {
- if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1)
- && !CRM_Utils_Array::value('is_hidden', $key)
- ) {
+ if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1) && empty($key['is_hidden'])) {
$params['group'][$key['group_id']] = -1;
}
}
}
/**
- * is there any real significant data in the hierarchical location array
+ * Is there any real significant data in the hierarchical location array
*
* @param array $fields the hierarchical value representation of this location
*
* @return boolean true if data exists, false otherwise
* @static
- * @access public
*/
- static function blockDataExists(&$fields) {
+ public static function blockDataExists(&$fields) {
if (!is_array($fields)) {
return FALSE;
}
}
/**
- * Function to that checks for duplicate contacts
+ * That checks for duplicate contacts
+ *
+ * @param array $fields fields array which are submitted
+ * @param $errors
+ * @param int $contactID contact id
+ * @param string $contactType contact type
*
- * @param array $fields fields array which are submitted
- * @param array $error error message array
- * @param int $contactID contact id
- * @param string $contactType contact type
*/
- static function checkDuplicateContacts(&$fields, &$errors, $contactID, $contactType) {
+ public static function checkDuplicateContacts(&$fields, &$errors, $contactID, $contactType) {
// if this is a forced save, ignore find duplicate rule
- if (!CRM_Utils_Array::value('_qf_Contact_upload_duplicate', $fields)) {
+ if (empty($fields['_qf_Contact_upload_duplicate'])) {
$dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $contactType);
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $contactType, 'Supervised', array($contactID));
$template = CRM_Core_Smarty::singleton();
$template->assign('isDuplicate', 1);
}
- elseif (CRM_Utils_Array::value('_qf_Contact_refresh_dedupe', $fields)) {
+ elseif (!empty($fields['_qf_Contact_refresh_dedupe'])) {
// add a session message for no matching contacts
CRM_Core_Session::setStatus(ts('No matching contact found.'), ts('None Found'), 'info');
}
}
}
- function getTemplateFileName() {
+ /**
+ * Use the form name to create the tpl file name
+ *
+ * @return string
+ */
+ public function getTemplateFileName() {
if ($this->_contactSubType) {
$templateFile = "CRM/Contact/Form/Edit/SubType/{$this->_contactSubType}.tpl";
$template = CRM_Core_Form::getTemplate();
/**
* Parse all address blocks present in given params
- * and return parse result for all address blocks,
- * This function either parse street address in to child
- * elements or build street address from child elements.
- *
- * @params $params an array of key value consist of address blocks.
- *
- * @return $parseSuccess as array of sucess/fails for each address block
- * @static
- */
- function parseAddress(&$params) {
+ * and return parse result for all address blocks,
+ * This function either parse street address in to child
+ * elements or build street address from child elements.
+ *
+ * @param $params array of key value consist of address blocks.
+ *
+ * @return array $parseSuccess as array of sucess/fails for each address block@static
+ */
+ public function parseAddress(&$params) {
$parseSuccess = $parsedFields = array();
if (!is_array($params['address']) ||
CRM_Utils_System::isNull($params['address'])
$parseFieldName = 'street_address';
foreach (array(
'street_number', 'street_name', 'street_unit') as $fld) {
- if (CRM_Utils_Array::value($fld, $address)) {
+ if (!empty($address[$fld])) {
$parseFieldName = 'street_number';
$buildStreetAddress = TRUE;
break;
$success = TRUE;
// consider address is automatically parseable,
// when we should found street_number and street_name
- if (!CRM_Utils_Array::value('street_name', $parsedFields) ||
- !CRM_Utils_Array::value('street_number', $parsedFields)
- ) {
+ if (empty($parsedFields['street_name']) || empty($parsedFields['street_number'])) {
$success = FALSE;
}
}
/**
- * check parse result and if some address block fails then this
+ * Check parse result and if some address block fails then this
* function return the status message for all address blocks.
*
* @param $parseResult an array of address blk instance and its status.
*
- * @return $statusMsg string status message for all address blocks.
- * @static
+ * @return null|string $statusMsg string status message for all address blocks.@static
*/
- static function parseAddressStatusMsg($parseResult) {
+ public static function parseAddressStatusMsg($parseResult) {
$statusMsg = NULL;
if (!is_array($parseResult) || empty($parseResult)) {
return $statusMsg;
* @return ordinal number for given number.
* @static
*/
- static function ordinalNumber($number) {
+ public static function ordinalNumber($number) {
if (empty($number)) {
return NULL;
}
*
* @param $deceasedParams array having contact id and deceased value.
*
- * @return $updateMembershipMsg string status message for updated membership.
+ * @return null|string $updateMembershipMsg string status message for updated membership.
*/
- function updateMembershipStatus($deceasedParams) {
+ public function updateMembershipStatus($deceasedParams) {
$updateMembershipMsg = NULL;
$contactId = CRM_Utils_Array::value('contact_id', $deceasedParams);
$deceasedDate = CRM_Utils_Array::value('deceased_date', $deceasedParams);
// process to set membership status to deceased for both active/inactive membership
if ($contactId &&
- $this->_contactType == 'Individual' &&
- CRM_Utils_Array::value('is_deceased', $deceasedParams)
- ) {
+ $this->_contactType == 'Individual' && !empty($deceasedParams['is_deceased'])) {
$session = CRM_Core_Session::singleton();
$userId = $session->get('userID');
return $updateMembershipMsg;
}
}
-