Example #1
0
 public function buildQuickForm()
 {
     $config =& CRM_Core_Config::singleton();
     $this->add('select', 'country_id', ts('Country'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::country());
     $countryID = isset($_POST['country_id']) ? $_POST['country_id'] : null;
     if (!$countryID) {
         $countryID = isset($this->_params['country_id']) ? $this->_params['country_id'] : null;
     }
     if ($countryID) {
         $this->add('select', 'state_province_id', ts('State'), array('' => ts('- select a state -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryID));
     } else {
         $this->add('select', 'state_province_id', ts('State'), array('' => ts('- select a country first -')));
     }
     $stateCountryURL = CRM_Utils_System::url('civicrm/ajax/jqState');
     $this->assign('stateCountryURL', $stateCountryURL);
     $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 function buildQuickForm($form, $proxSearch)
 {
     // is proximity search required (2) or optional (1)?
     $proxRequired = $proxSearch == 2 ? TRUE : FALSE;
     $form->assign('proximity_search', TRUE);
     $form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE);
     $form->add('text', 'prox_city', ts('City'), NULL, FALSE);
     $form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE);
     $defaults = self::setDefaultValues($form);
     if (CRM_Utils_Array::value('prox_country_id', $defaults)) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($defaults['prox_country_id']);
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->add('select', 'prox_state_province_id', ts('State/Province'), $stateProvince, $proxRequired);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired);
     $form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired);
     $proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
     $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired);
     // prox_distance_unit
     // state country js, CRM-5233
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'prox_state_province_id', 'country' => 'prox_country_id');
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
 }
