/** * Show shouts or shout */ public function index() { $shout = new Shout_Model(); $form_values = $shout->as_array(); $form_errors = array(); // Check post if (csrf::valid() && ($post = $this->input->post())) { $shout->author_id = $this->user->id; $shout->shout = $post['shout']; try { $shout->save(); if (!request::is_ajax()) { url::redirect(url::current()); } } catch (ORM_Validation_Exception $e) { $form_errors = $e->validation->errors(); $form_values = arr::overwrite($form_values, $post); } } $shouts = ORM::factory('shout')->find_all(10); $view = View_Mod::factory('generic/shout', array('mod_title' => __('Shouts'), 'shouts' => $shouts, 'can_shout' => ORM::factory('shout')->has_access(Shout_Model::ACCESS_WRITE, $this->user), 'errors' => $form_errors, 'values' => $form_values)); if (request::is_ajax()) { echo $view; return; } widget::add('main', $view); }
/** * Single role view * * @param string $role_id * @param string $action */ public function role($role_id, $action = null) { if ($action) { switch ($action) { // Delete role case 'delete': $this->_role_delete($role_id); return; } } $this->history = false; $role = new Role_Model((int) $role_id); $form_values = $role->as_array(); $form_errors = $errors = array(); // Check post if ($post = $this->input->post()) { $role->name = $post['name']; $role->description = $post['description']; try { $role->save(); url::redirect('/roles'); } catch (ORM_Validation_Exception $e) { $form_errors = $e->validation->errors(); } $form_values = arr::overwrite($form_values, $post); } // show form if ($role->id) { $this->breadcrumb[] = html::anchor('role/' . url::title($role->id, $role->name), html::specialchars($role->name)); $this->page_title = text::title($role->name); $this->page_actions[] = array('link' => 'role/' . url::title($role->id, $role->name) . '/delete', 'text' => __('Delete role'), 'class' => 'role-delete'); } else { $this->page_title = __('Role'); } if (empty($errors)) { widget::add('main', View_Mod::factory('roles/role_edit', array('values' => $form_values, 'errors' => $form_errors))); } else { $this->_error(Kohana::lang('generic.error'), $errors); } }
/** * Home page */ public function index() { $this->page_title = __('Welcome to :site', array(':site' => Kohana::config('site.site_name'))); // Display news feed $newsfeed = new NewsFeed($this->user); $newsfeed->max_items = 25; widget::add('main', View_Mod::factory('generic/newsfeed', array('newsfeed' => $newsfeed->as_array()))); // Shout $shouts = ORM::factory('shout')->find_all(10); widget::add('side', View_Mod::factory('generic/shout', array('mod_title' => __('Shouts'), 'shouts' => $shouts, 'can_shout' => ORM::factory('shout')->has_access(Shout_Model::ACCESS_WRITE, $this->user), 'errors' => array(), 'values' => array()))); // Online $guests = Online_User_Model::get_guest_count(); $online = Online_User_Model::find_online_users(); $counts = array(); if ($guests) { $counts[] = __2(':guests guest', ':guests guests', $guests, array(':guests' => $guests)); } if (count($online)) { $counts[] = __2(':members member', ':members members', count($online), array(':members' => count($online))); } widget::add('side', View_Mod::factory('generic/users', array('mod_title' => __('Online') . ': ' . implode(', ', $counts), 'viewer' => $this->user, 'users' => $online))); }
public function index() { $error = array(); $side_views = array(); // New users $new_users = ORM::factory('user')->order_by('id', 'DESC')->limit(50)->find_all(); $users = array(); foreach ($new_users as $user) { $users[date('Y-m-d', strtotime($user->created))][] = $user; } try { $birthdays = Users::get_birthdays(); } catch (Kohana_Exception $e) { $error[] = $e; } if (empty($error)) { $this->page_subtitle = __('Latest :users members', array(':users' => '<var>' . count($new_users) . '</var>')); widget::add('main', View_Mod::factory('member/members', array('users' => $users, 'type' => 'new'))); widget::add('side', View_Mod::factory('member/birthdays_list', array('mod_class' => 'birthdays', 'birthdays' => $birthdays))); } else { $this->page_title .= ' ' . __('Uh oh.'); widget::add('main', implode('<br />', $error)); } }
/** * Edit topic * * @param mixed $topic_id * @param mixed $area_id */ public function _topic_edit($topic_id, $area_id = false) { $this->history = false; $errors = array(); $forum_topic = new Forum_Topic_Model((int) $topic_id); $forum_area = $forum_topic->loaded() ? $forum_topic->forum_area : new Forum_Area_Model((int) $area_id); if ($forum_topic->loaded()) { // Editing topic $editing = true; if (!$forum_topic->has_access(Forum_Topic_Model::ACCESS_EDIT)) { url::back('forum'); } } else { if ($forum_area->loaded()) { // New topic $editing = false; if (!$forum_area->has_access(Forum_Area_Model::ACCESS_WRITE)) { url::back('forum'); } } else { // New topic in unknown area $errors[] = __('Area :area or topic :topic not found', array(':area' => (int) $area_id, ':topic' => (int) $topic_id)); } } if (empty($errors)) { $forum_post = new Forum_Post_Model((int) $forum_topic->first_post_id); $form_errors = array(); $form_values_topic = $forum_topic->as_array(); $form_values_post = $forum_post->as_array(); $form_topics = false; // Bound area? if ($forum_area->is_type(Forum_Area_Model::TYPE_BIND)) { // Get bind config and load topics $bind = Forum_Area_Model::binds($forum_area->bind); if ($editing) { // Can't edit bound topic $form_topics = array($forum_topic->bind_id => $forum_topic->name); } else { // Try to load options from configured model try { $bind_topics = ORM::factory($bind['model'])->find_bind_topics($forum_area->bind); $form_topics = array(0 => __('Choose..')) + $bind_topics; } catch (Kohana_Exception $e) { $form_topics = array(); } } } // Admin actions if ($editing && $forum_topic->has_access(Forum_Topic_Model::ACCESS_DELETE)) { $this->page_actions[] = array('link' => url::model($forum_topic) . '/delete/?token=' . csrf::token(), 'text' => __('Delete topic'), 'class' => 'topic-delete'); } // Check post if ($post = $this->input->post()) { $post['forum_area_id'] = $forum_area->id; $topic = $post; if (isset($bind_topics)) { $topic['name'] = arr::get($bind_topics, (int) $topic['bind_id'], ''); } $post_extra = $topic_extra = array('author_id' => $this->user->id, 'author_name' => $this->user->username); if ($editing) { $post_extra['modifies'] = (int) $forum_post->modifies + 1; $post_extra['modified'] = date::unix2sql(time()); } $post_extra['author_ip'] = $this->input->ip_address(); $post_extra['author_host'] = $this->input->host_name(); // validate post first and save topic if ok if (csrf::valid() && $forum_post->validate($post, false, $post_extra) && $forum_topic->validate($topic, true, $topic_extra)) { // post $forum_post->forum_topic_id = $forum_topic->id; $forum_post->save(); if (!$editing) { // topic $forum_topic->first_post_id = $forum_post->id; $forum_topic->last_post_id = $forum_post->id; $forum_topic->last_poster = $this->user->username; $forum_topic->last_posted = date::unix2sql(time()); $forum_topic->posts = 1; $forum_topic->save(); // area $forum_area->last_topic_id = $forum_topic->id; $forum_area->posts += 1; $forum_area->topics += 1; $forum_area->save(); // user $this->user->posts += 1; $this->user->save(); // News feed newsfeeditem_forum::topic($this->user, $forum_topic); } // redirect back to topic URL::redirect(url::model($forum_topic)); } else { $form_errors = array_merge($post->errors(), is_object($topic) ? $topic->errors() : array()); } $form_values_topic = arr::overwrite($form_values_topic, is_object($topic) ? $topic->as_array() : $topic); $form_values_post = arr::overwrite($form_values_post, $post->as_array()); } } // Show form if (empty($errors)) { $this->breadcrumb[] = html::anchor(url::model($forum_area), text::title($forum_area->name)); $this->page_title = $editing ? text::title($forum_topic->name) : __('New topic'); $this->page_subtitle = __('Area :area', array(':area' => html::anchor(url::model($forum_area), text::title($forum_area->name), array('title' => strip_tags($forum_area->description))))); widget::add('head', html::script(array('js/jquery.markitup.pack', 'js/markitup.bbcode'))); widget::add('main', View_Mod::factory('forum/topic_edit', array('topic' => $form_values_topic, 'topics' => $form_topics, 'post' => $form_values_post, 'errors' => $form_errors))); } else { $this->_error(__('Error'), $errors); } $this->_side_views(); }
/** * User profile */ public function _view() { $this->tab_id = 'profile'; $owner = $this->user && $this->member->id == $this->user->id; if ($owner && $this->user->newcomments) { $this->user->newcomments = 0; $this->user->save(); } // Actions if ($this->member->has_access(User_Model::ACCESS_EDIT)) { $this->page_actions[] = array('link' => url::user($this->member) . '/edit', 'text' => __('Settings'), 'class' => 'settings'); } // Picture widget::add('side', View_Mod::factory('member/member', array('mod_class' => 'member member-' . $this->member->id, 'user' => $this->member))); // Comments if ($this->member->has_access(User_Model::ACCESS_COMMENT)) { $comment = new User_Comment_Model(); $form_values = $comment->as_array(); $form_errors = array(); // check post if (csrf::valid() && ($post = $this->input->post())) { $comment->user_id = $this->member->id; $comment->author_id = $this->user->id; $comment->comment = $post['comment']; if (isset($post['private'])) { $comment->private = 1; } try { $comment->save(); if (!$owner) { $this->member->newcomments += 1; $this->member->save(); } $this->user->commentsleft += 1; $this->user->save(); if (!request::is_ajax()) { url::redirect(url::current()); } } catch (ORM_Validation_Exception $e) { $form_errors = $e->validation->errors(); $form_values = arr::overwrite($form_values, $post); } } // Handle pagination $per_page = 25; $page_num = $this->uri->segment('page') ? $this->uri->segment('page') : 1; $page_offset = ($page_num - 1) * $per_page; $total_comments = $this->member->get_comment_count(); $comments = $this->member->find_comments($page_num, $per_page, $this->user); $pagination = new Pagination(array('items_per_page' => $per_page, 'total_items' => $total_comments)); $view = View::factory('generic/comments', array('delete' => '/member/comment/%d/delete/?token=' . csrf::token(), 'private' => '/member/comment/%d/private/?token=' . csrf::token(), 'comments' => $comments, 'errors' => $form_errors, 'values' => $form_values, 'pagination' => $pagination, 'user' => $this->user)); if (request::is_ajax()) { echo $view; return; } widget::add('main', $view); } // Basic info $basic_info = array(); if (!empty($this->member->name)) { $basic_info[__('Name')] = html::specialchars($this->member->name); } if (!empty($this->member->city_name)) { $basic_info[__('City')] = html::specialchars($this->member->city_name); } if (!empty($this->member->dob) && $this->member->dob != '0000-00-00') { $basic_info[__('Date of Birth')] = __(':dob (:years years)', array(':dob' => date::format('DMYYYY', $this->member->dob), ':years' => date::timespan(strtotime($this->member->dob), null, 'years'))); } if (!empty($this->member->gender)) { $basic_info[__('Gender')] = $this->member->gender == 'm' ? __('Male') : __('Female'); } if (!empty($this->member->latitude) && !empty($this->member->longitude)) { $basic_info[__('Location')] = $this->member->latitude . ', ' . $this->member->longitude; $basic_info[__('Location')] = html::anchor('#map', __('Toggle map'), array('class' => 'expander', 'title' => __('Show/hide'))) . '<div id="map" style="display: none">' . __('Map loading') . '</div>'; $map = new Gmap('map', array('ScrollWheelZoom' => true)); $map->center($this->member->latitude, $this->member->longitude, 15)->controls('small')->types(); $map->add_marker($this->member->latitude, $this->member->longitude, html::avatar($this->member->avatar, $this->member->username) . html::user($this->member)); widget::add('foot', html::script_source($map->render('gmaps/jquery_event'))); widget::add('foot', html::script_source("\$('a[href*=\"#map\"]:first').click(function() { \$('#map').toggle('normal', gmap_open); return false; });")); } // Site info $site_info = array(__('Registered') => date::format('DMYYYY_HM', $this->member->created) . ' [#' . $this->member->id . ']', __('Logins') => __(':logins (:ago ago)', array(':logins' => number_format($this->member->logins, 0), ':ago' => '<abbr title="' . date::format('DMYYYY_HM', $this->member->last_login) . '">' . date::timespan_short($this->member->last_login) . '</abbr>')), __('Posts') => number_format($this->member->posts, 0), __('Comments') => number_format($this->member->commentsleft, 0)); // Initialize tabs $tabs = array('basic-info' => array('href' => '#basic-info', 'title' => __('Basic info'), 'tab' => new View('generic/list_info', array('id' => 'basic-info', 'title' => __('Basic info'), 'list' => $basic_info))), 'site-info' => array('href' => '#site-info', 'title' => __('Site info'), 'tab' => new View('generic/list_info', array('id' => 'site-info', 'title' => __('Site info'), 'list' => $site_info)))); widget::add('side', View::factory('generic/tabs', array('id' => 'info-tab', 'tabs' => $tabs))); $this->_side_views(); }
/** * Latest blog entries */ public function latest() { // Actions if ($this->user) { $this->page_actions[] = array('link' => 'blog/add', 'text' => __('New blog entry'), 'class' => 'topic-add'); } widget::add('main', View_Mod::factory('blog/entries', array('mod_class' => 'blogentries', 'entries' => ORM::factory('blog_entry')->find_latest(20)))); }
/** * Upcoming events */ public function upcoming() { $this->breadcrumb[] = html::anchor('events/upcoming', __('Upcoming events')); $this->page_title = text::title(__('Upcoming events')); $this->tab_id = 'upcoming'; // actions if ($this->visitor->logged_in(array('event', 'event admin', 'admin'))) { $this->page_actions[] = array('link' => 'event/add', 'text' => __('Add event'), 'class' => 'event-add'); } // fetch events if ($this->country) { $country = ORM::factory('country', $this->country); $filter = array('events.country_id' => $country->id); } else { $filter = false; } $events = ORM::factory('event')->find_upcoming(25, $filter); if ($events->count()) { $this->page_subtitle = __2(':events event', ':events events', $events->count(), array(':events' => '<var>' . $events->count() . '</var>')); widget::add('main', View_Mod::factory('generic/filters', array('filters' => $this->_build_filters($events)))); widget::add('main', View_Mod::factory('events/events', array('events' => $this->_build_events_list($events)))); } $this->_side_views(); }
/** * Edit tag * * @param integer|string $tag_id * @param integer|string $group_id */ public function _tag_edit($tag_id = false, $group_id = false) { $this->history = false; // for authenticated users only if (!$this->user) { url::redirect('/tags'); } $errors = $form_errors = array(); $tag = new Tag_Model((int) $tag_id); $form_values = $tag->get_defaults(); // check post if (request::method() == 'post') { $post = $this->input->post(); $extra = array('author_id' => $this->user->id); if ($tag->validate($post, true, $extra)) { url::redirect(url::model($tag)); } else { $form_errors = $post->errors(); } $form_values = arr::overwrite($form_values, $post->as_array()); } // editing old? if ($tag_id) { $this->page_subtitle = __('Edit tag'); $this->breadcrumb[] = html::anchor(url::model($tag->tag_group), $tag->tag_group->name); $this->breadcrumb[] = html::anchor(url::model($tag), $tag->name); if ($this->visitor->logged_in('admin')) { $this->page_actions[] = array('link' => url::model($tag) . '/delete', 'text' => __('Delete tag'), 'class' => 'tag-delete'); } if (!$tag->id) { $errors = array('tags.error_tag_not_found'); } } else { $this->page_subtitle = __('Add tag'); if ($group_id) { $tag_group = new Tag_Group_Model((int) $group_id); $this->breadcrumb[] = html::anchor(url::model($tag_group), $tag_group->name); $this->breadcrumb[] = html::anchor(url::model($tag_group) . '/add', __('Add tag')); if ($tag_group->id) { $form_values['tag_group_id'] = $tag_group->id; } else { $errors = array('tags.error_tag_group_not_found'); } } } // show form if (empty($errors)) { widget::add('main', View_Mod::factory('tags/tag_edit', array('values' => $form_values, 'errors' => $form_errors))); } else { $this->_error(Kohana::lang('generic.error'), $errors); } $this->_side_views(); }
/** * Construct new page controller */ function __construct() { parent::__construct(); // Init page values $this->country = Session::instance()->get('country', false); // AJAX requests output without template if (request::is_ajax()) { $this->auto_render = false; $this->history = false; return; } // Use profiler only when an admin is logged in if ($this->visitor->logged_in('admin')) { Profiler::enable(); } // Bind the generic page variables $this->template->bind('skin', $this->skin)->bind('skin_imports', $this->skin_imports)->bind('stylesheets', $this->stylesheets)->bind('language', $this->language)->bind('page_width', $this->page_width)->bind('page_main', $this->page_main)->bind('page_id', $this->page_id)->bind('page_class', $this->page_class)->bind('page_title', $this->page_title)->bind('page_subtitle', $this->page_subtitle); // Add controller name as default page id $this->page_id = Router::$controller; // Init page values $this->menu = Kohana::config('site.menu'); $skin_path = 'ui/' . Kohana::config('site.skin') . '/'; $this->skin = $skin_path . 'skin.less'; $this->skin_imports = array('ui/layout.less', 'ui/widget.less', 'ui/jquery-ui.css', 'ui/site.css', $skin_path . 'jquery-ui.css'); $this->page_width = Session::instance()->get('page_width', 'fixed'); $this->page_main = Session::instance()->get('page_main', 'left'); //$this->stylesheets = array('ui/' . Kohana::config('site.skin') . '/skin', 'ui/' . Kohana::config('site.skin') . '/jquery-ui'); $this->breadcrumb = array(); //html::anchor('/', __('Home'))); $this->tabs = array(); // If a country is seleced, add custom stylesheet if ($this->country && Kohana::config('site.country_css')) { widget::add('head', html::stylesheet('ui/' . utf8::strtolower($this->country) . '/skin')); } // Generic views widget::add('actions', View::factory('generic/actions')->bind('actions', $this->page_actions)); // widget::add('breadcrumb', View::factory('generic/breadcrumb')->bind('breadcrumb', $this->breadcrumb)); widget::add('navigation', View::factory('generic/navigation')->bind('items', $this->menu)->bind('selected', $this->page_id)); widget::add('tabs', View::factory('generic/tabs_top')->bind('tabs', $this->tabs)->bind('selected', $this->tab_id)); // Header widget::add('header', View::factory('generic/header')); // Footer widget::add('footer', View_Mod::factory('events/events_list', array('mod_id' => 'footer-events-new', 'mod_class' => 'article unit size1of4 cut events', 'mod_title' => __('New events'), 'events' => ORM::factory('event')->order_by('id', 'DESC')->find_all(10)))); widget::add('footer', View_Mod::factory('forum/topics_list', array('mod_id' => 'footer-topics-active', 'mod_class' => 'article unit size1of4 cut topics', 'mod_title' => __('New posts'), 'topics' => ORM::factory('forum_topic')->order_by('last_post_id', 'DESC')->find_all(10)))); widget::add('footer', View_Mod::factory('blog/entries_list', array('mod_id' => 'footer-blog-entries', 'mod_class' => 'article unit size1of4 cut blogentries', 'mod_title' => __('New blogs'), 'entries' => ORM::factory('blog_entry')->find_latest(10)))); // Dock $classes = array(html::anchor('set/width/narrow', __('Narrow'), array('onclick' => '$("body").addClass("fixed").removeClass("liquid"); $.get(this.href); return false;')), html::anchor('set/width/wide', __('Wide'), array('onclick' => '$("body").addClass("liquid").removeClass("narrow"); $.get(this.href); return false;')), html::anchor('set/main/left', __('Left'), array('onclick' => '$("body").addClass("left").removeClass("right"); $.get(this.href); return false;')), html::anchor('set/main/right', __('Right'), array('onclick' => '$("body").addClass("right").removeClass("left"); $.get(this.href); return false;'))); widget::add('dock2', __('Layout: ') . implode(', ', $classes)); // Language selection $available_languages = Kohana::config('locale.languages'); if (count($available_languages)) { $languages = array(); foreach ($available_languages as $lang => $locale) { $languages[] = html::anchor('set/lang/' . $lang, html::chars($locale[2])); } widget::add('dock2', ' | ' . __('Language: ') . implode(', ', $languages)); } if ($this->user) { // Authenticated view widget::add('dock', __('[#:id] :user', array(':id' => $this->user->id, ':user' => html::nick($this->user->id, $this->user->username)))); $new_messages = array(); if ($this->user->newcomments) { $new_messages[] = html::anchor(url::user($this->user), __(':commentsC', array(':comments' => $this->user->newcomments)), array('title' => __('New comments'), 'class' => 'new-comments')); } if (!empty($new_messages)) { widget::add('dock', ' - ' . __('New messages: ') . implode(' ', $new_messages)); } // Logout also from Facebook if (FB::enabled() && Visitor::instance()->get_provider()) { widget::add('dock', ' - ' . html::anchor('sign/out', FB::icon() . __('Sign out'), array('onclick' => "FB.Connect.logoutAndRedirect('/sign/out'); return false;"))); } else { widget::add('dock', ' - ' . html::anchor('sign/out', __('Sign out'))); } if (Kohana::config('site.inviteonly')) { // widget::add('dock', ' | ' . html::anchor('sign/up', __('Send invite'))); } // Admin functions if ($this->visitor->logged_in('admin')) { widget::add('dock2', ' | ' . __('Admin: ') . html::anchor('roles', __('Roles')) . ', ' . html::anchor('tags', __('Tags')) . ', ' . html::anchor('#kohana-profiler', __('Profiler'), array('onclick' => '$("#kohana-profiler").toggle();'))); } } else { // Non-authenticated view $form = form::open('sign/in'); $form .= form::input('username', null, 'title="' . __('Username') . '"'); $form .= form::password('password', '', 'title="' . __('Password') . '"'); $form .= form::submit('submit', __('Sign in')); $form .= form::close(); $form .= html::anchor('/sign/up', __('Sign up')); if (FB::enabled()) { $form .= ' | ' . FB::fbml_login(); } widget::add('dock', $form); } // End widget::add('end', View::factory('generic/end')); // Analytics $google_analytics = Kohana::config('site.google_analytics'); if ($google_analytics) { widget::add('head', html::script_source("\nvar _gaq = _gaq || []; _gaq.push(['_setAccount', '" . $google_analytics . "']); _gaq.push(['_trackPageview']);\n(function() {\n\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n\t(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);\n})();\n")); } // Ads $ads = Kohana::config('site.ads'); if ($ads && $ads['enabled']) { foreach ($ads['slots'] as $ad => $slot) { widget::add($slot, View::factory('ads/' . $ad)); } } // Facebook connect if (FB::enabled()) { FB::init(); } }
/** * Edit venue * * @param integer|string $venue_id * @param integer|string $category_id */ public function _venue_edit($venue_id = false, $category_id = false) { $this->history = false; $venue = new Venue_Model((int) $venue_id); // Check access if (!($venue->loaded() && $venue->has_access(Venue_Model::ACCESS_EDIT)) && !(!$venue->loaded() && $this->visitor->logged_in(array('admin', 'venue moderator', 'venue')))) { url::back('venues'); } $errors = $form_errors = array(); $form_values = $venue->as_array(); // check post if (request::method() == 'post') { $post = array_merge($this->input->post(), $_FILES); $extra = array('author_id' => $this->user->id); // got address, get geocode if (!empty($post['address']) && !empty($post['city_name'])) { list($extra['latitude'], $extra['longitude']) = Gmap::address_to_ll(implode(', ', array($post['address'], $post['zip'], $post['city_name']))); } if (csrf::valid() && $venue->validate($post, true, $extra)) { // handle logo upload if (isset($post->logo) && empty($post->logo['error'])) { $logo = Image_Model::factory('venues.logo', $post->logo, $this->user->id); if ($logo->id) { $venue->add($logo); $venue->default_image_id = $logo->id; $venue->save(); } } // handle picture uploads foreach (array($post->picture1, $post->picture2) as $picture) { if (isset($picture) && empty($picture['error'])) { $image = Image_Model::factory('venues.image', $picture, $this->user->id); if ($image->id) { $venue->add($image); $venue->save(); } } } // update tags $venue->remove(ORM::factory('tag')); if (!empty($post->tags)) { foreach ($post->tags as $tag_id => $tag) { $venue->add(ORM::factory('tag', $tag_id)); } } url::redirect(url::model($venue)); } else { $form_errors = $post->errors(); } $form_values = arr::overwrite($form_values, $post->as_array()); } // editing old? if ($venue_id) { if ($venue->has_access(Venue_Model::ACCESS_DELETE)) { $this->page_actions[] = array('link' => 'venue/' . url::title($venue->id, $venue->name) . '/delete/?token=' . csrf::token(), 'text' => __('Delete venue'), 'class' => 'venue-delete'); } $this->page_subtitle = __('Edit venue'); if (!$venue->id) { $errors = array('venues.error_venue_not_found'); } else { $venue_category = $venue->venue_category; } } else { $this->page_subtitle = __('Add venue'); if ($category_id) { $venue_category = new Venue_Category_Model((int) $category_id); if ($venue_category->id) { $form_values['venue_category_id'] = $venue_category->id; } else { $errors = array('venues.error_venue_category_not_found'); } } } $this->page_actions[] = array('link' => 'venue/' . url::title($venue->id, $venue->name), 'text' => __('Cancel'), 'class' => 'cancel'); $this->breadcrumb[] = html::anchor('/venues/' . url::title($venue_category->id, $venue_category->name), $venue_category->name); if ($venue->id) { $this->breadcrumb[] = html::anchor('/venue/' . url::title($venue->id, $venue->name), $venue->name); } // show form if (empty($errors)) { $form = array(); // tags if ($venue_category->tag_group_id) { $form['tags'] = $form_values['tags'] = array(); foreach ($venue_category->tag_group->tags as $tag) { $form['tags'][$tag->id] = $tag->name; if ($venue->has($tag)) { $form_values['tags'][$tag->id] = $tag->name; } } } $venue_categories = ORM::factory('venue_category')->find_all()->select_list('id', 'name'); $form['venue_category_id'] = $venue_categories; widget::add('main', View_Mod::factory('venues/venue_edit', array('form' => $form, 'values' => $form_values, 'errors' => $form_errors))); // city autocomplete $this->_autocomplete_city(); } else { $this->_error(Kohana::lang('generic.error'), $errors); } $this->_side_views(); }