<?php require_once("inc/init.php"); ?>
<?php include 'controller/mailCode2.php'; ?>
<h2 class="email-open-header">
	<?php echo $opened_email[0]['subject']; ?><span class="label txt-color-white">inbox</span>
	<a href="javascript:void(0);" rel="tooltip" data-placement="left" data-original-title="Print" class="txt-color-darken pull-right"><i class="fa fa-print"></i></a>	
</h2>

<div class="inbox-info-bar">
	<div class="row">
		<div class="col-sm-9">
			<img src="userImage/<?php echo $opened_email[0]['picture']; ?>" alt="me" class="away">
			<?php if ($_SESSION['staff_id']!=$opened_email[0]['user_from']) {
				?>
				<strong><?php echo $opened_email[0]['first_name'] . ' ' . $opened_email[0]['last_name']; ?></strong><span class="hidden-mobile"> to
				<?php
			} else{
				?>
				<span class="hidden-mobile"> From
				<?php
			}?>
			 <strong>me</strong> on <i><?php echo $opened_email[0]['date_time']; ?></i></span> 
		</div>
		<div class="col-sm-3 text-right">
			
			<div class="btn-group text-left">
				<button class="btn btn-primary btn-sm replythis">
					<i class="fa fa-reply"></i> Reply
				</button>
				<button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
					<i class="fa fa-angle-down"></i>
				</button>
				<ul class="dropdown-menu pull-right">
					<li>
						<a href="javascript:void(0);" class="replythis"><i class="fa fa-reply"></i> Reply</a>
					</li>
					<li>
						<a href="javascript:void(0);" class="replythis"><i class="fa fa-mail-forward"></i> Forward</a>
					</li>
					<li>
						<a href="javascript:void(0);"><i class="fa fa-print"></i> Print</a>
					</li>
					<li class="divider"></li>
					<li>
						<a href="javascript:void(0);"><i class="fa fa-ban"></i> Mark as spam!</a>
					</li>
					<li>
						<a href="javascript:void(0);"><i class="fa fa-trash-o"></i> Delete forever</a>
					</li>
				</ul>
			</div>

		</div>
	</div>
</div>

<div class="inbox-message">
	<?php echo $opened_email[0]['msg']; ?>
</div>

<?php 
if($opened_email[0]['attatchment']){
	$fileArray = explode(",",$opened_email[0]['attatchment']);
	$countFile = count($fileArray);
	$fileArray6 = array_slice($fileArray, 0,6);

	?>
<div class="inbox-download">
	<?php echo $countFile; ?> attachment(s) — <a href="javascript:void(0);"> Download all attachments</a> 
	
	<ul class="inbox-download-list">
	<?php
	$i=0;
	foreach ($fileArray6 as $file) {
		$i++;
		$ext = explode('.', basename($file)); //explode file name from dot(.) 
                $file_extension = end($ext);
	
	
 ?>

		<?php  
		if($file_extension == "jpg" || $file_extension == "png" || $file_extension == "jpeg" || $file_extension == "gif" || $file_extension == "icon"){
		?>
			<li>
			<div class="well well-sm">
				<span>
					<img src="mail_attatchment/<?php echo $file; ?>">
				</span>
				<br>
				<strong><?php echo $opened_email[0]['file_name'] ?></strong> 
				<br>
				<?php echo $opened_email[0]['file_size'] ?> kb 
				<br> 
				<a href="javascript:void(0);" download="download"> Download</a>  | <a href="javascript:void(0);" data-toggle="modal" data-target="#myModal<?php echo $i; ?>"> View</a>
			</div>
		</li>


			<div class="modal fade" id="myModal<?php echo $i; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<img src="mail_attatchment/<?php echo $file; ?>">
					</div><!-- /.modal-dialog -->
				</div><!-- /.modal -->

		<?php } else{?>
	
		<li>
			<div class="well well-sm">
				<span>
					<i class="fa fa-file"></i>
				</span>
				
				<br>
				<strong><?php echo $opened_email[0]['file_name'] ?></strong> 
				<br>
				<?php echo $opened_email[0]['file_size'] ?> mb 
				<br> 
				<a href="javascript:void(0);"> Download</a>
			</div>
		</li>

<?php } 
}
?>
	</ul>
</div>
<?php
}
?>


<div class="email-infobox">

	

<!-- 	<div class="well well-sm well-light">
		<h5>Upcoming Meetings</h5>
		
		<p>
			<span class="label label-success"><i class="fa fa-check"></i> <strike>Agenda Review @ 10 AM</strike> </span>
		</p>

		<p>
			<span class="label label-primary"><i class="fa fa-clock-o"></i> Client Meeting @ 2:30 PM</span>
		</p>

		<p>
			<span class="label label-warning"><i class="fa fa-clock-o"></i> Salary Review @ 4:00 PM</span>
		</p>		
	</div> -->	

	<!--  -->

</div>

<script type="text/javascript">
	
	/* DO NOT REMOVE : GLOBAL FUNCTIONS!
	 *
	 * pageSetUp(); WILL CALL THE FOLLOWING FUNCTIONS
	 *
	 * // activate tooltips
	 * $("[rel=tooltip]").tooltip();
	 *
	 * // activate popovers
	 * $("[rel=popover]").popover();
	 *
	 * // activate popovers with hover states
	 * $("[rel=popover-hover]").popover({ trigger: "hover" });
	 *
	 * // activate inline charts
	 * runAllCharts();
	 *
	 * // setup widgets
	 * setup_widgets_desktop();
	 *
	 * // run form elements
	 * runAllForms();
	 *
	 ********************************
	 *
	 * pageSetUp() is needed whenever you load a page.
	 * It initializes and checks for all basic elements of the page
	 * and makes rendering easier.
	 *
	 */

	pageSetUp();
	
	/*
	 * ALL PAGE RELATED SCRIPTS CAN GO BELOW HERE
	 * eg alert("my home function");
	 * 
	 * var pagefunction = function() {
	 *   ...
	 * }
	 * loadScript("js/plugin/_PLUGIN_NAME_.js", pagefunction);
	 * 
	 * TO LOAD A SCRIPT:
	 * var pagefunction = function (){ 
	 *  loadScript(".../plugin.js", run_after_loaded);	
	 * }
	 * 
	 * OR
	 * 
	 * loadScript(".../plugin.js", run_after_loaded);
	 */
	
	
	// PAGE RELATED SCRIPTS
	
	$(".table-wrap [rel=tooltip]").tooltip();

	$(".replythis").click(function(){
		loadURL("ajax/email-reply.php?::=<?php echo $opened_email[0]['mail_id'] ?>", $('#inbox-content > .table-wrap'));
	})
	
</script>
