<?php require_once('head.php'); ?>

  <body>
  <!-- container section start -->
  <section id="container" class="">
      
	<?php require_once('header.php'); ?>	

	<?php require_once('sidebar.php'); ?>
      
      <!--main content start-->
      <section id="main-content">
          <section class="wrapper">

			  <div class="row">
                  <div class="col-lg-12">
                      <!--breadcrumbs start -->
                      <ul class="breadcrumb">
                          <li><a href="dashboard.php"><i class="icon_house_alt"></i> Home</a></li>
                          <li class="active"> Messages</li>
						  <li class="pull-right"> <i class="icon_calendar"></i>
							 <?php echo date('l jS F Y'); ?></li>
                      </ul>
                      <!--breadcrumbs end -->
                  </div>
              </div>
			  
			  <div class="row">
					<div class="col-lg-12">
					<section class="panel panel-body">
					<h3><?php echo WEB_NAME ?></h3>
					<h4>ACCOUNT MESSAGES</h4>
					</section>
					</div>
              </div>
			  
				<!-- Messages Starts -->
				<div class="row">
			    <div class="col-sm-12">
				
				<?php
					dbconnect();
					adm_read($_GET['msgid'], '1');
					$sql = "SELECT * FROM `".MSGS_TABLE_NAME."` WHERE msg_id='{$_GET['msgid']}'";
					$stmt = $pdo->query($sql);
					$row = $stmt->fetch(PDO::FETCH_ASSOC) 
				?>
					
				  <section class="panel">
					  <header class="panel-heading">
						  <?php echo $row['msg_subject']; ?>
					  </header>
					  
					  <div class="panel-body">
					  
					  <div class="panel panel-info">
					  <div class="panel-heading">
					  Sent by: <?php if ($row['msg_sender'] == "admin") { echo 
											"You"; }else{ echo $row['sender_name'];} ?> | To: <?php if ($row['msg_rcvr'] == "admin") { echo 
											"You"; }else{ echo get_username($row['msg_rcvr']);} ?>
						
						<div class="date pull-right">
						<?php echo date('jS F Y', strtotime($row['msg_date'])); ?>
						</div>
											
					  </div>
					  <div class="panel-content"><?php echo $row['msg_cnt']; ?></div>
					  </div>
					  
					  <?php
									dbconnect();
									$sql = "SELECT * FROM `".RPLY_TABLE_NAME."` WHERE msg_id='{$_GET['msgid']}'";
									$stmt = $pdo->query($sql);
									while($row = $stmt->fetch(PDO::FETCH_ASSOC)){  
									?>
					  
					  <div class="panel panel-success">
					  <div class="panel-heading">
					  Replied by: <?php if ($row['rply_sender'] == "admin") { echo 
											"You"; }else{ echo $row['sender_name'];} ?>
						
						<div class="date pull-right">
						<?php if ($row['rply_date'] == "") { echo ""; }else{ echo date('jS F Y', strtotime($row['rply_date']));} ?>  | 
											<a href="delete-reply.php?msgid=<?php echo $row['msg_id']; ?>&rplyid=<?php echo $row['rply_id']; ?>&acc=<?php echo $row['sender_name']; ?>" onclick="javascript:return confirm('Are you sure you want to delete this Reply?');">Delete</a>
						</div>
											
					  </div>
					  <div class="panel-content"><?php echo $row['rply_cnt']; ?></div>
					  </div>
					  <?php } ?>
					  
					  <div class="date pull-right">
					  <a href="messages.php" class="btn btn-default"><i class="icon-envelope"></i> Back to Messages</a>
					  
					  </div>
				  </section>
			  </div>
			  </div>
			  <!-- Messages end -->
			  
			  
			  <!-- Add Messages Starts -->
			  <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                              Reply Message
                          </header>
						  
						  <div class="panel-body">
						  
						  <!-- Error Message -->
							<?php if (!empty($_GET['error'])): ?>
							<div class="alert fade in alert-danger">
								<button data-dismiss="alert" class="close close-sm" type="button">
								<i class="icon-remove"></i>
								</button>
								<?php echo $_GET['error']?>
							</div>
							<?php endif ?>
							
							<!-- Success Message -->
							<?php if (!empty($_GET['msg'])): ?>
							<div class="alert fade in alert-success">
								<button data-dismiss="alert" class="close close-sm" type="button">
								<i class="icon-remove"></i>
								</button>
								<?php echo $_GET['msg']?>
							</div>
							<?php endif ?>
							
						  
                           <form method="post" enctype="multipart/form-data" class="form-validate form-horizontal" id="rply-form" action="replied.php">
								
								<div class="form-group">
									<label class="col-md-4 control-label">Message </label>
									<div class="col-md-6">
									
									<textarea rows="3" cols="5" name="rply_cnt" class="auto form-control required" placeholder="Enter your message" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 80px;" required></textarea>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-4 control-label"></label>
									<div class="col-md-6">
									
									<input type="hidden" name="rply_sender" value="admin">
										<input type="hidden" name="rply_rcvr" value="<?php echo $_GET['acc']; ?>">
										<input type="hidden" name="sender_name" value="Account Officer">
										<input type="hidden" name="msg_id" value="<?php echo $_GET['msgid']; ?>">
									
									<input type="submit" id="submit" name="submit" value="Send Reply" class="btn btn-primary pull-left">
									</div>
								</div>
							</form>
							
							</div>
                      </section>
                  </div>
              </div>
			  <!-- Add Messages end -->

              

          </section>
      </section>
      <!--main content end-->
  </section>
  <!-- container section start -->

    <!-- javascripts -->
    <script src="../js/jquery.js"></script>
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="../js/jquery-ui-1.9.2.custom.min.js"></script>
    <!-- bootstrap -->
    <script src="../js/bootstrap.min.js"></script>
    <!-- nice scroll -->
    <script src="../js/jquery.scrollTo.min.js"></script>
    <script src="../js/jquery.nicescroll.js" type="text/javascript"></script>
	
	<!-- jquery validate js -->
    <script type="text/javascript" src="../js/jquery.validate.min.js"></script>

    <!-- custom form validation script for this page-->
    <script src="../js/form-validation-script.js"></script>

    <!-- custom select -->
    <script src="../js/jquery.customSelect.min.js" ></script>
    <!--custome script for all page-->
    <script src="../js/scripts.js"></script>

  </body>
</html>