/**
 *  Add an Website for a contact
 *
 * Allowed @params array keys are:
 * {@getfields website_create}
 * @example WebsiteCreate.php
 * {@example WebsiteCreate.php}
 *
 * @return array of newly created website property values.
 * @access public
 * @todo convert to using basic create - BAO function non-std
 */
function civicrm_api3_website_create($params)
{
    $websiteBAO = CRM_Core_BAO_Website::add($params);
    $values = array();
    _civicrm_api3_object_to_array($websiteBAO, $values[$websiteBAO->id]);
    return civicrm_api3_create_success($values, $params, 'website', 'get');
}
Пример #2
0
/**
 * Add an Website for a contact.
 *
 * @param array $params
 *
 * @return array
 *   API result array.
 * @todo convert to using basic create - BAO function non-std
 */
function civicrm_api3_website_create($params)
{
    //DO NOT USE THIS FUNCTION AS THE BASIS FOR A NEW API http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
    $websiteBAO = CRM_Core_BAO_Website::add($params);
    $values = array();
    _civicrm_api3_object_to_array($websiteBAO, $values[$websiteBAO->id]);
    return civicrm_api3_create_success($values, $params, 'Website', 'get');
}
Пример #3
0
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  */
 public function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     $params = array('contact_id' => $contactId);
     $websites = CRM_Core_BAO_Website::getValues($params, CRM_Core_DAO::$_nullArray);
     if (!empty($websites)) {
         foreach ($websites as $key => &$value) {
             $value['website_type'] = $websiteTypes[$value['website_type_id']];
         }
     }
     $this->assign('contactId', $contactId);
     $this->assign('website', $websites);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
Пример #4
0
 /**
  * Fetch object based on array of properties.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param array $defaults
  *   (reference ) an assoc array to hold the name / value pairs.
  *                        in a hierarchical manner
  * @param bool $microformat
  *   For location in microformat.
  *
  * @return CRM_Contact_BAO_Contact
  */
 public static function &retrieve(&$params, &$defaults, $microformat = FALSE)
 {
     if (array_key_exists('contact_id', $params)) {
         $params['id'] = $params['contact_id'];
     } elseif (array_key_exists('id', $params)) {
         $params['contact_id'] = $params['id'];
     }
     $contact = self::getValues($params, $defaults);
     unset($params['id']);
     //get the block information for this contact
     $entityBlock = array('contact_id' => $params['contact_id']);
     $blocks = CRM_Core_BAO_Location::getValues($entityBlock, $microformat);
     $defaults = array_merge($defaults, $blocks);
     foreach ($blocks as $block => $value) {
         $contact->{$block} = $value;
     }
     if (!isset($params['noNotes'])) {
         $contact->notes = CRM_Core_BAO_Note::getValues($params, $defaults);
     }
     if (!isset($params['noRelationships'])) {
         $contact->relationship = CRM_Contact_BAO_Relationship::getValues($params, $defaults);
     }
     if (!isset($params['noGroups'])) {
         $contact->groupContact = CRM_Contact_BAO_GroupContact::getValues($params, $defaults);
     }
     if (!isset($params['noWebsite'])) {
         $contact->website = CRM_Core_BAO_Website::getValues($params, $defaults);
     }
     return $contact;
 }
