<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| 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-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
*
*/
class CRM_Profile_Form extends CRM_Core_Form {
- CONST
+ const
MODE_REGISTER = 1,
- MODE_SEARCH = 2,
- MODE_CREATE = 4,
- MODE_EDIT = 8;
+ MODE_SEARCH = 2,
+ MODE_CREATE = 4,
+ MODE_EDIT = 8;
protected $_mode;
protected $_skipPermission = FALSE;
/**
- * The contact id that we are editing
+ * The contact id that we are editing.
*
* @var int
*/
protected $_id;
/**
- * The group id that we are editing
+ * The group id that we are editing.
*
* @var int
*/
protected $_ufGroup = array('name' => 'unknown');
/**
- * The group id that we are passing in url
+ * The group id that we are passing in url.
*
* @var int
*/
public $_grid;
/**
- * Name of button for saving matching contacts
+ * Name of button for saving matching contacts.
* @var
*/
protected $_duplicateButtonName;
/**
- * The title of the category we are editing
+ * The title of the category we are editing.
*
* @var string
*/
protected $_title;
/**
- * the fields needed to build this form
+ * The fields needed to build this form.
*
* @var array
*/
public $_fields;
/**
- * to store contact details
+ * store contact details.
*
* @var array
*/
protected $_contact;
/**
- * Do we allow updates of the contact
+ * Do we allow updates of the contact.
*
* @var int
*/
public $_isUpdateDupe = 0;
+ /**
+ * Dedupe using a specific rule (CRM-6131).
+ * Not currently exposed in profile settings, but can be set in a buildForm hook.
+ */
+ public $_ruleGroupID = NULL;
+
public $_isAddCaptcha = FALSE;
protected $_isPermissionedChecksum = FALSE;
protected $_context;
/**
- * THe contact type for registration case
+ * THe contact type for registration case.
*
* @var string
*/
protected $_ctype = NULL;
- protected $_defaults = NULL;
-
/**
* Store profile ids if multiple profile ids are passed using comma separated.
* Currently lets implement this functionality only for dialog mode
protected $_isContactActivityProfile = FALSE;
/**
- * Activity Id connected to the profile
+ * Activity Id connected to the profile.
*
* @var string
*/
protected $_recordId = NULL;
/**
- * action for multi record profile (create/edit/delete)
+ * Action for multi record profile (create/edit/delete)
*
* @var string
*/
protected $_customGroupId = NULL;
protected $_currentUserID = NULL;
- protected $_session = NULL;
+ protected $_session = NULL;
/**
- * pre processing work done here.
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Profile';
+ }
+
+ /**
+ * Pre processing work done here.
*
* gets session variables for table name, id of entity in table, type of entity and stores them.
*
* @param
*
* @return void
- *
- * @access public
*/
- function preProcess() {
- $this->_id = $this->get('id');
+ public function preProcess() {
+ $this->_id = $this->get('id');
$this->_profileIds = $this->get('profileIds');
- $this->_grid = CRM_Utils_Request::retrieve('grid', 'Integer', $this);
- $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
+ $this->_grid = CRM_Utils_Request::retrieve('grid', 'Integer', $this);
+ $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
//unset from session when $_GET doesn't have it
//except when the form is submitted
if ($this->_mode == self::MODE_EDIT) {
//specifies the action being done on a multi record field
$multiRecordAction = CRM_Utils_Request::retrieve('multiRecord', 'String', $this);
- $this->_multiRecord = (!is_numeric($multiRecordAction)) ?
- CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction;
+ $this->_multiRecord = (!is_numeric($multiRecordAction)) ? CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction;
if ($this->_multiRecord) {
$this->set('multiRecord', $this->_multiRecord);
}
if ($this->_multiRecord &&
- !in_array($this->_multiRecord, array(CRM_Core_Action::UPDATE, CRM_Core_Action::ADD, CRM_Core_Action::DELETE))) {
+ !in_array($this->_multiRecord, array(CRM_Core_Action::UPDATE, CRM_Core_Action::ADD, CRM_Core_Action::DELETE))
+ ) {
CRM_Core_Error::fatal(ts('Proper action not specified for this custom value record profile'));
}
}
if ($this->_multiRecord) {
if ($this->_multiRecord != CRM_Core_Action::ADD) {
$this->_recordId = CRM_Utils_Request::retrieve('recordId', 'Positive', $this);
- } else {
+ }
+ else {
$this->_recordId = NULL;
$this->set('recordId', NULL);
}
- //record id is neccessary for _multiRecord view and update/edit action
+ //record id is necessary for _multiRecord view and update/edit action
if (!$this->_recordId
- && ($this->_multiRecord == CRM_Core_Action::UPDATE || $this->_multiRecord == CRM_Core_Action::DELETE)) {
+ && ($this->_multiRecord == CRM_Core_Action::UPDATE || $this->_multiRecord == CRM_Core_Action::DELETE)
+ ) {
CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) requires record id while performing this action',
array(1 => $this->_gid)
));
- } elseif (empty($this->_multiRecordFields)) {
- CRM_Core_Error::fatal(ts('No Multi-Record Fields configured for this profile (gid=%1)',
+ }
+ elseif (empty($this->_multiRecordFields)) {
+ CRM_Core_Error::fatal(ts('No Multi-Record Fields configured for this profile (gid=%1)',
array(1 => $this->_gid)
));
}
if (array_key_exists($this->_recordId, $getValues)) {
$this->_recordExists = TRUE;
- } else {
+ }
+ else {
$this->_recordExists = FALSE;
if ($this->_multiRecord & CRM_Core_Action::UPDATE) {
CRM_Core_Session::setStatus(ts('Note: The record %1 doesnot exists. Upon save a new record will be create', array(1 => $this->_recordId)), ts('Record doesnot exist'), 'alert');
}
}
- } elseif (!empty($this->_multiRecordFields)
- && (!$this->_multiRecord || !in_array($this->_multiRecord, array(CRM_Core_Action::DELETE, CRM_Core_Action::UPDATE)) )) {
+ }
+ elseif (!empty($this->_multiRecordFields)
+ && (!$this->_multiRecord || !in_array($this->_multiRecord, array(
+ CRM_Core_Action::DELETE,
+ CRM_Core_Action::UPDATE,
+ )))
+ ) {
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header');
//multirecord listing page
$multiRecordFieldListing = TRUE;
if ($this->_multiRecord && !empty($this->_multiRecordFields)) {
$this->_fields = $this->_multiRecordFields;
$this->_multiRecordProfile = TRUE;
- } elseif ($this->_multiRecord && empty($this->_multiRecordFields)) {
+ }
+ elseif ($this->_multiRecord && empty($this->_multiRecordFields)) {
CRM_Core_Session::setStatus(ts('This feature is not currently available.'), ts('Sorry'), 'error');
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm', 'reset=1'));
}
}
/**
- * 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 void
*/
- function setDefaultsValues() {
+ public function setDefaultsValues() {
$this->_defaults = array();
if ($this->_multiRecordProfile && ($this->_multiRecord == CRM_Core_Action::DELETE)) {
return;
$fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
}
- $defaultValues = array( );
+ $defaultValues = array();
if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) {
$defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
if ($this->_recordExists == TRUE) {
$defaultValues = $defaultValues[$this->_recordId];
- } else {
+ }
+ else {
$defaultValues = NULL;
}
}
$this->_mode,
$value
);
- } else {
+ }
+ else {
$this->_defaults[$name] = "";
}
}
if ($htmlType == 'File') {
$entityId = $this->_id;
if (CRM_Utils_Array::value('field_type', $field) == 'Activity' &&
- $this->_activityId
- ) {
+ $this->_activityId
+ ) {
$entityId = $this->_activityId;
}
$url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key);
$customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
- $fileId = $url['file_id'];
- $deleteURL = CRM_Utils_System::url('civicrm/file',
- "reset=1&id={$fileId}&eid=$entityId&fid={$key}&action=delete"
- );
+ $fileId = $url['file_id'];
+ $deleteURL = CRM_Utils_System::url('civicrm/file',
+ "reset=1&id={$fileId}&eid=$entityId&fid={$key}&action=delete"
+ );
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' $deleteExtra ' )) this.href+='&confirmed=1'; else return false;\">$text</a>";
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$htmlType = $field['html_type'];
if ((!isset($this->_defaults[$name]) || $htmlType == 'File') &&
- (CRM_Utils_Array::value('field_type', $field) != 'Activity')
- ) {
+ (CRM_Utils_Array::value('field_type', $field) != 'Activity')
+ ) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID,
$name,
$this->_defaults,
$customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
- $fileId = $url['file_id'];
- $deleteURL = CRM_Utils_System::url('civicrm/file',
- "reset=1&id={$fileId}&eid=$entityId&fid={$customFieldID}&action=delete"
+ $fileId = $url['file_id'];
+ $deleteURL = CRM_Utils_System::url('civicrm/file',
+ "reset=1&id={$fileId}&eid=$entityId&fid={$customFieldID}&action=delete"
);
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' $deleteExtra ' )) this.href+='&confirmed=1'; else return false;\">$text</a>";
}
/**
- * Function to actually build the form
+ * Build the form object.
*
* @return void
- * @access public
*/
public function buildQuickForm() {
$this->add('hidden', 'gid', $this->_gid);
case self::MODE_REGISTER:
CRM_Utils_Hook::buildProfile($this->_ufGroup['name']);
break;
+
case self::MODE_SEARCH:
CRM_Utils_Hook::searchProfile($this->_ufGroup['name']);
break;
+
default:
}
if ($this->_id) {
$contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
- $contactType = $contactTypes[0];
+ $contactType = $contactTypes[0];
array_shift($contactTypes);
$contactSubtypes = $contactTypes;
if (
($profileType != 'Contact' && !$this->_isContactActivityProfile) &&
- (($profileSubType && !empty($contactSubtypes) && (!in_array($profileSubType,$contactSubtypes))) ||
+ (($profileSubType && !empty($contactSubtypes) && (!in_array($profileSubType, $contactSubtypes))) ||
($profileType != $contactType))
) {
$return = TRUE;
if (!$statusMessage) {
- $statusMessage =
- ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.",
+ $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.",
array(1 => $profileSubType ? $profileSubType : $profileType));
}
}
}
if (
- in_array(
- $profileType,
- array("Membership", "Participant", "Contribution")
- )
+ in_array(
+ $profileType,
+ array("Membership", "Participant", "Contribution")
+ )
) {
$return = TRUE;
if (!$statusMessage) {
if (!$this->_currentUserID) {
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
$primaryLocationType = $defaultLocationType->id;
- $anonUser = TRUE;
+ $anonUser = TRUE;
}
$this->assign('anonUser', $anonUser);
if ($this->_currentUserID) {
$this->_isAddCaptcha = FALSE;
}
- else if (!$this->_isAddCaptcha && !empty($addCaptcha)) {
+ elseif (!$this->_isAddCaptcha && !empty($addCaptcha)) {
$this->_isAddCaptcha = TRUE;
}
}
}
- /*
- * Function to validate profile and provided activity Id
- *
- * @params Integer $activityId Activity Id
- * @params Integer $gid Profile Id
- *
- * @return Array $errors Errors ( if any ).
- */
/**
- * @param $activityId
- * @param $contactId
- * @param $gid
+ * Validate profile and provided activity Id.
+ *
+ * @param int $activityId
+ * @param int $contactId
+ * @param int $gid
*
* @return array
*/
- static function validateContactActivityProfile($activityId, $contactId, $gid) {
+ public static function validateContactActivityProfile($activityId, $contactId, $gid) {
$errors = array();
if (!$activityId) {
$errors[] = 'Profile is using one or more activity fields, and is missing the activity Id (aid) in the URL.';
}
/**
- * global form rule
+ * Global form rule.
*
- * @param array $fields the input form values
- * @param array $files the uploaded files if any
- * @param object $form the form object
+ * @param array $fields
+ * The input form values.
+ * @param array $files
+ * The uploaded files if any.
+ * @param CRM_Core_Form $form
+ * The form object.
*
- * @return true if no errors, else array of errors
- * @access public
- * @static
+ * @return bool|array
+ * true if no errors, else array of errors
*/
- static function formRule($fields, $files, $form) {
+ public static function formRule($fields, $files, $form) {
CRM_Utils_Hook::validateProfile($form->_ufGroup['name']);
$errors = array();
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams,
$ctype,
$ruleType,
- $exceptions
+ $exceptions,
+ $form->_ruleGroupID
);
if ($ids) {
if ($form->_isUpdateDupe == 2) {
$contactLinks = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, TRUE, TRUE);
$duplicateContactsLinks = '<div class="matching-contacts-found">';
- $duplicateContactsLinks .= ts('One matching contact was found. ', array('count' => count($contactLinks['rows']), 'plural' => '%count matching contacts were found.<br />'));
+ $duplicateContactsLinks .= ts('One matching contact was found. ', array(
+ 'count' => count($contactLinks['rows']),
+ 'plural' => '%count matching contacts were found.<br />',
+ ));
if ($contactLinks['msg'] == 'view') {
- $duplicateContactsLinks .= ts('You can View the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View the existing contacts.'));
+ $duplicateContactsLinks .= ts('You can View the existing contact.', array(
+ 'count' => count($contactLinks['rows']),
+ 'plural' => 'You can View the existing contacts.',
+ ));
}
else {
- $duplicateContactsLinks .= ts('You can View or Edit the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View or Edit the existing contacts.'));
+ $duplicateContactsLinks .= ts('You can View or Edit the existing contact.', array(
+ 'count' => count($contactLinks['rows']),
+ 'plural' => 'You can View or Edit the existing contacts.',
+ ));
}
$duplicateContactsLinks .= '</div>';
$duplicateContactsLinks .= '<table class="matching-contacts-actions">';
$row = '';
- for ($i = 0; $i < sizeof($contactLinks['rows']); $i++) {
+ for ($i = 0; $i < count($contactLinks['rows']); $i++) {
$row .= ' <tr> ';
$row .= ' <td class="matching-contacts-name"> ';
$row .= $contactLinks['rows'][$i]['display_name'];
if ($stateProvinceDAO->country_id != $countryId) {
// country mismatch hence display error
$stateProvinces = CRM_Core_PseudoConstant::stateProvince();
- $countries = CRM_Core_PseudoConstant::country();
- $errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
+ $countries = CRM_Core_PseudoConstant::country();
+ $errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
}
}
}
if ($countyDAO->state_province_id != $stateProvinceId) {
// state province mismatch hence display error
$stateProvinces = CRM_Core_PseudoConstant::stateProvince();
- $counties = CRM_Core_PseudoConstant::county();
- $errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
+ $counties = CRM_Core_PseudoConstant::county();
+ $errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
}
}
}
/**
* Process the user submitted custom data values.
*
- * @access public
*
* @return void
*/
if ($tableName = CRM_Utils_Array::value('table_name', $returnValues)) {
$sql = "DELETE FROM {$tableName} WHERE id = %1 AND entity_id = %2";
$sqlParams = array(
- 1 => array($this->_recordId, 'Integer'),
- 2 => array($this->_id, 'Integer')
- );
- CRM_Core_DAO::executeQuery($sql, $sqlParams);
- CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success');
+ 1 => array($this->_recordId, 'Integer'),
+ 2 => array($this->_id, 'Integer'),
+ );
+ CRM_Core_DAO::executeQuery($sql, $sqlParams);
+ CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success');
}
}
return;
$details = $contactDetails[0][$this->_id];
}
if (!(!empty($details['addressee_id']) || !empty($details['email_greeting_id']) ||
- CRM_Utils_Array::value('postal_greeting_id', $details)
- )) {
+ CRM_Utils_Array::value('postal_greeting_id', $details)
+ )
+ ) {
$profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
//Though Profile type is contact we need
CRM_Core_Error::debug_log_message("Rolling back transaction as CMSUser Create failed in Profile_Form for contact " . $params['contactID']);
$transaction->rollback();
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create',
- 'reset=1&gid=' . $this->_gid
- ));
+ 'reset=1&gid=' . $this->_gid
+ ));
}
}
*
* @return null|string
*/
- function checkTemplateFileExists($suffix = NULL) {
+ public function checkTemplateFileExists($suffix = NULL) {
if ($this->_gid) {
$templateFile = "CRM/Profile/Form/{$this->_gid}/{$this->_name}.{$suffix}tpl";
$template = CRM_Core_Form::getTemplate();
}
/**
- * Use the form name to create the tpl file name
+ * Use the form name to create the tpl file name.
*
* @return string
- * @access public
*/
/**
* @return string
*/
- function getTemplateFileName() {
+ public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
}
* i.e. we dont override
*
* @return string
- * @access public
*/
/**
* @return string
*/
- function overrideExtraTemplateFileName() {
+ public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
}
-}
+}