Пример #1
0
 /**
  * singleton function used to manage this object
  *
  * @param string the key to permit session scope's
  *
  * @return object
  * @static
  *
  */
 static function &singleton()
 {
     if (self::$_singleton === NULL) {
         self::$_singleton = new CRM_Utils_ReCAPTCHA();
     }
     return self::$_singleton;
 }
 /**
  * Function to add the custom fields
  *
  * @param $id
  * @param $name
  * @param bool $viewOnly
  * @param null $profileContactType
  * @param null $fieldTypes
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-' && $profileContactType != 'honor') {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 if ($profileContactType) {
                     //Since we are showing honoree name separately so we are removing it from honoree profile just for display
                     $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
                     if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
                         unset($fields[$field['name']]);
                         continue;
                     }
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
                         $this->_fields[$profileContactType][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
Пример #3
0
 /**
  * Build the petition profile form.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  */
 public function buildCustom($id, $name, $viewOnly = FALSE)
 {
     if ($id) {
         $session = CRM_Core_Session::singleton();
         $this->assign("petition", $this->petition);
         //$contactID = $this->_contactId;
         $contactID = NULL;
         $this->assign('contact_id', $this->_contactId);
         $fields = NULL;
         // TODO: contactID is never set (commented above)
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         if ($fields) {
             $this->assign($name, $fields);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 // if state or country in the profile, create map
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_contactId) {
                     $addCaptcha = TRUE;
                 }
             }
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", TRUE);
             }
         }
     }
 }
Пример #4
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->add('hidden', 'gid', $this->_gid);
     switch ($this->_mode) {
         case self::MODE_CREATE:
         case self::MODE_EDIT:
         case self::MODE_REGISTER:
             CRM_Utils_Hook::buildProfile($this->_ufGroup['name']);
             break;
         case self::MODE_SEARCH:
             CRM_Utils_Hook::searchProfile($this->_ufGroup['name']);
             break;
         default:
     }
     //lets have single status message, CRM-4363
     $return = FALSE;
     $statusMessage = NULL;
     if ($this->_multiRecord & CRM_Core_Action::ADD && $this->_maxRecordLimit) {
         return;
     }
     if ($this->_multiRecord & CRM_Core_Action::DELETE) {
         if (!$this->_recordExists) {
             CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', array(1 => $this->_recordId)), ts('Record doesnot exists'), 'alert');
         } else {
             $this->assign('deleteRecord', TRUE);
         }
         return;
     }
     CRM_Core_BAO_Address::checkContactSharedAddressFields($this->_fields, $this->_id);
     // we should not allow component and mix profiles in search mode
     if ($this->_mode != self::MODE_REGISTER) {
         //check for mix profile fields (eg:  individual + other contact type)
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             if ($this->_mode & self::MODE_EDIT && $this->_isContactActivityProfile) {
                 $errors = self::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
                 if (!empty($errors)) {
                     $statusMessage = array_pop($errors);
                     $return = TRUE;
                 }
             } else {
                 $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
                 $return = TRUE;
             }
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         if ($this->_id) {
             $contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
             $contactType = $contactTypes[0];
             array_shift($contactTypes);
             $contactSubtypes = $contactTypes;
             $profileSubType = FALSE;
             if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                 $profileSubType = $profileType;
                 $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
             }
             if ($profileType != 'Contact' && !$this->_isContactActivityProfile && ($profileSubType && !empty($contactSubtypes) && !in_array($profileSubType, $contactSubtypes) || $profileType != $contactType)) {
                 $return = TRUE;
                 if (!$statusMessage) {
                     $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType));
                 }
             }
         }
         if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
             $return = TRUE;
             if (!$statusMessage) {
                 $statusMessage = ts('Profile is not configured for the selected action.');
             }
         }
     }
     //lets have single status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return FALSE;
     }
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // should we restrict what we display
     $admin = TRUE;
     if ($this->_mode == self::MODE_EDIT) {
         $admin = FALSE;
         // show all fields that are visibile:
         // if we are a admin OR the same user OR acl-user with access to the profile
         // or we have checksum access to this contact (i.e. the user without a login) - CRM-5909
         if (CRM_Core_Permission::check('administer users') || $this->_id == $this->_currentUserID || $this->_isPermissionedChecksum || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id')))) {
             $admin = TRUE;
         }
     }
     // if false, user is not logged-in.
     $anonUser = FALSE;
     if (!$this->_currentUserID) {
         $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = TRUE;
     }
     $this->assign('anonUser', $anonUser);
     $addCaptcha = array();
     $emailPresent = FALSE;
     // 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 == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
         if ($field['add_to_group_id']) {
             $addToGroupId = $field['add_to_group_id'];
         }
         //build array for captcha
         if ($field['add_captcha']) {
             $addCaptcha[$field['group_id']] = $field['add_captcha'];
         }
         if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
             $emailPresent = TRUE;
             $this->_mail = $name;
         }
     }
     // add captcha only for create mode.
     if ($this->_mode == self::MODE_CREATE) {
         // suppress captcha for logged in users only
         if ($this->_currentUserID) {
             $this->_isAddCaptcha = FALSE;
         } elseif (!$this->_isAddCaptcha && !empty($addCaptcha)) {
             $this->_isAddCaptcha = TRUE;
         }
         if ($this->_gid) {
             $dao = new CRM_Core_DAO_UFGroup();
             $dao->id = $this->_gid;
             $dao->addSelect();
             $dao->addSelect('is_update_dupe');
             if ($dao->find(TRUE)) {
                 if ($dao->is_update_dupe) {
                     $this->_isUpdateDupe = $dao->is_update_dupe;
                 }
             }
         }
     } else {
         $this->_isAddCaptcha = FALSE;
     }
     //finally add captcha to form.
     if ($this->_isAddCaptcha) {
         $captcha = CRM_Utils_ReCAPTCHA::singleton();
         $captcha->add($this);
     }
     $this->assign("isCaptcha", $this->_isAddCaptcha);
     if ($this->_mode != self::MODE_SEARCH) {
         if (isset($addToGroupId)) {
             $this->_ufGroup['add_to_group_id'] = $addToGroupId;
         }
     }
     //let's do set defaults for the profile
     $this->setDefaultsValues();
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL);
     if ($this->_mode == self::MODE_CREATE) {
         CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
     } else {
         $this->assign('showCMS', FALSE);
     }
     $this->assign('groupId', $this->_gid);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
     if ($this->_context == 'dialog') {
         $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
     }
 }
