Example #1
0
 public function index($params = array())
 {
     $userService = BOL_UserService::getInstance();
     $language = OW::getLanguage();
     $this->setPageHeading($language->text('hotlist', 'admin_heading_settings'));
     $this->setPageHeadingIconClass('ow_ic_gear_wheel');
     $settingsForm = new Form('settingsForm');
     $settingsForm->setId('settingsForm');
     $expiration_time = new TextField('expiration_time');
     $expiration_time->setRequired();
     $expiration_time->setLabel($language->text('hotlist', 'label_expiration_time'));
     $expiration_time_value = (int) OW::getConfig()->getValue('hotlist', 'expiration_time') / 86400;
     $expiration_time->setValue($expiration_time_value);
     $settingsForm->addElement($expiration_time);
     $submit = new Submit('save');
     $submit->addAttribute('class', 'ow_ic_save');
     $submit->setValue($language->text('hotlist', 'label_save_btn_label'));
     $settingsForm->addElement($submit);
     $this->addForm($settingsForm);
     if (OW::getRequest()->isPost()) {
         if ($settingsForm->isValid($_POST)) {
             $data = $settingsForm->getValues();
             OW::getConfig()->saveConfig('hotlist', 'expiration_time', $data['expiration_time'] * 86400);
             OW::getFeedback()->info($language->text('hotlist', 'settings_saved'));
             $this->redirect();
         }
     }
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
     $language = OW::getLanguage();
     $form = new Form("change-user-password");
     $form->setId("change-user-password");
     $oldPassword = new PasswordField('oldPassword');
     $oldPassword->setLabel($language->text('base', 'change_password_old_password'));
     $oldPassword->addValidator(new OldPasswordValidator());
     $oldPassword->setRequired();
     $form->addElement($oldPassword);
     $newPassword = new PasswordField('password');
     $newPassword->setLabel($language->text('base', 'change_password_new_password'));
     $newPassword->setRequired();
     $newPassword->addValidator(new NewPasswordValidator());
     $form->addElement($newPassword);
     $repeatPassword = new PasswordField('repeatPassword');
     $repeatPassword->setLabel($language->text('base', 'change_password_repeat_password'));
     $repeatPassword->setRequired();
     $form->addElement($repeatPassword);
     $submit = new Submit("change");
     $submit->setLabel($language->text('base', 'change_password_submit'));
     $form->setAjax(true);
     $form->addElement($submit);
     if (OW::getRequest()->isAjax()) {
         $result = false;
         if ($form->isValid($_POST)) {
             $data = $form->getValues();
             BOL_UserService::getInstance()->updatePassword(OW::getUser()->getId(), $data['password']);
             $result = true;
         }
         echo json_encode(array('result' => $result));
         exit;
     } else {
         $messageError = $language->text('base', 'change_password_error');
         $messageSuccess = $language->text('base', 'change_password_success');
         $js = " owForms['" . $form->getName() . "'].bind( 'success',\n            function( json )\n            {\n            \tif( json.result == true )\n            \t{\n            \t    \$('#TB_closeWindowButton').click();\n            \t    OW.info('{$messageSuccess}');\n                }\n                else\n                {\n                    OW.error('{$messageError}');\n                }\n\n            } ); ";
         OW::getDocument()->addOnloadScript($js);
         $this->addForm($form);
         $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.changePassword = new OW_BaseFieldValidators( " . json_encode(array('formName' => $form->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Join", "ajaxResponder"), 'passwordMaxLength' => UTIL_Validator::PASSWORD_MAX_LENGTH, 'passwordMinLength' => UTIL_Validator::PASSWORD_MIN_LENGTH)) . ",\n                                                            " . UTIL_Validator::EMAIL_PATTERN . ", " . UTIL_Validator::USER_NAME_PATTERN . " ); ";
         $onLoadJs .= " window.oldPassword = new OW_ChangePassword( " . json_encode(array('formName' => $form->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Edit", "ajaxResponder"))) . " ); ";
         OW::getDocument()->addOnloadScript($onLoadJs);
         $jsDir = OW::getPluginManager()->getPlugin("base")->getStaticJsUrl();
         OW::getDocument()->addScript($jsDir . "base_field_validators.js");
         OW::getDocument()->addScript($jsDir . "change_password.js");
     }
 }
Example #3
0
 public function index($params = array())
 {
     $userService = BOL_UserService::getInstance();
     $language = OW::getLanguage();
     $this->setPageHeading($language->text('admin', 'restrictedusernames'));
     $this->setPageHeadingIconClass('ow_ic_script');
     $restrictedUsernamesForm = new Form('restrictedUsernamesForm');
     $restrictedUsernamesForm->setId('restrictedUsernamesForm');
     $username = new TextField('restrictedUsername');
     $username->addAttribute('class', 'ow_text');
     $username->addAttribute('style', 'width: auto;');
     $username->setRequired();
     $username->setLabel($language->text('admin', 'restrictedusernames_username_label'));
     $restrictedUsernamesForm->addElement($username);
     $submit = new Submit('addUsername');
     $submit->addAttribute('class', 'ow_button');
     $submit->setValue($language->text('admin', 'restrictedusernames_add_username_button'));
     $restrictedUsernamesForm->addElement($submit);
     $this->addForm($restrictedUsernamesForm);
     $this->assign('restricted_list', $this->userService->getRestrictedUsernameList());
     if (OW::getRequest()->isPost()) {
         if ($restrictedUsernamesForm->isValid($_POST)) {
             $data = $restrictedUsernamesForm->getValues();
             $username = $this->userService->getRestrictedUsername($data['restrictedUsername']);
             if (empty($username)) {
                 $username = new BOL_RestrictedUsernames();
                 $username->setRestrictedUsername($data['restrictedUsername']);
                 $this->userService->addRestrictedUsername($username);
                 OW::getFeedback()->info($language->text('admin', 'restrictedusernames_username_added'));
                 $this->redirect();
             } else {
                 OW::getFeedback()->warning($language->text('admin', 'restrictedusernames_username_already_exists'));
             }
         }
     }
 }
