Ejemplo n.º 1
0
 function getLocBlock()
 {
     // i wish i could retrieve loc block info based on loc_block_id,
     // Anyway, lets retrieve an event which has loc_block_id set to 'lbid'.
     if ($_POST['lbid']) {
         $params = array('1' => array($_POST['lbid'], 'Integer'));
         $eventId = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_event WHERE loc_block_id=%1 LIMIT 1', $params);
     }
     // now lets use the event-id obtained above, to retrieve loc block information.
     if ($eventId) {
         $params = array('entity_id' => $eventId, 'entity_table' => 'civicrm_event');
         require_once 'CRM/Core/BAO/Location.php';
         // second parameter is of no use, but since required, lets use the same variable.
         $location = CRM_Core_BAO_Location::getValues($params, $params);
     }
     $result = array();
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     // lets output only required fields.
     foreach ($addressOptions as $element => $isSet) {
         if ($isSet && !in_array($element, array('im', 'openid'))) {
             if (in_array($element, array('country', 'state_province', 'county'))) {
                 $element .= '_id';
             } else {
                 if ($element == 'address_name') {
                     $element = 'name';
                 }
             }
             $fld = "address[1][{$element}]";
             $value = CRM_Utils_Array::value($element, $location['address'][1]);
             $value = $value ? $value : "";
             $result[str_replace(array('][', '[', "]"), array('_', '_', ''), $fld)] = $value;
         }
     }
     foreach (array('email', 'phone_type_id', 'phone') as $element) {
         $block = $element == 'phone_type_id' ? 'phone' : $element;
         for ($i = 1; $i < 3; $i++) {
             $fld = "{$block}[{$i}][{$element}]";
             $value = CRM_Utils_Array::value($element, $location[$block][$i]);
             $value = $value ? $value : "";
             $result[str_replace(array('][', '[', "]"), array('_', '_', ''), $fld)] = $value;
         }
     }
     // set the message if loc block is being used by more than one event.
     require_once 'CRM/Event/BAO/Event.php';
     $result['count_loc_used'] = CRM_Event_BAO_Event::countEventsUsingLocBlockId($_POST['lbid']);
     echo json_encode($result);
     exit;
 }
Ejemplo n.º 2
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = $this->_values;
     if (!empty($defaults['loc_block_id'])) {
         $defaults['loc_event_id'] = $defaults['loc_block_id'];
         $countLocUsed = CRM_Event_BAO_Event::countEventsUsingLocBlockId($defaults['loc_block_id']);
         if ($countLocUsed > 1) {
             $this->assign('locUsed', TRUE);
         }
     }
     $config = CRM_Core_Config::singleton();
     if (!isset($defaults['address'][1]['country_id'])) {
         $defaults['address'][1]['country_id'] = $config->defaultContactCountry;
     }
     if (!isset($defaults['address'][1]['state_province_id'])) {
         $defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince;
     }
     $defaults['location_option'] = $this->_oldLocBlockId ? 2 : 1;
     return $defaults;
 }
Ejemplo n.º 3
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = $this->_values;
     if (CRM_Utils_Array::value('loc_block_id', $defaults)) {
         $defaults['loc_event_id'] = $defaults['loc_block_id'];
         $countLocUsed = CRM_Event_BAO_Event::countEventsUsingLocBlockId($defaults['loc_block_id']);
         if ($countLocUsed > 1) {
             $this->assign('locUsed', true);
         }
     }
     require_once 'CRM/Contact/Form/Edit/Address.php';
     if (!empty($defaults['address'])) {
         $config = CRM_Core_Config::singleton();
         foreach ($defaults['address'] as $key => $value) {
             CRM_Contact_Form_Edit_Address::fixStateSelect($this, "address[{$key}][country_id]", "address[{$key}][state_province_id]", CRM_Utils_Array::value('country_id', CRM_Utils_Array::value('address', $defaults), $config->defaultContactCountry));
         }
     }
     $defaults['location_option'] = $this->_oldLocBlockId ? 2 : 1;
     return $defaults;
 }
Ejemplo n.º 4
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = $this->_values;
     if (CRM_Utils_Array::value('loc_block_id', $defaults)) {
         $defaults['loc_event_id'] = $defaults['loc_block_id'];
         $countLocUsed = CRM_Event_BAO_Event::countEventsUsingLocBlockId($defaults['loc_block_id']);
         if ($countLocUsed > 1) {
             $this->assign('locUsed', TRUE);
         }
     }
     $config = CRM_Core_Config::singleton();
     if (!isset($defaults['address'][1]['country_id'])) {
         $defaults['address'][1]['country_id'] = $config->defaultContactCountry;
     }
     if (!isset($defaults['address'][1]['state_province_id'])) {
         $defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince;
     }
     if (!empty($defaults['address'])) {
         foreach ($defaults['address'] as $key => $value) {
             CRM_Contact_Form_Edit_Address::fixStateSelect($this, "address[{$key}][country_id]", "address[{$key}][state_province_id]", "address[{$key}][county_id]", CRM_Utils_Array::value('country_id', $value, $config->defaultContactCountry), CRM_Utils_Array::value('state_province_id', $value));
         }
     }
     $defaults['location_option'] = $this->_oldLocBlockId ? 2 : 1;
     return $defaults;
 }