Example #3
0
 static function fixStateSelect(&$form, $countryElementName, $stateElementName, $countyElementName, $countryDefaultValue, $stateDefaultValue = NULL)
 {
     $countryID = $stateID = NULL;
     if (isset($form->_elementIndex[$countryElementName])) {
         //get the country id to load states -
         //first check for submitted value,
         //then check for user passed value.
         //finally check for element default val.
         $submittedVal = $form->getSubmitValue($countryElementName);
         if ($submittedVal) {
             $countryID = $submittedVal;
         } elseif ($countryDefaultValue) {
             $countryID = $countryDefaultValue;
         } else {
             $countryID = CRM_Utils_Array::value(0, $form->getElementValue($countryElementName));
         }
     }
     $stateTitle = ts('State/Province');
     if (isset($form->_fields[$stateElementName]['title'])) {
         $stateTitle = $form->_fields[$stateElementName]['title'];
     }
     if (isset($form->_elementIndex[$stateElementName])) {
         $submittedValState = $form->getSubmitValue($stateElementName);
         if ($submittedValState) {
             $stateID = $submittedValState;
         } elseif ($stateDefaultValue) {
             $stateID = $stateDefaultValue;
         } else {
             $stateID = CRM_Utils_Array::value(0, $form->getElementValue($stateElementName));
         }
     }
     if (isset($form->_elementIndex[$stateElementName])) {
         if ($countryID) {
             $stateProvinces = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID);
         } else {
             $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
         }
         $stateSelect =& $form->addElement('select', $stateElementName, $stateTitle, array('' => ts('- select -')) + $stateProvinces);
     }
     if (isset($form->_elementIndex[$stateElementName]) && isset($form->_elementIndex[$countyElementName])) {
         if ($stateID) {
             $counties = CRM_Core_PseudoConstant::countyForState($stateID);
         } else {
             $counties = CRM_Core_PseudoConstant::county();
         }
         $form->addElement('select', $countyElementName, ts('County'), array('' => ts('- select -')) + $counties);
     }
     // CRM-7296 freeze the select for state if address is shared with household
     // CRM-9070 freeze the select for state if it is view only
     if (isset($form->_fields) && !empty($form->_fields[$stateElementName]) && (!empty($form->_fields[$stateElementName]['is_shared']) || !empty($form->_fields[$stateElementName]['is_view']))) {
         $stateSelect->freeze();
     }
 }
 function testStateCountry()
 {
     $this->webtestLogin();
     $config = CRM_Core_Config::singleton();
     // Add new profile.
     $this->openCiviPage('admin/uf/group', 'reset=1');
     $this->click('newCiviCRMProfile-top');
     $this->waitForElementPresent('_qf_Group_next-bottom');
     //Name of profile
     $profileTitle = 'Country state province web test temp';
     $this->type('title', $profileTitle);
     // Standalone form or directory
     $this->click('uf_group_type_Profile');
     //click on save
     $this->click('_qf_Group_next');
     $this->waitForPageToLoad($this->getTimeoutMsec());
     //check for  profile create
     $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
     $gid = $this->urlArg('gid');
     //Add Country field to profile
     $this->openCiviPage('admin/uf/group/field/add', array('action' => 'add', 'reset' => 1, 'gid' => $gid), 'field_name[0]');
     $this->click('field_name[0]');
     $this->select('field_name[0]', 'value=Contact');
     $this->click("//option[@value='Contact']");
     $this->click('field_name[1]');
     $this->select('field_name[1]', 'value=country');
     $this->click("//option[@value='country']");
     $this->click('is_required');
     $this->click('_qf_Field_next_new');
     $this->waitForPageToLoad($this->getTimeoutMsec());
     //Add State field to profile
     $this->click('field_name[0]');
     $this->select('field_name[0]', 'value=Contact');
     $this->click("//option[@value='Contact']");
     $this->click('field_name[1]');
     $this->select('field_name[1]', 'value=state_province');
     $this->click("xpath=//select[@id='field_name_1']/option[@value='state_province']");
     $this->click('is_required');
     //click on save
     $this->click('_qf_Field_next');
     $this->waitForPageToLoad($this->getTimeoutMsec());
     if ($gid) {
         $this->openCiviPage('admin/setting/localization', 'reset=1', '_qf_Localization_next-bottom');
         $country = array(1001 => 'Afghanistan', 1013 => 'Australia', 1039 => 'Canada', 1101 => 'India');
         $enabledCountries = $this->getSelectOptions("countryLimit-t");
         $enabledStates = $this->getSelectOptions("provinceLimit-t");
         $newCountry = array();
         foreach ($country as $countryID => $countryName) {
             if (!in_array($countryName, $enabledCountries)) {
                 $newCountry[$countryID] = $countryName;
                 $this->addSelection("countryLimit-f", "label={$countryName}");
                 $this->click("xpath=//select[@id='countryLimit-f']/option[@value='{$countryID}']");
                 $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
             }
             if (!in_array($countryName, $enabledStates)) {
                 $this->addSelection("provinceLimit-f", "label={$countryName}");
                 $this->click("//option[@value='{$countryID}']");
                 $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
             }
             $added = true;
         }
         if ($added) {
             $this->click("_qf_Localization_next-bottom");
             $this->waitForPageToLoad($this->getTimeoutMsec());
             $this->waitForText('crm-notification-container', "Saved");
         }
         $this->openCiviPage("profile/create", "gid={$gid}&reset=1", NULL);
         $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
         $this->click("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
         $countryID = array_rand($country);
         $states = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID, 'id');
         $stateID = array_rand($states);
         $this->select("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select", "value={$countryID}");
         $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select/option[@value={$stateID}]");
         $this->click("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select");
         $this->select("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select", "value={$stateID}");
         $this->clickLink('_qf_Edit_next', NULL);
         // Delete profile
         $this->openCiviPage('admin/uf/group', 'action=delete&id=' . $gid, '_qf_Group_next-bottom');
         $this->clickLink('_qf_Group_next-bottom', 'newCiviCRMProfile-bottom');
         $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been deleted.");
         $this->openCiviPage("admin/setting/localization", "reset=1", "_qf_Localization_next-bottom");
         $enabledCountries = $this->getSelectOptions("countryLimit-t");
         $enabledStates = $this->getSelectOptions("provinceLimit-t");
         $removed = false;
         foreach ($newCountry as $countryID => $countryName) {
             $this->addSelection("countryLimit-t", "label={$countryName}");
             $this->click("xpath=//select[@id='countryLimit-t']/option[@value='{$countryID}']");
             $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
             $this->addSelection("provinceLimit-t", "label={$countryName}");
             $this->click("//option[@value='{$countryID}']");
             $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
             $removed = true;
         }
         if ($removed) {
             $this->click("_qf_Localization_next-bottom");
             $this->waitForPageToLoad($this->getTimeoutMsec());
             $this->waitForText('crm-notification-container', "Saved");
         }
     }
 }
