public static function getInstance() { if (!self::$instance instanceof self) { self::$instance = new self(); } return self::$instance; }
<?php include 'locations_repo.php'; error_log("save_location"); error_log(json_encode($_POST)); $locations_repo = LocationsRepository::getInstance(); $locations_repo->addLocation($_POST["lat"], $_POST['lng']); ?> <html> <body>Ubicacion recibida: <?php echo $_POST["lat"] + "," + $_POST['lng']; ?> </body> </html>
<?php include 'contacts_repo.php'; include 'locations_repo.php'; ContactsRepository::getInstance()->reset(); LocationsRepository::getInstance()->reset(); header("Location: ./index.php");
/** * main events admin function */ public static function main() { $path = ROOT . DS . 'public' . DS . 'uploads' . DS; // Request: add event if (Request::post('add_event')) { if (Security::check(Request::post('csrf'))) { if (EventsRepository::insert(EventsAdmin::_getEventData())) { Notification::set('success', __('Event was added with success!', 'events')); } else { Notification::set('error', __('Table->insert() returned an error. Event could not be saved.', 'events')); } Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus(EventsRepository::getLastId()) . '-events'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: edit event if (Request::post('edit_event')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('edit_event'); if (EventsRepository::update($id, EventsAdmin::_getEventData())) { Notification::set('success', __('Event was updated with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Event could not be saved.', 'events')); } Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: restore event if (Request::post('restore_trash_event')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('restore_trash_event'); if (EventsRepository::update($id, array('deleted' => 0))) { Notification::set('success', __('Event has been restored from trash with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Event could not be restored.', 'events')); } Request::redirect('index.php?id=events#trash/trash-events'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: delete event if (Request::post('delete_event')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('delete_event'); if (EventsRepository::update($id, array('deleted' => 1))) { Notification::set('success', __('Event has been moved to trash with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Event could not be deleted.', 'events')); } $record = EventsRepository::getById($id); Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: delete trash event if (Request::post('delete_trash_event')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('delete_trash_event'); if (EventsRepository::delete($id)) { Notification::set('success', __('Event has been deleted permanently with success!', 'events')); } else { Notification::set('error', __('Table->delete() returned an error. Event could not be deleted.', 'events')); } Request::redirect('index.php?id=events#trash/trash-events'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: update event status ['published','draft'] if (Request::get('eventaction') and Request::get('eventaction') == 'update_status') { if (Security::check(Request::get('token'))) { $id = (int) Request::get('event_id'); if (EventsRepository::update($id, array('status' => Request::get('status')))) { Notification::set('success', __('Event status has been updated with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Event status could not be updated.', 'events')); } Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: add category if (Request::post('add_category')) { if (Security::check(Request::post('csrf'))) { if (CategoriesRepository::insert(EventsAdmin::_getCategoryData())) { Notification::set('success', __('Category was added with success!', 'events')); } else { Notification::set('error', __('Table->insert() returned an error. Category could not be saved.', 'events')); } Request::redirect('index.php?id=events#categories'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: edit category if (Request::post('edit_category')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('edit_category'); if (CategoriesRepository::update($id, EventsAdmin::_getCategoryData())) { Notification::set('success', __('Category was updated with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Category could not be saved.', 'events')); } Request::redirect('index.php?id=events#categories'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: restore category if (Request::post('restore_trash_category')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('restore_trash_category'); if (CategoriesRepository::update($id, array('deleted' => 0))) { Notification::set('success', __('Category has been restored from trash with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Category could not be restored.', 'events')); } Request::redirect('index.php?id=events#trash/trash-categories'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: delete category if (Request::post('delete_category')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('delete_category'); if (!CategoriesRepository::hasEvents($id)) { if (CategoriesRepository::update($id, array('deleted' => 1))) { Notification::set('success', __('Category has been moved to trash with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Category could not be deleted.', 'events')); } } else { Notification::set('error', __('Deletion failed. This category is assigned to at least one event. Remove this category from every event to delete it.', 'events')); } Request::redirect('index.php?id=events#categories'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: delete trash category if (Request::post('delete_trash_category')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('delete_trash_category'); if (CategoriesRepository::delete($id)) { Notification::set('success', __('Category has been deleted permanently with success!', 'events')); } else { Notification::set('error', __('Table->delete() returned an error. Category could not be deleted.', 'events')); } Request::redirect('index.php?id=events#trash/trash-categories'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: add location if (Request::post('add_location')) { if (Security::check(Request::post('csrf'))) { if (LocationsRepository::insert(EventsAdmin::_getLocationData())) { Notification::set('success', __('Location was added with success!', 'events')); } else { Notification::set('error', __('Table->insert() returned an error. Location could not be saved.', 'events')); } Request::redirect('index.php?id=events#locations'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: edit location if (Request::post('edit_location')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('edit_location'); if (LocationsRepository::update($id, EventsAdmin::_getLocationData())) { Notification::set('success', __('Location was updated with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Location could not be saved.', 'events')); } Request::redirect('index.php?id=events#locations'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: restore location if (Request::post('restore_trash_location')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('restore_trash_location'); if (LocationsRepository::update($id, array('deleted' => 0))) { Notification::set('success', __('Location has been restored from trash with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Location could not be restored.', 'events')); } Request::redirect('index.php?id=events#trash/trash-locations'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: delete location if (Request::post('delete_location')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('delete_location'); if (!LocationsRepository::hasEvents($id)) { if (LocationsRepository::update($id, array('deleted' => 1))) { Notification::set('success', __('Location has been moved to trash with success!', 'events')); } else { Notification::set('error', __('Table->update() returned an error. Location could not be deleted.', 'events')); } } else { Notification::set('error', __('Deletion failed. This location is assigned to at least one event. Remove this location from every event to delete it.', 'events')); } Request::redirect('index.php?id=events#locations'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: delete trash location if (Request::post('delete_trash_location')) { if (Security::check(Request::post('csrf'))) { $id = (int) Request::post('delete_trash_location'); if (LocationsRepository::delete($id)) { Notification::set('success', __('Location has been deleted permanently with success!', 'events')); } else { Notification::set('error', __('Table->delete() returned an error. Location could not be deleted.', 'events')); } Request::redirect('index.php?id=events#trash/trash-locations'); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // get upload directories $directory_list = Dir::scan($path); $directories = array(DS => DS); if (!empty($directory_list)) { foreach ($directory_list as $directory_name) { $directories[$directory_name] = DS . $directory_name; } ksort($directories); } // Get files $file_list = File::scan($path . Option::get('events_image_directory')); $files = array('' => ''); if (!empty($file_list)) { foreach ($file_list as $file_name) { $files[$file_name] = $file_name; } ksort($files); } if (Request::get('action')) { switch (Request::get('action')) { // Request: configuration case "configuration": // Request: options if (Request::post('events_options_update') or Request::post('events_options_update_and_exit')) { if (Security::check(Request::post('csrf'))) { Option::update('events_image_directory', (string) Request::post('events_image_directory')); Option::update('events_placeholder_archive', (string) Request::post('events_placeholder_archive')); Notification::set('success', __('Configuration has been saved with success!', 'events')); Request::redirect('index.php?id=events' . (Request::post('events_options_update') ? '&action=configuration' : '')); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Request: action: resize images if (Request::post('events_action_resize_images') or Request::post('events_action_resize_images_and_exit')) { if (Security::check(Request::post('csrf'))) { $n = 0; $size = (int) Request::post('events_action_resize_size'); $image_dir = $path . Option::get('events_image_directory'); $image_dir_res = $path . Option::get('events_image_directory') . DS . 'resized'; $images = File::scan($image_dir); if (!empty($images)) { // create 'resized' directory if not exists if (!Dir::exists($image_dir_res)) { Dir::create($image_dir_res); } foreach ($images as $file_name) { if (File::exists($image_dir_res . DS . $file_name)) { if (Request::post('events_action_resize_overwrite')) { File::delete($image_dir_res . DS . $file_name); } else { continue; } } list($width, $height) = getimagesize($image_dir . DS . $file_name); $image_orientation = $width > $height ? Image::HEIGHT : Image::WIDTH; Image::factory($image_dir . DS . $file_name)->resize($size, $size, $image_orientation)->save($image_dir_res . DS . $file_name); $n++; } Notification::set('success', __($n . ' images have been resized and saved with success!', 'events')); } else { Notification::set('error', __('There are no images to resize in configured image directory.', 'events')); } Request::redirect('index.php?id=events' . (Request::post('events_action_resize_images') ? '&action=configuration' : '')); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events')); die; } } // Display configuration view View::factory('events/views/backend/configuration')->assign('directories', $directories)->display(); break; // Request: statistics // Request: statistics case "stats": // category-events $categories = CategoriesRepository::getAll(); $categories_active = CategoriesRepository::getActive(); $categories_data = array(); foreach ($categories_active as $c) { $categories_data[$c['id']] = array('title' => '"' . $c['title'] . '"', 'color' => '"#' . $c['color'] . '"', 'highlight' => '"' . EventsAdmin::adjustBrightness('#' . $c['color'], 25) . '"', 'count' => $categories[$c['id']]['count']); } // location-events $locations = LocationsRepository::getAll(); $locations_active = LocationsRepository::getActive(); $locations_data = array(); foreach ($locations_active as $l) { $locations_data[$l['id']] = array('title' => '"' . $l['title'] . '"', 'count' => $locations[$l['id']]['count']); } $locations_data = EventsAdmin::_sortArrayByFields($locations_data, array('count' => SORT_DESC, 'title' => array(SORT_ASC, SORT_STRING))); // year-events and year-visitors $years_data = array(); $categories_years_events = array(); foreach (EventsRepository::getYearEvents() as $year => $events) { $years_data[$year] = array('number_events' => count($events), 'number_visitors' => array_sum(array_column($events, 'number_visitors'))); foreach ($events as $event) { $categories_years_events[$event['category']][$year][] = $event; } } $categories_years_data = array(); $categories_years_visitors = array(); foreach ($categories_years_events as $category => $years) { foreach ($years as $year => $events) { foreach ($years_data as $total_year => $total_count) { if ($year == $total_year) { $categories_years_data[$category][$year] = count($events); $categories_years_visitors[$category][$year] = array_sum(array_column($events, 'number_visitors')); } else { if (array_key_exists($total_year, $categories_years_data[$category])) { $categories_years_data[$category][$year] = count($events); $categories_years_visitors[$category][$year] = array_sum(array_column($events, 'number_visitors')); } else { $categories_years_data[$category][$total_year] = 0; $categories_years_visitors[$category][$total_year] = 0; } } } } } // locations $locations_list = array(); $coordinates = array(); $longitudes = array(); $latitudes = array(); // get location data ready to use with OSM JavaScript foreach (LocationsRepository::getActive() as $location) { if ($location['address']) { $locations_list[] = '"' . $location['address'] . '"'; $coordinates[] = $location['lon'] . ',' . $location['lat']; $longitudes[] = $location['lon']; $latitudes[] = $location['lat']; } } // calculate map center $longitudes = EventsAdmin::_removeOutliers($longitudes, 0.5); $latitudes = EventsAdmin::_removeOutliers($latitudes, 0.5); $coordinates_average = array('lon' => array_sum($longitudes) / count($longitudes), 'lat' => array_sum($latitudes) / count($latitudes)); // event visitors and staff $participants = array(); $events = EventsRepository::getVisitorsAndStaff(); foreach ($events as $event) { if (!CategoriesRepository::hiddenInArchive($event['category'])) { $participants[$event['category']][] = array('title' => $event['title'], 'visitors' => (int) $event['number_visitors'], 'staff' => (int) $event['number_staff']); } } // Display statistics view View::factory('events/views/backend/statistics')->assign('categories', $categories)->assign('categories_active', $categories_active)->assign('categories_data', $categories_data)->assign('locations', $locations)->assign('locations_active', $locations_active)->assign('locations_data', $locations_data)->assign('years_data', $years_data)->assign('categories_years_data', $categories_years_data)->assign('categories_years_visitors', $categories_years_visitors)->assign('coordinates', $coordinates)->assign('coordinates_average', $coordinates_average)->assign('participants', $participants)->display(); break; } } else { // Display index view View::factory('events/views/backend/index')->assign('categories', CategoriesRepository::getAll())->assign('categories_active', CategoriesRepository::getActive())->assign('categories_select', CategoriesRepository::getActiveForSelect())->assign('categories_deleted', CategoriesRepository::getDeleted())->assign('locations', LocationsRepository::getAll())->assign('locations_active', LocationsRepository::getActive())->assign('locations_select', LocationsRepository::getActiveForSelect())->assign('locations_deleted', LocationsRepository::getDeleted())->assign('events_active', EventsRepository::getActive())->assign('events_upcoming', EventsRepository::getUpcoming())->assign('events_past', EventsRepository::getPast())->assign('events_draft', EventsRepository::getDraft())->assign('events_deleted', EventsRepository::getDeleted())->assign('imagepath', DS . 'public' . DS . 'uploads' . DS . Option::get('events_image_directory') . DS)->assign('files', $files)->display(); } }
/** * list events * * @param string $style ['extended', 'minimal', 'archive'] * @param string $time ['future', 'past', 'all'] * @param string $count number of records to show [number or 'all'] * @param string $order ['ASC', 'DESC'] * * @return array * */ public function listEvents($style, $time = 'all', $count = 'all', $order = 'ASC') { // load template according to given style $template = ''; $style = trim($style); if (in_array($style, array('extended', 'minimal', 'archive'))) { $template = 'list-' . $style; $groupby = $style == 'archive' ? 'year' : ''; $is_archive = $style == 'archive'; } else { $template = 'list-minimal'; } return View::factory('events/views/frontend/' . $template)->assign('eventlist', EventsRepository::getList($time, $count, $order, $groupby, $is_archive))->assign('categories', CategoriesRepository::getAll())->assign('locations', LocationsRepository::getAll())->assign('imagepath', 'public/uploads/' . Option::get('events_image_directory') . '/')->render(); }