Example #1
0
 * mobiCMS Content Management System (http://mobicms.net)
 *
 * For copyright and license information, please see the LICENSE.md
 * Installing the system or redistributions of files must retain the above copyright notice.
 *
 * @link        http://mobicms.net mobiCMS Project
 * @copyright   Copyright (C) mobiCMS Community
 * @license     LICENSE.md (see attached file)
 */
defined('MOBICMS') or die('Error: restricted access');
$id = App::request()->getFiltered('id', 0, FILTER_VALIDATE_INT);
$form = new Mobicms\Form\Form(['action' => App::request()->getUri() . ($id ? '?id=' . $id : '')]);
if ($id) {
    $stmt = App::db()->query("SELECT * FROM `news` WHERE `id` = " . $id);
    if ($stmt->rowCount()) {
        $result = $stmt->fetch();
        $form->title(_dg('Edit Article '))->element('text', 'title', ['label' => _g('Title'), 'value' => $result['title'], 'required' => true])->element('textarea', 'text', ['label' => _g('Text'), 'value' => $result['text'], 'editor' => true, 'required' => true])->element('checkbox', 'comments', ['label_inline' => _dg('Enable comments'), 'checked' => $result['comm_enable']])->divider()->element('submit', 'submit', ['value' => _g('Save'), 'class' => 'btn btn-primary'])->html('<a class="btn btn-link" href="../">' . _g('Back') . '</a>');
        $form->validate('title', 'lenght', ['min' => 3, 'max' => 100])->validate('text', 'lenght', ['min' => 3]);
    } else {
        $form->html('<div class="alert alert-danger">' . _g('Wrong data') . '</div>')->html('<a class="btn btn-link" href="../">' . _g('Back') . '</a>');
    }
} else {
    $form->html('<div class="alert alert-danger">' . _g('Wrong data') . '</div>')->html('<a class="btn btn-link" href="../">' . _g('Back') . '</a>');
}
if ($form->process() === true) {
    $stmt = App::db()->prepare("\n        UPDATE `news` SET\n        `title`       = ?,\n        `text`        = ?,\n        `comm_enable` = ?\n        WHERE `id`    = ?\n    ");
    $stmt->execute([App::filter($form->output['title'])->specialchars(), App::purify($form->output['text']), $form->output['comments'], $id]);
    $stmt = null;
}
App::view()->form = $form->display();
App::view()->setTemplate('edit_form.php');
Example #2
0
<?php

/*
 * mobiCMS Content Management System (http://mobicms.net)
 *
 * For copyright and license information, please see the LICENSE.md
 * Installing the system or redistributions of files must retain the above copyright notice.
 *
 * @link        http://mobicms.net mobiCMS Project
 * @copyright   Copyright (C) mobiCMS Community
 * @license     LICENSE.md (see attached file)
 */
defined('MOBICMS') or die('Error: restricted access');
$form = new Mobicms\Form\Form(['action' => App::request()->getUri()]);
$form->title(_dg('Add Article'))->element('text', 'title', ['label' => _g('Title'), 'required' => true])->element('textarea', 'text', ['label' => _g('Text'), 'editor' => true, 'required' => true])->element('checkbox', 'comments', ['label_inline' => _dg('Enable comments'), 'checked' => true])->divider()->element('submit', 'submit', ['value' => _g('Save'), 'class' => 'btn btn-primary'])->html('<a class="btn btn-link" href="../">' . _g('Back') . '</a>');
$form->validate('title', 'lenght', ['min' => 3, 'max' => 100])->validate('text', 'lenght', ['min' => 3]);
if ($form->process() === true) {
    $stmt = App::db()->prepare("\n        INSERT INTO `news` SET\n        `time`        = ?,\n        `author`      = ?,\n        `author_id`   = ?,\n        `title`       = ?,\n        `text`        = ?,\n        `comm_enable` = ?\n    ");
    $user = App::user()->get();
    $stmt->execute([time(), $user->nickname, $user->id, App::filter($form->output['title'])->specialchars(), App::purify($form->output['text']), $form->output['comments']]);
    $user->lastpost = time();
    $user->save();
    App::redirect('../');
}
App::view()->form = $form->display();
App::view()->setTemplate('edit_form.php');
Example #3
0
}
$form->element('text', 'imname', ['label' => _m('Your Name'), 'value' => $profile->imname, 'description' => _m('Max. 50 characters'), 'filter' => FILTER_SANITIZE_STRING]);
if (Config::$usrChangeSex || App::profile()->rights >= 7) {
    $form->element('radio', 'sex', ['label' => _s('Gender'), 'checked' => $profile->sex, 'items' => ['m' => _s('Male'), 'w' => _s('Female')]]);
}
$form->element('text', 'day', ['label' => _m('Birthday'), 'value' => date("d", strtotime($profile->birth)), 'class' => 'mini', 'filter' => FILTER_SANITIZE_NUMBER_INT])->element('text', 'month', ['value' => date("m", strtotime($profile->birth)), 'class' => 'mini', 'filter' => FILTER_SANITIZE_NUMBER_INT])->element('text', 'year', ['value' => date("Y", strtotime($profile->birth)), 'class' => 'small', 'description' => _m('Day, month, year'), 'filter' => FILTER_SANITIZE_NUMBER_INT])->element('text', 'live', ['label' => _m('Accommodation'), 'value' => $profile->live, 'description' => _m('Specify the country of residence, your city.<br/>Max. 100 characters.'), 'filter' => FILTER_SANITIZE_STRING])->element('textarea', 'about', ['label' => _m('About yourself'), 'value' => $profile->about, 'editor' => true, 'description' => _m('Max. 5000 characters')])->element('text', 'tel', ['label' => _m('Phone Number'), 'value' => $profile->tel, 'description' => _m('Max. 100 characters'), 'filter' => FILTER_SANITIZE_STRING])->element('text', 'siteurl', ['label' => _m('Site'), 'value' => $profile->siteurl, 'description' => _m('You can enter multiple URL, separated by spaces.<br/>Max. 100 characters'), 'filter' => FILTER_SANITIZE_STRING]);
if (!empty($profile->email)) {
    $form->element('text', 'email', ['label' => 'E-mail', 'value' => $profile->email, 'readonly' => true, 'filter' => FILTER_SANITIZE_EMAIL])->element('checkbox', 'mailvis', ['label_inline' => _m('Show in the Profile'), 'checked' => $profile->mailvis, 'description' => _m('Correctly specify your email address, that it will be sent your password.<br/>Max. 50 characters') . '<br/><a href="../email/">' . _m('Change E-mail') . '</a>']);
}
$form->element('text', 'skype', ['label' => 'Skype', 'value' => $profile->skype, 'description' => _m('Max. 50 characters'), 'filter' => FILTER_SANITIZE_STRING])->element('text', 'icq', ['label' => 'ICQ', 'value' => $profile->icq, 'description' => _m('Enter your UIN number'), 'filter' => FILTER_SANITIZE_NUMBER_INT])->divider()->element('submit', 'submit', ['value' => _s('Save'), 'class' => 'btn btn-primary'])->html('<a class="btn btn-link" href="../">' . _s('Back') . '</a>')->validate('status', 'lenght', ['min' => 3, 'max' => 50, 'empty' => true])->validate('imname', 'lenght', ['max' => 50])->validate('live', 'lenght', ['max' => 100])->validate('about', 'lenght', ['max' => 5000])->validate('tel', 'lenght', ['max' => 100])->validate('siteurl', 'lenght', ['max' => 100])->validate('skype', 'lenght', ['max' => 50])->validate('icq', 'numeric', ['min' => 10000, 'empty' => true]);
if ($form->process() === true) {
    $profile->status = $form->output['status'];
    $profile->sex = $form->output['sex'];
    $profile->imname = $form->output['imname'];
    $profile->live = $form->output['live'];
    $profile->about = App::purify($form->output['about']);
    $profile->tel = $form->output['tel'];
    $profile->siteurl = $form->output['siteurl'];
    $profile->mailvis = isset($form->output['mailvis']) ? 1 : 0;
    $profile->icq = $form->output['icq'];
    $profile->skype = $form->output['skype'];
    //TODO: Добавить валидацию даты
    if (empty($form->output['day']) && empty($form->output['month']) && empty($form->output['year'])) {
        $profile->birth = '00-00-0000';
    } else {
        $profile->birth = intval($form->output['year']) . '-' . intval($form->output['month']) . '-' . intval($form->output['day']);
    }
    $profile->save();
}
App::view()->form = $form->display();
App::view()->setTemplate('edit_form.php');