/** * function that takes an address array and gets the latitude / longitude * and postal code for this address. Note that at a later stage, we could * make this function also clean up the address into a more valid format * * @param array $values associative array of address data: country, street_address, city, state_province, postal code * @param boolean $stateName this parameter currently has no function * * @return boolean true if we modified the address, false otherwise * @static */ static function format(&$values, $stateName = FALSE) { CRM_Utils_System::checkPHPVersion(5, TRUE); $config = CRM_Core_Config::singleton(); $whereComponents = array(); if (CRM_Utils_Array::value('street_address', $values)) { $whereComponents['street'] = $values['street_address']; } if ($city = CRM_Utils_Array::value('city', $values)) { $whereComponents['city'] = $city; } if (CRM_Utils_Array::value('state_province', $values)) { if (CRM_Utils_Array::value('state_province_id', $values)) { $stateProvince = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $values['state_province_id']); } else { if (!$stateName) { $stateProvince = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $values['state_province'], 'name', 'abbreviation'); } else { $stateProvince = $values['state_province']; } } // dont add state twice if replicated in city (happens in NZ and other countries, CRM-2632) if ($stateProvince != $city) { $whereComponents['state'] = $stateProvince; } } if (CRM_Utils_Array::value('postal_code', $values)) { $whereComponents['postal'] = $values['postal_code']; } if (CRM_Utils_Array::value('country', $values)) { $whereComponents['country'] = $values['country']; } foreach ($whereComponents as $componentName => $componentValue) { $whereComponents[$componentName] = urlencode("{$componentName}=\"{$componentValue}\""); } $add = 'q=' . urlencode('select * from geo.placefinder where '); $add .= join(urlencode(' and '), $whereComponents); $add .= "&appid=" . urlencode($config->mapAPIKey); $query = 'http://' . self::$_server . self::$_uri . '?' . $add; require_once 'HTTP/Request.php'; $request = new HTTP_Request($query); $request->sendRequest(); $string = $request->getResponseBody(); // see CRM-11359 for why we suppress errors with @ $xml = @simplexml_load_string($string); if ($xml === FALSE) { // account blocked maybe? CRM_Core_Error::debug_var('Geocoding failed. Message from Yahoo:', $string); return FALSE; } if ($xml->getName() == 'error') { CRM_Core_Error::debug_var('query', $query); CRM_Core_Error::debug_log_message('Geocoding failed. Message from Yahoo: ' . (string) $xml->description); return FALSE; } if (is_a($xml->results->Result, 'SimpleXMLElement')) { $result = array(); $result = get_object_vars($xml->results->Result); foreach ($result as $key => $val) { if (is_scalar($val) && strlen($val)) { $ret[(string) $key] = (string) $val; } } $values['geo_code_1'] = $ret['latitude']; $values['geo_code_2'] = $ret['longitude']; if ($ret['postal']) { $current_pc = CRM_Utils_Array::value('postal_code', $values); $skip_postal = FALSE; if ($current_pc) { $current_pc_suffix = CRM_Utils_Array::value('postal_code_suffix', $values); $current_pc_complete = $current_pc . $current_pc_suffix; $new_pc_complete = preg_replace("/[+-]/", '', $ret['postal']); // if a postal code was already entered, don't change it, except to make it more precise if (strpos($new_pc_complete, $current_pc_complete) !== 0) { // Don't bother anonymous users with the message - they can't change a form they just submitted anyway if (CRM_Utils_System::isUserLoggedIn()) { $msg = ts('The Yahoo Geocoding system returned a different postal code (%1) than the one you entered (%2). If you want the Yahoo value, please delete the current postal code and save again.', array(1 => $ret['postal'], 2 => $current_pc_suffix ? "{$current_pc}-{$current_pc_suffix}" : $current_pc)); CRM_Core_Session::setStatus($msg, ts('Postal Code Mismatch'), 'error'); } $skip_postal = TRUE; } } if (!$skip_postal) { $values['postal_code'] = $ret['postal']; /* the following logic to split the string was borrowed from CRM/Core/BAO/Address.php -- CRM_Core_BAO_Address::fixAddress. This is actually the function that calls the geocoding script to begin with, but the postal code business takes place before geocoding gets called. */ if (preg_match('/^(\\d{4,5})[+-](\\d{4})$/', $ret['postal'], $match)) { $values['postal_code'] = $match[1]; $values['postal_code_suffix'] = $match[2]; } } } return TRUE; } // reset the geo code values if we did not get any good values $values['geo_code_1'] = $values['geo_code_2'] = 'null'; return FALSE; }
/** * Given a UF user object, make sure there is a contact * object for this user. If the user has new values, we need * to update the CRM DB with the new values * * @param Object $user * The drupal user object. * @param bool $update * Has the user object been edited. * @param $uf * * @param $ctype * @param bool $isLogin */ public static function synchronize(&$user, $update, $uf, $ctype, $isLogin = FALSE) { $userSystem = CRM_Core_Config::singleton()->userSystem; $session = CRM_Core_Session::singleton(); if (!is_object($session)) { CRM_Core_Error::fatal('wow, session is not an object?'); return; } $userSystemID = $userSystem->getBestUFID($user); $uniqId = $userSystem->getBestUFUniqueIdentifier($user); // if the id of the object is zero (true for anon users in drupal) // have we already processed this user, if so early // return. $userID = $session->get('userID'); $ufID = $session->get('ufID'); if (!$update && $ufID == $userSystemID) { return; } //check do we have logged in user. $isUserLoggedIn = CRM_Utils_System::isUserLoggedIn(); // reset the session if we are a different user if ($ufID && $ufID != $userSystemID) { $session->reset(); //get logged in user ids, and set to session. if ($isUserLoggedIn) { $userIds = self::getUFValues(); $session->set('ufID', CRM_Utils_Array::value('uf_id', $userIds, '')); $session->set('userID', CRM_Utils_Array::value('contact_id', $userIds, '')); $session->set('ufUniqID', CRM_Utils_Array::value('uf_name', $userIds, '')); } } // return early if ($userSystemID == 0) { return; } $ufmatch = self::synchronizeUFMatch($user, $userSystemID, $uniqId, $uf, NULL, $ctype, $isLogin); if (!$ufmatch) { return; } //make sure we have session w/ consistent ids. $ufID = $ufmatch->uf_id; $userID = $ufmatch->contact_id; $ufUniqID = ''; if ($isUserLoggedIn) { $loggedInUserUfID = CRM_Utils_System::getLoggedInUfID(); //are we processing logged in user. if ($loggedInUserUfID && $loggedInUserUfID != $ufID) { $userIds = self::getUFValues($loggedInUserUfID); $ufID = CRM_Utils_Array::value('uf_id', $userIds, ''); $userID = CRM_Utils_Array::value('contact_id', $userIds, ''); $ufUniqID = CRM_Utils_Array::value('uf_name', $userIds, ''); } } //set user ids to session. $session->set('ufID', $ufID); $session->set('userID', $userID); $session->set('ufUniqID', $ufUniqID); // add current contact to recently viewed if ($ufmatch->contact_id) { list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = CRM_Contact_BAO_Contact::getDisplayAndImage($ufmatch->contact_id, TRUE, TRUE); $otherRecent = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'editUrl' => CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$ufmatch->contact_id}")); CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$ufmatch->contact_id}"), $ufmatch->contact_id, $contactType, $ufmatch->contact_id, $displayName, $otherRecent); } }
<?php require_once 'civimobile.header.php'; ?> <!-- start of menu page --> <div data-role="page" id="cm-home"> <div data-role="header"> <h1>CiviMobile</h1> </div><!-- /header --> <div data-role="content"> <?php if (CRM_Utils_System::isUserLoggedIn()) { ?> <a data-role="button" data-icon="search" href="#cm-contact-search" title="Contacts" class="icons" data-transition="slideup" >Contact</a> <a data-role="button" data-icon="grid" href="#cm-events" title="Events" class="icons" data-transition="slideup" >Events</a> <a data-role="button" data-icon="info" href="#cm-surveys" title="Survey" class="icons" data-transition="slideup" >Survey</a> <a data-role="button" data-icon="delete" href="<?php echo CRM_Utils_System::url('civicrm/mobile/logout'); ?> " title="click to logout" class="icons" data-transition="slideup" data-ajax="false">Logout</a> <?php } else { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/mobile/login')); CRM_Utils_System::civiExit(); } ?> </div><!-- /content --> </div> <!-- end of menu page -->
/** * Given a UF user object, make sure there is a contact * object for this user. If the user has new values, we need * to update the CRM DB with the new values * * @param Object $user the drupal user object * @param boolean $update has the user object been edited * @param $uf * * @return void * @access public * @static */ static function synchronize(&$user, $update, $uf, $ctype, $isLogin = FALSE) { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); if (!is_object($session)) { CRM_Core_Error::fatal('wow, session is not an object?'); return; } if ($config->userSystem->is_drupal) { $key = 'uid'; $login = '******'; $mail = 'mail'; } elseif ($uf == 'Joomla') { $key = 'id'; $login = '******'; $mail = 'email'; if (!isset($user->id) || !isset($user->email)) { $user = JFactory::getUser(); } } elseif ($uf == 'WordPress') { $key = 'ID'; $login = '******'; $mail = 'user_email'; } else { CRM_Core_Error::statusBounce(ts('Please set the user framework variable')); } // if the id of the object is zero (true for anon users in drupal) // have we already processed this user, if so early // return. $userID = $session->get('userID'); $ufID = $session->get('ufID'); if (!$update && $ufID == $user->{$key}) { return; } //check do we have logged in user. $isUserLoggedIn = CRM_Utils_System::isUserLoggedIn(); // reset the session if we are a different user if ($ufID && $ufID != $user->{$key}) { $session->reset(); //get logged in user ids, and set to session. if ($isUserLoggedIn) { $userIds = self::getUFValues(); $session->set('ufID', CRM_Utils_Array::value('uf_id', $userIds, '')); $session->set('userID', CRM_Utils_Array::value('contact_id', $userIds, '')); $session->set('ufUniqID', CRM_Utils_Array::value('uf_name', $userIds, '')); } } // return early if ($user->{$key} == 0) { return; } if (!isset($uniqId) || !$uniqId) { $uniqId = $user->{$mail}; } $ufmatch = self::synchronizeUFMatch($user, $user->{$key}, $uniqId, $uf, NULL, $ctype, $isLogin); if (!$ufmatch) { return; } //make sure we have session w/ consistent ids. $ufID = $ufmatch->uf_id; $userID = $ufmatch->contact_id; $ufUniqID = isset($ufmatch->user_unique_id) ? $ufmatch->user_unique_id : ''; if ($isUserLoggedIn) { $loggedInUserUfID = CRM_Utils_System::getLoggedInUfID(); //are we processing logged in user. if ($loggedInUserUfID && $loggedInUserUfID != $ufID) { $userIds = self::getUFValues($loggedInUserUfID); $ufID = CRM_Utils_Array::value('uf_id', $userIds, ''); $userID = CRM_Utils_Array::value('contact_id', $userIds, ''); $ufUniqID = CRM_Utils_Array::value('uf_name', $userIds, ''); } } //set user ids to session. $session->set('ufID', $ufID); $session->set('userID', $userID); $session->set('ufUniqID', $ufUniqID); // add current contact to recently viewed if ($ufmatch->contact_id) { list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = CRM_Contact_BAO_Contact::getDisplayAndImage($ufmatch->contact_id, TRUE, TRUE); $otherRecent = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'editUrl' => CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$ufmatch->contact_id}")); CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$ufmatch->contact_id}"), $ufmatch->contact_id, $contactType, $ufmatch->contact_id, $displayName, $otherRecent); } if ($update) { // the only information we care about is uniqId, so lets check that if (!isset($ufmatch->user_unique_id) || $uniqId != $ufmatch->user_unique_id) { // uniqId has changed, so we need to update that everywhere $ufmatch->user_unique_id = $uniqId; $ufmatch->save(); } } }
/** * Given a UF user object, make sure there is a contact * object for this user. If the user has new values, we need * to update the CRM DB with the new values * * @param Object $user the drupal user object * @param boolean $update has the user object been edited * @param $uf * * @return void * @access public * @static */ static function synchronize(&$user, $update, $uf, $ctype, $isLogin = false) { $session = CRM_Core_Session::singleton(); if (!is_object($session)) { CRM_Core_Error::fatal('wow, session is not an object?'); return; } //print "synchronize called with uniq_id " . $user->identity_url . "<br/>"; if ($uf == 'Drupal') { $key = 'uid'; $login = '******'; $mail = 'mail'; } else { if ($uf == 'Joomla') { $key = 'id'; $login = '******'; $mail = 'email'; } else { if ($uf == 'Standalone') { $key = 'id'; $mail = 'email'; $uniqId = $user->identity_url; $query = "\nSELECT uf_id\nFROM civicrm_uf_match \nLEFT JOIN civicrm_openid ON ( civicrm_uf_match.contact_id = civicrm_openid.contact_id ) \nWHERE openid = %1"; $p = array(1 => array($uniqId, 'String')); $dao = CRM_Core_DAO::executeQuery($query, $p); if ($dao->fetch()) { $user->{$key} = $dao->uf_id; } if (!$user->{$key}) { // Let's get the next uf_id since we don't actually have one $user->{$key} = self::getNextUfIdValue(); } } else { CRM_Core_Error::statusBounce(ts('Please set the user framework variable')); } } } // make sure we load the joomla object to get valid information if ($uf == 'Joomla') { if (!isset($user->id) || !isset($user->email)) { $user =& JFactory::getUser(); } } // if the id of the object is zero (true for anon users in drupal) // have we already processed this user, if so early // return. $userID = $session->get('userID'); $ufID = $session->get('ufID'); if (!$update && $ufID == $user->{$key}) { //print "Already processed this user<br/>"; return; } //check do we have logged in user. require_once 'CRM/Utils/System.php'; $isUserLoggedIn = CRM_Utils_System::isUserLoggedIn(); // reset the session if we are a different user if ($ufID && $ufID != $user->{$key}) { $session->reset(); //get logged in user ids, and set to session. if ($isUserLoggedIn) { $userIds = self::getUFValues(); $session->set('ufID', CRM_Utils_Array::value('uf_id', $userIds, '')); $session->set('userID', CRM_Utils_Array::value('contact_id', $userIds, '')); $session->set('ufUniqID', CRM_Utils_Array::value('uf_name', $userIds, '')); } } // return early if ($user->{$key} == 0) { return; } if (!isset($uniqId) || !$uniqId) { $uniqId = $user->{$mail}; } //print "Calling synchronizeUFMatch...<br/>"; $ufmatch =& self::synchronizeUFMatch($user, $user->{$key}, $uniqId, $uf, null, $ctype, $isLogin); if (!$ufmatch) { return; } //make sure we have session w/ consistent ids. $ufID = $ufmatch->uf_id; $userID = $ufmatch->contact_id; $ufUniqID = isset($ufmatch->user_unique_id) ? $ufmatch->user_unique_id : ''; if ($isUserLoggedIn) { $loggedInUserUfID = CRM_Utils_System::getLoggedInUfID(); //are we processing logged in user. if ($loggedInUserUfID && $loggedInUserUfID != $ufID) { $userIds = self::getUFValues($loggedInUserUfID); $ufID = CRM_Utils_Array::value('uf_id', $userIds, ''); $userID = CRM_Utils_Array::value('contact_id', $userIds, ''); $ufUniqID = CRM_Utils_Array::value('uf_name', $userIds, ''); } } //set user ids to session. $session->set('ufID', $ufID); $session->set('userID', $userID); $session->set('ufUniqID', $ufUniqID); // add current contact to recentlty viewed if ($ufmatch->contact_id) { require_once 'CRM/Contact/BAO/Contact.php'; list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = CRM_Contact_BAO_Contact::getDisplayAndImage($ufmatch->contact_id, true, true); $otherRecent = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'editUrl' => CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$ufmatch->contact_id}")); CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$ufmatch->contact_id}"), $ufmatch->contact_id, $contactType, $ufmatch->contact_id, $displayName, $otherRecent); } if ($update) { // the only information we care about is uniqId, so lets check that if (!isset($ufmatch->user_unique_id) || $uniqId != $ufmatch->user_unique_id) { // uniqId has changed, so we need to update that everywhere $ufmatch->user_unique_id = $uniqId; $ufmatch->save(); } } }