<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
$this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this);
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
+
if (!isset($this->_gid) && $this->_fid) {
- $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
+ $this->_gid = CRM_Core_DAO::getFieldValue(
+ 'CRM_Core_DAO_CustomField',
$this->_fid,
'custom_group_id'
);
}
+
if ($this->_fid) {
- $this->_optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
+ $this->_optionGroupID = CRM_Core_DAO::getFieldValue(
+ 'CRM_Core_DAO_CustomField',
$this->_fid,
'option_group_id'
);
}
+ if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
+ CRM_Core_Error::fatal("You cannot add or edit muliple choice options in a reserved custom field-set.");
+ }
+
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
}
*/
public function buildQuickForm() {
if ($this->_action == CRM_Core_Action::DELETE) {
+ $option = civicrm_api3('option_value', 'getsingle', array('id' => $this->_id));
+ $this->assign('label', $option['label']);
$this->addButtons(array(
array(
'type' => 'next',
* @access public
*/
static function formRule($fields, $files, $form) {
- $optionLabel = CRM_Utils_Type::escape($fields['label'], 'String');
- $optionValue = CRM_Utils_Type::escape($fields['value'], 'String');
+ $optionLabel = $fields['label'];
+ $optionValue = $fields['value'];
$fieldId = $form->_fid;
$optionGroupId = $form->_optionGroupID;
$temp = array();
if (empty($form->_id)) {
$query = "
-SELECT count(*)
+SELECT count(*)
FROM civicrm_option_value
WHERE option_group_id = %1
AND label = %2";
- $params = array(1 => array($optionGroupId, 'Integer'),
+ $params = array(
+ 1 => array($optionGroupId, 'Integer'),
2 => array($optionLabel, 'String'),
);
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
}
$query = "
-SELECT count(*)
+SELECT count(*)
FROM civicrm_option_value
WHERE option_group_id = %1
AND value = %2";
- $params = array(1 => array($optionGroupId, 'Integer'),
+ $params = array(
+ 1 => array($optionGroupId, 'Integer'),
2 => array($optionValue, 'String'),
);
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
//check label duplicates within a custom field
$query = "
-SELECT count(*)
+SELECT count(*)
FROM civicrm_option_value
WHERE option_group_id = %1
AND id != %2
AND label = %3";
- $params = array(1 => array($optionGroupId, 'Integer'),
+ $params = array(
+ 1 => array($optionGroupId, 'Integer'),
2 => array($optionId, 'Integer'),
3 => array($optionLabel, 'String'),
);
//check value duplicates within a custom field
$query = "
-SELECT count(*)
+SELECT count(*)
FROM civicrm_option_value
WHERE option_group_id = %1
AND id != %2
AND value = %3";
- $params = array(1 => array($optionGroupId, 'Integer'),
+ $params = array(
+ 1 => array($optionGroupId, 'Integer'),
2 => array($optionId, 'Integer'),
3 => array($optionValue, 'String'),
);
}
$query = "
-SELECT data_type
+SELECT data_type
FROM civicrm_custom_field
WHERE id = %1";
$params = array(1 => array($fieldId, 'Integer'));
if (!empty($fields["value"])) {
$params = array(1 => array($fields['value'], 'String'));
$query = "
-SELECT count(*)
+SELECT count(*)
FROM civicrm_state_province
WHERE name = %1
OR abbreviation = %1";
$params = $this->controller->exportValues('Option');
if ($this->_action == CRM_Core_Action::DELETE) {
+ $option = civicrm_api3('option_value', 'getsingle', array('id' => $this->_id));
$fieldValues = array('option_group_id' => $this->_optionGroupID);
- $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
+ CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
CRM_Core_BAO_CustomOption::del($this->_id);
- CRM_Core_Session::setStatus(ts('Your multiple choice option has been deleted'), ts('Deleted'), 'success');
+ CRM_Core_Session::setStatus(ts('Option "%1" has been deleted.', array(1 => $option['label'])), ts('Deleted'), 'success');
return;
}
}
$fieldValues = array('option_group_id' => $this->_optionGroupID);
- $customOption->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, $params['weight'], $fieldValues);
+ $customOption->weight =
+ CRM_Utils_Weight::updateOtherWeights(
+ 'CRM_Core_DAO_OptionValue',
+ $oldWeight,
+ $params['weight'],
+ $fieldValues);
$customOption->option_group_id = $this->_optionGroupID;
$customField = new CRM_Core_DAO_CustomField();
$customField->id = $this->_fid;
- if ($customField->find(TRUE) &&
- ($customField->html_type == 'CheckBox' ||
+ if (
+ $customField->find(TRUE) &&
+ (
+ $customField->html_type == 'CheckBox' ||
$customField->html_type == 'AdvMulti-Select' ||
$customField->html_type == 'Multi-Select'
)
) {
- $defVal = explode(CRM_Core_DAO::VALUE_SEPARATOR,
+ $defVal = explode(
+ CRM_Core_DAO::VALUE_SEPARATOR,
substr($customField->default_value, 1, -1)
);
if (CRM_Utils_Array::value('default_value', $params)) {
else {
$defVal[] = $customOption->value;
}
- $customField->default_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $defVal) . CRM_Core_DAO::VALUE_SEPARATOR;
+ $customField->default_value =
+ CRM_Core_DAO::VALUE_SEPARATOR .
+ implode(CRM_Core_DAO::VALUE_SEPARATOR, $defVal) .
+ CRM_Core_DAO::VALUE_SEPARATOR;
$customField->save();
}
}
}
}
- $customField->default_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $tempVal) . CRM_Core_DAO::VALUE_SEPARATOR;
+ $customField->default_value =
+ CRM_Core_DAO::VALUE_SEPARATOR .
+ implode(CRM_Core_DAO::VALUE_SEPARATOR, $tempVal) .
+ CRM_Core_DAO::VALUE_SEPARATOR;
$customField->save();
}
}
$customOption->save();
- CRM_Core_Session::setStatus(ts('Your multiple choice option \'%1\' has been saved', array(1 => $customOption->label)), '', 'success');
+ $msg = ts('Your multiple choice option \'%1\' has been saved', array(1 => $customOption->label));
+ CRM_Core_Session::setStatus($msg, '', 'success');
$buttonName = $this->controller->getButtonName();
$session = CRM_Core_Session::singleton();
if ($buttonName == $this->getButtonName('next', 'new')) {
- CRM_Core_Session::setStatus(ts(' You can add another option.'), '', 'info');
- $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/option',
+ CRM_Core_Session::setStatus(ts('You can add another option.'), '', 'info');
+ $session->replaceUserContext(
+ CRM_Utils_System::url(
+ 'civicrm/admin/custom/group/field/option',
'reset=1&action=add&fid=' . $this->_fid . '&gid=' . $this->_gid
- ));
+ )
+ );
}
}
}