<?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>MESSAGES</h4>
					<p>Find below messages from clients to account officer</p>
					</section>
					</div>
              </div>
			  
				<!-- Messages Starts -->
				<div class="row">
			    <div class="col-sm-12">
				  <section class="panel">
					  <header class="panel-heading">
						  Account Messages
					  </header>
					  <table class="table table-hover">
						  <thead>
						  <tr>
						    <th>Sender</th>
							<th>Subject</th>
							<th>Date</th>
							<th>Delete</th>
						  </tr>
						  </thead>
						  <tbody>					  
						  <?php
								dbconnect();
								$sql = "SELECT * FROM `".MSGS_TABLE_NAME."` WHERE msg_rcvr='admin' OR msg_sender='admin' ORDER BY msg_id DESC";
								$stmt = $pdo->query($sql);
								while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ 
							?>
						  <tr style="background-color:<?php if ($row['adm_read'] == "0") { echo '#d9edf7'; }else{ echo "";} ?>;">
							  <td><a href="message-details.php?msgid=<?php echo $row['msg_id']; ?>&acc=<?php echo $row['msg_rcvr']; ?>">
								<?php if ($row['msg_sender'] == "admin") { echo 
											"You"; }else{ echo $row['sender_name'];} ?>
								</a></td>
								<td><a href="message-details.php?msgid=<?php echo $row['msg_id']; ?>&acc=<?php echo $row['msg_rcvr']; ?>"><?php echo $row['msg_subject']; ?></a></td>
								<td><a href="message-details.php?msgid=<?php echo $row['msg_id']; ?>&acc=<?php echo $row['msg_rcvr']; ?>"><?php echo date('jS F Y', strtotime($row['msg_date'])); ?></a></td>
								
								<td><a href="delete-message.php?msgid=<?php echo $row['msg_id']; ?>&acc=<?php echo $row['msg_rcvr']; ?>" onclick="javascript:return confirm('Are you sure you want to delete this Message?');" class="btn btn-danger btn-rad">Delete</a></td>
								
						  </tr>
						  <?php } ?>
						  </tbody>
					  </table>
				  </section>
			  </div>
			  </div>
			  <!-- Messages end -->
			  
			  
			  <!-- Add Messages Starts -->
			  <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                              Add New 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="msg-form" action="sent.php">
								
								<div class="form-group">
								
								<?php
										dbconnect();
										$sql = "SELECT user_name, user_acc FROM `".USERS_TABLE_NAME."` WHERE user_status='1' ORDER BY user_name ASC";
										$stmt = $pdo->query($sql);
										?>
									<label class="col-md-4 control-label">To </label>
									<div class="col-md-6">
										<select id="msg_rcvr" name="msg_rcvr" class="form-control" required>

<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>
											<option value='<?php echo $row['user_acc']; ?>'><?php echo $row['user_name']; ?>
											</option>
												<?php }  ?>
											</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-4 control-label">Subject </label>
									<div class="col-md-6">
										<input type="text" name="msg_subject" class="form-control required" placeholder="Enter your message subject" required>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-4 control-label">Message </label>
									<div class="col-md-6">
									
									<textarea rows="3" cols="5" name="msg_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="msg_sender" value="admin">
										<input type="hidden" name="sender_name" value="Account Officer">
										<input type="hidden" name="msg_read" value="0">
										<input type="hidden" name="adm_read" value="1">
									
									<input type="submit" id="submit" name="submit" value="Send Message" 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>