/**
 * Registration page shortcode.
 */
function wpas_sc_client_account()
{
    global $wpas_tickets, $current_user, $post;
    /**
     * For some reason when the user ID is set to 0
     * the query returns posts whose author has ID 1.
     * In order to avoid that (for non logged users)
     * we set the user ID to -1 if it is 0.
     * 
     * @var integer
     */
    $author = 0 !== $current_user->ID ? $current_user->ID : -1;
    $args = array('author' => $author, 'post_type' => 'ticket', 'post_status' => 'any', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => -1, 'no_found_rows' => false, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false);
    $wpas_tickets = new WP_Query($args);
    /* Get the ticket content */
    ob_start();
    /**
     * wpas_frontend_plugin_page_top is executed at the top
     * of every plugin page on the front end.
     */
    do_action('wpas_frontend_plugin_page_top', $post->ID, $post);
    /**
     * wpas_before_tickets_list hook
     */
    do_action('wpas_before_tickets_list');
    /* If user is not logged in we display the register form */
    if (!is_user_logged_in()) {
        $registration = wpas_get_option('login_page', false);
        if (false !== $registration && !empty($registration) && !is_null(get_post(intval($registration)))) {
            /* As the headers are already sent we can't use wp_redirect. */
            echo '<meta http-equiv="refresh" content="0; url=' . get_permalink($registration) . '" />';
            wpas_notification(false, __('You are being redirected...', 'wpas'));
            exit;
        }
        wpas_get_template('registration');
    } else {
        /**
         * Get the custom template.
         */
        wpas_get_template('list');
    }
    /**
     * wpas_after_tickets_list hook
     */
    do_action('wpas_after_tickets_list');
    /**
     * Finally get the buffer content and return.
     * 
     * @var string
     */
    $content = ob_get_clean();
    return $content;
}
 /**
  * Shows notifications at the top of any template file.
  *
  * @since 3.1.11
  * @return boolean True if a notification was found, false otherwise
  */
 public function trigger_templates_notifications()
 {
     /**
      * Display possible messages to the visitor.
      */
     if (!isset($_GET['message'])) {
         return false;
     }
     if (is_numeric($_GET['message'])) {
         wpas_notification(false, filter_input(INPUT_GET, 'message', FILTER_SANITIZE_NUMBER_INT));
     } else {
         wpas_notification('decode', filter_input(INPUT_GET, 'message', FILTER_SANITIZE_STRING), true);
     }
     return true;
 }
/**
 * Display the reply form.
 *
 * @since  3.0.0
 * @param  array  $args Additional arguments
 * @return void
 */
