public function buildQuickForm()
 {
     // CRM_Event_Form_Task_Batch::buildQuickForm() gets ufGroupId
     // from the form, so set it here to the id of the reserved profile
     $dao = new CRM_Core_DAO_UFGroup();
     $dao->name = 'participant_status';
     $dao->find(TRUE);
     $this->set('ufGroupId', $dao->id);
     $statuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
     asort($statuses, SORT_STRING);
     $this->add('select', 'status_change', ts('Change All Statuses'), array('' => ts('- select status -')) + $statuses);
     $this->assign('context', 'statusChange');
     # CRM-4321: display info on users being notified if any of the below statuses is enabled
     parent::assignToTemplate();
     parent::buildQuickForm();
 }
 /**
  * Build form for honoree contact / on behalf of organization.
  *
  * @param CRM_Core_Form $form
  *
  */
 public static function buildQuickForm(&$form)
 {
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->id = $form->_honoreeProfileId;
     if (!$ufGroup->find(TRUE)) {
         CRM_Core_Error::fatal(ts('Chosen honoree profile for this contribution is disabled'));
     }
     $prefix = 'honor';
     $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($form->_honoreeProfileId, FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
     $form->addElement('hidden', 'honoree_profile_id', $form->_honoreeProfileId);
     $form->assign('honoreeProfileFields', $honoreeProfileFields);
     // add the form elements
     foreach ($honoreeProfileFields as $name => $field) {
         // If soft credit type is not chosen then make omit requiredness from honoree profile fields
         if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
             $field['is_required'] = FALSE;
         }
         CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, $prefix);
     }
 }
Beispiel #3
0
 function buildQuickForm()
 {
     // CRM_Event_Form_Task_Batch::buildQuickForm() gets ufGroupId
     // from the form, so set it here to the id of the reserved profile
     require_once 'CRM/Core/DAO/UFGroup.php';
     $dao = new CRM_Core_DAO_UFGroup();
     $dao->name = 'participant_status';
     $dao->find(true);
     $this->set('ufGroupId', $dao->id);
     require_once 'CRM/Event/PseudoConstant.php';
     $statuses =& CRM_Event_PseudoConstant::participantStatus();
     asort($statuses, SORT_STRING);
     $this->add('select', 'status_change', ts('Change All Statuses'), array('' => ts('- select status -')) + $statuses, null, array('onchange' => "if (this.value) setStatusesTo(this.value);"));
     $this->assign('context', 'statusChange');
     # CRM-4321: display info on users being notified if any of the below statuses is enabled
     require_once 'CRM/Event/PseudoConstant.php';
     $notifyingStatuses = array(ts('Pending from waitlist'), ts('Pending from approval'), ts('Expired'), ts('Cancelled'));
     $notifyingStatuses = array_intersect($notifyingStatuses, CRM_Event_PseudoConstant::participantStatus());
     $this->assign('notifyingStatuses', implode(', ', $notifyingStatuses));
     parent::buildQuickForm();
 }
