/** * Action: edit */ public function action_edit() { $this->history = false; // Load role $role_id = (int) $this->request->param('id', 0); if ($role_id) { $role = Model_Role::factory($role_id); if (!$role->loaded()) { throw new Model_Exception($role, $role_id); } Permission::required($role, Model_Role::PERMISSION_UPDATE, self::$user); } else { $role = Model_Role::factory(); Permission::required($role, Model_Role::PERMISSION_CREATE, self::$user); } // Handle post $errors = array(); if ($_POST) { $role->name = Arr::get($_POST, 'name'); $role->description = Arr::get($_POST, 'description'); try { $role->save(); $this->request->redirect(Route::url('roles')); } catch (Validation_Exception $e) { $errors = $e->array->errors('validate'); } } // Set title $this->view = View_Page::factory(__('Role') . ($role->name ? ': ' . $role->name : '')); // Set actions if ($role->loaded() && Permission::has($role, Model_Role::PERMISSION_DELETE, self::$user)) { $this->page_actions[] = array('link' => Route::model($role, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete role'), 'class' => 'btn btn-danger role-delete'); } $this->view->add(View_Page::COLUMN_MAIN, $this->section_role($role, $errors)); }
/** * Construct controller */ public function before() { Permission::required(new Model_Forum_Private_Area(), Model_Forum_Private_Area::PERMISSION_READ, self::$user); $this->private = true; $this->tab_id = 'private'; parent::before(); }
/** * Controller default action */ public function action_index() { // Dismiss notification? if ($dismiss = (int) Arr::get($_REQUEST, 'dismiss')) { $notification = Model_Notification::factory($dismiss); if ($notification->loaded()) { Permission::required($notification, Model_Notification::PERMISSION_DELETE); $notification->delete(); /* if ($this->_request_type == self::REQUEST_AJAX) { $this->response->body(''); return; }*/ } } $section = $this->section_notifications(Notification::get_notifications(Visitor::$user)); if ($this->_request_type == self::REQUEST_AJAX) { $this->response->body($section); } else { $this->view = new View_Page('Notifications'); $this->view->add(View_Page::COLUMN_CENTER, $section); } }
/** * Action: edit */ public function action_edit() { $this->history = false; $this->tabs = null; $group_id = (int) $this->request->param('id', null); // Load group if ($group_id) { $group = Model_Forum_Group::factory((int) $group_id); if (!$group->loaded()) { throw new Model_Exception($group, (int) $group_id); } } else { $group = Model_Forum_Group::factory(); $group->created = time(); $group->author_id = Visitor::$user->id; } Permission::required($group, $group->loaded() ? Model_Forum_Group::PERMISSION_UPDATE : Model_Forum_Group::PERMISSION_CREATE); // Handle post $errors = array(); if ($_POST) { $group->set_fields(Arr::intersect($_POST, array('name', 'description', 'sort'))); try { $group->save(); $this->request->redirect(Route::model($group)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validate'); } } // Build page $this->view = new View_Page(__('Forum group') . ($group->name ? ': ' . HTML::chars($group->name) : '')); $this->view->tab = 'areas'; // Set actions if ($group->loaded() && Permission::has($group, Model_Forum_Group::PERMISSION_DELETE)) { $this->view->actions[] = array('link' => Route::model($group, 'delete'), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete group'), 'class' => 'btn btn-danger group-delete'); } $this->view->add(View_Page::COLUMN_CENTER, $this->section_edit($group, $errors)); }
/** * Action: edit */ public function action_edit() { $this->history = false; // Load role $role_id = (int) $this->request->param('id', 0); if ($role_id) { $role = Jelly::select('role', $role_id); if (!$role->loaded()) { throw new Model_Exception($role, $role_id); } Permission::required($role, Model_Role::PERMISSION_UPDATE, self::$user); } else { $role = Jelly::factory('role'); Permission::required($role, Model_Role::PERMISSION_CREATE, self::$user); } // Handle post $errors = array(); if ($_POST) { $role->set($_POST); try { $role->save(); $this->request->redirect(Route::get('roles')->uri()); } catch (Validate_Exception $e) { $errors = $e->array->errors('validate'); } } // Set title $this->page_title = __('Role') . ($role->name ? ': ' . HTML::chars($role->name) : ''); // Set actions if ($role->loaded() && Permission::has($role, Model_Role::PERMISSION_DELETE, self::$user)) { $this->page_actions[] = array('link' => Route::model($role, 'delete', false), 'text' => __('Delete role'), 'class' => 'role-delete'); } // Build form $form = array('values' => $role, 'errors' => $errors, 'cancel' => Request::back(Route::get('roles')->uri(), true), 'groups' => array(array('fields' => array('name' => array(), 'description' => array())))); //Widget::add('main', View_Module::factory('roles/edit', array('role' => $role, 'errors' => $errors))); Widget::add('main', View_Module::factory('form/anqh', array('form' => $form))); }
/** * Edit gallery * * @param integer $gallery_id * @param integer $event_id */ protected function _edit_gallery($gallery_id = null, $event_id = null) { $this->history = false; if ($gallery_id) { // Editing old $gallery = Model_Gallery::factory($gallery_id); if (!$gallery->loaded()) { throw new Model_Exception($gallery, $gallery_id); } Permission::required($gallery, Model_Gallery::PERMISSION_UPDATE, self::$user); $cancel = Route::model($gallery); $save = null; $upload = false; } else { // Creating new $gallery = Model_Gallery::factory(); Permission::required($gallery, Model_Gallery::PERMISSION_CREATE, self::$user); $cancel = Request::back(Route::url('galleries'), true); $save = __('Continue'); $upload = true; if ($event_id) { /** @var Model_Event $event */ $event = Model_Event::factory($event_id); } } // Handle post $errors = array(); if ($_POST || isset($_GET['from'])) { $event_id = $_POST ? (int) Arr::get($_POST, 'event') : (int) Arr::get($_GET, 'from'); $event = Model_Event::factory($event_id); if (!$gallery->loaded() && $event->loaded()) { // Redirect to existing gallery if trying to create duplicate $old = Model_Gallery::factory()->find_by_event($event_id); if ($old->loaded()) { $this->request->redirect(Route::model($old, 'upload')); } // Fill gallery info from event when creating new $gallery->name = $event->name; $gallery->date = $event->stamp_begin; $gallery->event_id = $event->id; } else { if ($gallery->loaded()) { // Editing old $gallery->set_fields(Arr::intersect($_POST, Model_Gallery::$editable_fields)); } } try { $gallery->save(); $this->request->redirect(Route::model($gallery, $upload ? 'upload' : null)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); } } // Build page $this->view = View_Page::factory(__('Upload images')); // Gallery edit form $section = $this->section_gallery_edit(isset($event) ? $event : null); $section->errors = $errors; $this->view->add(View_Page::COLUMN_MAIN, $section); // Gallery event info if (isset($event) && $event->loaded()) { $this->view->add(View_Page::COLUMN_MAIN, $this->section_event_info($event)); } $this->view->add(View_Page::COLUMN_SIDE, $this->section_upload_help()); }
/** * Edit forum topic * * @param integer $area_id * @param integer $topic_id * * @throws Model_Exception invalid area, invalid topic * @throws InvalidArgumentException missing area and topic */ protected function _edit_topic($area_id = null, $topic_id = null) { $this->history = false; $this->view = new View_Page(); if ($area_id && !$topic_id) { // Start new topic $mode = View_Forum_PostEdit::NEW_TOPIC; /** @var Model_Forum_Private_Area|Model_Forum_Area $area */ $area = $this->private ? Model_Forum_Private_Area::factory($area_id) : Model_Forum_Area::factory($area_id); if (!$area->loaded()) { throw new Model_Exception($area, $area_id); } Permission::required($area, Model_Forum_Area::PERMISSION_POST, self::$user); $this->view->title = HTML::chars($area->name); if ($this->private) { $topic = new Model_Forum_Private_Topic(); $post = new Model_Forum_Private_Post(); $cancel = Route::url('forum_area', array('id' => 'private', 'action' => '')); $recipients = array(); } else { $topic = new Model_Forum_Topic(); $post = new Model_Forum_Post(); $cancel = Route::model($area); } } else { if ($topic_id) { // Edit old topic $mode = View_Forum_PostEdit::EDIT_TOPIC; /** @var Model_Forum_Private_Topic|Model_Forum_Topic $topic */ $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id); if (!$topic->loaded()) { throw new Model_Exception($topic, $topic_id); } Permission::required($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user); // Build recipients list if ($this->private) { $recipients = $topic->find_recipient_names(); } $this->view->title_html = Forum::topic($topic); $cancel = Route::model($topic); // Set actions if (Permission::has($topic, Model_Forum_Topic::PERMISSION_DELETE, self::$user)) { $this->view->actions[] = array('link' => Route::model($topic, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete topic'), 'class' => 'btn btn-danger topic-delete'); } } else { throw new InvalidArgumentException('Topic and area missing'); } } $errors = array(); if ($_POST && Security::csrf_valid()) { // Get recipients if ($this->private) { $post_recipients = array(); foreach (explode(',', Arr::get_once($_POST, 'recipients')) as $recipient) { if ($user = Model_User::find_user_light(trim($recipient))) { $post_recipients[$user['id']] = $user['username']; } } // Make sure author is included $post_recipients[self::$user->id] = self::$user->username; } if (isset($post)) { // New topic $post->post = $_POST['post']; $post->forum_area_id = $area->id; $post->author_id = self::$user->id; $post->author_name = self::$user->username; $post->author_ip = Request::$client_ip; $post->author_host = Request::host_name(); $post->created = time(); try { $post->is_valid(); } catch (Validation_Exception $e) { $errors += $e->array->errors('validate'); } $topic->author_id = self::$user->id; $topic->author_name = self::$user->username; $topic->name = $_POST['name']; $topic->forum_area_id = $area->id; $topic->created = time(); try { $topic->is_valid(); } catch (Validation_Exception $e) { $errors += $e->array->errors('validate'); } // If no errors found, save models if (empty($errors)) { $topic->save(); // Recipients if ($this->private) { $topic->set_recipients($post_recipients); } // Post $post->forum_topic_id = $topic->id; $post->save(); // Topic $topic->first_post_id = $topic->last_post_id = $post->id; $topic->last_poster = self::$user->username; $topic->last_posted = time(); $topic->post_count = 1; $topic->save(); // Area, only public forums if (!$this->private) { $area->last_topic_id = $topic->id; $area->post_count++; $area->topic_count++; $area->save(); } // User self::$user->post_count++; self::$user->save(); // News feed if (!$this->private) { NewsfeedItem_Forum::topic(self::$user, $topic); } $this->request->redirect(Route::model($topic)); } isset($post_recipients) and $recipients = $post_recipients; } else { // Old topic $topic->set_fields(Arr::intersect($_POST, array('name', 'status', 'sticky'))); try { $topic->save(); // Recipients if ($this->private) { $topic->set_recipients($post_recipients); } $this->request->redirect(Route::model($topic)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validate'); } } } $form['errors'] = $errors; $section = $this->section_post_edit($mode, isset($post) ? $post : null); $section->forum_topic = $topic; $section->errors = $errors; $section->cancel = $cancel; $section->recipients = isset($recipients) ? implode(', ', $recipients) : null; $this->view->add(View_Page::COLUMN_MAIN, $section); }
/** * Action: Remove from ignore */ public function action_unignore() { $this->history = false; // Load user $user = $this->_get_user(); Permission::required($user, Model_User::PERMISSION_IGNORE, self::$user); if (Security::csrf_valid()) { self::$user->delete_ignore($user); } $this->request->redirect(URL::user($user)); }
/** * Edit entry * * @param integer $entry_id * * @throws Model_Exception */ protected function _edit_entry($entry_id = null) { $this->history = false; if ($entry_id) { // Editing old $entry = new Model_Blog_Entry($entry_id); if (!$entry->loaded()) { throw new Model_Exception($entry, $entry_id); } Permission::required($entry, Model_Blog_Entry::PERMISSION_UPDATE); $cancel = Route::model($entry); $this->view->title = __('Edit blog entry'); $entry->modified = time(); $entry->modify_count++; } else { // Creating new $entry = new Model_Blog_Entry(); Permission::required($entry, Model_Blog_Entry::PERMISSION_CREATE); $cancel = Request::back(Route::get('blogs')->uri(), true); $newsfeed = true; $this->view->title = __('New blog entry'); $entry->author_id = Visitor::$user->id; $entry->created = time(); } // Handle post $errors = array(); if ($_POST && Security::csrf_valid()) { try { $entry->name = Arr::get($_POST, 'name'); $entry->content = Arr::get($_POST, 'content'); $entry->save(); // Newsfeed if (isset($newsfeed) && $newsfeed) { NewsfeedItem_Blog::entry(Visitor::$user, $entry); } $this->request->redirect(Route::model($entry)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); } } // Form $section = $this->section_entry_edit($entry); $section->cancel = $cancel; $section->errors = $errors; $this->view->add(View_Page::COLUMN_CENTER, $section); }
/** * Edit event * * @param integer $event_id */ protected function _edit_event($event_id = null) { $this->history = false; if ($event_id) { // Editing old $event = Model_Event::factory($event_id); if (!$event->loaded()) { throw new Model_Exception($event, $event_id); } Permission::required($event, Model_Event::PERMISSION_UPDATE, self::$user); $cancel = Request::back(Route::model($event), true); $this->view = View_Page::factory(HTML::chars($event->name)); // Set actions if (Permission::has($event, Model_Event::PERMISSION_DELETE, self::$user)) { $this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete'); } $edit = true; } else { // Creating new $event = new Model_Event(); Permission::required($event, Model_Event::PERMISSION_CREATE, self::$user); $cancel = Request::back(Route::get('events')->uri(), true); $this->view = View_Page::factory(__('New event')); $event->author_id = self::$user->id; $event->created = time(); $edit = false; } // Handle post if ($_POST && Security::csrf_valid()) { // Handle venue if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) { // Hidden events require only city } else { if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) { // Old venue $venue = Model_Venue::factory($venue_id); } else { if ($venue_name = Arr::get($_POST, 'venue_name')) { // Check for duplicate venue $venues = Model_Venue::factory()->find_by_name($venue_name); if ($venues->count()) { $city_name = strtolower(Arr::get($_POST, 'city_name')); foreach ($venues as $venue_old) { if (strtolower($venue_old->city_name) == $city_name) { $venue = $venue_old; break; } } } } } } $post = Arr::intersect($_POST, Model_Event::$editable_fields); if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time'])) { $post['stamp_end']['date'] = $post['stamp_begin']['date']; } $event->set_fields($post); if (Arr::get($_POST, 'free')) { $event->price = 0; } // Venue/location $event->venue_hidden = (bool) $venue_hidden; if ($venue_hidden) { // Hidden events don't have a venue $event->venue_id = null; $event->venue_name = null; } else { if (isset($venue)) { // Venue loaded $event->venue_id = $venue->id; $event->city_name = $venue->city_name; } else { if (!empty($venue_name)) { // Create new venue $venue = Model_Venue::factory(); $venue->name = Arr::get($_POST, 'venue_name'); $venue->address = Arr::get($_POST, 'address'); $venue->latitude = Arr::get($_POST, 'latitude'); $venue->longitude = Arr::get($_POST, 'longitude'); $venue->event_host = true; $venue->author_id = self::$user->id; $venue->city_name = $event->city_name; try { $venue->save(); $event->venue_id = $venue->id; } catch (Validation_Exception $venue_validation) { } } } } // Validate event try { $event->is_valid(); } catch (Validation_Exception $event_validation) { } // If no errors found, save if (!isset($venue_validation) && !isset($event_validation)) { // Make sure end time is after start time, i.e. the next day if ($event->stamp_end < $event->stamp_begin) { $event->stamp_end += Date::DAY; } $event->save(); // Set tags $event->set_tags(Arr::get($_POST, 'tag')); $edit ? NewsfeedItem_Events::event_edit(self::$user, $event) : NewsfeedItem_Events::event(self::$user, $event); $this->request->redirect(Route::model($event)); } } // Fill the required information to view $this->view->event = $event; $this->view->event_errors = isset($event_validation) ? $event_validation->array->errors('validation') : null; $this->view->venue = isset($venue) ? $venue : null; $this->view->venue_errors = isset($venue_validation) ? $venue_validation->array->errors('validation') : null; // Tags $tags = array(); $tag_group = new Model_Tag_Group('Music'); if ($tag_group->loaded() && count($tag_group->tags())) { foreach ($tag_group->tags() as $tag) { $tags[$tag->id()] = $tag->name(); } } // Form $section = $this->section_event_edit($event); $section->event_errors = isset($event_validation) ? $event_validation->array->errors('validation') : null; $section->venue = isset($venue) ? $venue : $event->venue; $section->venue_errors = isset($venue_validation) ? $venue_validation->array->errors('validation') : null; $section->cancel = $cancel; $this->view->add(View_Page::COLUMN_TOP, $section); }
/** * Action: index */ public function action_index() { // Load group(s) $group_id = (int) $this->request->param('id'); $actions = array(); if (!$group_id) { // All groups $groups = Model_Forum_Group::factory()->find_all(); if (Permission::has(new Model_Forum_Group(), Model_Forum_Group::PERMISSION_CREATE, self::$user)) { $actions[] = array('link' => Route::url('forum_group_add'), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New group')); } } else { // One group $group = Model_Forum_Group::factory($group_id); if (!$group->loaded()) { throw new Model_Exception($group, $group_id); } Permission::required($group, Model_Forum_Group::PERMISSION_READ, self::$user); if (Permission::has($group, Model_Forum_Group::PERMISSION_UPDATE, self::$user)) { $actions[] = array('link' => Route::model($group, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit group')); } if (Permission::has($group, Model_Forum_Group::PERMISSION_CREATE_AREA, self::$user)) { $actions[] = array('link' => Route::model($group, 'add'), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New area')); } $groups = array($group); } // Build page $this->view = new View_Page(count($groups) > 1 ? __('Forum areas') : $groups[0]->name); $this->view->tab = 'areas'; $this->view->actions = $actions; foreach ($groups as $group) { $this->view->add(View_Page::COLUMN_MAIN, $this->section_group($group)); } $this->_side_views(); }
/** * Edit track. * * @param integer $track_id * * @throws Model_Exception */ protected function _edit_track($track_id = null) { $this->history = false; if ($track_id) { // Editing old $track = new Model_Music_Track($track_id); if (!$track->loaded()) { throw new Model_Exception($track, $track_id); } Permission::required($track, Model_Music_Track::PERMISSION_UPDATE); $cancel = Route::model($track); $this->view = new View_Page(HTML::chars($track->name)); // Set actions if (Permission::has($track, Model_Music_Track::PERMISSION_DELETE)) { $this->view->actions[] = array('link' => Route::model($track, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete'), 'class' => 'btn-danger music-delete'); } } else { // Creating new $track = new Model_Music_Track(); Permission::required($track, Model_Music_Track::PERMISSION_CREATE); $cancel = Request::back(Route::url('charts'), true); $newsfeed = true; $this->view = new View_Page($this->request->param('music') === 'mixtape' ? __('New mixtape') : __('New track')); $track->author_id = Visitor::$user->id; $track->type = $this->request->param('music') === 'mixtape' ? Model_Music_Track::TYPE_MIX : Model_Music_Track::TYPE_TRACK; $track->created = time(); } // Handle post $errors = array(); if ($_POST && Security::csrf_valid()) { try { $track->set_fields(Arr::intersect($_POST, Model_Music_Track::$editable_fields)); $track->save(); // Set tags $track->set_tags(Arr::get($_POST, 'tag')); // Newsfeed if (isset($newsfeed) && $newsfeed) { NewsfeedItem_Music::track(Visitor::$user, $track); // Create forum topic if ($track->add_forum_topic()) { Visitor::$user->post_count++; Visitor::$user->save(); } } $this->request->redirect(Route::model($track)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); } } // Form $section = $this->section_track_edit($track); $section->cancel = $cancel; $section->errors = $errors; $this->view->add(View_Page::COLUMN_TOP, $section); }
/** * Action: settings */ public function action_settings() { $this->history = false; $user = $this->_get_user(); Permission::required($user, Model_User::PERMISSION_UPDATE, self::$user); // Set generic page parameters $this->_set_page($user); // Handle post $errors = array(); if ($_POST && Security::csrf_valid()) { $user->set(Arr::extract($_POST, Model_User::$editable_fields)); // GeoNames if ($_POST['city_id'] && ($city = Geo::find_city((int) $_POST['city_id']))) { $user->city = $city; } $user->modified = time(); try { $user->save(); $this->request->redirect(URL::user($user)); } catch (Validate_Exception $e) { $errors = $e->array->errors('validation'); } } // Build form $form = array('values' => $user, 'errors' => $errors, 'cancel' => URL::user($user), 'hidden' => array('city_id' => $user->city ? $user->city->id : 0, 'latitude' => $user->latitude, 'longitude' => $user->longitude), 'groups' => array('basic' => array('header' => __('Basic information'), 'fields' => array('name' => array(), 'gender' => array('input' => 'radio'), 'dob' => array('pretty_format' => 'j.n.Y'), 'title' => array(), 'description' => array('attributes' => array('rows' => 5)))), 'contact' => array('header' => __('Contact information'), 'fields' => array('email' => array(), 'homepage' => array(), 'address_street' => array(), 'address_zip' => array(), 'address_city' => array())), 'forum' => array('header' => __('Forum settings'), 'fields' => array('signature' => array('attributes' => array('rows' => 5)))))); Widget::add('main', View_Module::factory('form/anqh', array('form' => $form))); // Autocomplete $this->autocomplete_city('address_city', 'city_id'); // Date picker $options = array('changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'd.m.yy', 'defaultDate' => date('j.n.Y', $user->dob), 'dayNames' => array(__('Sunday'), __('Monday'), __('Tuesday'), __('Wednesday'), __('Thursday'), __('Friday'), __('Saturday')), 'dayNamesMin' => array(__('Su'), __('Mo'), __('Tu'), __('We'), __('Th'), __('Fr'), __('Sa')), 'firstDay' => 1, 'monthNames' => array(__('January'), __('February'), __('March'), __('April'), __('May'), __('June'), __('July'), __('August'), __('September'), __('October'), __('November'), __('December')), 'monthNamesShort' => array(__('Jan'), __('Feb'), __('Mar'), __('Apr'), __('May'), __('Jun'), __('Jul'), __('Aug'), __('Sep'), __('Oct'), __('Nov'), __('Dec')), 'nextText' => __('»'), 'prevText' => __('«'), 'showWeek' => true, 'showOtherMonths' => true, 'weekHeader' => __('Wk'), 'yearRange' => '1900:+0'); Widget::add('foot', HTML::script_source('$("#field-dob").datepicker(' . json_encode($options) . ');')); // Maps Widget::add('foot', HTML::script_source(' $(function() { $("#fields-contact ul").append("<li><div id=\\"map\\">' . __('Loading map..') . '</div></li>"); $("#map").googleMap(' . ($user->latitude ? json_encode(array('marker' => true, 'lat' => $user->latitude, 'long' => $user->longitude)) : '') . '); $("input[name=address_street], input[name=address_city]").blur(function(event) { var address = $("input[name=address_street]").val(); var city = $("input[name=address_city]").val(); if (address != "" && city != "") { var geocode = address + ", " + city; geocoder.geocode({ address: geocode }, function(results, status) { if (status == google.maps.GeocoderStatus.OK && results.length) { map.setCenter(results[0].geometry.location); $("input[name=latitude]").val(results[0].geometry.location.lat()); $("input[name=longitude]").val(results[0].geometry.location.lng()); var marker = new google.maps.Marker({ position: results[0].geometry.location, map: map }); } }); } }); }); ')); }
/** * Action: private */ public function action_messages() { Permission::required(new Model_Forum_Private_Area(), Model_Forum_Private_Area::PERMISSION_READ, self::$user); // Build page $this->view = new View_Page(__('Private messages')); $this->view->tab = 'private-messages'; $this->view->subtitle = __('Personal and group messages'); // Set actions if (Permission::has(new Model_Forum_Private_Area(), Model_Forum_Private_Area::PERMISSION_POST, self::$user)) { $this->view->actions[] = array('link' => Route::url('forum_private_topic_add', array('action' => 'post')), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New message'), 'class' => 'btn btn-primary'); } // Pagination $pagination = $this->section_pagination(Model_Forum_Private_Topic::factory()->get_count(self::$user)); $this->view->add(View_Page::COLUMN_MAIN, $pagination); // Posts $this->view->add(View_Page::COLUMN_MAIN, $this->section_topics_private(Model_Forum_Private_Area::factory()->find_topics(self::$user, $pagination->offset, $pagination->items_per_page))); // Pagination $this->view->add(View_Page::COLUMN_MAIN, $pagination); $this->_side_views(); }
/** * Edit venue * * @param integer $venue_id */ protected function _edit_venue($venue_id = null) { $this->history = false; $edit = true; if ($venue_id) { // Editing old $venue = Model_Venue::factory($venue_id); if (!$venue->loaded()) { throw new Model_Exception($venue, $venue_id); } Permission::required($venue, Model_Venue::PERMISSION_UPDATE); $cancel = Route::model($venue); $this->view = View_Page::factory($venue->name); // Modified timestamp $venue->modified = time(); // Set actions if (Permission::has($venue, Model_Venue::PERMISSION_DELETE)) { $this->view->actions[] = array('link' => Route::model($venue, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete venue'), 'class' => 'btn btn-danger venue-delete'); } } else { // Creating new $edit = false; $venue = Model_Venue::factory(); $venue->author_id = Visitor::$user->id; $cancel = Route::url('venues'); $this->view = View_Page::factory(__('New venue')); } // Handle post $errors = array(); if ($_POST && Security::csrf_valid()) { $venue->set_fields(Arr::intersect($_POST, Model_Venue::$editable_fields)); try { $venue->save(); $edit ? NewsfeedItem_Venues::venue_edit(Visitor::$user, $venue) : NewsfeedItem_Venues::venue(Visitor::$user, $venue); $this->request->redirect(Route::model($venue)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); } } $section = $this->section_venue_edit($venue); $section->errors = $errors; $section->cancel = $cancel; $this->view->add(View_Page::COLUMN_TOP, $section); }
/** * Edit event * * @param integer $event_id */ protected function _edit_event($event_id = null) { $this->history = false; if ($event_id) { // Editing old $event = Model_Event::factory($event_id); if (!$event->loaded()) { throw new Model_Exception($event, $event_id); } Permission::required($event, Model_Event::PERMISSION_UPDATE); $cancel = Request::back(Route::model($event), true); $this->view = View_Page::factory(HTML::chars($event->name)); // Set actions if (Permission::has($event, Model_Event::PERMISSION_DELETE)) { $this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete'); } $edit = true; $event->update_count++; $event->modified = time(); } else { // Creating new $event = new Model_Event(); Permission::required($event, Model_Event::PERMISSION_CREATE); $cancel = Request::back(Route::get('events')->uri(), true); $this->view = View_Page::factory(__('New event')); $event->author_id = Visitor::$user->id; $event->created = time(); $edit = false; } // Handle post if ($_POST && Security::csrf_valid()) { $preview = isset($_POST['preview']); // Handle venue if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) { // Hidden events require only city } else { if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) { // Old venue $venue = Model_Venue::factory($venue_id); } else { if ($venue_name = Arr::get($_POST, 'venue_name')) { // Check for duplicate venue $venues = Model_Venue::factory()->find_by_name($venue_name); if ($venues->count()) { $city_name = strtolower(Arr::get($_POST, 'city_name')); foreach ($venues as $venue_old) { if (strtolower($venue_old->city_name) == $city_name) { $venue = $venue_old; break; } } } } } } $post = Arr::intersect($_POST, Model_Event::$editable_fields); if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time']) && !isset($post['stamp_end']['date'])) { $post['stamp_end']['date'] = $post['stamp_begin']['date']; } $event->set_fields($post); if (Arr::get($_POST, 'free')) { $event->price = 0; } // Venue/location $event->venue_hidden = (bool) $venue_hidden; if ($venue_hidden) { // Hidden events don't have a venue $event->venue_id = null; $event->venue_name = null; } else { if (isset($venue)) { // Venue loaded $event->venue_id = $venue->id; $event->city_name = $venue->city_name; } else { if (!empty($venue_name)) { // Create new venue $venue = Model_Venue::factory(); $venue->name = Arr::get($_POST, 'venue_name'); $venue->address = Arr::get($_POST, 'address'); $venue->latitude = Arr::get($_POST, 'latitude'); $venue->longitude = Arr::get($_POST, 'longitude'); $venue->foursquare_id = Arr::get($_POST, 'foursquare_id'); $venue->event_host = true; $venue->author_id = Visitor::$user->id; $venue->city_name = $event->city_name; if (!$preview) { try { $venue->save(); $event->venue_id = $venue->id; } catch (Validation_Exception $venue_validation) { } } } } } // Validate event try { $event->is_valid(); } catch (Validation_Exception $event_validation) { } // Handle preview request if ($preview) { if ($this->ajax) { $preview = '<p>' . self::_event_subtitle($event) . '</p>'; $preview .= '<div id="main" class="col-md-8">'; $preview .= $this->section_event_main($event); $preview .= '<hr></div>'; $this->response->body($preview); } return; } // Flyer if ($flyer_url = Arr::get($_POST, 'flyer')) { $event->flyer_url = $flyer_url; $image = new Model_Image(); $image->remote = $flyer_url; $image->created = time(); $image->author_id = Visitor::$user->id; try { $image->save(); try { $flyer = new Model_Flyer(); $flyer->set_fields(array('image_id' => $image->id, 'name' => $event->name, 'stamp_begin' => $event->stamp_begin)); $flyer->save(); } catch (Validation_Exception $flyer_validation) { $flyer_error = print_r($flyer_validation->array->errors('validation'), true); } } catch (Validation_Exception $image_validation) { $flyer_error = print_r($image_validation->array->errors('validation'), true); } catch (Kohana_Exception $e) { $flyer_error = $e->getMessage(); } } // If no errors found, save if (!isset($venue_validation) && !isset($event_validation) && !isset($flyer_error)) { // Make sure end time is after start time, i.e. the next day if ($event->stamp_end < $event->stamp_begin) { $event->stamp_end += Date::DAY; } $event->save(); // Handle flyer if (isset($image) && isset($flyer) && $flyer->loaded()) { $flyer->event_id = $event->id; $flyer->save(); $event->set_flyer($flyer); $event->save(); } // Set tags $event->set_tags(Arr::get($_POST, 'tag')); if ($edit) { // Don't flood edits right after save if (time() - $event->created > 60 * 30) { NewsfeedItem_Events::event_edit(Visitor::$user, $event); } } else { NewsfeedItem_Events::event(Visitor::$user, $event); // Add to favorites $event->add_favorite(Visitor::$user); // Create forum topic if ($event->add_forum_topic()) { Visitor::$user->post_count++; Visitor::$user->save(); } } $this->request->redirect(Route::model($event)); } } // Remove orphan flyer on all errors if (isset($flyer)) { $flyer->delete(); } else { if (isset($image)) { $image->delete(); } } // Tags $tags = array(); $tag_group = new Model_Tag_Group('Music'); if ($tag_group->loaded() && count($tag_group->tags())) { foreach ($tag_group->tags() as $tag) { $tags[$tag->id()] = $tag->name(); } } // Form $section = $this->section_event_edit($event); $section->event_errors = isset($event_validation) ? $event_validation->array->errors('validation') : null; $section->flyer_error = isset($flyer_error) ? $flyer_error : null; $section->venue = isset($venue) ? $venue : $event->venue; $section->venue_errors = isset($venue_validation) ? $venue_validation->array->errors('validation') : null; $section->cancel = $cancel; $this->view->add(View_Page::COLUMN_TOP, $section); }