Пример #5
0
 /**
  * Function to build the petition profile form
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE)
 {
     // create state country map array to hold selectors
     $stateCountryMap = array();
     if ($id) {
         $session = CRM_Core_Session::singleton();
         $this->assign("petition", $this->petition);
         //$contactID = $this->_contactId;
         $contactID = NULL;
         $this->assign('contact_id', $this->_contactId);
         $fields = NULL;
         // TODO: contactID is never set (commented above)
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         if ($fields) {
             /*
             // unset any email-* fields since we already collect it, CRM-2888
             foreach ( array_keys( $fields ) as $fieldName ) {
                 if ( substr( $fieldName, 0, 6 ) == 'email-' ) {
                     unset( $fields[$fieldName] );
                 }
             }
             */
             $this->assign($name, $fields);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 // if state or country in the profile, create map
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_contactId) {
                     $addCaptcha = TRUE;
                 }
             }
             // initialize the state country map
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", TRUE);
             }
         }
     }
 }
Пример #6
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     // add the email address
     $this->add('text', 'email', ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'), TRUE);
     $this->addRule('email', ts("Please enter a valid email address."), 'email');
     if (!$this->_groupID) {
         // create a selector box of all public groups
         $groupTypeCondition = CRM_Contact_BAO_Group::groupTypeCondition('Mailing');
         $query = "\nSELECT   id, title, description\n  FROM   civicrm_group\n WHERE   ( saved_search_id = 0\n    OR     saved_search_id IS NULL )\n   AND   visibility != 'User and User Admin Only'\n   AND   {$groupTypeCondition}\nORDER BY title";
         $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         $rows = array();
         while ($dao->fetch()) {
             $row = array();
             $row['id'] = $dao->id;
             $row['title'] = $dao->title;
             $row['description'] = $dao->description;
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $row['id'];
             $this->addElement('checkbox', $row['checkbox'], NULL, NULL);
             $rows[] = $row;
         }
         if (empty($rows)) {
             CRM_Core_Error::fatal(ts('There are no public mailing list groups to display.'));
         }
         $this->assign('rows', $rows);
         $this->addFormRule(array('CRM_Mailing_Form_Subscribe', 'formRule'));
     }
     $addCaptcha = TRUE;
     // if recaptcha is not configured, then dont add it
     // CRM-11316 Only enable ReCAPTCHA for anonymous visitors
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     if (empty($config->recaptchaPublicKey) || empty($config->recaptchaPrivateKey) || $contactID) {
         $addCaptcha = FALSE;
     } else {
         // if this is POST request and came from a block,
         // lets add recaptcha only if already present
         // gross hack for now
         if (!empty($_POST) && !array_key_exists('recaptcha_challenge_field', $_POST)) {
             $addCaptcha = FALSE;
         }
     }
     if ($addCaptcha) {
         // add captcha
         $captcha = CRM_Utils_ReCAPTCHA::singleton();
         $captcha->add($this);
         $this->assign('isCaptcha', TRUE);
     }
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Subscribe'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
Пример #7
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $id = CRM_PCP_BAO_PCP::getSupporterProfileId($this->_pageId, $this->_component);
     if (CRM_PCP_BAO_PCP::checkEmailProfile($id)) {
         $this->assign('profileDisplay', TRUE);
     }
     $fields = NULL;
     if ($this->_contactID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
     } else {
         CRM_Core_BAO_CMSUser::buildForm($this, $id, TRUE);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = FALSE;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
             if ($field['add_captcha'] && !$this->_contactID) {
                 $addCaptcha = TRUE;
             }
         }
         if ($addCaptcha) {
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign('isCaptcha', TRUE);
         }
     }
     if ($this->_component == 'contribute') {
         $this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($this->_pageId));
     } elseif ($this->_component == 'event') {
         $this->assign('campaignName', CRM_Event_PseudoConstant::event($this->_pageId));
     }
     if ($this->_single) {
         $button = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     } else {
         $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '         ', 'isDefault' => TRUE);
     }
     $this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
     $this->addButtons($button);
 }
 /**
  * Function to build the petition profile form
  *
  * @return None
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE)
 {
     if ($id) {
         $session = CRM_Core_Session::singleton();
         $this->assign("petition", $this->petition);
         //$contactID = $this->_contactId;
         $contactID = NULL;
         $this->assign('contact_id', $this->_contactId);
         $fields = NULL;
         // TODO: contactID is never set (commented above)
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         if ($fields) {
             /*
             // unset any email-* fields since we already collect it, CRM-2888
             foreach ( array_keys( $fields ) as $fieldName ) {
                 if ( substr( $fieldName, 0, 6 ) == 'email-' ) {
                     unset( $fields[$fieldName] );
                 }
             }
             */
             $this->assign($name, $fields);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
                 if ($field['add_captcha']) {
                     $addCaptcha = TRUE;
                 }
             }
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", TRUE);
             }
         }
     }
 }
