return;
        }
        if (isset($_GET['action']) && 'upgrade-plugin' == $_GET['action'] && (isset($_GET['plugin']) && strstr($_GET['plugin'], 'gam-event-manager.php'))) {
            return;
        }
        wp_redirect(admin_url('index.php?page=event-manager-setup'));
        exit;
    }
    /**
	 * Enqueue scripts for setup page
	 */
    public function admin_enqueue_scripts()
    {
        wp_enqueue_style('event_manager_setup_css', EVENT_MANAGER_PLUGIN_URL . '/assets/css/setup.css', array('dashicons'));
    }
    /**
	 * Create a page.
	 * @param  string $title
	 * @param  string $content
	 * @param  string $option
	 */
    public function create_page($title, $content, $option)
    {
        $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => sanitize_title($title), 'post_title' => $title, 'post_content' => $content, 'post_parent' => 0, 'comment_status' => 'closed');
        $page_id = wp_insert_post($page_data);
        if ($option) {
            update_option($option, $page_id);
        }
    }
    /**
	 * Output addons page
	 */
    public function output()
    {
        $step = !empty($_GET['step']) ? absint($_GET['step']) : 1;
        if (3 === $step && !empty($_POST)) {
            $create_pages = isset($_POST['gam-event-manager-create-page']) ? $_POST['gam-event-manager-create-page'] : array();
            $page_titles = $_POST['gam-event-manager-page-title'];
            $pages_to_create = array('submit_event_form' => '[submit_event_form]', 'event_dashboard' => '[event_dashboard]', 'events' => '[events]');
            foreach ($pages_to_create as $page => $content) {
                if (!isset($create_pages[$page]) || empty($page_titles[$page])) {
                    continue;
                }
                $this->create_page(sanitize_text_field($page_titles[$page]), $content, 'event_manager_' . $page . '_page_id');
            }
        }
        ?>

		<div class="wrap wp_event_manager wp_event_manager_addons_wrap">
		
			<h2><?php 
        _e('GAM Event Manager Setup', 'gam-event-manager');
        ?>
</h2>
			<ul class="gam-event-manager-setup-steps">
				<li class="<?php 
        if ($step === 1) {
            echo 'gam-event-manager-setup-active-step';
        }
        ?>
"><?php 
        _e('1. Introduction', 'gam-event-manager');
        ?>
</li>
				<li class="<?php 
        if ($step === 2) {
            echo 'gam-event-manager-setup-active-step';
        }
        ?>
"><?php 
        _e('2. Page Setup', 'gam-event-manager');
        ?>
</li>
				<li class="<?php 
        if ($step === 3) {
            echo 'gam-event-manager-setup-active-step';
        }
        ?>
"><?php 
        _e('3. Done', 'gam-event-manager');
        ?>
</li>
			</ul>
			<?php 
        if (1 === $step) {
            ?>

				<h3><?php 
            _e('Setup Wizard Introduction', 'gam-event-manager');
            ?>
</h3>
				<p><?php 
            _e('Thanks for installing <em>GAM Event Manager</em>!', 'gam-event-manager');
            ?>
</p>
				<p><?php 
            _e('This setup wizard will help you get started by creating the pages for event submission, event management, and listing your events.', 'gam-event-manager');
            ?>
</p>
				<p><?php 
            printf(__('If you want to skip the wizard and setup the pages and shortcodes yourself manually, the process is still relatively simple. Refer to the %sdocumentation%s for help.', 'gam-event-manager'), '<a href="https://gamthemes.com/documentation/">', '</a>');
            ?>
</p>
				<p class="submit">
					<a href="<?php 
            echo esc_url(add_query_arg('step', 2));
            ?>
" class="button button-primary"><?php 
            _e('Continue to page setup', 'gam-event-manager');
            ?>
</a>
					<a href="<?php 
            echo esc_url(add_query_arg('skip-event-manager-setup', 1, admin_url('index.php?page=event-manager-setup&step=3')));
            ?>
" class="button"><?php 
            _e('Skip setup. I will setup the plugin manually', 'gam-event-manager');
            ?>
</a>
				</p>
				
			<?php 
        }
        ?>

			<?php 
        if (2 === $step) {
            ?>

				<h3><?php 
            _e('Page Setup', 'gam-event-manager');
            ?>
</h3>
				<p><?php 
            printf(__('<em>GAM Event Manager</em> includes %1$sshortcodes%2$s which can be used within your %3$spages%2$s to output content. These can be created for you below. For more information on the event shortcodes view the %4$sshortcode documentation%2$s.', 'gam-event-manager'), '<a href="http://codex.wordpress.org/Shortcode" title="What is a shortcode?" target="_blank" class="help-page-link">', '</a>', '<a href="http://codex.wordpress.org/Pages" target="_blank" class="help-page-link">', '<a href="https://gamthemes.com/document/shortcode-reference/" target="_blank" class="help-page-link">');
            ?>
</p>
				<form action="<?php 
            echo esc_url(add_query_arg('step', 3));
            ?>
" method="post">
					<table class="gam-event-manager-shortcodes widefat">
					
						<thead>
						
							<tr>		
								<th>&nbsp;</th>
								<th><?php 
            _e('Page Title', 'gam-event-manager');
            ?>
</th>
								<th><?php 
            _e('Page Description', 'gam-event-manager');
            ?>
</th>
								<th><?php 
            _e('Content Shortcode', 'gam-event-manager');
            ?>
</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td><input type="checkbox" checked="checked" name="gam-event-manager-create-page[submit_event_form]" /></td>
								<td><input type="text" value="<?php 
            echo esc_attr(_x('Post a Event', 'Default page title (wizard)', 'gam-event-manager'));
            ?>
" name="gam-event-manager-page-title[submit_event_form]" /></td>
								<td>
									<p><?php 
            _e('This page allows peoples to post events to your website from the front-end.', 'gam-event-manager');
            ?>
</p>
									<p><?php 
            _e('If you do not want to accept submissions from users in this way (for example you just want to post events from the admin dashboard) you can skip creating this page.', 'gam-event-manager');
            ?>
</p>
								</td>
								<td><code>[submit_event_form]</code></td>
							</tr>
							<tr>
								<td><input type="checkbox" checked="checked" name="gam-event-manager-create-page[event_dashboard]" /></td>
								<td><input type="text" value="<?php 
            echo esc_attr(_x('Event Dashboard', 'Default page title (wizard)', 'gam-event-manager'));
            ?>
" name="gam-event-manager-page-title[event_dashboard]" /></td>
								<td>
									<p><?php 
            _e('This page allows peoples to manage and edit their own events from the front-end.', 'gam-event-manager');
            ?>
</p>
									<p><?php 
            _e('If you plan on managing all listings from the admin dashboard you can skip creating this page.', 'gam-event-manager');
            ?>
</p>
								</td>
								
								<td><code>[event_dashboard]</code></td>
							</tr>
							
							<tr>
								<td><input type="checkbox" checked="checked" name="gam-event-manager-create-page[events]" /></td>
								<td><input type="text" value="<?php 
            echo esc_attr(_x('Events', 'Default page title (wizard)', 'gam-event-manager'));
            ?>
" name="gam-event-manager-page-title[events]" /></td>
								<td><?php 
            _e('This page allows users to browse, search, and filter event listings on the front-end of your site.', 'gam-event-manager');
            ?>
</td>
								<td><code>[events]</code></td>
							</tr>
						</tbody>
						<tfoot>
							<tr>
								<th colspan="4">
									<input type="submit" class="button button-primary" value="Create selected pages" />
									<a href="<?php 
            echo esc_url(add_query_arg('step', 3));
            ?>
" class="button"><?php 
            _e('Skip this step', 'gam-event-manager');
            ?>
</a>
								</th>
							</tr>
						</tfoot>
					</table>
				</form>
            } elseif ('event_action' === $key) {
                ?>
                                        <ul class="event-dashboard-actions" >
										<?php 
                $actions = array();
                switch ($event->post_status) {
                    case 'publish':
                        $actions['edit'] = array('label' => __('Edit', 'wp-event-manager'), 'nonce' => false);
                        if (is_event_cancelled($event)) {
                            $actions['mark_not_cancelled'] = array('label' => __('Mark not cancelled', 'wp-event-manager'), 'nonce' => true);
                        } else {
                            $actions['mark_cancelled'] = array('label' => __('Mark cancelled', 'wp-event-manager'), 'nonce' => true);
                        }
                        break;
                    case 'expired':
                        if (event_manager_get_permalink('submit_event_form')) {
                            $actions['relist'] = array('label' => __('Relist', 'wp-event-manager'), 'nonce' => true);
                        }
                        break;
                    case 'pending_payment':
                    case 'pending':
                        if (event_manager_user_can_edit_pending_submissions()) {
                            $actions['edit'] = array('label' => __('Edit', 'wp-event-manager'), 'nonce' => false);
                        }
                        break;
                }
                $actions['delete'] = array('label' => __('Delete', 'wp-event-manager'), 'nonce' => true);
                $actions = apply_filters('event_manager_my_event_actions', $actions, $event);
                foreach ($actions as $action => $value) {
                    $action_url = add_query_arg(array('action' => $action, 'event_id' => $event->ID));
                    if ($value['nonce']) {
 /**
  * Handles actions on event dashboard
  */
 public function event_dashboard_handler()
 {
     if (!empty($_REQUEST['action']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_manager_my_event_actions')) {
         $action = sanitize_title($_REQUEST['action']);
         $event_id = absint($_REQUEST['event_id']);
         try {
             // Get Event
             $event = get_post($event_id);
             // Check ownership
             if (!event_manager_user_can_edit_event($event_id)) {
                 throw new Exception(__('Invalid ID', 'gam-event-manager'));
             }
             switch ($action) {
                 case 'mark_cancelled':
                     // Check status
                     if ($event->_cancelled == 1) {
                         throw new Exception(__('This event has already been cancelled', 'gam-event-manager'));
                     }
                     // Update
                     update_post_meta($event_id, '_cancelled', 1);
                     // Message
                     $this->event_dashboard_message = '<div class="event-manager-message">' . sprintf(__('%s has been cancelled', 'gam-event-manager'), $event->post_title) . '</div>';
                     break;
                 case 'mark_not_cancelled':
                     // Check status
                     if ($event->_cancelled != 1) {
                         throw new Exception(__('This event is not cancelled', 'gam-event-manager'));
                     }
                     // Update
                     update_post_meta($event_id, '_cancelled', 0);
                     // Message
                     $this->event_dashboard_message = '<div class="event-manager-message">' . sprintf(__('%s has been marked as not cancelled', 'gam-event-manager'), $event->post_title) . '</div>';
                     break;
                 case 'delete':
                     // Trash it
                     wp_trash_post($event_id);
                     // Message
                     $this->event_dashboard_message = '<div class="event-manager-message">' . sprintf(__('%s has been deleted', 'gam-event-manager'), $event->post_title) . '</div>';
                     break;
                 case 'relist':
                     // redirect to post page
                     wp_redirect(add_query_arg(array('event_id' => absint($event_id)), event_manager_get_permalink('submit_event_form')));
                     break;
                 default:
                     do_action('event_manager_event_dashboard_do_action_' . $action);
                     break;
             }
             do_action('event_manager_my_event_do_action', $action, $event_id);
         } catch (Exception $e) {
             $this->event_dashboard_message = '<div class="event-manager-error">' . $e->getMessage() . '</div>';
         }
     }
 }