public function __construct($conversationId, $opponentId)
 {
     parent::__construct('newMailMessageForm');
     $this->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA);
     $field = new TextField('newMessageText');
     $field->setValue(OW::getLanguage()->text('mailbox', 'text_message_invitation'));
     $field->setId('newMessageText');
     $this->addElement($field);
     $field = new HiddenField('attachment');
     $this->addElement($field);
     $field = new HiddenField('conversationId');
     $field->setValue($conversationId);
     $this->addElement($field);
     $field = new HiddenField('opponentId');
     $field->setValue($opponentId);
     $this->addElement($field);
     $field = new HiddenField('uid');
     $field->setValue(UTIL_HtmlTag::generateAutoId('mailbox_conversation_' . $conversationId . '_' . $opponentId));
     $this->addElement($field);
     $submit = new Submit('newMessageSendBtn');
     $submit->setId('newMessageSendBtn');
     $submit->setName('newMessageSendBtn');
     $submit->setValue(OW::getLanguage()->text('mailbox', 'add_button'));
     $this->addElement($submit);
     if (!OW::getRequest()->isAjax()) {
         $js = UTIL_JsGenerator::composeJsString('
         owForms["newMailMessageForm"].bind( "submit", function( r )
         {
             $("#newmessage-mail-send-btn").addClass("owm_preloader_circle");
         });');
         OW::getDocument()->addOnloadScript($js);
     }
     $this->setAction(OW::getRouter()->urlFor('MAILBOX_MCTRL_Messages', 'newmessage'));
 }
Example #2
0
 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);
             }
         }
     }
 }