Example #4
0
 public function index($params = array())
 {
     $userService = BOL_UserService::getInstance();
     $language = OW::getLanguage();
     $this->setPageHeading($language->text('admin', 'massmailing'));
     $this->setPageHeadingIconClass('ow_ic_script');
     $massMailingForm = new Form('massMailingForm');
     $massMailingForm->setId('massMailingForm');
     $rolesList = BOL_AuthorizationService::getInstance()->getRoleList();
     $userRoles = new CheckboxGroup('userRoles');
     $userRoles->setLabel($language->text('admin', 'massmailing_user_roles_label'));
     foreach ($rolesList as $role) {
         if ($role->name != 'guest') {
             $userRoles->addOption($role->name, $language->text('base', 'authorization_role_' . $role->name));
         }
     }
     $massMailingForm->addElement($userRoles);
     $emailFormat = new Selectbox('emailFormat');
     $emailFormat->setLabel($language->text('admin', 'massmailing_email_format_label'));
     $emailFormat->setOptions(array(self::EMAIL_FORMAT_TEXT => $language->text('admin', 'massmailing_email_format_text'), self::EMAIL_FORMAT_HTML => $language->text('admin', 'massmailing_email_format_html')));
     $emailFormat->setValue(self::EMAIL_FORMAT_TEXT);
     $emailFormat->setHasInvitation(false);
     if (!empty($_POST['emailFormat'])) {
         $emailFormat->setValue($_POST['emailFormat']);
     }
     $massMailingForm->addElement($emailFormat);
     $subject = new TextField('subject');
     $subject->addAttribute('class', 'ow_text');
     $subject->addAttribute('style', 'width: auto;');
     $subject->setRequired();
     $subject->setLabel($language->text('admin', 'massmailing_subject_label'));
     if (!empty($_POST['subject'])) {
         $subject->setValue($_POST['subject']);
     }
     $massMailingForm->addElement($subject);
     $body = new Textarea('body');
     if ($emailFormat->getValue() == self::EMAIL_FORMAT_HTML) {
         $body = new WysiwygTextarea('body');
         $body->forceAddButtons(array(BOL_TextFormatService::WS_BTN_IMAGE, BOL_TextFormatService::WS_BTN_HTML));
     }
     $body->addAttribute('class', 'ow_text');
     $body->addAttribute('style', 'width: auto;');
     $body->setRequired();
     $body->setLabel($language->text('admin', 'massmailing_body_label'));
     if (!empty($_POST['body'])) {
         $body->setValue($_POST['body']);
     }
     $massMailingForm->addElement($body);
     $submit = new Submit('startMailing');
     $submit->addAttribute('class', 'ow_button');
     $submit->setValue($language->text('admin', 'massmailing_start_mailing_button'));
     $massMailingForm->addElement($submit);
     $this->addForm($massMailingForm);
     $ignoreUnsubscribe = false;
     $isActive = true;
     if (defined('OW_PLUGIN_XP')) {
         $massMailingTimestamp = OW::getConfig()->getValue('admin', 'mass_mailing_timestamp');
         $timeout = $massMailingTimestamp + 60 * 60 * 24 - time();
         if ($timeout > 0) {
             $isActive = false;
             $this->assign('expireText', $language->text('admin', 'massmailing_expire_text', array('hours' => (int) ceil($timeout / (60 * 60)))));
         }
     }
     $this->assign('isActive', $isActive);
     $total = $userService->findMassMailingUserCount($ignoreUnsubscribe);
     if (OW::getRequest()->isPost() && $isActive && isset($_POST['startMailing'])) {
         if ($massMailingForm->isValid($_POST)) {
             $data = $massMailingForm->getValues();
             $start = 0;
             $count = self::MAILS_ARRAY_MAX_RECORDS;
             $mailCount = 0;
             $total = $userService->findMassMailingUserCount($ignoreUnsubscribe, $data['userRoles']);
             while ($start < $total) {
                 $result = $this->userService->findMassMailingUsers($start, $count, $ignoreUnsubscribe, $data['userRoles']);
                 $mails = array();
                 $userIdList = array();
                 foreach ($result as $user) {
                     $userIdList[] = $user->id;
                 }
                 $displayNameList = $this->userService->getDisplayNamesForList($userIdList);
                 $event = new BASE_CLASS_EventCollector('base.add_global_lang_keys');
                 OW::getEventManager()->trigger($event);
                 $vars = call_user_func_array('array_merge', $event->getData());
                 foreach ($result as $key => $user) {
                     $vars['user_email'] = $user->email;
                     $mail = OW::getMailer()->createMail();
                     $mail->addRecipientEmail($user->email);
                     $vars['user_name'] = $displayNameList[$user->id];
                     $code = md5($user->username . $user->password);
                     $link = OW::getRouter()->urlForRoute('base_massmailing_unsubscribe', array('id' => $user->id, 'code' => $code));
                     $subjectText = UTIL_String::replaceVars($data['subject'], $vars);
                     $mail->setSubject($subjectText);
                     if ($data['emailFormat'] === self::EMAIL_FORMAT_HTML) {
                         $htmlContent = UTIL_String::replaceVars($data['body'], $vars);
                         $htmlContent .= $language->text('admin', 'massmailing_unsubscribe_link_html', array('link' => $link));
                         $mail->setHtmlContent($htmlContent);
                         $textContent = preg_replace("/\\<br\\s*[\\/]?\\s*\\>/", "\n", $htmlContent);
                         $textContent = strip_tags($textContent);
                         $mail->setTextContent($textContent);
                     } else {
                         $textContent = UTIL_String::replaceVars($data['body'], $vars);
                         $textContent .= "\n\n" . $language->text('admin', 'massmailing_unsubscribe_link_text', array('link' => $link));
                         $mail->setTextContent($textContent);
                     }
                     $mails[] = $mail;
                     $mailCount++;
                 }
                 $start += $count;
                 //printVar($mails);
                 OW::getMailer()->addListToQueue($mails);
             }
             OW::getFeedback()->info($language->text('admin', 'massmailing_send_mails_message', array('count' => $mailCount)));
             if (defined('OW_PLUGIN_XP')) {
                 OW::getConfig()->saveConfig('admin', 'mass_mailing_timestamp', time());
             }
             $this->redirect();
         }
     }
     $this->assign('userCount', $total);
     $language->addKeyForJs('admin', 'questions_empty_lang_value');
     $language->addKeyForJs('admin', 'massmailing_total_members');
     $script = ' window.massMailing = new MassMailing(\'' . $this->ajaxResponderUrl . '\'); ';
     OW::getDocument()->addOnloadScript($script);
     $jsDir = OW::getPluginManager()->getPlugin("admin")->getStaticJsUrl();
     OW::getDocument()->addScript($jsDir . "mass_mailing.js");
 }
