Файл: adultscript-2.0.3-pro/files/admin/modules/kb/components/add.php
Строк: 50
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_kb_add
{
private $db;
public function __construct()
{
$this->db = VF::factory('database');
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
$kb = array(
'cat_id' => '', 'kb_title' => '', 'kb_content' => '', 'status' => 1
);
if (isset($_POST['submit_kb_add'])) {
$title = trim($_POST['kb_title']);
$category = (int) trim($_POST['cat_id']);
$content = trim($_POST['kb_content']);
$status = (int) trim($_POST['status']);
if ($title == '') {
$errors[] = 'Article title field cannot be left blank!';
} else {
$kb['kb_title'] = $title;
}
if ($category === 0) {
$errors[] = 'Please select a category for your article!';
} else {
$kb['cat_id'] = $category;
}
if ($content == '') {
$errors[] = 'Please enter the body of the article!';
} else {
$kb['kb_content'] = $content;
}
$kb['status'] = $status;
if (!$errors) {
$this->db->query("INSERT INTO #__kb
SET cat_id = ".$category.",
user_id = ".(int) $_SESSION['user_id'].",
kb_title = '".$this->db->escape($title)."',
kb_content = '".$this->db->escape($content)."',
add_date = '".date('Y-m-d h:i:s')."',
status = '".$status."'");
if ($this->db->affected_rows()) {
$this->db->query("UPDATE #__kb_categories
SET total_articles = total_articles+1
WHERE cat_id = ".$category."
LIMIT 1");
$messages[] = 'Article added!';
} else {
$errors[] = 'Failed to create article database entry! Aborting...';
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'kb';
$tpl->submenu = 'kb_add';
$tpl->meta_title = 'Admin::Knowledge Base::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->warnings = $warnings;
$tpl->kb = $kb;
$tpl->categories = $this->get_kb_categories();
$tpl->load(array('header', 'kb_add', 'footer'));
$tpl->display();
}
private function get_kb_categories()
{
return $this->db->get_rows("SELECT cat_id, name FROM #__kb_categories ORDER BY pos ASC");
}
}