Example #1
0
 /**
  * This function provides the HTML form elements that are specific
  * to the Household Contact Type
  *
  * @param object $form form object
  * @param int $inlineEditMode ( 1 for contact summary
  * top bar form and 2 for display name edit )
  *
  * @access public
  * @return void
  */
 public static function buildQuickForm(&$form, $inlineEditMode = NULL)
 {
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
     $form->applyFilter('__ALL__', 'trim');
     if (!$inlineEditMode || $inlineEditMode == 1) {
         // household_name
         $form->add('text', 'household_name', ts('Household Name'), $attributes['household_name']);
     }
     if (!$inlineEditMode || $inlineEditMode == 2) {
         // nick_name
         $form->addElement('text', 'nick_name', ts('Nickname'), $attributes['nick_name']);
         $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     }
     if (!$inlineEditMode) {
         $form->add('text', 'external_identifier', ts('External Id'), $attributes['external_identifier'], FALSE);
         $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
     }
 }
Example #2
0
 /**
  * @method  school_formelement_condition
  * @todo to display school field form element based on condition (if multiple school providing drop down box else static field)
  * @param object $mform    
  * @return array of objects(form elements)
  */
 public function school_formelement_condition($mform) {
     global $DB, $CFG, $USER;
     $hier = new hierarchy();
     if (is_siteadmin($USER->id)) {
         $schoolids = $DB->get_records('local_school', array('visible' => 1));
     } else
         $schoolids = $hier->get_assignedschools();
     if (!empty($schoolids)) {
         $count = sizeof($schoolids);
         if ($count > 1) {
             $parents = $hier->get_school_parent($schoolids, '', true);
             $mform->addElement('select', 'schoolid', get_string('select', 'local_collegestructure'), $parents);
             $mform->addRule('schoolid', get_string('missingschool', 'local_collegestructure'), 'required', null, 'client');
         } else {
             $schoolname = $DB->get_record('local_school', array('id' => $schoolids[0]->id));
             $mform->addElement('static', 'sid', get_string('schoolid', 'local_collegestructure'), $schoolname->fullname);
             $mform->addElement('hidden', 'schoolid', $schoolids[0]->id);
         }
         $mform->setType('schoolid', PARAM_INT);
     }
 }
 /**
  * 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'] .= '&nbsp;-&nbsp;';
                     $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'] .= '&nbsp;-&nbsp;';
                     $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();
     }
 }
 /**
  * Add form elements for course format.
  * @param object $mform			form definition
  * @param object $courseinfo	a record of general information from course info table
  * @return void
  */
 private function setup_format($mform, $courseinfo)
 {
     global $CFG, $DB, $USER;
     //Declare our globals for use
     global $courseId;
     $mform->addElement('html', '<a name="format"></a>');
     // anchor
     $mform->addElement('header', 'course_format_header', get_string('course_format_header', 'local_metadata'));
     $mform->addHelpButton('course_format_header', 'course_format_header', 'local_metadata');
     // Assessment
     $course_assessment = $mform->addElement('text', 'course_assessment', get_string('assessment_counter', 'local_metadata'), '');
     //$mform->addRule('course_assessment', get_string('err_required', 'local_metadata'), 'required', null, 'client');
     $mform->addRule('course_assessment', get_string('err_numeric', 'local_metadata'), 'numeric', null, 'client');
     $courseassessment = $DB->count_records('courseassessment', array('courseid' => $courseId));
     if ($courseassessment != 0) {
         $mform->setDefault('course_assessment', $courseassessment);
     } else {
         if ($courseinfo) {
             $mform->setDefault('course_assessment', $courseinfo->assessmentnumber);
         }
     }
     $mform->setType('course_assessment', PARAM_INT);
     // Session
     $course_assessment = $mform->addElement('text', 'course_session', get_string('session_counter', 'local_metadata'), '');
     //$mform->addRule('course_session', get_string('err_required', 'local_metadata'), 'required', null, 'client');
     $mform->addRule('course_session', get_string('err_numeric', 'local_metadata'), 'numeric', null, 'client');
     $coursesession = $DB->count_records('coursesession', array('courseid' => $courseId));
     if ($coursesession != 0) {
         $mform->setDefault('course_session', $coursesession);
     } else {
         if ($courseinfo) {
             $mform->setDefault('course_session', $courseinfo->sessionnumber);
         }
     }
     $mform->setType('course_session', PARAM_INT);
     $mform->addElement('static', 'h_6', '');
     // end of header
     $mform->setType('h_6', PARAM_RAW);
     $mform->closeHeaderBefore('h_6');
     $mform->setExpanded('course_format_header');
 }
