<?php include ("../core/kfunctions.php")?>

<html>

<head>

<?php kheader(); ?>

<?php 

require_once("../core/connect.php");

$result=$dbh->query("select * from scrap");



?>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

</head>

<body>



    <div id="wrapper">



        <!-- Navigation -->

        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">

            <!-- Brand and toggle get grouped for better mobile display -->

            <?php ktopbar(); ?>

            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->

            <?php kleftbar(); ?>

            <!-- /.navbar-collapse -->

        </nav>



        <div id="page-wrapper">



            <div class="container-fluid">



                <!-- Page Heading -->

                <div class="row">

                    <div class="col-lg-12">

                        <h1 class="page-header">

                            Messages

                        </h1>

                       <?php

					   

					  $status = $_GET["status"];

					  $id = $_GET["id"];

					  

					   if(isset($_POST['submit'])){

$recepient=$_POST['recepient'];

$message=$_POST['message'];

$sender=$names;

require_once('../core/connect.php');



$rolenumber=$_SESSION["rolenumber"];



$result2=$dbh->query("select * from users where rolenumber='$rolenumber'");

$row2=$result2->fetchObject();



$autoid=$row2->autoid;

$mth = date("m");

$dy = date("d");

$min = date("i");

$yr = date("Y");

$finalyr = substr($yr,2,2);





$messageid = $autoid.$finalyr.$mth.$dy.$min;



$count=$dbh->exec("insert into message (recepient,message,sender,messageid) values('$recepient','$message','$names','$messageid')");



$messresult=$dbh->query("select * from users where rolenumber='$recepient'");

$messrow=$messresult->fetchObject();



echo "<div style='width:49%; text-align:center;' class='alert alert-success'>".date("h:i:sa")."&nbsp;"."Message sent to ".$messrow->firstname."&nbsp;".$messrow->lastname."</div>";

					   }

?>





                    </div>

                </div>

                

<form method="post">

                <!-- /.row -->



                <div class="row">

                    <div class="col-lg-6">

                        <div class="panel panel-default">

                            <div class="panel-body">

                            

<div class="panel panel-green"><!--Initiative-->

<div class="panel-heading"><h3 class="panel-title">Select the receipent and enter the message to send</h3></div>

<div class="panel-body">

<?php

require_once('../core/connect.php');

$col=$dbh->query("select * from users and about!='supervisor double'");

$rower=$col->fetchObject();







?>



<div class="col-lg-8">

<select id="recepient" name="recepient" class="form-control">

<option value="none">Select recepient</option>

<?php

do{

$rolenumberz = $_SESSION["rolenumber"];

	

echo "

<option value=".$rower->rolenumber.">".$rower->firstname."&nbsp;".$rower->lastname."&nbsp;"."</option>";

}while($rower=$col->fetchObject())

?>

</select>

</div>

</div>

<div class="row">

                    <div class="col-lg-12 text-center">

                        

                            <div class="panel-body">

                                <textarea type="text" name="message"  class="form-control" placeholder="Type your message here"></textarea>  <br>



                          <div class="col-lg-3" align="left">

<input type="submit" name='submit' class="btn btn-sm btn-danger" value="Send"></form>             </div>  </div>

                                                    </div>

                    



                </div>

</div>











</div>

                            </div> </div>

                    </div>

                </div>

                <!-- /.row -->



             



            </div>

            <!-- /.container-fluid -->



        </div>

        <!-- /#page-wrapper -->



    </div>

    <!-- /#wrapper -->



    <!-- jQuery -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>



    <!-- Bootstrap Core JavaScript -->

    <script src="../js/bootstrap.min.js"></script>



</body>



</html>

