<script type="text/javascript">
<!--
$(document).ready(function() 
{
    $('.date').datepicker();
});
// -->
</script>

<h1><?php echo $this->translate('inquiry.title.view_detail'); ?></h1>

<?php if(!empty($this->error_messages)) : ?>
<div id="errorMessage">
<ul>
<?php foreach($this->error_messages as $element_name => $element_mess) : ?>
<?php foreach($element_mess as $mess_key => $mess_value) :?>
<?php $field_name = ""; if (!empty($element_name)) $field_name = $this->translate("inquiry.label.$element_name");  ?>
<li><?php echo $field_name . $mess_value; ?></li>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>

<div id="leftArea">
<h2><?php echo $this->translate('inquiry.caption.basic_info'); ?></h2>

<table border="0" cellpadding="0" cellspacing="0" summary="<?php echo $this->translate('inquiry.caption.basic_info'); ?>">

<tbody>

<tr>
<th><?php echo $this->translate('inquiry.label.inquiry_id'); ?></th>
<td><?php echo $this->escape($this->form_input['id']); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.service_name'); ?></th>
<td><?php echo $this->service_options[$this->form_input['service_id']]; ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.subject'); ?></th>
<td><?php  echo $this->escape($this->form_input['subject']); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.received_from'); ?></th>
<td><?php  echo $this->escape($this->form_input['received_from']); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.status'); ?></th>
<td><?php echo $this->status_options[$this->form_input['status']]; ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.priority'); ?></th>
<td><?php  echo $this->priority_options[$this->form_input['priority']]; ?></td>
</tr>
    
<tr>
<th><?php echo $this->translate('inquiry.label.registrant_name'); ?></th>
<td><?php  echo $this->escape($this->form_input['registrant_name']); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.accepter_name'); ?></th>
<td><?php  echo $this->escape($this->form_input['accepter_name']); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.approver_name'); ?></th>
<td><?php  echo $this->escape($this->form_input['approver_name']); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.operator_name'); ?></th>
<td>
<?php if(empty($this->form_input['operator_name'])) : ?>
<i><?php echo $this->translate('inquiry.message.unassign_operator'); ?></i>
<?php endif; ?>

<?php if ($this->is_operator) : ?>
<form action="<?php echo $this->appPath('controller'); ?>/change_operator/" method="GET">
<input type="hidden" name="inquiry_id" value="<?php echo $this->form_input['id']; ?>">
<select name="operator_id">
<?php foreach ((array) $this->user_options as $key => $value) : ?>
<?php $selected = $this->form_input['operator_id'] == $key ? "selected" : ""; ?>
<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $value; ?></option>
<?php endforeach; ?>
</select>
<input type="submit" value="<?php echo $this->translate('inquiry.operation.change_operator'); ?>">
</form>
<?php else : ?>
<?php echo $this->escape($this->form_input['operator_name']); ?>
<?php endif; ?>
</td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.content'); ?></th>
<td><?php echo nl2br($this->escape($this->form_input['content'])); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.attach_file'); ?></th>
<td>
<ul>
<?php foreach ($this->form_input['attach_files'] as $attach_file) : ?>
<li>
<?php if ($this->edit_flag) : ?>
<input type="checkbox" name="<?php echo $attach_file['id']; ?>" id="attach_<?php echo $attach_file['id']; ?>">
<?php endif; ?>
<label for="attach_<?php echo $attach_file['id']; ?>"><?php echo $attach_file['name']; ?></label>
&nbsp;&nbsp;<a href="./inquiry/download_file/inquiry_id/<?php echo $this->form_input['id']; ?>/attach_file_id/<?php echo $attach_file['id']; ?>/">DL</a>
</li>
<?php endforeach; ?>
</ul>
</td>
</tr>
    
</tbody>
</table>
</div>

<div id="rightArea">
<h2><?php echo $this->translate('inquiry.caption.datetime_info'); ?></h2>

<table border="0" cellpadding="0" cellspacing="0" summary="<?php echo $this->translate('inquiry.caption.datetime_info'); ?>">
<tbody>

<tr>
<th><?php echo $this->translate('inquiry.label.create_datetime'); ?></th>
<td colspan="2"><?php echo $this->escape($this->form_input['create_datetime']); ?></td>
</tr>
    
<tr>
<th><?php echo $this->translate('inquiry.label.accept_datetime'); ?></th>
<td colspan="2"><?php echo $this->escape($this->form_input['accept_datetime']); ?></td>
</tr>