//initialize civicrm
$rootPath = '/var/www/drupal7/sites/all/modules/civicrm/';
require_once $rootPath . 'civicrm.config.php';
require_once $rootPath . 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton();
CRM_Core_DAO::$_dbColumnValueCache = NULL;
//readfile
$fileName = 'MyImport2.csv';
CRM_Core_Error::debug('$fileName', $fileName);
exit;
//$fileName = 'test1.csv';
$read = fopen($fileName, 'r');
$rows = fgetcsv($read);
$contactSubType = array('Associate Supplier' => 'Associate', 'Foodservice Operator' => 'Food_Service_Operator');
$stateProvince = CRM_Core_PseudoConstant::stateProvinceForCountry(1039, 'abbreviation');
$errors['org'] = $errors['ind'] = $errors['mem'] = array();
$totalImported = 0;
while ($rows = fgetcsv($read)) {
    CRM_Core_Error::debug('$rows', $rows[0] . '/n \\n');
    $contactResult = civicrm_api3('Contact', 'get', array('return' => 'id', 'external_identifier' => $rows[0]));
    $membershipResult = array();
    if (empty($contactResult['id'])) {
        $contactParams = array('external_identifier' => $rows[0], 'contact_type' => 'Organization', 'sort_name' => $rows[3], 'contact_sub_type' => $contactSubType[$rows[2]], 'display_name' => $rows[3], 'source' => 'Import via script', 'organization_name' => $rows[5], 'email' => $rows[19], 'api.Address.create' => array('location_type_id' => 3, 'is_primary' => 1, 'street_address' => $rows[7], 'city' => $rows[13], 'state_province_id' => array_search($rows[14], $stateProvince), 'postal_code' => $rows[15], 'country_id' => 1039), 'api.Phone.create' => array(array('location_type_id' => 3, 'is_primary' => 1, 'phone' => $rows[11], 'phone_type_id' => 1), array('location_type_id' => 3, 'is_primary' => 1, 'phone' => $rows[12], 'phone_type_id' => 3)));
        $contactResult = civicrm_api3('Contact', 'create', $contactParams);
    } else {
        $errors['org'][] = $rows[0];
        // check for membership for CFRA ID
        $membershipResult = civicrm_api3('Membership', 'get', array('contact_id' => $contactResult['id'], 'return' => 'id'));
    }
    if (!empty($rows[9]) && !empty($rows[10])) {
 /**
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array $defaults
  *   (reference) the default values, some of which need to be resolved.
  * @param bool $reverse
  *   True if we want to resolve the values in the reverse direction (value -> name).
  */
 public static function resolveDefaults(&$defaults, $reverse = FALSE)
 {
     // Hack for birth_date.
     if (!empty($defaults['birth_date'])) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'communication_style', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'), $reverse);
     //lookup value of email/postal greeting, addressee, CRM-4575
     foreach (self::$_greetingTypes as $greeting) {
         $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => $greeting);
         CRM_Utils_Array::lookupValue($defaults, $greeting, CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     }
     $blocks = array('address', 'im', 'phone');
     foreach ($blocks as $name) {
         if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) {
             continue;
         }
         foreach ($defaults[$name] as $count => &$values) {
             //get location type id.
             CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), $reverse);
             if ($name == 'address') {
                 // FIXME: lookupValue doesn't work for vcard_name
                 if (!empty($values['location_type_id'])) {
                     $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name'));
                     $values['vcard_name'] = $vcardNames[$values['location_type_id']];
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 // CRM-7597
                 // if we find a country id above, we need to restrict it to that country
                 // rather than the list of all countries
                 if (!empty($values['country_id'])) {
                     $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id']);
                 } else {
                     $stateProvinceList = CRM_Core_PseudoConstant::stateProvince();
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse) && $reverse) {
                     if (!empty($values['country_id'])) {
                         $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id'], 'abbreviation');
                     } else {
                         $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceAbbreviation();
                     }
                     CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse);
                 }
                 if (!empty($values['state_province_id'])) {
                     $countyList = CRM_Core_PseudoConstant::countyForState($values['state_province_id']);
                 } else {
                     $countyList = CRM_Core_PseudoConstant::county();
                 }
                 CRM_Utils_Array::lookupValue($values, 'county', $countyList, $reverse);
             }
             if ($name == 'im') {
                 CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $reverse);
             }
             if ($name == 'phone') {
                 CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), $reverse);
             }
             // Kill the reference.
             unset($values);
         }
     }
 }
