/** * 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 = apply_filters('wpas_tickets_shortcode_query_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_get_notification_markup('info', __('You are being redirected...', 'awesome-support')); 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; }
/** * 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'); $args = wp_parse_args($args, $defaults); /** * 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', $args['form_class']); /** * wpas_ticket_details_reply_form_before hook * * @since 3.0.0 */ do_action('wpas_ticket_details_reply_form_before'); if ('closed' === $status) { echo wpas_get_notification_markup('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>.', 'awesome-support'), 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 $args['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 $args['container']; ?> id="<?php echo $args['container_id']; ?> " class="<?php echo $args['container_class']; ?> "> <?php echo $args['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' => $args['textarea_class'], '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.', 'awesome-support'); ?> " <?php if (false === $can_submit_empty) { ?> required="required"<?php } ?> ></textarea> <?php } echo $args['textarea_after']; ?> </<?php echo $args['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', 'awesome-support'); ?> "> <input type="checkbox" name="wpas_close_ticket" id="close_ticket" value="true"> <?php _e('Close this ticket', 'awesome-support'); ?> </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', 'awesome-support'), array('name' => 'wpas-submit', 'onsubmit' => __('Please Wait...', 'awesome-support'))); /** * 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()) { echo wpas_get_notification_markup('info', sprintf(__('To reply to this ticket, please <a href="%s">go to your admin panel</a>.', 'awesome-support'), add_query_arg(array('post' => $post_id, 'action' => 'edit'), admin_url('post.php')))); } else { echo wpas_get_notification_markup('info', __('You are not allowed to reply to this ticket.', 'awesome-support')); } /** * wpas_ticket_details_reply_form_after hook * * @since 3.0.0 */ do_action('wpas_ticket_details_reply_form_after'); }
/** * 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) . '" />'; echo wpas_get_notification_markup('info', __('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()) { echo wpas_get_notification_markup('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()) { echo wpas_get_notification_markup('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. */ echo wpas_get_notification_markup('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'); 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>'; } /** * 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; }
<tbody> <?php while ($wpas_tickets->have_posts()) { $wpas_tickets->the_post(); 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 wpas_make_button(__('Open a ticket', 'awesome-support'), array('type' => 'link', 'link' => wpas_get_submission_page_url(), 'class' => 'wpas-btn wpas-btn-default')); ?> </div> <?php } else { echo wpas_get_notification_markup('info', sprintf(__('You haven\'t submitted a ticket yet. <a href="%s">Click here to submit your first ticket</a>.', 'awesome-support'), wpas_get_submission_page_url())); }
/** * 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; // Custom Code By spgandhi@live.com if (isset($_GET['view'])) { $view = $_GET['view']; } else { $view = 'mine'; } // End - Custom Code by spgandhi@live.com $args = array('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); // Custom Code by spgandhi@live.com if ($view == 'mine') { $args['author'] = $author; } else { if ($view == 'hmc') { if (current_user_can('supervisor_view')) { echo '<h3>You will see all complains here.</h3>'; } else { if (current_user_can('hmc_view')) { $current_user_id = wp_get_current_user()->ID; $wing = get_user_meta($current_user_id, 'pie_dropdown_4', true); $room = get_user_meta($current_user_id, 'pie_number_5', true); $room_start = substr($room, 0, 1); $args['meta_query'] = array('relation' => 'AND', array('key' => '_wpas_wing', 'value' => $wing), array('key' => '_wpas_room_no', 'value' => array($room_start * 100, $room_start * 100 + 20), 'type' => 'numeric', 'compare' => 'BETWEEN')); echo '<h3>You will see all the complains of your floor here.</h3>'; $args['meta_key'] = '_wpas_wing'; $args['meta_value'] = $wing; } else { $args['author'] = $author; } } } else { $args['author'] = $author; } } // End - Custom code by spgandhi@live.com $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_get_notification_markup('info', __('You are being redirected...', 'awesome-support')); 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; }
do_action('wpas_before_login_form'); ?> <form class="wpas-form" id="wpas_form_login" method="post" role="form" action="<?php echo wpas_get_login_url(); ?> "> <h3><?php _e('Log in', 'awesome-support'); ?> </h3> <?php /* Registrations are not allowed. */ if ('disallow' === $registration) { echo wpas_get_notification_markup('failure', __('Registrations are currently not allowed.', 'awesome-support')); } $username = new WPAS_Custom_Field('log', array('name' => 'log', 'args' => array('required' => true, 'field_type' => 'text', 'label' => __('E-mail or username', 'awesome-support'), 'placeholder' => __('E-mail or username', 'awesome-support'), 'sanitize' => 'sanitize_text_field'))); echo $username->get_output(); $password = new WPAS_Custom_Field('pwd', array('name' => 'pwd', 'args' => array('required' => true, 'field_type' => 'password', 'label' => __('Password', 'awesome-support'), 'placeholder' => __('Password', 'awesome-support'), 'sanitize' => 'sanitize_text_field'))); echo $password->get_output(); /** * wpas_after_login_fields hook */ do_action('wpas_after_login_fields'); $rememberme = new WPAS_Custom_Field('rememberme', array('name' => 'rememberme', 'args' => array('required' => true, 'field_type' => 'checkbox', 'sanitize' => 'sanitize_text_field', 'options' => array('1' => __('Remember Me', 'awesome-support'))))); echo $rememberme->get_output(); wpas_do_field('login', $redirect_to); wpas_make_button(__('Log in'), array('onsubmit' => __('Logging In...', 'awesome-support'))); printf('<a href="%1$s" class="wpas-forgot-password-link">%2$s</a>', wp_lostpassword_url(wpas_get_tickets_list_page_url()), esc_html__('Forgot password?', 'awesome-support')); ?>
/** * Get all notifications in a human readable format * * @since 3.2 * * @param string $group Group of notifications to lookup * @param string $type Type of markup to use * * @return string */ function wpas_get_display_notifications($group = 'notifications', $type = 'success') { $notifications = wpas_get_notifications($group); $text = ''; if (!is_array($notifications)) { $text = $notifications; } else { if (count($notifications) >= 2) { $messages = array(); foreach ($notifications as $id => $message) { array_push($messages, wpas_readable_notification_message($message)); } $text = implode('<br>', $messages); } else { foreach ($notifications as $id => $message) { $text = wpas_readable_notification_message($message); } } } return wpas_get_notification_markup($type, $text); }
do_action('wpas_before_login_form'); ?> <form class="wpas-form" id="wpas_form_login" method="post" role="form" action="<?php echo wpas_get_login_url(); ?> "> <h3><?php _e('Log in', 'wpas'); ?> </h3> <?php /* Registrations are not allowed. */ if ('disallow' === $registration) { echo wpas_get_notification_markup('failure', __('Registrations are currently not allowed.', 'wpas')); } $username = new WPAS_Custom_Field('log', array('name' => 'log', 'args' => array('required' => true, 'field_type' => 'text', 'label' => __('E-mail or username', 'wpas'), 'placeholder' => __('E-mail or username', 'wpas'), 'sanitize' => 'sanitize_text_field'))); echo $username->get_output(); $password = new WPAS_Custom_Field('pwd', array('name' => 'pwd', 'args' => array('required' => true, 'field_type' => 'password', 'label' => __('Password', 'wpas'), 'placeholder' => __('Password', 'wpas'), 'sanitize' => 'sanitize_text_field'))); echo $password->get_output(); /** * wpas_after_login_fields hook */ do_action('wpas_after_login_fields'); $rememberme = new WPAS_Custom_Field('rememberme', array('name' => 'rememberme', 'args' => array('required' => true, 'field_type' => 'checkbox', 'sanitize' => 'sanitize_text_field', 'options' => array('1' => __('Remember Me', 'wpas'))))); echo $rememberme->get_output(); ?> <input type="hidden" name="redirect_to" value="<?php echo $redirect_to;