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

<html>

<head>

<?php kheader(); ?>



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

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

<style>

.checkbox

{display: inline-table !important;}

</style>

</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 id="wholebody">

            <div class="container-fluid">

<div class="row">

        <div class="col-sm-3 col-md-2">

            <div class="btn-group">

                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">

                    Mail <span class="caret"></span>

                </button>

                <ul class="dropdown-menu" role="menu">

                    <li><a href="#">Mail</a></li>

                    <li><a href="#">Contacts</a></li>

                    <li><a href="#">Tasks</a></li>

                </ul>

            </div>

        </div>



<div class="col-sm-9 col-md-10">

            <!-- Split button -->

            <div class="btn-group">

                

                

                

            </div>



            

                    </div>

    </div>

    <hr />



    <div class="row">

        <?php

        

        echo $rolenumber;

        if(isset($_POST["delete_mess"])){



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

        $result_message=$dbh->query("select * from message where recepient like '%$rolenumber%' and deleters not like '%$rolenumber%'");

                        $row_message=$result_message->fetchObject();

                        $count_message=$result_message->rowCount();



        if($count_message>0){

            $rolenumber=$_SESSION["rolenumber"];

            do{

            if(isset($_POST["chk".$row_message->autoid.""])){

                $chk=$_POST["chk".$row_message->autoid.""];





$result_deleters=$dbh->query("select * from message where recepient like '%$rolenumber%'");

$row_deleters=$result_deleters->fetchObject();

$count_deleters=$result_deleters->rowCount();



$deleterstatus=$row_deleters->deleters;

$newdeleterstatus=$deleterstatus.",".$rolenumber;





                $update_message=$dbh->query("update message set deleters='$newdeleterstatus' where messageid='$chk'");

            }

        }while($row_message=$result_message->fetchObject());

        }

        }



        ?>

        <form method='post'>

        <?php include("message_menu.php"); ?>

        <div class="col-sm-9 col-md-10">

           



            <div class="tab-content">

                <div class="tab-pane fade in active" id="home">

                    <div class="list-group">

                        

                        <?php

if(isset($_GET["msgt"])&&($_GET["msgt"]=='inb' or $_GET["msgt"]=='unr' or $_GET["msgt"]=='tra')){

if ($_GET['msgt']=='inb'){

$result_message=$dbh->query("select * from message where recepient like '%$rolenumber%' and deleters not like '%$rolenumber%'");

                        $row_message=$result_message->fetchObject();

                        $count_message=$result_message->rowCount();

                    }



elseif ($_GET['msgt']=='unr'){

                        $result_message=$dbh->query("select * from message where recepient like '%$rolenumber%' and dateread not like '%$rolenumber%' and deleters not like '%$rolenumber%'");

                        $row_message=$result_message->fetchObject();

                        $count_message=$result_message->rowCount();

                    }



elseif ($_GET['msgt']=='tra'){

                        $result_message=$dbh->query("select * from message where recepient like '%$rolenumber%' and deleters like '%$rolenumber%'");

                        $row_message=$result_message->fetchObject();

                        $count_message=$result_message->rowCount();

                    }



                        if($count_message>0){

                            do{



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

                        $row_users=$result_users->fetchObject();



                        echo $rolenumber."

                       <div class='list-group-item'>

                            <span class='checkbox'>

                                <label>

                                    <input type='checkbox' name='chk".$row_message->autoid."' value='".$row_message->messageid."'>

                                </label>

                            </span>

                            



                          <a href='messagerd.php?messageid=".$row_message->messageid."'>

                              <span class='name' style='min-width: 120px; display: inline-block;'>".$row_users->firstname." ".$row_users->lastname."</span> <span class=''>".$row_message->message."</span>

                             <span class='badge' style='float:right;'>".$row_message->dater."</span>



                                </a></div></form>";

                            }while($row_message=$result_message->fetchObject());



                            }else{

                        echo "

                        <a href='#' class='list-group-item'>

                            <span class='text-muted' style='font-size: 14px;'>There are no messages in this section</span>

                            </a>";

                            }

}

else {echo "</a><a href='#' class='list-group-item'>

                            <span class='text-muted' style='font-size: 14px;'>Ooops! You made a wrong selection :-(</span>

                            </a>";}

                                ?>













                    </div>





                </div>

                <div class="tab-pane fade in" id="profile">

                    <div class="list-group">

                        <div class="list-group-item">

                            <span class="text-center">This tab is empty.</span>

                        </div>

                    </div>

                </div>

                <div class="tab-pane fade in" id="messages">

                    ...</div>

                <div class="tab-pane fade in" id="settings">

                    This tab is empty.</div>

            </div>

            <!-- Ad -->

            







    </div>



        </div>

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



    </div>

    </div>

    <!-- /#wrapper -->

<script>

function sender(){

var selectedusers = document.getElementById("selectedusers");

var values = [];



<?php

$rolenumber=$_SESSION["rolenumber"];

$result_users=$dbh->query("select * from users where lastname!='' and rolenumber!='$rolenumber' and (status='active' or status='1')");

$row_users=$result_users->fetchObject();

$count_users=$result_users->rowCount();

if($count_users>0){

    do{

?>

if(document.getElementById("chkout<?php echo $row_users->autoid; ?>").checked) {

 var user = document.getElementById("chkout<?php echo $row_users->autoid; ?>").value;

  values.push(user);

}

<?php

}while($row_users=$result_users->fetchObject());

}

?>

selectedusers.value = values.join(", ");

}

</script>

    <!-- jQuery -->

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



    <!-- Bootstrap Core JavaScript -->

    



</body>



</html>

