本文整理汇总了PHP中SJB_UserManager::activateUserByUserName方法的典型用法代码示例。如果您正苦于以下问题:PHP SJB_UserManager::activateUserByUserName方法的具体用法?PHP SJB_UserManager::activateUserByUserName怎么用?PHP SJB_UserManager::activateUserByUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SJB_UserManager
的用法示例。
在下文中一共展示了SJB_UserManager::activateUserByUserName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$tp = SJB_System::getTemplateProcessor();
$errors = array();
$activated = SJB_Request::getVar('account_activated', '') == 'yes';
if (SJB_Request::getVar('returnToShoppingCart', false)) {
SJB_Session::setValue('fromAnonymousShoppingCart', 1);
}
if (!$activated) {
if (!isset($_REQUEST['username'], $_REQUEST['activation_key'])) {
$errors['PARAMETERS_MISSED'] = 1;
} elseif (!($userInfo = SJB_UserManager::getUserInfoByUserName($_REQUEST['username']))) {
$errors['USER_NOT_FOUND'] = 1;
} elseif ($userInfo['activation_key'] != $_REQUEST['activation_key']) {
$errors['INVALID_ACTIVATION_KEY'] = true;
} elseif ($userInfo['approval'] == 'Rejected') {
SJB_UserDBManager::deleteActivationKeyByUsername($_REQUEST['username']);
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/system/users/activate_account/?account_activated=no&approval_status=Rejected');
} else {
if (SJB_UserManager::activateUserByUserName($_REQUEST['username'])) {
SJB_UserDBManager::deleteActivationKeyByUsername($_REQUEST['username']);
if (!SJB_Authorization::isUserLoggedIn()) {
SJB_Authorization::login($_REQUEST['username'], false, false, $errors, true, true);
if (!SJB_SocialPlugin::getProfileSocialID($userInfo['sid'])) {
SJB_Notifications::sendUserWelcomeLetter($userInfo['sid']);
}
$requireApprove = SJB_UserGroupManager::isApproveByAdmin($userInfo['user_group_sid']);
if ($requireApprove && !empty($userInfo['approval'])) {
$approvalStatus = $userInfo['approval'];
} else {
$userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
$pageId = !empty($userGroupInfo['after_registration_redirect_to']) ? $userGroupInfo['after_registration_redirect_to'] : '';
$redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
SJB_HelperFunctions::redirect($redirectUrl . 'account_activated=yes');
}
}
$activated = 1;
} else {
$errors['CANNOT_ACTIVATE'] = TRUE;
}
}
}
$tp->assign('activated', $activated);
$tp->assign('errors', $errors);
$tp->assign('approvalStatus', !empty($approvalStatus) ? $approvalStatus : SJB_Request::getVar('approval_status', ''));
$tp->assign('isLoggedIn', SJB_Authorization::isUserLoggedIn());
$tp->display('activate_account.tpl');
}
示例2: execute
public function execute()
{
$tp = SJB_System::getTemplateProcessor();
$errors = array();
$template = 'sub_accounts.tpl';
$currentUserInfo = SJB_UserManager::getCurrentUserInfo();
$listSubusers = false;
if (!empty($currentUserInfo['subuser']) && SJB_Request::getVar('action_name') != 'edit' && SJB_Request::getVar('user_id', 0) != $currentUserInfo['subuser']['sid']) {
$errors['ACCESS_DENIED'] = 'ACCESS_DENIED';
}
switch (SJB_Request::getVar('action_name')) {
case 'new':
$form_submitted = SJB_Request::getMethod() === SJB_Request::METHOD_POST;
$user_group_sid = $currentUserInfo['user_group_sid'];
$user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
$_REQUEST['user_group_id'] = $user_group_info['id'];
$user = SJB_ObjectMother::createUser($_REQUEST, $user_group_sid);
$props = $user->getProperties();
$allowedProperties = array('username', 'email', 'password');
foreach ($props as $prop) {
if (!in_array($prop->getID(), $allowedProperties)) {
$user->deleteProperty($prop->getID());
}
}
$registration_form = SJB_ObjectMother::createForm($user);
$registration_form->registerTags($tp);
if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid) && $form_submitted) {
$email = $user->getPropertyValue('email');
if (is_array($email)) {
$email = $email['original'];
}
$user->setPropertyValue('username', $email);
}
$registration_form = SJB_ObjectMother::createForm($user);
if ($form_submitted && $registration_form->isDataValid($errors)) {
$user->addParentProperty($currentUserInfo['sid']);
$subuserPermissions = array('subuser_add_listings' => array('title' => 'Add new listings', 'value' => 'deny'), 'subuser_manage_listings' => array('title' => 'Manage listings and applications of other sub users', 'value' => 'deny'), 'subuser_manage_subscription' => array('title' => 'View and update subscription', 'value' => 'deny'), 'subuser_use_screening_questionnaires' => array('title' => 'Manage Questionnaries', 'value' => 'deny'));
SJB_UserManager::saveUser($user);
SJB_Statistics::addStatistics('addSubAccount', $user->getUserGroupSID(), $user->getSID());
SJB_Acl::clearPermissions('user', $user->getSID());
foreach ($subuserPermissions as $permissionID => $permission) {
$allowDeny = SJB_Request::getVar($permissionID, 'deny');
$subuserPermissions[$permissionID]['value'] = $allowDeny;
SJB_Acl::allow($permissionID, 'user', $user->getSID(), $allowDeny);
}
SJB_UserManager::activateUserByUserName($user->getUserName());
SJB_Notifications::sendSubuserRegistrationLetter($user, SJB_Request::get(), $subuserPermissions);
$tp->assign('isSubuserRegistered', true);
$listSubusers = true;
} else {
if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid)) {
$user->deleteProperty("username");
}
$registration_form = SJB_ObjectMother::createForm($user);
if ($form_submitted) {
$registration_form->isDataValid($errors);
}
$registration_form->registerTags($tp);
$form_fields = $registration_form->getFormFieldsInfo();
$user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
$tp->assign("user_group_info", $user_group_info);
$tp->assign("errors", $errors);
$tp->assign("form_fields", $form_fields);
$metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
$tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
$tp->display('subuser_registration_form.tpl');
}
break;
case 'edit':
$userInfo = SJB_UserManager::getUserInfoBySID(SJB_Request::getVar('user_id', 0));
if (!empty($userInfo) && $userInfo['parent_sid'] === $currentUserInfo['sid']) {
$userInfo = array_merge($userInfo, $_REQUEST);
$user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($currentUserInfo['user_group_sid']);
$user = new SJB_User($userInfo, $userInfo['user_group_sid']);
$user->setSID($userInfo['sid']);
$user->addParentProperty($currentUserInfo['sid']);
$props = $user->getProperties();
$allowedProperties = array('username', 'email', 'password');
foreach ($props as $prop) {
if (!in_array($prop->getID(), $allowedProperties)) {
$user->deleteProperty($prop->getID());
}
}
$user->makePropertyNotRequired("password");
$edit_profile_form = SJB_ObjectMother::createForm($user);
$edit_profile_form->registerTags($tp);
$edit_profile_form->makeDisabled("username");
$form_submitted = SJB_Request::getMethod() == SJB_Request::METHOD_POST;
if (empty($errors) && $form_submitted && $edit_profile_form->isDataValid($errors)) {
$password_value = $user->getPropertyValue('password');
if (empty($password_value['original'])) {
$user->deleteProperty('password');
}
$currentUser = SJB_UserManager::getCurrentUser();
if (!$currentUser->isSubuser()) {
$subuserPermissions = array('subuser_add_listings', 'subuser_manage_listings', 'subuser_manage_subscription', 'subuser_use_screening_questionnaires');
SJB_Acl::clearPermissions('user', $user->getSID());
foreach ($subuserPermissions as $permission) {
SJB_Acl::allow($permission, 'user', $user->getSID(), SJB_Request::getVar($permission, 'deny'));
}
//.........这里部分代码省略.........
示例3: execute
public function execute()
{
$tp = SJB_System::getTemplateProcessor();
$tp->assign('terms_of_use_check', SJB_System::getSettingByName('terms_of_use_check'));
$user_group_id = SJB_Request::getVar('user_group_id', null);
$form_submitted = isset($_REQUEST['action']) && $_REQUEST['action'] == 'register';
if (!is_null($user_group_id)) {
$user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id);
/**
* check if registration is allowed for this UserGroup
*/
if (!SJB_SocialPlugin::ifRegistrationIsAllowedByUserGroupSID($user_group_sid)) {
return null;
}
$user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
$user = SJB_ObjectMother::createUser($_REQUEST, $user_group_sid);
$user->deleteProperty('active');
$user->deleteProperty('featured');
$errors = array();
// social plugin
if ($form_submitted) {
SJB_Event::dispatch('SocialPlugin_AddListingFieldsIntoRegistration', $user, true);
SJB_Event::dispatch('MakeRegistrationFieldsNotRequired_SocialPlugin', $user, true);
} else {
SJB_Event::dispatch('PrepareRegistrationFields_SocialPlugin', $user, true);
SJB_Event::dispatch('SocialPlugin_AddListingFieldsIntoRegistration', $user, true);
SJB_Event::dispatch('FillRegistrationData_Plugin', $user, true);
}
$registration_form = SJB_ObjectMother::createForm($user);
$registration_form->registerTags($tp);
if ($form_submitted && $registration_form->isDataValid($errors)) {
SJB_Event::dispatch('FillRegistrationData_Plugin', $user, true);
SJB_Event::dispatch('AddReferencePluginDetails', $user, true);
$user->deleteProperty('captcha');
$user->deleteProperty('active');
$user->deleteProperty('featured');
SJB_UserManager::saveUser($user);
SJB_Statistics::addStatistics('addUser', $user->getUserGroupSID(), $user->getSID(), false, 0, 0, false, 0, SJB_SocialPlugin::getNetwork());
SJB_Statistics::addStatistics('addUser' . SJB_SocialPlugin::getNetwork(), $user->getUserGroupSID(), $user->getSID(), false, 0, 0, false, 0, SJB_SocialPlugin::getNetwork());
// subscribe user on default product
$defaultProduct = SJB_UserGroupManager::getDefaultProduct($user_group_sid);
$availableProductIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($user_group_sid);
if ($defaultProduct && in_array($defaultProduct, $availableProductIDs)) {
$contract = new SJB_Contract(array('product_sid' => $defaultProduct));
$contract->setUserSID($user->getSID());
$contract->saveInDB();
}
SJB_SocialPlugin::sendUserSocialRegistrationLetter($user);
// notify administrator
SJB_AdminNotifications::sendAdminUserRegistrationLetter($user);
// Activation
$isSendActivationEmail = SJB_UserGroupManager::isSendActivationEmail($user_group_sid);
$isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid);
if ($isApproveByAdmin) {
SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
}
if ($isSendActivationEmail) {
$isSent = SJB_Notifications::sendUserActivationLetter($user->getSID());
if ($isSent) {
$tp->display('../users/registration_confirm.tpl');
} else {
$tp->display('../users/registration_failed_to_send_activation_email.tpl');
}
} else {
if (!$isSendActivationEmail && $isApproveByAdmin) {
SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
$tp->display('../users/registration_pending.tpl');
} else {
SJB_UserManager::activateUserByUserName($user->getUserName());
$errors = array();
SJB_Authorization::login($user->getUserName(), $user->getPropertyValue('password'), false, $errors, false);
// save access token, profile info for synchronization
SJB_SocialPlugin::postRegistration();
$tp->assign('socialNetwork', SJB_SocialPlugin::getNetwork());
$pageId = !empty($user_group_info['after_registration_redirect_to']) ? $user_group_info['after_registration_redirect_to'] : '';
$redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
SJB_HelperFunctions::redirect($redirectUrl);
}
}
} else {
// social plugin
SJB_Event::dispatch('PrepareRegistrationFields_SocialPlugin', $user, true);
if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid)) {
$user->deleteProperty('username');
}
$registration_form = SJB_ObjectMother::createForm($user);
if ($form_submitted) {
$registration_form->isDataValid($errors);
}
$registration_form->registerTags($tp);
$registration_form_template = '../users/registration_form.tpl';
if (isset($_REQUEST['reg_form_template'])) {
$registration_form_template = $_REQUEST['reg_form_template'];
} elseif (!empty($user_group_info['reg_form_template'])) {
$registration_form_template = $user_group_info['reg_form_template'];
}
$form_fields = $registration_form->getFormFieldsInfo();
$user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
$tp->assign('user_group_info', $user_group_info);
$tp->assign('errors', $errors);
//.........这里部分代码省略.........
示例4: execute
public function execute()
{
$tp = SJB_System::getTemplateProcessor();
$template = SJB_Request::getVar('template', 'users.tpl');
$searchTemplate = SJB_Request::getVar('search_template', 'user_search_form.tpl');
$passedParametersViaUri = SJB_UrlParamProvider::getParams();
$userGroupID = $passedParametersViaUri ? array_shift($passedParametersViaUri) : false;
$userGroupSID = $userGroupID ? SJB_UserGroupManager::getUserGroupSIDByID($userGroupID) : null;
$errors = array();
/********** A C T I O N S W I T H U S E R S **********/
$action = SJB_Request::getVar('action_name');
if (!empty($action)) {
$users_sids = SJB_Request::getVar('users', array());
$_REQUEST['restore'] = 1;
switch ($action) {
case 'approve':
foreach ($users_sids as $user_sid => $value) {
$username = SJB_UserManager::getUserNameByUserSID($user_sid);
SJB_UserManager::setApprovalStatusByUserName($username, 'Approved');
SJB_UserManager::activateUserByUserName($username);
SJB_UserDBManager::deleteActivationKeyByUsername($username);
if (!SJB_SocialPlugin::getProfileSocialID($user_sid)) {
SJB_Notifications::sendUserWelcomeLetter($user_sid);
} else {
SJB_Notifications::sendUserApprovedLetter($user_sid);
}
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
break;
case 'reject':
$rejection_reason = SJB_Request::getVar('rejection_reason', '');
foreach ($users_sids as $user_sid => $value) {
$username = SJB_UserManager::getUserNameByUserSID($user_sid);
SJB_UserManager::setApprovalStatusByUserName($username, 'Rejected', $rejection_reason);
SJB_UserManager::deactivateUserByUserName($username);
SJB_Notifications::sendUserRejectedLetter($user_sid);
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
break;
case 'activate':
foreach ($users_sids as $user_sid => $value) {
$username = SJB_UserManager::getUserNameByUserSID($user_sid);
$userinfo = SJB_UserManager::getUserInfoByUserName($username);
SJB_UserManager::activateUserByUserName($username);
if ($userinfo['approval'] == 'Approved') {
SJB_UserDBManager::deleteActivationKeyByUsername($username);
SJB_Notifications::sendUserApprovedLetter($user_sid);
}
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
break;
case 'deactivate':
foreach ($users_sids as $user_sid => $value) {
$username = SJB_UserManager::getUserNameByUserSID($user_sid);
SJB_UserManager::deactivateUserByUserName($username);
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
break;
case 'delete':
foreach (array_keys($users_sids) as $user_sid) {
try {
SJB_UserManager::deleteUserById($user_sid);
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
break;
case 'send_activation_letter':
foreach ($users_sids as $user_sid => $value) {
SJB_Notifications::sendUserActivationLetter($user_sid);
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
break;
case 'change_product':
$productToChange = SJB_Request::getVar('product_to_change');
if (empty($productToChange)) {
$productToChange = 0;
}
foreach ($users_sids as $user_sid => $value) {
$user = SJB_UserManager::getObjectBySID($user_sid);
// UNSUBSCRIBE selected
if ($productToChange == 0) {
SJB_ContractManager::deleteAllContractsByUserSID($user_sid);
} else {
$productInfo = SJB_ProductsManager::getProductInfoBySID($productToChange);
$listingNumber = SJB_Request::getVar('number_of_listings', null);
if (is_null($listingNumber) && !empty($productInfo['number_of_listings'])) {
$listingNumber = $productInfo['number_of_listings'];
}
$contract = new SJB_Contract(array('product_sid' => $productToChange, 'numberOfListings' => $listingNumber, 'is_recurring' => 0));
$contract->setUserSID($user_sid);
$contract->saveInDB();
if ($contract->isFeaturedProfile()) {
SJB_UserManager::makeFeaturedBySID($user_sid);
}
}
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
break;
//.........这里部分代码省略.........
示例5: execute
//.........这里部分代码省略.........
case 'video':
case 'file':
// change temporary file ID
SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
// set value of user property to new uploaded file
$user->setPropertyValue($fieldId, $profilePropertyId);
break;
case 'logo':
// change temporary file ID and thumb ID
SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
// set value of user property to new uploaded file
$user->setPropertyValue($fieldId, $profilePropertyId);
break;
default:
break;
}
$tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
}
// save user with new values
SJB_UserManager::saveUser($user);
// clean temporary storage
$tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
// CLEAR TEMPORARY SESSION STORAGE
SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
}
}
// <<< SJB-1197
// notifying administrator
SJB_AdminNotifications::sendAdminUserRegistrationLetter($user);
// Activation
$isSendActivationEmail = SJB_UserGroupManager::isSendActivationEmail($user_group_sid);
$isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid);
if ($isApproveByAdmin) {
SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
}
if ($isSendActivationEmail) {
$fromAnonymousShoppingCart = SJB_Session::getValue('fromAnonymousShoppingCart');
SJB_Session::unsetValue('fromAnonymousShoppingCart');
$isSent = SJB_Notifications::sendUserActivationLetter($user->getSID(), $fromAnonymousShoppingCart ? true : false);
if ($isSent) {
$registration_form_template = 'registration_confirm.tpl';
} else {
SJB_FlashMessages::getInstance()->addWarning('ERROR_SEND_ACTIVATION_EMAIL');
$registration_form_template = 'registration_failed_to_send_activation_email.tpl';
}
} else {
if (!$isSendActivationEmail && $isApproveByAdmin) {
SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
$registration_form_template = 'registration_pending.tpl';
} else {
SJB_UserManager::activateUserByUserName($user->getUserName());
if (!SJB_SocialPlugin::getProfileSocialID($user->getSID())) {
SJB_Notifications::sendUserWelcomeLetter($user->getSID());
}
SJB_Authorization::login($user->getUserName(), $_REQUEST['password']['original'], false, $errors);
$proceedToPosting = SJB_Session::getValue('proceed_to_posting');
if ($proceedToPosting) {
$redirectUrl = SJB_HelperFunctions::getSiteUrl() . '/add-listing/?listing_type_id=' . SJB_Session::getValue('listing_type_id') . '&proceed_to_posting=' . $proceedToPosting . '&productSID=' . SJB_Session::getValue('productSID');
} else {
$pageId = !empty($user_group_info['after_registration_redirect_to']) ? $user_group_info['after_registration_redirect_to'] : '';
$redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
}
SJB_HelperFunctions::redirect($redirectUrl);
}
}
} else {
if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid)) {
$user->deleteProperty('username');
}
$registration_form = SJB_ObjectMother::createForm($user);
$registration_form->registerTags($tp);
$registration_form_template = 'registration_form.tpl';
if (isset($_REQUEST['reg_form_template'])) {
$registration_form_template = $_REQUEST['reg_form_template'];
} elseif (!empty($user_group_info['reg_form_template'])) {
$registration_form_template = $user_group_info['reg_form_template'];
}
$form_fields = $registration_form->getFormFieldsInfo();
// define default template with ajax checking
$registration_form->setDefaultTemplateByFieldName('email', 'email_ajaxchecking.tpl');
$registration_form->setDefaultTemplateByFieldName('username', 'unique_string.tpl');
// use specific template for user profile video
$registration_form->setDefaultTemplateByFieldName('video', 'video_profile.tpl');
$user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
$tp->assign('user_group_info', $user_group_info);
$tp->assign('errors', $errors);
$tp->assign('form_fields', $form_fields);
$metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
$tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
}
} else {
$registration_form_template = 'registration_choose_user_group.tpl';
$user_groups_info = SJB_UserGroupManager::getAllUserGroupsInfo();
$tp->assign('user_groups_info', $user_groups_info);
}
$tp->assign('userTree', true);
$tp->assign('errors', $errors);
$tp->display($registration_form_template);
}
示例6: execute
public function execute()
{
$tp = SJB_System::getTemplateProcessor();
$extUserID = SJB_Request::getVar('extUserID', null);
$passedParametersViaUri = SJB_UrlParamProvider::getParams();
$userGroupID = $passedParametersViaUri ? array_shift($passedParametersViaUri) : false;
if (!$userGroupID) {
$userGroupsInfo = SJB_UserGroupManager::getAllUserGroupsInfo();
$tp->assign('user_groups_info', $userGroupsInfo);
$tp->display('add_user_choose_user_group.tpl');
} else {
$userGroupSID = SJB_UserGroupManager::getUserGroupSIDByID($userGroupID);
$userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userGroupSID);
$user = SJB_ObjectMother::createUser($_REQUEST, $userGroupSID);
$user->deleteProperty('active');
$user->addExtUserIDProperty($extUserID);
$registration_form = SJB_ObjectMother::createForm($user);
$registration_form->registerTags($tp);
$form_submitted = SJB_Request::getVar('action', '') == 'add';
$errors = array();
if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($userGroupSID) && $form_submitted) {
$email = $user->getPropertyValue('email');
if (is_array($email)) {
$email = $email['original'];
}
$user->setPropertyValue('username', $email);
}
if ($form_submitted && $registration_form->isDataValid($errors)) {
SJB_UserManager::saveUser($user);
// >>> SJB-1197
// needs to check session for ajax-uploaded files, and set it to user profile
$tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
$formToken = SJB_Request::getVar('form_token');
if (!empty($formToken)) {
$tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken);
if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) {
// prepare user profile fields array
$userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo();
$userProfileFields = array();
foreach ($userProfileFieldsInfo as $field) {
$userProfileFields[$field['id']] = $field;
}
// look for temporary values
foreach ($tmpUploadedFields as $fieldId => $fieldInfo) {
// check field ID for valid ID in user profile fields
if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) {
continue;
}
$fieldType = $userProfileFields[$fieldId]['type'];
$profilePropertyId = $fieldId . '_' . $user->getSID();
switch (strtolower($fieldType)) {
case 'video':
case 'file':
// change temporary file ID
SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
// set value of user property to new uploaded file
$user->setPropertyValue($fieldId, $profilePropertyId);
break;
case 'logo':
// change temporary file ID and thumb ID
SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
// set value of user property to new uploaded file
$user->setPropertyValue($fieldId, $profilePropertyId);
break;
default:
break;
}
$tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
}
// and save user with new fields data
SJB_UserManager::saveUser($user);
// clean temporary storage
$tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
// CLEAR TEMPORARY SESSION STORAGE
SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
}
}
// <<< SJB-1197
SJB_UserManager::activateUserByUserName($user->getUserName());
$defaultProduct = SJB_UserGroupManager::getDefaultProduct($userGroupSID);
$availableProductIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userGroupSID);
if ($defaultProduct && in_array($defaultProduct, $availableProductIDs)) {
$contract = new SJB_Contract(array('product_sid' => $defaultProduct));
$contract->setUserSID($user->getSID());
$contract->saveInDB();
}
SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-users/" . mb_strtolower($userGroupInfo['id'], 'utf8'));
} else {
if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($userGroupSID)) {
$user->deleteProperty('username');
}
$registration_form = SJB_ObjectMother::createForm($user);
$registration_form->registerTags($tp);
$tp->assign("errors", $errors);
$tp->assign("user_group", $userGroupInfo);
$tp->assign('userTree', true);
$tp->assign("form_fields", $registration_form->getFormFieldsInfo());
$tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
$tp->display("add_user.tpl");
//.........这里部分代码省略.........