Пример #5
0
 /**
  * FIXME: we should make this method like getLocBlock() OR use the same method and
  * remove this one.
  *
  * obtain the location of given contact-id.
  * This method is used by on-behalf-of form to dynamically generate poulate the
  * location field values for selected permissioned contact.
  */
 public static function getPermissionedLocation()
 {
     $cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
     $ufId = CRM_Utils_Request::retrieve('ufId', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
     // Verify user id
     $user = CRM_Utils_Request::retrieve('uid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, CRM_Core_Session::singleton()->get('userID'));
     if (empty($user) || CRM_Utils_Request::retrieve('cs', 'String', $form, FALSE) && !CRM_Contact_BAO_Contact_Permission::validateChecksumContact($user, CRM_Core_DAO::$_nullObject, FALSE)) {
         CRM_Utils_System::civiExit();
     }
     // Verify user permission on related contact
     $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($user, NULL, NULL, 'Organization');
     if (!isset($organizations[$cid])) {
         CRM_Utils_System::civiExit();
     }
     $values = array();
     $entityBlock = array('contact_id' => $cid);
     $location = CRM_Core_BAO_Location::getValues($entityBlock);
     $config = CRM_Core_Config::singleton();
     $addressSequence = array_flip($config->addressSequence());
     $profileFields = CRM_Core_BAO_UFGroup::getFields($ufId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
     $website = CRM_Core_BAO_Website::getValues($entityBlock, $values);
     foreach ($location as $fld => $values) {
         if (is_array($values) && !empty($values)) {
             $locType = $values[1]['location_type_id'];
             if ($fld == 'email') {
                 $elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                 unset($profileFields["{$fld}-{$locType}"]);
             } elseif ($fld == 'phone') {
                 $phoneTypeId = $values[1]['phone_type_id'];
                 $elements["onbehalf_{$fld}-{$locType}-{$phoneTypeId}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                 unset($profileFields["{$fld}-{$locType}-{$phoneTypeId}"]);
             } elseif ($fld == 'im') {
                 $providerId = $values[1]['provider_id'];
                 $elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                 $elements["onbehalf_{$fld}-{$locType}provider_id"] = array('type' => 'Select', 'value' => $location[$fld][1]['provider_id']);
                 unset($profileFields["{$fld}-{$locType}-{$providerId}"]);
             }
         }
     }
     if (!empty($website)) {
         foreach ($website as $key => $val) {
             $websiteTypeId = $values[1]['website_type_id'];
             $elements["onbehalf_url-1"] = array('type' => 'Text', 'value' => $website[1]['url']);
             $elements["onbehalf_url-1-website_type_id"] = array('type' => 'Select', 'value' => $website[1]['website_type_id']);
             unset($profileFields["url-1"]);
         }
     }
     $locTypeId = isset($location['address'][1]) ? $location['address'][1]['location_type_id'] : NULL;
     $addressFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'county', 'state_province', 'country');
     foreach ($addressFields as $field) {
         if (array_key_exists($field, $addressSequence)) {
             $addField = $field;
             $type = 'Text';
             if (in_array($field, array('state_province', 'country', 'county'))) {
                 $addField = "{$field}_id";
                 $type = 'Select';
             }
             $elements["onbehalf_{$field}-{$locTypeId}"] = array('type' => $type, 'value' => isset($location['address'][1]) ? CRM_Utils_Array::value($addField, $location['address'][1]) : NULL);
             unset($profileFields["{$field}-{$locTypeId}"]);
         }
     }
     //set custom field defaults
     $defaults = array();
     CRM_Core_BAO_UFGroup::setProfileDefaults($cid, $profileFields, $defaults, TRUE, NULL, NULL, TRUE);
     if (!empty($defaults)) {
         foreach ($profileFields as $key => $val) {
             if (array_key_exists($key, $defaults)) {
                 $htmlType = CRM_Utils_Array::value('html_type', $val);
                 if ($htmlType == 'Radio') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                 } elseif ($htmlType == 'CheckBox') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     foreach ($defaults[$key] as $k => $v) {
                         $elements["onbehalf_{$key}"]['value'][$k] = $v;
                     }
                 } elseif (strstr($htmlType, 'Multi-Select') && $htmlType != 'AdvMulti-Select') {
                     $elements["onbehalf_{$key}"]['type'] = 'Multi-Select';
                     $elements["onbehalf_{$key}"]['value'] = array_values($defaults[$key]);
                 } elseif ($htmlType == 'Autocomplete-Select') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                 } elseif ($htmlType == 'Select Date') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                     $elements["onbehalf_{$key}_display"]['value'] = $defaults[$key];
                 } else {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                 }
             } else {
                 $elements["onbehalf_{$key}"]['value'] = '';
             }
         }
     }
     CRM_Utils_JSON::output($elements);
 }