Beispiel #4
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         CRM_Utils_System::setTitle(ts('Title and Settings') . " ({$title})");
         $ufJoinParams = array('module' => 'OnBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $onBehalfIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         if ($onBehalfIDs) {
             // get the first one only
             $defaults['onbehalf_profile_id'] = $onBehalfIDs[0];
         }
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $this->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id;
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE);
             $defaults = array_merge($defaults, $jsonData);
             $defaults['honor_block_is_active'] = $ufJoinDAO->is_active;
         } else {
             $ufGroupDAO = new CRM_Core_DAO_UFGroup();
             $ufGroupDAO->name = 'honoree_individual';
             if ($ufGroupDAO->find(TRUE)) {
                 $defaults['honoree_profile'] = $ufGroupDAO->id;
             }
             $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
         }
     } else {
         CRM_Utils_System::setTitle(ts('Title and Settings'));
         $ufGroupDAO = new CRM_Core_DAO_UFGroup();
         $ufGroupDAO->name = 'honoree_individual';
         if ($ufGroupDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufGroupDAO->id;
         }
         $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
     }
     return $defaults;
 }
 /**
  * run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 function run()
 {
     $this->preProcess();
     $this->assign('recentlyViewed', FALSE);
     $this->assign('ufGroupName', 'unknown');
     // override later (if possible)
     if ($this->_gid) {
         $ufgroupDAO = new CRM_Core_DAO_UFGroup();
         $ufgroupDAO->id = $this->_gid;
         if (!$ufgroupDAO->find(TRUE)) {
             CRM_Core_Error::fatal();
         }
     }
     if ($this->_gid) {
         // set the title of the page
         if ($ufgroupDAO->title) {
             CRM_Utils_System::setTitle($ufgroupDAO->title);
         }
         if ($ufgroupDAO->name) {
             $this->assign('ufGroupName', $ufgroupDAO->name);
         }
     }
     $this->assign('isReset', TRUE);
     $formController = new CRM_Core_Controller_Simple('CRM_Profile_Form_Search', ts('Search Profile'), CRM_Core_Action::ADD);
     $formController->setEmbedded(TRUE);
     $formController->set('gid', $this->_gid);
     $formController->process();
     $searchError = FALSE;
     // check if there is a POST
     if (!empty($_POST)) {
         if ($formController->validate() !== TRUE) {
             $searchError = TRUE;
         }
     }
     // also get the search tpl name
     $this->assign('searchTPL', $formController->getHookedTemplateFileName());
     $this->assign('search', $this->_search);
     // search if search returned a form error?
     if ((empty($_GET['reset']) || !empty($_GET['force'])) && !$searchError) {
         $this->assign('isReset', FALSE);
         $gidString = $this->_gid;
         if (empty($this->_profileIds)) {
             $gids = $this->_gid;
         } else {
             $gids = $this->_profileIds;
             $gidString = implode(',', $this->_profileIds);
         }
         $map = 0;
         $linkToUF = 0;
         $editLink = FALSE;
         if ($this->_gid) {
             $map = $ufgroupDAO->is_map;
             $linkToUF = $ufgroupDAO->is_uf_link;
             $editLink = $ufgroupDAO->is_edit_link;
         }
         if ($map) {
             $this->assign('mapURL', CRM_Utils_System::url('civicrm/profile/map', "map=1&gid={$gidString}&reset=1"));
         }
         if (!empty($this->_params['group'])) {
             foreach ($this->_params['group'] as $key => $val) {
                 if (!$val) {
                     unset($this->_params['group'][$key]);
                 }
             }
         }
         // the selector will override this if the user does have
         // edit permissions as determined by the mask, CRM-4341
         // do not allow edit for anon users in joomla frontend, CRM-4668
         $config = CRM_Core_Config::singleton();
         if (!CRM_Core_Permission::check('access CiviCRM') || $config->userFrameworkFrontend == 1) {
             $editLink = FALSE;
         }
         $selector = new CRM_Profile_Selector_Listings($this->_params, $this->_customFields, $gids, $map, $editLink, $linkToUF);
         $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TEMPLATE);
         $controller->setEmbedded(TRUE);
         $controller->run();
     }
     //CRM-6862 -run form cotroller after
     //selector, since it erase $_POST
     $formController->run();
     return parent::run();
 }
Beispiel #6
0
 /**
  * adds $value['foo_display'] for each $value['foo'] enum from civicrm_uf_group
  *
  * @param array $values (reference)  the array up for enhancing
  * @return void
  */
 function addDisplayEnums(&$values)
 {
     $enumFields =& CRM_Core_DAO_UFGroup::getEnums();
     foreach ($enumFields as $enum) {
         if (isset($values[$enum])) {
             $values[$enum . '_display'] = CRM_Core_DAO_UFGroup::tsEnum($enum, $values[$enum]);
         }
     }
 }
Beispiel #7
0
 /**
  * Migrate honoree information to uf_join.module_data as honoree columns (text and title) will be dropped
  * on DB upgrade
  *
  * @param CRM_Queue_TaskContext $ctx
  *
  * @return bool
  *   TRUE for success
  */
 public static function migrateHonoreeInfo(CRM_Queue_TaskContext $ctx)
 {
     $query = "ALTER TABLE `civicrm_uf_join`\n    ADD COLUMN `module_data` longtext COMMENT 'Json serialized array of data used by the ufjoin.module'";
     CRM_Core_DAO::executeQuery($query);
     $honorTypes = array_keys(CRM_Core_OptionGroup::values('honor_type'));
     $ufGroupDAO = new CRM_Core_DAO_UFGroup();
     $ufGroupDAO->name = 'new_individual';
     $ufGroupDAO->find(TRUE);
     $query = "SELECT * FROM civicrm_contribution_page";
     $dao = CRM_Core_DAO::executeQuery($query);
     if ($dao->N) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         while ($dao->fetch()) {
             $honorParams = array('soft_credit' => array('soft_credit_types' => $honorTypes));
             if ($domain->locales) {
                 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
                 foreach ($locales as $locale) {
                     $honor_block_title = "honor_block_title_{$locale}";
                     $honor_block_text = "honor_block_text_{$locale}";
                     $honorParams['soft_credit'] += array($locale => array('honor_block_title' => $dao->{$honor_block_title}, 'honor_block_text' => $dao->{$honor_block_text}));
                 }
             } else {
                 $honorParams['soft_credit'] += array('default' => array('honor_block_title' => $dao->honor_block_title, 'honor_block_text' => $dao->honor_block_text));
             }
             $ufJoinParam = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'is_active' => $dao->honor_block_is_active, 'entity_id' => $dao->id, 'uf_group_id' => $ufGroupDAO->id, 'module_data' => json_encode($honorParams));
             CRM_Core_BAO_UFJoin::create($ufJoinParam);
         }
     }
     return TRUE;
 }
