Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/kb/components/edit.php
Строк: 52
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_kb_edit
{
    private 
$db;
    public function 
__construct()
    {
        
$this->db VF::factory('database');
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        
$warnings    = array('Please keep in mind this tool saves the exact html you create here! There is no escaping!!!');
        
$kb            = array();
        
$id            = (isset($_GET['id'])) ? (int) trim($_GET['id']) : 0;
        
        
$this->db->query("SELECT cat_id FROM #__kb WHERE kb_id = ".$id." LIMIT 1");
        if (
$this->db->affected_rows()) {
            
$o_cat_id = (int) $this->db->fetch_field('cat_id');
            if (isset(
$_POST['submit_kb_edit'])) {
                
$title        trim($_POST['kb_title']);
                
$category    = (int) trim($_POST['cat_id']);
                
$content    str_replace(array("rn""r"), "n"trim($_POST['kb_content']));
                
$status        = (int) trim($_POST['status']);
            
                if (
$title == '') {
                    
$errors[]        = 'Article title field cannot be left blank!';
                }
            
                if (
$category === 0) {
                    
$errors[]        = 'Please select a category for your article!';
                }
            
                if (
$content == '') {
                    
$errors[]        = 'Please enter the body of the article!';
                }
            
                
$kb['status'] = $status;
            
                if (!
$errors) {
                    
$this->db->query("UPDATE #__kb
                                      SET cat_id = "
.$category.",
                                          kb_title = '"
.$this->db->escape($title)."',
                                          kb_content = '"
.$this->db->escape($content)."',
                                          edit_id = "
.(int) $_SESSION['user_id'].",
                                          edit_date = '"
.date('Y-m-d h:i:s')."',
                                          status = '"
.$status."'
                                      WHERE kb_id = "
.$id."
                                      LIMIT 1"
);
                    if (
$category !== $o_cat_id) {
                        
$this->db->query("UPDATE #__kb_categories
                                          SET total_articles = total_articles+1
                                          WHERE cat_id = "
.$category."
                                          LIMIT 1"
);
                        
$this->db->query("UPDATE #__kb_categories
                                          SET total_articles = total_articles-1
                                          WHERE cat_id = "
.$o_cat_id."
                                          LIMIT 1"
);
                    }
                    
                    
$messages[] = 'Article updated!';
                }
            }
            
            
$this->db->query("SELECT *
                              FROM #__kb
                              WHERE kb_id = "
.$id."
                              LIMIT 1"
);
            
$kb $this->db->fetch_assoc();
        }
        
        
$tpl VF::factory('template');
        
$tpl->menu            'kb';
        
$tpl->submenu        'kb_manage';
        
$tpl->meta_title    'Admin::Knowledge Base::Manage';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->warnings        $warnings;
        
$tpl->kb            $kb;
        
$tpl->categories    $this->get_kb_categories();
        
$tpl->load(array('header''kb_edit''footer'));
        
$tpl->display();
    }
    
    private function 
get_kb_categories()
    {
        return 
$this->db->get_rows("SELECT cat_id, name FROM #__kb_categories ORDER BY pos ASC");
    }
}
Онлайн: 2
Реклама