Example #7
0
 function jqState(&$config)
 {
     if (!isset($_GET['_value']) || empty($_GET['_value'])) {
         exit;
     }
     require_once 'CRM/Core/PseudoConstant.php';
     $result =& CRM_Core_PseudoConstant::stateProvinceForCountry($_GET['_value']);
     $elements = array(array('name' => ts('- select a state-'), 'value' => ''));
     foreach ($result as $id => $name) {
         $elements[] = array('name' => $name, 'value' => $id);
     }
     require_once "CRM/Utils/JSON.php";
     echo json_encode($elements);
     exit;
 }
function simpledonate_civicrm_pageRun(&$page)
{
    $pageName = $page->getVar('_name');
    if ($pageName == 'Civi\\Angular\\Page\\Main' && $page->urlPath[1] == 'simple') {
        //Get all contribution page detils and session details to be used in js
        $settingVal = simpledonate_getSimpleDonateSetting();
        $session = CRM_Core_Session::singleton();
        $contactID = $session->get('userID');
        if ($settingVal['donatePageID']) {
            $extends = CRM_Core_Component::getComponentID('CiviContribute');
            $priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $settingVal['donatePageID'], $extends);
            $priceField = civicrm_api3('PriceField', 'get', array("price_set_id" => $priceSetID));
            //Check for is_quick_config
            $isQuickConfig = civicrm_api3('PriceSet', 'getvalue', array('id' => $priceSetID, 'return' => "is_quick_config"));
            //Check for Other amount
            $otherAmount = FALSE;
            foreach ($priceField['values'] as $key => $value) {
                if ($value['name'] == 'other_amount') {
                    $otherAmount = TRUE;
                } else {
                    $priceFieldVal = civicrm_api3('PriceFieldValue', 'get', array('return' => "amount, title, name, is_default", "price_field_id" => $value['id']));
                    $priceList = $priceFieldVal['values'];
                    $htmlPriceList[$value['html_type']] = $priceFieldVal['values'];
                }
            }
            //Get donation page details
            $donateConfig = $donatePage = civicrm_api3('ContributionPage', 'getsingle', array('id' => $settingVal['donatePageID']));
            CRM_Utils_System::setTitle($donateConfig['title']);
            // Set the page title
            $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $donatePage['currency'], 'symbol', 'name');
            $test = !empty($_GET['test']) ? 'test' : 'live';
            // Check for test or live donation
            //Get payment processor details
            if (is_array($donatePage['payment_processor'])) {
                $paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($donatePage['payment_processor'], $test);
            } else {
                $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($donatePage['payment_processor'], $test);
                $paymentProcessors[$paymentProcessor['id']] = $paymentProcessor;
                $paymentProcessors[$paymentProcessor['id']]['hide'] = $donateConfig['is_pay_later'] ? FALSE : TRUE;
            }
            //set Country and State value
            $config = CRM_Core_Config::singleton();
            $defaultContactCountry = $config->defaultContactCountry;
            $stateProvince = array_flip(CRM_Core_PseudoConstant::stateProvinceForCountry($defaultContactCountry));
            $countryList = CRM_Core_PseudoConstant::country();
            $stateList = array();
            foreach ($countryList as $key => $val) {
                $stateList[$key] = CRM_Core_PseudoConstant::stateProvinceForCountry($key);
            }
            CRM_Core_Resources::singleton()->addSetting(array('simpledonate' => array('sessionContact' => $contactID, 'priceSetID' => $priceSetID, 'ziptasticEnable' => $settingVal['ziptasticEnable'], 'countryList' => CRM_Core_PseudoConstant::country(), 'stateList' => $stateList, 'country' => $defaultContactCountry, 'allStates' => $stateProvince, 'currency' => $currencySymbol, 'config' => $donateConfig, 'paymentProcessor' => $paymentProcessors, 'priceList' => $priceList, 'otherAmount' => $otherAmount, 'isTest' => $test == 'test' ? 1 : 0, 'htmlPriceList' => $htmlPriceList, 'isQuickConfig' => $isQuickConfig)));
            //Include bootstrap and custom css files to affect this angular page only
            CRM_Core_Resources::singleton()->addStyleFile('com.webaccessglobal.simpledonate', 'css/bootstrap.min.css', 103, 'page-header');
            CRM_Core_Resources::singleton()->addStyleFile('com.webaccessglobal.simpledonate', 'css/simpledonate.css', 100, 'page-body');
        }
        if ($contactID) {
            $id = array('id' => $contactID);
            $result = civicrm_api3('Contact', 'getSingle', $id);
            CRM_Core_Resources::singleton()->addSetting(array('simpledonateVal' => $result));
        }
    }
}
Example #9
0
 static function fixStateSelect(&$form, $countryElementName, $stateElementName, $countryDefaultValue)
 {
     $countryID = null;
     if (isset($form->_elementIndex[$countryElementName])) {
         $countryValue = $form->getElementValue($countryElementName);
         if ($countryValue) {
             $countryID = $countryValue[0];
         } else {
             $countryID = $countryDefaultValue;
         }
     }
     $stateTitle = ts('State/Province');
     if (isset($form->_fields[$stateElementName]['title'])) {
         $stateTitle = $form->_fields[$stateElementName]['title'];
     }
     if ($countryID && isset($form->_elementIndex[$stateElementName])) {
         $form->addElement('select', $stateElementName, $stateTitle, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryID));
     }
 }
