Example #1
0
 public function actionDefault($backlink)
 {
     $this->backlink = $backlink;
     $this->form = new AppForm($this, 'login');
     $this->form->addText('userName', 'Uživatelské jméno:')->addRule(Form::FILLED, 'Uživatelské jméno musí být vyplněno.');
     $this->form->addPassword('password', 'Přístupové heslo:')->addRule(Form::FILLED, 'Přístupové heslo musí být vyplněno.');
     //->addRule(Form::MIN_LENGTH, 'Heslo musí být minimálně %d znaků', 12);
     $this->form->addSubmit('login', 'Přihlásit');
     $this->form->onSubmit[] = array($this, 'FormSubmitted');
     $this->template->form = $this->form;
     if (!isset($this->template->result)) {
         $this->template->result = "";
     }
     $this->user->setAuthenticationHandler(new UsersModel());
 }
Example #2
0
 public static function display()
 {
     $messages = "";
     if ($_POST['cc_form'] === 'add-group') {
         $group = $_POST['group'];
         $rows = Database::select('users', 'name', array('name = ? AND type = ?', $group, 'group'), null, 1)->fetch(PDO::FETCH_ASSOC);
         if (!empty($rows)) {
             $messages .= Message::error(__('admin', 'group-in-use'));
         } else {
             $row = DB::select('users', array('data'), array('users_id = ?', $_GET['parent']))->fetch(PDO::FETCH_ASSOC);
             $inheritance = unserialize($row['data']);
             $inheritance = $inheritance['permissions'];
             $result = Database::insert('users', array('name' => filter('admin_add_group_name', $group), 'type' => 'group', 'group' => '-1', 'data' => serialize(filter('admin_add_group_data', array('permissions' => $inheritance)))));
             if ($result === 1) {
                 $messages .= Message::success(__('admin', 'group-added'));
             }
         }
     }
     $form = new Form('self', 'post', 'add-group');
     $form->startFieldset(__("admin", 'group-information'));
     $form->addInput(__('admin', 'group-name'), 'text', 'group', self::get('group'));
     $groups = Users::allGroups();
     foreach ($groups as $key => $value) {
         $groups[$value->getId()] = $value->getName();
     }
     $form->addSelectList(__('admin', 'inherit-permissions'), 'parent', $groups);
     plugin('admin_add_group_custom_fields', array(&$form));
     $form->addSubmit('', 'add-group', __('admin', 'add-group'));
     $form->endFieldset();
     plugin('admin_add_group_custom_fieldset', array(&$form));
     $form = $form->endAndGetHTML();
     return array(__('admin', 'add-group'), $messages . $form);
 }
Example #3
0
 protected function createComponentForm()
 {
     $form = new Form();
     $form->addText('title', 'Titulek', 80)->addRule(Form::FILLED, 'Vyplňte prosím titulek!');
     $form->addTextarea('text', 'Text', 50, 20)->addRule(Form::FILLED, 'Vyplňte prosím text článku!')->getControlPrototype()->setClass('wysiwyg');
     $form->addSubmit('ok', 'Upravit')->getControlPrototype()->data['confirm'] = "Opravdu chcete upravit tento clanek?";
     $form->onSuccess[] = callback($this, 'process');
     return $form;
 }
Example #4
0
 private function loginForm()
 {
     $form = new Form();
     $form->setAction(Lib_Link::build('login/login'));
     $form->addText('userLogin', 'Jmeno:', 10)->addRule(Form::FILLED, 'Vloz svoje uzivatelske jmeno.');
     $form->addPassword('userPassword', 'Heslo:', 10)->addRule(Form::FILLED, 'Vloz tvoje heslo.')->addRule(Form::MIN_LENGTH, 'Heslo musi byt dlouhe minimalne %d znaku.', 3);
     $form->addSubmit('login', 'Prihlasit');
     return $form . '';
 }
