/** * Function to actually build the form * * @param null * * @return void * @access public */ public function buildQuickForm() { if ($this->_gid) { $this->_title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'title'); CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Custom Fields')); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomField'); // label $this->add('text', 'label', ts('Field Label'), $attributes['label'], TRUE); $dt =& self::$_dataTypeValues; $it = array(); foreach ($dt as $key => $value) { $it[$key] = self::$_dataToLabels[$key]; } $sel =& $this->addElement('hierselect', 'data_type', ts('Data and Input Field Type'), 'onclick="clearSearchBoxes();custom_option_html_type(this.form)"; onBlur="custom_option_html_type(this.form)";', ' '); $sel->setOptions(array($dt, $it)); if ($this->_action == CRM_Core_Action::UPDATE) { $this->freeze('data_type'); } $includeFieldIds = NULL; if ($this->_action == CRM_Core_Action::UPDATE) { $includeFieldIds = $this->_values['id']; } $optionGroups = CRM_Core_BAO_CustomField::customOptionGroup($includeFieldIds); $emptyOptGroup = FALSE; if (empty($optionGroups)) { $emptyOptGroup = TRUE; $optionTypes = array('1' => ts('Create a new set of options')); } else { $optionTypes = array('1' => ts('Create a new set of options'), '2' => ts('Reuse an existing set')); $this->add('select', 'option_group_id', ts('Multiple Choice Option Sets'), array('' => ts('- select -')) + $optionGroups); } $element =& $this->addRadio('option_type', ts('Option Type'), $optionTypes, array('onclick' => "showOptionSelect();"), '<br/>'); $contactGroups = CRM_Core_PseudoConstant::group(); asort($contactGroups); $this->add('select', 'group_id', ts('Limit List to Group'), $contactGroups, FALSE, array('multiple' => 'multiple')); $this->add('text', 'filter', ts('Advanced Filter'), $attributes['filter']); $this->add('hidden', 'filter_selected', 'Group', array('id' => 'filter_selected')); //if empty option group freeze the option type. if ($emptyOptGroup) { $element->freeze(); } // form fields of Custom Option rows $defaultOption = array(); $_showHide = new CRM_Core_ShowHideBlocks('', ''); for ($i = 1; $i <= self::NUM_OPTION; $i++) { //the show hide blocks $showBlocks = 'optionField_' . $i; if ($i > 2) { $_showHide->addHide($showBlocks); if ($i == self::NUM_OPTION) { $_showHide->addHide('additionalOption'); } } else { $_showHide->addShow($showBlocks); } $optionAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue'); // label $this->add('text', 'option_label[' . $i . ']', ts('Label'), $optionAttributes['label']); // value $this->add('text', 'option_value[' . $i . ']', ts('Value'), $optionAttributes['value']); // weight $this->add('text', "option_weight[{$i}]", ts('Order'), $optionAttributes['weight']); // is active ? $this->add('checkbox', "option_status[{$i}]", ts('Active?')); $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i); //for checkbox handling of default option $this->add('checkbox', "default_checkbox_option[{$i}]", NULL); } //default option selection $this->addGroup($defaultOption, 'default_option'); $_showHide->addToTemplate(); // text length for alpha numeric data types $this->add('text', 'text_length', ts('Database field length'), $attributes['text_length'], FALSE); $this->addRule('text_length', ts('Value should be a positive number'), 'integer'); $this->add('text', 'start_date_years', ts('Dates may be up to'), $attributes['start_date_years'], FALSE); $this->add('text', 'end_date_years', ts('Dates may be up to'), $attributes['end_date_years'], FALSE); $this->addRule('start_date_years', ts('Value should be a positive number'), 'integer'); $this->addRule('end_date_years', ts('Value should be a positive number'), 'integer'); $this->add('select', 'date_format', ts('Date Format'), array('' => ts('- select -')) + CRM_Core_SelectValues::getDatePluginInputFormats()); $this->add('select', 'time_format', ts('Time'), array('' => ts('- none -')) + CRM_Core_SelectValues::getTimeFormats()); // for Note field $this->add('text', 'note_columns', ts('Width (columns)') . ' ', $attributes['note_columns'], FALSE); $this->add('text', 'note_rows', ts('Height (rows)') . ' ', $attributes['note_rows'], FALSE); $this->add('text', 'note_length', ts('Maximum length') . ' ', $attributes['text_length'], FALSE); $this->addRule('note_columns', ts('Value should be a positive number'), 'positiveInteger'); $this->addRule('note_rows', ts('Value should be a positive number'), 'positiveInteger'); $this->addRule('note_length', ts('Value should be a positive number'), 'positiveInteger'); // weight $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE); $this->addRule('weight', ts('is a numeric field'), 'numeric'); // is required ? $this->add('checkbox', 'is_required', ts('Required?')); // checkbox / radio options per line $this->add('text', 'options_per_line', ts('Options Per Line')); $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric'); // default value, help pre, help post, mask, attributes, javascript ? $this->add('text', 'default_value', ts('Default Value'), $attributes['default_value']); $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']); $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']); $this->add('text', 'mask', ts('Mask'), $attributes['mask']); // is active ? $this->add('checkbox', 'is_active', ts('Active?')); // is active ? $this->add('checkbox', 'is_view', ts('View Only?')); // is searchable ? $this->addElement('checkbox', 'is_searchable', ts('Is this Field Searchable?'), NULL, array('onclick' => "showSearchRange(this)")); // is searchable by range? $searchRange = array(); $searchRange[] = $this->createElement('radio', NULL, NULL, ts('Yes'), '1'); $searchRange[] = $this->createElement('radio', NULL, NULL, ts('No'), '0'); $this->addGroup($searchRange, 'is_search_range', ts('Search by Range?')); // 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')))); // add a form rule to check default value $this->addFormRule(array('CRM_Custom_Form_Field', 'formRule'), $this); // 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', 'reset=1&action=browse&gid=' . $this->_gid); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'")); } }