/** * figure out the post url for the form * * @param $action the default action if one is pre-specified * * @return string the url to post the form * @access public * @static */ function postURL($action) { if (!empty($action)) { return $action; } return CRM_Utils_System_Mambo::url($_GET['task']); }
/** * Synchronize the object with the UF Match entry. Can be called stand-alone from * the drupalUsers script * * @param Object $user the drupal user object * @param string $userKey the id of the user from the uf object * @param string $mail the email address of the user * @param string $uf the name of the user framework * @param integer $status returns the status if user created or already exits (used for drupal sync) * * @return the ufmatch object that was found or created * @access public * @static */ function &synchronizeUFMatch(&$user, $userKey, $mail, $uf, $status = null) { // validate that mail is a valid email address. Drupal does not check for this stuff require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::email($mail)) { return $status ? null : false; } $newContact = false; // make sure that a contact id exists for this user id $ufmatch =& new CRM_Core_DAO_UFMatch(); $ufmatch->uf_id = $userKey; $ufmatch->domain_id = CRM_Core_Config::domainID(); if (!$ufmatch->find(true)) { $query = "\nSELECT civicrm_contact.id as contact_id, civicrm_contact.domain_id as domain_id\nFROM civicrm_contact\nLEFT JOIN civicrm_location ON ( civicrm_location.entity_table = 'civicrm_contact' AND\n civicrm_contact.id = civicrm_location.entity_id AND \n civicrm_location.is_primary = 1 )\nLEFT JOIN civicrm_email ON ( civicrm_location.id = civicrm_email.location_id AND civicrm_email.is_primary = 1 )\nWHERE civicrm_email.email = '" . CRM_Utils_Type::escape($mail, 'String') . "' AND civicrm_contact.domain_id = " . CRM_Core_Config::domainID(); $dao =& new CRM_Core_DAO(); $dao->query($query); if ($dao->fetch()) { $ufmatch->contact_id = $dao->contact_id; $ufmatch->domain_id = $dao->domain_id; $ufmatch->email = $mail; } else { if ($uf == 'Mambo') { CRM_Utils_System_Mambo::setEmail($user); } require_once 'CRM/Core/BAO/LocationType.php'; $locationType =& CRM_Core_BAO_LocationType::getDefault(); //CRM_Core_Error::debug('M', $mail); $params = array('email' => $mail, 'location_type' => $locationType->name); $contact =& crm_create_contact($params, 'Individual'); if (is_a($contact, 'CRM_Core_Error')) { //CRM_Core_Error::debug( 'error', $contact ); exit(1); } $ufmatch->contact_id = $contact->id; $ufmatch->domain_id = $contact->domain_id; $ufmatch->email = $mail; } $ufmatch->save(); $newContact = true; } return $status ? $newContact : $ufmatch; }