Beispiel #8
0
 /** 
  * pre processing work done here. 
  * 
  * gets session variables for table name, id of entity in table, type of entity and stores them. 
  * 
  * @param  
  * @return void 
  * 
  * @access public 
  */
 function preProcess()
 {
     require_once 'CRM/Core/BAO/UFGroup.php';
     require_once "CRM/Core/BAO/UFField.php";
     $this->_id = $this->get('id');
     $this->_gid = $this->get('gid');
     $this->_grid = CRM_Utils_Request::retrieve('grid', 'Integer', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
     if (!$this->_gid) {
         $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, false, 0, 'GET');
     }
     //get values for captch and dupe update.
     if ($this->_gid) {
         $dao = new CRM_Core_DAO_UFGroup();
         $dao->id = $this->_gid;
         if ($dao->find(true)) {
             $this->_isUpdateDupe = $dao->is_update_dupe;
             $this->_isAddCaptcha = $dao->add_captcha;
         }
         $dao->free();
     }
     // if we dont have a gid use the default, else just use that specific gid
     if (($this->_mode == self::MODE_REGISTER || $this->_mode == self::MODE_CREATE) && !$this->_gid) {
         $this->_ctype = CRM_Utils_Request::retrieve('ctype', 'String', $this, false, 'Individual', 'REQUEST');
         $this->_fields = CRM_Core_BAO_UFGroup::getRegistrationFields($this->_action, $this->_mode, $this->_ctype);
     } else {
         if ($this->_mode == self::MODE_SEARCH) {
             $this->_fields = CRM_Core_BAO_UFGroup::getListingFields($this->_action, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $this->_gid, true, null, $this->_skipPermission, CRM_Core_Permission::SEARCH);
         } else {
             $this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_gid, false, null, null, null, false, null, $this->_skipPermission, null, $this->_action == CRM_Core_Action::ADD ? CRM_Core_Permission::CREATE : CRM_Core_Permission::EDIT);
             ///is profile double-opt process configurablem, key
             ///should be present in civicrm.settting.php file
             $config =& CRM_Core_Config::singleton();
             if ($config->profileDoubleOptIn && CRM_Utils_Array::value('group', $this->_fields)) {
                 $emailField = false;
                 foreach ($this->_fields as $name => $values) {
                     if (substr($name, 0, 6) == 'email-') {
                         $emailField = true;
                     }
                 }
                 if (!$emailField) {
                     $session =& CRM_Core_Session::singleton();
                     $status = ts("Email field should be included in profile if you want to use Group(s) when Profile double-opt in process is enabled.");
                     $session->setStatus($status);
                 }
             }
         }
     }
     if (!is_array($this->_fields)) {
         $session =& CRM_Core_Session::singleton();
         CRM_Core_Session::setStatus(ts('This feature is not currently available.'));
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm', 'reset=1'));
     }
     if ($this->_mode != self::MODE_SEARCH) {
         CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
         $this->setDefaults($defaults);
     }
     $this->setDefaultsValues();
 }
 /**
  * Create honor-contact method
  */
 public function testcreateAndGetHonorContact()
 {
     $firstName = 'John_' . substr(sha1(rand()), 0, 7);
     $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
     $email = "{$firstName}.{$lastName}@example.com";
     //Get profile id of name honoree_individual used to create profileContact
     $honoreeProfileId = NULL;
     $ufGroupDAO = new CRM_Core_DAO_UFGroup();
     $ufGroupDAO->name = 'honoree_individual';
     if ($ufGroupDAO->find(TRUE)) {
         $honoreeProfileId = $ufGroupDAO->id;
     }
     $params = array('prefix_id' => 3, 'first_name' => $firstName, 'last_name' => $lastName, 'email-1' => $email);
     $softParam = array('soft_credit_type_id' => 1);
     $honoreeContactId = CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray, NULL, NULL, $honoreeProfileId);
     $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $honoreeContactId, 'first_name', 'id', $firstName, 'Database check for created honor contact record.');
     //create contribution on behalf of honary.
     $contactId = Contact::createIndividual();
     $softParam['contact_id'] = $honoreeContactId;
     $ids = array('contribution' => NULL);
     $param = array('contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 4, 'contribution_status_id' => 1, 'receive_date' => date('Ymd'), 'total_amount' => 66);
     $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids);
     $id = $contribution->id;
     $softParam['contribution_id'] = $id;
     $softParam['currency'] = $contribution->currency;
     $softParam['amount'] = $contribution->total_amount;
     //Create Soft Contribution for honoree contact
     CRM_Contribute_BAO_ContributionSoft::add($softParam);
     $this->assertDBCompareValue('CRM_Contribute_DAO_ContributionSoft', $id, 'contact_id', 'contribution_id', $honoreeContactId, 'Check DB for honor contact of the contribution');
     //get honorary information
     $getHonorContact = CRM_Contribute_BAO_Contribution::getHonorContacts($honoreeContactId);
     $this->assertEquals(array($id => array('honor_type' => 'In Honor of', 'honorId' => $id, 'display_name' => 'John Doe', 'type' => 'Event Fee', 'type_id' => '4', 'amount' => '$ 66.00', 'source' => NULL, 'receive_date' => date('Y-m-d 00:00:00'), 'contribution_status' => 'Completed')), $getHonorContact);
     $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $honoreeContactId, 'first_name', 'id', $firstName, 'Database check for created honor contact record.');
     //get annual contribution information
     $annual = CRM_Contribute_BAO_Contribution::annual($contactId);
     $config = CRM_Core_Config::singleton();
     $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
     $this->assertDBCompareValue('CRM_Contribute_DAO_Contribution', $id, 'total_amount', 'id', ltrim($annual[2], $currencySymbol), 'Check DB for total amount of the contribution');
     //Delete honor contact
     Contact::delete($honoreeContactId);
     //Delete Contribution record
     $this->contributionDelete($contribution->id);
     //Delete contributor contact
     Contact::delete($contactId);
 }
