/** * build a form for the given UF group * * @param int $id the group id * @param CRM_Core_Form $form the form element * @param string $name the name that we should store the fields as * @param array $allFields reference to the array where all the fields are stored * * @return void * @static * @access public */ function buildQuickForm($id, &$form, $name, &$allFields) { $fields =& CRM_Core_BAO_UFGroup::getFields($id, false, $action); foreach ($fields as $n => $fld) { if (!array_key_exists($n, $allFields)) { $allFields[$n] = $fld; } } $form->assign($name, $fields); foreach ($fields as $name => $field) { $required = $field['is_required']; if (substr($field['name'], 0, 14) === 'state_province') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $form->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth')); } else { if ($field['name'] === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $form->addGroup($genderOptions, $field['name'], $field['title']); } else { if ($field['name'] === 'individual_prefix') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix()); } else { if ($field['name'] === 'individual_suffix') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix()); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($form, 0, CRM_CONTACT_FORM_GROUPTAG_GROUP); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($form, 0, CRM_CONTACT_FORM_GROUPTAG_TAG); } else { if (substr($field['name'], 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']); CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, $inactiveNeeded, false); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { $form->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } if ($field['rule']) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']); } } }
/** * Function to actually build the form * * @return None * @access public */ function buildQuickForm() { // assign a few constants used by all display elements // we can obsolete this when smarty can access class constans directly $this->assign('locationCount', CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS + 1); $this->assign('blockCount', CRM_CONTACT_FORM_LOCATION_BLOCKS + 1); $this->assign('contact_type', $this->_contactType); require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_Form_" . $this->_contactType) . ".php"; eval('CRM_Contact_Form_' . $this->_contactType . '::buildQuickForm( $this );'); // add the communications block CRM_Contact_Form_Edit::buildCommunicationBlock($this); /* Entering the compact location engine */ $location =& CRM_Contact_Form_Location::buildLocationBlock($this, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); /* End of locations */ // add note block if ($this->_action & CRM_CORE_ACTION_ADD) { $note =& CRM_Contact_Form_Note::buildNoteBlock($this); } //add tags and groups block $groupTag =& CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_contactId, CRM_CONTACT_FORM_GROUPTAG_ALL); //Custom Group Inline Edit form $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this->_contactId); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1'); $config =& CRM_Core_Config::singleton(); CRM_Core_ShowHideBlocks::links($this, 'notes', '', ''); // add the dedupe button $this->addElement('submit', $this->_dedupeButtonName, ts('Check for Matching Contact(s)')); $this->addElement('submit', $this->_duplicateButtonName, ts('Save Duplicate Contact')); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'subName' => 'view', 'isDefault' => true), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { // add the form elements require_once "CRM/Contribute/PseudoConstant.php"; foreach ($this->_fields as $name => $field) { $required = $field['is_required']; if (substr($field['name'], 0, 14) === 'state_province') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required); } else { if ($field['name'] === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $this->addGroup($genderOptions, $field['name'], $field['title']); if ($required) { $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { if ($field['name'] === 'individual_prefix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($field['name'] === 'individual_suffix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($field['name'] === 'preferred_communication_method') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm()); } else { if ($field['name'] === 'preferred_mail_format') { $this->add('select', $name, $field['title'], array(CRM_Core_SelectValues::pcm())); } else { if (substr($field['name'], 0, 7) === 'do_not_') { $this->add('checkbox', $name, $field['title'], $field['attributes'], $required); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, false, $required, $field['title'], null); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']); } else { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) { CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']); } else { if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required); } else { if ($field['name'] == 'payment_instrument') { $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($field['name'] == 'contribution_type') { $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { $this->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } } } } } } } } $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true))); }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { if ($this->_mode != CRM_PROFILE_FORM_MODE_REGISTER) { //check for mix profile (eg: individual + other contact type) require_once "CRM/Core/BAO/UFField.php"; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { CRM_Utils_System::setUFMessage(ts("This Profile includes fields for contact types other than 'Individuals' and can not be used to create/update contacts.")); $config =& CRM_Core_Config::singleton(); CRM_Utils_System::redirect($config->userFrameworkBaseURL); } } $this->assign('mode', $this->_mode); $this->assign('action', $this->_action); $this->assign('fields', $this->_fields); $this->assign('fieldset', $this->_fieldset); /* if ($this->_mode & self::MODE_EDIT) { $group =& new CRM_Core_DAO_UFGroup(); $group->id = $this->_gid; if ($group->find(true)) { $this->assign('help_pre', $group->help_pre); $this->assign('help_post', $group->help_post); } }*/ // do we need inactive options ? if ($this->_action & CRM_CORE_ACTION_VIEW) { $inactiveNeeded = true; } else { $inactiveNeeded = false; } // should we restrict what we display $admin = true; if ($this->_mode == CRM_PROFILE_FORM_MODE_EDIT) { $admin = false; $session =& CRM_Core_Session::singleton(); // show all fields that are visibile: if we are a admin or the same user or in registration mode if (CRM_Utils_System::checkPermission('administer users') || $this->_id == $session->get('userID')) { $admin = true; } } require_once "CRM/Contribute/PseudoConstant.php"; // add the form elements foreach ($this->_fields as $name => $field) { // make sure that there is enough permission to expose this field if (!$admin && $field['visibility'] == 'User and User Admin Only') { unset($this->_fields[$name]); continue; } // since the CMS manages the email field, suppress the email display if in // register mode which occur within the CMS form if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER && substr($name, 0, 5) == 'email') { unset($this->_fields[$name]); continue; } $required = $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH ? false : $field['is_required']; //if ( $field['name'] === 'state_province' ) { if (substr($field['name'], 0, 14) === 'state_province') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required); } else { if ($field['name'] === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $this->addGroup($genderOptions, $field['name'], $field['title']); if ($required) { $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { if ($field['name'] === 'individual_prefix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($field['name'] === 'individual_suffix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($field['name'] === 'preferred_communication_method') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm()); } else { if ($field['name'] === 'preferred_mail_format') { $this->add('select', $name, $field['title'], CRM_Core_SelectValues::pmf()); } else { if (substr($field['name'], 0, 3) === 'is_' or substr($field['name'], 0, 7) === 'do_not_') { $this->add('checkbox', $name, $field['title'], $field['attributes'], $required); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, true, $required, $field['title'], null); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']); } else { if (substr($field['name'], 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']); CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']); CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $this->_id, $this->_mode); } else { if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required); $this->addRule($field['name'], ts('Select a valid date.'), 'qfDate'); } else { if ($field['name'] == 'payment_instrument') { $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($field['name'] == 'contribution_type') { $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { $this->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } } } } } } } if (in_array($field['name'], array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $this->addRule($field['name'], ts('Please enter a valid amount.'), 'money'); } if ($field['rule']) { if ($field['rule'] == 'email' && $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH) { continue; } else { $this->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']); } } } // if view mode pls freeze it with the done button. if ($this->_action & CRM_CORE_ACTION_VIEW) { $this->freeze(); } $this->setDefaults($defaults); }