Example #5
0
 public function actionUserChange($akce = 0, $id = -1)
 {
     $this->access($id);
     //kvůli Nette - action je vyhrazeno
     $action = $akce;
     $this->verifyUser();
     $this->form = new AppForm($this, 'userChange');
     //TODO: Definovat zprávu
     //$this->form->addProtection($this->formProtectedMessage);
     $msg = 'Heslo musí obsahovat VELKÁ a malá písmena a číslice!';
     $this->form->addGroup('Přihlašovací informace');
     $this->form->addText('userName', 'Uživatelské jméno:')->addRule(Form::FILLED, 'Uživatelské jméno musí být vyplněno.')->addRule(Form::MIN_LENGTH, 'Uživatelské jméno musí mít alespoň %d znaky.', 4)->addRule(Form::MAX_LENGTH, 'Uživatelské jméno může mít nejvýše %d znaků.', 20);
     if ($action > 0) {
         $this->form['userName']->setDisabled(true);
     }
     if ($action != 1) {
         $this->form->addPassword('password1', 'Heslo:')->addRule(Form::FILLED, 'Heslo musí být vyplněno.')->addRule(Form::MIN_LENGTH, 'Heslo musí mít alespoň %d znaků.', 8)->addRule(Form::MAX_LENGTH, 'Heslo může mít nejvýše %d znaků', 50)->addRule(Form::REGEXP, $msg, '/[A-Z]+/')->addRule(Form::REGEXP, $msg, '/[a-z]+/')->addRule(Form::REGEXP, $msg, '/[0-9]+/');
         $this->form->addPassword('password2', 'Přístupové heslo (pro kontrolu):')->addRule(Form::EQUAL, 'Zadaná hesla se neshodují.', $this->form['password1']);
         $this->form->addText('navrhHesla', 'Navrhované heslo:');
     }
     if ($action < 2) {
         $this->form->addGroup('Osobní informace');
         $this->form->addText('firstName', 'Jméno:')->addRule(Form::FILLED, 'Jméno musí být vyplněno.');
         $this->form->addText('surname', 'Přijmení:')->addRule(Form::FILLED, 'Přijmení musí být vyplněno.');
         $this->form->addText('title', 'Titul:')->addRule(Form::MAX_LENGTH, 'Titul může mít nejvýše %d znaků.', 10);
         $this->form->addGroup('Kontaktní informace');
         $this->form->addText('email', 'E-mail:')->addRule(Form::FILLED, 'E-mail musí být vyplněn.')->addRule(Form::EMAIL, 'Zadaný e-mail není platný.');
         $this->form->addText('icq', 'ICQ:')->addCondition(Form::FILLED)->addRule(Form::NUMERIC, 'ICQ musí být číslo.')->addRule(Form::MAX_LENGTH, 'ICQ může mít nejvýše %d znaků.', 10);
         $this->form->addText('skype', 'Skype:')->addRule(Form::MAX_LENGTH, 'Skype může mát nejvýše %d znaků.', 50);
         $this->form->addText('mobile', 'Mobilní telefon:')->addCondition(Form::FILLED)->addRule(Form::NUMERIC, 'Mobilní telefon musí být číslo.')->addRule(Form::MAX_LENGTH, 'Mobilní telefon může mít nejvýše %d znaků.', 20);
         $roles = UsersModel::getRoles();
         // Zobrazujeme pouze tehdy je-li uživatel administrátor - aby si uživatel sám nemohl měnit skupinu
         if ($this->user->isInRole('Administrator')) {
             $this->form->addGroup('Přístupová práva (může být vybráno více skupin)');
             $this->form->addMultiSelect('prava', 'Přístupová práva:', $roles, 2);
         }
     }
     $this->form->onSubmit[] = array($this, 'UserFormSubmitted');
     $this->form->addHidden('action')->setValue($action);
     if ($action > 0) {
         $data = UsersModel::getUser($id);
         $data['navrhHesla'] = UsersModel::genPass();
         // Nastavíme výchozí hodnoty pro formulář
         $this->form->setDefaults($data);
         $this->form->addHidden('id')->setValue($id);
         $this->form->addSubmit('ok', 'Aktualizovat');
         //            ->onClick[] = array($this, 'OkClicked'); // nebo 'OkClickHandler'
     } else {
         $data['navrhHesla'] = UsersModel::genPass();
         // Nastavíme výchozí hodnoty pro formulář
         $this->form->setDefaults($data);
         $this->form->addSubmit('ok', 'Vytvořit');
         //            ->onClick[] = array($this, 'OkClicked'); // nebo 'OkClickHandler'
     }
     $this->template->form = $this->form;
 }