Example #5
0
 public function index($params)
 {
     $userId = OW::getUser()->getId();
     if (OW::getRequest()->isAjax()) {
         exit;
     }
     if (!OW::getUser()->isAuthenticated() || $userId === null) {
         throw new AuthenticateException();
     }
     $contentMenu = new BASE_CMP_PreferenceContentMenu();
     $contentMenu->getElement('privacy')->setActive(true);
     $this->addComponent('contentMenu', $contentMenu);
     $language = OW::getLanguage();
     $this->setPageHeading($language->text('privacy', 'privacy_index'));
     $this->setPageHeadingIconClass('ow_ic_lock');
     // -- Action form --
     $privacyForm = new Form('privacyForm');
     $privacyForm->setId('privacyForm');
     $actionSubmit = new Submit('privacySubmit');
     $actionSubmit->addAttribute('class', 'ow_button ow_ic_save');
     $actionSubmit->setValue($language->text('privacy', 'privacy_submit_button'));
     $privacyForm->addElement($actionSubmit);
     // --
     $actionList = PRIVACY_BOL_ActionService::getInstance()->findAllAction();
     $actionNameList = array();
     foreach ($actionList as $action) {
         $actionNameList[$action->key] = $action->key;
     }
     $actionValueList = PRIVACY_BOL_ActionService::getInstance()->getActionValueList($actionNameList, $userId);
     $actionValuesEvent = new BASE_CLASS_EventCollector(PRIVACY_BOL_ActionService::EVENT_GET_PRIVACY_LIST);
     OW::getEventManager()->trigger($actionValuesEvent);
     $data = $actionValuesEvent->getData();
     $actionValuesInfo = empty($data) ? array() : $data;
     $optionsList = array();
     $sortOptionsList = array();
     $order = array();
     // -- sort action values
     foreach ($actionValuesInfo as $value) {
         $optionsList[$value['key']] = $value['label'];
         $order[$value['sortOrder']] = $value['key'];
     }
     asort($order);
     foreach ($order as $key) {
         $sortOptionsList[$key] = $optionsList[$key];
     }
     // --
     $resultList = array();
     foreach ($actionList as $action) {
         /* @var $action PRIVACY_CLASS_Action */
         if (!empty($action->label)) {
             $formElement = new Selectbox($action->key);
             $formElement->setLabel($action->label);
             $formElement->setDescription('');
             if (!empty($action->description)) {
                 $formElement->setDescription($action->description);
             }
             $formElement->setOptions($sortOptionsList);
             $formElement->setHasInvitation(false);
             if (!empty($actionValueList[$action->key])) {
                 $formElement->setValue($actionValueList[$action->key]);
                 if (array_key_exists($actionValueList[$action->key], $sortOptionsList)) {
                     $formElement->setValue($actionValueList[$action->key]);
                 } else {
                     if ($actionValueList[$action->key] != 'everybody') {
                         $formElement->setValue('only_for_me');
                     }
                 }
             }
             $privacyForm->addElement($formElement);
             $resultList[$action->key] = $action->key;
         }
     }
     if (OW::getRequest()->isPost()) {
         if ($privacyForm->isValid($_POST)) {
             $values = $privacyForm->getValues();
             $restul = PRIVACY_BOL_ActionService::getInstance()->saveActionValues($values, $userId);
             if ($restul) {
                 OW::getFeedback()->info($language->text('privacy', 'action_action_data_was_saved'));
             } else {
                 OW::getFeedback()->warning($language->text('privacy', 'action_action_data_not_changed'));
             }
             $this->redirect();
         }
     }
     $this->addForm($privacyForm);
     $this->assign('actionList', $resultList);
 }
