private function _handleImportContact($xml) { $settings = CerberusSettings::getInstance(); $logger = DevblocksPlatform::getConsoleLog(); $sFirstName = (string) $xml->first_name; $sLastName = (string) $xml->last_name; $sEmail = (string) $xml->email; $sPassword = (string) $xml->password; $sOrganization = (string) $xml->organization; // Dupe check org if (null != ($address = DAO_Address::lookupAddress($sEmail))) { $logger->info('[Importer] Avoiding creating duplicate contact #' . $address->id . ' (' . $sEmail . ')'); // [TODO] Still associate with org if local blank? // [TODO] Still associate password if local blank? return true; } $fields = array(DAO_Address::FIRST_NAME => $sFirstName, DAO_Address::LAST_NAME => $sLastName, DAO_Address::EMAIL => $sEmail); // Associate SC password if (!empty($sPassword) && $sPassword != md5('')) { $fields[DAO_Address::IS_REGISTERED] = 1; $fields[DAO_Address::PASS] = $sPassword; } $address_id = DAO_Address::create($fields); // Associate with organization if (!empty($sOrganization)) { if (null != ($org_id = DAO_ContactOrg::lookup($sOrganization, true))) { DAO_Address::update($address_id, array(DAO_Address::CONTACT_ORG_ID => $org_id)); } } $logger->info('[Importer] Imported contact #' . $address_id . ' (' . $sEmail . ')'); return true; }
private function _postCreateAction($path) { $xmlstr = $this->getPayload(); $xml_in = simplexml_load_string($xmlstr); $fields = array(); $flds = DAO_Address::getFields(); unset($flds[DAO_Address::ID]); foreach ($flds as $idx => $f) { $idx_name = $this->translate($idx, true); if ($idx_name == null) { continue; } @($value = DevblocksPlatform::importGPC($xml_in->{$idx_name}, 'string')); if ($this->isValid($idx_name, $value)) { $fields[$idx] = $value; } } if (empty($fields[DAO_Address::EMAIL])) { $this->_error("All required fields were not provided."); } if (null != ($address = DAO_Address::lookupAddress($fields[DAO_Address::EMAIL], false))) { $this->_error("Address already exists."); } // Only valid orgs // [TODO] This referential integrity belongs in DAO if (!empty($fields[DAO_Address::CONTACT_ORG_ID])) { $in_contact_org = intval($fields[DAO_Address::CONTACT_ORG_ID]); if (null == ($contact_org = DAO_ContactOrg::get($in_contact_org))) { unset($fields[DAO_Address::CONTACT_ORG_ID]); } } $id = DAO_Address::create($fields); // send confirmation if requested @($confirmation_link = DevblocksPlatform::importGPC($xml_in->send_confirmation, 'string', '')); if (!empty($confirmation_link)) { $this->_sendConfirmation($fields[DAO_Address::EMAIL], $confirmation_link); } // Render $this->_getIdAction(array($id)); }
function saveContactAction() { $active_worker = CerberusApplication::getActiveWorker(); $db = DevblocksPlatform::getDatabaseService(); @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); @($email = trim(DevblocksPlatform::importGPC($_REQUEST['email'], 'string', ''))); @($first_name = trim(DevblocksPlatform::importGPC($_REQUEST['first_name'], 'string', ''))); @($last_name = trim(DevblocksPlatform::importGPC($_REQUEST['last_name'], 'string', ''))); @($contact_org = trim(DevblocksPlatform::importGPC($_REQUEST['contact_org'], 'string', ''))); @($is_banned = DevblocksPlatform::importGPC($_REQUEST['is_banned'], 'integer', 0)); @($pass = DevblocksPlatform::importGPC($_REQUEST['pass'], 'string', '')); @($unregister = DevblocksPlatform::importGPC($_REQUEST['unregister'], 'integer', 0)); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); if ($active_worker->hasPriv('core.addybook.addy.actions.update')) { $contact_org_id = 0; if (!empty($contact_org)) { $contact_org_id = DAO_ContactOrg::lookup($contact_org, true); $contact_org = DAO_ContactOrg::get($contact_org_id); } // Common fields $fields = array(DAO_Address::FIRST_NAME => $first_name, DAO_Address::LAST_NAME => $last_name, DAO_Address::CONTACT_ORG_ID => $contact_org_id, DAO_Address::IS_BANNED => $is_banned); // Are we clearing the contact's login? if ($unregister) { $fields[DAO_Address::IS_REGISTERED] = 0; $fields[DAO_Address::PASS] = ''; } elseif (!empty($pass)) { // Are we changing their password? $fields[DAO_Address::IS_REGISTERED] = 1; $fields[DAO_Address::PASS] = md5($pass); } if ($id == 0) { $fields = $fields + array(DAO_Address::EMAIL => $email); $id = DAO_Address::create($fields); } else { DAO_Address::update($id, $fields); } // Custom field saves @($field_ids = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array())); DAO_CustomFieldValue::handleFormPost(ChCustomFieldSource_Address::ID, $id, $field_ids); /* * Notify anything that wants to know when Address Peek saves. */ $eventMgr = DevblocksPlatform::getEventService(); $eventMgr->trigger(new Model_DevblocksEvent('address.peek.saved', array('address_id' => $id, 'changed_fields' => $fields))); } if (!empty($view_id)) { $view = C4_AbstractViewLoader::getView($view_id); $view->render(); } }
/** * Enter description here... * * @param unknown_type $email * @param unknown_type $create_if_null * @return Model_Address */ static function lookupAddress($email, $create_if_null = false) { $db = DevblocksPlatform::getDatabaseService(); $address = null; $email = trim(strtolower($email)); $addresses = self::getWhere(sprintf("email = %s", $db->qstr($email))); if (is_array($addresses) && !empty($addresses)) { $address = array_shift($addresses); } elseif ($create_if_null) { $fields = array(self::EMAIL => $email); $id = DAO_Address::create($fields); $address = DAO_Address::get($id); } return $address; }