Beispiel #10
0
 /**
  * Get the profile type (eg: individual/organization/household)
  *
  * @param int $ufGroupId
  *   Uf group id.
  * @param bool $returnMixType
  *   This is true, then field type of mix profile field is returned.
  * @param bool $onlyPure
  *   True if only pure profiles are required.
  *
  * @param bool $skipComponentType
  *
  * @return string
  *   profile group_type
  *
  */
 public static function getProfileType($ufGroupId, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE)
 {
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->id = $ufGroupId;
     $ufGroup->is_active = 1;
     $ufGroup->find(TRUE);
     return self::calculateProfileType($ufGroup->group_type, $returnMixType, $onlyPure, $skipComponentType);
 }
Beispiel #11
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     // add the hidden field to redirect the postProcess from
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->id = $this->_gid;
     if (!$ufGroup->find(TRUE)) {
         CRM_Core_Error::fatal();
     }
     // set the title
     if ($this->_multiRecord && $this->_customGroupTitle) {
         $groupTitle = $this->_multiRecord & CRM_Core_Action::UPDATE ? 'Edit ' . $this->_customGroupTitle . ' Record' : $this->_customGroupTitle;
     } else {
         $groupTitle = $ufGroup->title;
     }
     CRM_Utils_System::setTitle($groupTitle);
     $this->assign('recentlyViewed', FALSE);
     if ($this->_context != 'dialog') {
         $this->_postURL = CRM_Utils_Array::value('postURL', $_POST);
         $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST);
         $gidString = $this->_gid;
         if (!empty($this->_profileIds)) {
             $gidString = implode(',', $this->_profileIds);
         }
         if (!$this->_postURL) {
             $this->_postURL = $ufGroup->post_URL;
         }
         if (!$this->_postURL) {
             if ($this->_context == 'Search') {
                 $this->_postURL = CRM_Utils_System::url('civicrm/contact/search');
             } elseif ($this->_id && $this->_gid) {
                 $urlParams = "reset=1&id={$this->_id}&gid={$gidString}";
                 if ($this->_isContactActivityProfile && $this->_activityId) {
                     $urlParams .= "&aid={$this->_activityId}";
                 }
                 // get checksum if present
                 if ($this->get('cs')) {
                     $urlParams .= "&cs=" . $this->get('cs');
                 }
                 $this->_postURL = CRM_Utils_System::url('civicrm/profile/view', $urlParams);
             }
         }
         if (!$this->_cancelURL) {
             if ($ufGroup->cancel_URL) {
                 $this->_cancelURL = $ufGroup->cancel_URL;
             } else {
                 $this->_cancelURL = CRM_Utils_System::url('civicrm/profile', "reset=1&gid={$gidString}");
             }
         }
         if ($this->_multiRecordProfile) {
             $urlParams = "reset=1&id={$this->_id}&gid={$gidString}";
             // get checksum if present
             if ($this->get('cs')) {
                 $urlParams .= "&cs=" . $this->get('cs');
             }
             $this->_postURL = CRM_Utils_System::url('civicrm/profile/edit', $urlParams);
             $this->_cancelURL = CRM_Utils_System::url('civicrm/profile/edit', $urlParams);
             //passing the post url to template so the popup form does
             //proper redirection and proccess form errors if any
             if (!isset($this->_onPopupClose) || $this->_onPopupClose == 'redirectToProfile') {
                 $popupRedirect = CRM_Utils_System::url('civicrm/profile/edit', $urlParams, FALSE, NULL, FALSE);
             } elseif ($this->_onPopupClose == 'redirectToTab') {
                 $popupRedirect = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_id}&selectedChild=custom_{$this->_customGroupId}", FALSE, NULL, FALSE);
             }
             $this->assign('urlParams', $urlParams);
             $this->assign('postUrl', $popupRedirect);
         }
         // we do this gross hack since qf also does entity replacement
         $this->_postURL = str_replace('&', '&', $this->_postURL);
         $this->_cancelURL = str_replace('&', '&', $this->_cancelURL);
         $this->addElement('hidden', 'postURL', $this->_postURL);
         if ($this->_cancelURL) {
             $this->addElement('hidden', 'cancelURL', $this->_cancelURL);
         }
         // also retain error URL if set
         $this->_errorURL = CRM_Utils_Array::value('errorURL', $_POST);
         if ($this->_errorURL) {
             // we do this gross hack since qf also does entity replacement
             $this->_errorURL = str_replace('&', '&', $this->_errorURL);
             $this->addElement('hidden', 'errorURL', $this->_errorURL);
         }
         // replace the session stack in case user cancels (and we dont go into postProcess)
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($this->_postURL);
     }
     parent::buildQuickForm();
     if ($this->_multiRecord & CRM_Core_Action::DELETE && $this->_recordExists) {
         $this->_deleteButtonName = $this->getButtonName('upload', 'delete');
         $this->addElement('submit', $this->_deleteButtonName, ts('Delete'));
         $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'), 'isDefault' => TRUE);
         $this->addButtons($buttons);
         return;
     }
     //get the value from session, this is set if there is any file
     //upload field
     $uploadNames = $this->get('uploadNames');
     if (!empty($uploadNames)) {
         $buttonName = 'upload';
     } else {
         $buttonName = 'next';
     }
     $buttons[] = array('type' => $buttonName, 'name' => ts('Save'), 'isDefault' => TRUE);
     if ($this->_context != 'dialog') {
         $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'), 'isDefault' => TRUE);
     }
     $this->addButtons($buttons);
     $this->addFormRule(array('CRM_Profile_Form', 'formRule'), $this);
 }