Example #6
0
 public function actionAddReply($id, $internal)
 {
     $this->form = new AppForm($this, 'sendReply');
     $this->form->addHidden('tiket', $id);
     $this->form->addHidden('internal', $internal);
     $this->form->addTextArea('message', 'Odpověď/komentář:', 10);
     $this->form->addSubmit('send', 'Odeslat');
     $this->form->onSubmit[] = array($this, 'ReplyFormProcess');
     $this->template->form = $this->form;
 }
Example #7
0
 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;
 }
Example #8
0
File: CRUD.php Project: atk4/atk4
 /**
  * Configures necessary components when CRUD is in the editing mode.
  *
  * @param array $fields List of fields for add form
  *
  * @return void|Model If model, then bail out, no greed needed
  */
 protected function configureEdit($fields = null)
 {
     // We are actually in the frame!
     if ($this->isEditing('edit')) {
         $m = $this->form->setModel($this->model, $fields);
         $m->load($this->id);
         $this->form->addSubmit();
         $this->form->onSubmit(array($this, 'formSubmit'));
         return $m;
     } elseif ($this->isEditing()) {
         return;
     }
     $this->virtual_page->addColumn('edit', 'Editing ' . $this->entity_name, array('descr' => 'Edit', 'icon' => 'pencil'), $this->grid);
 }
Example #9
0
 public static function display()
 {
     if (!is_numeric($_GET['id'])) {
         cc_redirect(Admin::link('users'));
     }
     if ($_POST['cc_form'] == 'edit-group') {
         $id = $_GET['id'];
         $previous = (array) unserialize(urldecode($_POST['previous']));
         $group = $_POST['group'];
         $permissions = (array) $_POST['permissions'];
         $new = array_merge($previous, $permissions);
         foreach ($new as $k => $v) {
             if ($v == "1") {
                 $new[$k] = true;
             }
             if (!array_key_exists($k, $permissions)) {
                 $new[$k] = false;
             }
         }
         if (DB::update('users', array('name', 'data'), array($group, serialize(filter('admin_edit_group_data', array('permissions' => $new)))), array('users_id = ?', $id))) {
             $message = Message::success(__('admin', 'group-information-updated'));
         } else {
             $message = Message::error(__('admin', 'database-error'));
         }
     }
     $p = Permissions::getAll();
     $g = new Group((int) $_GET['id']);
     $p_form = new Form('');
     $p_form->setCC_Form('edit-group');
     $p_form->startFieldset(__('admin', 'group-information'));
     $p_form->addInput(__('admin', 'group-name'), 'text', 'group', $g->getName());
     $p_form->endFieldset();
     $p_form->addHTML(sprintf("<h3>%s</h3>", __('admin', 'permissions')));
     $p_table = new Table('permissions');
     $p_table->addHeader(array('Name', 'Allowed'));
     foreach ($p as $k => $v) {
         $previous[$v['name']] = $g->isAllowed($v['name']);
         $p_table->addRow(array(__('permissions', $v['name']), sprintf('<input type="checkbox" name="permissions[%s]"%svalue="1"/>', $v['name'], $g->isAllowed($v['name']) ? ' checked="checked"' : '')));
     }
     $p_form->addHidden('previous', urlencode(serialize($previous)));
     $p_form->addHTML($p_table->html());
     $p_form->addSubmit('', 'save-permissions', __('admin', 'save-changes'));
     return array(sprintf('%s: %s', __('admin', 'edit-group'), $g->getName()), $message . $p_form->html());
 }
