Пример #1
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('Articles');
     $article = Model_Article::find($id);
     $val = Model_Article::validate('edit');
     if ($val->run()) {
         $article->nombre = Input::post('nombre');
         $article->periodista_id = Input::post('periodista_id');
         $article->seccion_id = Input::post('seccion_id');
         $article->dimension_id = Input::post('dimension_id');
         $article->fecha = Input::post('fecha');
         if ($article->save()) {
             Session::set_flash('success', 'Updated article #' . $id);
             Response::redirect('articles');
         } else {
             Session::set_flash('error', 'Could not update article #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $article->nombre = $val->validated('nombre');
             $article->periodista_id = $val->validated('periodista_id');
             $article->seccion_id = $val->validated('seccion_id');
             $article->dimension_id = $val->validated('dimension_id');
             $article->fecha = $val->validated('fecha');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('article', $article, false);
     }
     $this->template->title = "Articles";
     $this->template->content = View::forge('articles/edit');
 }
Пример #2
0
 /**
  * Редактирование статьи
  * 
  * @param int $id id статьи
  * @param string $language язык
  */
 public function action_edit($id = null)
 {
     is_null($id) and \Response::redirect('admin/articles');
     $article = \Model_Article::find($id, array('related' => 'category'));
     if (!empty($article)) {
         $val = \Model_Article::validate('edit');
         if ($val->run()) {
             $article->title = \Input::post('title');
             $article->category_id = \Input::post('category_id');
             $article->on_main_page = \Input::post('on_main_page', 0);
             $article->preview = \Input::post('preview');
             $article->full_text = \Input::post('full_text');
             if ($article->save()) {
                 \Session::set_flash('success', e('Статья успешно отредактирована'));
                 \Response::redirect('admin/articles');
             } else {
                 \Session::set_flash('error', e('Невозможно отредактировать статью' . $id));
             }
         } else {
             if (\Input::method() == 'POST') {
                 $article->title = $val->validated('title');
                 $article->category_id = $val->validated('category_id');
                 $article->on_main_page = $val->validated('on_main_page');
                 $article->preview = $val->validated('preview');
                 $article->full_text = $val->validated('full_text');
                 \Session::set_flash('error', $val->error());
             }
             $this->template->set_global('article', $article, false);
         }
         // Категории статей
         $data['categories'] = \Model_Category::get_categories_for_select();
         $this->template->title = "Статьи";
         $this->template->content = \View::forge('articles/edit', $data, false);
     } else {
         throw new \HttpNotFoundException();
     }
 }
Пример #3
0
 private function saveArticle(Model_Article $article, View_Html $view)
 {
     if (isset($_REQUEST['save'])) {
         foreach (array("published", "archived") as $name) {
             $_POST[$name] = Filter_Date::fromString($_POST[$name]);
         }
         if (!isset($_POST['flags'])) {
             $_POST['flags'] = array();
         }
         $article->setData($_POST);
         if (!($errors = $article->validate())) {
             $article->save();
             $article->getRights()->setRights($_POST['rights'], $_POST['owner'], $_POST['group'])->save();
             $article->dropTags();
             $tags = isset($_POST['tag']) ? $_POST['tag'] : (isset($_POST['tags']) ? explode(", ", $_POST['tags']) : null);
             Model_Tag::setAutoCreate();
             if ($tags) {
                 $article->addTags($tags);
             }
             if ($_FILES && $_FILES["attach"]) {
                 $store = $this->getStorage();
                 foreach ($_FILES["attach"]["name"] as $index => $name) {
                     $attachment = new Model_Attachment($store);
                     $file = array('name' => $name, 'tmp_name' => $_FILES['attach']['tmp_name'][$index], 'error' => $_FILES['attach']['error'][$index], 'size' => $_FILES['attach']['size'][$index], 'type' => $_FILES['attach']['type'][$index]);
                     if ($attachment->uploadFile($file)) {
                         $attachment->attachTo($article);
                         $attachment->save();
                     }
                 }
             }
             $view->redir('Admin_Topic', 'default', array('id' => $article->topic));
             return true;
         }
         $view->errors = $errors;
     }
     return false;
 }
Пример #4
0
 /**
  * Edit article
  *
  * @param int $id article-ID
  *
  * @author Nguyen Van Hiep
  * @access public
  *
  * @version 1.0
  * @since 1.0
  */
 public function action_edit($id = null, $current_cat_view = '', $current_lang_view = '')
 {
     $a = Model_Article::find($id);
     if (!$a) {
         Session::set_flash('error', __('message.art_not_exists'));
         Response::redirect('admin/article');
     }
     $view = View::forge('admin/article/edit');
     $view->a = $a;
     $view->err = array();
     $view->sel_cats = Model_ArtCat::get_cat_from_art($id);
     $view->langs = $this->langs;
     $view->cats = Model_Categories::get_cat_list();
     if ($current_cat_view != 'cat' and $current_lang_view != 'lang') {
         $view->current_cat_view = "cat={$current_cat_view}&lang={$current_lang_view}";
     } elseif ($current_cat_view != 'cat') {
         $view->current_cat_view = "cat={$current_cat_view}&lang=";
     } elseif ($current_lang_view != 'lang') {
         $view->current_cat_view = "cat=&lang={$current_lang_view}";
     } else {
         $view->current_cat_view = "cat=&lang=";
     }
     if (Input::method() == 'POST') {
         if (count(Input::file()) == 0) {
             Session::set_flash('error', __('message.upload_files_error'));
             Response::redirect('admin/articLe/edit');
         }
         $a->title = Input::post('title');
         $a->slug = Input::post('slug');
         $a->title_search = str_replace('-', ' ', Input::post('slug'));
         $a->desc = Input::post('desc');
         $a->content = Input::post('content');
         $content_search = strip_tags(Input::post('content'));
         $a->content_search = preg_replace('/[\\s]+/mu', ' ', $content_search);
         // remove all tab, new line
         $content_no_mark = Input::vn_str_filter(strip_tags(Input::post('content')));
         $a->content_search_no_mark = preg_replace('/[\\s]+/mu', ' ', $content_no_mark);
         $a->lang = Input::post('lang');
         $a->updated_at = date('Y-m-d h:i:s', time());
         $val = Model_Article::validate('edit', $a);
         Upload::process($this->config);
         $upload_errs = Upload::get_errors();
         $up_err = reset($upload_errs);
         $input_file = Input::file();
         $upthumb = $input_file['thumbnail']['name'];
         $is_upthumb = true;
         // Check if upload new thumbnail or not
         if ($up_err['field'] == 'thumbnail' and strlen($upthumb) == 0) {
             $upload_errs = array();
             $is_upthumb = false;
         }
         if ($val->run() and count($upload_errs) == 0) {
             //save account
             if ($a->save()) {
                 // Save Article-Category
                 Model_ArtCat::save_art_cat($a->id, Input::post('cat') ? Input::post('cat') : array(), true);
                 //Save images
                 $this->save_thumb($a->id, $is_upthumb);
                 //redirect to index page
                 Session::set_flash('success', __('message.art_edited'));
                 Response::redirect("admin/article?{$view->current_cat_view}");
             } else {
                 //fail in transaction
                 Session::set_flash('error', __('message.registration_failed'));
             }
         } else {
             $view->err = $val->error_message();
             $err = $this->upload_errors($upload_errs);
             $view->err = array_merge($view->err, $err);
         }
     }
     $this->template->title = __('prod.edit');
     $this->template->content = $view;
 }
Пример #5
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('article');
     if (!($article = Model_Article::find($id))) {
         Session::set_flash('error', 'Could not find article #' . $id);
         Response::redirect('article');
     }
     $val = Model_Article::validate('edit');
     if ($val->run()) {
         $article->category_id = Input::post('category_id');
         $article->name = Input::post('name');
         $article->url_title = str_replace(" ", "-", strtolower(Input::post('name')));
         $article->description = Input::post('description');
         $article->keywords = Input::post('keywords');
         $article->image = Input::post('image');
         $article->editor_id = $this->current_user->id;
         if ($article->save()) {
             Session::set_flash('success', 'Updated article #' . $id);
             Response::redirect('admin/article');
         } else {
             Session::set_flash('error', 'Could not update article #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $article->category_id = $val->validated('category_id');
             $article->name = $val->validated('name');
             $article->description = $val->validated('description');
             $article->keywords = $val->validated('keywords');
             $article->image = $val->validated('image');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('article', $article, false);
     }
     $this->template->title = "Articles";
     $data['categories'] = Model_Category::getSelectList();
     $this->template->content = View::forge('admin/article/create', $data);
 }