Пример #6
0
 /**
  * process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     // Process / save websites
     CRM_Core_BAO_Website::create($params['website'], $this->_contactId, true);
     $this->log();
     $this->response();
 }
Пример #7
0
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     // Process / save websites
     // CRM-10551
     // Use updateBlankLocInfo to overwrite blanked values of matching type
     $params['updateBlankLocInfo'] = TRUE;
     CRM_Core_BAO_Website::create($params, $this->_contactId);
     $this->log();
     $this->response();
 }
 /**
  * FIXME: we should make this method like getLocBlock() OR use the same method and
  * remove this one.
  *
  * Function to obtain the location of given contact-id.
  * This method is used by on-behalf-of form to dynamically generate poulate the
  * location field values for selected permissioned contact.
  */
 function getPermissionedLocation()
 {
     $cid = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     if ($_GET['ufId']) {
         $ufId = CRM_Utils_Type::escape($_GET['ufId'], 'Integer');
     } elseif ($_GET['relContact']) {
         $relContact = CRM_Utils_Type::escape($_GET['relContact'], 'Integer');
     }
     $values = array();
     $entityBlock = array('contact_id' => $cid);
     $location = CRM_Core_BAO_Location::getValues($entityBlock);
     $config = CRM_Core_Config::singleton();
     $addressSequence = array_flip($config->addressSequence());
     if ($relContact) {
         $elements = array("phone_1_phone" => $location['phone'][1]['phone'], "email_1_email" => $location['email'][1]['email']);
         if (array_key_exists('street_address', $addressSequence)) {
             $elements["address_1_street_address"] = $location['address'][1]['street_address'];
         }
         if (array_key_exists('supplemental_address_1', $addressSequence)) {
             $elements['address_1_supplemental_address_1'] = $location['address'][1]['supplemental_address_1'];
         }
         if (array_key_exists('supplemental_address_2', $addressSequence)) {
             $elements['address_1_supplemental_address_2'] = $location['address'][1]['supplemental_address_2'];
         }
         if (array_key_exists('city', $addressSequence)) {
             $elements['address_1_city'] = $location['address'][1]['city'];
         }
         if (array_key_exists('postal_code', $addressSequence)) {
             $elements['address_1_postal_code'] = $location['address'][1]['postal_code'];
             $elements['address_1_postal_code_suffix'] = $location['address'][1]['postal_code_suffix'];
         }
         if (array_key_exists('country', $addressSequence)) {
             $elements['address_1_country_id'] = $location['address'][1]['country_id'];
         }
         if (array_key_exists('state_province', $addressSequence)) {
             $elements['address_1_state_province_id'] = $location['address'][1]['state_province_id'];
         }
     } else {
         $profileFields = CRM_Core_BAO_UFGroup::getFields($ufId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         $website = CRM_Core_BAO_Website::getValues($entityBlock, $values);
         foreach ($location as $fld => $values) {
             if (is_array($values) && !empty($values)) {
                 $locType = $values[1]['location_type_id'];
                 if ($fld == 'email') {
                     $elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                     unset($profileFields["{$fld}-{$locType}"]);
                 } elseif ($fld == 'phone') {
                     $phoneTypeId = $values[1]['phone_type_id'];
                     $elements["onbehalf_{$fld}-{$locType}-{$phoneTypeId}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                     unset($profileFields["{$fld}-{$locType}-{$phoneTypeId}"]);
                 } elseif ($fld == 'im') {
                     $providerId = $values[1]['provider_id'];
                     $elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                     $elements["onbehalf_{$fld}-{$locType}provider_id"] = array('type' => 'Select', 'value' => $location[$fld][1]['provider_id']);
                     unset($profileFields["{$fld}-{$locType}-{$providerId}"]);
                 }
             }
         }
         if (!empty($website)) {
             foreach ($website as $key => $val) {
                 $websiteTypeId = $values[1]['website_type_id'];
                 $elements["onbehalf_url-1"] = array('type' => 'Text', 'value' => $website[1]['url']);
                 $elements["onbehalf_url-1-website_type_id"] = array('type' => 'Select', 'value' => $website[1]['website_type_id']);
                 unset($profileFields["url-1"]);
             }
         }
         $locTypeId = $location['address'][1]['location_type_id'];
         $addressFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'country', 'state_province');
         foreach ($addressFields as $field) {
             if (array_key_exists($field, $addressSequence)) {
                 $addField = $field;
                 if (in_array($field, array('state_province', 'country'))) {
                     $addField = "{$field}_id";
                 }
                 $elements["onbehalf_{$field}-{$locTypeId}"] = array('type' => 'Text', 'value' => $location['address'][1][$addField]);
                 unset($profileFields["{$field}-{$locTypeId}"]);
             }
         }
         //set custom field defaults
         $defaults = array();
         CRM_Core_BAO_UFGroup::setProfileDefaults($cid, $profileFields, $defaults, TRUE, NULL, NULL, TRUE);
         if (!empty($defaults)) {
             foreach ($profileFields as $key => $val) {
                 if (array_key_exists($key, $defaults)) {
                     $htmlType = CRM_Utils_Array::value('html_type', $val);
                     if ($htmlType == 'Radio') {
                         $elements["onbehalf[{$key}]"]['type'] = $htmlType;
                         $elements["onbehalf[{$key}]"]['value'] = $defaults[$key];
                     } elseif ($htmlType == 'CheckBox') {
                         foreach ($defaults[$key] as $k => $v) {
                             $elements["onbehalf[{$key}][{$k}]"]['type'] = $htmlType;
                             $elements["onbehalf[{$key}][{$k}]"]['value'] = $v;
                         }
                     } elseif ($htmlType == 'Multi-Select') {
                         foreach ($defaults[$key] as $k => $v) {
                             $elements["onbehalf_{$key}"]['type'] = $htmlType;
                             $elements["onbehalf_{$key}"]['value'][$k] = $v;
                         }
                     } elseif ($htmlType == 'Autocomplete-Select') {
                         $elements["onbehalf_{$key}"]['type'] = $htmlType;
                         $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                         $elements["onbehalf_{$key}"]['id'] = $defaults["{$key}_id"];
                     } else {
                         $elements["onbehalf_{$key}"]['type'] = $htmlType;
                         $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                     }
                 } else {
                     $elements["onbehalf_{$key}"]['value'] = '';
                 }
             }
         }
     }
     echo json_encode($elements);
     CRM_Utils_System::civiExit();
 }
Пример #9
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     foreach ($this->_websites as $count => $value) {
         if (!empty($value['id']) && isset($params['website'][$count])) {
             $params['website'][$count]['id'] = $value['id'];
         }
     }
     // Process / save websites
     CRM_Core_BAO_Website::create($params['website'], $this->_contactId, TRUE);
     $this->log();
     $this->response();
 }