Пример #9
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     //lets have single status message, CRM-4363
     $return = false;
     $statusMessage = null;
     //we should not allow component and mix profiles in search mode
     if ($this->_mode != self::MODE_REGISTER) {
         //check for mix profile fields (eg:  individual + other contact type)
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         if ($this->_id) {
             list($contactType, $contactSubType) = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
             if ($profileType != 'Contact' && $contactType != $profileType && !CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                 $return = true;
                 if (!$statusMessage) {
                     $statusMessage = ts('This profile is not configured for "%1" contact type.', array(1 => $contactType));
                 }
             }
             if ($contactSubType && CRM_Contact_BAO_ContactType::isaSubType($profileType) && $profileType != $contactSubType) {
                 $return = true;
                 if (!$statusMessage) {
                     $statusMessage = ts('This profile is not configured for "%1" contact subtype.', array(1 => $contactSubType));
                 }
             }
         }
         if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
             $return = true;
             if (!$statusMessage) {
                 $statusMessage = ts('Profile is not configured for the selected action.');
             }
         }
     }
     //lets have sigle status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return false;
     }
     $sBlocks = array();
     $hBlocks = array();
     $config =& CRM_Core_Config::singleton();
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign_by_ref('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // do we need inactive options ?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $inactiveNeeded = true;
     } else {
         $inactiveNeeded = false;
     }
     $session =& CRM_Core_Session::singleton();
     // should we restrict what we display
     $admin = true;
     if ($this->_mode == self::MODE_EDIT) {
         $admin = false;
         // show all fields that are visibile: if we are a admin or the same user or in registration mode
         if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID')) {
             $admin = true;
         }
     }
     $userID = $session->get('userID');
     $anonUser = false;
     // if false, user is not logged-in.
     if (!$userID) {
         require_once 'CRM/Core/BAO/LocationType.php';
         $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = true;
         $this->assign('anonUser', true);
     }
     $addCaptcha = array();
     $emailPresent = false;
     // cache the state country fields. based on the results, we could use our javascript solution
     // in create or register mode
     $stateCountryMap = array();
     // 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' || CRM_Utils_Array::value('is_view', $field)) {
             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 == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
         if ($prefixName == 'state_province' || $prefixName == 'country') {
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$prefixName] = $name;
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
         if ($field['add_to_group_id']) {
             $addToGroupId = $field['add_to_group_id'];
         }
         //build array for captcha
         if ($field['add_captcha']) {
             $addCaptcha[$field['group_id']] = $field['add_captcha'];
         }
         if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
             $emailPresent = true;
             $this->_mail = $name;
         }
     }
     $setCaptcha = false;
     // do this only for CiviCRM created forms
     if ($this->_mode == self::MODE_CREATE) {
         if (!empty($addCaptcha)) {
             $setCaptcha = true;
         }
         if ($this->_gid) {
             $dao = new CRM_Core_DAO_UFGroup();
             $dao->id = $this->_gid;
             $dao->addSelect();
             $dao->addSelect('add_captcha', 'is_update_dupe');
             if ($dao->find(true)) {
                 if ($dao->add_captcha) {
                     $setCaptcha = true;
                 }
                 if ($dao->is_update_dupe) {
                     $this->_isUpdateDupe = true;
                 }
             }
         }
         if ($setCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
     if ($this->_mode != self::MODE_SEARCH) {
         if (isset($addToGroupId)) {
             $this->add('hidden', "group[{$addToGroupId}]", 1);
             $this->_addToGroupID = $addToGroupId;
         }
     }
     // also do state country js
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, null);
     if ($this->_mode == self::MODE_CREATE) {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
     } else {
         $this->assign('showCMS', false);
     }
     $this->assign('groupId', $this->_gid);
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
     if ($this->_context == 'dialog') {
         $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
     }
 }