Beispiel #12
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     // add the hidden field to redirect the postProcess from
     require_once 'CRM/UF/Form/Group.php';
     require_once 'CRM/Core/DAO/UFGroup.php';
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->id = $this->_gid;
     if (!$ufGroup->find(true)) {
         CRM_Core_Error::fatal();
     }
     // set the title
     CRM_Utils_System::setTitle($ufGroup->title);
     $this->assign('recentlyViewed', false);
     if ($this->_context != 'dialog') {
         $this->_postURL = CRM_Utils_Array::value('postURL', $_POST);
         $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST);
         $gidString = $this->_gid;
         if (!empty($this->_profileIds)) {
             $gidString = implode(',', $this->_profileIds);
         }
         if (!$this->_postURL) {
             $this->_postURL = $ufGroup->post_URL;
         }
         if (!$this->_postURL) {
             if ($this->_context == 'Search') {
                 $this->_postURL = CRM_Utils_System::url('civicrm/contact/search');
             } elseif ($this->_id && $this->_gid) {
                 $this->_postURL = CRM_Utils_System::url('civicrm/profile/view', "reset=1&id={$this->_id}&gid={$gidString}");
             }
         }
         if (!$this->_cancelURL) {
             if ($ufGroup->cancel_URL) {
                 $this->_cancelURL = $ufGroup->cancel_URL;
             } else {
                 $this->_cancelURL = CRM_Utils_System::url('civicrm/profile', "reset=1&gid={$gidString}");
             }
         }
         // we do this gross hack since qf also does entity replacement
         $this->_postURL = str_replace('&', '&', $this->_postURL);
         $this->_cancelURL = str_replace('&', '&', $this->_cancelURL);
         $this->addElement('hidden', 'postURL', $this->_postURL);
         if ($this->_cancelURL) {
             $this->addElement('hidden', 'cancelURL', $this->_cancelURL);
         }
         // also retain error URL if set
         $this->_errorURL = CRM_Utils_Array::value('errorURL', $_POST);
         if ($this->_errorURL) {
             // we do this gross hack since qf also does entity replacement
             $this->_errorURL = str_replace('&', '&', $this->_errorURL);
             $this->addElement('hidden', 'errorURL', $this->_errorURL);
         }
         // replace the session stack in case user cancels (and we dont go into postProcess)
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($this->_postURL);
     }
     parent::buildQuickForm();
     //get the value from session, this is set if there is any file
     //upload field
     $uploadNames = $this->get('uploadNames');
     if (!empty($uploadNames)) {
         $buttonName = 'upload';
     } else {
         $buttonName = 'next';
     }
     $buttons[] = array('type' => $buttonName, 'name' => ts('Save'), 'isDefault' => true);
     if ($this->_context != 'dialog') {
         $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'), 'isDefault' => true);
     }
     $this->addButtons($buttons);
     $this->addFormRule(array('CRM_Profile_Form', 'formRule'), $this);
 }
 /**
  * function to get the profile type (eg: individual/organization/household)
  *
  * @param int      $ufGroupId     uf group id
  * @param boolean  $returnMixType this is true, then field type of  mix profile field is returned
  * @param boolean  $onlyPure      true if only pure profiles are required
  *
  * @return  profile group_type
  * @acess public
  * @static
  */
 static function getProfileType($ufGroupId, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE)
 {
     // profile types
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $subTypes = CRM_Contact_BAO_ContactType::subTypes();
     $components = array('Contribution', 'Participant', 'Membership', 'Activity');
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->id = $ufGroupId;
     $ufGroup->is_active = 1;
     $ufGroup->find(TRUE);
     $profileTypes = array();
     if ($ufGroup->group_type) {
         $typeParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ufGroup->group_type);
         $profileTypes = explode(',', $typeParts[0]);
     }
     if ($onlyPure) {
         if (count($profileTypes) == 1) {
             return $profileTypes[0];
         } else {
             return NULL;
         }
     }
     //we need to unset Contact
     if (count($profileTypes) > 1) {
         $index = array_search('Contact', $profileTypes);
         if ($index !== FALSE) {
             unset($profileTypes[$index]);
         }
     }
     $profileType = $mixProfileType = NULL;
     // this case handles pure profile
     if (count($profileTypes) == 1) {
         $profileType = array_pop($profileTypes);
     } else {
         //check the there are any components include in profile
         $componentCount = array();
         foreach ($components as $value) {
             if (in_array($value, $profileTypes)) {
                 $componentCount[] = $value;
             }
         }
         //check contact type included in profile
         $contactTypeCount = array();
         foreach ($contactTypes as $value) {
             if (in_array($value, $profileTypes)) {
                 $contactTypeCount[] = $value;
             }
         }
         // subtype counter
         $subTypeCount = array();
         foreach ($subTypes as $value) {
             if (in_array($value, $profileTypes)) {
                 $subTypeCount[] = $value;
             }
         }
         if (!$skipComponentType && count($componentCount) == 1) {
             $profileType = $componentCount[0];
         } elseif (count($componentCount) > 1) {
             $mixProfileType = $componentCount[1];
         } elseif (count($subTypeCount) == 1) {
             $profileType = $subTypeCount[0];
         } elseif (count($contactTypeCount) == 1) {
             $profileType = $contactTypeCount[0];
         } elseif (count($subTypeCount) > 1) {
             // this is mix subtype profiles
             $mixProfileType = $subTypeCount[1];
         } elseif (count($contactTypeCount) > 1) {
             // this is mix contact profiles
             $mixProfileType = $contactTypeCount[1];
         }
     }
     if ($mixProfileType) {
         if ($returnMixType) {
             return $mixProfileType;
         } else {
             return 'Mixed';
         }
     } else {
         return $profileType;
     }
 }
