/** * 增加新的用户组 * * @param object $data * @return boolean true|false * @access public */ public function addGroup(GroupSave $data) { if (!$this->groupValidate->add($data)) { return $this->setErrorMsg($this->groupValidate->getErrorMessage()); } if (!$this->acl->checkGroupLevelPermission($data->level, Acl::GROUP_LEVEL_TYPE_LEVEL)) { return $this->setErrorMsg(Lang::get('common.account_level_deny')); } if ($this->groupModel->addGroup($data->toArray()) !== false) { return true; } return $this->setErrorMsg(Lang::get('common.action_error')); }
/** * Constructor Summary * * o Creates a standard progress bar into a dialog box (QuickForm). * Form name, buttons 'start', 'cancel' labels and style, and * title of dialog box may also be changed. * <code> * $monitor = new HTML_Progress_Monitor(); * </code> * * o Creates a progress bar into a dialog box, with only a new * form name. * <code> * $monitor = new HTML_Progress_Monitor($formName); * </code> * * o Creates a progress bar into a dialog box, with a new form name, * new buttons name and style, and also a different title box. * <code> * $monitor = new HTML_Progress_Monitor($formName, $attributes); * </code> * * @param string $formName (optional) Name of monitor dialog box (QuickForm) * @param array $attributes (optional) List of renderer options * @param array $errorPrefs (optional) Hash of params to configure error handler * * @since 1.0 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT */ function HTML_Progress_Monitor($formName = 'ProgressMonitor', $attributes = array(), $errorPrefs = array()) { $bar = new HTML_Progress($errorPrefs); $this->_progress = $bar; if (!is_string($formName)) { return $this->_progress->raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$formName', 'was' => gettype($formName), 'expected' => 'string', 'paramnum' => 1)); } elseif (!is_array($attributes)) { return $this->_progress->raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$attributes', 'was' => gettype($attributes), 'expected' => 'array', 'paramnum' => 2)); } $this->_id = md5(microtime()); $this->_form = new HTML_QuickForm($formName); $this->_form->removeAttribute('name'); // XHTML compliance $this->windowname = isset($attributes['title']) ? $attributes['title'] : 'In progress ...'; $this->buttonStart = isset($attributes['start']) ? $attributes['start'] : 'Start'; $this->buttonCancel = isset($attributes['cancel']) ? $attributes['cancel'] : 'Cancel'; $buttonAttr = isset($attributes['button']) ? $attributes['button'] : ''; $this->_form->addElement('header', 'windowname', $this->windowname); $this->_form->addElement('static', 'progressBar'); $this->_form->addElement('static', 'progressStatus'); $style = $this->isStarted() ? array('disabled' => 'true') : null; $buttons[] =& $this->_form->createElement('submit', 'start', $this->buttonStart, $style); $buttons[] =& $this->_form->createElement('submit', 'cancel', $this->buttonCancel); $buttons[0]->updateAttributes($buttonAttr); $buttons[1]->updateAttributes($buttonAttr); $this->_form->addGroup($buttons, 'buttons', '', ' ', false); // default embedded progress element with look-and-feel $this->setProgressElement($bar); $str =& $this->_form->getElement('progressStatus'); $str->setText('<div id="status" class="progressStatus"> </div>'); }
/** * Add the unit handling options to the form. * @param object $mform the form being built. */ protected function add_unit_options($mform) { $mform->addElement('header', 'unithandling', get_string('unithandling', 'qtype_numerical')); $unitoptions = array(qtype_numerical::UNITNONE => get_string('onlynumerical', 'qtype_numerical'), qtype_numerical::UNITOPTIONAL => get_string('manynumerical', 'qtype_numerical'), qtype_numerical::UNITGRADED => get_string('unitgraded', 'qtype_numerical')); $mform->addElement('select', 'unitrole', get_string('unithandling', 'qtype_numerical'), $unitoptions); $penaltygrp = array(); $penaltygrp[] = $mform->createElement('text', 'unitpenalty', get_string('unitpenalty', 'qtype_numerical'), array('size' => 6)); $mform->setType('unitpenalty', PARAM_FLOAT); $mform->setDefault('unitpenalty', 0.1); $unitgradingtypes = array(qtype_numerical::UNITGRADEDOUTOFMARK => get_string('decfractionofresponsegrade', 'qtype_numerical'), qtype_numerical::UNITGRADEDOUTOFMAX => get_string('decfractionofquestiongrade', 'qtype_numerical')); $penaltygrp[] = $mform->createElement('select', 'unitgradingtypes', '', $unitgradingtypes); $mform->setDefault('unitgradingtypes', 1); $mform->addGroup($penaltygrp, 'penaltygrp', get_string('unitpenalty', 'qtype_numerical'), ' ', false); $mform->addHelpButton('penaltygrp', 'unitpenalty', 'qtype_numerical'); $unitinputoptions = array(qtype_numerical::UNITINPUT => get_string('editableunittext', 'qtype_numerical'), qtype_numerical::UNITRADIO => get_string('unitchoice', 'qtype_numerical'), qtype_numerical::UNITSELECT => get_string('unitselect', 'qtype_numerical')); $mform->addElement('select', 'multichoicedisplay', get_string('studentunitanswer', 'qtype_numerical'), $unitinputoptions); $unitsleftoptions = array(0 => get_string('rightexample', 'qtype_numerical'), 1 => get_string('leftexample', 'qtype_numerical')); $mform->addElement('select', 'unitsleft', get_string('unitposition', 'qtype_numerical'), $unitsleftoptions); $mform->setDefault('unitsleft', 0); $mform->disabledIf('penaltygrp', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('penaltygrp', 'unitrole', 'eq', qtype_numerical::UNITOPTIONAL); $mform->disabledIf('unitsleft', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('multichoicedisplay', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('multichoicedisplay', 'unitrole', 'eq', qtype_numerical::UNITOPTIONAL); }
/** * The progress uploader class constructor * * @param string $formName (optional) Name of monitor dialog box (QuickForm) * @param array $attributes (optional) List of renderer options * * @since 1.1 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT */ function HTML_Progress_Uploader($formName = 'ProgressUploader', $attributes = array()) { $this->_package = 'HTML_Progress_Uploader'; Error_Raise::initialize($this->_package, array('HTML_Progress', '_getErrorMessage')); if (!is_string($formName)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$formName', 'was' => gettype($formName), 'expected' => 'string', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif (!is_array($attributes)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$attributes', 'was' => gettype($attributes), 'expected' => 'array', 'paramnum' => 2), PEAR_ERROR_TRIGGER); } parent::FTP_Upload(); // checks all necessary dependencies $this->_form = new HTML_QuickForm($formName); $this->windowname = isset($attributes['title']) ? $attributes['title'] : 'Upload ...'; $this->captionMask = isset($attributes['mask']) ? $attributes['mask'] : '%s'; $this->buttonStart = isset($attributes['start']) ? $attributes['start'] : 'Start'; $this->buttonCancel = isset($attributes['cancel']) ? $attributes['cancel'] : 'Cancel'; $buttonAttr = isset($attributes['button']) ? $attributes['button'] : ''; $this->_form->addElement('header', 'windowname', $this->windowname); $this->_form->addElement('static', 'progressBar'); $this->_form->addElement('static', 'progressStatus'); $style = $this->isStarted() ? array('disabled' => 'true') : null; $buttons[] =& $this->_form->createElement('submit', 'start', $this->buttonStart, $style); $buttons[] =& $this->_form->createElement('submit', 'cancel', $this->buttonCancel); $buttons[0]->updateAttributes($buttonAttr); $buttons[1]->updateAttributes($buttonAttr); $this->_form->addGroup($buttons, 'buttons', '', ' ', false); // default embedded progress element with look-and-feel $this->_progress = new HTML_Progress(); $this->setProgressElement($this->_progress); $str =& $this->_form->getElement('progressStatus'); $str->setText('<div id="status" class="progressStatus"> </div>'); }
/** * This function for building custom fields * * @param object $qf form object (reference) * @param string $elementName name of the custom field * @param boolean $inactiveNeeded * @param boolean $userRequired true if required else false * @param boolean $search true if used for search else false * @param string $label label for custom field * * @access public * @static */ function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired, $search = false, $label = null) { $field =& new CRM_Core_DAO_CustomField(); $field->id = $fieldId; if (!$field->find(true)) { /* FIXME: failure! */ return null; } if (!isset($label)) { $label = $field->label; } /** * This was split into a different function before. however thanx to php4's bug with references, * it was not working, so i munged it back into one big function - lobo */ switch ($field->html_type) { case 'Text': if ($field->is_search_range && $search) { $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes); $qf->add('text', $elementName . '_to', ts('To'), $field->attributes); } else { $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, ($useRequired || $field->is_required) && !$search); } break; case 'TextArea': $attributes = ''; if ($field->note_rows) { $attributes .= 'rows=' . $field->note_rows; } else { $attributes .= 'rows=4'; } if ($field->note_columns) { $attributes .= ' cols=' . $field->note_columns; } else { $attributes .= ' cols=60'; } $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $attributes, ($useRequired || $field->is_required) && !$search); break; case 'Select Date': if ($field->is_search_range && $search) { $qf->add('date', $elementName . '_from', $label . ' ' . ts('From'), CRM_Core_SelectValues::date('custom', $field->start_date_years, $field->end_date_years, $field->date_parts), ($useRequired || $field->is_required) && !$search); $qf->add('date', $elementName . '_to', $label . ' ' . ts('To'), CRM_Core_SelectValues::date('custom', $field->start_date_years, $field->end_date_years, $field->date_parts), ($useRequired || $field->is_required) && !$search); } else { $qf->add('date', $elementName, $label, CRM_Core_SelectValues::date('custom', $field->start_date_years, $field->end_date_years, $field->date_parts), ($useRequired || $field->is_required) && !$search); } break; case 'Radio': $choice = array(); if ($field->data_type != 'Boolean') { $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); foreach ($customOption as $v) { $choice[] = $qf->createElement('radio', null, '', $v['label'], $v['value'], $field->attributes); } $qf->addGroup($choice, $elementName, $label); } else { $choice[] = $qf->createElement('radio', null, '', ts('Yes'), '1', $field->attributes); $choice[] = $qf->createElement('radio', null, '', ts('No'), '0', $field->attributes); $qf->addGroup($choice, $elementName, $label); } if (($useRequired || $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select': $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); $selectOption = array(); foreach ($customOption as $v) { $selectOption[$v['value']] = $v['label']; } $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, ($useRequired || $field->is_required) && !$search); break; //added for select multiple //added for select multiple case 'Multi-Select': $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); $selectOption = array(); foreach ($customOption as $v) { $selectOption[$v['value']] = $v['label']; } $qf->addElement('select', $elementName, $label, $selectOption, array("size" => "5", "multiple")); if (($useRequired || $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'CheckBox': $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); $check = array(); foreach ($customOption as $v) { $check[] =& $qf->createElement('checkbox', $v['value'], null, $v['label']); } $qf->addGroup($check, $elementName, $label); if (($useRequired || $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select State/Province': //Add State if ($qf->getAction() & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $stateOption = array('' => '') + CRM_Core_PseudoConstant::stateProvince(); } else { $stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); } $qf->add('select', $elementName, $label, $stateOption, ($useRequired || $field->is_required) && !$search); break; case 'Select Country': //Add Country if ($qf->getAction() & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $countryOption = array('' => '') + CRM_Core_PseudoConstant::country(); } else { $countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); } $qf->add('select', $elementName, $label, $countryOption, ($useRequired || $field->is_required) && !$search); break; } switch ($field->data_type) { case 'Int': // integers will have numeric rule applied to them. if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer'); $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer'); } else { $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer'); } break; case 'Date': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From is not a valid date.', array(1 => $label)), 'qfDate'); $qf->addRule($elementName . '_to', ts('%1 To is not a valid date.', array(1 => $label)), 'qfDate'); } else { $qf->addRule($elementName, ts('%1 is not a valid date.', array(1 => $label)), 'qfDate'); } break; case 'Float': case 'Money': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } else { $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } break; } }
/** * Adds controls specific to this filter in the form. * @param object $mform A MoodleForm object to setup */ public function setupForm(&$mform) { global $CFG; $report = $this->_parent_report; $filter = $this->_uniqueid; $filter_js = array('var ac_show_panel = function( url ) { var x = window.open(url, \'newWindow\', \'height=700,width=650,resizable=yes,scrollbars=yes,screenX=50,screenY=50\'); } window.ac_show_panel = ac_show_panel;'); $filt_action_url_base = $CFG->wwwroot . '/local/eliscore/lib/form/autocomplete.php?report=' . $report . '&filter=' . $filter; if ($this->_ui === 'inline') { $mform->addElement('hidden', $this->_uniqueid, $this->get_default(), array('id' => 'id_' . $this->_uniqueid)); $mform->setType($this->_uniqueid, PARAM_TEXT); $search_url = $filt_action_url_base . '&mode=search&q='; $config_url = $filt_action_url_base . '&mode=config'; $main_input_ph = $this->_selection_enabled === true ? get_string('filt_autoc_typetosearch', 'local_eliscore') : ''; $text_input = array($mform->createElement('text', $this->_uniqueid, $this->_label, array('placeholder' => $main_input_ph))); if ($this->config_allowed() === true) { $text_input[] = $mform->createElement('static', 'configlink', '', '<a onclick="ac_show_panel(\'' . $config_url . '\');" href="#">' . '<img src=' . $CFG->wwwroot . '/local/elisprogram/pix/configuration.png>' . '</a>'); } $text_input[] = $mform->createElement('html', '<div id="search_results_outer" class="filt_ac_res filt_ac_res_inline"> <div id="search_status" class="filt_ac_status filt_ac_status_inline"></div> <div id="search_results"></div> </div>'); $mform->addGroup($text_input, 'grp', $this->_label); $mform->setType($this->_uniqueid, PARAM_RAW); if ($this->_selection_enabled === true) { if ($this->_required) { // This adds red * & that a required form field exists + validation $mform->addGroupRule('grp', get_string('required'), 'required', null, 1, 'client'); if ($this->_useid) { $mform->addRule($this->_uniqueid, get_string('required'), 'required', null, 'client'); // hidden doesn't display } } $mform->addElement('html', "<link rel='stylesheet' type='text/css' href='{$CFG->wwwroot}/local/eliscore/lib/form/autocomplete.css' />"); $mform->addElement('html', "<script src='{$CFG->wwwroot}/local/eliscore/js/jquery-1.7.1.min.js'></script>"); $mform->addElement('html', "<script src='{$CFG->wwwroot}/local/eliscore/lib/form/autocomplete.js'></script>"); $filter_js[] = "var search_textbox = 'id_grp_{$this->_uniqueid}';\n var search_results = 'search_results';\n var search_status = 'search_status';\n var search_results_outer = 'search_results_outer';\n\n var autocomplete = new autocomplete_ui(search_textbox,search_results,search_status,'{$search_url}','search_results_outer');\n autocomplete.str_searching = '" . get_string('filt_autoc_searching', 'local_eliscore') . "';\n autocomplete.str_typetosearch = '" . get_string('filt_autoc_typetosearch', 'local_eliscore') . "';\n\n \$('#'+search_textbox).focus().click(function(e){e.stopPropagation();}).keyup(function(e) {\n if (e.keyCode != 13) {\n \$('#'+search_results_outer).show().click(function(e) { e.stopPropagation() });\n \$('body').click(function(e){ \$('#'+search_results_outer).hide(); });\n var pos = \$(this).position();\n var height = \$(this).outerHeight();\n \$('#'+search_results_outer).css('left',pos.left+2).css('top',(pos.top+height+2));\n }\n });"; } else { $mform->freeze('grp'); } if (!empty($this->_default_label)) { $mform->setDefault('grp[' . $this->_uniqueid . ']', $this->_default_label); } } else { $popup_link = '<span id="id_' . $this->_uniqueid . '_label"></span> '; if ($this->_selection_enabled === true) { $popup_link .= '<a onclick="ac_show_panel(\'' . $filt_action_url_base . '\');" href="#">' . get_string('filt_autoc_select', 'local_eliscore') . '</a>'; } $mform->addElement('static', 'selector', $this->_label, $popup_link); $mform->addElement('html', '<div style="display:none;">'); $mform->addElement('text', $this->_uniqueid . '_labelsave', ''); $mform->setType($this->_uniqueid . '_labelsave', PARAM_TEXT); $mform->addElement('text', $this->_uniqueid, ''); $mform->setType($this->_uniqueid, PARAM_TEXT); if (!empty($this->_default_label)) { $mform->setDefault($this->_uniqueid . '_labelsave', $this->_default_label); } if (!empty($this->_default_id)) { $mform->setDefault($this->_uniqueid, $this->_default_id); } $mform->addElement('html', '</div>'); if (!empty($this->_filterhelp) && is_array($this->_filterhelp) && isset($this->_filterhelp[2])) { //$mform->addHelpButton('selector', $this->_filterhelp[0], $this->_filterhelp[2]); } $filter_js[] = 'labelsave = document.getElementById(\'id_' . $this->_uniqueid . '_labelsave\'); labeldisp = document.getElementById(\'id_' . $this->_uniqueid . '_label\'); if (labelsave != null && labeldisp != null) { labeldisp.innerHTML = labelsave.value; }'; } $mform->addElement('html', '<script>' . implode("\n\n", $filter_js) . '</script>'); }
/** * This function for building custom fields * * @param object $qf form object (reference) * @param string $elementName name of the custom field * @param boolean $inactiveNeeded * @param boolean $useRequired true if required else false * @param boolean $search true if used for search else false * @param string $label label for custom field * * @access public * @static */ public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $feezeOptions = array()) { $field = new CRM_Price_DAO_PriceField(); $field->id = $fieldId; if (!$field->find(TRUE)) { /* FIXME: failure! */ return NULL; } $is_pay_later = 0; if (isset($qf->_mode) && empty($qf->_mode)) { $is_pay_later = 1; } elseif (isset($qf->_values)) { $is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values); } $otherAmount = $qf->get('values'); $config = CRM_Core_Config::singleton(); $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name'); $qf->assign('currencySymbol', $currencySymbol); // get currency name for price field and option attributes $currencyName = $config->defaultCurrency; if (!isset($label)) { $label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label; } if ($field->name == 'contribution_amount') { $qf->_contributionAmount = 1; } if (isset($qf->_online) && $qf->_online) { $useRequired = FALSE; } $customOption = $fieldOptions; if (!is_array($customOption)) { $customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded); } //use value field. $valueFieldName = 'amount'; $seperator = '|'; switch ($field->html_type) { case 'Text': $optionKey = key($customOption); $count = CRM_Utils_Array::value('count', $customOption[$optionKey], ''); $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], ''); $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value)); $extra = array(); if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) { foreach ($fieldOptions as &$fieldOption) { if ($fieldOption['name'] == 'other_amount') { $fieldOption['label'] = $fieldOption['label'] . ' ' . $currencySymbol; } } $qf->assign('priceset', $elementName); $extra = array('onclick' => 'useAmountOther();'); } // if seperate membership payment is used with quick config priceset then change the other amount label if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) { $label = ts('Additional Contribution'); $useRequired = 0; } elseif (CRM_Utils_Array::value('label', $fieldOptions[$optionKey])) { //check for label. $label = $fieldOptions[$optionKey]['label']; } $element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required); if ($is_pay_later) { $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4')); } // CRM-6902 if (in_array($optionKey, $feezeOptions)) { $element->freeze(); } //CRM-10117 if (!empty($qf->_quickConfig)) { $message = ts('Please enter a valid amount.'); $type = 'money'; } else { $message = ts('%1 must be an integer (whole number).', array(1 => $label)); $type = 'positiveInteger'; } // integers will have numeric rule applied to them. $qf->addRule($elementName, $message, $type); break; case 'Radio': $choice = array(); if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) { $qf->assign('contriPriceset', $elementName); } foreach ($customOption as $opId => $opt) { if ($field->is_display_amounts) { $opt['label'] = CRM_Utils_Array::value('label', $opt) ? $opt['label'] : ''; $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>'; } $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); $extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName); if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') { $extra += array('onclick' => 'clearAmountOther();'); } elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') { $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']); $qf->assign('membershipFieldID', $field->id); } $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra); if ($is_pay_later) { $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4')); } // CRM-6902 if (in_array($opId, $feezeOptions)) { $choice[$opId]->freeze(); } } if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') { $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1', array('onclick' => 'clearAmountOther();')); } if (!$field->is_required) { // add "none" option if (CRM_Utils_Array::value('is_allow_other_amount', $otherAmount) && $field->name == 'contribution_amount') { $none = ts('Other Amount'); } elseif (!empty($qf->_membershipBlock) && !CRM_Utils_Array::value('is_required', $qf->_membershipBlock) && $field->name == 'membership_amount') { $none = ts('No thank you'); } else { $none = ts('- none -'); } $choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, '0')))); } $element =& $qf->addGroup($choice, $elementName, $label); // make contribution field required for quick config when membership block is enabled if (($field->name == 'membership_amount' || $field->name == 'contribution_amount') && !empty($qf->_membershipBlock) && !$field->is_required) { $useRequired = $field->is_required = TRUE; } if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select': $selectOption = $allowedOptions = $priceVal = array(); foreach ($customOption as $opt) { $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $selectOption[$opt['id']] = $opt['label']; if (!in_array($opt['id'], $feezeOptions)) { $allowedOptions[] = $opt['id']; } if ($is_pay_later) { $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4')); } } $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal))); // CRM-6902 $button = substr($qf->controller->getButtonName(), -4); if (!empty($feezeOptions) && $button != 'skip') { $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/"); } break; case 'CheckBox': $check = array(); foreach ($customOption as $opId => $opt) { $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $check[$opId] =& $qf->createElement('checkbox', $opt['id'], NULL, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName)); if ($is_pay_later) { $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4')); $qf->addGroup($txtcheck, 'txt-' . $elementName, $label); } // CRM-6902 if (in_array($opId, $feezeOptions)) { $check[$opId]->freeze(); } } $element =& $qf->addGroup($check, $elementName, $label); if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; } if (isset($qf->_online) && $qf->_online) { $element->freeze(); } }
/** * This function for building custom fields * * @param object $qf form object (reference) * @param string $elementName name of the custom field * @param boolean $inactiveNeeded * @param boolean $useRequired true if required else false * @param boolean $search true if used for search else false * @param string $label label for custom field * * @access public * @static */ public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = true, $label = null, $fieldOptions = null, $feezeOptions = array()) { require_once 'CRM/Utils/Money.php'; $field = new CRM_Price_DAO_Field(); $field->id = $fieldId; if (!$field->find(true)) { /* FIXME: failure! */ return null; } $config = CRM_Core_Config::singleton(); $qf->assign('currencySymbol', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Currency', $config->defaultCurrency, 'symbol', 'name')); if (!isset($label)) { $label = $field->label; } if (isset($qf->_online) && $qf->_online) { $useRequired = false; } $customOption = $fieldOptions; if (!is_array($customOption)) { $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded); } //use value field. $valueFieldName = 'amount'; $seperator = '|'; switch ($field->html_type) { case 'Text': $optionKey = key($customOption); $count = CRM_Utils_Array::value('count', $customOption[$optionKey], ''); $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], ''); $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value)); //check for label. if (CRM_Utils_Array::value('label', $fieldOptions[$optionKey])) { $label = $fieldOptions[$optionKey]['label']; } if ($field->is_display_amounts) { $label .= ' - '; $label .= CRM_Utils_Money::format(CRM_Utils_Array::value($valueFieldName, $customOption[$optionKey])); } $element =& $qf->add('text', $elementName, $label, array_merge(array('size' => "4"), array('price' => json_encode(array($optionKey, $priceVal)))), $useRequired && $field->is_required); // CRM-6902 if (in_array($optionKey, $feezeOptions)) { $element->freeze(); } // integers will have numeric rule applied to them. $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'positiveInteger'); break; case 'Radio': $choice = array(); foreach ($customOption as $opId => $opt) { if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); $choice[$opId] = $qf->createElement('radio', null, '', $opt['label'], $opt['id'], array('price' => json_encode(array($elementName, $priceVal)))); // CRM-6902 if (in_array($opId, $feezeOptions)) { $choice[$opId]->freeze(); } } if (!$field->is_required) { // add "none" option $choice[] = $qf->createElement('radio', null, '', '-none-', '0', array('price' => json_encode(array($elementName, "0")))); } $element =& $qf->addGroup($choice, $elementName, $label); if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select': $selectOption = $allowedOptions = $priceVal = array(); foreach ($customOption as $opt) { $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $selectOption[$opt['id']] = $opt['label']; if (!in_array($opt['id'], $feezeOptions)) { $allowedOptions[] = $opt['id']; } } $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal))); // CRM-6902 $button = substr($qf->controller->getButtonName(), -4); if (!empty($feezeOptions) && $button != 'skip') { $qf->addRule($elementName, ts('Participant count for this option is full.'), 'regex', "/" . implode('|', $allowedOptions) . "/"); } break; case 'CheckBox': $check = array(); foreach ($customOption as $opId => $opt) { $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $check[$opId] =& $qf->createElement('checkbox', $opt['id'], null, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal)))); // CRM-6902 if (in_array($opId, $feezeOptions)) { $check[$opId]->freeze(); } } $element =& $qf->addGroup($check, $elementName, $label); if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; } if (isset($qf->_online) && $qf->_online) { $element->freeze(); } }
/** * Add form elements for course contact information. * @param object $mform form definition * @param object $courseinfo a record of general information from course info table. * @param object $contactinfo a record of contact information from course instructor table. * @return void */ private function setup_contact($mform, $courseinfo, $contactinfo) { global $CFG, $DB, $USER; //Declare our globals for use global $course; $mform->addElement('html', '<a name="contact"></a>'); // anchor $mform->addElement('header', 'course_contact_header', get_string('course_contact_header', 'local_metadata')); // Email $course_email = $mform->addElement('text', 'course_email', get_string('course_email', 'local_metadata'), ''); if ($contactinfo) { $mform->setDefault('course_email', $contactinfo->email); } else { $mform->setDefault('course_email', $USER->email); } //$mform->addRule('course_email', get_string('err_required', 'local_metadata'), 'required', null, 'client'); $mform->addRule('course_email', get_string('err_email', 'local_metadata'), 'email', null, 'client'); $mform->setType('course_email', PARAM_TEXT); // Phone $course_phone = $mform->addElement('text', 'course_phone', get_string('course_phone', 'local_metadata'), ''); if ($contactinfo) { $mform->setDefault('course_phone', $contactinfo->phonenumber); } $mform->setType('course_phone', PARAM_TEXT); // Office $course_office = $mform->addElement('text', 'course_office', get_string('course_office', 'local_metadata'), ''); if ($contactinfo) { $mform->setDefault('course_office', $contactinfo->officelocation); } //$mform->addRule('course_office', get_string('err_required', 'local_metadata'), 'required', null, 'client'); $mform->setType('course_office', PARAM_TEXT); // Office hours // Set default hours $mform->addElement('advcheckbox', 'default_officeh', get_string('course_officeh', 'local_metadata'), get_string('default_officeh', 'local_metadata'), null, array(0, get_string('default_officeh', 'local_metadata'))); $mform->addHelpButton('default_officeh', 'default_officeh', 'local_metadata'); // Set day $daygroup = array(); foreach (get_days() as $day) { $daygroup[] =& $mform->createElement('advcheckbox', $day, '', $day, null, array(0, $day)); } $mform->addGroup($daygroup, 'daygroup', '', array(' '), false); // Set time $timegroup = array(); $hour = array(); for ($i = 0; $i < 13; $i++) { $hour[] = sprintf("%02d", $i); } $minute = array(); for ($i = 0; $i < 60; $i++) { $minute[] = sprintf("%02d", $i); } $time_format = array('AM', 'PM'); $timegroup[] =& $mform->createElement('static', 'fromhour_label', '', get_string('fromhour_label', 'local_metadata')); $timegroup[] =& $mform->createElement('select', 'fromhour', '', $hour, ''); $timegroup[] =& $mform->createElement('select', 'fromminute', '', $minute, ''); $timegroup[] =& $mform->createElement('select', 'fromformat', '', $time_format, ''); $timegroup[] =& $mform->createElement('static', 'tohour_label', '', get_string('tohour_label', 'local_metadata')); $timegroup[] =& $mform->createElement('select', 'tohour', '', $hour, ''); $timegroup[] =& $mform->createElement('select', 'tominute', '', $minute, ''); $timegroup[] =& $mform->createElement('select', 'toformat', '', $time_format, ''); $mform->addGroup($timegroup, 'timegroup', '', array(' '), false); $mform->disabledIf('daygroup', 'default_officeh', 'checked'); $mform->disabledIf('timegroup', 'default_officeh', 'checked'); if (empty($contactinfo->officehours)) { $mform->setDefault('default_officeh', true); } else { if ($contactinfo->officehours == 'By appointment') { $mform->setDefault('default_officeh', true); } else { $formats = explode(" ", $contactinfo->officehours); $mform->setDefault('toformat', array_pop($formats) == 'AM' ? 0 : 1); $totimes = explode(":", array_pop($formats)); $mform->setDefault('tohour', $totimes[0]); $mform->setDefault('tominute', $totimes[1]); array_pop($formats); $mform->setDefault('fromformat', array_pop($formats) == 'AM' ? 0 : 1); $fromtimes = explode(":", array_pop($formats)); $mform->setDefault('fromhour', $fromtimes[0]); $mform->setDefault('fromminute', $fromtimes[1]); foreach ($formats as $day) { $mform->setDefault($day, true); } } } $mform->addElement('static', 'h_2', ''); // end of header $mform->setType('h_2', PARAM_RAW); $mform->closeHeaderBefore('h_2'); $mform->setExpanded('course_contact_header'); }
/** * build the radio/text form elements for the amount field * * @param object $form form object * @param boolean $required true if you want to add formRule * @param int $discountId discount id for the event * * @return void * @access public * @static */ public static function buildAmount(&$form, $required = true, $discountId = null) { //get the button name. $button = substr($form->controller->getButtonName(), -4); if ($button == 'skip') { $required = false; } $elements = array(); if (isset($form->_priceSetId)) { $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />'); $form->add('hidden', 'priceSetId', $form->_priceSetId); $form->assign('priceSet', $form->_priceSet); require_once 'CRM/Price/BAO/Field.php'; foreach ($form->_values['fee']['fields'] as $field) { $fieldId = $field['id']; $elementName = 'price_' . $fieldId; if ($button == 'skip') { $isRequire = false; } else { $isRequire = CRM_Utils_Array::value('is_required', $field); } CRM_Price_BAO_Field::addQuickFormElement($form, $elementName, $fieldId, false, $isRequire); } } else { if (!empty($form->_values['fee'])) { $form->_feeBlock =& $form->_values['fee']; if (isset($form->_values['discount'])) { if (!isset($discountId) && $form->_action != CRM_Core_Action::UPDATE) { require_once 'CRM/Core/BAO/Discount.php'; $form->_discountId = $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); } if ($discountId) { $form->_feeBlock =& $form->_values['discount'][$discountId]; } } require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::buildAmount('event', $form, $form->_feeBlock); if ($form->_action != CRM_Core_Action::UPDATE) { require_once 'CRM/Utils/Money.php'; foreach ($form->_feeBlock as $fee) { if (is_array($fee)) { $elements[] =& $form->createElement('radio', null, '', CRM_Utils_Money::format($fee['value']) . ' ' . $fee['label'], $fee['amount_id']); } } $form->_defaults['amount'] = CRM_Utils_Array::value('default_fee_id', $form->_values['event']); $element =& $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />'); if (isset($form->_online) && $form->_online) { $element->freeze(); } if ($required) { $form->addRule('amount', ts('Fee Level is a required field.'), 'required'); } } } } }
/** * This function for building custom fields * * @param object $qf form object (reference) * @param string $elementName name of the custom field * @param boolean $inactiveNeeded * @param boolean $userRequired true if required else false * @param boolean $search true if used for search else false * @param string $label label for custom field * * @access public * @static */ public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded = FALSE, $useRequired = TRUE, $search = FALSE, $label = NULL) { // we use $_POST directly, since we dont want to use session memory, CRM-4677 if (isset($_POST['_qf_Relationship_refresh']) && ($_POST['_qf_Relationship_refresh'] == 'Search' || $_POST['_qf_Relationship_refresh'] == 'Search Again')) { $useRequired = FALSE; } $field = self::getFieldObject($fieldId); // Custom field HTML should indicate group+field name $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id); $dataCrmCustomVal = $groupName . ':' . $field->name; $dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"'; $field->attributes .= $dataCrmCustomAttr; // Fixed for Issue CRM-2183 if ($field->html_type == 'TextArea' && $search) { $field->html_type = 'Text'; } // FIXME: Why are select state/country separate widget types? if (in_array($field->html_type, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country'))) { $selectAttributes = array('data-crm-custom' => $dataCrmCustomVal, 'class' => 'crm-select2'); if (strpos($field->html_type, 'Multi') === 0) { $selectAttributes['multiple'] = 'multiple'; } } // Add popup link for editing options. Normally this is handled by CRM_Core_Form->addSelect if (in_array($field->html_type, array('Select', 'Multi-Select')) && !$search && CRM_Core_Permission::check('administer CiviCRM')) { $selectAttributes += array('data-api-entity' => 'contact', 'data-api-field' => 'custom_' . $field->id, 'data-option-group-url' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id)); } if (!isset($label)) { $label = $field->label; } /** * at some point in time we might want to split the below into small functions **/ switch ($field->html_type) { case 'Text': if ($field->is_search_range && $search) { $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes); $qf->add('text', $elementName . '_to', ts('To'), $field->attributes); } else { $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search); } break; case 'TextArea': $attributes = $dataCrmCustomAttr; if ($field->note_rows) { $attributes .= 'rows=' . $field->note_rows; } else { $attributes .= 'rows=4'; } if ($field->note_columns) { $attributes .= ' cols=' . $field->note_columns; } else { $attributes .= ' cols=60'; } if ($field->text_length) { $attributes .= ' maxlength=' . $field->text_length; } $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $attributes, $useRequired && !$search); break; case 'Select Date': if ($field->is_search_range && $search) { $qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal)); $qf->addDate($elementName . '_to', ts('To'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal)); } else { $required = $useRequired && !$search; $qf->addDate($elementName, $label, $required, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal)); } break; case 'Radio': $choice = array(); if ($field->data_type != 'Boolean') { $customOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); foreach ($customOption as $v => $l) { $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes); } $group = $qf->addGroup($choice, $elementName, $label); } else { $choice[] = $qf->createElement('radio', NULL, '', ts('Yes'), '1', $field->attributes); $choice[] = $qf->createElement('radio', NULL, '', ts('No'), '0', $field->attributes); $group = $qf->addGroup($choice, $elementName, $label); } if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } else { $group->setAttribute('unselectable', TRUE); } break; case 'Select': $selectOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && !$search, $selectAttributes); break; //added for select multiple //added for select multiple case 'AdvMulti-Select': $selectOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); if ($search && count($selectOption) > 1) { $selectOption['CiviCRM_OP_OR'] = ts('Select to match ANY; unselect to match ALL'); } $include =& $qf->addElement('advmultiselect', $elementName, $label, $selectOption, array('size' => 5, 'style' => '', 'class' => 'advmultiselect', 'data-crm-custom' => $dataCrmCustomVal)); $include->setButtonAttributes('add', array('value' => ts('Add >>'))); $include->setButtonAttributes('remove', array('value' => ts('<< Remove'))); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Multi-Select': $selectOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); if ($search && count($selectOption) > 1) { $selectOption['CiviCRM_OP_OR'] = ts('Select to match ANY; unselect to match ALL'); } $qf->addElement('select', $elementName, $label, $selectOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'CheckBox': $customOption = CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); $check = array(); foreach ($customOption as $v => $l) { $check[] =& $qf->addElement('advcheckbox', $v, NULL, $l, array('data-crm-custom' => $dataCrmCustomVal)); } if ($search && count($check) > 1) { $check[] =& $qf->addElement('advcheckbox', 'CiviCRM_OP_OR', NULL, ts('Check to match ANY; uncheck to match ALL'), array('data-crm-custom' => $dataCrmCustomVal)); } $qf->addGroup($check, $elementName, $label); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'File': // we should not build upload file in search mode if ($search) { return; } $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search); $qf->addUploadElement($elementName); break; case 'Select State/Province': //Add State $stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); $qf->add('select', $elementName, $label, $stateOption, $useRequired && !$search, $selectAttributes); $qf->_stateCountryMap['state_province'][] = $elementName; break; case 'Multi-Select State/Province': //Add Multi-select State/Province $stateOption = CRM_Core_PseudoConstant::stateProvince(); $qf->addElement('select', $elementName, $label, $stateOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select Country': //Add Country $countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); $qf->add('select', $elementName, $label, $countryOption, $useRequired && !$search, $selectAttributes); $qf->_stateCountryMap['country'][] = $elementName; break; case 'Multi-Select Country': //Add Country $countryOption = CRM_Core_PseudoConstant::country(); $qf->addElement('select', $elementName, $label, $countryOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'RichTextEditor': $attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal); if ($field->text_length) { $attributes['maxlength'] = $field->text_length; } $qf->addWysiwyg($elementName, $label, $attributes, $search); break; case 'Autocomplete-Select': $qf->add('text', $elementName, $label, $field->attributes, $useRequired && !$search); $hiddenEleName = $elementName . '_id'; if (substr($elementName, -1) == ']') { $hiddenEleName = substr($elementName, 0, -1) . '_id]'; } $qf->addElement('hidden', $hiddenEleName, '', array('id' => str_replace(array(']', '['), array('', '_'), $hiddenEleName))); static $customUrls = array(); if ($field->data_type == 'ContactReference') { //$urlParams = "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1&context=customfield&id={$field->id}"; $urlParams = "context=customfield&id={$field->id}"; $customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref', $urlParams, FALSE, NULL, FALSE); $actualElementValue = $qf->getSubmitValue($hiddenEleName); $qf->addRule($elementName, ts('Select a valid contact for %1.', array(1 => $label)), 'validContact', $actualElementValue); } else { $customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/auto', "reset=1&ogid={$field->option_group_id}&cfid={$field->id}", FALSE, NULL, FALSE); $qf->addRule($elementName, ts('Select a valid value for %1.', array(1 => $label)), 'autocomplete', array('fieldID' => $field->id, 'optionGroupID' => $field->option_group_id)); } $qf->assign('customUrls', $customUrls); break; } switch ($field->data_type) { case 'Int': // integers will have numeric rule applied to them. if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer'); $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer'); } else { $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer'); } break; case 'Float': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } else { $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } break; case 'Money': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); $qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); } else { $qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); } break; case 'Link': $qf->add('text', $elementName, $label, array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false", 'data-crm-custom' => $dataCrmCustomVal), $useRequired && !$search); $qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL'); break; } if ($field->is_view && !$search) { $qf->freeze($elementName); } }
/** * This function for building custom fields * * @param object $qf form object (reference) * @param string $elementName name of the custom field * @param boolean $inactiveNeeded * @param boolean $useRequired true if required else false * @param boolean $search true if used for search else false * @param string $label label for custom field * * @access public * @static */ public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = true, $label = null) { require_once 'CRM/Utils/Money.php'; $field =& new CRM_Price_DAO_Field(); $field->id = $fieldId; if (!$field->find(true)) { /* FIXME: failure! */ return null; } $config =& CRM_Core_Config::singleton(); $qf->assign('currencySymbol', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Currency', $config->defaultCurrency, 'symbol', 'name')); if (!isset($label)) { $label = $field->label; } if (isset($qf->_online) && $qf->_online) { $useRequired = false; } //use value field. $valueFieldName = 'value'; switch ($field->html_type) { case 'Text': $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded); // text fields only have one option $optionKey = key($customOption); if ($field->is_display_amounts) { $label .= ' - '; $label .= CRM_Utils_Money::format(CRM_Utils_Array::value($valueFieldName, $customOption[$optionKey])); } $element =& $qf->add('text', $elementName, $label, array_merge(array('size' => "4"), array('price' => json_encode(array($optionKey, $customOption[$optionKey][$valueFieldName])))), $useRequired && $field->is_required); // integers will have numeric rule applied to them. $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'positiveInteger'); break; case 'Radio': $choice = array(); $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded); if (!$field->is_required) { // add "none" option $choice[] = $qf->createElement('radio', null, '', '-none-', '0', array('price' => json_encode(array($elementName, "0")))); } foreach ($customOption as $opt) { if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $choice[] = $qf->createElement('radio', null, '', $opt['label'], $opt['id'], array('price' => json_encode(array($elementName, $opt[$valueFieldName])))); } $element =& $qf->addGroup($choice, $elementName, $label); if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select': $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded); $selectOption = array(); foreach ($customOption as $opt) { $amount[$opt['id']] = $opt[$valueFieldName]; if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $selectOption[$opt['id']] = $opt['label']; } $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($amount))); break; case 'CheckBox': $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded); $check = array(); foreach ($customOption as $opt) { if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $check[] =& $qf->createElement('checkbox', $opt['id'], null, $opt['label'], array('price' => json_encode(array($opt['id'], $opt[$valueFieldName])))); } $element =& $qf->addGroup($check, $elementName, $label); if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; } if (isset($qf->_online) && $qf->_online) { $element->freeze(); } }
/** * add_field_arrow * * @param object $mform * @param string $plugin * @param string $name * @param array $arrows * @param array $add_js * @return void, but will update $mform */ protected function add_field_arrow($mform, $plugin, $name, $arrows, $add_js) { $config_name = 'config_' . $name; $elements_name = 'elements_' . $name; $static = array(); $params = array('href' => '#', 'onclick' => 'return select_arrow(this)'); foreach ($arrows as $arrow) { $static[] = html_writer::tag('a', $arrow, $params); } $static = implode(' ', $static); $static = html_writer::tag('span', $static, array('class' => 'arrows')); $elements = array(); if ($add_js) { $js = ''; $js .= '<script type="text/javascript">' . "\n"; $js .= "//<![CDATA[\n"; $js .= "function select_arrow(txt) {\n"; $js .= " var obj = txt.parentNode.previousSibling;\n"; $js .= " while (obj) {\n"; $js .= " if (obj.tagName=='INPUT') {\n"; $js .= " obj.value = txt.innerHTML;\n"; $js .= " obj = null;\n"; $js .= " } else {\n"; $js .= " obj = obj.previousSibling;\n"; $js .= " }\n"; $js .= " }\n"; $js .= " return false;\n"; $js .= "}\n"; $js .= "function select_all_courses(truefalse) {\n"; $js .= " var obj = document.getElementById('menumycourses');\n"; $js .= " if (obj) {\n"; $js .= " var i_max = obj.options.length;\n"; $js .= " for (var i=0; i<i_max; i++) {\n"; $js .= " obj.options[i].selected = truefalse;\n"; $js .= " }\n"; $js .= " }\n"; $js .= " return false;\n"; $js .= "}\n"; $js .= "//]]>\n"; $js .= "</script>\n"; $elements[] = $mform->createElement('static', '', '', $js); } $params = array('size' => 2); $elements[] = $mform->createElement('text', $config_name, '', $params); $elements[] = $mform->createElement('static', '', '', $static); $mform->addGroup($elements, $elements_name, get_string($name, $plugin), ' ', false); $mform->setType($config_name, PARAM_TEXT); }
/** * Setup a table row * * @param object $mform The moodle form * @param int $type The datatype of the rows * @param array $dataset The row data * @param bool $extrarow Whether an extra row should be added. * @uses $CFG * @uses $OUTPUT */ protected function setup_table_type_row($mform, $type, $dataset = array(), $extrarow) { global $CFG, $OUTPUT; $typename = $this->types[$type]; $deletescoretype = get_string('results_delete_score', self::LANG_FILE); $notypeselected = get_string("results_no_{$typename}_selected", self::LANG_FILE); $selecttype = get_string("results_select_{$typename}", self::LANG_FILE); $setdefault = false; $prefix = $typename . '_'; $cache = 0; $defaults = array(); $configs = array(); if ($extrarow) { $empty_record = new stdClass(); $empty_record->min = ''; $empty_record->max = ''; $empty_record->selected = ''; $empty_record->value = ''; array_push($dataset, $empty_record); $cache = 1; } $i = 0; foreach ($dataset as $data) { //error checking if (!isset($data->min, $data->max)) { continue; } // Start a table row and column $tablehtml = html_writer::start_tag('tr'); $tablehtml .= html_writer::start_tag('td', array('style' => 'text-align:center;')); $mform->addElement('html', $tablehtml); $group = array(); // Add minimum field $attributes = array('size' => 8, 'maxlength' => 8, 'value' => $data->min); if (!(array_key_exists('active', $this->_customdata) && $this->_customdata['active'])) { $attributes['disabled'] = 'disabled'; } $group[] = $mform->createElement('text', "{$prefix}{$i}_min", '', $attributes); // Add maximum field $attributes['value'] = $data->max; $group[] = $mform->createElement('text', "{$prefix}{$i}_max", '', $attributes); // Add link and icon (Delete link). $attributes = array('title' => $deletescoretype, 'alt' => $deletescoretype, 'class' => 'elisicon-remove elisiconcolored', 'onclick' => $this->prefixes[$type] . '_object.deleteRow(this); return false;'); $group[] = $mform->createElement('link', 'delete', '', "#", '', $attributes); // Add minimum, maximum and delete to field group $mform->addGroup($group, "{$prefix}{$i}_score", '', '', false); $mform->setType("{$prefix}{$i}_min", PARAM_TEXT); $mform->setType("{$prefix}{$i}_max", PARAM_TEXT); $tablehtml = html_writer::end_tag('td'); $tablehtml .= html_writer::start_tag('td', array('style' => 'text-align:center;')); $mform->addElement('html', $tablehtml); if ($this->rowtypes[$type] == 'picklist') { $name = ''; if (!empty($data->selected)) { $name = $this->get_label_name($typename, $data->selected); } else { $name = $notypeselected; } // Need to add 2 hidden elements - 1 for Moodle forms and 1 For dynamic table. $mform->addElement('hidden', "{$prefix}{$i}_selected", $data->selected); $mform->setType("{$prefix}{$i}_selected", PARAM_TEXT); $attributes = array('id' => "{$prefix}{$i}_label"); $attributes = array('size' => 20, 'value' => $name, 'disabled' => 'disabled'); $attributes = array('id' => "id_{$prefix}{$i}_label", 'value' => $name, 'name' => "{$prefix}{$i}_label", 'type' => 'text'); if (!(array_key_exists('active', $this->_customdata) && $this->_customdata['active'])) { $attributes['disabled'] = 'disabled'; } $output = html_writer::empty_tag('input', $attributes); $attributes = array('id' => "id_{$prefix}{$i}_selected", 'value' => $data->selected, 'name' => "{$prefix}{$i}_selected", 'type' => 'hidden'); $output .= html_writer::empty_tag('input', $attributes); $url = "{$typename}selector.php?id=id_{$prefix}{$i}_&callback=add_selection"; $attributes = array('name' => 'typeselector'); $output .= html_writer::link('#', $selecttype, $attributes); $output .= html_writer::end_tag('td'); $output .= html_writer::start_tag('td'); $mform->addElement('html', $output); } else { if ($this->rowtypes[$type] == 'doubleselect') { $options = $this->get_profile_fields(); $attributes = array(); if (!(array_key_exists('active', $this->_customdata) && $this->_customdata['active'])) { $attributes = array('disabled' => 'disabled'); } $url = $CFG->wwwroot . '/local/elisprogram/resultsprofileselect.php'; $frame = "{$prefix}{$i}_frame"; $value = "{$prefix}{$i}_value"; $attributes['onchange'] = "replace_content(\"{$url}\",\"{$frame}\",this.value,\"{$value}\");"; $mform->addElement('select', "{$prefix}{$i}_selected", '', $options, $attributes); $attributes = array(); if (!(array_key_exists('active', $this->_customdata) && $this->_customdata['active'])) { $attributes = array('disabled' => 'disabled'); } $tablehtml = html_writer::end_tag('td'); $tablehtml .= html_writer::start_tag('td'); $tablehtml .= html_writer::start_tag('div', array('id' => $frame)); $mform->addElement('html', $tablehtml); $selected = $data->selected; $selected_form = optional_param("{$prefix}{$i}_selected", 0, PARAM_INT); if ($selected_form > 0) { $selected = $selected_form; } if ($selected != '') { $defaults["{$prefix}{$i}_selected"] = $selected; if (!array_key_exists($selected, $configs)) { $configs[$selected] = $this->get_profile_config($selected); } if ($configs[$selected]['control'] == 'menu') { $choices = explode("\n", $configs[$selected]['options']); $options = array_combine($choices, $choices); asort($options); $mform->addElement('select', "{$prefix}{$i}_value", '', $options, $attributes); } else { $mform->addElement('text', "{$prefix}{$i}_value", '', $attributes); $mform->setType("{$prefix}{$i}_value", PARAM_TEXT); } if ($data->value != '') { $defaults["{$prefix}{$i}_value"] = $data->value; } } $tablehtml = html_writer::end_tag('div'); $mform->addElement('html', $tablehtml); } } $tablehtml = html_writer::end_tag('td'); $tablehtml .= html_writer::end_tag('tr'); $mform->addElement('html', $tablehtml); $mform->setDefaults($defaults); $i++; } }
/** * Create communication preferences block for the contact. * * @param object $form - CRM_Core_Form (or it's subclass) * @return none * * @access public * @static */ function buildCommunicationBlock(&$form) { // since the pcm - preferred comminication method is logically // grouped hence we'll use groups of HTML_QuickForm $privacy = array(); // checkboxes for DO NOT phone, email, mail // we take labels from SelectValues $t = CRM_Core_SelectValues::privacy(); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']); $form->addGroup($privacy, 'privacy', ts('Privacy'), ' '); // preferred communication method $form->add('select', 'preferred_communication_method', ts('Prefers'), CRM_Core_SelectValues::pcm()); $form->add('select', 'preferred_mail_format', ts('Mail Format'), CRM_Core_SelectValues::pmf()); }
/** * Sets contents of passed object to values from current object. * * If desired, this method can also make copies of all associated (fkey referrers) * objects. * * @param object $copyObj An object of \gossi\trixionary\model\Sport (or compatible) type. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. * @throws PropelException */ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { $copyObj->setTitle($this->getTitle()); $copyObj->setSlug($this->getSlug()); $copyObj->setAthleteLabel($this->getAthleteLabel()); $copyObj->setObjectSlug($this->getObjectSlug()); $copyObj->setObjectLabel($this->getObjectLabel()); $copyObj->setObjectPluralLabel($this->getObjectPluralLabel()); $copyObj->setSkillSlug($this->getSkillSlug()); $copyObj->setSkillLabel($this->getSkillLabel()); $copyObj->setSkillPluralLabel($this->getSkillPluralLabel()); $copyObj->setSkillPictureUrl($this->getSkillPictureUrl()); $copyObj->setGroupSlug($this->getGroupSlug()); $copyObj->setGroupLabel($this->getGroupLabel()); $copyObj->setGroupPluralLabel($this->getGroupPluralLabel()); $copyObj->setTransitionLabel($this->getTransitionLabel()); $copyObj->setTransitionPluralLabel($this->getTransitionPluralLabel()); $copyObj->setTransitionsSlug($this->getTransitionsSlug()); $copyObj->setPositionSlug($this->getPositionSlug()); $copyObj->setPositionLabel($this->getPositionLabel()); $copyObj->setFeatureComposition($this->getFeatureComposition()); $copyObj->setFeatureTester($this->getFeatureTester()); $copyObj->setIsDefault($this->getIsDefault()); if ($deepCopy) { // important: temporarily setNew(false) because this affects the behavior of // the getter/setter methods for fkey referrer objects. $copyObj->setNew(false); foreach ($this->getObjects() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addObject($relObj->copy($deepCopy)); } } foreach ($this->getPositions() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addPosition($relObj->copy($deepCopy)); } } foreach ($this->getSkills() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addSkill($relObj->copy($deepCopy)); } } foreach ($this->getGroups() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addGroup($relObj->copy($deepCopy)); } } } // if ($deepCopy) if ($makeNew) { $copyObj->setNew(true); $copyObj->setId(NULL); // this is a auto-increment column, so set to default value } }
/** * DB_DataObject_FormBuilder_QuickForm::_addElementGroupToForm() * * Adds a group of elements to a form object * Used in _generateForm(). * * @param object $form The QuickForm object to add the group to * @param array $element Array of QuickForm element objects * @param string $fieldName The field name to use for the QuickForm element group * @param string $separator Some text or HTML snippet used to separate the group entries * @access protected * @see DB_DataObject_FormBuilder::_generateForm() */ function _addElementGroupToForm(&$form, &$element, $fieldName, $separator = '') { $form->addGroup($element, $this->getFieldName($fieldName), $this->getFieldLabel($fieldName), $separator, false); }
/** * Function used to build form element for soft credit block * * @param object $form form object * @access public * * @return void */ static function buildQuickForm(&$form) { if ($form->_mode == 'live' && !empty($form->_values['honor_block_is_active'])) { $ufJoinDAO = new CRM_Core_DAO_UFJoin(); $ufJoinDAO->module = 'soft_credit'; $ufJoinDAO->entity_id = $form->_id; if ($ufJoinDAO->find(TRUE)) { $jsonData = json_decode($ufJoinDAO->module_data); if ($jsonData) { $form->assign('honor_block_title', $jsonData->soft_credit->honor_block_title); $form->assign('honor_block_text', $jsonData->soft_credit->honor_block_text); $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); $extraOption = array('onclick' => "enableHonorType();"); // radio button for Honor Type foreach ($jsonData->soft_credit->soft_credit_types as $value) { $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value, $extraOption); } $form->addGroup($honorTypes, 'soft_credit_type_id', NULL); } } return $form; } $prefix = 'soft_credit_'; // by default generate 5 blocks $item_count = 6; $showSoftCreditRow = 2; $showCreateNew = TRUE; if ($form->_action & CRM_Core_Action::UPDATE) { $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE); } elseif ($form->_pledgeID) { //Check and select most recent completed contrubtion and use it to retrieve //soft-credit information to use as default for current pledge payment, CRM-13981 $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID); foreach ($pledgePayments as $id => $record) { if ($record['contribution_id']) { $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE); if ($record['status'] == 'Completed' && count($softCredits) > 0) { $form->_softCreditInfo = $softCredits; } } } } if (property_exists($form, "_softCreditInfo")) { if (!empty($form->_softCreditInfo['soft_credit'])) { $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']); $showSoftCreditRow++; $showCreateNew = FALSE; } } for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) { CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix); $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); $form->add('select', "{$prefix}type[{$rowNumber}]", ts('Soft Credit Type'), array('' => ts('- select -')) + CRM_Core_OptionGroup::values("{$prefix}type", FALSE)); if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) { $form->add('hidden', "{$prefix}id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']); } } // CRM-7368 allow user to set or edit PCP link for contributions $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage(); if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) { $form->assign('siteHasPCPs', 1); $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1', FALSE, NULL, FALSE); $form->assign('pcpDataUrl', $pcpDataUrl); $form->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page')); $form->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id')); $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL); $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)')); $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)')); } $form->assign('showSoftCreditRow', $showSoftCreditRow); $form->assign('rowCount', $item_count); $form->assign('showCreateNew', $showCreateNew); $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("{$prefix}type"), array('id' => 'sct_default_id')); // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page if (!empty($form->_values['pcp_made_through_id'])) { $form->assign('pcpLinked', 1); } }
/** * This function for building custom fields * * @param object $qf form object (reference) * @param string $elementName name of the custom field * @param boolean $inactiveNeeded * @param boolean $userRequired true if required else false * @param boolean $search true if used for search else false * @param string $label label for custom field * * @access public * @static */ public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded = false, $useRequired = true, $search = false, $label = null) { // we use $_POST directly, since we dont want to use session memory, CRM-4677 if (isset($_POST['_qf_Relationship_refresh']) && ($_POST['_qf_Relationship_refresh'] == 'Search' || $_POST['_qf_Relationship_refresh'] == 'Search Again')) { $useRequired = 0; } $field =& new CRM_Core_DAO_CustomField(); $field->id = $fieldId; if (!$field->find(true)) { CRM_Core_Error::fatal(); } // Fixed for Issue CRM-2183 if ($field->html_type == 'TextArea' && $search) { $field->html_type = 'Text'; } if (!isset($label)) { $label = $field->label; } /** * at some point in time we might want to split the below into small functions **/ switch ($field->html_type) { case 'Text': if ($field->is_search_range && $search) { $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes); $qf->add('text', $elementName . '_to', ts('To'), $field->attributes); } else { $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, ($useRequired || $useRequired && $field->is_required) && !$search); } break; case 'TextArea': $attributes = ''; if ($field->note_rows) { $attributes .= 'rows=' . $field->note_rows; } else { $attributes .= 'rows=4'; } if ($field->note_columns) { $attributes .= ' cols=' . $field->note_columns; } else { $attributes .= ' cols=60'; } $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $attributes, ($useRequired || $useRequired && $field->is_required) && !$search); break; case 'Select Date': if ($field->is_search_range && $search) { $qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), false, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years)); $qf->addDate($elementName . '_to', ts('To'), false, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years)); } else { $required = ($useRequired || $useRequired && $field->is_required) && !$search; $qf->addDate($elementName, $label, $required, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years)); } break; case 'Radio': $choice = array(); if ($field->data_type != 'Boolean') { $customOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); foreach ($customOption as $v => $l) { $choice[] = $qf->createElement('radio', null, '', $l, (string) $v, $field->attributes); } $qf->addGroup($choice, $elementName, $label); } else { $choice[] = $qf->createElement('radio', null, '', ts('Yes'), '1', $field->attributes); $choice[] = $qf->createElement('radio', null, '', ts('No'), '0', $field->attributes); $qf->addGroup($choice, $elementName, $label); } if (($useRequired || $useRequired && $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select': $selectOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, ($useRequired || $useRequired && $field->is_required) && !$search); break; //added for select multiple //added for select multiple case 'AdvMulti-Select': $selectOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); $include =& $qf->addElement('advmultiselect', $elementName, $label, $selectOption, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect')); $include->setButtonAttributes('add', array('value' => ts('Add >>'))); $include->setButtonAttributes('remove', array('value' => ts('<< Remove'))); if (($useRequired || $useRequired && $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Multi-Select': $selectOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); if ($search && count($selectOption) > 1) { $selectOption['CiviCRM_OP_OR'] = ts('Select to match ANY; unselect to match ALL'); } $qf->addElement('select', $elementName, $label, $selectOption, array("size" => "5", "multiple")); if (($useRequired || $useRequired && $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'CheckBox': $customOption = CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id); $check = array(); foreach ($customOption as $v => $l) { $check[] =& $qf->addElement('advcheckbox', $v, null, $l); } if ($search && count($check) > 1) { $check[] =& $qf->addElement('advcheckbox', 'CiviCRM_OP_OR', null, ts('Check to match ANY; uncheck to match ALL')); } $qf->addGroup($check, $elementName, $label); if (($useRequired || $useRequired && $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'File': // we should not build upload file in search mode if ($search) { return; } $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && $field->is_required && !$search); $qf->addUploadElement($elementName); break; case 'Select State/Province': //Add State $stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); $qf->add('select', $elementName, $label, $stateOption, $useRequired && $field->is_required && !$search); break; case 'Multi-Select State/Province': //Add Multi-select State/Province $stateOption = CRM_Core_PseudoConstant::stateProvince(); $qf->addElement('select', $elementName, $label, $stateOption, array("size" => "5", "multiple")); if (($useRequired || $useRequired && $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select Country': //Add Country $countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); $qf->add('select', $elementName, $label, $countryOption, $useRequired && $field->is_required && !$search); break; case 'Multi-Select Country': //Add Country $countryOption = CRM_Core_PseudoConstant::country(); $qf->addElement('select', $elementName, $label, $countryOption, array("size" => "5", "multiple")); if (($useRequired || $useRequired && $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'RichTextEditor': $element =& $qf->addWysiwyg($elementName, $label, array('rows' => $field->note_rows), $search); break; case 'Autocomplete-Select': $qf->add('text', $elementName, $label, $field->attributes, ($useRequired || $useRequired && $field->is_required) && !$search); $qf->addElement('hidden', $elementName . '_id', '', array('id' => $elementName . '_id')); static $customUrls = array(); if ($field->data_type == 'ContactReference') { $customUrls[$elementName] = CRM_Utils_System::url("civicrm/ajax/contactlist", "reset=1&context=customfield&id={$field->id}", false, null, false); $actualElementValue = $qf->_submitValues[$elementName . '_id']; $qf->addRule($elementName, ts('Select a valid contact for %1.', array(1 => $label)), 'validContact', $actualElementValue); } else { $customUrls[$elementName] = CRM_Utils_System::url("civicrm/ajax/auto", "reset=1&ogid={$field->option_group_id}&cfid={$field->id}", false, null, false); $qf->addRule($elementName, ts('Select a valid value for %1.', array(1 => $label)), 'autocomplete', array('fieldID' => $field->id, 'optionGroupID' => $field->option_group_id)); } $qf->assign("customUrls", $customUrls); break; } switch ($field->data_type) { case 'Int': // integers will have numeric rule applied to them. if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer'); $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer'); } else { $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer'); } break; case 'Float': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } else { $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } break; case 'Money': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); $qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); } else { $qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); } break; case 'Link': $element =& $qf->add('text', $elementName, $label, array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false"), ($useRequired || $useRequired && $field->is_required) && !$search); $qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL'); break; } }
/** * Constructor (ZE2) Summary * * o Creates a standard progress bar into a dialog box (QuickForm). * Form name, buttons 'start', 'cancel' labels and style, and * title of dialog box may also be changed. * <code> * $monitor = new HTML_Progress2_Monitor(); * </code> * * o Creates a progress bar into a dialog box, with only a new * form name. * <code> * $monitor = new HTML_Progress2_Monitor($formName); * </code> * * o Creates a progress bar into a dialog box, with a new form name, * new buttons name and style, and also a different title box. * <code> * $monitor = new HTML_Progress2_Monitor($formName, $attributes); * </code> * * @param string $formName (optional) Name of monitor dialog box (QuickForm) * @param array $attributes (optional) List of renderer options * @param array $errorPrefs (optional) Hash of params to configure error handler * * @since 2.0.0 * @access protected * @throws HTML_PROGRESS2_ERROR_INVALID_INPUT */ function __construct($formName = 'ProgressMonitor', $attributes = array(), $errorPrefs = array()) { $this->_progress = new HTML_Progress2($errorPrefs); if (!is_string($formName)) { return $this->_progress->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT, 'exception', array('var' => '$formName', 'was' => gettype($formName), 'expected' => 'string', 'paramnum' => 1)); } elseif (!is_array($attributes)) { return $this->_progress->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT, 'exception', array('var' => '$attributes', 'was' => gettype($attributes), 'expected' => 'array', 'paramnum' => 2)); } $this->_id = md5(microtime()); $this->_observerCount = 0; $this->_form = new HTML_QuickForm($formName); $this->_form->removeAttribute('name'); // XHTML compliance $captionAttr = array('id' => 'monitorStatus', 'valign' => 'bottom', 'left' => 0); $this->windowname = isset($attributes['title']) ? $attributes['title'] : 'In progress ...'; $this->buttonStart = isset($attributes['start']) ? $attributes['start'] : 'Start'; $this->buttonCancel = isset($attributes['cancel']) ? $attributes['cancel'] : 'Cancel'; $buttonAttr = isset($attributes['button']) ? $attributes['button'] : ''; $this->autorun = isset($attributes['autorun']) ? $attributes['autorun'] : false; $this->caption = isset($attributes['caption']) ? $attributes['caption'] : $captionAttr; $this->_progress->addLabel(HTML_PROGRESS2_LABEL_TEXT, $this->caption['id']); $captionAttr = $this->caption; unset($captionAttr['id']); $this->_progress->setLabelAttributes($this->caption['id'], $captionAttr); $this->_progress->setProgressAttributes('top=0 left=0'); $this->_form->addElement('header', 'windowname', $this->windowname); $this->_form->addElement('static', 'progressBar'); if ($this->isStarted()) { $style = array('disabled' => 'true'); } else { $style = null; } $buttons[] =& $this->_form->createElement('submit', 'start', $this->buttonStart, $style); $buttons[] =& $this->_form->createElement('submit', 'cancel', $this->buttonCancel); $buttons[0]->updateAttributes($buttonAttr); $buttons[1]->updateAttributes($buttonAttr); $this->_form->addGroup($buttons, 'buttons', '', ' ', false); // default embedded progress element with look-and-feel $this->setProgressElement($this->_progress); }