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

   		<form action="<?php JRoute::_('index.php'); ?>" method="post" name="adminForm" id="adminForm">

		<div class='componentheading'>
            <?php if ($this->pagetitle) { echo $this->pagetitle; } ?>
		</div>

        <table width='100%'>
        <tr>
          <td class="title">
		  	<?php // echo "<a href='index.php?option=".$option."&Itemid=".$this->Itemid."&controller=ticket&task=new'><img src='".$mainframe->getCfg('live_site')."/components/com_billets/images/newticket.png' align='center' border='0'></a>"; ?>
            <?php 
			echo "<a href='".JRoute::_('index.php?option=com_billets&controller=ticket&task=new&Itemid='.$this->Itemid )."'>";
            echo "<img src='".$mainframe->getCfg('live_site')."/components/com_billets/images/newticket.png' align='center' border='0'>"; 
			echo "</a>"; 
			?>
          </td>
          <td class='input'>
		  	<?php // echo "<a href='index.php?option=".$option."&Itemid=".$this->Itemid."&controller=ticket&task=new'>"; echo _BILLETS_NEWSUPPORTTICKET."</a>"; ?>
            <?php 
			echo "<a href='".JRoute::_('index.php?option=com_billets&controller=ticket&task=new&Itemid='.$this->Itemid )."'>";
            echo _BILLETS_NEWSUPPORTTICKET; 
			echo "</a>"; 
			?>
          </td>
          <td class='right'><?php echo _BILLETS_QUICKSEARCH; ?>:</td>
          <td class="input">
            <input type="text" name="search" value="<?php echo htmlspecialchars( $this->search );?>" class="text_area" onchange='submitForm("<?php echo $task; ?>")' />
          </td>
          <td class='right'><?php echo $this->statuses; ?></td>
        </tr>
        </table>
       
        <table class="userlist">
		<thead>
            <tr>
                <th class="title">
                <?php echo JHTML::_('grid.sort', _BILLETS_ID." " , "id", $this->order_dir, $this->order, $task ); ?> +
                <?php echo JHTML::_('grid.sort', _BILLETS_TYPE." " , "type", $this->order_dir, $this->order, $task ); ?>
                </th>
                <th class="title">
                <?php echo JHTML::_('grid.sort', _BILLETS_SUBJECT." " , "subject", $this->order_dir, $this->order, $task ); ?>
                </th>
                <th class="title">
                <?php echo JHTML::_('grid.sort', _BILLETS_LASTMODIFIED." " , "lastmodified", $this->order_dir, $this->order, $task ); ?>
                <br />
                <?php echo JHTML::_('grid.sort', _BILLETS_AND." "._BILLETS_CREATED." " , "created", $this->order_dir, $this->order, $task ); ?>
                </th>
                <th class="title">
                <center>
                <?php echo JHTML::_('grid.sort', ""._BILLETS_STATUS." " , "status", $this->order_dir, $this->order, $task ); ?>
                </center>
                </th>
                <th class="title">
                <center>
                <?php echo JHTML::_('grid.sort', ""._BILLETS_FEEDBACK." " , "feedback", $this->order_dir, $this->order, $task ); ?>
                </center>
                </th>
          </tr>
		</thead>
        <tbody>
			<?php
					$today 			= date( "Y-m-d" );
					$yesterday_time	= time() - (24 * 60 * 60); // timestamp - 24 hours * 60 mins * 60secs
					$yesterday		= date( "Y-m-d", $yesterday_time ); 

			for ($i=0, $n=count( $this->items ); $i < $n; $i++)
			{
				$r =& $this->items[$i];

					// $last_modified 	= mosFormatDate($r->last_modified_datetime, "%Y-%m-%d");
					// $created 		= mosFormatDate($r->created_datetime, "%Y-%m-%d");
			  	echo "<tr>";
					echo "<td class='noborder'>"; 
						echo "<a href='".JRoute::_('index.php?option=com_billets&controller=ticket&task=view&id='.$r->id.'&Itemid='.$this->Itemid )."'>";
						echo $r->id;
						echo "</a>";
						echo "&nbsp;";						
						echo "<a href='".JRoute::_('index.php?option=com_billets&controller=ticket&task=view&id='.$r->id.'&Itemid='.$this->Itemid)."'>";
						if ( defined($r->type) ) { echo constant($r->type); } else { echo _BILLETS_UNDEFINED; } 
						echo "</a>";						
					echo "</td>";
					echo "<td class='noborder'>"; 
						echo "<a href='".JRoute::_('index.php?option=com_billets&controller=ticket&task=view&id='.$r->id.'&Itemid='.$this->Itemid )."'>";
						echo stripslashes($r->subject);
						echo "</a>";
					echo "</td>";

					echo "<td class='noborder'>";
						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 class='noborder'><center>"; 
						echo billetsSupportTicketStatusImage($r->status);
						echo "<br />";
						echo billetsSupportTicketStatus($r->status);
					echo "</center></td>";
					echo "<td class='noborder'><center>"; 
						echo billetsFeedbackRatingImage($r->feedback_rating);
					echo "</center></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td class='topnowrap' colspan='1'>";
						if ($r->description) { ?>
						<span class="href" id="showhidedescription_<?php echo $r->id; ?>" onclick="displayDiv ('description_<?php echo $r->id; ?>', 'showhidedescription_<?php echo $r->id; ?>', '<?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>";
			  } // end foreach

			if (!$this->items) {
			  	echo "<tr>";
				echo "<td colspan='7'>";					
				  echo _BILLETS_NONE;
			  	echo "</td>";
			  	echo "</tr>";
			}			
			?>
        </tbody>
        <tfoot>
        	<tr>
                <td colspan='7'>
                    <div class="pagination">
                    <?php echo $this->pagination->getListFooter(); ?>
                    </div>            
                </td>
            </tr>
        </tfoot>
        </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="order" value="<?php echo $this->order; ?>" />
		<input type="hidden" name="order_dir" value="<?php echo $this->order_dir; ?>" />
		<input type="hidden" name="Itemid" value="<?php echo $this->Itemid;?>" />
		</form>