function wpas_get_reply_form($args = array())
{
    global $wp_query;
    $post_id = $wp_query->post->ID;
    $status = wpas_get_ticket_status($post_id);
    $defaults = array('form_id' => 'wpas-new-reply', 'form_class' => 'wpas-form', 'container' => 'div', 'container_id' => 'wpas-reply-box', 'container_class' => 'wpas-form-group wpas-wysiwyg-textarea', 'textarea_before' => '', 'textarea_after' => '', 'textarea_class' => 'wpas-form-control wpas-wysiwyg');
    extract(shortcode_atts($defaults, $args));
    /**
     * Filter the form class.
     *
     * This can be useful for addons doing something on the reply form,
     * like adding an upload feature for instance.
     *
     * @since  3.0.0
     * @var    string
     */
    $form_class = apply_filters('wpas_frontend_reply_form_class', $form_class);
    /**
     * wpas_ticket_details_reply_form_before hook
     *
     * @since  3.0.0
     */
    do_action('wpas_ticket_details_reply_form_before');
    if ('closed' === $status) {
        wpas_notification('info', sprintf(__('The ticket has been closed. If you feel that your issue has not been solved yet or something new came up in relation to this ticket, <a href="%s">you can re-open it by clicking this link</a>.', 'wpas'), wpas_get_reopen_url()));
        /**
         * Check if the ticket is currently open and if the current user
         * is allowed to post a reply.
         */
    } elseif ('open' === $status && true === wpas_can_reply_ticket()) {
        ?>

		<form id="<?php 
        echo $form_id;
        ?>
" class="<?php 
        echo $form_class;
        ?>
" method="post" action="<?php 
        echo get_permalink($post_id);
        ?>
" enctype="multipart/form-data">

			<?php 
        /**
         * wpas_ticket_details_reply_textarea_before hook
         *
         * @since  3.0.0
         */
        do_action('wpas_ticket_details_reply_textarea_before');
        ?>

			<<?php 
        echo $container;
        ?>
 id="<?php 
        echo $container_id;
        ?>
" class="<?php 
        echo $container_class;
        ?>
">
				<?php 
        echo $textarea_before;
        /**
         * Load the visual editor if enabled
         */
        if (true === boolval(wpas_get_option('frontend_wysiwyg_editor'))) {
            $editor_defaults = apply_filters('wpas_ticket_editor_args', array('media_buttons' => false, 'textarea_name' => 'wpas_user_reply', 'textarea_rows' => 10, 'tabindex' => 2, 'editor_class' => wpas_get_field_class('wpas_reply', $textarea_class, false), 'quicktags' => false, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,hr,|,bullist,numlist,|,link,unlink', 'toolbar2' => '')));
            wp_editor('', 'wpas-reply-wysiwyg', apply_filters('wpas_reply_wysiwyg_args', $editor_defaults));
        } else {
            /**
             * Define if the reply can be submitted empty or not.
             *
             * @since  3.0.0
             * @var boolean
             */
            $can_submit_empty = apply_filters('wpas_can_reply_be_empty', false);
            ?>
						<textarea class="form-control" rows="10" name="wpas_user_reply" rows="6" id="wpas-reply-textarea" placeholder="<?php 
            _e('Type your reply here.', 'wpas');
            ?>
" <?php 
            if (false === $can_submit_empty) {
                ?>
required="required"<?php 
            }
            ?>
></textarea>
					<?php 
        }
        echo $textarea_after;
        ?>
			</<?php 
        echo $container;
        ?>
>

			<?php 
        /**
         * wpas_ticket_details_reply_textarea_after hook
         *
         * @since  3.0.0
         */
        do_action('wpas_ticket_details_reply_textarea_after');
        if (current_user_can('close_ticket')) {
            ?>

				<div class="checkbox">
					<label for="close_ticket" data-toggle="tooltip" data-placement="right" title="" data-original-title="<?php 
            _e('No reply is required to close', 'wpas');
            ?>
">
						<input type="checkbox" name="wpas_close_ticket" id="close_ticket" value="true"> <?php 
            _e('Close this ticket', 'wpas');
            ?>
					</label>
				</div>

			<?php 
        }
        /**
         * wpas_ticket_details_reply_close_checkbox_after hook
         *
         * @since  3.0.0
         */
        do_action('wpas_ticket_details_reply_close_checkbox_after');
        ?>

			<input type="hidden" name="ticket_id" value="<?php 
        echo $post_id;
        ?>
" />

			<?php 
        wp_nonce_field('send_reply', 'client_reply', false, true);
        wpas_make_button(__('Reply', 'wpas'), array('name' => 'wpas-submit', 'onsubmit' => __('Please Wait...', 'wpas')));
        /**
         * wpas_ticket_details_reply_close_checkbox_after hook
         *
         * @since  3.0.0
         */
        do_action('wpas_ticket_details_reply_form_before_close');
        ?>

		</form>

	<?php 
        /**
         * This case is an agent viewing the ticket from the front-end. All actions are tracked in the back-end only, that's why we prevent agents from replying through the front-end.
         */
    } elseif ('open' === $status && false === wpas_can_reply_ticket()) {
        wpas_notification('info', sprintf(__('To reply to this ticket, please <a href="%s">go to your admin panel</a>.', 'wpas'), add_query_arg(array('post' => $post_id, 'action' => 'edit'), admin_url('post.php'))));
    } else {
        wpas_notification('info', __('You are not allowed to reply to this ticket.', 'wpas'));
    }
    /**
     * wpas_ticket_details_reply_form_after hook
     *
     * @since  3.0.0
     */
    do_action('wpas_ticket_details_reply_form_after');
}
Exemplo n.º 4
0
?>
">

	<form class="wpas-form" method="post" role="form" action="<?php 
echo wpas_get_login_url();
?>
">
		<h3><?php 
_e('Log in');
?>
</h3>

		<?php 
/* Registrations are not allowed. */
if (false === $registration) {
    wpas_notification('failure', __('Registrations are currently not allowed.', 'wpas'));
}
?>
		
		<div <?php 
wpas_get_field_container_class('log');
?>
>			
			<label><?php 
_e('E-mail or username', 'wpas');
?>
</label>
			<input type="text" name="log" <?php 
wpas_get_field_class('log');
?>
 placeholder="<?php 
/**
 * Submission for shortcode.
 */
function wpas_sc_submit_form()
{
    global $post;
    /* Start the buffer */
    ob_start();
    /* Open main container */
    ?>
<div class="wpas"><?php 
    /**
     * wpas_before_ticket_submit hook
     */
    do_action('wpas_before_ticket_submit');
    /**
     * wpas_frontend_plugin_page_top is executed at the top
     * of every plugin page on the front end.
     */
    do_action('wpas_frontend_plugin_page_top', $post->ID, $post);
    /* If user is not logged in we display the register form */
    if (!is_user_logged_in()) {
        $registration = wpas_get_option('login_page', false);
        if (false !== $registration && !empty($registration) && !is_null(get_post(intval($registration)))) {
            /* As the headers are already sent we can't use wp_redirect. */
            echo '<meta http-equiv="refresh" content="0; url=' . get_permalink($registration) . '" />';
            wpas_notification(false, __('You are being redirected...', 'wpas'));
            exit;
        }
        wpas_get_template('registration');
        /**
         * If user is logged in we display the ticket submission form
         */
    } else {
        /**
         * wpas_before_ticket_submission_form hook
         */
        do_action('wpas_before_ticket_submission_form_before_wrapper');
        /* Namespace our content */
        echo '<div class="wpas">';
        /**
         * wpas_before_all_templates hook.
         *
         * This hook is called at the top of every template
         * used for the plugin front-end. This allows for adding actions
         * (like notifications for instance) on all plugin related pages.
         */
        do_action('wpas_before_all_templates');
        /**
         * wpas_before_ticket_submission_form hook
         */
        do_action('wpas_before_ticket_submission_form');
        /**
         * Check if the current user is logged in
         */
        if (false === is_user_logged_in()) {
            wpas_notification('failure', sprintf(__('You need to <a href="%s">log-in</a> to submit a ticket.', 'wpas'), esc_url('')));
        } else {
            /**
             * Make sure the current user can submit a ticket.
             */
            if (false === wpas_can_submit_ticket($post->ID)) {
                wpas_notification('failure', __('You are not allowed to submit a ticket.', 'wpas'));
            } else {
                /**
                 * We check if the user is authorized to submit a ticket.
                 * User must be logged-in and can't have the capability. If the
                 * user isn't authorized to submit, we return the error message hereafter.
                 *
                 * Basically, admins and agents aren't allowed to submit a ticket as they
                 * need to do it in the back-end.
                 *
                 * If you want to allow admins and agents to submit tickets through the
                 * front-end, please use the filter wpas_agent_submit_front_end and set the value to (bool) true.
                 */
                if (is_user_logged_in() && current_user_can('edit_ticket') && false === apply_filters('wpas_agent_submit_front_end', false)) {
                    /**
                     * Keep in mind that if you allow agents to open ticket through the front-end, actions
                     * will not be tracked.
                     */
                    wpas_notification('info', sprintf(__('Sorry, support team members cannot submit tickets from here. If you need to open a ticket, please go to your admin panel or <a href="%s">click here to open a new ticket</a>.', 'wpas'), add_query_arg(array('post_type' => 'ticket'), admin_url('post-new.php'))));
                    /**
                     * If the user is authorized to post a ticket, we display the submit form
                     */
                } else {
                    global $post;
                    /**
                     * wpas_submission_form_before hook
                     *
                     * @since  3.0.0
                     */
                    do_action('wpas_submission_form_before');
                    if (isset($_GET['message'])) {
                        /* This seems to be a predefined error message. */
                        if (is_numeric($_GET['message'])) {
                            wpas_notification(false, $_GET['message']);
                        } else {
                            $messages = json_decode(base64_decode((string) $_GET['message']));
                            $contents = '';
                            if (is_array($messages) && count($messages) > 1) {
                                $contents = '<ul>';
                                foreach ($messages as $message) {
                                    $contents .= "<li>{$message}</li>";
                                }
                                $contents .= '</ul>';
                            } elseif (is_array($messages)) {
                                $contents = $messages[0];
                            }
                            wpas_notification('failure', $contents);
                        }
                    }
                    wpas_get_template('submission');
                    /**
                     * wpas_submission_form_after hook
                     *
                     * @since  3.0.0
                     */
                    do_action('wpas_submission_form_after');
                }
            }
        }
        /**
         * wpas_after_ticket_submission_form hook
         */
        do_action('wpas_after_ticket_submission_form');
        echo '</div>';
        if (isset($_SESSION['formtmp'])) {
            unset($_SESSION['formtmp']);
        }
    }
    /**
     * wpas_after_ticket_submit hook
     */
    do_action('wpas_after_ticket_submit');
    ?>

	</div>

	<?php 
    /* Get buffer content */
    $sc = ob_get_contents();
    /* Clean the buffer */
    ob_end_clean();
    /* Return shortcode's content */
    return $sc;
}
Exemplo n.º 6
0
        echo '<tr>';
        foreach ($columns as $column_id => $column) {
            echo '<td';
            /* If current column is the date we add the date attribute for sorting purpose */
            if ('date' === $column_id) {
                echo ' data-order="' . strtotime(get_the_time()) . '"';
            }
            /* We don't forget to close the <td> tag */
            echo '>';
            /* Display the content for this column */
            wpas_get_tickets_list_column_content($column_id, $column);
            echo '</td>';
        }
        echo '</tr>';
    }
    wp_reset_query();
    ?>
            </tbody>
        </table>
        <?php 
    echo paginate_links(array('base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $wpas_tickets->max_num_pages));
    ?>

        <?php 
    wpas_make_button(__('Open a ticket', 'wpas'), array('type' => 'link', 'link' => esc_url(get_permalink(wpas_get_option('ticket_submit'))), 'class' => 'wpas-btn wpas-btn-default'));
    ?>
    </div>
<?php 
} else {
    wpas_notification('info', sprintf(__('You haven\'t submitted a ticket yet. <a href="%s">Click here to submit your first ticket</a>.', 'wpas'), esc_url(get_permalink(wpas_get_option('ticket_submit')))));
}
 /**
  * Shows notifications at the top of any template file.
  *
  * @since 3.1.11
  * @return boolean True if a notification was found, false otherwise
  */
 public function trigger_templates_notifications()
 {
     /**
      * Display possible messages to the visitor.
      */
     if (!isset($_GET['message'])) {
         return false;
     }
     if (is_numeric($_GET['message'])) {
         wpas_notification(false, $_GET['message']);
     } else {
         wpas_notification('decode', $_GET['message']);
     }
     return true;
 }