Example #6
0
 public function edit($params)
 {
     if (!isset($params['questionId'])) {
         throw new Redirect404Exception();
     }
     $questionId = (int) @$params['questionId'];
     if (empty($questionId)) {
         throw new Redirect404Exception();
     }
     $this->addContentMenu();
     $this->contentMenu->getElement('qst_index')->setActive(true);
     $editQuestion = $this->questionService->findQuestionById($questionId);
     $parent = $editQuestion->parent;
     $parentIsset = false;
     if (!empty($parent)) {
         $parentDto = $this->questionService->findQuestionByName($parent);
         $parentIsset = !empty($parentDto) ? true : false;
         if ($parentIsset) {
             $this->assign('parentUrl', OW::getRouter()->urlFor('ADMIN_CTRL_Questions', 'edit', array("questionId" => $parentDto->id)));
             $this->assign('parentLabel', $this->questionService->getQuestionLang($parentDto->name));
         }
     }
     $this->assign('parentIsset', $parentIsset);
     if ($editQuestion === null) {
         throw new Redirect404Exception();
     }
     $this->assign('question', $editQuestion);
     //$editQuestionToAccountType = $this->questionService->findAccountTypeByQuestionName( $editQuestion->name );
     // get available account types from DB
     /* @var BOL_QuestionService $this->questionService */
     $accountTypes = $this->questionService->findAllAccountTypes();
     $serviceLang = BOL_LanguageService::getInstance();
     $language = OW::getLanguage();
     $currentLanguageId = OW::getLanguage()->getCurrentId();
     $accounts = array(BOL_QuestionService::ALL_ACCOUNT_TYPES => $language->text('base', 'questions_account_type_all'));
     /* @var $value BOL_QuestionAccount */
     foreach ($accountTypes as $value) {
         $accounts[$value->name] = $language->text('base', 'questions_account_type_' . $value->name);
     }
     $sections = $this->questionService->findAllSections();
     // need to hide sections select box
     if (empty($section)) {
         $this->assign('no_sections', true);
     }
     $sectionsArray = array();
     /* @var $section BOL_QuestionSection */
     foreach ($sections as $section) {
         $sectionsArray[$section->name] = $language->text('base', 'questions_section_' . $section->name . '_label');
     }
     $presentations = array();
     $presentationsLabel = array();
     $presentationList = $this->questionService->getPresentations();
     if ($editQuestion->name != 'password') {
         unset($presentationList[BOL_QuestionService::QUESTION_PRESENTATION_PASSWORD]);
     }
     foreach ($presentationList as $presentationKey => $presentation) {
         if ($presentationList[$editQuestion->presentation] == $presentation) {
             $presentations[$presentationKey] = $presentationKey;
             //TODO add langs with presentation labels
             $presentationsLabel[$presentationKey] = $language->text('base', 'questions_question_presentation_' . $presentationKey . '_label');
         }
     }
     $presentation = $editQuestion->presentation;
     if (OW::getSession()->isKeySet(self::EDIT_QUESTION_SESSION_VAR)) {
         $session = OW::getSession()->get(self::EDIT_QUESTION_SESSION_VAR);
         if (isset($session['qst_answer_type']) && isset($presentations[$session['qst_answer_type']])) {
             $presentation = $presentations[$session['qst_answer_type']];
         }
     }
     if (isset($_POST['qst_answer_type']) && isset($presentations[$_POST['qst_answer_type']])) {
         $presentation = $presentations[$_POST['qst_answer_type']];
     }
     //$this->addForm(new LanguageValueEditForm( 'base', 'questions_question_' . ($editQuestion->id) . '_label', $this ) );
     //--  -------------------------------------
     //--  add question values form creating
     //--  -------------------------------------
     $questionValues = $this->questionService->findQuestionValues($editQuestion->name);
     $this->assign('questionValues', $questionValues);
     //add field values form
     $addQuestionValuesForm = new AddValuesForm($questionId);
     $addQuestionValuesForm->setAction($this->ajaxResponderUrl);
     $this->addForm($addQuestionValuesForm);
     //--  -------------------------------------
     //--  edit field form creating
     //--  -------------------------------------
     $editForm = new Form('qst_edit_form');
     $editForm->setId('qst_edit_form');
     $disableActionList = array('disable_account_type' => false, 'disable_answer_type' => false, 'disable_presentation' => false, 'disable_column_count' => false, 'disable_display_config' => false, 'disable_required' => false, 'disable_on_join' => false, 'disable_on_view' => false, 'disable_on_search' => false, 'disable_on_edit' => false);
     $event = new OW_Event('admin.disable_fields_on_edit_profile_question', array('questionDto' => $editQuestion), $disableActionList);
     OW::getEventManager()->trigger($event);
     $disableActionList = $event->getData();
     if (count($accountTypes) > 1) {
         $qstAccountType = new Selectbox('qst_account_type');
         $qstAccountType->setLabel($language->text('admin', 'questions_for_account_type_label'));
         $qstAccountType->setDescription($language->text('admin', 'questions_for_account_type_description'));
         $qstAccountType->setOptions($accounts);
         $qstAccountType->setValue(BOL_QuestionService::ALL_ACCOUNT_TYPES);
         $qstAccountType->setHasInvitation(false);
         if ($editQuestion->accountTypeName !== null) {
             $qstAccountType->setValue($editQuestion->accountTypeName);
         }
         if ($editQuestion->base == 1) {
             $qstAccountType->addAttribute('disabled', 'disabled');
         } else {
             if ($disableActionList['disable_account_type']) {
                 $qstAnswerType->setRequired(false);
                 $qstAccountType->addAttribute('disabled', 'disabled');
             }
         }
         $editForm->addElement($qstAccountType);
     }
     if (!empty($sectionsArray)) {
         $qstSection = new Selectbox('qst_section');
         $qstSection->setLabel($language->text('admin', 'questions_question_section_label'));
         $qstSection->setOptions($sectionsArray);
         $qstSection->setValue($editQuestion->sectionName);
         $qstSection->setHasInvitation(false);
         $editForm->addElement($qstSection);
     }
     $qstAnswerType = new Selectbox('qst_answer_type');
     $qstAnswerType->setLabel($language->text('admin', 'questions_answer_type_label'));
     $qstAnswerType->addAttribute('class', $qstAnswerType->getName());
     $qstAnswerType->setOptions($presentationsLabel);
     $qstAnswerType->setValue($presentation);
     $qstAnswerType->setRequired();
     $qstAnswerType->setHasInvitation(false);
     if ($parentIsset) {
         $qstAnswerType->setValue($parentDto->columnCount);
         $qstAnswerType->addAttribute('disabled', 'disabled');
     }
     if ((int) $editQuestion->base === 1 || count($presentations) <= 1 || $parentIsset || $disableActionList['disable_answer_type']) {
         $qstAnswerType->setRequired(false);
         $qstAnswerType->addAttribute('disabled', 'disabled');
     }
     $editForm->addElement($qstAnswerType);
     $columnCountPresentation = array(BOL_QuestionService::QUESTION_PRESENTATION_MULTICHECKBOX, BOL_QuestionService::QUESTION_PRESENTATION_RADIO);
     if (in_array($presentation, $columnCountPresentation)) {
         $qstColumnCount = new Selectbox('qst_column_count');
         $qstColumnCount->addAttribute('class', $qstColumnCount->getName());
         $qstColumnCount->setLabel($language->text('admin', 'questions_columns_count_label'));
         $qstColumnCount->setRequired();
         $qstColumnCount->setOptions($this->qstColumnCountValues);
         $qstColumnCount->setValue($editQuestion->columnCount);
         $parentIsset = !empty($parentDto) ? true : false;
         if ($parentIsset) {
             $qstColumnCount->setValue($parentDto->columnCount);
             $qstColumnCount->addAttribute('disabled', 'disabled');
             $qstColumnCount->setRequired(false);
         } else {
             if ($disableActionList['disable_column_count']) {
                 $qstAnswerType->setRequired(false);
                 $qstAnswerType->addAttribute('disabled', 'disabled');
             }
         }
         $editForm->addElement($qstColumnCount);
     }
     $presentationConfigList = BOL_QuestionService::getInstance()->getConfigList($presentation);
     $presentationConfigValues = json_decode($editQuestion->custom, true);
     if ($editQuestion->name !== 'joinStamp' && !$disableActionList['disable_display_config']) {
         foreach ($presentationConfigList as $config) {
             $className = $config->presentationClass;
             /* @var $qstConfig OW_FormElement */
             $qstConfig = new $className($config->name);
             $qstConfig->setLabel($language->text('admin', 'questions_config_' . $config->name . '_label'));
             if (!empty($config->description)) {
                 $qstConfig->setDescription($config->description);
             }
             if (isset($presentationConfigValues[$config->name])) {
                 $qstConfig->setValue($presentationConfigValues[$config->name]);
             }
             $editForm->addElement($qstConfig);
         }
     }
     $qstRequired = new CheckboxField('qst_required');
     $qstRequired->setLabel($language->text('admin', 'questions_required_label'));
     $qstRequired->setDescription($language->text('admin', 'questions_required_description'));
     $qstRequired->setValue((bool) $editQuestion->required);
     if ((int) $editQuestion->base === 1 || $disableActionList['disable_required']) {
         $qstRequired->addAttribute('disabled', 'disabled');
     }
     $editForm->addElement($qstRequired);
     $qstOnSignUp = new CheckboxField('qst_on_sign_up');
     $qstOnSignUp->setLabel($language->text('admin', 'questions_on_sing_up_label'));
     $qstOnSignUp->setDescription($language->text('admin', 'questions_on_sing_up_description'));
     $qstOnSignUp->setValue((bool) $editQuestion->onJoin);
     if ((int) $editQuestion->base === 1 || $disableActionList['disable_on_join']) {
         $qstOnSignUp->addAttribute('disabled', 'disabled');
     }
     $editForm->addElement($qstOnSignUp);
     $qstOnEdit = new CheckboxField('qst_on_edit');
     $qstOnEdit->setLabel($language->text('admin', 'questions_on_edit_label'));
     $qstOnEdit->setDescription($language->text('admin', 'questions_on_edit_description'));
     $qstOnEdit->setValue((bool) $editQuestion->onEdit);
     $description = $language->text('admin', 'questions_on_edit_description');
     if ($editQuestion->name === 'username') {
         $qstOnEdit->setDescription($language->text('admin', 'questions_on_edit_description') . "<br/><br/>" . $language->text('admin', 'questions_edit_username_warning'));
     } else {
         if ((int) $editQuestion->base === 1 || $disableActionList['disable_on_edit']) {
             $qstOnEdit->addAttribute('disabled', 'disabled');
         }
     }
     $editForm->addElement($qstOnEdit);
     $qstOnView = new CheckboxField('qst_on_view');
     $qstOnView->setLabel($language->text('admin', 'questions_on_view_label'));
     $qstOnView->setDescription($language->text('admin', 'questions_on_view_description'));
     $qstOnView->setValue((bool) $editQuestion->onView);
     if ((int) $editQuestion->base === 1 && $editQuestion->name !== 'joinStamp' || $disableActionList['disable_on_view']) {
         $qstOnView->addAttribute('disabled', 'disabled');
     }
     $editForm->addElement($qstOnView);
     $qstOnSearch = new CheckboxField('qst_on_search');
     $qstOnSearch->setLabel($language->text('admin', 'questions_on_search_label'));
     $qstOnSearch->setDescription($language->text('admin', 'questions_on_search_description'));
     $qstOnSearch->setValue((bool) $editQuestion->onSearch);
     if ((int) $editQuestion->base === 1 && $editQuestion->name != 'username' || $parentIsset || $disableActionList['disable_on_search']) {
         $qstOnSearch->addAttribute('disabled', 'disabled');
     }
     $editForm->addElement($qstOnSearch);
     $qstSubmit = new Submit('qst_submit');
     $qstSubmit->addAttribute('class', 'ow_button ow_ic_save');
     $qstSubmit->setValue($language->text('admin', 'btn_label_edit'));
     $editForm->addElement($qstSubmit);
     if (OW::getSession()->isKeySet(self::EDIT_QUESTION_SESSION_VAR)) {
         $editForm->setValues(OW::getSession()->get(self::EDIT_QUESTION_SESSION_VAR));
         OW::getSession()->delete(self::EDIT_QUESTION_SESSION_VAR);
     }
     $this->addForm($editForm);
     if (OW_Request::getInstance()->isPost()) {
         if ((isset($_POST['qst_submit_and_add']) || isset($_POST['qst_submit'])) && $editForm->isValid($_POST)) {
             OW::getSession()->delete(self::EDIT_QUESTION_SESSION_VAR);
             $updated = false;
             $data = $editForm->getValues();
             $elements = $editForm->getElements();
             foreach ($elements as $element) {
                 if (!$element->getAttribute('disabled')) {
                     switch ($element->getName()) {
                         case 'qst_required':
                             $editQuestion->required = isset($_POST['qst_required']) ? 1 : 0;
                             break;
                         case 'qst_on_sign_up':
                             $editQuestion->onJoin = isset($_POST['qst_on_sign_up']) ? 1 : 0;
                             break;
                         case 'qst_on_edit':
                             $editQuestion->onEdit = isset($_POST['qst_on_edit']) ? 1 : 0;
                             break;
                         case 'qst_on_search':
                             $editQuestion->onSearch = isset($_POST['qst_on_search']) ? 1 : 0;
                             break;
                         case 'qst_on_view':
                             $editQuestion->onView = isset($_POST['qst_on_view']) ? 1 : 0;
                             break;
                         case 'qst_answer_type':
                             $editQuestion->presentation = htmlspecialchars($data['qst_answer_type']);
                             break;
                         case 'qst_column_count':
                             $editQuestion->columnCount = htmlspecialchars($data['qst_column_count']);
                             break;
                         case 'qst_section':
                             if (!empty($data['qst_section'])) {
                                 $section = $this->questionService->findSectionBySectionName(htmlspecialchars(trim($data['qst_section'])));
                                 $sectionName = null;
                                 if (isset($section)) {
                                     $sectionName = $section->name;
                                 }
                                 if ($editQuestion->sectionName !== $sectionName) {
                                     $editQuestion->sectionName = $sectionName;
                                     $editQuestion->sortOrder = (int) BOL_QuestionService::getInstance()->findLastQuestionOrder($editQuestion->sectionName) + 1;
                                 }
                             }
                             break;
                         case 'qst_account_type':
                             if ($data['qst_account_type'] !== null) {
                                 $editQuestion->accountTypeName = htmlspecialchars(trim($data['qst_account_type']));
                                 if ($editQuestion->accountTypeName === BOL_QuestionService::ALL_ACCOUNT_TYPES) {
                                     $editQuestion->accountTypeName = null;
                                 }
                             }
                             break;
                     }
                 }
             }
             if (!$disableActionList['disable_display_config']) {
                 // save question configs
                 $configs = array();
                 foreach ($presentationConfigList as $config) {
                     if (isset($data[$config->name])) {
                         $configs[$config->name] = $data[$config->name];
                     }
                 }
                 $editQuestion->custom = json_encode($configs);
             }
             $this->questionService->saveOrUpdateQuestion($editQuestion);
             if (OW::getDbo()->getAffectedRows() > 0) {
                 $updated = true;
                 $list = $this->questionService->findQuestionChildren($editQuestion->name);
                 /* @var BOL_Question $child */
                 foreach ($list as $child) {
                     $child->columnCount = $editQuestion->columnCount;
                     $this->questionService->saveOrUpdateQuestion($child);
                 }
             }
             //update question values sort
             if (isset($_POST['question_values_order'])) {
                 $valuesOrder = json_decode($_POST['question_values_order'], true);
                 if (isset($valuesOrder) && count($valuesOrder) > 0 && is_array($valuesOrder)) {
                     foreach ($questionValues as $questionValue) {
                         if (isset($valuesOrder[$questionValue->value])) {
                             $questionValue->sortOrder = (int) $valuesOrder[$questionValue->value];
                         }
                         $this->questionService->saveOrUpdateQuestionValue($questionValue);
                         if (OW::getDbo()->getAffectedRows() > 0) {
                             $updated = true;
                         }
                     }
                 }
             }
             if ($updated) {
                 OW::getFeedback()->info($language->text('admin', 'questions_update_question_message'));
             } else {
                 OW::getFeedback()->info($language->text('admin', 'questions_question_was_not_updated_message'));
             }
             //exit;
             $this->redirect(OW::getRouter()->urlFor('ADMIN_CTRL_Questions', 'index'));
         }
         $editForm->setValues($_POST);
         OW::getSession()->set(self::EDIT_QUESTION_SESSION_VAR, $_POST);
         //OW::getFeedback()->error($language->text('admin', 'questions_question_was_not_updated_message'));
         $this->redirect();
     }
     $types = array();
     foreach ($this->questionService->getPresentations() as $presentation => $type) {
         if ($type === 'select') {
             $types[] = $presentation;
         }
     }
     $questionLabel = $this->questionService->getQuestionLang($editQuestion->name);
     $questionDescription = $this->questionService->getQuestionDescriptionLang($editQuestion->name);
     $noValue = $language->text('admin', 'questions_empty_lang_value');
     $questionLabel = mb_strlen(trim($questionLabel)) == 0 || $questionLabel == '&nbsp;' ? $noValue : $questionLabel;
     $questionDescription = mb_strlen(trim($questionDescription)) == 0 || $questionDescription == '&nbsp;' ? $noValue : $questionDescription;
     $this->assign('questionLabel', $questionLabel);
     $this->assign('questionDescription', $questionDescription);
     $language->addKeyForJs('admin', 'questions_empty_lang_value');
     $language->addKeyForJs('admin', 'questions_edit_question_name_title');
     $language->addKeyForJs('admin', 'questions_edit_question_description_title');
     $language->addKeyForJs('admin', 'questions_edit_question_value_title');
     $language->addKeyForJs('admin', 'questions_edit_delete_value_confirm_message');
     $fields = array();
     foreach ($editForm->getElements() as $element) {
         if (!$element instanceof HiddenField) {
             $fields[$element->getName()] = $element->getName();
         }
     }
     $this->assign('formData', $fields);
     $script = '
                 window.editQuestion = new editQuestion(' . json_encode(array('types' => $types, 'ajaxResponderUrl' => $this->ajaxResponderUrl)) . ');
                 ';
     OW::getDocument()->addOnloadScript($script);
     $jsDir = OW::getPluginManager()->getPlugin("admin")->getStaticJsUrl();
     $baseJsDir = OW::getPluginManager()->getPlugin("base")->getStaticJsUrl();
     OW::getDocument()->addScript($jsDir . "questions.js");
     OW::getDocument()->addScript($baseJsDir . "jquery-ui.min.js");
 }
