public function index() { $language = OW::getLanguage(); $billingService = BOL_BillingService::getInstance(); $adminForm = new Form('adminForm'); $element = new TextField('creditValue'); $element->setRequired(true); $element->setLabel($language->text('billingcredits', 'admin_usd_credit_value')); $element->setDescription($language->text('billingcredits', 'admin_usd_credit_value_desc')); $element->setValue($billingService->getGatewayConfigValue('billingcredits', 'creditValue')); $validator = new FloatValidator(0.1); $validator->setErrorMessage($language->text('billingcredits', 'invalid_numeric_format')); $element->addValidator($validator); $adminForm->addElement($element); $element = new Submit('saveSettings'); $element->setValue($language->text('billingcredits', 'admin_save_settings')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); $billingService->setGatewayConfigValue('billingcredits', 'creditValue', $values['creditValue']); OW::getFeedback()->info($language->text('billingcredits', 'user_save_success')); } } $this->addForm($adminForm); $this->setPageHeading(OW::getLanguage()->text('billingcredits', 'config_page_heading')); $this->setPageTitle(OW::getLanguage()->text('billingcredits', 'config_page_heading')); $this->setPageHeadingIconClass('ow_ic_app'); }
/** * @covers Form::addControl */ public function testAddControl() { $this->myForm->setValue('verify', 'required'); $this->myForm->addControl('verify', new \Textbox('phone')); $this->assertArrayHasKey('verify', $this->myForm->getControls()); $this->assertArrayHasKey('verify', $this->myForm->getValues()); }
/** * The action that displays the entry insert form . * * @param PDO $pdo The PDO object. * @return Opt_View */ function action($pdo, $config) { $view = new Opt_View('add.tpl'); $view->title = 'Add new entry'; $form = new Form($view); $form->setAction('index.php?action=add'); $form->addField('author', 'required,min_len=3,max_len=30', 'The length must be between 3 and 30 characters.'); $form->addField('email', 'required,email,min_len=3,max_len=100', 'The value must be a valid mail with maximum 100 characters long.'); $form->addField('website', 'url,min_len=3,max_len=100', 'The value must be a valid URL with maximum 100 characters long.'); $form->addField('body', 'required,min_len=3', 'The body must be at least 3 characters long.'); if ($form->validate()) { $values = $form->getValues(); $stmt = $pdo->prepare('INSERT INTO `entries` (`author`, `email`, `date`, `website`, `body`) VALUES(:author, :email, :date, :website, :body)'); $stmt->bindValue(':author', $values['author'], PDO::PARAM_STR); $stmt->bindValue(':email', $values['email'], PDO::PARAM_STR); $stmt->bindValue(':date', time(), PDO::PARAM_INT); $stmt->bindValue(':website', $values['website'], PDO::PARAM_STR); $stmt->bindValue(':body', $values['body'], PDO::PARAM_STR); $stmt->execute(); $view->setTemplate('message.tpl'); $view->message = 'The entry has been successfully added!'; $view->redirect = 'index.php?action=list'; } else { // The form is an object, so we need to inform OPT about it. $view->form = $form; $view->setFormat('form', 'Objective'); } return $view; }
public function settings() { $adminForm = new Form('adminForm'); $language = OW::getLanguage(); $config = OW::getConfig(); $element = new TextField('autoclick'); $element->setRequired(true); $validator = new IntValidator(1); $validator->setErrorMessage($language->text('autoviewmore', 'admin_invalid_number_error')); $element->addValidator($validator); $element->setLabel($language->text('autoviewmore', 'admin_auto_click')); $element->setValue($config->getValue('autoviewmore', 'autoclick')); $adminForm->addElement($element); $element = new Submit('saveSettings'); $element->setValue($language->text('autoviewmore', 'admin_save_settings')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); $config = OW::getConfig(); $config->saveConfig('autoviewmore', 'autoclick', $values['autoclick']); OW::getFeedback()->info($language->text('autoviewmore', 'user_save_success')); } } $this->addForm($adminForm); }
function testShouldSetNameToCategory() { $form = new Form(null); $this->assertTrue($form->isValid(['name' => 'wheels'])); $category = $form->getValues(); $this->assertEquals('wheels', $category['name'], 'should copy name from form to category'); }
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"); } }
private function exampleForm() { $countries = array('Select your country', 'Europe' => array('CZ' => 'Czech Republic', 'FR' => 'France', 'DE' => 'Germany', 'GR' => 'Greece', 'HU' => 'Hungary', 'IE' => 'Ireland', 'IT' => 'Italy', 'NL' => 'Netherlands', 'PL' => 'Poland', 'SK' => 'Slovakia', 'ES' => 'Spain', 'CH' => 'Switzerland', 'UA' => 'Ukraine', 'GB' => 'United Kingdom'), 'AU' => 'Australia', 'CA' => 'Canada', 'EG' => 'Egypt', 'JP' => 'Japan', 'US' => 'United States', '?' => 'other'); $sex = array('m' => 'male', 'f' => 'female'); // Step 1: Define form with validation rules $form = new Form(); // group Personal data $form->addGroup('Personal data')->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.'); $form->addText('name', 'Your name:', 35)->addRule(Form::FILLED, 'Enter your name'); $form->addText('age', 'Your age:', 5)->addRule(Form::FILLED, 'Enter your age')->addRule(Form::INTEGER, 'Age must be numeric value')->addRule(Form::RANGE, 'Age must be in range from %.2f to %.2f', array(9.9, 100)); $form->addRadioList('gender', 'Your gender:', $sex); $form->addText('email', 'E-mail:', 35)->setEmptyValue('@')->addCondition(Form::FILLED)->addRule(Form::EMAIL, 'Incorrect E-mail Address'); // ... then check email // group Shipping address $form->addGroup('Shipping address')->setOption('embedNext', TRUE); $form->addCheckbox('send', 'Ship to address')->addCondition(Form::EQUAL, TRUE)->toggle('sendBox'); // toggle div #sendBox // subgroup $form->addGroup()->setOption('container', Html::el('div')->id('sendBox')); $form->addText('street', 'Street:', 35); $form->addText('city', 'City:', 35)->addConditionOn($form['send'], Form::EQUAL, TRUE)->addRule(Form::FILLED, 'Enter your shipping address'); $form->addSelect('country', 'Country:', $countries)->skipFirst()->addConditionOn($form['send'], Form::EQUAL, TRUE)->addRule(Form::FILLED, 'Select your country'); // group Your account $form->addGroup('Your account'); $form->addPassword('password', 'Choose password:'******'Choose your password')->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3); $form->addPassword('password2', 'Reenter password:'******'password'], Form::VALID)->addRule(Form::FILLED, 'Reenter your password')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']); $form->addFile('avatar', 'Picture:')->addCondition(Form::FILLED)->addRule(Form::MIME_TYPE, 'Uploaded file is not image', 'image/*'); $form->addHidden('userid'); $form->addTextArea('note', 'Comment:', 30, 5); // group for buttons $form->addGroup(); $form->addSubmit('submit1', 'Send'); // Step 2: Check if form was submitted? if ($form->isSubmitted()) { // Step 2c: Check if form is valid if ($form->isValid()) { echo '<h2>Form was submitted and successfully validated</h2>'; $values = $form->getValues(); Debug::dump($values); // this is the end, my friend :-) if (empty($disableExit)) { exit; } } } else { // not submitted, define default values $defaults = array('name' => 'John Doe', 'userid' => 231, 'country' => 'CZ'); $form->setDefaults($defaults); } return $form; }
public function onSettingsFormSubmit(Form $form) { if (!$form->isValid()) { return; } $content = "<?php\nreturn " . var_export($form->getValues(), TRUE) . ";\n"; if (!@file_put_contents(Environment::expand('safe://%settingsFile%'), $content)) { $form->addError(__('Cannot write settings.')); return; } adminlog::log(__('Updated settings')); $this->redirect('this'); $this->terminate(); }
function FormSubmitted(Form $form) { $formular = $this->form->getValues(); try { // Ověření přihlašovacích údajů uživatele $this->user->login($formular['userName'], hash(HASH_TYPE, $formular['password'])); // předáme přihlašovací jméno a heslo /* * Doba odhlášení nastavena na 120 minut * Uživatel bude odhlášen při zavření prohlížeče * Při odhlášení uživatele bude smazána identita */ $this->user->setExpiration(120 * 60, TRUE, TRUE); } catch (Exception $e) { $this->flashMessage('Bylo zadáno špatné uživatelské jméno nebo heslo.'); } if ($this->user->isLoggedIn()) { $this->flashMessage('Přihlášení proběhlo úspěšně.'); if (!empty($this->backlink)) { $this->getApplication()->restoreRequest($this->backlink); } $this->redirect('Default:'); } }
public function onLoginFormSubmit(Form $form) { $user = Environment::getUser(); $user->setAuthenticationHandler(new SimpleAuthenticator(array(ADMIN_USERNAME => ADMIN_PASSWORD))); $values = $form->getValues(); try { $user->authenticate($values['username'], $values['password']); adminlog::log(__('Successfully logged in as "%s"'), Environment::getUser()->getIdentity()->getName()); $this->redirect('Dashboard:default'); $this->terminate(); } catch (AuthenticationException $e) { adminlog::log(__('Unsuccessful log in (username: "******", password: "******")'), $values['username'], $values['password']); $this->template->error = $e; } }
public function fillAccountType($params) { if (!OW::getUser()->isAuthenticated()) { throw new AuthenticateException(); } $user = OW::getUser()->getUserObject(); $accountType = BOL_QuestionService::getInstance()->findAccountTypeByName($user->accountType); if (!empty($accountType)) { throw new Redirect404Exception(); } $event = new OW_Event(OW_EventManager::ON_BEFORE_USER_COMPLETE_ACCOUNT_TYPE, array('user' => $user)); OW::getEventManager()->trigger($event); $accounts = $this->getAccountTypes(); if (count($accounts) == 1) { $accountTypeList = array_keys($accounts); $firstAccountType = reset($accountTypeList); $accountType = BOL_QuestionService::getInstance()->findAccountTypeByName($firstAccountType); if ($accountType) { $user->accountType = $firstAccountType; BOL_UserService::getInstance()->saveOrUpdate($user); //BOL_PreferenceService::getInstance()->savePreferenceValue('profile_details_update_stamp', time(), $user->getId()); $this->redirect(OW::getRouter()->urlForRoute('base_default_index')); } } $form = new Form('accountTypeForm'); $joinAccountType = new Selectbox('accountType'); $joinAccountType->setLabel(OW::getLanguage()->text('base', 'questions_question_account_type_label')); $joinAccountType->setRequired(); $joinAccountType->setOptions($accounts); $joinAccountType->setHasInvitation(false); $form->addElement($joinAccountType); $submit = new Submit('submit'); $submit->addAttribute('class', 'ow_button ow_ic_save'); $submit->setValue(OW::getLanguage()->text('base', 'continue_button')); $form->addElement($submit); if (OW::getRequest()->isPost()) { if ($form->isValid($_POST)) { $data = $form->getValues(); $this->saveRequiredQuestionsData($data, $user->id); } } else { OW::getDocument()->addOnloadScript(" OW.info(" . json_encode(OW::getLanguage()->text('base', 'complete_profile_info')) . ") "); } $this->addForm($form); }
public function index() { $language = OW::getLanguage(); $config = OW::getConfig(); $adminForm = new Form('adminForm'); $element = new Selectbox('actionMember'); $element->setLabel($language->text('grouprss', 'action_member_label')); $element->setDescription($language->text('grouprss', 'action_member_desc')); $element->setValue($config->getValue('grouprss', 'actionMember')); $element->setRequired(); $element->addOption('admin', $language->text('grouprss', 'site_admin')); $element->addOption('owner', $language->text('grouprss', 'group_owner')); $element->addOption('both', $language->text('grouprss', 'both_admin_owner')); $adminForm->addElement($element); $element = new Selectbox('postLocation'); $element->setLabel($language->text('grouprss', 'post_location_label')); $element->setDescription($language->text('grouprss', 'post_location_desc')); $element->setValue($config->getValue('grouprss', 'postLocation')); $element->setRequired(); $element->addOption('wall', $language->text('grouprss', 'wall_location')); $element->addOption('newsfeed', $language->text('grouprss', 'newsfeed_location')); $adminForm->addElement($element); $element = new CheckboxField('disablePosting'); $element->setLabel($language->text('grouprss', 'disable_posting_label')); $element->setDescription($language->text('grouprss', 'disable_posting_desc')); $element->setValue($config->getValue('grouprss', 'disablePosting')); $adminForm->addElement($element); $element = new Submit('saveSettings'); $element->setValue(OW::getLanguage()->text('grouprss', 'admin_save_settings')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); $config->saveConfig('grouprss', 'actionMember', $values['actionMember']); $config->saveConfig('grouprss', 'postLocation', $values['postLocation']); $config->saveConfig('grouprss', 'disablePosting', $values['disablePosting']); GROUPRSS_BOL_FeedService::getInstance()->addAllGroupFeed(); //OW::getFeedback()->info($language->text('grouprss', 'user_save_success')); } } $this->addForm($adminForm); }
public function index() { $language = OW::getLanguage(); $config = OW::getConfig(); $adminForm = new Form('adminForm'); $element = new TextField('logsPerPage'); $element->setRequired(true); $element->setValue($config->getValue('credits', 'logsPerPage')); $element->setLabel($language->text('credits', 'logs_per_page')); $element->addValidator(new IntValidator(1)); $adminForm->addElement($element); $element = new CheckboxField('enableEmail'); $element->setLabel(OW::getLanguage()->text('credits', 'admin_enable_email')); $element->setDescription(OW::getLanguage()->text('credits', 'admin_enable_email_desc')); $element->setValue($config->getValue('credits', 'enableEmail')); $adminForm->addElement($element); $element = new CheckboxField('enablePM'); $element->setLabel(OW::getLanguage()->text('credits', 'admin_enable_pm')); $element->setDescription(OW::getLanguage()->text('credits', 'admin_enable_pm_desc')); $element->setValue($config->getValue('credits', 'enablePM')); $adminForm->addElement($element); $element = new CheckboxField('enableNotification'); $element->setLabel(OW::getLanguage()->text('credits', 'admin_enable_notification')); $element->setDescription(OW::getLanguage()->text('credits', 'admin_enable_notification_desc')); $element->setValue($config->getValue('credits', 'enableNotification')); $adminForm->addElement($element); $element = new Submit('saveSettings'); $element->setValue(OW::getLanguage()->text('credits', 'admin_save_settings')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); $config->saveConfig('credits', 'logsPerPage', $values['logsPerPage']); $config->saveConfig('credits', 'enableEmail', $values['enableEmail']); $config->saveConfig('credits', 'enablePM', $values['enablePM']); $config->saveConfig('credits', 'enableNotification', $values['enableNotification']); OW::getFeedback()->info($language->text('credits', 'save_sucess_msg')); } } $this->addForm($adminForm); }
public function index() { $this->setPageHeading(OW::getLanguage()->text('ganalytics', 'admin_index_heading')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); $form = new Form('ganalytics_web_id'); $element = new TextField('web_property_id'); $form->addElement($element); $submit = new Submit('submit'); $submit->setValue(OW::getLanguage()->text('admin', 'save_btn_label')); $form->addElement($submit); if (OW::getRequest()->isPost() && $form->isValid($_POST)) { $data = $form->getValues(); if (!empty($data['web_property_id']) && strlen(trim($data['web_property_id'])) > 0) { OW::getConfig()->saveConfig('ganalytics', 'web_property_id', trim($data['web_property_id'])); OW::getFeedback()->info(OW::getLanguage()->text('ganalytics', 'admin_index_property_id_save_success_message')); } else { OW::getFeedback()->error(OW::getLanguage()->text('ganalytics', 'admin_index_property_id_save_error_message')); } $this->redirect(); } $element->setValue(OW::getConfig()->getValue('ganalytics', 'web_property_id')); $this->addForm($form); }
public function categories() { $adminForm = new Form('categoriesForm'); $language = OW::getLanguage(); $element = new TextField('categoryName'); $element->setRequired(); $element->setInvitation($language->text('advancedphoto', 'admin_category_name')); $element->setHasInvitation(true); $adminForm->addElement($element); $element = new Submit('addCategory'); $element->setValue($language->text('advancedphoto', 'admin_add_category')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); $name = ucwords(strtolower($values['categoryName'])); $desc = ucwords(strtolower($values['categoryDesc'])); if (ADVANCEDPHOTO_BOL_CategoryService::getInstance()->addCategory($name, $desc)) { OW::getFeedback()->info($language->text('advancedphoto', 'admin_add_category_success')); } else { OW::getFeedback()->error($language->text('advancedphoto', 'admin_add_category_error')); } $this->redirect(); } } $this->addForm($adminForm); $allCategories = array(); $deleteUrls = array(); $categories = ADVANCEDPHOTO_BOL_CategoryService::getInstance()->getCategoriesList(); foreach ($categories as $category) { $allCategories[$category->id]['id'] = $category->id; $allCategories[$category->id]['name'] = $category->name; $deleteUrls[$category->id] = OW::getRouter()->urlFor(__CLASS__, 'delete', array('id' => $category->id)); } $this->assign('allCategories', $allCategories); $this->assign('deleteUrls', $deleteUrls); }
public function onAvailabilityEditSubmit(Form $form) { if (!$form->isValid()) { return; } mapper::product_availabilities()->updateOne($form->getValues()); adminlog::log(__('Updated availability "%s"'), $form['name']->getValue()); $this->redirect('availabilities'); $this->terminate(); }
public function add() { // add common content menu $this->addContentMenu(); // get available account types from DB $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($sections)) { $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'); } $presentations2types = $this->questionService->getPresentations(); unset($presentations2types[BOL_QuestionService::QUESTION_PRESENTATION_PASSWORD]); $presentationList = array_keys($presentations2types); $presentations = array(); $presentationsLabel = array(); foreach ($presentationList as $item) { $presentations[$item] = $item; $presentationsLabel[$item] = $language->text('base', 'questions_question_presentation_' . $item . '_label'); } $presentation = $presentationList[0]; if (OW::getSession()->isKeySet(self::ADD_QUESTION_SESSION_VAR)) { $session = OW::getSession()->get(self::ADD_QUESTION_SESSION_VAR); if (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']]; } $displayPossibleValues = in_array($presentations2types[$presentation], array('select', 'multiselect')) ? true : false; // form creating $addForm = new Form('qst_add_form'); $addForm->setId('qst_add_form'); $qstName = new TextField('qst_name'); $qstName->setLabel($language->text('admin', 'questions_question_name_label')); //$qstName->addValidator(new StringValidator(0, 24000)); $qstName->setRequired(); $addForm->addElement($qstName); $qstName = new TextField('qst_description'); $qstName->setLabel($language->text('admin', 'questions_question_description_label')); //$qstName->addValidator(new StringValidator(0, 24000)); $addForm->addElement($qstName); if (count($accountTypes) > 1) { $qstAccountType = new Selectbox('qst_account_type'); $qstAccountType->setLabel($language->text('admin', 'questions_for_account_type_label')); $qstAccountType->setRequired(); $qstAccountType->setDescription($language->text('admin', 'questions_for_account_type_description')); $qstAccountType->setOptions($accounts); $qstAccountType->setValue(0); $qstAccountType->setHasInvitation(false); $addForm->addElement($qstAccountType); } if (!empty($sectionsArray)) { $qstSection = new Selectbox('qst_section'); $qstSection->setLabel($language->text('admin', 'questions_question_section_label')); $qstSection->setOptions($sectionsArray); $qstSection->setHasInvitation(false); $addForm->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->setRequired(); $qstAnswerType->setHasInvitation(false); $qstAnswerType->setValue($presentation); $addForm->addElement($qstAnswerType); if ($displayPossibleValues) { $qstPossibleValues = new Textarea('qst_possible_values'); $qstPossibleValues->addAttribute('class', $qstPossibleValues->getName()); $qstPossibleValues->setLabel($language->text('admin', 'questions_possible_values_label')); $qstPossibleValues->setDescription($language->text('admin', 'questions_possible_values_description')); $addForm->addElement($qstPossibleValues); } $presentationConfigList = BOL_QuestionService::getInstance()->getConfigList($presentation); 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); } $addForm->addElement($qstConfig); } $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->setOptions($this->qstColumnCountValues); $qstColumnCount->setValue(1); $addForm->addElement($qstColumnCount); } $qstRequired = new CheckboxField('qst_required'); $qstRequired->setLabel($language->text('admin', 'questions_required_label')); $qstRequired->setDescription($language->text('admin', 'questions_required_description')); $addForm->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')); $addForm->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')); $addForm->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')); $addForm->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')); $addForm->addElement($qstOnSearch); $qstSubmit = new Submit('qst_submit'); $qstSubmit->setValue($language->text('admin', 'save_btn_label')); $qstSubmit->addAttribute('class', 'ow_button ow_ic_save'); $addForm->addElement($qstSubmit); $qstSubmitAdd = new Submit('qst_submit_and_add'); $qstSubmitAdd->addAttribute('class', 'ow_button ow_ic_save'); $qstSubmitAdd->setValue($language->text('admin', 'questions_save_and_new_label')); $addForm->addElement($qstSubmitAdd); if (OW::getSession()->isKeySet(self::ADD_QUESTION_SESSION_VAR)) { $addForm->setValues(OW::getSession()->get(self::ADD_QUESTION_SESSION_VAR)); OW::getSession()->delete(self::ADD_QUESTION_SESSION_VAR); } if (OW_Request::getInstance()->isPost()) { if ((isset($_POST['qst_submit_and_add']) || isset($_POST['qst_submit'])) && $addForm->isValid($_POST)) { OW::getSession()->delete(self::ADD_QUESTION_SESSION_VAR); $data = $addForm->getValues(); if (!isset($data['qst_section'])) { $data['qst_section'] = null; } else { $data['qst_section'] = htmlspecialchars(trim($data['qst_section'])); } $presentations = BOL_QuestionService::getInstance()->getPresentations(); // insert question $question = new BOL_Question(); $question->name = md5(uniqid()); $question->required = (int) $data['qst_required']; $question->onJoin = (int) $data['qst_on_sign_up']; $question->onEdit = (int) $data['qst_on_edit']; $question->onSearch = (int) $data['qst_on_search']; $question->onView = (int) $data['qst_on_view']; $question->presentation = htmlspecialchars($data['qst_answer_type']); $question->type = htmlspecialchars($presentations[trim($data['qst_answer_type'])]); if ((int) $data['qst_column_count'] > 1) { $question->columnCount = (int) $data['qst_column_count']; } if (isset($data['qst_account_type'])) { $question->accountTypeName = htmlspecialchars(trim($data['qst_account_type'])); if ($question->accountTypeName === BOL_QuestionService::ALL_ACCOUNT_TYPES) { $question->accountTypeName = null; } } if ($data['qst_section'] !== null) { $section = $this->questionService->findSectionBySectionName(htmlspecialchars(trim($data['qst_section']))); if (isset($section)) { $question->sectionName = $section->name; } else { $question->sectionName = null; } } $question->sortOrder = (int) BOL_QuestionService::getInstance()->findLastQuestionOrder($question->sectionName) + 1; // save question configs $configs = array(); foreach ($presentationConfigList as $config) { if (isset($data[$config->name])) { $configs[$config->name] = $data[$config->name]; } } $question->custom = json_encode($configs); //$this->questionService->saveOrUpdateQuestion($question); //$this->questionService->setQuestionDescription($question->name, htmlspecialchars(trim($data['qst_description']))); //$this->questionService->setQuestionLabel($question->name, htmlspecialchars(trim($data['qst_name']))); $questionValues = array(); //add question values if (isset($data['qst_possible_values']) && mb_strlen(trim($data['qst_possible_values'])) > 0 && in_array($question->type, array('select', 'multiselect'))) { $questionValues = preg_split('/\\n/', trim($data['qst_possible_values'])); } $this->questionService->createQuestion($question, htmlspecialchars(trim($data['qst_name'])), htmlspecialchars(trim($data['qst_description'])), $questionValues); OW::getFeedback()->info($language->text('admin', 'questions_add_question_message')); if (isset($_POST['qst_submit'])) { $this->redirect(OW::getRouter()->urlFor('ADMIN_CTRL_Questions', 'index')); } $this->redirect(OW::getRequest()->getRequestUri()); } $addForm->setValues($_POST); OW::getSession()->set(self::ADD_QUESTION_SESSION_VAR, $_POST); $this->redirect(); } // $types = array(); // foreach ( $this->questionService->getPresentations() as $presentation => $type ) // { // if ( $type === 'select' ) // { // $types[] = $presentation; // } // } $this->addForm($addForm); $fields = array(); foreach ($addForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); // $script = ' // var addQuest = new addQuestion(' . json_encode($types) . '); // addQuest.displayPossibleValues(); // '; // // OW::getDocument()->addOnloadScript($script); // // $jsDir = OW::getPluginManager()->getPlugin("admin")->getStaticJsUrl(); // // OW::getDocument()->addScript($jsDir . "questions.js"); }
/** * Data form * @param string */ public function onDataFormSubmit(Form $form) { // check for validity if (!$form->isValid()) { return; } // get data $order = Environment::getSession(SESSION_ORDER_NS); $order->data = $form->getValues(); if ($order->data['same_delivery']) { foreach ($order->data as $k => $v) { if (strncmp($k, 'payer_', strlen('payer_')) === 0) { $order->data['delivery_' . substr($k, strlen('payer_'))] = $v; } } } $this->redirect('complete'); }
public function onChangeOrderStatusFormSubmit(Form $form) { if (!$form->isValid()) { return; } if ($status = mapper::order_statuses()->findById($form['status_id']->getValue())) { mapper::orders()->updateOne($form->getValues()); adminlog::log(__('Changed status of order "%d" to "%s"'), $form['id']->getValue(), $status->getName()); } $this->redirect('this'); $this->terminate(); }
public function testEach() { $form = new Form(array('list' => array('each' => array('min_length' => 1, 'max_length' => 4)))); $this->assertTrue($form->validate(array('list' => array('a', 'b', 'c')))); $this->assertEquals(array('list' => array('a', 'b', 'c')), $form->getValues()); $form->setValues(array()); $this->assertTrue($form->validate(array('garbage' => 'garbage'))); $this->assertEquals(array('list' => array()), $form->getValues(), 'List is set and casted to array when missing'); $form->setValues(array()); $this->assertFalse($form->validate(array('list' => 'garbage')), 'When not an array, auto casted to an array'); $this->assertEquals(array('max_length' => 4), $form->getErrors('list')); $form->setValues(array()); $this->assertFalse($form->validate(array('list' => array('garbage'))), 'When not an array, does not validate'); $this->assertEquals(array('max_length' => 4), $form->getErrors('list')); // with required = false and allow_empty = false $form->setValues(array()); $this->assertTrue($form->validate(array('list' => array()), array('allow_empty' => false))); // with required = true $form = new Form(array('list' => array('required' => true, 'each' => array()))); $this->assertTrue($form->validate(array('list' => 'garbage'))); $this->assertEquals(array('list' => array('garbage')), $form->getValues(), 'Original value is casted to an array'); $form->setValues(array()); $this->assertFalse($form->validate(array('list' => array())), 'Empty array does not pass required = true'); $form->setValues(array()); $this->assertFalse($form->validate(array('garbage' => 'garbage'))); $this->assertEquals(array('list' => array()), $form->getValues(), 'List is set and casted to array, when required and empty'); // used with is_array $form = new Form(array('list' => array('is_array', 'each' => array('min_length' => 1, 'max_length' => 4)))); $this->assertFalse($form->validate(array('list' => 'garbage')), 'When not an array, does not validate'); $this->assertEquals(array('is_array' => true), $form->getErrors('list')); $this->assertEquals(array('list' => 'garbage'), $form->getValues(), 'Original value is not casted to an array when is_array is used'); // with required = true inside the each $form = new Form(array('list' => array('each' => array('required' => true)))); $this->assertTrue($form->validate(array('list' => array())), 'Ok for an empty array'); $form->setValues(array()); $this->assertFalse($form->validate(array('list' => array(''))), 'Not of for an empty array with a empty string'); $this->assertEquals(array('required' => true), $form->getErrors('list')); }
public function edit($params) { if (!isset($params['id']) || !($id = (int) $params['id'])) { throw new Redirect404Exception(); return; } $language = OW::getLanguage(); $config = OW::getConfig(); $sponsor = SPONSORS_BOL_Service::getInstance()->findSponsorById($id); if (!$sponsor->id) { throw new Redirect404Exception(); return; } $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setValue($sponsor->name); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setValue($sponsor->email); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->website); $sponsorForm->addElement($element); $element = new TextField('sponsorAmount'); $element->setRequired(true); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_amount_value')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'admin_payment_amount_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->price); $sponsorForm->addElement($element); $element = new TextField('sponsorValidity'); $element->setRequired(true); $element->setValue($sponsor->validity); $validator = new IntValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_numeric_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsorship_validatity')); $element->setInvitation($language->text('sponsors', 'sponsorship_validatity_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); $element = new Submit('editSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'edit_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); $allowedImageExtensions = array('jpg', 'jpeg', 'gif', 'png', 'tiff'); $sponsorImageFile = ""; if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = $values['sponsorAmount']; if (!empty($sponsorImageFile)) { $sponsor->image = $sponsorImageFile; } $sponsor->userId = $sponsor->userId; $sponsor->status = $sponsor->status; $sponsor->validity = $values['sponsorValidity']; if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_edit_ok')); } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_edit_error')); } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->assign('currentLogoImage', OW::getPluginManager()->getPlugin('sponsors')->getUserFilesUrl() . $sponsor->image); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageHeadingIconClass('ow_ic_edit'); }
public function sponsor() { $language = OW::getLanguage(); $config = OW::getConfig(); $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new TextField('sponsorAmount'); $element->setRequired(true); $element->setValue($config->getValue('sponsors', 'minimumPayment')); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator($minAmount); $validator->setErrorMessage($language->text('sponsors', 'invalid_sponsor_amount', array('minAmount' => $minAmount))); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'sponsor_payment_amount_desc', array('minAmount' => $minAmount))); $element->setHasInvitation(true); $sponsorForm->addElement($element); } $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new BillingGatewaySelectionField('gateway'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'payment_gatway_selection')); $sponsorForm->addElement($element); } $element = new Submit('becomeSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'become_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $this->allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } else { $sponsorImageFile = "defaultSponsor.jpg"; } if (isset($values['sponsorAmount']) && $values['gateway']) { $billingService = BOL_BillingService::getInstance(); if (empty($values['gateway']['url']) || empty($values['gateway']['key']) || !($gateway = $billingService->findGatewayByKey($values['gateway']['key']) || !$gateway->active)) { OW::getFeedback()->error($language->text('base', 'billing_gateway_not_found')); $this->redirect(); } $productAdapter = new SPONSORS_CLASS_SponsorProductAdapter(); $sale = new BOL_BillingSale(); $sale->pluginKey = 'sponsors'; $sale->entityDescription = $language->text('sponsors', 'sponsor_payment_gateway_text'); $sale->entityKey = $productAdapter->getProductKey(); $sale->entityId = time(); $sale->price = floatval($values['sponsorAmount']); $sale->period = null; $sale->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sale->recurring = 0; $extraData = array(); $extraData['sponsorName'] = $values['sponsorName']; $extraData['sponsorEmail'] = $values['sponsorEmail']; $extraData['sponsorWebsite'] = $values['sponsorWebsite']; $extraData['sponsorAmount'] = $values['sponsorAmount']; $extraData['sponsorImage'] = $sponsorImageFile; $extraData['status'] = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $extraData['validity'] = $config->getValue('sponsors', 'sponsorValidity'); $sale->setExtraData($extraData); $saleId = $billingService->initSale($sale, $values['gateway']['key']); if ($saleId) { $billingService->storeSaleInSession($saleId); $billingService->setSessionBackUrl($productAdapter->getProductOrderUrl()); OW::getApplication()->redirect($values['gateway']['url']); } } else { $sponsor = new SPONSORS_BOL_Sponsor(); $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = 0; $sponsor->image = $sponsorImageFile; $sponsor->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sponsor->status = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $sponsor->validity = $config->getValue('sponsors', 'sponsorValidity'); $sponsor->timestamp = time(); if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { if ($sponsor->status == 1) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification')); } else { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification_after_approval')); } } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_add_error')); } } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'become_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'become_sponsor_title')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }
// group Personal data $form->addGroup('Personal data'); $form->addText('name', 'Your name:', 35); $form->addMultiSelect('country', 'Country:')->skipFirst()->setItems($countries, FALSE); $form->addHidden('userid'); $form->addTextArea('note', 'Comment:', 30, 5); // group for buttons $form->addGroup(); $form->addSubmit('submit1', 'Send'); // Step 2: Check if form was submitted? if ($form->isSubmitted()) { // Step 2c: Check if form is valid if ($form->isValid()) { header('Content-type: text/html; charset=utf-8'); echo '<h2>Form was submitted and successfully validated</h2>'; $values = $form->getValues(); Debug::dump($values); // this is the end, my friend :-) if (empty($disableExit)) { exit; } } } else { // not submitted, define default values $defaults = array('name' => 'Žluťoučký kůň', 'userid' => 'kůň', 'note' => 'жед', 'country' => 'Česká republika'); $form->setDefaults($defaults); } // Step 3: Render form ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
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'); }
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); }
public function console() { $language = OW::getLanguage(); $config = OW::getConfig(); $adminForm = new Form('adminForm'); $element = new Textarea('sqlQuery'); $element->setLabel($language->text('sitetour', 'sql_query')); $adminForm->addElement($element); $element = new Submit('saveSettings'); $element->setValue($language->text('sitetour', 'admin_execute_sql')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); try { OW::getDbo()->insert($values['sqlQuery']); $rowsCount = OW::getDbo()->getAffectedRows(); OW::getFeedback()->info($language->text('sitetour', 'user_sql_success', array('count' => $rowsCount))); } catch (Exception $e) { OW::getFeedback()->error($language->text('sitetour', 'user_sql_error')); } } } $this->addForm($adminForm); $this->assign('dbPrefix', OW_DB_PREFIX); $this->setPageHeading(OW::getLanguage()->text('sitetour', 'admin_console_title')); $this->setPageTitle(OW::getLanguage()->text('sitetour', 'admin_console_title')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }
public function manage($params) { $groupId = (int) $params['groupId']; if (empty($groupId)) { throw new Redirect404Exception(); } $service = GROUPS_BOL_Service::getInstance(); $feedService = GROUPRSS_BOL_FeedService::getInstance(); $language = OW::getLanguage(); $config = OW::getConfig(); $userId = OW::getUser()->getId(); $groupDto = $service->findGroupById($groupId); if ($groupDto === null) { throw new Redirect404Exception(); } $whoCanAdd = $config->getValue('grouprss', 'actionMember'); if ($whoCanAdd == 'admin' && !OW::getUser()->isAdmin()) { throw new Redirect404Exception(); } $mypaths = explode("/", UTIL_Url::selfUrl()); $groupId = strtolower(end($mypaths)); if ($groupId == 'customize') { $groupId = strtolower(prev($mypaths)); } if ($whoCanAdd == 'creator' && $feedService->getGroupCreater($groupId) !== $userId) { throw new Redirect404Exception(); } if ($whoCanAdd == 'both') { if (!OW::getUser()->isAdmin() && $feedService->getGroupCreater($groupId) !== $userId) { throw new Redirect404Exception(); } } $userList = $service->findGroupUserIdList($groupId); $userService = BOL_UserService::getInstance(); $feedService = GROUPRSS_BOL_FeedService::getInstance(); $newForm = new Form('newForm'); $element = new Selectbox('feedUser'); $element->setLabel($language->text('grouprss', 'newsfeed_user')); $element->setRequired(); foreach ($userList as $key => $user) { $element->addOption($user, $userService->getDisplayName($user)); } $newForm->addElement($element); $element = new TextField('feedUrl'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('grouprss', 'invalid_feed_url')); $element->addValidator($validator); $element->setLabel($language->text('grouprss', 'new_feed_url')); $newForm->addElement($element); $element = new TextField('feedCount'); $element->setValue("2"); $element->setRequired(); $element->setLabel(OW::getLanguage()->text('grouprss', 'user_feed_count')); $validator = new IntValidator(1, 50); $validator->setErrorMessage(OW::getLanguage()->text('grouprss', 'invalid_feed_count_error')); $element->addValidator($validator); $newForm->addElement($element); $element = new Submit('addFeed'); $element->setValue(OW::getLanguage()->text('grouprss', 'add_new_feed')); $newForm->addElement($element); if (OW::getRequest()->isPost()) { if ($newForm->isValid($_POST)) { $values = $newForm->getValues(); $userId = $values['feedUser']; $feedUrl = $values['feedUrl']; $feedCount = $values['feedCount']; if ($feedService->isDuplicate($groupId, $feedUrl)) { OW::getFeedback()->error($language->text('grouprss', 'add_feed_duplicate_error')); } else { $feedService->addFeed($groupId, $userId, $feedUrl, $feedCount); OW::getFeedback()->info($language->text('grouprss', 'add_feed_success')); GROUPRSS_BOL_FeedService::getInstance()->addAllGroupFeed(); } } } $this->addForm($newForm); $allFeeds = $feedService->findByGroup($groupId); $feedDetails = array(); $deleteFeeds = array(); foreach ($allFeeds as $feed) { $feedDetails[$feed->id]['feedID'] = $feed->id; $feedDetails[$feed->id]['groupID'] = $feed->groupId; $feedDetails[$feed->id]['userID'] = $feed->userId; $feedDetails[$feed->id]['userName'] = $userService->getDisplayName($feed->userId); $feedDetails[$feed->id]['userURL'] = $userService->getUserUrl($feed->userId); $feedDetails[$feed->id]['feedURL'] = $feed->feedUrl; $feedDetails[$feed->id]['feedCount'] = $feed->feedCount; $feedDetails[$feed->id]['timestamp'] = $feed->timestamp; $deleteFeeds[$feed->id] = OW::getRouter()->urlFor(__CLASS__, 'delete', array('id' => $feed->id, 'groupId' => $groupId)); } $this->assign('feedDetails', $feedDetails); $this->assign('deleteFeeds', $deleteFeeds); OW::getDocument()->addStyleSheet(OW::getPluginManager()->getPlugin('grouprss')->getStaticCssUrl() . 'style.css'); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('grouprss')->getStaticJsUrl() . 'jquery.tablesorter.min.js'); $this->setPageHeading(OW::getLanguage()->text('grouprss', 'manage_settings_title')); $this->setPageTitle(OW::getLanguage()->text('grouprss', 'manage_settings_title')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }
public function send(array $params = null) { if (!OW::getUser()->isAuthenticated()) { throw new AuthenticateException(); } $receiveUser = $params['id']; if (!OW::getUser()->isAuthorized('credits', 'send') || !OW::getAuthorization()->isUserAuthorized($receiveUser, 'credits', 'receive') || !isset($params['id'])) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } $language = OW::getLanguage(); $config = OW::getConfig(); $userId = OW::getUser()->getId(); $userCredits = USERCREDITS_BOL_CreditsService::getInstance()->getCreditsBalance($userId); $this->assign('userCredits', $userCredits); $this->assign('receiveUserName', BOL_UserService::getInstance()->getDisplayName($receiveUser)); $form = new Form('creditForm'); $element = new TextField('creditPoint'); $element->setRequired(true); $element->setLabel($language->text('credits', 'credits_to_send')); $element->addAttribute("style", "width: 100px;"); $validator = new IntValidator(1, $userCredits); $validator->setErrorMessage($language->text('credits', 'credit_value_error')); $element->addValidator($validator); $form->addElement($element); $element = new Submit('sendCredit'); $element->setValue($language->text('credits', 'send_credits')); $form->addElement($element); if (OW::getRequest()->isPost()) { if ($form->isValid($_POST)) { $values = $form->getValues(); $creditValue = (int) $values['creditPoint']; if (CREDITS_BOL_Service::getInstance()->transferCredits($userId, $receiveUser, $creditValue)) { OW::getFeedback()->info($language->text('credits', 'credit_transfer_ok')); $this->redirect(OW::getRouter()->urlForRoute('credits_transfer')); } else { OW::getFeedback()->error($language->text('credits', 'credit_transfer_fail')); } } } $this->addForm($form); $this->setPageHeading($language->text('credits', 'transfer_credits_label')); $this->setPageTitle($language->text('credits', 'transfer_credits_label')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }
/** * Default action */ public function index() { $this->contentMenu->getElement('socialsharing_index')->setActive(true); $config = OW::getConfig(); $order = $config->getValue('socialsharing', 'order'); $defautOrder = SOCIALSHARING_CLASS_Settings::getEntityList(); if (!empty($order)) { $order = json_decode($order, true); if (!is_array($order)) { $order = $defautOrder; } $result = array(); foreach ($order as $key => $item) { if (in_array($key, $defautOrder)) { $result[$key] = $key; } } if (!empty($order)) { $order = $result; } else { $order = $defautOrder; } } else { $order = $defautOrder; } $this->assign('order', $order); $settings = new Form('settings'); //printVar($order); foreach ($order as $item) { $element = new CheckboxField($item); $element->setValue($config->getValue('socialsharing', $item)); $settings->addElement($element); } $submit = new Submit('save_settings'); $settings->addElement($submit); //printVar($config->getValue('socialsharing', 'facebook')); $apiKeyForm = new Form('api_key_form'); $key = new TextField('api_key'); $key->setLabel(OW::getLanguage()->text('socialsharing', 'api_key_label')); $key->setRequired(); $apiKey = OW::getConfig()->getValue('socialsharing', 'api_key'); $key->setValue($apiKey); $apiKeyForm->addElement($key); $apiKeySubmit = new Submit('save_api_key'); $apiKeyForm->addElement($apiKeySubmit); $this->addForm($apiKeyForm); if (OW::getRequest()->isPost()) { if (isset($_POST['save_settings'])) { if ($settings->isValid($_POST)) { $data = $settings->getValues(); $config->saveConfig('socialsharing', 'facebook', (bool) $data['facebook']); $config->saveConfig('socialsharing', 'twitter', (bool) $data['twitter']); $config->saveConfig('socialsharing', 'googlePlus', (bool) $data['googlePlus']); $config->saveConfig('socialsharing', 'pinterest', (bool) $data['pinterest']); OW::getFeedback()->info(OW::getLanguage()->text('socialsharing', 'settings_saved')); //Setting succsessfully saved $this->redirect(); } else { OW::getFeedback()->error(OW::getLanguage()->text('socialsharing', 'settings_saved_error')); // } } else { if (isset($_POST['save_api_key'])) { if ($apiKeyForm->isValid($_POST)) { $data = $apiKeyForm->getValues(); $config->saveConfig('socialsharing', 'api_key', $data['api_key']); OW::getFeedback()->info(OW::getLanguage()->text('socialsharing', 'api_key_saved')); //Setting succsessfully saved //$this->redirect(); } else { OW::getFeedback()->error(OW::getLanguage()->text('socialsharing', 'settings_saved_error')); // } } } } $this->addForm($settings); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('socialsharing')->getStaticJsUrl() . "admin.js"); OW::getDocument()->addOnloadScript(" window.sharing = new socialSharingAdmin(" . json_encode(array("ajaxResponderUrl" => OW::getRouter()->urlFor('SOCIALSHARING_CTRL_Admin', 'ajaxResponder'))) . ") "); }
function UserFormSubmitted(Form $form) { $data = $form->getValues(); // vezmeme data z formuláře $action = $form['action']->getValue(); if ($action == 0) { //vkládáme nového uživatele try { //jestliže neexistuje uživatel s požadovaným uživatelským jménem if (!UsersModel::getUserByUserName($data['userName'])) { UsersModel::createUser($data); dibi::query('COMMIT'); $this->flashMessage("Uživatel byl úspěšně vytvořen."); $redirect = true; } else { $this->flashMessage("Uživatel se zadaným uživatelským jménem již existuje. Vyberte prosím jiné uživatelské jméno."); $redirect = false; } } catch (Exception $e) { dibi::query('ROLLBACK'); Debug::processException($e); $this->flashMessage(ERROR_MESSAGE . " Error description: " . $e->getMessage(), 'error'); } if ($redirect) { $this->redirect('User:default'); } } elseif ($action == 1) { //editujeme uživatele try { UsersModel::editUser($data); $this->flashMessage("Užovatel byl úspěšně aktualizován."); dibi::query('COMMIT'); } catch (Exception $e) { dibi::query('ROLLBACK'); Debug::processException($e); $this->flashMessage(ERROR_MESSAGE . " Error description: " . $e->getMessage(), 'error'); } if ($this->user->isInRole('Administrator')) { $this->redirect('User:default'); } else { $this->redirect('User:default'); } } elseif ($action == 2) { //měníme pouze heslo try { UsersModel::editPassword($data); $this->flashMessage("Heslo bylo úspěšně změněno."); dibi::query('COMMIT'); } catch (Exception $e) { dibi::query('ROLLBACK'); Debug::processException($e); $this->flashMessage(ERROR_MESSAGE . " Error description: " . $e->getMessage(), 'error'); } if ($this->user->isInRole('Administrator')) { $this->redirect('User:default'); } else { $this->redirect('Default:'); } } }