Example #10
0
 function buildForm(&$form)
 {
     $config =& CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
     $form->addElement('select', 'tag', ts('Tag'), $tag);
     $form->add('text', 'distance', ts('Distance'));
     $form->add('text', 'street_address', ts('Street Address'));
     $form->add('text', 'city', ts('City'));
     $form->add('text', 'postal_code', ts('Postal Code'));
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'state_province_id', 'country' => 'country_id');
     $defaults = array();
     if ($countryDefault) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
         $defaults['country_id'] = $countryDefault;
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'country_id', ts('Country'), $country, true);
     $form->add('text', 'distance', ts('Radius for Proximity Search (in km)'), null, true);
     // state country js, CRM-5233
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Proximity Search');
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $form->assign('elements', array('tag', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'distance'));
 }
Example #11
0
 static function jqState($config)
 {
     if (!isset($_GET['_value']) || empty($_GET['_value'])) {
         CRM_Utils_System::civiExit();
     }
     $result = CRM_Core_PseudoConstant::stateProvinceForCountry($_GET['_value']);
     $elements = array(array('name' => ts('- select a state -'), 'value' => ''));
     foreach ($result as $id => $name) {
         $elements[] = array('name' => $name, 'value' => $id);
     }
     echo json_encode($elements);
     CRM_Utils_System::civiExit();
 }
 static function location(&$form)
 {
     // Build location criteria based on _submitValues if
     // available; otherwise, use $form->_formValues.
     $formValues = $form->_submitValues;
     if (empty($formValues) && !empty($form->_formValues)) {
         $formValues = $form->_formValues;
     }
     $form->addElement('hidden', 'hidden_location', 1);
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), 'city' => array(ts('City'), $attributes['city'], NULL, NULL), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL), 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', TRUE), 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL));
     $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0);
     $form->assign('parseStreetAddress', $parseStreetAddress);
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select, $multiSelect) = $v;
         if (in_array($name, array('street_number', 'street_name', 'street_unit'))) {
             if (!$parseStreetAddress) {
                 continue;
             }
         } elseif (!$addressOptions[$name]) {
             continue;
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         if ($select) {
             $config = CRM_Core_Config::singleton();
             $countryDefault = $config->defaultContactCountry;
             $stateCountryMap[] = array('state_province' => 'state_province', 'country' => 'country', 'county' => 'county');
             if ($select == 'stateProvince') {
                 if ($countryDefault && !isset($formValues['country'])) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                 } elseif ($formValues['country']) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($formValues['country']);
                 } else {
                     //if not setdefault any country
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                 }
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } elseif ($select == 'country') {
                 if ($countryDefault) {
                     //for setdefault country
                     $defaultValues = array();
                     $defaultValues[$name] = $countryDefault;
                     $form->setDefaults($defaultValues);
                 }
                 $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } elseif ($select == 'county') {
                 if (array_key_exists('state_province', $formValues) && !CRM_Utils_System::isNull($formValues['state_province'])) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($formValues['state_province']);
                 } else {
                     $selectElements = array('' => ts('- select a state -'));
                 }
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } else {
                 $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                 $element = $form->addElement('select', $name, $title, $selectElements);
             }
             if ($multiSelect) {
                 $element->setMultiple(TRUE);
             }
         } else {
             $form->addElement('text', $name, $title, $attributes);
         }
         if ($addressOptions['postal_code']) {
             $form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes));
             $form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes));
         }
     }
     // extend addresses with proximity search
     $form->addElement('text', 'prox_distance', ts('Find contacts within'));
     $form->addElement('select', 'prox_distance_unit', NULL, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers')));
     // is there another form rule that does decimals besides money ? ...
     $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion();
     $form->addElement('select', 'world_region', ts('World Region'), $worldRegions);
     // checkboxes for location type
     $location_type = array();
     $locationType = CRM_Core_PseudoConstant::locationType();
     foreach ($locationType as $locationTypeID => $locationTypeName) {
         $location_type[] = $form->createElement('checkbox', $locationTypeID, NULL, $locationTypeName);
     }
     $form->addGroup($location_type, 'location_type', ts('Location Types'), ' ');
     // custom data extending addresses -
     $extends = array('Address');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
     if ($groupDetails) {
         $form->assign('addressGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $elementName = 'custom_' . $field['id'];
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], FALSE, FALSE, TRUE);
             }
         }
     }
 }