Example #7
0
 public function upload()
 {
     if (!OW::getUser()->isAuthorized('ivideo', 'add')) {
         $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
         return;
     }
     $eventParams = array('pluginKey' => 'ivideo', 'action' => 'upload_video');
     $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams);
     if ($credits === false) {
         $this->assign('authMsg', OW::getEventManager()->call('usercredits.error_message', $eventParams));
         return;
     } else {
         $this->assign('authMsg', null);
     }
     $language = OW::getLanguage();
     $config = OW::getConfig();
     $uploadForm = new Form('uploadForm');
     $uploadForm->setId('THEFORM');
     $uploadForm->setEnctype('multipart/form-data');
     $element = new TextField('videoName');
     $element->setRequired(true);
     $element->addValidator(new uploadValidator());
     $element->setLabel($language->text('ivideo', 'upload_video_name'));
     $uploadForm->addElement($element);
     $element = new WysiwygTextarea('videoDescription');
     $element->setRequired(true);
     $element->setLabel($language->text('ivideo', 'upload_video_desc'));
     $uploadForm->addElement($element);
     $element = new Selectbox('videoCategory');
     $element->setRequired(true);
     $element->setLabel($language->text('ivideo', 'admin_video_category'));
     foreach (IVIDEO_BOL_CategoryDao::getInstance()->findAll() as $category) {
         $element->addOption($category->id, $category->name);
     }
     $uploadForm->addElement($element);
     $tagService = BOL_TagService::getInstance();
     $tf = new TagsField('tf');
     $tf->setLabel($language->text('ivideo', 'tags_field_label'));
     $uploadForm->addElement($tf);
     $element = new Submit('uploadVideo');
     $element->setValue($language->text('ivideo', 'user_upload_video'));
     $uploadForm->addElement($element);
     if (OW::getRequest()->isPost()) {
         if ($uploadForm->isValid($_POST) && isset($_POST['ax-uploaded-files'])) {
             $values = $uploadForm->getValues();
             $fileName = OW::getSession()->get('ivideo.filename');
             if (is_null($fileName)) {
                 OW::getFeedback()->error($language->text('ivideo', 'admin_video_not_uploaded_error'));
             } else {
                 $video = new IVIDEO_BOL_Video();
                 $video->name = ucwords(UTIL_HtmlTag::stripTags($values['videoName']));
                 $description = UTIL_HtmlTag::stripJs($values['videoDescription']);
                 $description = UTIL_HtmlTag::stripTags($description, array('frame', 'style'), array(), true);
                 $video->description = $description;
                 $video->owner = OW::getuser()->getId();
                 $video->timestamp = time();
                 $video->status = $config->getValue('ivideo', 'videoApproval') == 'auto' ? 'approved' : 'pending';
                 $video->filename = $fileName;
                 $videoId = IVIDEO_BOL_Service::getInstance()->addVideo($video);
                 if ($videoId) {
                     $fullFileName = OW::getPluginManager()->getPlugin('ivideo')->getUserFilesDir() . $fileName;
                     $imageFileName = OW::getPluginManager()->getPlugin('ivideo')->getUserFilesDir() . $fileName . ".png";
                     $ffmpegPath = $config->getValue('ivideo', 'ffmpegPath');
                     if (!empty($ffmpegPath) && file_exists($ffmpegPath)) {
                         exec("{$ffmpegPath} -y -itsoffset -4 -i '{$fullFileName}' -r 1 -f image2 '{$imageFileName}'");
                     }
                     IVIDEO_BOL_VideoCategoryService::getInstance()->setVideoCategories($videoId, $values['videoCategory']);
                     BOL_TagService::getInstance()->updateEntityTags($video->id, 'ivideo-video', TagsField::getTags($values['tf']));
                     $event = new OW_Event('feed.action', array('pluginKey' => 'ivideo', 'entityType' => 'ivideo-comments', 'entityId' => $video->id, 'userId' => $video->owner));
                     OW::getEventManager()->trigger($event);
                     $this->redirect(OW::getRouter()->urlForRoute('ivideo_view_list', array('type' => 'latest')));
                     OW::getFeedback()->info($language->text('ivideo', 'admin_upload_video_ok'));
                 } else {
                     OW::getFeedback()->error($language->text('ivideo', 'admin_upload_video_fail'));
                 }
             }
         }
     }
     $this->addForm($uploadForm);
     if (OW::getSession()->isKeySet('ivideo.filename')) {
         OW::getSession()->delete('ivideo.filename');
     }
     $jsURL = OW::getPluginManager()->getPlugin('ivideo')->getStaticUrl() . 'ajaxupload' . '/';
     $this->assign('filesDir', json_encode(OW::getPluginManager()->getPlugin('ivideo')->getUserFilesDir()));
     $this->assign('uploadAction', json_encode(OW::getRouter()->urlFor('IVIDEO_CTRL_Upload', 'action')));
     $this->assign('maxSize', $config->getValue('ivideo', 'allowedFileSize'));
     $this->assign('allowedExtn', UTIL_String::arrayToDelimitedString(explode(",", $config->getValue('ivideo', 'allowedExtensions')), ",", "'", "'"));
     $this->assign('allowedExtnText', UTIL_String::arrayToDelimitedString(explode(",", $config->getValue('ivideo', 'allowedExtensions')), ","));
     $this->assign('flashURL', $jsURL);
     $this->assign('videoApproval', $config->getValue('ivideo', 'videoApproval'));
     $theme = $config->getValue('ivideo', 'theme');
     OW::getDocument()->addStyleSheet($jsURL . 'css/' . $theme . '/style.css');
     OW::getDocument()->addScript($jsURL . "js/ajaxupload-min.js");
     $this->setPageHeading(OW::getLanguage()->text('ivideo', 'video_user_upload'));
     $this->setPageTitle(OW::getLanguage()->text('ivideo', 'video_user_upload'));
     $this->setPageHeadingIconClass('ow_ic_video');
 }