Example #10
0
 public static function display()
 {
     $messages = "";
     if ($_POST['cc_form'] === 'add-user') {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $cpassword = $_POST['confirm-password'];
         $group = $_POST['group'];
         if ($password != $cpassword) {
             $messages .= Message::error(__('admin', 'passwords-dont-match'));
         } else {
             $rows = Database::select('users', 'name', array('name = ? AND type = ?', $username, 'user'), null, 1)->fetch(PDO::FETCH_ASSOC);
             if (!empty($rows)) {
                 $messages .= Message::error(__('admin', 'username-in-use'));
             } else {
                 $hash = hash('whirlpool', $password);
                 $result = Database::insert('users', array('name' => filter('admin_add_user_username', $username), 'value' => $hash, 'type' => 'user', 'group' => filter('admin_add_group', $group), 'data' => serialize(filter('admin_add_user_data', array()))));
                 if ($result === 1) {
                     $messages .= Message::success(__('admin', 'user-added'));
                 }
             }
         }
     }
     $form = new Form('self', 'post', 'add-user');
     $groups = Users::allGroups();
     foreach ($groups as $key => $value) {
         $groups[$value->getId()] = $value->getName();
     }
     $form->startFieldset(__("admin", 'user-information'));
     $form->addInput(__('admin', 'username'), 'text', 'username', self::get('username'));
     $form->addInput(__('admin', 'password'), 'password', 'password');
     $form->addInput(__('admin', 'confirm-password'), 'password', 'confirm-password');
     $form->addSelectList(__('admin', 'group'), 'group', $groups, true, self::get('group'));
     plugin('admin_add_user_custom_fields', array(&$form));
     $form->addSubmit('', 'add-user', __('admin', 'add-user'));
     $form->endFieldset();
     plugin('admin_add_user_custom_fieldset', array(&$form));
     $form = $form->endAndGetHTML();
     return array(__('admin', 'add-user'), $messages . $form);
 }
Example #11
0
 public static function display()
 {
     $type = $_GET['type'];
     $types = Content::contentTypes();
     if (array_key_exists($type, $types) === false && array_key_exists($_POST['type'], $types) === false) {
         $opt_list = array();
         foreach ($types as $single_type => $class) {
             $opt_list[$single_type] = call_user_func($class . '::name');
         }
         $form = new Form('self', 'post', 'add_node_1');
         $form->addSelectList(__('admin', 'content-type'), 'type', $opt_list, true, 'page');
         $form->addSubmit('', 'continue', __('admin', 'continue'));
         return array(__('admin', 'add-page'), $form->endAndGetHTML());
     }
     if (!$type && $_POST['type']) {
         if (array_key_exists('continue', $_POST)) {
             cc_redirect(Admin::link($_GET['page'], array('type' => $_POST['type'])));
         } else {
             return;
         }
     }
     AdminSidebar::registerForPage('content/create-page', 'EditPage::fileUploadBlock');
     return Content::nodeDisplay('create_display', $type, array());
 }
