/**
  * 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)));
 }
Exemple #2
0
 /**
  * Create communication preferences block for the contact.
  *
  * @param object $form - CRM_Core_Form (or it's subclass)
  * @return none
  *
  * @access public
  * @static
  */
 function buildCommunicationBlock(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     $privacy = array();
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']);
     $form->addGroup($privacy, 'privacy', ts('Privacy'), ' ');
     // preferred communication method
     $form->add('select', 'preferred_communication_method', ts('Prefers'), CRM_Core_SelectValues::pcm());
     $form->add('select', 'preferred_mail_format', ts('Mail Format'), CRM_Core_SelectValues::pmf());
 }
 /**
  * function to check if an error in Core( non-custom fields ) field
  *
  * @param String   $errorMessage   A string containing all the error-fields.
  *
  * @access public
  */
 function isErrorInCoreData($params, &$errorMessage)
 {
     foreach ($params as $key => $value) {
         if ($value) {
             switch ($key) {
                 case 'birth_date':
                     if (!CRM_Utils_Rule::date($value)) {
                         //return _crm_error('Birth Date');
                         CRM_Import_Parser_Contact::addToErrorMsg('Birth Date', $errorMessage);
                     }
                     break;
                 case 'gender':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::gender(true))) {
                         //return _crm_error('Invalid value for field  : Gender');
                         CRM_Import_Parser_Contact::addToErrorMsg('Gender', $errorMessage);
                     }
                     break;
                 case 'preferred_communication_method':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pcm(), CASE_LOWER))) {
                         //return _crm_error('Invalid value for field  : Preferred Communication Method');
                         CRM_Import_Parser_Contact::addToErrorMsg('Preferred Communication Method', $errorMessage);
                     }
                     break;
                 case 'preferred_mail_format':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) {
                         //return _crm_error('Invalid value for field  : Preferred Communication Method');
                         CRM_Import_Parser_Contact::addToErrorMsg('Preferred Mail Format', $errorMessage);
                     }
                     break;
                 case 'individual_prefix':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualPrefix(true))) {
                         //return _crm_error('Invalid value for field  : Individual Prefix');
                         CRM_Import_Parser_Contact::addToErrorMsg('Individual Prefix', $errorMessage);
                     }
                     break;
                 case 'individual_suffix':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualSuffix(true))) {
                         //return _crm_error('Invalid value for field  : Individual Suffix');
                         CRM_Import_Parser_Contact::addToErrorMsg('Individual Suffix', $errorMessage);
                     }
                     break;
                 case 'state_province':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['state_province']) {
                                 if (CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : State Province ');
                                     CRM_Import_Parser_Contact::addToErrorMsg('State Province', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'country':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['country']) {
                                 if (CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::countryIsoCode()) || CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : Country');
                                     CRM_Import_Parser_Contact::addToErrorMsg('Country', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_1':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_1']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : geo_code_1');
                                     CRM_Import_Parser_Contact::addToErrorMsg('geo_code_1', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_2':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_2']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : geo_code_2');
                                     CRM_Import_Parser_Contact::addToErrorMsg('geo_code_2', $errorMessage);
                                 }
                             }
                         }
                     }
             }
         }
     }
     //return true;
 }
Exemple #4
0
 /**
  * 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);
 }