Example #8
0
 public static function shortcut_menu()
 {
     PHPWS_Core::initModClass('access', 'Shortcut.php');
     $sch_id = filter_input(INPUT_GET, 'sch_id', FILTER_SANITIZE_NUMBER_INT);
     if ($sch_id === false) {
         $sch_id = 0;
     }
     if (!$sch_id) {
         @($key_id = $_REQUEST['key_id']);
         if (!$key_id) {
             javascript('close_window');
             return;
         } else {
             $shortcut = new Access_Shortcut();
             $key = new Key($key_id);
             if (!$key->id) {
                 javascript('close_window');
                 return;
             }
             $shortcut->keyword = trim(preg_replace('/[^\\w\\s\\-]/', '', $key->title));
         }
     } else {
         $shortcut = new Access_Shortcut($sch_id);
         if (!$shortcut->id) {
             return 'Error: shortcut not found';
         }
     }
     $form = new \Form();
     $form->setAction('index.php');
     $form->appendCSS('bootstrap');
     $form->setId('shortcut-menu');
     $form->addHidden('authkey', \Current_User::getAuthKey());
     $form->addHidden('module', 'access');
     $form->addHidden('command', 'post_shortcut');
     if (isset($key_id)) {
         $form->addHidden('key_id', $key_id);
     } else {
         $form->addHidden('sch_id', $shortcut->id);
     }
     $keyword = $form->addTextField('keyword', $shortcut->keyword)->setRequired();
     $keyword->setPlaceholder(dgettext('access', 'Type in a keyword'));
     $tpl = $form->getInputStringArray();
     $template = new \Template($tpl);
     $template->setModuleTemplate('access', 'shortcut_menu.tpl');
     $content = $template->render();
     return $content;
 }