Beispiel #14
0
 /**
  * function to check for mix profiles groups (eg: individual + other contact types)
  *
  * @return  true for mix profile group else false
  * @acess public
  * @static
  */
 static function checkProfileGroupType($ctype)
 {
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $query = "\nSELECT ufg.id as id\n  FROM civicrm_uf_group as ufg, civicrm_uf_join as ufj\n WHERE ufg.id = ufj.uf_group_id\n   AND ufj.module = 'User Registration'\n   AND ufg.is_active = 1 ";
     $ufGroup =& CRM_Core_DAO::executeQuery($query);
     $fields = array();
     $validProfiles = array('Individual', 'Organization', 'Household', 'Contribution');
     while ($ufGroup->fetch()) {
         $profileType = self::getProfileType($ufGroup->id);
         if (in_array($profileType, $validProfiles)) {
             continue;
         } else {
             if ($profileType) {
                 return false;
             }
         }
     }
     return true;
 }
Beispiel #15
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         CRM_Utils_System::setTitle(ts('Title and Settings') . " ({$title})");
         foreach (array('on_behalf', 'soft_credit') as $module) {
             $ufJoinDAO = new CRM_Core_DAO_UFJoin();
             $ufJoinDAO->module = $module;
             $ufJoinDAO->entity_id = $this->_id;
             if ($ufJoinDAO->find(TRUE)) {
                 $jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, $module);
                 if ($module == 'soft_credit') {
                     $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id;
                     $defaults = array_merge($defaults, $jsonData);
                     $defaults['honor_block_is_active'] = $ufJoinDAO->is_active;
                 } else {
                     $defaults['onbehalf_profile_id'] = $ufJoinDAO->uf_group_id;
                     $defaults = array_merge($defaults, $jsonData);
                     $defaults['is_organization'] = $ufJoinDAO->is_active;
                 }
             } else {
                 if ($module == 'soft_credit') {
                     $ufGroupDAO = new CRM_Core_DAO_UFGroup();
                     $ufGroupDAO->name = 'honoree_individual';
                     if ($ufGroupDAO->find(TRUE)) {
                         $defaults['honoree_profile'] = $ufGroupDAO->id;
                     }
                     $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
                 } else {
                     $ufGroupDAO = new CRM_Core_DAO_UFGroup();
                     $ufGroupDAO->name = 'on_behalf_organization';
                     if ($ufGroupDAO->find(TRUE)) {
                         $defaults['onbehalf_profile_id'] = $ufGroupDAO->id;
                     }
                     $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
                     $defaults['is_for_organization'] = 1;
                 }
             }
         }
     } else {
         $ufGroupDAO = new CRM_Core_DAO_UFGroup();
         $ufGroupDAO->name = 'honoree_individual';
         if ($ufGroupDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufGroupDAO->id;
         }
         $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
     }
     return $defaults;
 }
 function upgrade_3_3_alpha1($rev)
 {
     $config = CRM_Core_Config::singleton();
     if ($config->userSystem->is_drupal) {
         // CRM-6426 - make civicrm profiles permissioned on drupal my account
         $config->userSystem->updateCategories();
     }
     // CRM-6846
     // insert name column for custom field table.
     // make sure name for custom field, group and
     // profile should be unique and properly munged.
     $colQuery = 'ALTER TABLE `civicrm_custom_field` ADD `name` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `custom_group_id` ';
     CRM_Core_DAO::executeQuery($colQuery, CRM_Core_DAO::$_nullArray, TRUE, NULL, FALSE, FALSE);
     $customFldCntQuery = 'select count(*) from civicrm_custom_field where name like %1 and id != %2';
     $customField = new CRM_Core_DAO_CustomField();
     $customField->selectAdd();
     $customField->selectAdd('id, label');
     $customField->find();
     while ($customField->fetch()) {
         $name = CRM_Utils_String::munge($customField->label, '_', 64);
         $fldCnt = CRM_Core_DAO::singleValueQuery($customFldCntQuery, array(1 => array($name, 'String'), 2 => array($customField->id, 'Integer')), TRUE, FALSE);
         if ($fldCnt) {
             $name = CRM_Utils_String::munge("{$name}_" . rand(), '_', 64);
         }
         $customFieldQuery = "\nUpdate `civicrm_custom_field`\nSET `name` = %1\nWHERE id = %2\n";
         $customFieldParams = array(1 => array($name, 'String'), 2 => array($customField->id, 'Integer'));
         CRM_Core_DAO::executeQuery($customFieldQuery, $customFieldParams, TRUE, NULL, FALSE, FALSE);
     }
     $customField->free();
     $customGrpCntQuery = 'select count(*) from civicrm_custom_group where name like %1 and id != %2';
     $customGroup = new CRM_Core_DAO_CustomGroup();
     $customGroup->selectAdd();
     $customGroup->selectAdd('id, title');
     $customGroup->find();
     while ($customGroup->fetch()) {
         $name = CRM_Utils_String::munge($customGroup->title, '_', 64);
         $grpCnt = CRM_Core_DAO::singleValueQuery($customGrpCntQuery, array(1 => array($name, 'String'), 2 => array($customGroup->id, 'Integer')));
         if ($grpCnt) {
             $name = CRM_Utils_String::munge("{$name}_" . rand(), '_', 64);
         }
         CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $customGroup->id, 'name', $name);
     }
     $customGroup->free();
     $ufGrpCntQuery = 'select count(*) from civicrm_uf_group where name like %1 and id != %2';
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->selectAdd();
     $ufGroup->selectAdd('id, title');
     $ufGroup->find();
     while ($ufGroup->fetch()) {
         $name = CRM_Utils_String::munge($ufGroup->title, '_', 64);
         $ufGrpCnt = CRM_Core_DAO::singleValueQuery($ufGrpCntQuery, array(1 => array($name, 'String'), 2 => array($ufGroup->id, 'Integer')));
         if ($ufGrpCnt) {
             $name = CRM_Utils_String::munge("{$name}_" . rand(), '_', 64);
         }
         CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $ufGroup->id, 'name', $name);
     }
     $ufGroup->free();
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
     // now modify the config so that the directories are stored in option group/value
     // CRM-6914
     // require_once 'CRM/Core/BAO/ConfigSetting.php';
     // $params = array( );
     // CRM_Core_BAO_ConfigSetting::add( $parambs );
 }