<tr>
<th><?php echo $this->translate('inquiry.label.approve_datetime'); ?></th>
<td colspan="2"><?php echo $this->escape($this->form_input['approval_datetime']); ?></td>
</tr>
    
<tr>
<th><?php echo $this->translate('inquiry.label.replylimit'); ?></th>
<td class="cell1">
<?php if ($this->can_setlimit) : ?>
<form method="post" name="replylimit_form" action="<?php echo $this->appPath('controller');?>/setup_datetime/">
<input class="date" type="text" style="width:8em;" name="replylimit_date" value="<?php echo $this->escape($this->form_input['replylimit_date']); ?>"/>
<input class="clock" type="text" style="width:5em;" name="replylimit_time" value="<?php echo $this->escape($this->form_input['replylimit_time']); ?>"/>
<input type="hidden" name="field" value="replylimit">
<input type="hidden" name="inquiry_id" value="<?php echo $this->escape($this->form_input['id']); ?>">
</form>
<?php elseif (!empty($this->form_input['replylimit_datetime'])) : ?>
<?php echo $this->escape($this->form_input['replylimit_datetime']); ?>
<?php else: ?>
<i><?php echo $this->translate('common.label.unset'); ?></i>
<?php endif; ?>
</td>
<td class="btn1">
<?php if ($this->can_setlimit) : ?>
<a onclick="document.replylimit_form.submit();"><img src="./img/detail/btn_setting.gif" width="50" height="20" border="0" class="imgover"></a>
<?php endif; ?>
</td>
</tr>
    
<tr>
<th><?php echo $this->translate('inquiry.label.suspension_datetime'); ?></th>
<td>
<?php if (!empty($this->form_input['suspension_datetime'])) : ?>
<?php echo $this->escape($this->form_input['suspension_datetime']); ?>
<?php else : ?>
----
<?php endif; ?>
</td>
<td class="btn1">
<?php if ($this->can_suspend)  : ?>
<form method="get" name="suspend_form" action="<?php echo $this->appPath('controller');?>/setup_datetime/" style="margin:0;">
<input type="hidden" name="field" value="suspend">
<input type="hidden" name="inquiry_id" value="<?php echo $this->escape($this->form_input['id']); ?>">
</form>
<a onclick="document.suspend_form.submit();"><img src="./img/detail/btn_reserve.gif" alt="<?php echo $this->translate('inquiry.operation.suspend'); ?>" width="50" height="20" border="0" class="imgover"></a>
<?php elseif ($this->can_resume) : ?>
<form method="get" name="resume_form" action="<?php echo $this->appPath('controller');?>/setup_datetime/" style="margin:0;">
<input type="hidden" name="field" value="resume">
<input type="hidden" name="inquiry_id" value="<?php echo $this->escape($this->form_input['id']); ?>">
</form>
<a onclick="document.resume_form.submit();"><img src="./img/detail/btn_delete.gif" alt="<?php echo $this->translate('inquiry.operation.unsuspend'); ?>" width="50" height="20" border="0" class="imgover"></a>
<?php endif; ?>
</td>
</tr>
    
<tr>
<th><?php echo $this->translate('inquiry.label.solution_datetime'); ?></th>
<td>
<?php if (!empty($this->form_input['solution_datetime'])) : ?>
<?php echo $this->escape($this->form_input['solution_datetime']); ?>
<?php else : ?>
----
<?php endif; ?>
</td>
<td class="btn1">
   <?php if ($this->can_solution) : ?>
<form method="post" name="solution_form" action="<?php echo $this->appPath('controller');?>/setup_datetime/" style="margin:0;">
<input type="hidden" name="field" value="solution">
<input type="hidden" name="datetime" value="">
<input type="hidden" name="inquiry_id" value="<?php echo $this->escape($this->form_input['id']); ?>">
<a onclick="document.solution_form.submit();"><img src="./img/detail/btn_solution.gif" alt="<?php echo $this->translate('inquiry.operation.solution'); ?>" width="50" height="20" border="0" class="imgover"></a>
</form>
<?php endif; ?>
</td>
</tr>

</tbody>
</table>


<h2><?php echo $this->translate('inquiry.caption.relation_info'); ?></h2>
<table border="0" cellpadding="0" cellspacing="0" summary="<?php echo $this->translate('inquiry.caption.relation_info'); ?>">
<tbody>