Пример #10
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Contribute/BAO/PCP.php';
     $id = CRM_Contribute_BAO_PCP::getSupporterProfileId($this->_pageId);
     if (CRM_Contribute_BAO_PCP::checkEmailProfile($id)) {
         $this->assign('profileDisplay', true);
     }
     $fields = null;
     require_once "CRM/Core/BAO/UFGroup.php";
     if ($this->_contactID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     } else {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $id, true);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = false;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             require_once "CRM/Core/BAO/UFGroup.php";
             require_once "CRM/Profile/Form.php";
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             if ($field['add_captcha']) {
                 $addCaptcha = true;
             }
         }
         if ($addCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
     require_once "CRM/Contribute/PseudoConstant.php";
     $this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($this->_pageId));
     if ($this->_single) {
         $button = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')));
     } else {
         $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '         ', 'isDefault' => true);
     }
     $this->addFormRule(array('CRM_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     $this->addButtons($button);
 }
Пример #11
0
 /**  
  * Function to add the custom fields
  *  
  * @return None  
  * @access public  
  */
 function buildCustom($id, $name, $viewOnly = false)
 {
     $stateCountryMap = array();
     if ($id) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         require_once 'CRM/Profile/Form.php';
         $session = CRM_Core_Session::singleton();
         $contactID = $this->_userID;
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'contribution_type' => 1);
         $fields = null;
         if ($contactID) {
             require_once "CRM/Core/BAO/UFGroup.php";
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
         }
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus("Some of the profile fields cannot be configured for this page.");
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             $this->assign($name, $fields);
             $addCaptcha = false;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, true);
                 $this->_fields[$key] = $field;
                 if ($field['add_captcha']) {
                     $addCaptcha = true;
                 }
             }
             require_once 'CRM/Core/BAO/Address.php';
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 require_once 'CRM/Utils/ReCAPTCHA.php';
                 $captcha =& CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", true);
             }
         }
     }
 }
