<?php defined('_JEXEC') or die('Restricted access'); ?>

		<form action="index.php" method="post" name="adminForm" id="adminForm">
		<?php 
		$r = $this->row;
		// date stuff		
		$today 			= date( "Y-m-d" );
		$yesterday_time	= time() - (24 * 60 * 60); // timestamp - 24 hours * 60 mins * 60secs
		$yesterday		= date( "Y-m-d", $yesterday_time ); 
		// ticket-specific
		$last_modified 	= JHTML::_('date', $r->last_modified_datetime, "%a, %d %b %Y");
		$created 		= JHTML::_('date', $r->created_datetime, "%a, %d %b %Y");

		?>
		<table class="adminheading">
		<tr>
            <th class='billets_ticket'>
            		<div class='componentheading'>
            <?php echo _BILLETS_VIEWTICKET; ?>
            		</div>
            </th>            
		</tr>
		</table>


   		
        <table class="userlist">
		<thead>
        <tr>
              <th><?php echo _BILLETS_ID; ?></th>
              <th><?php echo _BILLETS_TYPE; ?></th>
              <th><?php echo _BILLETS_SUBJECT; ?></th>
              <th><?php echo _BILLETS_LASTMODIFIED."<br />"._BILLETS_AND." "._BILLETS_CREATED; ?></th>
              <th><center><?php echo _BILLETS_STATUS; ?></center></th>
              <th><center><?php echo _BILLETS_FEEDBACK; ?></center></th>
        </tr>
        </thead>
        <tbody>
			<?php
			  	echo "<tr>";
					echo "<td>"; echo $r->id; echo "</td>";
					echo "<td>"; if ( defined($r->type) ) { echo constant($r->type); } else { echo _BILLETS_UNDEFINED; } echo "</td>";
					echo "<td>"; 
						echo stripslashes( $r->subject );
					echo "</td>";
					echo "<td>"; 
						if ($last_modified == $today) {
							echo JHTML::_('date', $r->last_modified_datetime, "%I:%M%p"); // strftime formatting
						} elseif ($last_modified == $yesterday) {
							echo _BILLETS_YESTERDAY.", ".JHTML::_('date', $r->last_modified_datetime, "%I:%M%p"); // strftime formatting
						} else {
							echo JHTML::_('date', $r->last_modified_datetime, "%d %b %Y, %I:%M%p"); // strftime formatting
						}
						
						echo "<br /><hr>";
		
						if ($created == $today) {
							echo JHTML::_('date', $r->created_datetime, "%I:%M%p"); // strftime formatting
						} elseif ($created == $yesterday) {
							echo _BILLETS_YESTERDAY.", ".JHTML::_('date', $r->created_datetime, "%I:%M%p"); // strftime formatting
						} else {
							echo JHTML::_('date', $r->created_datetime, "%d %b %Y, %I:%M%p"); // strftime formatting
						}
					echo "</td>";
					echo "<td><center>"; 
						echo billetsSupportTicketStatusImage($r->status);
						if ($r->closed_datetime > 0) {
							echo "<br />".JHTML::_('date', $r->closed_datetime, "%a, %d %b %Y, %I:%M%p");					
						} else {
							echo "<br />".billetsSupportTicketStatus($r->status); 
						}

					echo "</center></td>";
					echo "<td><center>"; 
						echo billetsFeedbackRatingImage($r->feedback_rating);
					echo "</center></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td class='topnowrap' colspan='2' valign='top' nowrap>";
						if ($r->description) { ?>
						<span class="href" id="showhidedescription" onclick="displayDiv ('description_<?php echo $r->id; ?>', 'showhidedescription', '<?php echo _BILLETS_SHOWDESCRIPTION; ?>', '<?php echo _BILLETS_HIDEDESCRIPTION; ?>');"><?php echo _BILLETS_SHOWDESCRIPTION; ?></span> 				
						  <?php }                  
					echo "</td>";
					echo "<td colspan='6' class='billets_faded'>"; 
						if ($r->description) { echo ". . . . ."; ?>
						<div id="description_<?php echo $r->id; ?>" style="display: none">
                        	<?php 
							echo "<div class='billets_paddedl'>";
							echo nl2br( stripslashes( $r->description ) );
							echo "</div>";				  
							?>
						</div>
					<?php }
					echo "</td>";
				echo "</tr>";

			?>
          </tbody>
          </table>
			
            <p></p>
            
        	<h3>
				<?php echo _BILLETS_DISCUSSION; ?>
				<?php // if ($r->status == '0') { ?>                  
                    <span class="href" id="showhideaddcomment" onclick="displayDiv ('addcomment', 'showhideaddcomment', '<?php echo _BILLETS_ADDCOMMENT; ?>', '<?php echo _BILLETS_ADDCOMMENT; ?>');"><?php echo _BILLETS_ADDCOMMENT; ?></span> 
				<?php // } ?>
            </h3>
            
				<?php // if ($r->status == '0') { ?>          
                        <div id="addcomment" style="display: none">
                        <table class="userlist">
                        <tr>
                          <td class="input">
                          <textarea name="message" class="text_area" cols="40" rows="10" style="width:500px" width="500px" ></textarea>
                          </td>
                        </tr>
                        <tr>
                          <td class="input">
                            <input type='button' class='button' onclick="submitform('addcomment')" value='<?php echo _BILLETS_ADDCOMMENT; ?>' />
                          </td>
                        </tr>
                        </table>
                        </div>
                  <?php // } ?>
           
              <table class="userlist">
                <?php
                if ($this->messages) { foreach ($this->messages as $r) {
                    echo "<tr>";
                    echo "<td>";					
					  echo "<img src='".$mainframe->getCfg('live_site')."/components/com_billets/images/comment.png'>";
                    echo "</td>";					
                    echo "<td>";					
                      echo "<strong>$r->username_from</strong> (".JHTML::_('date', $r->datetime, "%a, %d %b %Y, %I:%M%p")."):<br>";
						echo "<div class='billets_paddedl'>";
						echo nl2br( stripslashes( $r->message ) );
						echo "</div>";
                    echo "</td>";
                    echo "</tr>";
				} } else {
                    echo "<tr>";
                    echo "<td>";					
					  echo _BILLETS_NONE;
                    echo "</td>";
                    echo "</tr>";
				}
                ?>
              </table> 

            <?php if ($this->row->status == '0' || $this->row->status == '3') { ?>
                            
                <h3><?php echo _BILLETS_CLOSETICKET; ?></h3>
                <div class="note"><?php echo _BILLETS_CLOSETICKET_INTRO; ?></div>
                
                <table>		
                    <?php if ($this->row->sender_userid == $this->user->id) { ?>
                        <tr>
                          <td class='input'>
                            <input type='button' class='button' onclick="submitform( 'closeunsatisfactory' )" value='<?php echo _BILLETS_UNSATISFACTORY; ?>' />
                          </td>
                          <td class='input'>
                            <input type='button' class='button' onclick="submitform( 'closepoor' )" value='<?php echo _BILLETS_POOR; ?>' />
                          </td>
                          <td class='input'>
                            <input type='button' class='button' onclick="submitform( 'closeaverage' )" value='<?php echo _BILLETS_AVERAGE; ?>' />
                          </td>
                          <td class='input'>
                            <input type='button' class='button' onclick="submitform( 'closegood' )" value='<?php echo _BILLETS_GOOD; ?>' />
                          </td>
                          <td class='input'>
                            <input type='button' class='button' onclick="submitform( 'closegreat' )" value='<?php echo _BILLETS_GREAT; ?>' />
                          </td>
                        </tr>
                    <?php } ?>
                </table>   
            
			<?php } ?>                
	            
          </td>
        </tr>
        </table>  


		<input type="hidden" name="option" value="<?php echo $option;?>" />
		<input type="hidden" name="controller" value="<?php echo $this->_name;?>" />		
		<input type="hidden" name="task" value="" />
        <input type="hidden" name="id" value="<?php echo $this->row->id; ?>" />
		<input type="hidden" name="Itemid" value="<?php echo $this->Itemid;?>" />
        <?php echo JHTML::_( 'form.token' ); ?>
		</form>