<?php include ('header.php'); ?>
    <!-- Messages List -->
    <div class="col-sm-8 col-lg-9">
        <!-- Messages List Block -->
        <div class="block">
            <!-- Messages List Title -->
            <div class="block-title">
                
                <h2><i class="fa fa-paper-plane"></i> <Strong>iMail</Strong> Inbox</h2>
            </div>
            <!-- END Messages List Title -->

            <!-- Messages List Content -->
            <div class="table-responsive">
                <table class="table table-hover">
            <thead>
				<tr>
					<td class="text-center">
					</td>
					<td colspan="3">
					</td>
					<td class="text-right text-muted" colspan="3">
						You have <?php echo count($mail); ?> iMails
					</td>
				</tr>
			</thead>
                    <tbody>
                        <!-- Use the first row as a prototype for your column widths -->
                        
				      <?php if(!$mail) {
    					echo '<tr><td colspan="5">Hey '.Auth::$pilot->firstname.'! You have no messages, yet!</td></tr>';
    					echo '<tr>
    					</tr>';
    					}
    					else {
        					foreach($mail as $data) {
            					if ($data->read_state=='0') {
            						$tdclr = "#dcffc9";
                					$status = '<i class="gi gi-envelope" data-toggle="tooltip" title="" data-original-title="iMail Un-read"></i>' ;
            					}
            					else {
            						$tdclr = "#eaeaea";
                					$status = '<i class="gi gi-message_empty text-muted" data-toggle="tooltip" title="" data-original-title="iMail Read"></i>';
            					}
            					?>
            					<?php 
            						$user = PilotData::GetPilotData($data->who_from); $pilot = PilotData::GetPilotCode($user->code, $data->who_from);
            						
            						if($data->who_from == ADMIN_BOT_ACCOUNT) {
            							$display_name = '<span class="label label-success">SYSTEM ADMIN</span> ';
            						} else {
            							$display_name = '<span class="label label-default">'.$pilot.'</span> | '.$user->firstname.' '.$user->lastname;
            						}
            						
            					?>
    					<tr>
    						<td bgcolor="<?php echo $tdclr; ?>"></td>
        					<td bgcolor="<?php echo $tdclr; ?>" class="text-left"><?php echo $status;?></td>
        					<td bgcolor="<?php echo $tdclr; ?>" class="text-left">
        					  <a href="<?php echo SITE_URL ?>/index.php/Mail/item/<?php echo $data->thread_id;?>"><button class="btn btn-default" data-toggle="tooltip" title="" data-original-title="View"><i class="fa fa-eye text-muted"></i></button></a> 
        					  <a href="<?php echo SITE_URL ?>/index.php/Mail/reply/<?php echo $data->thread_id;?>"><button class="btn btn-default" data-toggle="tooltip" title="" data-original-title="Reply"><i class="fa fa-reply text-success"></i></button></a> 
        					  <a href="<?php echo SITE_URL ?>/index.php/Mail/delete/<?php echo $data->id;?>"><button class="btn btn-default" data-toggle="tooltip" title="" data-original-title="Delete"><i class="fa fa-trash-o text-danger"></i></button></a>
        					</td>
        					
        					<td bgcolor="<?php echo $tdclr; ?>" class="text-left" style="width: 25%;"><?php echo $display_name; ?> </td>
        					
        					<td bgcolor="<?php echo $tdclr; ?>" class="text-left">
        					    <a href="<?php echo SITE_URL ?>/index.php/Mail/item/<?php echo $data->thread_id;?>">
        					        <?php echo $data->subject; ?>
        					    </a>
        					    <span class="text-muted"><em><?php
        					    
        					    $pos=strpos($data->message, ' ', 0);
        					    if($pos < 1)
        					    {
        					    	echo '.......';
        					    }
        					    else
        					    {
        					    	$poss=strpos($data->message, ' ', 15);
        					    echo substr($data->message,0,$poss );  
        					    }	
        					    ?>...</em></span>
        					</td>
        					
        					<td bgcolor="<?php echo $tdclr; ?>" class="text-right"><em><?php /* echo date(DATE_FORMAT.' h:ia', strtotime($data->date));*/ echo time_elapsed($data->date); ?></em></td>
        					<td bgcolor="<?php echo $tdclr; ?>"></td>
        					
        					
    					</tr>
    					
				<?php
				}
				?>
    					<?php
    					}
    					?>
    					
                    </tbody>
                </table>
                <span class="pull-right">iMail <strong><em>v4</em></strong></span><br><br>
            </div>
            <!-- END Messages List Content -->
        </div>
        <!-- END Messages List Block -->
    </div>
    <!-- END Messages List -->
      
    </div>
<!-- END Inbox Content -->