Пример #12
0
 /**  
  * Function to add the custom fields
  *  
  * @return None  
  * @access public  
  */
 function buildCustom($id, $name, $viewOnly = false)
 {
     $stateCountryMap = array();
     if ($id) {
         $button = substr($this->controller->getButtonName(), -4);
         require_once 'CRM/Core/BAO/UFGroup.php';
         require_once 'CRM/Profile/Form.php';
         $session =& CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         // we don't allow conflicting fields to be
         // configured via profile
         $fieldsToIgnore = array('participant_fee_amount' => 1, 'participant_fee_level' => 1);
         $fields = null;
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
         }
         if (is_array($fields)) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
         }
         if (array_intersect_key($fields, $fieldsToIgnore)) {
             $fields = array_diff_key($fields, $fieldsToIgnore);
             CRM_Core_Session::setStatus("Some of the profile fields cannot be configured for this page.");
         }
         $addCaptcha = false;
         $this->assign($name, $fields);
         if (is_array($fields)) {
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File') {
                     // ignore file upload fields
                     continue;
                 }
                 //make the field optional if primary participant
                 //have been skip the additional participant.
                 if ($button == 'skip') {
                     $field['is_required'] = false;
                 } else {
                     if ($field['add_captcha']) {
                         // only add captcha for first page
                         $addCaptcha = true;
                     }
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, true);
                 $this->_fields[$key] = $field;
             }
         }
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
         if ($addCaptcha && !$viewOnly) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
 }
 /**
  * Function to add the custom fields
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     $stateCountryMap = array();
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                     if ($prefixName == "state_province") {
                         if ($profileContactType == 'onbehalf') {
                             //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
                             //as already done during Contribution registration via onBehalf's quickForm
                             $field['is_required'] = FALSE;
                         } else {
                             if (count($this->_submitValues)) {
                                 $locationTypeId = $field['location_type_id'];
                                 if (array_key_exists("country-{$locationTypeId}", $fields) && array_key_exists("state_province-{$locationTypeId}", $fields) && !empty($this->_submitValues["country-{$locationTypeId}"])) {
                                     $field['is_required'] = CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$locationTypeId}");
                                 }
                             }
                         }
                     }
                 }
                 if ($profileContactType) {
                     //Since we are showing honoree name separately so we are removing it from honoree profile just for display
                     $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
                     if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
                         unset($fields[$field['name']]);
                         continue;
                     }
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
                         $this->_fields[$profileContactType][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
Пример #14
0
 /**
  * Function to add the custom fields
  *
  * @return None
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $onBehalf = FALSE, $fieldTypes = NULL)
 {
     $stateCountryMap = array();
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 if ($onBehalf) {
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                         $this->_fields['onbehalf'][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
Пример #15
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $profileID = CRM_Core_DAO::getFieldValue('CRM_Auction_DAO_Auction', $this->_aid, 'donor_profile_id');
     if (!$profileID) {
         CRM_Core_Error::fatal('Profile not configured for this auction.');
     }
     require_once 'CRM/Auction/BAO/Item.php';
     if (CRM_Auction_BAO_Item::isEmailInProfile($profileID)) {
         $this->assign('profileDisplay', TRUE);
     }
     $fields = NULL;
     require_once "CRM/Core/BAO/UFGroup.php";
     if ($this->_donorID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($profileID, $this->_donorID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_Auction_Form_ItemAccount', 'formRule'), $this);
     } else {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE);
         $fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = FALSE;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             require_once "CRM/Core/BAO/UFGroup.php";
             require_once "CRM/Profile/Form.php";
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             if ($field['add_captcha']) {
                 $addCaptcha = TRUE;
             }
         }
         if ($addCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", TRUE);
         }
     }
     $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '         ', 'isDefault' => TRUE);
     $this->addButtons($button);
 }
Пример #16
0
 /**
  * Add the custom fields.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  */
 public function buildCustom($id, $name, $viewOnly = FALSE)
 {
     if ($id) {
         $button = substr($this->controller->getButtonName(), -4);
         $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         // we don't allow conflicting fields to be
         // configured via profile
         $fieldsToIgnore = array('participant_fee_amount' => 1, 'participant_fee_level' => 1);
         if ($contactID) {
             //FIX CRM-9653
             if (is_array($id)) {
                 $fields = array();
                 foreach ($id as $profileID) {
                     $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
                     $fields = array_merge($fields, $field);
                 }
             } else {
                 if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                     $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
                 }
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
         }
         if (array_intersect_key($fields, $fieldsToIgnore)) {
             $fields = array_diff_key($fields, $fieldsToIgnore);
             CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
         }
         $addCaptcha = FALSE;
         if (!empty($this->_fields)) {
             $fields = @array_diff_assoc($fields, $this->_fields);
         }
         if (empty($this->_params[0]['additional_participants']) && is_null($cid)) {
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
         }
         $this->assign($name, $fields);
         if (is_array($fields)) {
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 //make the field optional if primary participant
                 //have been skip the additional participant.
                 if ($button == 'skip') {
                     $field['is_required'] = FALSE;
                 } elseif ($field['add_captcha'] && !$contactID) {
                     // only add captcha for first page
                     $addCaptcha = TRUE;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
             }
         }
         if ($addCaptcha && !$viewOnly) {
             $captcha = CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign('isCaptcha', TRUE);
         }
     }
 }