Example #5
0
 /**
  * DB_DataObject_FormBuilder_QuickForm::_addFieldRulesToForm()
  *
  * Adds a set of rules to a form that will apply to a specific element
  * Used in _generateForm().
  *
  * @param object $form      The form object to add the ruleset to
  * @param array  $rules     Array of rule names to be enforced on the element (must be registered QuickForm rules)
  * @param string $fieldName Name of the form element in question
  * @access protected
  * @see DB_DataObject_FormBuilder::_generateForm()
  */
 function _addFieldRulesToForm(&$form, $rules, $fieldName)
 {
     $fieldLabel = $this->getFieldLabel($fieldName);
     $ruleSide = $this->clientRules ? 'client' : 'server';
     foreach ($rules as $rule) {
         if ($rule['rule'] === false) {
             $form->addRule($this->getFieldName($fieldName), sprintf($rule['message'], $fieldLabel), $rule['validator'], '', $ruleSide);
         } else {
             $form->addRule($this->getFieldName($fieldName), sprintf($rule['message'], $fieldLabel), $rule['validator'], $rule['rule'], $ruleSide);
         }
         // End if
     }
     // End while
 }
 /**
  * Add Plugin settings input to Moodle form
  * @param object $mform
  */
 public function type_config_form(&$mform)
 {
     $public_account = get_config('boxnet', 'public_account');
     $api_key = get_config('boxnet', 'api_key');
     if (empty($api_key)) {
         $api_key = '';
     }
     $strrequired = get_string('required');
     $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'), array('value' => $api_key, 'size' => '40'));
     $mform->addRule('api_key', $strrequired, 'required', null, 'client');
     $mform->addElement('static', null, '', get_string('information', 'repository_boxnet'));
 }
 /**
  * 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);
     }
 }
 /**
  * Add custom requirement rules to filter elements
  *
  * @param   object $mform  The mform object for the filter page
  * @param   string $key    The filter field key
  * @param   object $fields The filter field values object
  *
  * @return  object $mform  The modified mform object for the filter page
  */
 function apply_filter_required_rule($mform, $key, $fields)
 {
     if ($mform->elementExists($key . '_grp')) {
         $mform->addRule($key . '_grp', get_string('required'), 'required', null, 'client');
         $mform->registerRule('custom_rule', 'function', 'user_course_completion_check_custom_rule');
         $mform->addRule($key . '_grp', get_string('required'), 'custom_rule', array($key, $fields));
     }
     return $mform;
 }
Example #9
0
 /**
  * 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 .= '&nbsp;-&nbsp;';
                 $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'] .= '&nbsp;-&nbsp;';
                     $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'] .= '&nbsp;-&nbsp;';
                     $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'] .= '&nbsp;-&nbsp;';
                     $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();
     }
 }
Example #10
0
 /**
  * Called by HTML_QuickForm whenever form event is made on this element.
  * Adds necessary rules to the element and checks that coorenct instance of gradingform_instance
  * is passed in attributes
  *
  * @param string $event Name of event
  * @param mixed $arg event arguments
  * @param object $caller calling object
  * @return bool
  * @throws moodle_exception
  */
 public function onQuickFormEvent($event, $arg, &$caller)
 {
     if ($event == 'createElement') {
         $attributes = $arg[2];
         if (!is_array($attributes) || !array_key_exists('gradinginstance', $attributes) || !$attributes['gradinginstance'] instanceof gradingform_instance) {
             throw new moodle_exception('exc_gradingformelement', 'grading');
         }
     }
     $name = $this->getName();
     if ($name && $caller->elementExists($name)) {
         $caller->addRule($name, $this->get_gradinginstance()->default_validation_error_message(), 'gradingvalidated', $this->gradingattributes);
     }
     return parent::onQuickFormEvent($event, $arg, $caller);
 }
