<?php 
/** 
 * @package JCHAT::LAMESSAGES::administrator::components::com_jchat
 * @subpackage views
 * @subpackage lamessages
 * @subpackage tmpl
 * @author Joomla! Extensions Store
 * @Copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html 
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Factory;
?>
<form action="<?php echo Route::_('index.php?option=com_jchat&view=lamessages'); ?>" method="post" class="jes jesform editform" name="adminForm" id="adminForm">
	<div class="btn-toolbar well" id="toolbar">
		<div class="btn-wrapper pull-left" id="toolbar-buttons">
			<button onclick="jQuery.submitbutton('lamessages.applyEntity')" class="btn btn-primary btn-sm">
				<span class="glyphicon glyphicon-edit"></span> <?php echo Text::_('COM_JCHAT_SAVE');?>
			</button>
			
			<button onclick="jQuery.submitbutton('lamessages.saveEntity')" class="btn btn-primary btn-sm">
				<span class="glyphicon glyphicon-edit"></span> <?php echo Text::_('COM_JCHAT_SAVE_CLOSE');?>
			</button>
			
			<button onclick="jQuery.submitbutton('lamessages.responseMessage')" class="btn btn-primary btn-sm">
				<span class="glyphicon glyphicon-remove"></span> <?php echo Text::_('COM_JCHAT_RESPONSE_LEAVED_MESSAGES');?>
			</button>
			
			<button onclick="jQuery.submitbutton('lamessages.cancelEntity')" class="btn btn-primary btn-sm">
				<span class="glyphicon glyphicon-download-alt"></span> <?php echo Text::_('COM_JCHAT_CANCEL');?>
			</button>
		</div>
	</div>
	
	<div class="accordion-group">
		<div class="accordion-heading opened">
			<div class="accordion-toggle noaccordion">
				<h4><span class="glyphicon glyphicon-edit"></span> <?php echo Text::_( 'COM_JCHAT_TICKET_DETAILS' ); ?></h4>
			</div>
		</div>
		<div id="details" class="accordion-body">
	      	<div class="accordion-inner">
				<table class="sitetable">
				<tbody>
					<tr>
						<td width="20%" class="left_title"> 
							<?php echo Text::_( 'ID' ); ?>: 
						</td>
						<td width="80%" class="right_details">
							<label class="label label-info">
								<?php echo $this->record->id;?> 
							</label>
						</td>
					</tr>
					<tr>
						<td width="20%" class="left_title"> 
							<?php echo Text::_( 'COM_JCHAT_LAMESSAGE_NAME' ); ?>: 
						</td>
						<td width="80%" class="right_details">
					 		<input class="inputbox" type="text" name="name" id="name" data-validation="required" aria-required="true" size="50" value="<?php echo $this->record->name;?>" />
						</td>
					</tr>
					<tr>
						<td class="left_title"> 
							<?php echo Text::_( 'COM_JCHAT_LAMESSAGE_EMAIL' ); ?>:  
						</td>
						<td class="right_details">
							<input class="inputbox" type="text" name="email" id="email" data-validation="required email" size="50" value="<?php echo $this->record->email;?>" />
						</td>
					</tr>
					<?php if($this->phoneNumberEnabled):?>
					<tr>
						<td class="left_title"> 
							<?php echo Text::_( 'COM_JCHAT_LAMESSAGE_PHONENUMBER' ); ?>:  
						</td>
						<td class="right_details">
							<input class="inputbox" type="text" name="phonenumber" id="phonenumber" size="50" value="<?php echo $this->record->phonenumber;?>" />
						</td>
					</tr>
					<?php endif;?>
					<tr>
						<td class="left_title">
							<?php echo Text::_( 'COM_JCHAT_MESSAGE' ); ?>:
						</td>
						<td class="right_details">
							<textarea class="inputbox" type="text" name="message" id="message" rows="5" cols="80" ><?php echo $this->record->message;?></textarea>
						</td>
					</tr>
					<tr>
						<td class="left_title">
							<?php echo Text::_( 'COM_JCHAT_SENT' ); ?>:
						</td>
						<td class="right_details">
							<div class="input-prepend active">
								<span class="add-on"><span class="icon-calendar" aria-hidden="true"></span></span>
								<input class="inputbox" type="text" name="sentdate" id="sentdate" data-validation="required" aria-required="true" data-role="calendar" autocomplete="off" size="50" value="<?php echo $this->record->sentdate;?>" />
							</div>
						</td>
					</tr>
					<tr>
						<td class="left_title">
							<?php echo Text::_( 'COM_JCHAT_LAMESSAGE_USERID' ); ?>:
						</td>
						<td class="right_details">
							<label class="label label-info">
								<?php echo isset($this->record->_username_logged) ? $this->record->_username_logged : Text::_('COM_JCHAT_ANONYMOUS');?> 
							</label>
						</td>
					</tr>
					<tr>
						<td class="left_title">
							<?php echo Text::_( 'COM_JCHAT_WORKED' ); ?>:
						</td>
						<td class="right_details">
							<?php echo $this->lists['worked']; ?>
						</td>
					</tr> 
					<tr>
						<td class="left_title">
							<?php echo Text::_( 'COM_JCHAT_CLOSED_TICKET' ); ?>:
						</td>
						<td class="right_details">
							<?php echo $this->lists['closed']; ?>
						</td>
					</tr> 
				</tbody>
				</table>
			</div>
		</div>
	</div>
	
	<div class="accordion-group">
		<div class="accordion-heading opened">
			<div class="accordion-toggle noaccordion">
				<h4><span class="glyphicon glyphicon-pencil"></span> <?php echo Text::_( 'COM_JCHAT_TICKET_REPLY' ); ?></h4>
			</div>
		</div>
		<div id="details" class="accordion-body">
	      	<div class="accordion-inner">
	      		<table class="sitetable response">
					<tr>
						<td width="20%" class="left_title"> 
							<?php echo Text::_( 'COM_JCHAT_EMAIL_SUBJECT' ); ?>: 
						</td>
						<td width="80%" class="right_details messageresponse">
					 		<input name="email_subject" data-validation="required" aria-required="true" size="50" value="<?php echo Text::sprintf('COM_JCHAT_REPLYSUBJECT', $this->record->id, $this->record->sentdate); ?>" class="inputbox wide"/>
						</td>
					</tr>
					<tr class="nomessage">
						<td width="20%" class="left_title"> 
							<?php echo Text::_( 'COM_JCHAT_COMPOSE_RESPONSE' ); ?>: 
						</td>
						<td width="80%" class="right_details messageresponse"> 
					 		<?php echo $this->editor->display( 'response',  null , '100%', '350', '75', '20', false ) ; ?>
						</td>
					</tr>
					<tr class="nomessage">
						<td width="20%" class="left_title"></td>
						<td width="80%" class="right_details messageresponse">
							<div class="btn-wrapper" id="toolbar-upload">
								<button onclick="Joomla.submitbutton('lamessages.responsemessage')" class="btn btn-default btn-sm">
									<span class="glyphicon glyphicon-send"></span>
									<?php echo Text::_( 'COM_JCHAT_RESPONSE_LEAVED_MESSAGES' ); ?>
								</button>
							</div>
						</td>
					</tr>
				</tbody>
				</table>
			</div>
			<input type="hidden" name="ticket_sender" value="<?php echo $this->nameOfUser;?>"/>
		</div>
	</div>
	
	<div class="accordion-group">
		<div class="accordion-heading opened">
			<div class="accordion-toggle noaccordion">
				<h4><span class="glyphicon glyphicon-list-alt"></span> <?php echo Text::_( 'COM_JCHAT_TICKET_RESPONSES' ); ?></h4>
			</div>
		</div>
		<div id="details" class="accordion-body">
	      	<div class="accordion-inner">
				<table class="sitetable response">
					<tbody>
						<?php if(isset($this->record->responses) && is_array($this->record->responses)): 
							$this->record->responses = array_reverse($this->record->responses);
							?>
							<?php foreach($this->record->responses as $responseGiven): ?>
							<tr>
								<td width="20%" class="left_title"> 
									<p>
										<?php 
											// Transform the date string, get date time in UTC from DB
											$dateObject = Factory::getDate($responseGiven[0]);
											// Set local time zone
											$dateObject->setTimezone(new DateTimeZone($this->joomlaConfig));
										?>
										<label class="label label-success"><?php echo $dateObject->format('Y-m-d H:i:s', true, false); ?></label>
									</p>
									<p>
										<label class="label label-warning"><?php echo $responseGiven[2]; ?></label>
									</p>
								</td>
								<td width="80%" class="right_details messageresponse">
									<div class="well well-large">
										<?php echo $responseGiven[1];?> 
									</div>
								</td>
							</tr>
							<?php endforeach; ?>
						<?php endif; ?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
		
	<input type="hidden" name="option" value="<?php echo $this->option;?>" /> 
	<input type="hidden" name="id" value="<?php echo $this->record->id;?>" /> 
	<input type="hidden" name="task" value="" /> 
</form>