Example #12
0
 public static function create_display()
 {
     i18n::set('admin');
     if ($_POST['cc_form'] == 'create_page') {
         plugin('admin_create_post_pre_proccessing');
         $id = $_GET['id'];
         $title = filter('admin_create_post_title', self::get('title'));
         $content = filter('admin_create_post_content', self::get('content_area'));
         $last_modified = filter('admin_create_post_last_modified', time());
         $settings = filter('admin_create_post_settings', self::get('settings'));
         $weight = filter('admin_create_post_weight', self::get('weight'));
         $menutitle = filter('admin_create_post_menutitle', self::get('menutitle'));
         $parent_id = filter('admin_create_post_parent_id', self::get('parent_id'));
         $slug = filter('admin_create_post_slug', self::get('slug'));
         if (empty($menutitle) || empty($slug)) {
             $message = Message::error(__('blank-error'));
             plugin('admin_create_post_blank_error');
         } else {
             plugin('admin_create_post_post_proccessing');
             $values = array('title' => $title, 'content' => $content, 'settings' => unserialize($settings), 'weight' => $weight, 'menutitle' => $menutitle, 'parent_id' => $parent_id, 'slug' => $slug);
             $values = filter('admin_create_post_posted_values', $values);
             $values['settings'] = serialize($values['settings']);
             $res = Content::createNode($_GET['type'], $values);
             if ($res) {
                 $message = Message::success(sprintf(__('page-creation-successful') . ' (<a href="%s">%s</a>)', Admin::link('content'), __('view-all-pages')));
             } else {
                 $message = Message::error(__('page-creation-failed'));
             }
         }
         //Hooks::bind('post_edit_page', 'EditPage::handlePost');
     }
     $r = $message;
     $themeList = array_subkeys(Themes::getThemeList(), 'name');
     $themeList['-1'] = 'Default Theme';
     ksort($themeList);
     $form = new Form('self', 'post', 'create_page');
     $form->addHidden('settings', 'a:0:{}');
     $form->startFieldset(__('page-info'), array('id' => 'page_info_f'));
     $form->addInput(__('page-title'), 'text', 'title', self::get('title'), array('class' => 'large'));
     $form->addHidden('content_type', self::get('type'));
     $form->addSelectList(__('theme-override'), 'theme', $themeList);
     $form->addSelectList(__('parent'), 'parent_id', self::buildParentOptions(), true, $_POST['parent_id'] ? $_POST['parent_id'] : '0');
     $form->endFieldset();
     plugin('admin_create_custom_fields', array(&$form));
     $form->startFieldset(__('menu-settings'), array('id' => 'menu_settings_f'));
     $form->addInput(__('menu-title'), 'text', 'menutitle', self::get('menutitle'));
     $form->addInput(__('slug'), 'text', 'slug', self::get('slug'));
     $form->addInput(__('weight'), 'text', 'weight', $_POST['weight'] ? $_POST['weight'] : '0');
     $form->endFieldset();
     plugin('admin_create_custom_fields2', array(&$form));
     $form->startFieldset(__('content'));
     $content = self::get('content_area');
     $form->addEditor('<p></p>', 'content_area', empty($content) ? "<p></p>" : $content);
     $form->endFieldset();
     plugin('admin_create_custom_fields3', array(&$form));
     $form->addSubmit('', 'save', __('save'));
     i18n::restore();
     return array(__('admin', 'add-page'), $r . $form->endAndGetHTML());
 }
Example #13
0
 public static function create_display()
 {
     i18n::set('external-link-nodetype');
     $message = "";
     if ($_POST['cc_form'] == 'create_external_link') {
         $id = $_GET['id'];
         $weight = self::get('weight');
         $menutitle = self::get('menutitle');
         $parent_id = self::get('parent_id');
         $slug = self::get('slug');
         if (empty($url) || empty($text)) {
             $message = Message::error(__('blank-error'));
         } else {
             if (empty($weight)) {
                 $weight = '0';
             }
             $values = array('title' => '', 'content' => '', 'settings' => 'a:0:{}', 'weight' => $weight, 'menutitle' => $menutitle, 'parent_id' => $parent_id, 'slug' => $slug);
             $res = Content::createNode($_GET['type'], $values);
             if ($res) {
                 $message = Message::success(sprintf(__('link-creation-successful') . ' (<a href="%s">%s</a>)', Admin::link('content'), __('admin', 'view-all-pages')));
             } else {
                 $message = Message::error(__('link-creation-failed'));
             }
         }
     }
     $r = $message;
     $form = new Form('self', 'post', 'create_external_link');
     $form->addInput(__('url'), 'text', 'slug', self::get('slug'));
     $form->addInput(__('display-text'), 'text', 'menutitle', self::get('menutitle'));
     $form->addSelectList(__('parent'), 'parent_id', PageNode::buildParentOptions(), true, $_POST['parent_id'] ? $_POST['parent_id'] : '0');
     $form->addInput(__('weight'), 'text', 'weight', self::get('weight'));
     $form->addSubmit('', 'create', 'Create');
     i18n::restore();
     return array(__('external-link-nodetype', 'create-external-link'), $form->endAndGetHTML());
 }