Example #11
0
 /**
  * Called by HTML_QuickForm whenever form event is made on this element.
  *
  * @param string $event Name of event
  * @param mixed $arg event arguments
  * @param object $caller calling object
  * @return mixed
  */
 public function onQuickFormEvent($event, $arg, &$caller)
 {
     global $COURSE;
     switch ($event) {
         case 'updateValue':
             $value = $this->_findValue($caller->_constantValues);
             if (null === $value) {
                 if ($caller->isSubmitted()) {
                     $value = $this->_findValue($caller->_submitValues);
                 } else {
                     $value = $this->_findValue($caller->_defaultValues);
                 }
             }
             $name = $this->getName();
             // Set disable actions.
             $caller->disabledIf($name . '[modgrade_scale]', $name . '[modgrade_type]', 'neq', 'scale');
             $caller->disabledIf($name . '[modgrade_point]', $name . '[modgrade_type]', 'neq', 'point');
             // Set element state for existing data.
             if (!empty($this->_elements)) {
                 if (!empty($value)) {
                     if ($value < 0) {
                         $this->_elements[1]->setValue('scale');
                         $this->_elements[4]->setValue($value * -1);
                     } else {
                         if ($value > 0) {
                             $this->_elements[1]->setValue('point');
                             $this->_elements[7]->setValue($value);
                         }
                     }
                 } else {
                     $this->_elements[1]->setValue('none');
                     $this->_elements[7]->setValue('');
                 }
             }
             // Value Validation.
             if ($name && $caller->elementExists($name)) {
                 $checkmaxgrade = function ($val) {
                     if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'point') {
                         if (!isset($val['modgrade_point'])) {
                             return false;
                         }
                         return $this->validate_point($val['modgrade_point']);
                     }
                     return true;
                 };
                 $checkvalidscale = function ($val) {
                     if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'scale') {
                         if (!isset($val['modgrade_scale'])) {
                             return false;
                         }
                         return $this->validate_scale($val['modgrade_scale']);
                     }
                     return true;
                 };
                 $maxgradeexceeded = get_string('modgradeerrorbadpoint', 'grades', get_config('core', 'gradepointmax'));
                 $invalidscale = get_string('modgradeerrorbadscale', 'grades');
                 $caller->addRule($name, $maxgradeexceeded, 'callback', $checkmaxgrade);
                 $caller->addRule($name, $invalidscale, 'callback', $checkvalidscale);
             }
             break;
     }
     return parent::onQuickFormEvent($event, $arg, $caller);
 }
Example #12
0
/**
 * adds the list of plagiarism settings to a form
 *
 * @param object $mform - Moodle form object
 */