Example #9
0
 public function index($params)
 {
     $userId = OW::getUser()->getId();
     if (OW::getRequest()->isAjax()) {
         exit;
     }
     if (!OW::getUser()->isAuthenticated() || $userId === null) {
         throw new AuthenticateException();
     }
     $language = OW::getLanguage();
     $this->setPageHeading($language->text('base', 'preference_index'));
     $this->setPageHeadingIconClass('ow_ic_gear_wheel');
     // -- Preference form --
     $preferenceForm = new Form('preferenceForm');
     $preferenceForm->setId('preferenceForm');
     $preferenceSubmit = new Submit('preferenceSubmit');
     $preferenceSubmit->addAttribute('class', 'ow_button ow_ic_save');
     $preferenceSubmit->setValue($language->text('base', 'preference_submit_button'));
     $preferenceForm->addElement($preferenceSubmit);
     // --
     $sectionList = BOL_PreferenceService::getInstance()->findAllSections();
     $preferenceList = BOL_PreferenceService::getInstance()->findAllPreference();
     $preferenceNameList = array();
     foreach ($preferenceList as $preference) {
         $preferenceNameList[$preference->key] = $preference->key;
     }
     $preferenceValuesList = BOL_PreferenceService::getInstance()->getPreferenceValueListByUserIdList($preferenceNameList, array($userId));
     $formElementEvent = new BASE_CLASS_EventCollector(BOL_PreferenceService::PREFERENCE_ADD_FORM_ELEMENT_EVENT, array('values' => $preferenceValuesList[$userId]));
     OW::getEventManager()->trigger($formElementEvent);
     $data = $formElementEvent->getData();
     $formElements = empty($data) ? array() : call_user_func_array('array_merge', $data);
     $formElementList = array();
     foreach ($formElements as $formElement) {
         /* @var $formElement FormElement */
         $formElementList[$formElement->getName()] = $formElement;
     }
     $resultList = array();
     foreach ($sectionList as $section) {
         foreach ($preferenceList as $preference) {
             if ($preference->sectionName === $section->name && !empty($formElementList[$preference->key])) {
                 $resultList[$section->name][$preference->key] = $preference->key;
                 $element = $formElementList[$preference->key];
                 $preferenceForm->addElement($element);
             }
         }
     }
     if (OW::getRequest()->isPost()) {
         if ($preferenceForm->isValid($_POST)) {
             $values = $preferenceForm->getValues();
             $restul = BOL_PreferenceService::getInstance()->savePreferenceValues($values, $userId);
             if ($restul) {
                 OW::getFeedback()->info($language->text('base', 'preference_preference_data_was_saved'));
             } else {
                 OW::getFeedback()->warning($language->text('base', 'preference_preference_data_not_changed'));
             }
             $this->redirect();
         }
     }
     $this->addForm($preferenceForm);
     $data = array();
     $sectionLabelEvent = new BASE_CLASS_EventCollector(BOL_PreferenceService::PREFERENCE_SECTION_LABEL_EVENT);
     OW::getEventManager()->trigger($sectionLabelEvent);
     $data = $sectionLabelEvent->getData();
     $sectionLabels = empty($data) ? array() : call_user_func_array('array_merge', $data);
     $this->assign('preferenceList', $resultList);
     $this->assign('sectionLabels', $sectionLabels);
 }