Example #14
0
    public function getSearchBox()
    {
        static $id_count = 0;
        if ($id_count) {
            $id = 'search_list_' . $id_count;
        } else {
            $id = 'search_list';
            $id_count++;
        }
        $values = $this->getLinkValues();
        unset($values['pager_search']);
        unset($values['go']);
        $form = new \Form($id);
        $form->useGetMethod();
        $form->addClass('form-inline');
        $form->setAction('index.php');
        //$form->appendCSS('bootstrap');
        foreach ($values as $k => $v) {
            $form->addHidden($k, $v);
        }
        $input_array[] = '<div style="width: 300px">';
        $form->setOpen(false);
        $input_array[] = $form->printTag();
        $input_array[] = implode("\n", $form->getHiddens());
        $si = $form->addTextField('pager_c_search', $this->search);
        $si->addClass('pager_c_search');
        $si->addClass('form-control');
        $si->setPlaceholder(_('Search'));
        $input_array[] = '<div class="input-group">';
        $input_array[] = (string) $si;
        $input_array[] = '<span class="input-group-btn">';
        if ($this->search_button) {
            $sub = $form->addSubmit('submit', 'Go')->addClass('btn btn-success');
            $input_array[] = (string) $sub;
        }
        $input_array[] = <<<EOF
<input type="submit" onclick="\$(this).parents('form').find('input.pager_c_search').val('');" class="btn btn-info" value="Clear" />
EOF;
        $input_array[] = '</span>';
        $input_array[] = '</div>';
        $input_array[] = '</form></div>';
        return implode("\n", $input_array);
    }
Example #15
0
<?php

echo $this->translate("I see %d little indians!", 10);
echo _("Escaping some \"fancy\" text");
// PHPFilter Nette Framework integration
$form = new Form();
$form->addText('name', 'Your name:');
$form->addSubmit('ok', 'Send')->onClick[] = 'OkClicked';
// nebo 'OkClickHandler'
$form->addSubmit('cancel', 'Cancel');
Example #16
0
?>
</title>

		<?php 
load_library(array('bootstrap-css', 'jquery'));
queue_css(TH_PUB_ADMIN . 'design/styles.css');
load_css();
load_js();
?>
	</head>
	<body class="login">
		<div id="login-wrapper">
			<h2><?php 
_e('login_cc');
?>
</h2>
			<?php 
$form = new Form('self', 'post', 'login');
$form->startFieldset('');
$form->addInput(__("Username"), 'text', 'cc_login_uname');
$form->addInput(__("Password"), 'password', 'cc_login_passwd');
$form->addInput(__("remember-me"), 'checkbox', 'cc_login_remember', 'yes');
$form->addSubmit('', 'cc_login_login', __('login_cc'));
$form->endFieldset();
echo $form->endAndGetHTML();
i18n::restore();
?>
		</div>
	</body>