function turnitin_get_form_elements($mform)
{
    $ynoptions = array(0 => get_string('no'), 1 => get_string('yes'));
    $tiishowoptions = array(PLAGIARISM_TII_SHOW_NEVER => get_string("never"), PLAGIARISM_TII_SHOW_ALWAYS => get_string("always"), PLAGIARISM_TII_SHOW_CLOSED => get_string("showwhenclosed", "plagiarism_turnitin"));
    $tiidraftoptions = array(PLAGIARISM_TII_DRAFTSUBMIT_IMMEDIATE => get_string("submitondraft", "plagiarism_turnitin"), PLAGIARISM_TII_DRAFTSUBMIT_FINAL => get_string("submitonfinal", "plagiarism_turnitin"));
    $reportgenoptions = array(0 => get_string('reportgenimmediate', 'plagiarism_turnitin'), 1 => get_string('reportgenimmediateoverwrite', 'plagiarism_turnitin'), 2 => get_string('reportgenduedate', 'plagiarism_turnitin'));
    $excludetype = array(0 => get_string('no'), 1 => get_string('wordcount', 'plagiarism_turnitin'), 2 => get_string('percentage', 'plagiarism_turnitin'));
    $mform->addElement('header', 'plagiarismdesc');
    $mform->addElement('select', 'use_turnitin', get_string("useturnitin", "plagiarism_turnitin"), $ynoptions);
    $mform->addElement('select', 'plagiarism_show_student_score', get_string("showstudentsscore", "plagiarism_turnitin"), $tiishowoptions);
    $mform->addHelpButton('plagiarism_show_student_score', 'showstudentsscore', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_show_student_report', get_string("showstudentsreport", "plagiarism_turnitin"), $tiishowoptions);
    $mform->addHelpButton('plagiarism_show_student_report', 'showstudentsreport', 'plagiarism_turnitin');
    if ($mform->elementExists('var4')) {
        $mform->addElement('select', 'plagiarism_draft_submit', get_string("draftsubmit", "plagiarism_turnitin"), $tiidraftoptions);
    }
    $mform->addElement('select', 'plagiarism_compare_student_papers', get_string("comparestudents", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_compare_student_papers', 'comparestudents', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_compare_internet', get_string("compareinternet", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_compare_internet', 'compareinternet', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_compare_journals', get_string("comparejournals", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_compare_journals', 'comparejournals', 'plagiarism_turnitin');
    if (get_config('plagiarism', 'turnitin_institutionnode')) {
        $mform->addElement('select', 'plagiarism_compare_institution', get_string("compareinstitution", "plagiarism_turnitin"), $ynoptions);
        $mform->addHelpButton('plagiarism_compare_institution', 'compareinstitution', 'plagiarism_turnitin');
    }
    $mform->addElement('select', 'plagiarism_report_gen', get_string("reportgen", "plagiarism_turnitin"), $reportgenoptions);
    $mform->addHelpButton('plagiarism_report_gen', 'reportgen', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_exclude_biblio', get_string("excludebiblio", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_exclude_biblio', 'excludebiblio', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_exclude_quoted', get_string("excludequoted", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_exclude_quoted', 'excludequoted', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_exclude_matches', get_string("excludematches", "plagiarism_turnitin"), $excludetype);
    $mform->addHelpButton('plagiarism_exclude_matches', 'excludematches', 'plagiarism_turnitin');
    $mform->addElement('text', 'plagiarism_exclude_matches_value', '');
    $mform->addRule('plagiarism_exclude_matches_value', null, 'numeric', null, 'client');
    $mform->disabledIf('plagiarism_exclude_matches_value', 'plagiarism_exclude_matches', 'eq', 0);
    $mform->addElement('select', 'plagiarism_anonymity', get_string("anonymity", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_anonymity', 'anonymity', 'plagiarism_turnitin');
}
Example #13
0
 /**
  * This function provides the HTML form elements that are specific
  * to the Individual Contact Type
  *
  * @param object $form form object
  * @param int $inlineEditMode ( 1 for contact summary
  * top bar form and 2 for display name edit )
  *
  * @access public
  * @return void
  */
 public static function buildQuickForm(&$form, $inlineEditMode = NULL)
 {
     $form->applyFilter('__ALL__', 'trim');
     if (!$inlineEditMode || $inlineEditMode == 1) {
         //prefix
         $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
         if (!empty($prefix)) {
             $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix);
         }
         $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
         // first_name
         $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
         //middle_name
         $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
         // last_name
         $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
         // suffix
         $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
         if ($suffix) {
             $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix);
         }
     }
     if (!$inlineEditMode || $inlineEditMode == 2) {
         // nick_name
         $form->addElement('text', 'nick_name', ts('Nickname'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
         // job title
         // override the size for UI to look better
         $attributes['job_title']['size'] = 30;
         $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
         //Current Employer Element
         $employerDataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&employee_id=' . $form->_contactId, FALSE, NULL, FALSE);
         $form->assign('employerDataURL', $employerDataURL);
         $form->addElement('text', 'current_employer', ts('Current Employer'), '');
         $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id'));
         $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     }
     if (!$inlineEditMode) {
         $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_ajax_check_similar', NULL, TRUE);
         if ($checkSimilar == null) {
             $checkSimilar = 0;
         }
         $form->assign('checkSimilar', $checkSimilar);
         //External Identifier Element
         $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE);
         $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
         $config = CRM_Core_Config::singleton();
         CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
     }
 }
Example #14
0
 /**
  * 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>');
 }
 /**
  * Add custom requirement rules to filter elements
  *
  * @param   object $mform  The mform object for the filter page
  * @param   string $key    The filter field key
  * @param   object $fields The filter field values object
  *
  * @return  object $mform  The modified mform object for the filter page
  */
 public static function apply_filter_required_rule($mform, $key, $fields)
 {
     $elem = "{$key}_grp";
     if ($mform->elementExists($elem)) {
         $mform->addRule($elem, get_string('required'), 'required', null, 'client');
         $mform->registerRule('custom_rule', 'function', 'course_completion_check_custom_rule');
         $mform->addRule($elem, get_string('required'), 'custom_rule', array($key, $fields));
     }
     return $mform;
 }
Example #16
0
    /**
     * Add Plugin settings input to Moodle form
     * @param object $mform
     */
    public static function type_config_form($mform, $classname = 'repository') {
        global $CFG;
        $api_key = get_config('flickr', 'api_key');
        $secret = get_config('flickr', 'secret');

        if (empty($api_key)) {
            $api_key = '';
        }
        if (empty($secret)) {
            $secret = '';
        }

        $strrequired = get_string('required');
        $mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr'), array('value'=>$api_key,'size' => '40'));
        $mform->addElement('text', 'secret', get_string('secret', 'repository_flickr'), array('value'=>$secret,'size' => '40'));

        //retrieve the flickr instances
        $params = array();
        $params['context'] = array();
        //$params['currentcontext'] = $this->context;
        $params['onlyvisible'] = false;
        $params['type'] = 'flickr';
        $instances = repository::get_instances($params);
        if (empty($instances)) {
            $callbackurl = get_string('callbackwarning', 'repository_flickr');
            $mform->addElement('static', null, '',  $callbackurl);
        } else {
            $instance = array_shift($instances);
            $callbackurl = $CFG->wwwroot.'/repository/repository_callback.php?repo_id='.$instance->id;
            $mform->addElement('static', 'callbackurl', '', get_string('callbackurltext', 'repository_flickr', $callbackurl));
        }

        $mform->addRule('api_key', $strrequired, 'required', null, 'client');
        $mform->addRule('secret', $strrequired, 'required', null, 'client');
    }
 /**
  * Add custom requirement rules to filter elements
  *
  * @param   object $mform  The mform object for the filter page
  * @param   string $key    The filter field key
  * @param   object $fields The filter field values object
  *
  * @return  object $mform  The modified mform object for the filter page
  */
 public static function apply_filter_required_rule($mform, $key, $fields)
 {
     $elem = "{$key}_grp";
     if ($mform->elementExists($elem)) {
         $mform->addRule($elem, get_string('required'), 'required', null, 'client');
         $mform->addGroupRule($elem, get_string('required'), 'required', null, 2, 'client');
         // TBV
     }
     return $mform;
 }
 /**
  * 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;
     }
 }
Example #19
0
    /**
     * @method settingelements
     * @todo to set form elements
     * @param object $mform object
     * @param string $place1
     * @param string $place2 
     * @return array of objects ($mfrom objects)
     * */
    public function settingelements($mform, $place1, $place2) {
        global $hierarchy;
        $hierarchy = new hierarchy();
        $faculties = $hierarchy->get_assignedschools();
        $school = $hierarchy->get_school_parent($faculties);
        $newel = $mform->createElement('select', 'schoolid', get_string('schoolid', 'local_collegestructure'), $school);
        $mform->insertElementBefore($newel, $place1);
        $mform->addRule('schoolid', get_string('missingschool', 'local_collegestructure'), 'required', null, 'client');
        $school_value = $mform->getElementValue('schoolid');

        //Creating program element after getting the school value
        if (isset($school_value) && !empty($school_value)) {
            $school_id = $school_value[0];
            $programs = $hierarchy->get_records_cobaltselect_menu('local_program', "schoolid=$school_id AND visible=1", null, '', 'id,fullname', '--Select--');
            $newel2 = $mform->createElement('select', 'programid', get_string('selectprogram', 'local_programs'), $programs);
            $mform->insertElementBefore($newel2, $place2);
            $mform->addRule('programid', get_string('missingfullname', 'local_programs'), 'required', null, 'client');
            $program_value = $mform->getElementValue('programid');
            return $program_value;
        }
    }
 /**
  * Function to build the form
  *
  * @param object $form form object
  *
  * @return void
  * @access public
  */
 public static function buildPCPForm($form)
 {
     $form->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages?'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','block','radio',false);"));
     $form->addElement('checkbox', 'is_approval_needed', ts('Approval required'));
     $profile = array();
     $isUserRequired = NULL;
     $config = CRM_Core_Config::singleton();
     if ($config->userFramework != 'Standalone') {
         $isUserRequired = 2;
     }
     CRM_Core_DAO::commonRetrieveAll('CRM_Core_DAO_UFGroup', 'is_cms_user', $isUserRequired, $profiles, array('title', 'is_active'));
     if (!empty($profiles)) {
         foreach ($profiles as $key => $value) {
             if ($value['is_active']) {
                 $profile[$key] = $value['title'];
             }
         }
         $form->assign('profile', $profile);
     }
     $form->add('select', 'supporter_profile_id', ts('Supporter profile'), array('' => ts('- select -')) + $profile, TRUE);
     $form->addElement('checkbox', 'is_tellfriend_enabled', ts("Allow 'Tell a friend' functionality"), NULL, array('onclick' => "return showHideByValue('is_tellfriend_enabled',true,'tflimit','table-row','radio',false);"));
     $form->add('text', 'tellfriend_limit', ts("'Tell a friend' maximum recipients limit"), CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'tellfriend_limit'));
     $form->addRule('tellfriend_limit', ts('Please enter a valid limit.'), 'integer');
     $form->add('text', 'link_text', ts("'Create Personal Campaign Page' link text"), CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'link_text'));
     $form->add('text', 'notify_email', ts('Notify Email'), CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'notify_email'));
 }
Example #21
0
 /**
  * Add Plugin settings input to Moodle form
  * @param object $mform
  */
 public static function type_config_form($mform, $classname = 'repository')
 {
     $api_key = get_config('flickr_public', 'api_key');
     if (empty($api_key)) {
         $api_key = '';
     }
     $strrequired = get_string('required');
     $mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr_public'), array('value' => $api_key, 'size' => '40'));
     $mform->addRule('api_key', $strrequired, 'required', null, 'client');
     $mform->addElement('static', null, '', get_string('information', 'repository_flickr_public'));
 }
Example #22
0
 /**
  * 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;
     }
 }
Example #23
0
 /**
  * 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 .= '&nbsp;-&nbsp;';
                 $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'] .= '&nbsp;-&nbsp;';
                     $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'] .= '&nbsp;-&nbsp;';
                     $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'] .= '&nbsp;-&nbsp;';
                     $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();
     }
 }
Example #24
0
 /**
  * build form for address input fields
  *
  * @param object  $form - CRM_Core_Form (or subclass)
  * @param int     $addressBlockCount - the index of the address array (if multiple addresses on a page)
  * @param boolean $sharing - false, if we want to skip the address sharing features
  * @param boolean $inlineEdit true when edit used in inline edit
  *
  * @return void
  *
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE)
 {
     // passing this via the session is AWFUL. we need to fix this
     if (!$addressBlockCount) {
         $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
     } else {
         $blockId = $addressBlockCount;
     }
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->applyFilter('__ALL__', 'trim');
     $js = array();
     if (!$inlineEdit) {
         $js = array('onChange' => 'checkLocation( this.id );');
     }
     $form->addSelect("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     } else {
         //make location type required for inline edit
         $form->addRule("address[{$blockId}][location_type_id]", ts('%1 is a required field.', array(1 => ts('Location Type'))), 'required');
     }
     $form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
     }
     $form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
     // hidden element to store master address id
     $form->addElement('hidden', "address[{$blockId}][master_id]");
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], NULL), 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL), 'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL), 'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL), 'city' => array(ts('City'), $attributes['city'], NULL), 'postal_code' => array(ts('Zip / Postal Code'), array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')), NULL), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'), NULL), 'county_id' => array(ts('County'), $attributes['county_id'], NULL), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], NULL), 'country_id' => array(ts('Country'), $attributes['country_id'], NULL), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 11), NULL), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 11), NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL));
     $stateCountryMap = array();
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select) = $v;
         $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
         if (empty($addressOptions[$nameWithoutID])) {
             $continue = TRUE;
             if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) {
                 $continue = FALSE;
             }
             if ($continue) {
                 continue;
             }
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         //build normal select if country is not present in address block
         if ($name == 'state_province_id' && !$addressOptions['country']) {
             $select = 'stateProvince';
         }
         if (!$select) {
             if ($name == 'country_id' || $name == 'state_province_id' || $name == 'county_id') {
                 if ($name == 'country_id') {
                     $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
                     $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
                 } elseif ($name == 'state_province_id') {
                     $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
                     if ($countryDefault) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                     } else {
                         $selectOptions = array('' => ts('- select a country -'));
                     }
                 } elseif ($name == 'county_id') {
                     $stateCountryMap[$blockId]['county'] = "address_{$blockId}_{$name}";
                     if ($form->getSubmitValue("address[{$blockId}][state_province_id]")) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($form->getSubmitValue("address[{$blockId}][state_province_id]"));
                     } elseif ($form->getSubmitValue("address[{$blockId}][county_id]")) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county();
                     } else {
                         $selectOptions = array('' => ts('- select a state -'));
                     }
                 }
                 $form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
             } else {
                 if ($name == 'address_name') {
                     $name = 'name';
                 }
                 $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
             }
         } else {
             if ($name == 'state_province_id') {
                 $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
             }
             $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
         }
     }
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $entityId = NULL;
     if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
         $entityId = $form->_values['address'][$blockId]['id'];
     }
     // CRM-11665 geocode override option
     $geoCode = FALSE;
     if (!empty($config->geocodeMethod)) {
         $geoCode = TRUE;
         $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding'));
     }
     $form->assign('geoCode', $geoCode);
     // Process any address custom data -
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
     if (isset($groupTree) && is_array($groupTree)) {
         // use simplified formatted groupTree
         $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
         // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
         foreach ($groupTree as $id => $group) {
             foreach ($group['fields'] as $fldId => $field) {
                 $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
                 $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
             }
         }
         $defaults = array();
         CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
         // since we change element name for address custom data, we need to format the setdefault values
         $addressDefaults = array();
         foreach ($defaults as $key => $val) {
             if (empty($val)) {
                 continue;
             }
             // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
             // this works for all types custom data
             $keyValues = explode('[', str_replace(']', '', $key));
             $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
         }
         $form->setDefaults($addressDefaults);
         // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
         // And we can't set it to 'address_' because we want to set it in a slightly different format.
         CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
         // during contact editing : if no address is filled
         // required custom data must not produce 'required' form rule error
         // more handling done in formRule func
         if (!$inlineEdit) {
             CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
         }
         $template = CRM_Core_Smarty::singleton();
         $tplGroupTree = $template->get_template_vars('address_groupTree');
         $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;
         $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
         // unset the temp smarty var that got created
         $form->assign('dnc_groupTree', NULL);
     }
     // address custom data processing ends ..
     if ($sharing) {
         // shared address
         $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address'));
         // get the reserved for address
         $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name');
         if (!$profileId) {
             CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.'));
         }
         CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId));
     }
 }
 /**
  * Add custom requirement rules to filter elements
  *
  * @param   object $mform  The mform object for the filter page
  * @param   string $key    The filter field key
  * @param   object $fields The filter field values object
  *
  * @return  object $mform  The modified mform object for the filter page
  */
 function apply_filter_required_rule($mform, $key, $fields)
 {
     if ($mform->elementExists($key . '_grp')) {
         $mform->addRule($key . '_grp', get_string('required'), 'required', null, 'client');
         $mform->addGroupRule($key . '_grp', array($key => array(array(get_string('required'), 'required', null, 'client'))));
     }
     return $mform;
 }