Esempio n. 1
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('post');
     if (!($post = Model_Post::find($id))) {
         Session::set_flash('error', '投稿が見つかりませんでした。');
         Response::redirect('post');
     }
     $val = Model_Post::validate('edit');
     if ($val->run() && $post->check(Input::post('delete_password'))) {
         $post->name = Input::post('name');
         $post->title = Input::post('title');
         $post->body = Input::post('body');
         if ($post->save()) {
             Session::set_flash('success', '編集が完了しました。');
             Response::redirect('post');
         } else {
             Session::set_flash('error', '編集に失敗しました。');
         }
     } else {
         if (Input::method() == 'POST' && !$val->run()) {
             $post->name = $val->validated('name');
             $post->title = $val->validated('title');
             $post->body = $val->validated('body');
             Session::set_flash('error', $val->error());
         } elseif (Input::method() == 'POST' && !$post->check(Input::post('delete_password'))) {
             Session::set_flash('error', array('パスワードが違います。'));
         }
         $this->template->set_global('post', $post, false);
     }
     $this->template->set_global('title', 'SAMPLE BBS');
     $this->template->content = View::forge('post/edit', array('title' => 'SAMPLE BBS'));
 }
Esempio n. 2
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('post');
     if (!($post = Model_Post::find($id))) {
         Session::set_flash('error', 'Could not find post #' . $id);
         Response::redirect('post');
     }
     $val = Model_Post::validate('edit');
     if ($val->run()) {
         $post->title = Input::post('title');
         $post->body = Input::post('body');
         if ($post->save()) {
             Session::set_flash('success', 'Updated post #' . $id);
             Response::redirect('post');
         } else {
             Session::set_flash('error', 'Could not update post #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $post->title = $val->validated('title');
             $post->body = $val->validated('body');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('post', $post, false);
     }
     $this->template->title = "Posts";
     $this->template->content = View::forge('post/edit');
 }
Esempio n. 3
0
 public function action_edit($id = null)
 {
     $post = Model_Post::find($id);
     $val = Model_Post::validate('edit');
     if ($val->run()) {
         $post->title = Input::post('title');
         //$post->slug = Input::post('slug');
         $post->summary = Input::post('summary');
         $post->body = Input::post('body');
         $post->user_id = Input::post('user_id');
         if ($post->save()) {
             Session::set_flash('success', 'Updated post #' . $id);
             Response::redirect('admin/posts');
         } else {
             Session::set_flash('error', 'Could not update post #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $post->title = $val->validated('title');
             $post->slug = $val->validated('slug');
             $post->summary = $val->validated('summary');
             $post->body = $val->validated('body');
             $post->user_id = $val->validated('user_id');
             Session::set_flash('error', $val->show_errors());
         }
         $this->template->set_global('post', $post, false);
     }
     $this->template->title = "Create Post";
     $view = View::forge('admin/posts/create');
     // Set some data
     $view->set_global('users', Arr::assoc_to_keyval(Model_User::find('all'), 'id', 'username'));
     $this->template->content = $view;
 }
Esempio n. 4
0
 public function action_edit($id = null)
 {
     $post = Model_Post::find($id);
     $val = Model_Post::validate('edit');
     if ($val->run()) {
         $post->serial_dive_no = Input::post('serial_dive_no');
         $this->_form($post);
         if ($post->save()) {
             Session::set_flash('success', e('Updated post #' . $id));
             Response::redirect('admin/posts');
         } else {
             Session::set_flash('error', e('Could not update post #' . $id));
         }
     } else {
         if (Input::method() == 'POST') {
             $post->serial_dive_no = $val->validated('serial_dive_no');
             $post->date = $val->validated('date');
             $post->location = $val->validated('location');
             $post->point = $val->validated('point');
             $post->point_type = $val->validated('point_type');
             $post->purpose_of_dive = $val->validated('purpose_of_dive');
             $post->diving_shop = $val->validated('diving_shop');
             $post->entry = $val->validated('entry');
             $post->exit = $val->validated('exit');
             $post->water_temp_top = $val->validated('water_temp_top');
             $post->water_temp_bottom = $val->validated('water_temp_bottom');
             $post->depth_of_water_ave = $val->validated('depth_of_water_ave');
             $post->depth_of_water_max = $val->validated('depth_of_water_max');
             $post->pressure_start = $val->validated('pressure_start');
             $post->pressure_end = $val->validated('pressure_end');
             $post->dive_time = $val->validated('dive_time');
             $post->weather = $val->validated('weather');
             $post->air_temp = $val->validated('air_temp');
             $post->wind = $val->validated('wind');
             $post->wind_type = $val->validated('wind_type');
             $post->wave = $val->validated('wave');
             $post->suit = $val->validated('suit');
             $post->weight = $val->validated('weight');
             $post->computer = $val->validated('computer');
             $post->tank = $val->validated('tank');
             $post->tank_cap = $val->validated('tank_cap');
             $post->visibility = $val->validated('visibility');
             $post->impression = $val->validated('impression');
             $post->buddy = $val->validated('buddy');
             $post->instructor_and_guide = $val->validated('instructor_and_guide');
             $post->report = $val->validated('report');
             $post->comment = $val->validated('comment');
             $post->status = $val->validated('status');
             $post->user_id = $val->validated('user_id');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('post', $post, false);
     }
     $this->template->title = "EditPost";
     $this->template->content = View::forge('admin/posts/edit');
 }
Esempio n. 5
0
 public function action_update($Pid = 0)
 {
     $username = Auth::get_screen_name();
     $this->data['token_key'] = Config::get('security.csrf_token_key');
     $this->data['token'] = Security::fetch_token();
     if (Security::check_token()) {
         $val = Model_Post::validate();
         if ($val->run()) {
             $post = Model_Post::find($Pid);
             $post->class = Input::post('cla');
             $post->Title = Input::post('title');
             $post->Pcontent = Input::post('Pcontent');
             $post->Kid = Input::post('category');
             Upload::process();
             if (Upload::is_valid()) {
                 //設定を元に保存をする
                 Upload::save();
                 foreach (Upload::get_files() as $file) {
                     $post->image = $file['saved_as'];
                 }
             }
             $post->save();
             $this->action_categorize();
             $this->data['users'] = Model_Users::query()->where('username', '=', $username)->get();
             $this->data['posts'] = Model_Post::query()->where('username', '=', $username)->order_by('Ptime', 'desc')->get();
             $message = '投稿内容を変更しました。';
             $view = View::forge('mypage/mypage', $this->data);
             $view->username = $username;
             $view->set_global('message', $message, false);
             $view->set_global('error', $this->error, false);
             //バリデーションエラー
         } else {
             $this->action_categorize();
             $Pid and $this->data['posts'] = DB::select()->from('Post')->where('Pid', '=', $Pid)->execute();
             $view = View::forge('post/PostEdit', $this->data);
             $this->error = $val->error();
             $view->username = $username;
             $view->set_global('error', $this->error, false);
         }
     } else {
         Profiler::mark('CSRFだー!');
     }
     return $view;
 }
Esempio n. 6
0
 public function post_edit($id = null)
 {
     $post = Model_Post::find($id);
     $val = Model_Post::validate('edit');
     if ($val->run()) {
         $post->slug = Input::post('slug');
         $post->title = Input::post('title');
         $post->body = Input::post('body');
         $post->user_id = Input::post('user_id');
         $post->active = Input::post('active');
         $categories = array();
         $categories = Input::post('category_id');
         //exit(var_dump(Input::post('category_id')));
         unset($post->categories);
         foreach ($categories as $category_id) {
             $post->categories[] = Model_Category::find($category_id);
         }
         if ($post->save()) {
             Session::set_flash('success', e('Updated post #' . $id));
             Response::redirect('admin/posts');
         } else {
             Session::set_flash('error', e('Could not update post #' . $id));
         }
     } else {
         if (Input::method() == 'POST') {
             $post->slug = $val->validated('slug');
             $post->title = $val->validated('title');
             $post->body = $val->validated('body');
             $post->user_id = $val->validated('user_id');
             $post->active = $val->validated('active');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('post', $post, false);
     }
     $this->template->title = "Posts";
     $this->template->content = View::forge('admin/posts/edit');
 }
Esempio n. 7
0
 public function action_save()
 {
     //ページネーションの設定
     $count = Model_Post::count();
     $config = array('pagination_url' => 'noteshare/home', 'uri_segment' => 2, 'num_links' => 3, 'per_page' => $this->per_page, 'total_items' => $count, 'show_first' => true, 'show_last' => true);
     //ページネーションオブジェクトの作成
     $pagination = Pagination::forge('post_pagination', $config);
     $this->data['rows'] = Model_Post::query()->order_by('Ptime', 'desc')->limit($this->per_page)->offset($pagination->offset)->get();
     //postでデータが送信されたか?
     if (Input::post()) {
         //CSRF対策用のトークンを生成
         $this->data['token_key'] = Config::get('security.csrf_token_key');
         $this->data['token'] = Security::fetch_token();
         //CSRF対策
         if (Security::check_token()) {
             //バリデーション定義の読み込み
             $val = Model_Post::validate();
             if ($val->run()) {
                 $form = array();
                 $form['username'] = Auth::get_screen_name();
                 $form['Kid'] = input::post('category');
                 $form['class'] = "【" . Input::post('cla') . "】";
                 $form['Title'] = Input::post('title');
                 $form['Pcontent'] = Input::post('Pcontent');
                 //アップロードファイルがバリデーション通りなら投稿内容保存
                 if (Upload::is_valid()) {
                     //設定を元に保存をする
                     Upload::save();
                     foreach (Upload::get_files() as $file) {
                         $form['image'] = $file['saved_as'];
                     }
                 }
                 //モデルの呼び出し
                 $post = Model_Post::forge();
                 $post->set($form);
                 $post->save();
                 //home/homeに遷移
                 Response::redirect('home');
                 //バリデーションエラー
             } else {
                 $this->error = $val->error();
                 $this->action_categorize();
                 $view = View::forge('home/home', $this->data);
                 $view->set_safe('pagination', $pagination);
                 $view->set_global('error', $this->error, false);
                 $view->set_global('csrmsg', $this->csrmsg, false);
                 $view->set_global('msg', $this->msg, false);
             }
             //CSRFエラー
         } else {
             $this->csrmsg = '不正なリクエストです。<br>もう一度home画面にアクセスし、投稿をやり直してください。';
             $this->action_categorize();
             $view = View::forge('home/home', $this->data);
             $view->set_safe('pagination', $pagination);
             $view->set_global('error', $this->error, false);
             $view->set_global('csrmsg', $this->csrmsg, false);
             $view->set_global('msg', $this->msg, false);
             Profiler::mark('CSRFです');
         }
         //postエラー
     } else {
     }
     return $view;
 }