Example #13
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $config = CRM_Core_Config::singleton();
     $i18n = CRM_Core_I18n::singleton();
     CRM_Utils_System::setTitle(ts('Settings - Localization'));
     $locales = CRM_Core_I18n::languages();
     $warningTitle = json_encode(ts("Warning"));
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if ($domain->locales) {
         // for multi-lingual sites, populate default language drop-down with available languages
         $lcMessages = array();
         foreach ($locales as $loc => $lang) {
             if (substr_count($domain->locales, $loc)) {
                 $lcMessages[$loc] = $lang;
             }
         }
         $this->addElement('select', 'lcMessages', ts('Default Language'), $lcMessages);
         // add language limiter and language adder
         $this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($lcMessages), NULL, NULL, NULL, NULL, '   ');
         $this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff($locales, $lcMessages)));
         // add the ability to return to single language
         $warning = ts('This will make your CiviCRM installation a single-language one again. THIS WILL DELETE ALL DATA RELATED TO LANGUAGES OTHER THAN THE DEFAULT ONE SELECTED ABOVE (and only that language will be preserved).');
         $this->assign('warning', $warning);
         $warning = json_encode($warning);
         $this->addElement('checkbox', 'makeSinglelingual', ts('Return to Single Language'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
     } else {
         // for single-lingual sites, populate default language drop-down with all languages
         $this->addElement('select', 'lcMessages', ts('Default Language'), $locales);
         $warning = ts('Enabling multiple languages changes the schema of your database, so make sure you know what you are doing when enabling this function; making a database backup is strongly recommended.');
         $this->assign('warning', $warning);
         $warning = json_encode($warning);
         $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(TRUE);
         if ($validTriggerPermission && !$config->logging) {
             $this->addElement('checkbox', 'makeMultilingual', ts('Enable Multiple Languages'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
         }
     }
     $this->addElement('checkbox', 'inheritLocale', ts('Inherit CMS Language'));
     $this->addElement('text', 'monetaryThousandSeparator', ts('Thousands Separator'), array('size' => 2));
     $this->addElement('text', 'monetaryDecimalPoint', ts('Decimal Delimiter'), array('size' => 2));
     $this->addElement('text', 'moneyformat', ts('Monetary Amount Display'));
     $this->addElement('text', 'moneyvalueformat', ts('Monetary Value Display'));
     $country = array();
     CRM_Core_PseudoConstant::populate($country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
     $i18n->localizeArray($country, array('context' => 'country'));
     asort($country);
     $includeCountry =& $this->addElement('advmultiselect', 'countryLimit', ts('Available Countries') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeCountry->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeCountry->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $includeState =& $this->addElement('advmultiselect', 'provinceLimit', ts('Available States and Provinces') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeState->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeState->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $this->addElement('select', 'defaultContactCountry', ts('Default Country'), array('' => ts('- select -')) + $country);
     /***Default State/Province***/
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'defaultContactStateProvince', 'country' => 'defaultContactCountry');
     $countryDefault = isset($this->_submitValues['defaultContactCountry']) ? $this->_submitValues['defaultContactCountry'] : $config->defaultContactCountry;
     if ($countryDefault) {
         $selectStateProvinceOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
     } else {
         $selectStateProvinceOptions = array('' => ts('- select a country -'));
     }
     $i18n->localizeArray($selectStateProvinceOptions, array('context' => 'state_province'));
     asort($selectStateProvinceOptions);
     $this->addElement('select', 'defaultContactStateProvince', ts('Default State/Province'), $selectStateProvinceOptions);
     // state country js
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $defaults = array();
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     // we do this only to initialize currencySymbols, kinda hackish but works!
     $config->defaultCurrencySymbol();
     $symbol = $config->currencySymbols;
     foreach ($symbol as $key => $value) {
         $this->_currencySymbols[$key] = "{$key}";
         if ($value) {
             $this->_currencySymbols[$key] .= " ({$value})";
         }
     }
     $this->addElement('select', 'defaultCurrency', ts('Default Currency'), $this->_currencySymbols);
     $includeCurrency =& $this->addElement('advmultiselect', 'currencyLimit', ts('Available Currencies') . ' ', $this->_currencySymbols, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeCurrency->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeCurrency->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $this->addElement('text', 'legacyEncoding', ts('Legacy Encoding'));
     $this->addElement('text', 'customTranslateFunction', ts('Custom Translate Function'));
     $this->addElement('text', 'fieldSeparator', ts('Import / Export Field Separator'), array('size' => 2));
     $this->addFormRule(array('CRM_Admin_Form_Setting_Localization', 'formRule'));
     parent::buildQuickForm();
 }
Example #14
0
 function buildForm(&$form)
 {
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->add('text', 'distance', ts('Distance'), NULL, TRUE);
     $proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
     $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, TRUE);
     $form->add('text', 'street_address', ts('Street Address'));
     $form->add('text', 'city', ts('City'));
     $form->add('text', 'postal_code', ts('Postal Code'));
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'state_province_id', 'country' => 'country_id');
     $defaults = array();
     if ($countryDefault) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
         $defaults['country_id'] = $countryDefault;
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'country_id', ts('Country'), $country, TRUE);
     $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
     $form->addElement('select', 'group', ts('Group'), $group);
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tag'), $tag);
     // state country js, CRM-5233
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Proximity Search');
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $form->assign('elements', array('distance', 'prox_distance_unit', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'group', 'tag'));
 }
Example #15
0
 static function fixStateSelect(&$form, $countryElementName, $stateElementName, $countryDefaultValue)
 {
     $countryID = null;
     if (isset($form->_elementIndex[$countryElementName])) {
         //get the country id to load states -
         //first check for submitted value,
         //then check for user passed value.
         //finally check for element default val.
         $submittedVal = $form->getSubmitValue($countryElementName);
         if ($submittedVal) {
             $countryID = $submittedVal;
         } else {
             if ($countryDefaultValue) {
                 $countryID = $countryDefaultValue;
             } else {
                 $countryID = CRM_Utils_Array::value(0, $form->getElementValue($countryElementName));
             }
         }
     }
     $stateTitle = ts('State/Province');
     if (isset($form->_fields[$stateElementName]['title'])) {
         $stateTitle = $form->_fields[$stateElementName]['title'];
     }
     if ($countryID && isset($form->_elementIndex[$stateElementName])) {
         $form->addElement('select', $stateElementName, $stateTitle, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryID));
     }
 }
Example #16
0
 static function location(&$form)
 {
     $form->addElement('hidden', 'hidden_location', 1);
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], null, null), 'city' => array(ts('City'), $attributes['city'], null, null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null, null), 'county' => array(ts('County'), $attributes['county_id'], 'county', false), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', true), 'country' => array(ts('Country'), $attributes['country_id'], 'country', false), 'address_name' => array(ts('Address Name'), $attributes['address_name'], null, null));
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select, $multiSelect) = $v;
         if (!$addressOptions[$name]) {
             continue;
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         if ($select) {
             $config = CRM_Core_Config::singleton();
             $countryDefault = $config->defaultContactCountry;
             $stateCountryMap[] = array('state_province' => 'state_province', 'country' => 'country');
             if ($select == 'stateProvince') {
                 if ($countryDefault && !isset($form->_submitValues['country'])) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                 } else {
                     if ($form->_submitValues['country']) {
                         $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($form->_submitValues['country']);
                     } else {
                         //if not setdefault any country
                         $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                     }
                 }
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } else {
                 if ($select == 'country') {
                     if ($countryDefault) {
                         //for setdefault country
                         $defaultValues = array();
                         $defaultValues[$name] = $countryDefault;
                         $form->setDefaults($defaultValues);
                     }
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                     $element = $form->addElement('select', $name, $title, $selectElements);
                 } else {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                     $element = $form->addElement('select', $name, $title, $selectElements);
                 }
             }
             if ($multiSelect) {
                 $element->setMultiple(true);
             }
         } else {
             $form->addElement('text', $name, $title, $attributes);
         }
         if ($addressOptions['postal_code']) {
             $form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes));
             $form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes));
         }
     }
     // extend addresses with proximity search
     $form->addElement('text', 'prox_distance', ts('Find contacts within'));
     $form->addElement('select', 'prox_distance_unit', null, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers')));
     // is there another form rule that does decimals besides money ? ...
     $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion();
     $form->addElement('select', 'world_region', ts('World Region'), $worldRegions);
     // checkboxes for location type
     $location_type = array();
     $locationType = CRM_Core_PseudoConstant::locationType();
     foreach ($locationType as $locationTypeID => $locationTypeName) {
         $location_type[] = HTML_QuickForm::createElement('checkbox', $locationTypeID, null, $locationTypeName);
     }
     $form->addGroup($location_type, 'location_type', ts('Location Types'), '&nbsp;');
     // custom data extending addresses -
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $extends = array('Address');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends);
     if ($groupDetails) {
         require_once 'CRM/Core/BAO/CustomField.php';
         $form->assign('addressGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $elementName = 'custom_' . $field['id'];
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], false, false, true);
             }
         }
     }
 }