Beispiel #17
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields =& self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['uf_group'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Beispiel #18
0
 /**
  * Add the UF Group.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  * @param array $ids
  *   Reference array contains the id.
  *
  *
  * @return object
  */
 public static function add(&$params, $ids = array())
 {
     $fields = array('is_active', 'add_captcha', 'is_map', 'is_update_dupe', 'is_edit_link', 'is_uf_link', 'is_cms_user');
     foreach ($fields as $field) {
         $params[$field] = CRM_Utils_Array::value($field, $params, FALSE);
     }
     $params['limit_listings_group_id'] = CRM_Utils_Array::value('group', $params);
     $params['add_to_group_id'] = CRM_Utils_Array::value('add_contact_to_group', $params);
     //CRM-15427
     if (!empty($params['group_type']) && is_array($params['group_type'])) {
         $params['group_type'] = implode(',', $params['group_type']);
     }
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->copyValues($params);
     $ufGroupID = CRM_Utils_Array::value('ufgroup', $ids, CRM_Utils_Array::value('id', $params));
     if (!$ufGroupID) {
         $ufGroup->name = CRM_Utils_String::munge($ufGroup->title, '_', 56);
     }
     $ufGroup->id = $ufGroupID;
     $ufGroup->save();
     if (!$ufGroupID) {
         $ufGroup->name = $ufGroup->name . "_{$ufGroup->id}";
         $ufGroup->save();
     }
     return $ufGroup;
 }
Beispiel #19
0
 /**
  * @param $rev
  */
 public function upgrade_3_4_3($rev)
 {
     // CRM-8147, update group_type for uf groups, check and add component field types
     $ufGroups = new CRM_Core_DAO_UFGroup();
     $ufGroups->find();
     $skipGroupTypes = array('Individual,Contact', 'Organization,Contact', 'Household,Contact', 'Contact', 'Individual', 'Organization', 'Household');
     while ($ufGroups->fetch()) {
         if (!in_array($ufGroups->group_type, $skipGroupTypes)) {
             $groupTypes = CRM_Core_BAO_UFGroup::calculateGroupType($ufGroups->id, TRUE);
             CRM_Core_BAO_UFGroup::updateGroupTypes($ufGroups->id, $groupTypes);
         }
     }
     $ufGroups->free();
     // CRM-8134 add phone_ext column if it wasn't already added for this site in 3.3.7 upgrade (3.3.7 was released after 3.4.0)
     $dao = new CRM_Contact_DAO_Contact();
     $dbName = $dao->_database;
     $chkExtQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1\n                        AND TABLE_NAME = 'civicrm_phone' AND COLUMN_NAME = 'phone_ext'";
     $extensionExists = CRM_Core_DAO::singleValueQuery($chkExtQuery, array(1 => array($dbName, 'String')), TRUE, FALSE);
     if (!$extensionExists) {
         $colQuery = 'ALTER TABLE `civicrm_phone` ADD `phone_ext` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `phone` ';
         CRM_Core_DAO::executeQuery($colQuery);
     }
     $sql = "SELECT id FROM civicrm_location_type WHERE name = 'Main'";
     if (!CRM_Core_DAO::singleValueQuery($sql)) {
         $query = "\nINSERT INTO civicrm_location_type ( name, description, is_reserved, is_active )\n     VALUES ( 'Main', 'Main office location', 0, 1 );";
         CRM_Core_DAO::executeQuery($query);
     }
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
 }
Beispiel #20
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'));
     }
 }
