public function index($id = null) { $page = ORM::factory('page', $id); $post = $_POST; if (isset($post['banner'])) { $banner = $post['banner']; unset($post['banner']); } if (isset($banner) && count($banner) > 0) { $banner_images = $banner; $page_banners = $page->banners; $arr = array(); foreach ($page_banners as $b) { $arr[] = $b; $page->remove($b); } if (count($arr)) { ORM::factory('banner')->delete_all($arr); } $b = ORM::factory('banner'); $b = new Banner_Model(); $b->title = $page->title . ' - Banner'; foreach ($banner_images as $image) { $b->add(ORM::factory('media', $image)); } $page->add($b); } if (isset($post['gallery'])) { $gallery = $post['gallery']; unset($post['gallery']); } if (isset($gallery) && count($gallery) > 0) { $page_images = $page->medias; $arr = array(); foreach ($page_images as $img) { $arr[] = $img->id; $page->remove($img); } foreach ($gallery as $image) { $page->add(ORM::factory('media', $image)); } } foreach ($post as $key => $val) { // Set user data $page->{$key} = $val; } $this->page = $page; $this->template = new View('templates/' . $this->page->template->url); $this->setup_done = false; $this->__setup(); $extraJS = "\$(function() {\r\n\t\t\t\$('body').append('<div style=\"position:absolute;top:0px;left:0px;background: rgb(0, 174, 239); color:#fff;padding:20px;\">THIS IS ONLY A PREVIEW</div>');\r\n\t\t});"; $this->__set_options(array("seoTitle" => "PREVIEW - " . $this->page->seoTitle, "extraJS" => $this->page->extraJS . $extraJS)); }
public function save($id) { $page = ORM::factory('page', $id); if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things $post = new Validation($_POST); // Add some rules, the input field, followed by a list of checks, carried out in order // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid if (isset($post['banner'])) { $banner = $post['banner']; unset($post['banner']); } if (isset($banner) && count($banner) > 0) { $banner_images = $banner; $page_banners = $page->banners; $arr = array(); foreach ($page_banners as $b) { $arr[] = $b; $page->remove($b); } if (count($arr)) { ORM::factory('banner')->delete_all($arr); } $b = ORM::factory('banner'); $b = new Banner_Model(); $b->title = $page->title . ' - Banner'; $b->save(); foreach ($banner_images as $image) { $b->add(ORM::factory('media', $image)); } $b->save(); $page->add($b); /* remove current banners_pages where page_id = $id; add new banner and new banners_medias where banner_id = new banner and media_id = selected id */ } if (isset($post['gallery'])) { $gallery = $post['gallery']; unset($post['gallery']); } if (isset($gallery) && count($gallery) > 0) { $page_images = $page->medias; $arr = array(); foreach ($page_images as $img) { $arr[] = $img->id; $page->remove($img); } foreach ($gallery as $image) { $page->add(ORM::factory('media', $image)); } } foreach ($post as $key => $val) { // Set user data $page->{$key} = $val; } if ($page->save()) { $this->index(); url::redirect('admin/pages'); } else { $this->edit($id); $this->template->error_message = "Sorry, there has been an error, please try again."; } // ok, do whatever ... } else { $this->edit($id); if ($post['title'] == '') { $this->template->error_message = "Sorry, there needs to be a title."; } } } else { $this->edit($id); $this->template->error_message = "nothing has been posted!!!!"; } }