<tr>
<th><?php echo $this->translate('inquiry.label.parent'); ?></th>
<td colspan="2">
<?php if (!empty($this->parent_inquiry)) : ?>
<a href="./inquiry/view_detail/inquiry_id/<?php echo $this->parent_inquiry['id']; ?>"><?php echo $this->parent_inquiry['subject']; ?></a>
<?php else : ?>
----
<?php endif; ?>
</td>
</tr>

<tr>
<th rowspan="2"><?php echo $this->translate('inquiry.label.derivated'); ?></th>
<td class="cell2" colspan="2">
<?php if (!empty($this->derivated_inquiries)) : ?>
<form name="derivation_delete_form" method="get" action="./inquiry/remove_derivation/" style="margin:0;padding:0;">
<input type="hidden" name="inquiry_id" value="<?php echo $this->escape($this->form_input['id']); ?>">
<ul>    
<?php foreach ((array) $this->derivated_inquiries as $derivated_inquiry) : ?>
<li>
<input type="checkbox" name="derivated_inquiry_id[]" id="derivated_<?php echo $derivated_inquiry['id']; ?>" value="<?php echo $derivated_inquiry['id']; ?>" style="margin:0;padding:0;width:1em;"/>
<label for="derivated_<?php echo $derivated_inquiry['id']; ?>"><?php echo $this->escape($derivated_inquiry['subject']); ?>&nbsp;&nbsp;<a href="<?php echo $this->appPath('controller'); ?>/view_detail/inquiry_id/<?php echo $derivated_inquiry['id']; ?>">詳細</a></label>
</li>
<?php endforeach; ?>
</ul>
</form>
<?php else : ?>
----
<?php endif; ?>
</td>
</tr>

<tr>
<td></td>
<td class="btn2">
<?php if ($this->can_derivation) : ?>
<a href="./inquiry/derivate_input/parent_inquiry_id/<?php echo $this->escape($this->form_input['id']); ?>"><img src="./img/detail/btn_add.gif" alt="<?php echo $this->translate('common.operation.add'); ?>" width="50" height="20" border="0" class="imgover"></a>
<a onclick="document.derivation_delete_form.submit();"><img src="./img/detail/btn_delete.gif" alt="<?php echo $this->translate('common.operation.delete'); ?>" width="50" height="20" border="0" class="imgover"></a>
<?php endif; ?>
</td>
</tr>

<tr>
<th rowspan="2"><?php echo $this->translate('inquiry.label.referenced'); ?></th>
<td class="cell2" colspan="2">
<?php if (!empty($this->referenced_inquiries)) : ?>
<form name="reference_delete_form" method="GET" action="./inquiry/remove_reference/" style="margin:0;padding:0;">
<input type="hidden" name="inquiry_id" value="<?php echo $this->escape($this->form_input['id']); ?>">
<ul>    
<?php foreach((array) $this->referenced_inquiries as $ref_inquiry) : ?>
<li>
<input type="checkbox" name="referenced_inquiry_id[]" id="referenced_<?php echo $ref_inquiry['id']; ?>" value="<?php echo $ref_inquiry['id']; ?>" style="margin:0;padding:0;width:1em;"/>
<label for="referenced_<?php echo $ref_inquiry['id']; ?>"><?php echo $ref_inquiry['subject']; ?>&nbsp;&nbsp;<a href="<?php echo $this->appPath('controller'); ?>/view_detail/inquiry_id/<?php echo $ref_inquiry['id']; ?>">&gt;詳細</a><br/></label>
</li>
<?php endforeach; ?>
</ul>
</form>
<?php else : ?>
----
<?php endif; ?>
</td>
</tr>
<tr>
<td class="cell2">
<?php if ($this->can_reference) : ?>
<form name="reference_add_form" method="GET" action="./inquiry/add_reference" style="margin:0;padding:0;">
<input type="hidden" name="inquiry_id" value="<?php echo $this->escape($this->form_input['id']); ?>">
<select name="referenced_inquiry_id[]">
<option>----</option>
<?php foreach((array)$this->inquiry_options as $key=>$value) : ?>
<option value="<?php echo $key; ?>"><?php echo $value; ?></option>
<?php endforeach; ?>
</select>
</form>
<?php else : ?>
----
<?php endif; ?>
</td>
<td class="btn2">
<?php if ($this->can_reference) : ?>
<a onclick="document.reference_add_form.submit();"><img src="./img/detail/btn_add.gif" alt="<?php echo $this->translate('common.operation.add'); ?>" width="50" height="20" border="0" class="imgover"></a>
<a onclick="document.reference_delete_form.submit();"><img src="./img/detail/btn_delete.gif" alt="<?php echo $this->translate('common.operation.delete'); ?>" width="50" height="20" border="0" class="imgover"></a>
<?php endif; ?>
</td>
</tr>
    