Beispiel #21
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'));
     }
 }
Beispiel #22
0
 /** 
  * run this page (figure out the action needed and perform it). 
  * 
  * @return void 
  */
 function run()
 {
     $this->preProcess();
     $this->assign('recentlyViewed', false);
     if ($this->_gid) {
         $ufgroupDAO = new CRM_Core_DAO_UFGroup();
         $ufgroupDAO->id = $this->_gid;
         if (!$ufgroupDAO->find(true)) {
             CRM_Core_Error::fatal();
         }
     }
     if ($this->_gid) {
         // set the title of the page
         if ($ufgroupDAO->title) {
             CRM_Utils_System::setTitle($ufgroupDAO->title);
         }
     }
     // do not do any work if we are in reset mode
     if (!CRM_Utils_Array::value('reset', $_GET) || CRM_Utils_Array::value('force', $_GET)) {
         $this->assign('isReset', false);
         $map = 0;
         $linkToUF = 0;
         $editLink = false;
         if ($this->_gid) {
             $map = $ufgroupDAO->is_map;
             $linkToUF = $ufgroupDAO->is_uf_link;
             $editLink = $ufgroupDAO->is_edit_link;
         }
         if ($map) {
             $this->assign('mapURL', CRM_Utils_System::url('civicrm/profile/map', "map=1&gid={$this->_gid}&reset=1"));
         }
         if (CRM_Utils_Array::value('group', $this->_params)) {
             foreach ($this->_params['group'] as $key => $val) {
                 if (!$val) {
                     unset($this->_params['group'][$key]);
                 }
             }
         }
         // the selector will override this if the user does have
         // edit permissions as determined by the mask, CRM-4341
         // do not allow edit for anon users in joomla frontend, CRM-4668
         $config =& CRM_Core_Config::singleton();
         if (!CRM_Core_Permission::check('access CiviCRM') || $config->userFrameworkFrontend == 1) {
             $editLink = false;
         }
         $selector =& new CRM_Profile_Selector_Listings($this->_params, $this->_customFields, $this->_gid, $map, $editLink, $linkToUF);
         $controller =& new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TEMPLATE);
         $controller->setEmbedded(true);
         $controller->run();
     } else {
         $this->assign('isReset', true);
     }
     $formController =& new CRM_Core_Controller_Simple('CRM_Profile_Form_Search', ts('Search Profile'), CRM_Core_Action::ADD);
     $formController->setEmbedded(true);
     $formController->process();
     $formController->run();
     // also get the search tpl name
     $this->assign('searchTPL', $formController->getTemplateFileName());
     $this->assign('search', $this->_search);
     return parent::run();
 }
Beispiel #23
0
 /**
  * function to add the UF Group
  *
  * @param array $params reference array contains the values submitted by the form
  * @param array $ids    reference array contains the id
  * 
  * @access public
  * @static 
  * @return object
  */
 static function add(&$params, &$ids)
 {
     require_once 'CRM/Utils/Array.php';
     $fields = array('is_active', 'add_captcha', 'is_map', 'is_update_dupe', 'is_edit_link', 'is_uf_link', 'is_cms_user');
     foreach ($fields as $field) {
         $params[$field] = CRM_Utils_Array::value($field, $params, false);
     }
     $params['limit_listings_group_id'] = CRM_Utils_Array::value('group', $params);
     $params['add_to_group_id'] = CRM_Utils_Array::value('add_contact_to_group', $params);
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->copyValues($params);
     $ufGroupID = CRM_Utils_Array::value('ufgroup', $ids);
     if (!$ufGroupID) {
         $ufGroup->name = CRM_Utils_String::munge($ufGroup->title, '_', 64);
     }
     $ufGroup->id = $ufGroupID;
     $ufGroup->save();
     return $ufGroup;
 }