</html>
Example #17
0
 public static function display()
 {
     $r = "";
     if ($_POST['cc_form'] == 'settings') {
         $name_lookup = array();
         Database::beginTransaction();
         foreach ($_POST as $key => $value) {
             if ($key == 'cc_form') {
                 continue;
             }
             if (substr($key, 0, 12) == 'cc_settings_') {
                 $name_lookup[substr($key, 12)] = explode('|', $value);
                 continue;
             }
             $setting_name = $key;
             //var_dump(array_key_exists($key, $name_lookup),$name_lookup);
             if (!array_key_exists($setting_name, $name_lookup)) {
                 continue;
             }
             if ($key == 'clean-urls') {
                 $value = (bool) $value;
             }
             Database::update('settings', array('data'), array(serialize($value)), array('package = ? AND name = ?', $name_lookup[$setting_name][1], $name_lookup[$setting_name][0]));
         }
         $r .= Message::success(__('admin', 'settings-saved'));
         Database::endTransaction();
     }
     $settings = Database::select('settings', '*', array('package = ? OR package = ? OR package = ? OR package = ?', 'core', 'admin', 'site', 'gui'), array('package', 'ASC', 'name', 'ASC'));
     $settings = $settings->fetchAll(PDO::FETCH_ASSOC);
     $rows = array();
     foreach ($settings as $row) {
         if (!array_key_exists($row['package'], $rows)) {
             $rows[$row['package']] = array();
         }
         $rows[$row['package']][] = $row;
     }
     ksort($rows);
     $form = new Form('self', 'POST', 'settings');
     foreach ($rows as $cat => $catRows) {
         $form->startFieldset(__('settings', $cat));
         foreach ($catRows as $row) {
             $data = unserialize($row['data']);
             $form->addHidden('cc_settings_' . UTF8::slugify($row['name']), $row['name'] . '|' . $row['package']);
             if ($row['name'] == 'clean urls') {
                 $form->addSelectList(__('settings', $row['name']), UTF8::slugify($row['name']), array(1 => __('admin', 'yes'), 0 => __('admin', 'no')), true, $data);
             } else {
                 if ($row['name'] == 'theme') {
                     $themes = Themes::getThemeList();
                     $options = array();
                     foreach ($themes as $slug => $ini) {
                         $options[$slug] = $ini['name'];
                     }
                     $form->addSelectList(__('settings', $row['name']), UTF8::slugify($row['name']), $options, true, $data);
                 } else {
                     if ($row['name'] == 'locale') {
                         $locales = i18n::getLocales();
                         $form->addSelectList(__('settings', $row['name']), UTF8::slugify($row['name']), $locales, false, $data);
                     } else {
                         if ($row['name'] == 'homepage id') {
                             $form->addSelectList(__('settings', $row['name']), UTF8::slugify($row['name']), Content::optionListArrayFromArray(Content::parseNavigation()), true, $data);
                         } else {
                             if ($row['name'] == 'site name') {
                                 $form->addInput(__('settings', $row['name']), 'text', UTF8::slugify($row['name']), $data);
                             } else {
                                 if ($row['name'] == 'editor') {
                                     $editors = Editors::getNamesOfRegistered();
                                     $form->addSelectList(__('settings', $row['name']), UTF8::slugify($row['name']), $editors, false, $data);
                                 } else {
                                     if ($row['name'] == 'homepage') {
                                         $form->addSelectList(__('settings', $row['name']), UTF8::slugify($row['name']), Admin::getAdminPageOptions(), true, $data);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $form->endFieldset();
     }
     $form->startFieldset('');
     $form->addSubmit('', 'save-settings', __('admin', 'save'));
     $form->endFieldset();
     return array(__('admin', 'settings'), $r . $form->endAndGetHTML());
 }
Example #18
0
 public static function display()
 {
     $id = $_GET['id'];
     if (!is_numeric($id)) {
         i18n::restore();
         cc_redirect(Admin::link('users'));
         return 'redirected.';
     }
     $messages = "";
     if ($_POST['cc_form'] === 'edit-user') {
         $username = $_POST['name'];
         $password = $_POST['password'];
         $cpassword = $_POST['confirm-password'];
         $group = $_POST['group'];
         if ($password != $cpassword) {
             $messages .= Message::error(__('admin', 'passwords-dont-match'));
         } else {
             $result = Database::select('users', '*', array('users_id = ?', $id));
             $row = $result->fetch(PDO::FETCH_ASSOC);
             $result = Database::select('users', '*', array('name = ?', $username));
             if (!empty($result)) {
                 $userRow = $result->fetch(PDO::FETCH_ASSOC);
             } else {
                 $result = false;
             }
             if ($result && $userRow['name'] == $username && $id != $userRow['id']) {
                 $messages .= Message::error(__('admin', 'username-in-use'));
             } else {
                 if (!empty($password) && !empty($cpassword) && $password == $cpassword) {
                     $hash = hash('whirlpool', $password);
                 } else {
                     $hash = $row['value'];
                 }
                 $data = unserialize($row['data']);
                 $result = Database::update('users', array('name' => filter('admin_edit_user_username', $username), 'value' => $hash, 'type' => 'user', 'group' => filter('admin_edit_group', $group), 'data' => serialize(filter('admin_edit_user_data', $data))), null, array('id = ?', $id));
                 if ($result === 1) {
                     $messages .= Message::success(__('admin', 'user-updated'));
                 }
             }
         }
     }
     $result = Database::select('users', '*', array('users_id = ?', $id));
     if (empty($result)) {
         i18n::restore();
         cc_redirect(Admin::link('users'));
     }
     self::$row = $result->fetch(PDO::FETCH_ASSOC);
     $form = new Form('self', 'post', 'edit-user');
     $groups = Users::allGroups();
     foreach ($groups as $key => $value) {
         $groups[$value->getId()] = $value->getName();
     }
     $form->startFieldset(__("admin", 'user-information'));
     $form->addInput(__('admin', 'username'), 'text', 'name', self::get('name'));
     $form->addInput(__('admin', 'password'), 'password', 'password');
     $form->addInput(__('admin', 'confirm-password'), 'password', 'confirm-password');
     $form->addSelectList(__('admin', 'group'), 'group', $groups, true, self::get('group'));
     plugin('admin_edit_user_custom_fields', array(&$form));
     $form->addSubmit('', 'edit-user', __('admin', 'edit-user'));
     $form->endFieldset();
     plugin('admin_edit_user_custom_fieldset', array(&$form));
     $form = $form->endAndGetHTML();
     return array(sprintf("%s: %s", __('admin', 'edit-user'), self::get('name')), $messages . $form);
 }
Example #19
0
$form->addText('name', 'Your name:', 35);
// item name, label, size, maxlength
$form->addTextArea('note', 'Comment:', 30, 5);
$form->addRadioList('gender', 'Your gender:', $sex);
$form->addCheckbox('send', 'Ship to address');
$form->addSelect('country', 'Country:', $countries)->skipFirst();
$form->addMultiSelect('countrym', 'Country:', $countries);
$form->addPassword('password', 'Choose password:'******'avatar', 'Picture:');
$form->addHidden('userid');
$sub = $form->addContainer('firstperson');
$sub->addText('age', 'Your age:', 5);
$sub = $form->addContainer('secondperson');
$sub->addText('age', 'Your age:', 5);
$sub->addFile('avatar', 'Picture:');
$form->addSubmit('submit1', 'Send');
$_SERVER['REQUEST_METHOD'] = 'POST';
/* valid data
$_POST = array(
	'name' => 'string',
	'note' => 'textbox',
	'gender' => 'm',
	'send' => 'on',
	'country' => '1',
	'countrym' => array(
		0 => '0',
		1 => '1',
		2 => '2',
	),
	'password' => 'string',
	'firstperson' => array(
Example #20
0
 */
require_once LIBS_DIR . '/Nette/loader.php';
require_once LIBS_DIR . '/Extras/DatePicker.php';
Debug::enable();
// budoucí metoda Form::addDatePicker()
function Form_addDatePicker(Form $_this, $name, $label, $cols = NULL, $maxLength = NULL)
{
    return $_this[$name] = new DatePicker($label, $cols, $maxLength);
}
Form::extensionMethod('Form::addDatePicker', 'Form_addDatePicker');
// v PHP 5.2
//Form::extensionMethod('addDatePicker', 'Form_addDatePicker'); // v PHP 5.3
// Step 1: Define form with validation rules
$form = new Form();
$form->addDatePicker('datum', 'Kdy to bude?', 10)->addRule(Form::FILLED, 'Zadejte prosím datum.');
$form->addSubmit('submit_date', 'Odešli');
// 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;
        }
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">