<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
ob_start();
$pid     = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : '';
$pauthor = isset( $_GET['wsdesk_author'] ) ? sanitize_text_field( $_GET['wsdesk_author'] ) : '';
$ticket  = eh_crm_get_ticket( array( 'ticket_id' => $pid ) );
?>
<center>
	<div class="satisfaction-div wsdesk_wrapper">
		<?php
		if ( $ticket ) {
			$gstatus = eh_crm_get_ticketmeta( $ticket[0]['ticket_id'], 'ticket_rating' );
			if ( ! $gstatus ) {
				if ( $ticket[0]['ticket_email'] === $pauthor ) {
					  $ticket_title = eh_crm_wpml_translations( $ticket[0]['ticket_title'], 'ticket_title', 'ticket_title' );
					  echo '<h3>' . esc_html__( 'How is our Support?', 'wsdesk' ) . '</h3>';
					  echo '<h4><u>Ticket (#' . esc_html( $pid ) . ') : [ ' . esc_html( $ticket_title ) . ' ]</u></h4>';
					?>
						<input type="hidden" id="satisfaction_id" value="<?php echo esc_html( $pid ); ?>">
						<input type="hidden" id="satisfaction_author" value="<?php echo esc_html( $pauthor ); ?>">
						<table class="satisfaction-thumbs">
							<tr>
								<td style="width: 50%;text-align: center;">
									<div style="margin-right: 10px;">
										<input id="satisfaction-good" name="satisfaction-thumb" checked type="radio" class="glyphicon with-font with-good glyphicon-thumbs-up" value="good" />
										<label for="satisfaction-good" class="satisfaction-label"><?php esc_html_e( 'Good !', 'wsdesk' ); ?></label>
									</div>
								</td>
								<td style="width: 50%;text-align: center;">
									<div style="margin-left: 10px;">
										<input id="satisfaction-bad" name="satisfaction-thumb" type="radio" class="glyphicon with-font with-bad glyphicon-thumbs-up" value="bad"/>
										<label for="satisfaction-bad" class="satisfaction-label"><?php esc_html_e( 'Bad !', 'wsdesk' ); ?></label>
									</div>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<textarea rows="5" style="width: 100%" id="satisfaction_comment"></textarea>
								</td>
							</tr>
							<tr>
								<td colspan="2" style="text-align: center">
									<button class="btn btn-primary" id="submit_satisfaction" data-loading-text="<?php esc_html_e( 'Submitting...', 'wsdesk' ); ?>"><?php esc_html_e( 'Submit', 'wsdesk' ); ?></button>
								</td>
							</tr>
						</table>
					<?php
				} else {
					?>
						<h1><?php esc_html_e( 'Oops!', 'wsdesk' ); ?></h1><h4><?php esc_html_e( 'Unauthorized Access!', 'wsdesk' ); ?></h4>
					<?php
				}
			} else {
				if ( $ticket[0]['ticket_email'] === $pauthor ) {
					?>
						<h1><?php esc_html_e( 'Thank you', 'wsdesk' ); ?></h1><p><?php esc_html_e( 'Already took Satisfaction Survey for the ticket', 'wsdesk' ); ?>( #<?php echo esc_html( $pid ); ?> )</p>
					<?php
				} else {
					?>
						<h1><?php esc_html_e( 'Oops!', 'wsdesk' ); ?></h1><h4><?php esc_html_e( 'Unauthorized Access!', 'wsdesk' ); ?></h4>
					<?php
				}
			}
		} else {
			?>
				<h1><?php esc_html_e( 'Oops!', 'wsdesk' ); ?></h1><h4><?php esc_html_e( 'Access Denied!', 'wsdesk' ); ?></h4>
			<?php
		}
		?>
		<br>
		<?php
		if ( ! defined( 'WSDESK_POWERED_SUPPORT' ) ) {
			echo '<div class="powered_wsdesk"><span>' . esc_html__( 'Powered by', 'wsdesk' ) . '</span> <a href="https://elextensions.com/plugin/wsdesk-wordpress-support-desk-plugin/" target="_blank" rel="nofollow">WSDesk</a></div>';
		}
		?>
	</div>
</center>
<?php
return ob_get_clean();
