<?php
   function createRandomPassword()
   {
   $chars = "003232303232023232023456789";
   srand((double)microtime()*1000000);
   $i = 0;
   $pass = '' ;
   while ($i <= 7) {
   $num = rand() % 33;
   $tmp = substr($chars, $num, 1);
   $pass = $pass . $tmp;
   $i++;
   }
   return $pass;
   }
   $sess=createRandomPassword();
   ?>
<div class="content-wrapper">
   <!-- Content Header (Page header) -->
   <div class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h5 class="m-0 card-title">Messaging Management Module</h5>
            </div>
            <!-- /.col -->
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item">Dashboard</li>
                  <li class="breadcrumb-item">Extra</li>
                  <li class="breadcrumb-item active"> Messages</li>
               </ol>
            </div>
            <!-- /.col -->
         </div>
         <!-- /.row -->
      </div>
   </div>
<?php
if($posi=='Teacher')
{
 ?>
 <section class="content">
  <ul class="nav nav-tabs">
          <li class="nav-item">
            <a class="nav-link" data-toggle="tab" href="#exammessages"> Exam Results Messages <i class="fa fa-file"></i></a>
         </li>
  </ul>
  <div class="tab-content">
       <div id="exammessages" class="container tab-pane active">
         <div class="row">
             <div class="col-sm-5">
                <div class="form-group">
                      <label for="inputStatus">Select Exam <span class="requireds">*</span></label>
                      <select id="examuid" class="form-control custom-select" required>
                        <option selected value="">...</option>
                        <?php
                        $query=mysqli_query($con,"select * from Exam ORDER BY id DESC");
                        while($row=mysqli_fetch_array($query))
                        {
                        ?>
                        <option value="<?php echo $row["id"]; ?>"><?php echo $row["Title"].' -> ('.$row["Year"].' - '.$row["Term"].' - '.$row["Period"].')'; ?></option>
                        <?php
                         }
                         ?>
                     </select>
                 </div>
             </div>
             <div class="col-sm-4">
                <div class="form-group">
                  <label for="inputStatus">Select Class <span class="requireds">*</span></label>
                  <select id="darasa" class="form-control custom-select" required>
                    <option selected value="">Select Class ---</option>
                    <option value="GRADE 1">GRADE 1</option>
                    <option value="GRADE 2">GRADE 2</option>
                    <option value="GRADE 3">GRADE 3</option>
                    <option value="GRADE 4">GRADE 4</option>
                    <option value="GRADE 5">GRADE 5</option>
                    <option value="GRADE 6">GRADE 6</option>
                    <option value="GRADE 7">GRADE 7</option>
                    <option value="GRADE 8">GRADE 8</option>
                    <option value="GRADE 9">GRADE 9</option>
                  </select>
                </div> 
             </div>
             
             <div class="col-sm-9">
               <div class="table-responsive" style="max-height:500px; overflow-y:scroll">
                  <table class="table table-hover table-sm table-d" id="selectedclazexamtable" style="font-size:12px">
                    <thead>
                    <tr>
                        <th class="text-danger" colspan="4">
                          Send exam results to parents
                        </th>
                    </tr>
                    <tr class="">
                       <th colspan="">  </th>
                       <th colspan="">  </th>
                       <th colspan="2"> </th>
                       <th colspan="9"> <label class="text-orange"> Select/Unselect All </label>  <input type="checkbox" class="pull-right" id="selectAllcandidates" /></th>
                    </tr>
                    <tr id="lowerone" style="font-size:11px">
                       <th>#</th>
                       <th>Pupil</th>
                       <th>Class</th>
                       <th>Contact</th>
                       <th>Maths</th>
                       <th>Kis</th>
                       <th>Eng</th>
                       <th>CRE</th>
                       <th>CRA</th>
                       <th>Envi. A.</th>
                       <th>Total</th>
                       <th>Action</th>
                    </tr>
                    
                     <tr id="upperone" style="display:none">
                        <th>#</th>
                        <th>Pupil</th>
                        <th>Class</th>
                        <th>Contact</th>
                        <th>Maths</th>
                        <th>Kis</th>
                        <th>Eng</th>
                        <th>CRE</th>
                        <th>CRA</th>
                        <th>SS</th>
                        <th>IS</th>
                        <th>Agri</th>
                        <th>Total</th>
                        <th>Action</th>
                    </tr>
                    
                    <tr id="uppertwo" style="display:none">
                        <th>#</th>
                        <th>Pupil</th>
                        <th>Class</th>
                        <th>Contact</th>
                        <th>Maths</th>
                        <th>Kis</th>
                        <th>Eng</th>
                        <th>CRE</th>
                        <th>CRA</th>
                        <th>SS</th>
                        <th>IS</th>
                        <th>Agri</th>
                        <th>Pretech</th>
                        <th>Total</th>
                        <th>Action</th>
                    </tr>
                    </thead>
                    <tbody id="selectedclazexam">
                        
                    </tbody>
                  </table>
                  </div>   
             </div>
             
             <div class="col-sm-3">
                <table class="table">
                    <tr>
                       <td><em style="font-size:10px">Dear Parent your child (Name) attained the following in xxxx exam: Exam results </em></td>
                    </tr>
                    <tr>
                        <td colspan="">
                            <label id="labelexammessage"></label>
                            <button class="btn btn-dark btn-sm pull-right" id="submitresults">Send Results <i class="fa fa-paper-plane"></i></button>
                        </td>
                    </tr>
                </table>
             </div>
             
             <div class="col-sm-8">
                <hr />
                <h6 class="alert-warning">
                <center>Latest Sent Messages</center>
                </h6>
                <table class="table table-hover" id="sentresults" style="font-size:12px;font-family:Arial">
                <thead>
                <tr class="alert-warning">
                    <th>#</th>
                    <th>Parent Name </th>
                    <th>Sent to </th>
                    <th>Message</th>
                    <th>Sent By</th>
                    <th>Date</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                    $query=mysqli_query($con,"select exammessages.*,pupils.PName as pare,pupils.Names as lana,Staffs.Name as uza from exammessages left join Staffs ON Staffs.id=exammessages.User left join pupils ON pupils.count=exammessages.pid  ORDER BY id DESC limit 600");
                    $cnt=1;
                    while($row=mysqli_fetch_array($query))
                    {
                    ?>  
                    <tr class="row-select">
                    <td><?php echo $cnt; ?></td>
                    <td><?php echo $row["pare"]; ?></td>
                    <td class="alert-success"><?php echo $row["Phone"]; ?></td>
                    <td class="alert-secondary"><?php echo $row["Msg"]; ?></td>
                    <td><?php echo $row["uza"]; ?></td>
                    <td class="text-danger"><?php echo $row["Dat"]; ?></td>
                    </tr>
                    <?php  
                    $cnt=$cnt+1;
                    }
                    ?>
                </tbody>
                </table> 
             </div>
         </div>
      </div>  
  </div>
  </section>
 <?php
}else
{
    ?>
   <section class="content">
      <ul class="nav nav-tabs">
         <li class="nav-item">
            <a class="nav-link active" data-toggle="tab" href="#mess"> Single Message <i class="fa fa-user"></i></a>
         </li>
         <li class="nav-item">
            <a class="nav-link" data-toggle="tab" href="#emai"> Message to Staffs <i class="fa fa-group"></i></a>
         </li>
          <li class="nav-item">
            <a class="nav-link" data-toggle="tab" href="#toparents"> Message to Parents <i class="fa fa-group"></i></a>
         </li>
          <li class="nav-item">
            <a class="nav-link" data-toggle="tab" href="#exammessages"> Exam Results Messages <i class="fa fa-file"></i></a>
         </li>
          <li class="nav-item">
            <a class="nav-link" data-toggle="tab" href="#Balancemessages"> Fee Balance Messages <i class="fa fa-dollar"></i></a>
         </li>
      </ul>
      <div class="tab-content">
         <div id="mess" class="container tab-pane active"> 
           <hr />
                  <form method="POST" id="" enctype="multipart/form-data" onsubmit="return false">
                     <div class="row">
                        <div class="col-md-5">
                           <div class="card card-primary">
                              <div class="card-header">
                                 <h3 class="card-title">Compose Message</h3>
                                 <div class="card-tools">
                                    <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                                    <i class="fas fa-minus"></i>
                                    </button>
                                 </div>
                              </div>
                              <div class="card-body">
                                 <div class="form-group">
                                    <label for="inputName">Contact <span class="text-danger">*</span></label>
                                    <input type="text" id="conta" class="form-control" required>
                                 </div>
                                 <div class="form-group">
                                    <label for="inputDescription">Message <span class="text-danger">*</span></label>
                                    <textarea class="tinymce-editor form-control" id="themsg" required></textarea>
                                 </div>
                    
                                 <div class="form-group">
                                    <input type="hidden" id="txtsession" name="" value="<?php echo $sess; ?>" />
                                    <center><label id="feedmesg"></label></center>
                                 </div>
                                 
                                 <div class="form-group">
                                    <button class="btn btn-success pull-right" id="singlemsg" disabled>Send <i class="fa fa-paper-plane"></i></button>
                                 </div>
                              </div>
                           </div>
                        </div>
                        <div class="col-md-7 col-sm-6">
                        <h6 class="alert-success">
                         <center>Latest Sent Messages</center>
                      </h6>
                      <table class="table table-hover table-dark table-sm" id="tablemails" style="font-size:12px;font-family:Arial">
                         <thead>
                            <tr class="alert-warning">
                               <th>#</th>
                               <th>Sent To </th>
                               <th>Message</th>
                               <th>Date</th>
                               <th>Sent By</th>
                            </tr>
                         </thead>
                         <tbody>
                            <?php
                               $query=mysqli_query($con,"select emails.*,Staffs.Name as snam from emails left join Staffs ON Staffs.id=emails.User where emails.sid='' ORDER BY eid DESC");
                               $cnt=1;
                               while($row=mysqli_fetch_array($query))
                               {
                                 ?>  
                            <tr class="row-select">
                               <td><?php echo $cnt; ?></td>
                               <td><?php echo $row["Phone"]; ?></td>
                               <td class="alert-success"><?php echo $row["Msg"]; ?></td>
                               <td class="text-danger"><?php echo $row["Dat"]; ?></td>
                               <td ><?php echo $row["snam"]; ?></td>
                            </tr>
                            <?php  
                               $cnt=$cnt+1;
                               }
                               ?>
                         </tbody>
                      </table>
                        </div>
                        
                     </div>
                  </form>
         </div>
         
         <div id="emai" class="container tab-pane">
            <div class="row">
               <div class="col-md-8">
                  <div class="card ">
                     <div class="card-header">
                        <div class="card-body">
                        
                           <div class="table-responsive" id=''>
                              <h5 class="alert-danger">
                                 <center>Select Recipients of your message</center>
                              </h5>
                              <div class="table-responsive" style="max-height:500px; overflow-y:scroll">
                              <table class="table table-hover table-sm table-d" id="tableemployees" style="font-size:12px">
                                 <thead>
                                    <tr class="">
                                       <th colspan=""></th>
                                       <th colspan=""></th>
                                       <th colspan="2">
                                       </th>
                                       <th colspan="2"><label class="text-orange"> Select/Unselect All </label>  <input type="checkbox" class="pull-right" id="selectAll" /></th>
                                    </tr>
                                    <tr>
                                       <th>#</th>
                                       <th>Staff</th>
                                       <th>Nature of Work</th>
                                       <th>Contact</th>
                                       <th>Action</th>
                                    </tr>
                                 </thead>
                                 <tbody>
                                    <?php
                                       $query=mysqli_query($con,"select * from Staffs where Status='Active' AND Phone !='' ORDER BY Name ASC");
                                       $cnt=1;
                                       while($row=mysqli_fetch_array($query))
                                       {
                                         ?>  
                                    <tr class="row-select">
                                       <td><?php echo $cnt; ?></td>
                                       <td><?php echo $row["Name"]; ?></td>
                                       <td><?php echo $row["Nature"]; ?></td>
                                       <td><?php echo $row["Phone"]; ?></td>
                                       <td>
                                          <input type="hidden" class="contact" value="<?php echo $row["Phone"]; ?>" />
                                          <input type="hidden" class="Staffsid" value="<?php echo $row["id"]; ?>" />
                                          <input type="checkbox" name='checkbox[$rowid]' value="<?php echo $row["id"]; ?>">
                                       </td>
                                    </tr>
                                    <?php  
                                       $cnt=$cnt+1;
                                       }
                                       ?>
                                 </tbody>
                              </table>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
               <div class="col-md-4">
                  <form method="POST" action="" id="" enctype="multipart/form-data" novalidate onsubmit="return false;">
                     <div class="row">
                        <div class="col-md-12">
                           <div class="card card-primary">
                              <div class="card-header">
                                 <h3 class="card-title">Compose Text</h3>
                                 <div class="card-tools">
                                    <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                                    <i class="fas fa-minus"></i>
                                    </button>
                                 </div>
                              </div>
                              <div class="card-body">
                                 <div class="form-group">
                                    <label for="inputDescription">Compose Message <span class="text-danger">*</span></label>
                                    <textarea class="tinymce-editor form-control" id="mainmess" required></textarea>
                                 </div>
                              
                                 <div class="form-group">
                                    <input type="hidden" id="txtsession" name="" value="<?php echo $sess; ?>" />
                                    <center><label id="feedbackemails"></label></center>
                                 </div>
                                 <div class="form-group">
                                    <center><label class="text-danger"><em>Message will be sent to selected Staffs only</em></label></center>
                                    <button class="btn btn-success pull-right" id="subemail" disabled>Send <i class="fa fa-paper-plane"></i></button>
                                 </div>
                              </div>
                           </div>
                           <!-- /.card -->
                        </div>
                     </div>
                  </form>
               </div>
               
              <div class="col-md-8">
                <hr />
                <h6 class="alert-success">
                <center>Latest Sent Messages</center>
                </h6>
                <table class="table table-hover" id="stafftexts" style="font-size:12px;font-family:Arial">
                <thead>
                <tr class="alert-warning">
                    <th>#</th>
                    <th>Recipient </th>
                    <th>Message</th>
                    <th>Sent By</th>
                    <th>Date</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                    $query=mysqli_query($con,"select emails.*,Staffs.Name as snam from emails left join Staffs ON Staffs.id=emails.sid where emails.ESent='Yes'  ORDER BY eid DESC");
                    $cnt=1;
                    while($row=mysqli_fetch_array($query))
                    {
                    ?>  
                    <tr class="row-select">
                    <td><?php echo $cnt; ?></td>
                    <td><?php echo $row["snam"]; ?></td>
                    <td><?php echo $row["Msg"]; ?></td>
                     <td><?php echo $row["UserName"]; ?></td>
                    <td class="text-danger"><?php echo $row["Dat"]; ?></td>
                    </tr>
                    <?php  
                    $cnt=$cnt+1;
                    }
                    ?>
                </tbody>
                </table>
              </div> 
            </div>
         </div>
         
       <div id="toparents" class="container tab-pane">
         <div class="row">
                <div class="col-md-8">
                  <div class="card ">
                     <div class="card-header">
                        <div class="card-body">
                              <form method="post" action="">
                                <div class="form-group">
                                  <label for="inputStatus">Filter Parents by Class <span class="requireds">*</span></label>
                                  <span>NB: <em class="text-danger">Only parents whose phones numbers are set will displayed here</em></span>
                                  <select id="recipintparents" class="form-control custom-select" required>
                                    <option selected value="">Select Class ---</option>
                                    <option value="BABY CLASS">BABY CLASS</option>
                                    <option value="PP1">PP1</option>
                                    <option value="PP2">PP2</option>
                                    <option value="GRADE 1">GRADE 1</option>
                                    <option value="GRADE 2">GRADE 2</option>
                                    <option value="GRADE 3">GRADE 3</option>
                                    <option value="GRADE 4">GRADE 4</option>
                                    <option value="GRADE 5">GRADE 5</option>
                                    <option value="GRADE 6">GRADE 6</option>
                                    <option value="GRADE 7">GRADE 7</option>
                                    <option value="GRADE 8">GRADE 8</option>
                                    <option value="GRADE 9">GRADE 9</option>
                                  </select>
                               </div>
                            </form>  
                            
                           <div class="table-responsive" id=''>
                              <h5 class="alert-danger">
                                 <center>Select Recipients of your message</center>
                              </h5>
                              <div class="table-responsive" style="max-height:500px; overflow-y:scroll">
                              <table class="table table-hover table-sm table-d" id="mapupils" style="font-size:12px">
                                 <thead>
                                    <tr class="">
                                       <th colspan=""></th>
                                       <th colspan=""></th>
                                       <th colspan="2">
                                       </th>
                                       <!--th colspan="2"><label class="text-orange"> Select/Unselect All </label>  <input type="checkbox" class="pull-right" id="selectAllpa" /></th-->
                                    </tr>
                                    <tr>
                                       <th>#</th>
                                       <th>Pupil</th>
                                       <th>Class</th>
                                       <th>Parent Name</th>
                                       <th>Contact</th>
                                    </tr>
                                 </thead>
                                 <tbody id="selectedclaz">
                                 </tbody>
                              </table>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
               
            <div class="col-md-4">
                  <form method="POST" action="" id="" enctype="multipart/form-data" novalidate onsubmit="return false;">
                     <div class="row">
                        <div class="col-md-12">
                           <div class="card card-primary">
                              <div class="card-header">
                                 <h3 class="card-title">Compose Text</h3>
                                 <div class="card-tools">
                                    <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                                    <i class="fas fa-minus"></i>
                                    </button>
                                 </div>
                              </div>
                              <div class="card-body">
                                 <div class="form-group">
                                    <label for="inputDescription">Compose Message <span class="text-danger">*</span></label>
                                    <textarea class="form-control" id="messtopare" required></textarea>
                                 </div>
                              
                                 <div class="form-group">
                                    <input type="hidden" id="txtsession" name="" value="<?php echo $sess; ?>" />
                                    <center><label id="feedmesstopare"></label></center>
                                 </div>
                                 <div class="form-group">
                                    <center><label class="text-danger"><em>Message will be sent to selected parents only</em></label></center>
                                    <!--button class="btn btn-success pull-right" id="subtext">Next <i class="fa fa-paper-plane"></i></button-->
                                    <button class="btn btn-info btn-sm pull-right" id="bnext" disabled>Next <i class="fa fa-arrow-right"></i></button>
                                 </div>
                              </div>
                           </div>
                           <!-- /.card -->
                        </div>
                        <div class="col-md-12">
                           <div class="form-group">
                              <label class=""> Latest Messages Sessions </label>
                              <select class="form-control" id="compses">
                                   <option value="">---</option>
                                    <?php
                                    $query=mysqli_query($con,"select * from SS GROUP by Ses ORDER BY id DESC");
                                    while($row=mysqli_fetch_array($query))
                                    {
                                     ?>
                                     <option value="<?php echo $row["Ses"]; ?>"><?php echo $row["Ses"]; ?></option>
                                     <?php
                                    }
                                    ?>
                             </select>
                           </div>
                        </div>
                     </div>
                  </form>
               </div>
               
               <div class="col-md-8">
                <hr />
                <h6 class="alert-success">
                <center>Latest Sent Messages</center>
                </h6>
                <table class="table table-hover" id="Tparentsmessage" style="font-size:12px;font-family:Arial">
                <thead>
                <tr class="alert-warning">
                    <th>#</th>
                    <th>Parent Name </th>
                    <th>Contant </th>
                    <th>Leaner</th>
                    <th>Message</th>
                    <th>Sent By</th>
                    <th>Date</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                    $query=mysqli_query($con,"select parentsmessages.*,pupils.PName as pare,pupils.Names as lana from parentsmessages left join pupils ON pupils.count=parentsmessages.pid ORDER BY id DESC");
                    $cnt=1;
                    while($row=mysqli_fetch_array($query))
                    {
                    ?>  
                    <tr class="row-select">
                    <td><?php echo $cnt; ?></td>
                    <td><?php echo $row["pare"]; ?></td>
                    <td><?php echo $row["Phone"]; ?></td>
                    <td><?php echo $row["lana"]; ?></td>
                    <td class="alert-secondary"><?php echo $row["Msg"]; ?></td>
                    <td><?php echo $row["UserName"]; ?></td>
                    <td class="text-danger"><?php echo $row["Dat"]; ?></td>
                    </tr>
                    <?php  
                    $cnt=$cnt+1;
                    }
                    ?>
                </tbody>
                </table>
              </div>
         </div>
       </div>
       
       <div id="exammessages" class="container tab-pane">
         <div class="row">
             <div class="col-sm-5">
                <div class="form-group">
                      <label for="inputStatus">Select Exam <span class="requireds">*</span></label>
                      <select id="examuid" class="form-control custom-select" required>
                        <option selected value="">Select Exam</option>
                        <?php
                        $query=mysqli_query($con,"select * from Exam ORDER BY id DESC");
                        while($row=mysqli_fetch_array($query))
                        {
                        ?>
                        <option value="<?php echo $row["id"]; ?>"><?php echo $row["Title"].' -> ('.$row["Year"].' - '.$row["Term"].' - '.$row["Period"].')'; ?></option>
                        <?php
                         }
                         ?>
                     </select>
                 </div>
             </div>
             <div class="col-sm-4">
                <div class="form-group">
                  <label for="inputStatus">Select Class <span class="requireds">*</span></label>
                  <select id="darasa" class="form-control custom-select" required>
                    <option selected value="">Select Class ---</option>
                    <option value="GRADE 1">GRADE 1</option>
                    <option value="GRADE 2">GRADE 2</option>
                    <option value="GRADE 3">GRADE 3</option>
                    <option value="GRADE 4">GRADE 4</option>
                    <option value="GRADE 5">GRADE 5</option>
                    <option value="GRADE 6">GRADE 6</option>
                    <option value="GRADE 7">GRADE 7</option>
                    <option value="GRADE 8">GRADE 8</option>
                    <option value="GRADE 9">GRADE 9</option>
                  </select>
                </div> 
             </div>
             
             <div class="col-sm-9">
               <div class="table-responsive" style="max-height:500px; overflow-y:scroll">
                  <table class="table table-hover table-sm table-d" id="selectedclazexamtable" style="font-size:12px">
                    <thead>
                    <tr>
                        <th class="text-danger" colspan="4">
                          Send Exam results to parents
                        </th>
                    </tr>
                    <tr class="">
                       <th colspan="">  </th>
                       <th colspan="">  </th>
                       <th colspan="2"> </th>
                       <th colspan="9"> <label class="text-orange"> Select/Unselect All </label>  <input type="checkbox" class="pull-right" id="selectAllcandidates" /></th>
                    </tr>
                    <tr id="lowerone" style="font-size:11px">
                       <th>#</th>
                       <th>Pupil</th>
                       <th>Class</th>
                       <th>Contact</th>
                       <th>Maths</th>
                       <th>Kis</th>
                       <th>Eng</th>
                       <th>CRE</th>
                       <th>CRA</th>
                       <th>Envi. A.</th>
                       <th>Total</th>
                       <th>Action</th>
                    </tr>
                    
                     <tr id="upperone" style="display:none">
                        <th>#</th>
                        <th>Pupil</th>
                        <th>Class</th>
                        <th>Contact</th>
                        <th>Maths</th>
                        <th>Kis</th>
                        <th>Eng</th>
                        <th>CRE</th>
                        <th>CRA</th>
                        <th>SS</th>
                        <th>IS</th>
                        <th>Agri</th>
                        <th>Total</th>
                        <th>Action</th>
                    </tr>
                    
                    <tr id="uppertwo" style="display:none">
                        <th>#</th>
                        <th>Pupil</th>
                        <th>Class</th>
                        <th>Contact</th>
                        <th>Maths</th>
                        <th>Kis</th>
                        <th>Eng</th>
                        <th>CRE</th>
                        <th>CRA</th>
                        <th>SS</th>
                        <th>IS</th>
                        <th>Agri</th>
                        <th>Pretech</th>
                        <th>Total</th>
                        <th>Action</th>
                    </tr>
                    </thead>
                    <tbody id="selectedclazexam">
                        
                    </tbody>
                  </table>
                  </div>   
             </div>
             
             <div class="col-sm-3">
                <table class="table">
                    <tr>
                       <td><em style="font-size:10px">Dear Parent your child (Name) attained the following in xxxx exam: Exam results </em></td>
                    </tr>
                    <tr>
                        <td colspan="">
                            <label id="labelexammessage"></label>
                            <button class="btn btn-dark btn-sm pull-right" id="submitresults" disabled>Send Results <i class="fa fa-paper-plane"></i></button>
                        </td>
                    </tr>
                </table>
             </div>
             
             <div class="col-sm-8">
                <hr />
                <h6 class="alert-warning">
                <center>Latest Sent Messages</center>
                </h6>
                <table class="table table-hover" id="sentresults" style="font-size:12px;font-family:Arial">
                <thead>
                <tr class="alert-warning">
                    <th>#</th>
                    <th>Parent Name </th>
                    <th>Sent to </th>
                    <th>Message</th>
                    <th>Sent By</th>
                    <th>Date</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                    $query=mysqli_query($con,"select exammessages.*,pupils.PName as pare,pupils.Names as lana,Staffs.Name as uza from exammessages left join Staffs ON Staffs.id=exammessages.User left join pupils ON pupils.count=exammessages.pid  ORDER BY id DESC limit 600");
                    $cnt=1;
                    while($row=mysqli_fetch_array($query))
                    {
                    ?>  
                    <tr class="row-select">
                    <td><?php echo $cnt; ?></td>
                    <td><?php echo $row["pare"]; ?></td>
                    <td class="alert-success"><?php echo $row["Phone"]; ?></td>
                    <td class="alert-secondary"><?php echo $row["Msg"]; ?></td>
                    <td><?php echo $row["uza"]; ?></td>
                    <td class="text-danger"><?php echo $row["Dat"]; ?></td>
                    </tr>
                    <?php  
                    $cnt=$cnt+1;
                    }
                    ?>
                </tbody>
                </table> 
             </div>
         </div>
      </div>
      
       <div id="Balancemessages" class="container tab-pane">
          <div class="container-fluid">
            <div class="row">
             <div class="col-sm-12">
                 <h6 class="card-title">Filter Records by</h6>
             </div>
             <div class="col-sm-2">
                <div class="form-group" style="margin-left:10px">
                <select id="yeear" class="form-control custom-select" required style="">
                <option selected value="">Year</option>
                <option value="2022">2022</option></option>
                <option value="2023">2023</option>
                <option value="2024">2024</option>
                <option value="2025">2025</option>
                <option value="2026">2026</option>
                <option value="2027">2027</option>
                <option value="2028">2028</option>
                <option value="2029">2029</option>
                <option value="2030">2030</option>
                <option value="2031">2031</option>
                <option value="2032">2032</option>
                <option value="2033">2033</option>
                <option value="2034">2034</option>
                <option value="2035">2035</option>
                <option value="2036">2036</option>
                <option value="2037">2037</option>
                <option value="2038">2038</option>
                <option value="2039">2039</option>
                <option value="2040">2040</option>
                </select>
                </div>
             </div>
             
             <div class="col-sm-2">
                <div class="form-group">
                <select id="termterm" class="form-control custom-select" required>
                <option selected value="">Term</option>
                <option value="Term One">Term One</option>
                <option value="Term Two">Term Two</option></option>
                <option value="Term Three">Term Three</option>
                </select>
                </div>  
             </div>
             
             <div class="col-sm-2">
                <div class="form-group">
                 <select id="selegrade" class="form-control custom-select" required>
                  <option value=""> Class </option>
                  <option value="BABY CLASS">BABY CLASS</option>
                  <option value="PP1">PP1</option>
                  <option value="BABY PP2">PP2</option>
                  <option value="GRADE 1">GRADE 1</option>
                  <option value="GRADE 2">GRADE 2</option>
                  <option value="GRADE 3">GRADE 3</option>
                  <option value="GRADE 4">GRADE 4</option>
                  <option value="GRADE 5">GRADE 5</option>
                  <option value="GRADE 6">GRADE 6</option>
                  <option value="GRADE 7">GRADE 7</option>
                  <option value="GRADE 8">GRADE 8</option>
                  <option value="GRADE 9">GRADE 9</option>
                  <option value="CLASS 8">CLASS 8</option>
                </select>
              </div>   
             </div>
             <div class="col-sm-2">
              <div class="form-group">
                <label for="inputStatus"><span class="requireds"></span></label>
                <button class="btn btn-success btn-sm" id="fetchfee"> Filter <i class="fa fa-refresh fa-spin" title="Click to Filter"></i></button>
              </div>
             </div>
            </div>
            
            <div class="row">
             <div class="col-sm-8">
                <div class="table-responsive" id="divpaidfees">
                 <table class="table table-bordered table-sm" id="tablefees" style="font-size:12px">
                     <thead>
                         <tr class="bg-info">
                             <th colspan="13" style="font-size:12px">School Fees for: <strong class=""> </th>
                         </tr>
                         <tr class="">
                                   <th colspan="9"></th>
                                   <th colspan="2"><label class="text-orange"> Select/Unselect All </label> &nbsp <input type="checkbox" class="pull-right" id="selectAllbala" /></th>
                         </tr>
                         <tr>
                             <th>#</th>
                             <th>Pupils Name</th>
                             <th>Contact</th>
                             <th>Adm No.</th>
                             <th>Class</th>
                             <th>Total Fee (KES)</th>
                             <th>Total Paid</th>
                             <th>Balance</th>
                             <th class="bg-secondary">CFB</th>
                             <th class="bg-warning">T.Balance</th>
                            <th><i class="fa fa-check" disabled></i></th>
                         </tr>
                     </thead>
                     <tbody id="bodybody"> </tbody>
                  </table>
                 </div>
             </div>
             
              <div class="col-sm-4">
                <table class="table">
                    <tr class="bg-warning">
                        <td>Content</td>
                    </tr>
                    <tr>
                       <td colspan="2"><em style="font-size:10px">Dear Parent kindly clear (Child name) school balance which stands at: xxxx  </em></td>
                    </tr>
                    <tr class="alert-success">
                        <td>Send message to parents of selected learners</td>
                    </tr>
                    <tr class="">
                        <td class="text-danger">Deadline Date <span>*</span></td>
                    </tr>
                    <tr>
                        <td><input type="date" class="form-control" id="deddate"  required /></td>
                    </tr>
                    <tr>
                        <td colspan="">
                            <label id="feebalancemessage"></label>
                            <button class="btn btn-info btn-sm pull-right" id="subfeebala" disabled>Submit<i class="fa fa-paper-plane"></i></button>
                        </td>
                    </tr>
                </table>
             </div>
             
            </div>
            <div class="row">
                
              <div class="col-sm-8">
                <h6 class="alert-success">
                <center>Latest Sent Messages</center>
                </h6>
                <table class="table table-hover" id="tablefeemessages" style="font-size:11px;font-family:Arial">
                <thead>
                <tr class="alert-warning">
                    <th>#</th>
                    <th>Parent Name </th>
                    <th>Sent to </th>
                    <th>Message</th>
                    <th>Sent By</th>
                    <th>Date</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                    $query=mysqli_query($con,"select feemessages.*,pupils.PName as pare,pupils.Names as lana,Staffs.Name as uza from feemessages left join Staffs ON Staffs.id=feemessages.User left join pupils ON pupils.count=feemessages.pid ORDER BY id DESC limit 150");
                    $cnt=1;
                    while($row=mysqli_fetch_array($query))
                    {
                    ?>  
                    <tr class="row-select">
                    <td><?php echo $cnt; ?></td>
                    <td><?php echo $row["pare"]; ?></td>
                    <td class="alert-success"><?php echo $row["Phone"]; ?></td>
                    <td class="alert-secondary"><?php echo $row["Msg"]; ?></td>
                    <td><?php echo $row["uza"]; ?></td>
                    <td class="text-danger"><?php echo $row["Dat"]; ?></td>
                    </tr>
                    <?php  
                    $cnt=$cnt+1;
                    }
                    ?>
                </tbody>
                </table> 
             </div>
            </div>
          </div>
      </div>
      </div>
      <br />
      <hr />
   </section>
   <?php
}
?>
</div>