/** * Links a user to an account. * * @param int $userId * @param int $accountId * @param array $aPermissions array of permissions to set (see OA_Permission.) eg: * array(OA_PERM_SUPER_ACCOUNT, OA_PERM_BANNER_EDIT) * @param array $aAllowedPermissions array of permissions that are allowed to be set. * Confusingly, the array format is different from * $aPermissions in that the permission is set in the * array key. The array value is not used and should be set to true. eg: * array(OA_PERM_SUPER_ACCOUNT => true, OA_PERM_BANNER_EDIT => true) * @return boolean true on successful linking, false otherwise. */ private function linkUserToAccount($userId, $accountId, $aPermissions = null, $aAllowedPermissions = null) { if (!$this->checkPermissions(OA_ACCOUNT_ADMIN)) { return false; } if (!$this->checkIdExistence('users', $userId)) { $this->raiseError(self::ERROR_UNKNOWN_USER_ID); return false; } $result = OA_Permission::setAccountAccess($accountId, $userId); if (PEAR::isError($result)) { $this->raiseError($result->getMessage()); return false; } if (!empty($aPermissions)) { $result = OA_Permission::storeUserAccountsPermissions($aPermissions, $accountId, $userId, $aAllowedPermissions); if (PEAR::isError($result)) { $this->raiseError($result->getMessage()); return false; } } return true; }
/** * This method modifies an existing agency. Undefined fields do not change * and defined fields with a NULL value also remain unchanged. * * @access public * * @param OA_Dll_AgencyInfo &$oAgency <br /> * <b>For adding</b><br /> * <b>Required properties:</b> agencyName<br /> * <b>Optional properties:</b> contactName, emailAddress, username, password<br /> * * <b>For modify</b><br /> * <b>Required properties:</b> agencyId<br /> * <b>Optional properties:</b> agencyName, contactName, emailAddress<br /> * * @return boolean True if the operation was successful * */ function modify(&$oAgency) { if (!$this->checkPermissions(OA_ACCOUNT_ADMIN)) { return false; } $agencyData = (array) $oAgency; // Name $agencyData['name'] = $oAgency->agencyName; // Default fields $agencyData['contact'] = $oAgency->contactName; $agencyData['email'] = $oAgency->emailAddress; if ($this->_validate($oAgency)) { $doAgency = OA_Dal::factoryDO('agency'); if (!isset($agencyData['agencyId'])) { $doAgency->setFrom($agencyData); $oAgency->agencyId = $doAgency->insert(); if ($oAgency->agencyId) { // Set the account ID $doAgency = OA_Dal::staticGetDO('agency', $oAgency->agencyId); $oAgency->accountId = (int) $doAgency->account_id; } if (isset($agencyData['username']) || isset($agencyData['userEmail'])) { // Use the authentication plugin to create the user $oPlugin = OA_Auth::staticGetAuthPlugin(); $userId = $oPlugin->getMatchingUserId($agencyData['userEmail'], $agencyData['username']); $userId = $oPlugin->saveUser($userId, $agencyData['username'], $agencyData['password'], $agencyData['contactName'], $agencyData['userEmail'], $agencyData['language'], $oAgency->accountId); if ($userId) { // Link the user and give permission to create new accounts $aAllowedPermissions = array(OA_PERM_SUPER_ACCOUNT => 'This string intentionally left blank. WTF?'); $aPermissions = array(OA_PERM_SUPER_ACCOUNT); OA_Permission::setAccountAccess($oAgency->accountId, $userId); OA_Permission::storeUserAccountsPermissions($aPermissions, $oAgency->accountId, $userId, $aAllowedPermissions); } } } else { $doAgency->get($agencyData['agencyId']); $doAgency->setFrom($agencyData); $doAgency->update(); } return true; } else { return false; } }
function _setAccountsAndPermissions($userId, $accountPermissions) { foreach ($accountPermissions as $accountId => $aPermissions) { OA_Permission::setAccountAccess($accountId, $userId); OA_Permission::storeUserAccountsPermissions($aPermissions, $accountId, $userId); } }
/** * Links user with account and set apropriate messages. * Common method reused across user access pages * * @param integer $userId User ID * @param integer $accountId Account ID * @param array $permissions Array of permissions * @param array $aAllowedPermissions Array of allowed permissions */ function linkUserToAccount($userId, $accountId, $permissions, $aAllowedPermissions) { if (!empty($userId)) { if (!OA_Permission::isUserLinkedToAccount($accountId, $userId)) { OA_Session::setMessage($GLOBALS['strUserLinkedToAccount']); } else { OA_Session::setMessage($GLOBALS['strUserAccountUpdated']); } OA_Permission::setAccountAccess($accountId, $userId); OA_Permission::storeUserAccountsPermissions($permissions, $accountId, $userId, $aAllowedPermissions); } }