First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
326
sites/all/modules/civicrm/CRM/Custom/Form/ChangeFieldType.php
Normal file
326
sites/all/modules/civicrm/CRM/Custom/Form/ChangeFieldType.php
Normal file
|
@ -0,0 +1,326 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for Deleting Group
|
||||
*/
|
||||
class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The field id
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Array of custom field values
|
||||
*/
|
||||
protected $_values;
|
||||
|
||||
/**
|
||||
* Mapper array of valid field type
|
||||
*/
|
||||
protected $_htmlTypeTransitions;
|
||||
|
||||
/**
|
||||
* Set up variables to build the form.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive',
|
||||
$this, TRUE
|
||||
);
|
||||
|
||||
$this->_values = array();
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Core_BAO_CustomField::retrieve($params, $this->_values);
|
||||
|
||||
$this->_htmlTypeTransitions = self::fieldTypeTransitions(CRM_Utils_Array::value('data_type', $this->_values),
|
||||
CRM_Utils_Array::value('html_type', $this->_values)
|
||||
);
|
||||
|
||||
if (empty($this->_values) || empty($this->_htmlTypeTransitions)) {
|
||||
CRM_Core_Error::fatal(ts("Invalid custom field or can't change input type of this custom field."));
|
||||
}
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/admin/custom/group/field/update',
|
||||
"action=update&reset=1&gid={$this->_values['custom_group_id']}&id={$this->_id}"
|
||||
);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext($url);
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Change Field Type: %1',
|
||||
array(1 => $this->_values['label'])
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$srcHtmlType = $this->add('select',
|
||||
'src_html_type',
|
||||
ts('Current HTML Type'),
|
||||
array($this->_values['html_type'] => $this->_values['html_type']),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$srcHtmlType->setValue($this->_values['html_type']);
|
||||
$srcHtmlType->freeze();
|
||||
|
||||
$this->assign('srcHtmlType', $this->_values['html_type']);
|
||||
|
||||
$dstHtmlType = $this->add('select',
|
||||
'dst_html_type',
|
||||
ts('New HTML Type'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $this->_htmlTypeTransitions,
|
||||
TRUE
|
||||
);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Change Field Type'),
|
||||
'isDefault' => TRUE,
|
||||
'js' => array('onclick' => 'return checkCustomDataField();'),
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
|
||||
$this->_values['custom_group_id'],
|
||||
'table_name'
|
||||
);
|
||||
|
||||
$singleValueOps = array(
|
||||
'Text',
|
||||
'Select',
|
||||
'Radio',
|
||||
'Autocomplete-Select',
|
||||
);
|
||||
|
||||
$mutliValueOps = array(
|
||||
'CheckBox',
|
||||
'Multi-Select',
|
||||
'AdvMulti-Select',
|
||||
);
|
||||
|
||||
$srcHtmlType = $this->_values['html_type'];
|
||||
$dstHtmlType = $params['dst_html_type'];
|
||||
|
||||
$customField = new CRM_Core_DAO_CustomField();
|
||||
$customField->id = $this->_id;
|
||||
$customField->find(TRUE);
|
||||
|
||||
if ($dstHtmlType == 'Text' && in_array($srcHtmlType, array(
|
||||
'Select',
|
||||
'Radio',
|
||||
'Autocomplete-Select',
|
||||
))
|
||||
) {
|
||||
$customField->option_group_id = "NULL";
|
||||
CRM_Core_BAO_CustomField::checkOptionGroup($this->_values['option_group_id']);
|
||||
}
|
||||
|
||||
if (in_array($srcHtmlType, $mutliValueOps) &&
|
||||
in_array($dstHtmlType, $singleValueOps)
|
||||
) {
|
||||
$this->flattenToFirstValue($tableName, $this->_values['column_name']);
|
||||
}
|
||||
elseif (in_array($srcHtmlType, $singleValueOps) &&
|
||||
in_array($dstHtmlType, $mutliValueOps)
|
||||
) {
|
||||
$this->firstValueToFlatten($tableName, $this->_values['column_name']);
|
||||
}
|
||||
|
||||
$customField->html_type = $dstHtmlType;
|
||||
$customField->save();
|
||||
|
||||
// Reset cache for custom fields
|
||||
CRM_Core_BAO_Cache::deleteGroup('contact fields');
|
||||
|
||||
CRM_Core_Session::setStatus(ts('Input type of custom field \'%1\' has been successfully changed to \'%2\'.',
|
||||
array(1 => $this->_values['label'], 2 => $dstHtmlType)
|
||||
), ts('Field Type Changed'), 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dataType
|
||||
* @param $htmlType
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function fieldTypeTransitions($dataType, $htmlType) {
|
||||
// Text field is single value field,
|
||||
// can not be change to other single value option which contains option group
|
||||
if ($htmlType == 'Text') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$singleValueOps = array(
|
||||
'Text' => 'Text',
|
||||
'Select' => 'Select',
|
||||
'Radio' => 'Radio',
|
||||
'Autocomplete-Select' => 'Autocomplete-Select',
|
||||
);
|
||||
|
||||
$mutliValueOps = array(
|
||||
'CheckBox' => 'CheckBox',
|
||||
'Multi-Select' => 'Multi-Select',
|
||||
'AdvMulti-Select' => 'AdvMulti-Select',
|
||||
);
|
||||
|
||||
switch ($dataType) {
|
||||
case 'String':
|
||||
if (in_array($htmlType, array_keys($singleValueOps))) {
|
||||
unset($singleValueOps[$htmlType]);
|
||||
return array_merge($singleValueOps, $mutliValueOps);
|
||||
}
|
||||
elseif (in_array($htmlType, array_keys($mutliValueOps))) {
|
||||
unset($singleValueOps['Text']);
|
||||
foreach ($singleValueOps as $type => $label) {
|
||||
$singleValueOps[$type] = "{$label} ( " . ts('Not Safe') . " )";
|
||||
}
|
||||
unset($mutliValueOps[$htmlType]);
|
||||
return array_merge($mutliValueOps, $singleValueOps);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Int':
|
||||
case 'Float':
|
||||
case 'Int':
|
||||
case 'Money':
|
||||
if (in_array($htmlType, array_keys($singleValueOps))) {
|
||||
unset($singleValueOps[$htmlType]);
|
||||
return $singleValueOps;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Memo':
|
||||
$ops = array(
|
||||
'TextArea' => 'TextArea',
|
||||
'RichTextEditor' => 'RichTextEditor',
|
||||
);
|
||||
if (in_array($htmlType, array_keys($ops))) {
|
||||
unset($ops[$htmlType]);
|
||||
return $ops;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a single-value column (eg: a Radio or Select etc ) and convert
|
||||
* value to the multi listed value (eg:"^Foo^")
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
*/
|
||||
public function firstValueToFlatten($table, $column) {
|
||||
$selectSql = "SELECT id, $column FROM $table WHERE $column IS NOT NULL";
|
||||
$updateSql = "UPDATE $table SET $column = %1 WHERE id = %2";
|
||||
$dao = CRM_Core_DAO::executeQuery($selectSql);
|
||||
while ($dao->fetch()) {
|
||||
if (!$dao->{$column}) {
|
||||
continue;
|
||||
}
|
||||
$value = CRM_Core_DAO::VALUE_SEPARATOR . $dao->{$column} . CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
$params = array(
|
||||
1 => array((string) $value, 'String'),
|
||||
2 => array($dao->id, 'Integer'),
|
||||
);
|
||||
CRM_Core_DAO::executeQuery($updateSql, $params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a multi-value column (e.g. a Multi-Select or CheckBox column), and convert
|
||||
* all values (of the form "^^" or "^Foo^" or "^Foo^Bar^") to the first listed value ("Foo")
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
*/
|
||||
public function flattenToFirstValue($table, $column) {
|
||||
$selectSql = "SELECT id, $column FROM $table WHERE $column IS NOT NULL";
|
||||
$updateSql = "UPDATE $table SET $column = %1 WHERE id = %2";
|
||||
$dao = CRM_Core_DAO::executeQuery($selectSql);
|
||||
while ($dao->fetch()) {
|
||||
$values = self::explode($dao->{$column});
|
||||
$params = array(
|
||||
1 => array((string) array_shift($values), 'String'),
|
||||
2 => array($dao->id, 'Integer'),
|
||||
);
|
||||
CRM_Core_DAO::executeQuery($updateSql, $params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function explode($str) {
|
||||
if (empty($str) || $str == CRM_Core_DAO::VALUE_SEPARATOR . CRM_Core_DAO::VALUE_SEPARATOR) {
|
||||
return array();
|
||||
}
|
||||
else {
|
||||
return explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($str, CRM_Core_DAO::VALUE_SEPARATOR));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
197
sites/all/modules/civicrm/CRM/Custom/Form/CustomData.php
Normal file
197
sites/all/modules/civicrm/CRM/Custom/Form/CustomData.php
Normal file
|
@ -0,0 +1,197 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* this class builds custom data
|
||||
*/
|
||||
class CRM_Custom_Form_CustomData {
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param null|string $subName
|
||||
* @param null|string $subType
|
||||
* @param null|int $groupCount
|
||||
* @param string $type
|
||||
* @param null|int $entityID
|
||||
* @param null $onlySubType
|
||||
*/
|
||||
public static function preProcess(
|
||||
&$form, $subName = NULL, $subType = NULL,
|
||||
$groupCount = NULL, $type = NULL, $entityID = NULL, $onlySubType = NULL
|
||||
) {
|
||||
if ($type) {
|
||||
$form->_type = $type;
|
||||
}
|
||||
else {
|
||||
$form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
|
||||
}
|
||||
|
||||
if (isset($subType)) {
|
||||
$form->_subType = $subType;
|
||||
}
|
||||
else {
|
||||
$form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
|
||||
}
|
||||
|
||||
if ($form->_subType == 'null') {
|
||||
$form->_subType = NULL;
|
||||
}
|
||||
|
||||
if (isset($subName)) {
|
||||
$form->_subName = $subName;
|
||||
}
|
||||
else {
|
||||
$form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
|
||||
}
|
||||
|
||||
if ($form->_subName == 'null') {
|
||||
$form->_subName = NULL;
|
||||
}
|
||||
|
||||
if ($groupCount) {
|
||||
$form->_groupCount = $groupCount;
|
||||
}
|
||||
else {
|
||||
$form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
|
||||
}
|
||||
|
||||
$form->assign('cgCount', $form->_groupCount);
|
||||
|
||||
//carry qf key, since this form is not inhereting core form.
|
||||
if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String')) {
|
||||
$form->assign('qfKey', $qfKey);
|
||||
}
|
||||
|
||||
if ($entityID) {
|
||||
$form->_entityId = $entityID;
|
||||
}
|
||||
else {
|
||||
$form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
|
||||
}
|
||||
|
||||
$typeCheck = CRM_Utils_Request::retrieve('type', 'String');
|
||||
$urlGroupId = CRM_Utils_Request::retrieve('groupID', 'Positive');
|
||||
if (isset($typeCheck) && $urlGroupId) {
|
||||
$form->_groupID = $urlGroupId;
|
||||
}
|
||||
else {
|
||||
$form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
|
||||
}
|
||||
|
||||
$gid = (isset($form->_groupID)) ? $form->_groupID : NULL;
|
||||
$getCachedTree = isset($form->_getCachedTree) ? $form->_getCachedTree : TRUE;
|
||||
|
||||
$subType = $form->_subType;
|
||||
if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
|
||||
$subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR));
|
||||
}
|
||||
|
||||
self::setGroupTree($form, $subType, $gid, $onlySubType, $getCachedTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setDefaultValues(&$form) {
|
||||
$defaults = array();
|
||||
CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults, FALSE, FALSE, $form->get('action'));
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$form->addElement('hidden', 'hidden_custom', 1);
|
||||
$form->addElement('hidden', "hidden_custom_group_count[{$form->_groupID}]", $form->_groupCount);
|
||||
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $form->_groupTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $form
|
||||
* @param $subType
|
||||
* @param $gid
|
||||
* @param $onlySubType
|
||||
* @param $getCachedTree
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setGroupTree(&$form, $subType, $gid, $onlySubType = NULL, $getCachedTree = FALSE) {
|
||||
$singleRecord = NULL;
|
||||
if (!empty($form->_groupCount) && !empty($form->_multiRecordDisplay) && $form->_multiRecordDisplay == 'single') {
|
||||
$singleRecord = $form->_groupCount;
|
||||
}
|
||||
$mode = CRM_Utils_Request::retrieve('mode', 'String', $form);
|
||||
// when a new record is being added for multivalued custom fields.
|
||||
if (isset($form->_groupCount) && $form->_groupCount == 0 && $mode == 'add' &&
|
||||
!empty($form->_multiRecordDisplay) && $form->_multiRecordDisplay == 'single') {
|
||||
$singleRecord = 'new';
|
||||
}
|
||||
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type,
|
||||
NULL,
|
||||
$form->_entityId,
|
||||
$gid,
|
||||
$subType,
|
||||
$form->_subName,
|
||||
$getCachedTree,
|
||||
$onlySubType,
|
||||
FALSE,
|
||||
TRUE,
|
||||
$singleRecord
|
||||
);
|
||||
|
||||
if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
|
||||
$form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL, NULL, $form->_entityId);
|
||||
}
|
||||
// we should use simplified formatted groupTree
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
|
||||
|
||||
if (isset($form->_groupTree) && is_array($form->_groupTree)) {
|
||||
$keys = array_keys($groupTree);
|
||||
foreach ($keys as $key) {
|
||||
$form->_groupTree[$key] = $groupTree[$key];
|
||||
}
|
||||
return array($form, $groupTree);
|
||||
}
|
||||
else {
|
||||
$form->_groupTree = $groupTree;
|
||||
return array($form, $groupTree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?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 form is intended to replace the overloading of many forms to generate a snippet for custom data.
|
||||
*/
|
||||
class CRM_Custom_Form_CustomDataByType extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Preprocess function.
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
$this->_type = $this->_cdType = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, TRUE);
|
||||
$this->_subType = CRM_Utils_Request::retrieve('subType', 'String');
|
||||
$this->_subName = CRM_Utils_Request::retrieve('subName', 'String');
|
||||
$this->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive');
|
||||
$this->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive');
|
||||
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive');
|
||||
$this->_onlySubtype = CRM_Utils_Request::retrieve('onlySubtype', 'Boolean');
|
||||
$this->assign('cdType', FALSE);
|
||||
$this->assign('cgCount', $this->_groupCount);
|
||||
|
||||
$contactTypes = CRM_Contact_BAO_ContactType::contactTypeInfo();
|
||||
if (array_key_exists($this->_type, $contactTypes)) {
|
||||
$this->assign('contactId', $this->_entityId);
|
||||
}
|
||||
if (!is_array($this->_subType) && strstr($this->_subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
|
||||
$this->_subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($this->_subType, CRM_Core_DAO::VALUE_SEPARATOR));
|
||||
}
|
||||
CRM_Custom_Form_CustomData::setGroupTree($this, $this->_subType, $this->_groupID, $this->_onlySubtype);
|
||||
|
||||
$this->assign('suppressForm', TRUE);
|
||||
$this->controller->_generateQFKey = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, FALSE, FALSE, $this->get('action'));
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build quick form.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addElement('hidden', 'hidden_custom', 1);
|
||||
$this->addElement('hidden', "hidden_custom_group_count[{$this->_groupID}]", $this->_groupCount);
|
||||
CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree);
|
||||
}
|
||||
|
||||
}
|
111
sites/all/modules/civicrm/CRM/Custom/Form/DeleteField.php
Normal file
111
sites/all/modules/civicrm/CRM/Custom/Form/DeleteField.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for deleting a field
|
||||
*/
|
||||
class CRM_Custom_Form_DeleteField extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The group id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The title of the group being deleted.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Set up variables to build the form.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_id = $this->get('id');
|
||||
|
||||
$defaults = array();
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Core_BAO_CustomField::retrieve($params, $defaults);
|
||||
|
||||
$this->_title = CRM_Utils_Array::value('label', $defaults);
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Delete %1', array(1 => $this->_title)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete Custom Field'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$field = new CRM_Core_DAO_CustomField();
|
||||
$field->id = $this->_id;
|
||||
$field->find(TRUE);
|
||||
|
||||
CRM_Core_BAO_CustomField::deleteField($field);
|
||||
|
||||
// also delete any profiles associted with this custom field
|
||||
CRM_Core_Session::setStatus(ts('The custom field \'%1\' has been deleted.', array(1 => $field->label)), '', 'success');
|
||||
|
||||
}
|
||||
|
||||
}
|
120
sites/all/modules/civicrm/CRM/Custom/Form/DeleteGroup.php
Normal file
120
sites/all/modules/civicrm/CRM/Custom/Form/DeleteGroup.php
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for Deleting Group
|
||||
*/
|
||||
class CRM_Custom_Form_DeleteGroup extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The group id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The title of the group being deleted.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Set up variables to build the form.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_id = $this->get('id');
|
||||
|
||||
$defaults = array();
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Core_BAO_CustomGroup::retrieve($params, $defaults);
|
||||
$this->_title = $defaults['title'];
|
||||
|
||||
//check wheter this contain any custom fields
|
||||
$customField = new CRM_Core_DAO_CustomField();
|
||||
$customField->custom_group_id = $this->_id;
|
||||
|
||||
if ($customField->find(TRUE)) {
|
||||
CRM_Core_Session::setStatus(ts("The Group '%1' cannot be deleted! You must Delete all custom fields in this group prior to deleting the group.", array(1 => $this->_title)), ts('Deletion Error'), 'error');
|
||||
$url = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1");
|
||||
CRM_Utils_System::redirect($url);
|
||||
return TRUE;
|
||||
}
|
||||
$this->assign('title', $this->_title);
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Confirm Custom Group Delete'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete Custom Group'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$group = new CRM_Core_DAO_CustomGroup();
|
||||
$group->id = $this->_id;
|
||||
$group->find(TRUE);
|
||||
|
||||
$wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_CustomGroup', $this->_id);
|
||||
CRM_Core_BAO_CustomGroup::deleteGroup($group);
|
||||
CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", array(1 => $group->title)), '', 'success');
|
||||
}
|
||||
|
||||
}
|
1046
sites/all/modules/civicrm/CRM/Custom/Form/Field.php
Normal file
1046
sites/all/modules/civicrm/CRM/Custom/Form/Field.php
Normal file
File diff suppressed because it is too large
Load diff
526
sites/all/modules/civicrm/CRM/Custom/Form/Group.php
Normal file
526
sites/all/modules/civicrm/CRM/Custom/Form/Group.php
Normal file
|
@ -0,0 +1,526 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* form to process actions on the set aspect of Custom Data
|
||||
*/
|
||||
class CRM_Custom_Form_Group extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The set id saved to the session for an update.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* set is empty or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isGroupEmpty = TRUE;
|
||||
|
||||
/**
|
||||
* Array of existing subtypes set for a custom set.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_subtypes = array();
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// current set id
|
||||
$this->_id = $this->get('id');
|
||||
|
||||
if ($this->_id && $isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_id, 'is_reserved', 'id')) {
|
||||
CRM_Core_Error::fatal("You cannot edit the settings of a reserved custom field-set.");
|
||||
}
|
||||
// setting title for html page
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
|
||||
CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $title)));
|
||||
}
|
||||
elseif ($this->_action == CRM_Core_Action::VIEW) {
|
||||
$title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
|
||||
CRM_Utils_System::setTitle(ts('Preview %1', array(1 => $title)));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('New Custom Field Set'));
|
||||
}
|
||||
|
||||
if (isset($this->_id)) {
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Core_BAO_CustomGroup::retrieve($params, $this->_defaults);
|
||||
|
||||
$subExtends = CRM_Utils_Array::value('extends_entity_column_value', $this->_defaults);
|
||||
if (!empty($subExtends)) {
|
||||
$this->_subtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subExtends, 1, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param $self
|
||||
*
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
|
||||
//validate group title as well as name.
|
||||
$title = $fields['title'];
|
||||
$name = CRM_Utils_String::munge($title, '_', 64);
|
||||
$query = 'select count(*) from civicrm_custom_group where ( name like %1 OR title like %2 ) and id != %3';
|
||||
$grpCnt = CRM_Core_DAO::singleValueQuery($query, array(
|
||||
1 => array($name, 'String'),
|
||||
2 => array($title, 'String'),
|
||||
3 => array((int) $self->_id, 'Integer'),
|
||||
));
|
||||
if ($grpCnt) {
|
||||
$errors['title'] = ts('Custom group \'%1\' already exists in Database.', array(1 => $title));
|
||||
}
|
||||
|
||||
if (!empty($fields['extends'][1])) {
|
||||
if (in_array('', $fields['extends'][1]) && count($fields['extends'][1]) > 1) {
|
||||
$errors['extends'] = ts("Cannot combine other option with 'Any'.");
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($fields['extends'][0])) {
|
||||
$errors['extends'] = ts("You need to select the type of record that this set of custom fields is applicable for.");
|
||||
}
|
||||
|
||||
$extends = array('Activity', 'Relationship', 'Group', 'Contribution', 'Membership', 'Event', 'Participant');
|
||||
if (in_array($fields['extends'][0], $extends) && $fields['style'] == 'Tab') {
|
||||
$errors['style'] = ts("Display Style should be Inline for this Class");
|
||||
$self->assign('showStyle', TRUE);
|
||||
}
|
||||
|
||||
if (!empty($fields['is_multiple'])) {
|
||||
$self->assign('showMultiple', TRUE);
|
||||
}
|
||||
|
||||
if (empty($fields['is_multiple']) && $fields['style'] == 'Tab with table') {
|
||||
$errors['style'] = ts("Display Style 'Tab with table' is only supported for multiple-record custom field sets.");
|
||||
}
|
||||
|
||||
//checks the given custom set doesnot start with digit
|
||||
$title = $fields['title'];
|
||||
if (!empty($title)) {
|
||||
// gives the ascii value
|
||||
$asciiValue = ord($title{0});
|
||||
if ($asciiValue >= 48 && $asciiValue <= 57) {
|
||||
$errors['title'] = ts("Name cannot not start with a digit");
|
||||
}
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* add the rules (mainly global rules) for form.
|
||||
* All local rules are added near the element
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
* @see valid_date
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Custom_Form_Group', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup');
|
||||
|
||||
//title
|
||||
$this->add('text', 'title', ts('Set Name'), $attributes['title'], TRUE);
|
||||
|
||||
//Fix for code alignment, CRM-3058
|
||||
$contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
|
||||
$this->assign('contactTypes', json_encode($contactTypes));
|
||||
|
||||
$sel1 = array("" => ts("- select -")) + CRM_Core_SelectValues::customGroupExtends();
|
||||
$sel2 = array();
|
||||
$activityType = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
|
||||
|
||||
$eventType = CRM_Core_OptionGroup::values('event_type');
|
||||
$grantType = CRM_Core_OptionGroup::values('grant_type');
|
||||
$campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
|
||||
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
|
||||
$participantRole = CRM_Core_OptionGroup::values('participant_role');
|
||||
|
||||
ksort($sel1);
|
||||
asort($activityType);
|
||||
asort($eventType);
|
||||
asort($grantType);
|
||||
asort($membershipType);
|
||||
asort($participantRole);
|
||||
|
||||
$sel2['Event'] = $eventType;
|
||||
$sel2['Grant'] = $grantType;
|
||||
$sel2['Activity'] = $activityType;
|
||||
$sel2['Campaign'] = $campaignTypes;
|
||||
$sel2['Membership'] = $membershipType;
|
||||
$sel2['ParticipantRole'] = $participantRole;
|
||||
$sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
|
||||
$sel2['ParticipantEventType'] = $eventType;
|
||||
$sel2['Contribution'] = CRM_Contribute_PseudoConstant::financialType();
|
||||
$sel2['Relationship'] = self::getRelationshipTypes();
|
||||
|
||||
$sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
|
||||
$sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
|
||||
$sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
|
||||
|
||||
CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($sel2);
|
||||
|
||||
foreach ($sel2 as $main => $sub) {
|
||||
if (!empty($sel2[$main])) {
|
||||
$sel2[$main] = array(
|
||||
'' => ts("- Any -"),
|
||||
) + $sel2[$main];
|
||||
}
|
||||
}
|
||||
|
||||
$cSubTypes = CRM_Core_Component::contactSubTypes();
|
||||
|
||||
if (!empty($cSubTypes)) {
|
||||
$contactSubTypes = array();
|
||||
foreach ($cSubTypes as $key => $value) {
|
||||
$contactSubTypes[$key] = $key;
|
||||
}
|
||||
$sel2['Contact'] = array(
|
||||
"" => ("- Any -"),
|
||||
) + $contactSubTypes;
|
||||
}
|
||||
else {
|
||||
if (!isset($this->_id)) {
|
||||
$formName = 'document.forms.' . $this->_name;
|
||||
|
||||
$js = "<script type='text/javascript'>\n";
|
||||
$js .= "{$formName}['extends_1'].style.display = 'none';\n";
|
||||
$js .= "</script>";
|
||||
$this->assign('initHideBlocks', $js);
|
||||
}
|
||||
}
|
||||
|
||||
$sel = &$this->add('hierselect',
|
||||
'extends',
|
||||
ts('Used For'),
|
||||
array(
|
||||
'name' => 'extends[0]',
|
||||
'style' => 'vertical-align: top;',
|
||||
),
|
||||
TRUE
|
||||
);
|
||||
$sel->setOptions(array($sel1, $sel2));
|
||||
if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
|
||||
// make second selector a multi-select -
|
||||
$sel->_elements[1]->setMultiple(TRUE);
|
||||
$sel->_elements[1]->setSize(5);
|
||||
}
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$subName = CRM_Utils_Array::value('extends_entity_column_id', $this->_defaults);
|
||||
if ($this->_defaults['extends'] == 'Participant') {
|
||||
if ($subName == 1) {
|
||||
$this->_defaults['extends'] = 'ParticipantRole';
|
||||
}
|
||||
elseif ($subName == 2) {
|
||||
$this->_defaults['extends'] = 'ParticipantEventName';
|
||||
}
|
||||
elseif ($subName == 3) {
|
||||
$this->_defaults['extends'] = 'ParticipantEventType';
|
||||
}
|
||||
}
|
||||
|
||||
//allow to edit settings if custom set is empty CRM-5258
|
||||
$this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id);
|
||||
if (!$this->_isGroupEmpty) {
|
||||
if (!empty($this->_subtypes)) {
|
||||
// we want to allow adding / updating subtypes for this case,
|
||||
// and therefore freeze the first selector only.
|
||||
$sel->_elements[0]->freeze();
|
||||
}
|
||||
else {
|
||||
// freeze both the selectors
|
||||
$sel->freeze();
|
||||
}
|
||||
}
|
||||
$this->assign('isCustomGroupEmpty', $this->_isGroupEmpty);
|
||||
$this->assign('gid', $this->_id);
|
||||
}
|
||||
$this->assign('defaultSubtypes', json_encode($this->_subtypes));
|
||||
|
||||
// help text
|
||||
$this->add('wysiwyg', 'help_pre', ts('Pre-form Help'), $attributes['help_pre']);
|
||||
$this->add('wysiwyg', 'help_post', ts('Post-form Help'), $attributes['help_post']);
|
||||
|
||||
// weight
|
||||
$this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
|
||||
$this->addRule('weight', ts('is a numeric field'), 'numeric');
|
||||
|
||||
// display style
|
||||
$this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
|
||||
|
||||
// is this set collapsed or expanded ?
|
||||
$this->addElement('advcheckbox', 'collapse_display', ts('Collapse this set on initial display'));
|
||||
|
||||
// is this set collapsed or expanded ? in advanced search
|
||||
$this->addElement('advcheckbox', 'collapse_adv_display', ts('Collapse this set in Advanced Search'));
|
||||
|
||||
// is this set active ?
|
||||
$this->addElement('advcheckbox', 'is_active', ts('Is this Custom Data Set active?'));
|
||||
|
||||
//Is this set visible on public pages?
|
||||
$this->addElement('advcheckbox', 'is_public', ts('Is this Custom Data Set public?'));
|
||||
|
||||
// does this set have multiple record?
|
||||
$multiple = $this->addElement('advcheckbox', 'is_multiple',
|
||||
ts('Does this Custom Field Set allow multiple records?'), NULL);
|
||||
|
||||
// $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] );
|
||||
// $this->addRule('min_multiple', ts('is a numeric field') , 'numeric');
|
||||
|
||||
$max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']);
|
||||
$this->addRule('max_multiple', ts('is a numeric field'), 'numeric');
|
||||
|
||||
//allow to edit settings if custom set is empty CRM-5258
|
||||
$this->assign('isGroupEmpty', $this->_isGroupEmpty);
|
||||
if (!$this->_isGroupEmpty) {
|
||||
$multiple->freeze();
|
||||
//$min_multiple->freeze();
|
||||
$max_multiple->freeze();
|
||||
}
|
||||
|
||||
$this->assign('showStyle', FALSE);
|
||||
$this->assign('showMultiple', FALSE);
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
);
|
||||
if (!$this->_isGroupEmpty && !empty($this->_subtypes)) {
|
||||
$buttons[0]['class'] = 'crm-warnDataLoss';
|
||||
}
|
||||
$this->addButtons($buttons);
|
||||
|
||||
// TODO: Is this condition ever true? Can this code be removed?
|
||||
if ($this->_action & CRM_Core_Action::VIEW) {
|
||||
$this->freeze();
|
||||
$this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = &$this->_defaults;
|
||||
$this->assign('showMaxMultiple', TRUE);
|
||||
if ($this->_action == CRM_Core_Action::ADD) {
|
||||
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_CustomGroup');
|
||||
|
||||
$defaults['is_multiple'] = $defaults['min_multiple'] = 0;
|
||||
$defaults['is_active'] = $defaults['is_public'] = $defaults['collapse_display'] = 1;
|
||||
$defaults['style'] = 'Inline';
|
||||
}
|
||||
elseif (empty($defaults['max_multiple']) && !$this->_isGroupEmpty) {
|
||||
$this->assign('showMaxMultiple', FALSE);
|
||||
}
|
||||
|
||||
if (($this->_action & CRM_Core_Action::UPDATE) && !empty($defaults['is_multiple'])) {
|
||||
$defaults['collapse_display'] = 0;
|
||||
}
|
||||
|
||||
if (isset($defaults['extends'])) {
|
||||
$extends = $defaults['extends'];
|
||||
unset($defaults['extends']);
|
||||
|
||||
$defaults['extends'][0] = $extends;
|
||||
|
||||
if (!empty($this->_subtypes)) {
|
||||
$defaults['extends'][1] = $this->_subtypes;
|
||||
}
|
||||
else {
|
||||
$defaults['extends'][1] = array(0 => '');
|
||||
}
|
||||
|
||||
if ($extends == 'Relationship' && !empty($this->_subtypes)) {
|
||||
$relationshipDefaults = array();
|
||||
foreach ($defaults['extends'][1] as $donCare => $rel_type_id) {
|
||||
$relationshipDefaults[] = $rel_type_id;
|
||||
}
|
||||
|
||||
$defaults['extends'][1] = $relationshipDefaults;
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues('Group');
|
||||
$params['overrideFKConstraint'] = 0;
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$params['id'] = $this->_id;
|
||||
if ($this->_defaults['extends'][0] != $params['extends'][0]) {
|
||||
$params['overrideFKConstraint'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($this->_subtypes)) {
|
||||
$subtypesToBeRemoved = array();
|
||||
$subtypesToPreserve = $params['extends'][1];
|
||||
// Don't remove any value if group is extended to -any- subtype
|
||||
if (!empty($subtypesToPreserve[0])) {
|
||||
$subtypesToBeRemoved = array_diff($this->_subtypes, array_intersect($this->_subtypes, $subtypesToPreserve));
|
||||
}
|
||||
CRM_Contact_BAO_ContactType::deleteCustomRowsOfSubtype($this->_id, $subtypesToBeRemoved, $subtypesToPreserve);
|
||||
}
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::ADD) {
|
||||
//new custom set , so lets set the created_id
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$params['created_id'] = $session->get('userID');
|
||||
$params['created_date'] = date('YmdHis');
|
||||
}
|
||||
|
||||
$group = CRM_Core_BAO_CustomGroup::create($params);
|
||||
|
||||
// reset the cache
|
||||
CRM_Core_BAO_Cache::deleteGroup('contact fields');
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
CRM_Core_Session::setStatus(ts('Your custom field set \'%1 \' has been saved.', array(1 => $group->title)), ts('Saved'), 'success');
|
||||
}
|
||||
else {
|
||||
// Jump directly to adding a field if popups are disabled
|
||||
$action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? '' : '/add';
|
||||
$url = CRM_Utils_System::url("civicrm/admin/custom/group/field$action", 'reset=1&new=1&gid=' . $group->id . '&action=' . ($action ? 'add' : 'browse'));
|
||||
CRM_Core_Session::setStatus(ts("Your custom field set '%1' has been added. You can add custom fields now.",
|
||||
array(1 => $group->title)
|
||||
), ts('Saved'), 'success');
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext($url);
|
||||
}
|
||||
|
||||
// prompt Drupal Views users to update $db_prefix in settings.php, if necessary
|
||||
global $db_prefix;
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if (is_array($db_prefix) && $config->userSystem->is_drupal && module_exists('views')) {
|
||||
// get table_name for each custom group
|
||||
$tables = array();
|
||||
$sql = "SELECT table_name FROM civicrm_custom_group WHERE is_active = 1";
|
||||
$result = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($result->fetch()) {
|
||||
$tables[$result->table_name] = $result->table_name;
|
||||
}
|
||||
|
||||
// find out which tables are missing from the $db_prefix array
|
||||
$missingTableNames = array_diff_key($tables, $db_prefix);
|
||||
|
||||
if (!empty($missingTableNames)) {
|
||||
CRM_Core_Session::setStatus(ts("To ensure that all of your custom data groups are available to Views, you may need to add the following key(s) to the db_prefix array in your settings.php file: '%1'.",
|
||||
array(1 => implode(', ', $missingTableNames))
|
||||
), ts('Note'), 'info');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formatted list of relationship labels.
|
||||
*
|
||||
* @return array
|
||||
* Array (int $id => string $label).
|
||||
*/
|
||||
public static function getRelationshipTypes() {
|
||||
// Note: We include inactive reltypes because we don't want to break custom-data
|
||||
// UI when a reltype is disabled.
|
||||
return CRM_Core_DAO::executeQuery('
|
||||
SELECT
|
||||
id,
|
||||
(CASE 1
|
||||
WHEN label_a_b is not null AND label_b_a is not null AND label_a_b != label_b_a
|
||||
THEN concat(label_a_b, \' / \', label_b_a)
|
||||
WHEN label_a_b is not null
|
||||
THEN label_a_b
|
||||
WHEN label_b_a is not null
|
||||
THEN label_b_a
|
||||
ELSE concat("RelType #", id)
|
||||
END) as label
|
||||
FROM civicrm_relationship_type
|
||||
'
|
||||
)->fetchMap('id', 'label');
|
||||
}
|
||||
|
||||
}
|
182
sites/all/modules/civicrm/CRM/Custom/Form/MoveField.php
Normal file
182
sites/all/modules/civicrm/CRM/Custom/Form/MoveField.php
Normal file
|
@ -0,0 +1,182 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for Deleting Group
|
||||
*/
|
||||
class CRM_Custom_Form_MoveField extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The src group id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_srcGID;
|
||||
|
||||
/**
|
||||
* The src field id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_srcFID;
|
||||
|
||||
/**
|
||||
* The dst group id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_dstGID;
|
||||
|
||||
/**
|
||||
* The dst field id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_dstFID;
|
||||
|
||||
/**
|
||||
* The title of the field being moved.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_srcFieldLabel;
|
||||
|
||||
/**
|
||||
* Set up variables to build the form.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_srcFID = CRM_Utils_Request::retrieve('fid', 'Positive',
|
||||
$this, TRUE
|
||||
);
|
||||
|
||||
$this->_srcGID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
|
||||
$this->_srcFID,
|
||||
'custom_group_id'
|
||||
);
|
||||
|
||||
$this->_srcFieldLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
|
||||
$this->_srcFID,
|
||||
'label'
|
||||
);
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Custom Field Move: %1',
|
||||
array(1 => $this->_srcFieldLabel)
|
||||
));
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_srcGID}"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$customGroup = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
|
||||
unset($customGroup[$this->_srcGID]);
|
||||
if (empty($customGroup)) {
|
||||
CRM_Core_Error::statusBounce(ts('You need more than one custom group to move fields'));
|
||||
}
|
||||
|
||||
$customGroup = array(
|
||||
'' => ts('- select -'),
|
||||
) + $customGroup;
|
||||
$this->add('select',
|
||||
'dst_group_id',
|
||||
ts('Destination'),
|
||||
$customGroup,
|
||||
TRUE
|
||||
);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Move Custom Field'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->addFormRule(array('CRM_Custom_Form_MoveField', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$self->_dstGID = $fields['dst_group_id'];
|
||||
$tmp = CRM_Core_BAO_CustomField::_moveFieldValidate($self->_srcFID, $self->_dstGID);
|
||||
$errors = array();
|
||||
if ($tmp['newGroupID']) {
|
||||
$errors['dst_group_id'] = $tmp['newGroupID'];
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Core_BAO_CustomField::moveField($this->_srcFID, $this->_dstGID);
|
||||
|
||||
$dstGroup = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
|
||||
$this->_dstGID,
|
||||
'title'
|
||||
);
|
||||
$srcUrl = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_dstGID}");
|
||||
CRM_Core_Session::setStatus(ts("%1 has been moved to the custom set <a href='%3'>%2</a>.",
|
||||
array(
|
||||
1 => $this->_srcFieldLabel,
|
||||
2 => $dstGroup,
|
||||
3 => $srcUrl,
|
||||
)), '', 'success');
|
||||
}
|
||||
|
||||
}
|
516
sites/all/modules/civicrm/CRM/Custom/Form/Option.php
Normal file
516
sites/all/modules/civicrm/CRM/Custom/Form/Option.php
Normal file
|
@ -0,0 +1,516 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* form to process actions on the field aspect of Custom
|
||||
*/
|
||||
class CRM_Custom_Form_Option extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The custom field id saved to the session for an update
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_fid;
|
||||
|
||||
/**
|
||||
* The custom group id saved to the session for an update
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_gid;
|
||||
|
||||
/**
|
||||
* The option group ID
|
||||
*/
|
||||
protected $_optionGroupID = NULL;
|
||||
|
||||
/**
|
||||
* The Option id, used when editing the Option
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$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->_fid,
|
||||
'custom_group_id'
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->_fid) {
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $fieldDefaults = array();
|
||||
if (isset($this->_id)) {
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Core_BAO_CustomOption::retrieve($params, $defaults);
|
||||
|
||||
$paramsField = array('id' => $this->_fid);
|
||||
CRM_Core_BAO_CustomField::retrieve($paramsField, $fieldDefaults);
|
||||
|
||||
if ($fieldDefaults['html_type'] == 'CheckBox'
|
||||
|| $fieldDefaults['html_type'] == 'Multi-Select'
|
||||
|| $fieldDefaults['html_type'] == 'AdvMulti-Select'
|
||||
) {
|
||||
if (!empty($fieldDefaults['default_value'])) {
|
||||
$defaultCheckValues = explode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
substr($fieldDefaults['default_value'], 1, -1)
|
||||
);
|
||||
if (in_array($defaults['value'], $defaultCheckValues)) {
|
||||
$defaults['default_value'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (CRM_Utils_Array::value('default_value', $fieldDefaults) == CRM_Utils_Array::value('value', $defaults)) {
|
||||
$defaults['default_value'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$defaults['is_active'] = 1;
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$fieldValues = array('option_group_id' => $this->_optionGroupID);
|
||||
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
// lets trim all the whitespace
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
// hidden Option Id for validation use
|
||||
$this->add('hidden', 'optionId', $this->_id);
|
||||
|
||||
//hidden field ID for validation use
|
||||
$this->add('hidden', 'fieldId', $this->_fid);
|
||||
|
||||
// label
|
||||
$this->add('text', 'label', ts('Option Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
|
||||
|
||||
$this->add('text', 'value', ts('Option Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'), TRUE);
|
||||
|
||||
// weight
|
||||
$this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
|
||||
$this->addRule('weight', ts('is a numeric field'), 'numeric');
|
||||
|
||||
// is active ?
|
||||
$this->add('checkbox', 'is_active', ts('Active?'));
|
||||
|
||||
// Set the default value for Custom Field
|
||||
$this->add('checkbox', 'default_value', ts('Default'));
|
||||
|
||||
// add a custom form rule
|
||||
$this->addFormRule(array('CRM_Custom_Form_Option', 'formRule'), $this);
|
||||
|
||||
// add buttons
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// if view mode pls freeze it with the done button.
|
||||
if ($this->_action & CRM_Core_Action::VIEW) {
|
||||
$this->freeze();
|
||||
$url = CRM_Utils_System::url('civicrm/admin/custom/group/field/option',
|
||||
'reset=1&action=browse&fid=' . $this->_fid . '&gid=' . $this->_gid,
|
||||
TRUE, NULL, FALSE
|
||||
);
|
||||
$this->addElement('button',
|
||||
'done',
|
||||
ts('Done'),
|
||||
array('onclick' => "location.href='$url'", 'class' => 'crm-form-submit cancel', 'crm-icon' => 'fa-times')
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->assign('id', $this->_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
$optionLabel = $fields['label'];
|
||||
$optionValue = $fields['value'];
|
||||
$fieldId = $form->_fid;
|
||||
$optionGroupId = $form->_optionGroupID;
|
||||
|
||||
$temp = array();
|
||||
if (empty($form->_id)) {
|
||||
$query = "
|
||||
SELECT count(*)
|
||||
FROM civicrm_option_value
|
||||
WHERE option_group_id = %1
|
||||
AND label = %2";
|
||||
$params = array(
|
||||
1 => array($optionGroupId, 'Integer'),
|
||||
2 => array($optionLabel, 'String'),
|
||||
);
|
||||
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
|
||||
$errors['label'] = ts('There is an entry with the same label.');
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT count(*)
|
||||
FROM civicrm_option_value
|
||||
WHERE option_group_id = %1
|
||||
AND value = %2";
|
||||
$params = array(
|
||||
1 => array($optionGroupId, 'Integer'),
|
||||
2 => array($optionValue, 'String'),
|
||||
);
|
||||
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
|
||||
$errors['value'] = ts('There is an entry with the same value.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
//capture duplicate entries while updating Custom Options
|
||||
$optionId = CRM_Utils_Type::escape($fields['optionId'], 'Integer');
|
||||
|
||||
//check label duplicates within a custom field
|
||||
$query = "
|
||||
SELECT count(*)
|
||||
FROM civicrm_option_value
|
||||
WHERE option_group_id = %1
|
||||
AND id != %2
|
||||
AND label = %3";
|
||||
$params = array(
|
||||
1 => array($optionGroupId, 'Integer'),
|
||||
2 => array($optionId, 'Integer'),
|
||||
3 => array($optionLabel, 'String'),
|
||||
);
|
||||
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
|
||||
$errors['label'] = ts('There is an entry with the same label.');
|
||||
}
|
||||
|
||||
//check value duplicates within a custom field
|
||||
$query = "
|
||||
SELECT count(*)
|
||||
FROM civicrm_option_value
|
||||
WHERE option_group_id = %1
|
||||
AND id != %2
|
||||
AND value = %3";
|
||||
$params = array(
|
||||
1 => array($optionGroupId, 'Integer'),
|
||||
2 => array($optionId, 'Integer'),
|
||||
3 => array($optionValue, 'String'),
|
||||
);
|
||||
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
|
||||
$errors['value'] = ts('There is an entry with the same value.');
|
||||
}
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT data_type
|
||||
FROM civicrm_custom_field
|
||||
WHERE id = %1";
|
||||
$params = array(1 => array($fieldId, 'Integer'));
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $params);
|
||||
if ($dao->fetch()) {
|
||||
switch ($dao->data_type) {
|
||||
case 'Int':
|
||||
if (!CRM_Utils_Rule::integer($fields["value"])) {
|
||||
$errors['value'] = ts('Please enter a valid integer value.');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Float':
|
||||
// case 'Money':
|
||||
if (!CRM_Utils_Rule::numeric($fields["value"])) {
|
||||
$errors['value'] = ts('Please enter a valid number.');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Money':
|
||||
if (!CRM_Utils_Rule::money($fields["value"])) {
|
||||
$errors['value'] = ts('Please enter a valid value.');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Date':
|
||||
if (!CRM_Utils_Rule::date($fields["value"])) {
|
||||
$errors['value'] = ts('Please enter a valid date using YYYY-MM-DD format. Example: 2004-12-31.');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Boolean':
|
||||
if (!CRM_Utils_Rule::integer($fields["value"]) &&
|
||||
($fields["value"] != '1' || $fields["value"] != '0')
|
||||
) {
|
||||
$errors['value'] = ts('Please enter 1 or 0 as value.');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Country':
|
||||
if (!empty($fields["value"])) {
|
||||
$params = array(1 => array($fields['value'], 'String'));
|
||||
$query = "SELECT count(*) FROM civicrm_country WHERE name = %1 OR iso_code = %1";
|
||||
if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
|
||||
$errors['value'] = ts('Invalid default value for country.');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'StateProvince':
|
||||
if (!empty($fields["value"])) {
|
||||
$params = array(1 => array($fields['value'], 'String'));
|
||||
$query = "
|
||||
SELECT count(*)
|
||||
FROM civicrm_state_province
|
||||
WHERE name = %1
|
||||
OR abbreviation = %1";
|
||||
if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
|
||||
$errors['value'] = ts('The invalid value for State/Province data type');
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$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);
|
||||
CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
|
||||
CRM_Core_BAO_CustomOption::del($this->_id);
|
||||
CRM_Core_Session::setStatus(ts('Option "%1" has been deleted.', array(1 => $option['label'])), ts('Deleted'), 'success');
|
||||
return;
|
||||
}
|
||||
|
||||
// set values for custom field properties and save
|
||||
$customOption = new CRM_Core_DAO_OptionValue();
|
||||
$customOption->label = $params['label'];
|
||||
$customOption->name = CRM_Utils_String::titleToVar($params['label']);
|
||||
$customOption->weight = $params['weight'];
|
||||
$customOption->value = $params['value'];
|
||||
$customOption->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
|
||||
$oldWeight = NULL;
|
||||
if ($this->_id) {
|
||||
$customOption->id = $this->_id;
|
||||
CRM_Core_BAO_CustomOption::updateCustomValues($params);
|
||||
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'weight', 'id');
|
||||
}
|
||||
|
||||
$fieldValues = array('option_group_id' => $this->_optionGroupID);
|
||||
$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' ||
|
||||
$customField->html_type == 'AdvMulti-Select' ||
|
||||
$customField->html_type == 'Multi-Select'
|
||||
)
|
||||
) {
|
||||
$defVal = explode(
|
||||
CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
substr($customField->default_value, 1, -1)
|
||||
);
|
||||
if (!empty($params['default_value'])) {
|
||||
if (!in_array($customOption->value, $defVal)) {
|
||||
if (empty($defVal[0])) {
|
||||
$defVal = array($customOption->value);
|
||||
}
|
||||
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->save();
|
||||
}
|
||||
}
|
||||
elseif (in_array($customOption->value, $defVal)) {
|
||||
$tempVal = array();
|
||||
foreach ($defVal as $v) {
|
||||
if ($v != $customOption->value) {
|
||||
$tempVal[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$customField->default_value
|
||||
= CRM_Core_DAO::VALUE_SEPARATOR .
|
||||
implode(CRM_Core_DAO::VALUE_SEPARATOR, $tempVal) .
|
||||
CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
$customField->save();
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch ($customField->data_type) {
|
||||
case 'Money':
|
||||
$customOption->value = CRM_Utils_Rule::cleanMoney($customOption->value);
|
||||
break;
|
||||
|
||||
case 'Int':
|
||||
$customOption->value = intval($customOption->value);
|
||||
break;
|
||||
|
||||
case 'Float':
|
||||
$customOption->value = floatval($customOption->value);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($params['default_value'])) {
|
||||
$customField->default_value = $customOption->value;
|
||||
$customField->save();
|
||||
}
|
||||
elseif ($customField->find(TRUE) && $customField->default_value == $customOption->value) {
|
||||
// this is the case where this option is the current default value and we have been reset
|
||||
$customField->default_value = 'null';
|
||||
$customField->save();
|
||||
}
|
||||
}
|
||||
|
||||
$customOption->save();
|
||||
|
||||
$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',
|
||||
'reset=1&action=add&fid=' . $this->_fid . '&gid=' . $this->_gid
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
130
sites/all/modules/civicrm/CRM/Custom/Form/Preview.php
Normal file
130
sites/all/modules/civicrm/CRM/Custom/Form/Preview.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?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
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for previewing custom data
|
||||
*
|
||||
* It delegates the work to lower level subclasses and integrates the changes
|
||||
* back in. It also uses a lot of functionality with the CRM API's, so any change
|
||||
* made here could potentially affect the API etc. Be careful, be aware, use unit tests.
|
||||
*
|
||||
*/
|
||||
class CRM_Custom_Form_Preview extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The group tree data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_groupTree;
|
||||
|
||||
/**
|
||||
* Pre processing work done here.
|
||||
*
|
||||
* gets session variables for group or field id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// get the controller vars
|
||||
$this->_groupId = $this->get('groupId');
|
||||
$this->_fieldId = $this->get('fieldId');
|
||||
if ($this->_fieldId) {
|
||||
// field preview
|
||||
$defaults = array();
|
||||
$params = array('id' => $this->_fieldId);
|
||||
$fieldDAO = new CRM_Core_DAO_CustomField();
|
||||
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
|
||||
|
||||
if (!empty($defaults['is_view'])) {
|
||||
CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.'));
|
||||
}
|
||||
elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) {
|
||||
CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.'));
|
||||
}
|
||||
|
||||
$groupTree = array();
|
||||
$groupTree[$this->_groupId]['id'] = 0;
|
||||
$groupTree[$this->_groupId]['fields'] = array();
|
||||
$groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults;
|
||||
$this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
|
||||
$this->assign('preview_type', 'field');
|
||||
}
|
||||
else {
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId);
|
||||
$this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this);
|
||||
$this->assign('preview_type', 'group');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, FALSE, FALSE);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if (is_array($this->_groupTree[$this->_groupId])) {
|
||||
foreach ($this->_groupTree[$this->_groupId]['fields'] as & $field) {
|
||||
//add the form elements
|
||||
CRM_Core_BAO_CustomField::addQuickFormElement($this, $field['element_name'], $field['id'], CRM_Utils_Array::value('is_required', $field));
|
||||
}
|
||||
|
||||
$this->assign('groupTree', $this->_groupTree);
|
||||
}
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Done with Preview'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue