Esempio n. 1
0
/**
 * Outputs table of events belonging to user
 * @param array $args
 */
function em_events_admin($args = array())
{
    global $EM_Event, $bp;
    if (is_user_logged_in() && current_user_can('edit_events')) {
        if (!empty($_GET['action']) && $_GET['action'] == 'edit') {
            if (empty($_REQUEST['redirect_to'])) {
                $_REQUEST['redirect_to'] = em_add_get_params($_SERVER['REQUEST_URI'], array('action' => null, 'event_id' => null));
            }
            em_event_form();
        } else {
            $limit = !empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
            //Default limit
            $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
            $offset = $page > 1 ? ($page - 1) * $limit : 0;
            $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'ASC';
            $scope_names = em_get_scopes();
            $scope = !empty($_REQUEST['scope']) && array_key_exists($_REQUEST['scope'], $scope_names) ? $_REQUEST['scope'] : 'future';
            if (array_key_exists('status', $_REQUEST)) {
                $status = $_REQUEST['status'] ? 1 : 0;
            } else {
                $status = false;
            }
            $search = !empty($_REQUEST['em_search']) ? $_REQUEST['em_search'] : '';
            $args = array('scope' => $scope, 'order' => $order, 'search' => $search, 'owner' => get_current_user_id(), 'status' => $status);
            $events_count = EM_Events::count($args);
            //count events without limits for pagination
            $args['limit'] = $limit;
            $args['offset'] = $offset;
            $EM_Events = EM_Events::get($args);
            if ($scope != 'future') {
                $future_count = EM_Events::count(array('status' => 1, 'owner' => get_current_user_id(), 'scope' => 'future'));
            } else {
                $future_count = $events_count;
            }
            $pending_count = EM_Events::count(array('status' => 0, 'owner' => get_current_user_id(), 'scope' => 'all'));
            em_locate_template('tables/events.php', true, array('args' => $args, 'EM_Events' => $EM_Events, 'events_count' => $events_count, 'future_count' => $future_count, 'pending_count' => $pending_count, 'page' => $page, 'limit' => $limit, 'offset' => $offset, 'show_add_new' => true));
        }
    } elseif (!is_user_logged_in() && get_option('dbem_events_anonymous_submissions')) {
        em_event_form($args);
    } else {
        echo apply_filters('em_event_submission_login', __("You must log in to view and manage your events.", 'dbem'));
    }
}
Esempio n. 2
0
/**
 * Outputs table of events belonging to user
 * Additional search arguments:
 * * show_add_new - passes argument to template as $show_add_new whether to show the add new event button
 * @param array $args
 */
function em_events_admin($args = array())
{
    global $EM_Event, $bp;
    if (is_user_logged_in() && current_user_can('edit_events')) {
        if (!empty($_GET['action']) && $_GET['action'] == 'edit') {
            if (empty($_REQUEST['redirect_to'])) {
                $_REQUEST['redirect_to'] = em_add_get_params($_SERVER['REQUEST_URI'], array('action' => null, 'event_id' => null));
            }
            em_event_form();
        } else {
            if (get_option('dbem_css_editors')) {
                echo '<div class="css-events-admin">';
            }
            //template $args for different views
            $args_views['pending'] = array('status' => 0, 'owner' => get_current_user_id(), 'scope' => 'all', 'recurring' => 'include');
            $args_views['draft'] = array('status' => null, 'owner' => get_current_user_id(), 'scope' => 'all', 'recurring' => 'include');
            $args_views['past'] = array('status' => 'all', 'owner' => get_current_user_id(), 'scope' => 'past');
            $args_views['future'] = array('status' => '1', 'owner' => get_current_user_id(), 'scope' => 'future');
            //get listing options for $args
            $limit = !empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
            //Default limit
            $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
            $offset = $page > 1 ? ($page - 1) * $limit : 0;
            $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'ASC';
            $search = !empty($_REQUEST['em_search']) ? $_REQUEST['em_search'] : '';
            //deal with view or scope/status combinations
            $show_add_new = isset($args['show_add_new']) ? $args['show_add_new'] : true;
            $args = array('order' => $order, 'search' => $search, 'owner' => get_current_user_id());
            if (!empty($_REQUEST['view']) && in_array($_REQUEST['view'], array('future', 'draft', 'past', 'pending'))) {
                $args = array_merge($args, $args_views[$_REQUEST['view']]);
            } else {
                $scope_names = em_get_scopes();
                $args['scope'] = !empty($_REQUEST['scope']) && array_key_exists($_REQUEST['scope'], $scope_names) ? $_REQUEST['scope'] : 'future';
                if (array_key_exists('status', $_REQUEST)) {
                    $status = $_REQUEST['status'] ? 1 : 0;
                    if ($_REQUEST['status'] == 'all') {
                        $status = 'all';
                    }
                    if ($_REQUEST['status'] == 'draft') {
                        $status = null;
                    }
                } else {
                    $status = false;
                }
                $args['status'] = $status;
            }
            $events_count = EM_Events::count($args);
            //count events without limits for pagination
            $args['limit'] = $limit;
            $args['offset'] = $offset;
            $EM_Events = EM_Events::get($args);
            //now get the limited events to display
            $future_count = EM_Events::count($args_views['future']);
            $pending_count = EM_Events::count($args_views['pending']);
            $draft_count = EM_Events::count($args_views['draft']);
            $past_count = EM_Events::count($args_views['past']);
            em_locate_template('tables/events.php', true, array('args' => $args, 'EM_Events' => $EM_Events, 'events_count' => $events_count, 'future_count' => $future_count, 'pending_count' => $pending_count, 'draft_count' => $draft_count, 'past_count' => $past_count, 'page' => $page, 'limit' => $limit, 'offset' => $offset, 'show_add_new' => $show_add_new));
            if (get_option('dbem_css_editors')) {
                echo '</div>';
            }
        }
    } elseif (!is_user_logged_in() && get_option('dbem_events_anonymous_submissions')) {
        em_event_form($args);
    } else {
        if (get_option('dbem_css_editors')) {
            echo '<div class="css-events-admin">';
        }
        echo '<div class="css-events-admin-login">' . apply_filters('em_event_submission_login', __("You must log in to view and manage your events.", 'dbem')) . '</div>';
        if (get_option('dbem_css_editors')) {
            echo '</div>';
        }
    }
}
        } else {
            echo '<p>Registro no disponible</p>';
        }
        ?>
			</section><!-- end of active bookings -->

		<?php 
    } else {
        ?>

			<!-- event finished -->
			<section class="wrap wrap--content">
				<p>Evento finalizado</p>
			</section><!-- end of event finished -->

		<?php 
    }
    ?>
<!-- end of bookings form -->

	</div><!-- end of flexboxer -->

<?php 
} elseif (is_user_role('author') || is_user_role('editor') || is_user_role('administrator')) {
    echo '<div class="wrap--form js-showonload js-showonload-active">';
    em_event_form();
    echo '</div>';
} else {
    header('Location: ' . site_url() . '?action=nopermission');
}
get_footer();