public static function renderListTypeSelect($uniqName, $fieldName, $value) { $language = OW::getLanguage(); $field = new Selectbox($fieldName); $uniqId = uniqid("select-list-"); $field->setId($uniqId); $field->setOptions(array('latest' => $language->text('ucarousel', 'widget_list_type_latest'), 'recently' => $language->text('ucarousel', 'widget_list_type_recently'), 'online' => $language->text('ucarousel', 'widget_list_type_online'), 'featured' => $language->text('ucarousel', 'widget_list_type_featured'), 'by_role' => $language->text('ucarousel', 'widget_list_type_by_role'), 'by_account_type' => $language->text('ucarousel', 'widget_list_type_by_account_type'))); $field->setValue($value); if ($value != "by_role") { OW::getDocument()->addOnloadScript('$("#uc-role-setting").parents("tr:eq(0)").hide();'); } if ($value != "by_account_type") { OW::getDocument()->addOnloadScript('$("#uc-account-type-setting").parents("tr:eq(0)").hide();'); } OW::getDocument()->addOnloadScript('$("#' . $uniqId . '").change(function() { ' . '$("#uc-role-setting").parents("tr:eq(0)").hide(); ' . '$("#uc-account-type-setting").parents("tr:eq(0)").hide(); ' . 'if ($(this).val() == "by_role") $("#uc-role-setting").parents("tr:eq(0)").show(); ' . 'if ($(this).val() == "by_account_type") $("#uc-account-type-setting").parents("tr:eq(0)").show(); ' . ' })'); return $field->renderInput(); }
public function index($params) { $adminMode = false; $oneAccountType = false; $viewerId = OW::getUser()->getId(); if (!OW::getUser()->isAuthenticated() || $viewerId === null) { throw new AuthenticateException(); } if (!empty($params['userId']) && $params['userId'] != $viewerId) { if (OW::getUser()->isAdmin() || OW::getUser()->isAuthorized('base')) { $adminMode = true; $userId = (int) $params['userId']; $user = BOL_UserService::getInstance()->findUserById($userId); if (empty($user) || BOL_AuthorizationService::getInstance()->isSuperModerator($userId)) { throw new Redirect404Exception(); } $editUserId = $userId; } else { throw new Redirect403Exception(); } } else { $editUserId = $viewerId; $changePassword = new BASE_CMP_ChangePassword(); $this->addComponent("changePassword", $changePassword); $contentMenu = new BASE_CMP_DashboardContentMenu(); $contentMenu->getElement('profile_edit')->setActive(true); $this->addComponent('contentMenu', $contentMenu); $user = OW::getUser()->getUserObject(); //BOL_UserService::getInstance()->findUserById($editUserId); } $accountType = $user->accountType; // dispaly account type if (OW::getUser()->isAdmin() || OW::getUser()->isAuthorized('base')) { $accountType = !empty($_GET['accountType']) ? $_GET['accountType'] : $user->accountType; // get available account types from DB $accountTypes = BOL_QuestionService::getInstance()->findAllAccountTypes(); $accounts = array(); if (count($accountTypes) > 1) { /* @var $value BOL_QuestionAccount */ foreach ($accountTypes as $key => $value) { $accounts[$value->name] = OW::getLanguage()->text('base', 'questions_account_type_' . $value->name); } if (!in_array($accountType, array_keys($accounts))) { if (in_array($user->accountType, array_keys($accounts))) { $accountType = $user->accountType; } else { $accountType = BOL_QuestionService::getInstance()->getDefaultAccountType()->name; } } $editAccountType = new Selectbox('accountType'); $editAccountType->setId('accountType'); $editAccountType->setLabel(OW::getLanguage()->text('base', 'questions_question_account_type_label')); $editAccountType->setRequired(); $editAccountType->setOptions($accounts); $editAccountType->setHasInvitation(false); } else { $accountType = BOL_QuestionService::getInstance()->getDefaultAccountType()->name; } } $language = OW::getLanguage(); $this->setPageHeading($language->text('base', 'edit_index')); $this->setPageHeadingIconClass('ow_ic_user'); // -- Edit form -- $editForm = new EditQuestionForm('editForm', $editUserId); $editForm->setId('editForm'); $this->assign('displayAccountType', false); // dispaly account type if (!empty($editAccountType)) { $editAccountType->setValue($accountType); $editForm->addElement($editAccountType); OW::getDocument()->addOnloadScript(" \$('#accountType').change(function() {\n\n var form = \$(\"<form method='get'><input type='text' name='accountType' value='\" + \$(this).val() + \"' /></form>\");\n \$('body').append(form);\n \$(form).submit();\n\n } ); "); $this->assign('displayAccountType', true); } $editSubmit = new Submit('editSubmit'); $editSubmit->addAttribute('class', 'ow_button ow_ic_save'); $editSubmit->setValue($language->text('base', 'edit_button')); $editForm->addElement($editSubmit); $questions = $this->questionService->findEditQuestionsForAccountType($accountType); $section = null; $questionArray = array(); $questionNameList = array(); // echo '<pre>'; // print_r($questions); // echo '</pre>'; $userData = BOL_QuestionService::getInstance()->getQuestionData(array($editUserId), array(HAMMU_DB_IM_USING_HAMMU_AS_KEY)); $im_using_hammu_as = $userData[$editUserId][HAMMU_DB_IM_USING_HAMMU_AS_KEY]; foreach ($questions as $sort => $question) { if ($section !== $question['sectionName']) { $section = $question['sectionName']; } $questionArray[$section][$sort] = $questions[$sort]; $questionNameList[] = $questions[$sort]['name']; } echo "user->" . $editUserId; $this->assign('questionArray', $questionArray); $questionData = $this->questionService->getQuestionData(array($editUserId), $questionNameList); $questionValues = $this->questionService->findQuestionsValuesByQuestionNameList($questionNameList); $editForm->addQuestions($questions, $questionValues, !empty($questionData[$editUserId]) ? $questionData[$editUserId] : array()); if (OW::getRequest()->isPost() && isset($_POST['editSubmit'])) { if ($editForm->isValid($_POST)) { $data = $editForm->getValues(); foreach ($questionArray as $section) { foreach ($section as $key => $question) { switch ($question['presentation']) { case 'multicheckbox': if (is_array($data[$question['name']])) { $data[$question['name']] = array_sum($data[$question['name']]); } else { $data[$question['name']] = 0; } break; } } } // save user data if (!empty($user->id)) { if ($this->questionService->saveQuestionsData($data, $user->id)) { if (!$adminMode) { $event = new OW_Event(OW_EventManager::ON_USER_EDIT, array('userId' => $user->id, 'method' => 'native')); OW::getEventManager()->trigger($event); OW::getFeedback()->info($language->text('base', 'edit_successfull_edit')); $this->redirect(); } else { $event = new OW_Event(OW_EventManager::ON_USER_EDIT_BY_ADMIN, array('userId' => $user->id)); OW::getEventManager()->trigger($event); OW::getFeedback()->info($language->text('base', 'edit_successfull_edit')); $this->redirect(OW::getRouter()->urlForRoute('base_user_profile', array('username' => BOL_UserService::getInstance()->getUserName($editUserId)))); } } else { OW::getFeedback()->info($language->text('base', 'edit_edit_error')); } } else { OW::getFeedback()->info($language->text('base', 'edit_edit_error')); } } } $this->addForm($editForm); $this->assign('unregisterProfileUrl', OW::getRouter()->urlForRoute('base_delete_user')); $language->addKeyForJs('base', 'join_error_username_not_valid'); $language->addKeyForJs('base', 'join_error_username_already_exist'); $language->addKeyForJs('base', 'join_error_email_not_valid'); $language->addKeyForJs('base', 'join_error_email_already_exist'); $language->addKeyForJs('base', 'join_error_password_not_valid'); $language->addKeyForJs('base', 'join_error_password_too_short'); $language->addKeyForJs('base', 'join_error_password_too_long'); //include js $onLoadJs = " window.edit = new OW_BaseFieldValidators( " . json_encode(array('formName' => $editForm->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Edit", "ajaxResponder"))) . ",\n " . UTIL_Validator::EMAIL_PATTERN . ", " . UTIL_Validator::USER_NAME_PATTERN . ", " . $editUserId . " ); "; $this->assign('isAdmin', OW::getUser()->isAdmin()); OW::getDocument()->addOnloadScript($onLoadJs); $jsDir = OW::getPluginManager()->getPlugin("base")->getStaticJsUrl(); OW::getDocument()->addScript($jsDir . "base_field_validators.js"); if (!$adminMode) { $editSynchronizeHook = OW::getRegistry()->getArray(self::EDIT_SYNCHRONIZE_HOOK); if (!empty($editSynchronizeHook)) { $content = array(); foreach ($editSynchronizeHook as $function) { $result = call_user_func($function); if (trim($result)) { $content[] = $result; } } $content = array_filter($content, 'trim'); if (!empty($content)) { $this->assign('editSynchronizeHook', $content); } } } }
public function __construct($entityType, $actions, $features, $info) { parent::__construct("HINT_ConfigurationForm"); $language = OW::getLanguage(); $this->actions = $actions; $this->entityType = $entityType; // Actions foreach ($actions as $action) { $field = new CheckboxField("action-" . $action["key"]); $field->setId("action-" . $action["key"]); $field->addAttribute("data-key", $action["key"]); $field->setValue($action["active"]); $field->setLabel($action["label"]); $field->addAttribute("class", "h-refresher"); $this->addElement($field); } // Additional Features $field = new CheckboxField("uheader_enabled"); $field->setId("feature_uheader"); $field->setValue($features["cover"]); $field->addAttribute("class", "h-refresher"); $field->addAttribute("data-key", "cover"); $this->addElement($field); // User Information $line0Options = HINT_BOL_Service::getInstance()->getInfoLineSettings($entityType, HINT_BOL_Service::INFO_LINE0); $field = new Selectbox("info_" . HINT_BOL_Service::INFO_LINE0); $field->setId("info0"); foreach ($line0Options as $lineOption) { $field->addOption($lineOption["key"], $lineOption["label"]); } if (!empty($info[HINT_BOL_Service::INFO_LINE0]["key"])) { $field->setValue($info[HINT_BOL_Service::INFO_LINE0]["key"]); } $this->addElement($field); $questions = $this->findQuestions(); $questionOptions = array(); foreach ($questions as $question) { $questionOptions[$question->name] = BOL_QuestionService::getInstance()->getQuestionLang($question->name); } $field = new Selectbox("info_" . HINT_BOL_Service::INFO_LINE0 . "_question"); $field->setId("info0_q"); $field->setOptions($questionOptions); if (!empty($info[HINT_BOL_Service::INFO_LINE0]["question"])) { $field->setValue($info[HINT_BOL_Service::INFO_LINE0]["question"]); } $this->addElement($field); $line1Options = HINT_BOL_Service::getInstance()->getInfoLineSettings($entityType, HINT_BOL_Service::INFO_LINE1); $field = new Selectbox("info_" . HINT_BOL_Service::INFO_LINE1); $field->setId("info1"); foreach ($line1Options as $lineOption) { $field->addOption($lineOption["key"], $lineOption["label"]); } if (!empty($info[HINT_BOL_Service::INFO_LINE1]["key"])) { $field->setValue($info[HINT_BOL_Service::INFO_LINE1]["key"]); } $this->addElement($field); $field = new Selectbox("info_" . HINT_BOL_Service::INFO_LINE1 . "_question"); $field->setId("info1_q"); $field->setOptions($questionOptions); if (!empty($info[HINT_BOL_Service::INFO_LINE1]["question"])) { $field->setValue($info[HINT_BOL_Service::INFO_LINE1]["question"]); } $this->addElement($field); $line2Options = HINT_BOL_Service::getInstance()->getInfoLineSettings($entityType, HINT_BOL_Service::INFO_LINE2); $field = new Selectbox("info_" . HINT_BOL_Service::INFO_LINE2); $field->setId("info2"); foreach ($line2Options as $lineOption) { $field->addOption($lineOption["key"], $lineOption["label"]); } if (!empty($info[HINT_BOL_Service::INFO_LINE2]["key"])) { $field->setValue($info[HINT_BOL_Service::INFO_LINE2]["key"]); } $this->addElement($field); $field = new Selectbox("info_" . HINT_BOL_Service::INFO_LINE2 . "_question"); $field->setId("info2_q"); $field->setOptions($questionOptions); if (!empty($info[HINT_BOL_Service::INFO_LINE2]["question"])) { $field->setValue($info[HINT_BOL_Service::INFO_LINE2]["question"]); } $this->addElement($field); // submit $submit = new Submit('save'); $submit->setValue($language->text('hint', 'admin_save_btn')); $this->addElement($submit); }
public function index($params) { $adminMode = false; $viewerId = OW::getUser()->getId(); if (!OW::getUser()->isAuthenticated() || $viewerId === null) { throw new AuthenticateException(); } if (!empty($params['userId']) && $params['userId'] != $viewerId) { if (OW::getUser()->isAdmin() || OW::getUser()->isAuthorized('base')) { $adminMode = true; $userId = (int) $params['userId']; $user = BOL_UserService::getInstance()->findUserById($userId); if (empty($user) || BOL_AuthorizationService::getInstance()->isSuperModerator($userId)) { throw new Redirect404Exception(); } $editUserId = $userId; } else { throw new Redirect403Exception(); } } else { $editUserId = $viewerId; $changePassword = new BASE_CMP_ChangePassword(); $this->addComponent("changePassword", $changePassword); $contentMenu = new BASE_CMP_DashboardContentMenu(); $contentMenu->getElement('profile_edit')->setActive(true); $this->addComponent('contentMenu', $contentMenu); $user = OW::getUser()->getUserObject(); //BOL_UserService::getInstance()->findUserById($editUserId); } $changeList = BOL_PreferenceService::getInstance()->getPreferenceValue(self::PREFERENCE_LIST_OF_CHANGES, $editUserId); if (empty($changeList)) { $changeList = '[]'; } $this->assign('changeList', json_decode($changeList, true)); $isEditedUserModerator = BOL_AuthorizationService::getInstance()->isModerator($editUserId) || BOL_AuthorizationService::getInstance()->isSuperModerator($editUserId); $accountType = $user->accountType; // dispaly account type if (OW::getUser()->isAdmin() || OW::getUser()->isAuthorized('base')) { $accountType = !empty($_GET['accountType']) ? $_GET['accountType'] : $user->accountType; // get available account types from DB $accountTypes = BOL_QuestionService::getInstance()->findAllAccountTypes(); $accounts = array(); if (count($accountTypes) > 1) { /* @var $value BOL_QuestionAccount */ foreach ($accountTypes as $key => $value) { $accounts[$value->name] = OW::getLanguage()->text('base', 'questions_account_type_' . $value->name); } if (!in_array($accountType, array_keys($accounts))) { if (in_array($user->accountType, array_keys($accounts))) { $accountType = $user->accountType; } else { $accountType = BOL_QuestionService::getInstance()->getDefaultAccountType()->name; } } $editAccountType = new Selectbox('accountType'); $editAccountType->setId('accountType'); $editAccountType->setLabel(OW::getLanguage()->text('base', 'questions_question_account_type_label')); $editAccountType->setRequired(); $editAccountType->setOptions($accounts); $editAccountType->setHasInvitation(false); } else { $accountType = BOL_QuestionService::getInstance()->getDefaultAccountType()->name; } } $language = OW::getLanguage(); $this->setPageHeading($language->text('base', 'edit_index')); $this->setPageHeadingIconClass('ow_ic_user'); // -- Edit form -- $editForm = new EditQuestionForm('editForm', $editUserId); $editForm->setId('editForm'); $this->assign('displayAccountType', false); // dispaly account type if (!empty($editAccountType)) { $editAccountType->setValue($accountType); $editForm->addElement($editAccountType); OW::getDocument()->addOnloadScript(" \$('#accountType').change(function() {\n \n var form = \$(\"<form method='get'><input type='text' name='accountType' value='\" + \$(this).val() + \"' /></form>\");\n \$('body').append(form);\n \$(form).submit();\n\n } ); "); $this->assign('displayAccountType', true); } $userId = !empty($params['userId']) ? $params['userId'] : $viewerId; // add avatar field $editAvatar = OW::getClassInstance("BASE_CLASS_AvatarField", 'avatar', false); $editAvatar->setLabel(OW::getLanguage()->text('base', 'questions_question_user_photo_label')); $editAvatar->setValue(BOL_AvatarService::getInstance()->getAvatarUrl($userId, 1, null, true, false)); $displayPhotoUpload = OW::getConfig()->getValue('base', 'join_display_photo_upload'); // add the required avatar validator if ($displayPhotoUpload == BOL_UserService::CONFIG_JOIN_DISPLAY_AND_SET_REQUIRED_PHOTO_UPLOAD) { $avatarValidator = OW::getClassInstance("BASE_CLASS_AvatarFieldValidator", true, $userId); $editAvatar->addValidator($avatarValidator); } $editForm->addElement($editAvatar); $isUserApproved = BOL_UserService::getInstance()->isApproved($editUserId); $this->assign('isUserApproved', $isUserApproved); // add submit button $editSubmit = new Submit('editSubmit'); $editSubmit->addAttribute('class', 'ow_button ow_ic_save'); $editSubmit->setValue($language->text('base', 'edit_button')); if ($adminMode && !$isUserApproved) { $editSubmit->setName('saveAndApprove'); $editSubmit->setValue($language->text('base', 'save_and_approve')); // TODO: remove if (!$isEditedUserModerator) { // add delete button $script = UTIL_JsGenerator::newInstance()->jQueryEvent('input.delete_user_by_moderator', 'click', 'OW.Users.deleteUser(e.data.userId, e.data.callbackUrl, false);', array('e'), array('userId' => $userId, 'callbackUrl' => OW::getRouter()->urlForRoute('base_member_dashboard'))); OW::getDocument()->addOnloadScript($script); } } $editForm->addElement($editSubmit); // prepare question list $questions = $this->questionService->findEditQuestionsForAccountType($accountType); $section = null; $questionArray = array(); $questionNameList = array(); foreach ($questions as $sort => $question) { if ($section !== $question['sectionName']) { $section = $question['sectionName']; } $questionArray[$section][$sort] = $questions[$sort]; $questionNameList[] = $questions[$sort]['name']; } $this->assign('questionArray', $questionArray); $questionData = $this->questionService->getQuestionData(array($editUserId), $questionNameList); $questionValues = $this->questionService->findQuestionsValuesByQuestionNameList($questionNameList); // add question to form $editForm->addQuestions($questions, $questionValues, !empty($questionData[$editUserId]) ? $questionData[$editUserId] : array()); // process form if (OW::getRequest()->isPost()) { if (isset($_POST['editSubmit']) || isset($_POST['saveAndApprove'])) { $this->process($editForm, $user->id, $questionArray, $adminMode); } } $this->addForm($editForm); $deleteUrl = OW::getRouter()->urlForRoute('base_delete_user'); $this->assign('unregisterProfileUrl', $deleteUrl); // add langs to js $language->addKeyForJs('base', 'join_error_username_not_valid'); $language->addKeyForJs('base', 'join_error_username_already_exist'); $language->addKeyForJs('base', 'join_error_email_not_valid'); $language->addKeyForJs('base', 'join_error_email_already_exist'); $language->addKeyForJs('base', 'join_error_password_not_valid'); $language->addKeyForJs('base', 'join_error_password_too_short'); $language->addKeyForJs('base', 'join_error_password_too_long'); //include js $onLoadJs = " window.edit = new OW_BaseFieldValidators( " . json_encode(array('formName' => $editForm->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Edit", "ajaxResponder"))) . ",\n " . UTIL_Validator::EMAIL_PATTERN . ", " . UTIL_Validator::USER_NAME_PATTERN . ", " . $editUserId . " ); "; $this->assign('isAdmin', OW::getUser()->isAdmin()); $this->assign('isEditedUserModerator', $isEditedUserModerator); $this->assign('adminMode', $adminMode); $approveEnabled = OW::getConfig()->getValue('base', 'mandatory_user_approve'); $this->assign('approveEnabled', $approveEnabled); OW::getDocument()->addOnloadScript(' $("input.write_message_button").click( function() { OW.ajaxFloatBox("BASE_CMP_SendMessageToEmail", [' . (int) $editUserId . '], { title: ' . json_encode($language->text('base', 'send_message_to_email')) . ', width:600 }); } ); '); OW::getDocument()->addOnloadScript($onLoadJs); $jsDir = OW::getPluginManager()->getPlugin("base")->getStaticJsUrl(); OW::getDocument()->addScript($jsDir . "base_field_validators.js"); if (!$adminMode) { $editSynchronizeHook = OW::getRegistry()->getArray(self::EDIT_SYNCHRONIZE_HOOK); if (!empty($editSynchronizeHook)) { $content = array(); foreach ($editSynchronizeHook as $function) { $result = call_user_func($function); if (trim($result)) { $content[] = $result; } } $content = array_filter($content, 'trim'); if (!empty($content)) { $this->assign('editSynchronizeHook', $content); } } } }