<?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');
* 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');