Admin_articles::edit PHP Метод

edit() публичный Метод

add article
public edit ( $id = '' )
    public function edit($id = '')
    {
        if ($id == '' or !is_numeric($id)) {
            redirect('admin/kb/articles');
        }
        $id = (int) $id;
        $data['nav'] = 'articles';
        $this->template->title(lang('lang_edit_article'));
        // Get the categories
        $this->load->library('categories/categories_library');
        $this->load->model('categories/categories_model');
        $data['tree'] = $this->categories_model->walk_categories(0, 0, 'checkbox', 0, '', TRUE);
        $data['row'] = $this->articles_model->get_article($id);
        $data['attach'] = $this->articles_model->get_attachments($id);
        $data['cats'] = $this->articles_model->get_category_relationship($id);
        $data['tree'] = $this->categories_model->walk_categories(0, 0, 'checkbox', 0, $data['cats'], TRUE);
        if ($data['row']['article_author'] > 0) {
            $user = $this->users_model->get_user($data['row']['article_author']);
            $data['username'] = $user['user_username'];
        }
        $data['action'] = 'edit';
        $this->load->helper(array('form', 'url', 'html'));
        $this->load->library('form_validation');
        $this->form_validation->set_rules('article_title', 'lang:lang_title', 'required');
        $this->form_validation->set_rules('article_uri', 'lang:lang_uri', 'alpha_dash');
        $this->form_validation->set_rules('article_keywords', 'lang:lang_keywords', 'trim|xss_clean');
        $this->form_validation->set_rules('article_short_desc', 'lang:lang_short_description', 'trim|xss_clean');
        $this->form_validation->set_rules('article_description', 'lang:lang_description', 'trim|xss_clean');
        $this->form_validation->set_rules('article_display', 'lang:lang_display', 'trim');
        $this->form_validation->set_rules('article_order', 'lang:lang_weight', 'numeric');
        $this->events->trigger('articles/validation');
        if ($this->form_validation->run() == FALSE) {
            $this->template->build('admin/articles/form', $data);
        } else {
            $owner = 1;
            if ($user = $this->users_model->get_user($this->input->post('article_author', TRUE))) {
                $owner = $user['user_id'];
            }
            $data = array('article_uri' => $this->input->post('article_uri', TRUE), 'article_author' => $owner, 'article_title' => $this->input->post('article_title', TRUE), 'article_keywords' => $this->input->post('article_keywords', TRUE), 'article_short_desc' => $this->input->post('article_short_desc', TRUE), 'article_description' => $this->input->post('article_description', TRUE), 'article_display' => $this->input->post('article_display', TRUE), 'article_order' => $this->input->post('article_order', TRUE));
            $this->articles_model->edit_article($id, $data);
            $this->session->set_flashdata('msg', lang('lang_settings_saved'));
            // now add cat to product relationship
            if (isset($_POST['cats'])) {
                $this->articles_model->insert_cats($_POST['cats'], $id);
            }
            if ($_FILES['userfile']['name'] != "") {
                $target = ROOTPATH . 'uploads/' . $id;
                $this->_mkdir($target);
                $config['upload_path'] = $target;
                $config['allowed_types'] = $this->config->item('allowed_types');
                $this->load->library('upload', $config);
                if (!$this->upload->do_upload()) {
                    $this->session->set_flashdata('error', $this->upload->display_errors());
                    redirect('admin/kb/articles/edit/' . $id);
                } else {
                    $upload = array('upload_data' => $this->upload->data());
                    $insert = array('article_id' => $id, 'attach_title' => $this->input->post('attach_title', TRUE), 'attach_file' => $upload['upload_data']['file_name'], 'attach_type' => $upload['upload_data']['file_type'], 'attach_size' => $upload['upload_data']['file_size']);
                    $this->db->insert('attachments', $insert);
                    $data['attach'] = $this->articles_model->get_attachments($id);
                }
            }
            if (isset($_POST['save']) && $_POST['save'] != "") {
                redirect('admin/kb/articles/edit/' . $id);
            }
            redirect('admin/kb/articles/');
        }
    }