</tbody>
</table>
</div>


<ul id="btnArea">
<li id="comment">
<?php if ($this->can_comment_create) : ?>
<a href="<?php echo $this->appPath(); ?>/comment/create_input/inquiry_id/<?php echo $this->escape($this->form_input['id']); ?>"><img src="./img/detail/btn_comment.gif" alt="<?php echo $this->translate('inquiry.operation.comment'); ?>" border="0" class="imgover"></a>
<?php endif; ?>
</li>
<li>
<?php if ($this->can_reply_create) : ?>
<a href="<?php echo $this->appPath(); ?>/reply/create_input/inquiry_id/<?php echo $this->escape($this->form_input['id']); ?>"><img src="./img/detail/btn_answer.gif" alt="<?php echo $this->translate('inquiry.operation.reply'); ?>" border="0" class="imgover"></a>
<?php endif; ?>
</li>
</ul>

<br/>
<ul>
<li>&gt;&gt;&gt;&nbsp;&nbsp;<a href="<?php echo $this->appPath(''); ?>/inquiry/view_all/service_id/<?php echo $this->form_input['service_id']; ?>"><?php echo $this->translate('inquiry.operation.back_list'); ?></a></li>
</ul>
<br/>

<h2><?php echo $this->translate('inquiry.caption.reply_history'); ?></h2>

<?php
if (!empty($this->replies)) :
?>
<table border="0" cellpadding="0" cellspacing="0" summary="<?php echo $this->translate('inquiry.caption.reply_history'); ?>" class="def">
<tbody>

<tr>
<th>ID</th>
<th>&nbsp;</th>
<th><?php echo $this->translate('reply.label.subject'); ?></th>
<th><?php echo $this->translate('reply.label.respondent_name'); ?></th>
<th><?php echo $this->translate('reply.label.reply_datetime'); ?></th>
<th>&nbsp;</th>
<!-- <th>INQ_ID-PARENT_ID-TYPE</th> -->
</tr>
    
<?php foreach ((array) $this->replies as $reply) : ?>
<?php $class = $reply['type'] == 1 ? "reply" : "comment"; ?>
<tr class="<?php echo $class; ?>">

<td>
<?php echo $this->escape($reply['id']); ?>
</td>
<td>
<img src="./images/icons/<?php echo $this->escape($reply['method']); ?>.png"/>
</td>
<td style="text-align:left">
<?php /*echo str_repeat('&nbsp&nbsp;&nbsp&nbsp;', $reply['level']);*/ echo $this->escape($reply['subject']); ?>
</td>  
<td>
<?php echo $this->escape($reply['respondent_name']); ?>
</td>
<td>
<?php echo $this->escape($reply['reply_datetime']); ?>
</td>
<td>
<?php if ($this->can_comment_create) : ?>
<a href="comment/create_input/parent_id/<?php echo $this->escape($reply['id']); ?>"><?php echo $this->translate('inquiry.operation.comment'); ?></a>
<?php endif; ?>
<?php if ($this->can_reply_create && $reply['type'] == 1) : ?>
&nbsp;/&nbsp;
<a href="reply/create_input/parent_id/<?php echo $this->escape($reply['id']); ?>"><?php echo $this->translate('inquiry.operation.reply'); ?></a>
<?php endif; ?>
</td>
<!--
<td><?php echo $this->escape($reply['inquiry_id']); ?>-<?php echo $this->escape($reply['parent_id']); ?>-<?php echo $this->escape($reply['type']); ?></td>
-->
</tr>

<tr id="<?php echo $reply['id']; ?>" class="<?php echo $class; ?>">
<td colspan="2">
<?php $label_class = ($reply['type'] == 1) ? $this->translate('inquiry.label.reply') : $this->translate('inquiry.label.comment'); ?>
<?php echo $label_class; ?>
<?php echo $this->translate('reply.label.content'); ?>
</td>
<td colspan="4" style="text-align:left;">
<div id="#content<?php echo $reply['id']; ?>">
<?php echo nl2br($this->escape($reply['content'])); ?>
</div>
</td>
</tr>

<?php endforeach; ?>
</tbody>
</table>
<?php else : ?> 
<?php echo $this->translate('inquiry.message.no_reply'); ?>
<?php endif; ?>

