contact_id; $getDao = function () use ($contactId) { // Get the oldest join date for the contact's memberships. $dao = CRM_Core_DAO::executeQuery( 'SELECT join_date FROM civicrm_membership WHERE contact_id=%1 ORDER BY join_date ASC LIMIT 1', array( 1 => array($contactId, 'Integer') ) ); return $dao; }; $dao = $getDao(); $fetchResult = $dao->fetch(); if(!$fetchResult) { // retry after sleeping 2 seconds in order to avoid a race condition usleep(2000000); $dao->free(); $dao = $getDao(); $fetchResult = $dao->fetch(); } if($fetchResult) { // Make the API call. $joinDate = $dao->join_date; $apiUrl = civicrm_api3('setting', 'getvalue', array( 'name' => 'memberdashboard_button_api_url', 'group' => MEMBERDASHBOARD_SETTINGS_GROUP )); $user = civicrm_api3('setting', 'getvalue', array( 'name' => 'memberdashboard_button_api_user', 'group' => MEMBERDASHBOARD_SETTINGS_GROUP )); $password = civicrm_api3('setting', 'getvalue', array( 'name' => 'memberdashboard_button_api_password', 'group' => MEMBERDASHBOARD_SETTINGS_GROUP )); if(!empty($apiUrl) && !empty($user) && !empty($password)) { $url = "$apiUrl?contact_id=" . $contactId . "&date=" . $joinDate; $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "$user:$password"); curl_setopt($curl, CURLOPT_URL, $url); curl_exec($curl); } } $dao->free(); } catch(Exception $e) { // Ignore it. Not the end of the world if this fails. } } } function memberdashboard_civicrm_buildForm($formName, &$form) { // Hack to fix state select box in 4.4.x if($formName == 'CRM_Profile_Form_Edit') { $contactId = CRM_Core_Session::singleton()->get('userID'); if($contactId) { $contact = civicrm_api3('contact', 'getsingle', array( 'id' => $contactId )); $defaults['state_province-Primary'] = $contact['state_province_id']; $form->setDefaults($defaults); } } } function memberdashboard_civicrm_postProcess($formName, &$form) { // Redirect to Member Dashboard after updating billing info. The // default behavior is to go to the standard CiviCRM dashboard, // which is undesirable. if($formName == 'CRM_Contribute_Form_UpdateBilling') { CRM_Utils_System::redirect(CRM_Utils_System::url( 'civicrm/member-dashboard' )); } }