Пример #17
0
 /**
  * Add the custom fields.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  * @param null $profileContactType
  * @param array $fieldTypes
  */
 public function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-' && !in_array($profileContactType, array('honor', 'onbehalf'))) {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             //remove common fields only if profile is not configured for onbehalf/honor
             if (!in_array($profileContactType, array('honor', 'onbehalf'))) {
                 $fields = array_diff_assoc($fields, $this->_fields);
             }
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             // fetch file preview when not submitted yet, like in online contribution Confirm and ThankYou page
             $viewOnlyFileValues = empty($profileContactType) ? array() : array($profileContactType => array());
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     //retrieve file value from submitted values on basis of $profileContactType
                     $fileValue = CRM_Utils_Array::value($key, $this->_params);
                     if (!empty($profileContactType) && !empty($this->_params[$profileContactType])) {
                         $fileValue = CRM_Utils_Array::value($key, $this->_params[$profileContactType]);
                     }
                     if ($fileValue) {
                         $path = CRM_Utils_Array::value('name', $fileValue);
                         $fileType = CRM_Utils_Array::value('type', $fileValue);
                         $fileValue = CRM_Utils_File::getFileURL($path, $fileType);
                     }
                     // format custom file value fetched from submitted value
                     if ($profileContactType) {
                         $viewOnlyFileValues[$profileContactType][$key] = $fileValue;
                     } else {
                         $viewOnlyFileValues[$key] = $fileValue;
                     }
                 }
                 if ($profileContactType) {
                     //Since we are showing honoree name separately so we are removing it from honoree profile just for display
                     if ($profileContactType == 'honor') {
                         $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
                         if (in_array($field['name'], $honoreeNamefields)) {
                             unset($fields[$field['name']]);
                             continue;
                         }
                     }
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
                         $this->_fields[$profileContactType][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             if ($profileContactType && count($viewOnlyFileValues[$profileContactType])) {
                 $this->assign('viewOnlyPrefixFileValues', $viewOnlyFileValues);
             } elseif (count($viewOnlyFileValues)) {
                 $this->assign('viewOnlyFileValues', $viewOnlyFileValues);
             }
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }