<?php   

// get additional SMS in Current month

$branch=$_SESSION['branch'];
$monthId=date("m");
$sessionID=date("Y");

$qr="SELECT SUM(add_sms) as TaditionalSms FROM eduportal_branches_SMScredit_limit WHERE month_id='$monthId'  and branch_id='$branch' AND session_id=".$sessionID;
$AdSMS = $m->query($qr);


// this code is to update the sms credit limit of every page refresh
$total_sms_monthly_used=getCurrentMonthFeeSms($m)+getCurrentMonthResultSms($m)+getCurrentMonthOtherSms($m)+getCurrentMonthAttendanceSms($m)+0;
$sms_credit=$brid[0]['monthly_credit']+$AdSMS[0]['TaditionalSms'];

$m->where("module_id", 11);
$m->where("user_id", $_SESSION['user_id']);
$userSearchStudent=$m->get("users_privilege_detail");


// getting unread notifications
  $m->where("branch_id",$_SESSION['branch']);
  $read_notifications=$m->get('eduportal_push_notifications_read_details');
  $push_notifications=$m->query("select * from eduportal_push_notifications order by notif_id desc ");

  $unseen_nots=count($push_notifications)-count($read_notifications);
  if($unseen_nots<0){$unseen_nots=0;}

// getting updates

  $m->where("branch_id",$_SESSION['branch']);
  $seen_updates=$m->get('eduportal_seen_updates');
  $updates=$m->query("select * from eduportal_updates_details where status='0' order by updates_id desc ");
  $unseen_updates=count($updates)-count($seen_updates);
  if($unseen_updates<0){$unseen_updates=0;}

// get used whatsapp sms

$dateWhatsapp=date("Y-m-d");

$query="select * from edu_whatsapp_messages_details where msg_date='$dateWhatsapp' and branch_id =".$_SESSION['branch'];
$usedWhatsappSMS = $m->query($query);
?>


<style type="text/css">


.icon-button {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
color: #333333;
background: none;
border: none;
outline: none;
border-radius: 50%;
}

.icon-button:hover {
cursor: pointer;
}

.icon-button:active {
background: #cccccc;
}

.icon-button__badge {
position: absolute;
top: 1px;
right: 14px;
height: 25px;
width: 25px;
line-height: 23px;
color: #ffffff;
font-size: 12px;
background-color: #ff3131;
border: 2px solid #ffffff;
border-radius: 50%;
display: block;
text-align: center;
-webkit-box-shadow: 0px 8px 10px 0px rgb(0 0 0 / 25%);
box-shadow: 0px 8px 10px 0px rgb(0 0 0 / 25%);
}

.icon-button2__badge {
position: absolute;
top: -2px;
right: 7px;
height: 30px;
width: 34px;
line-height: 28px;
color: #ffffff;
font-size: 12px;
background-color: dodgerblue;
border: 2px solid #ffffff;
border-radius: 50%;
display: block;
text-align: center;
-webkit-box-shadow: 0px 8px 10px 0px rgb(0 0 0 / 25%);
box-shadow: 0px 8px 10px 0px rgb(0 0 0 / 25%);
}


.icon-button1__badge {
position: absolute;
top: 1px;
right: 14px;
height: 25px;
width: 25px;
line-height: 23px;
color: #ffffff;
font-size: 14px;
font-weight: 600;
background-color: #2ad7c5;
border: 2px solid #ffffff;
border-radius: 50%;
display: block;
text-align: center;
-webkit-box-shadow: 0px 8px 10px 0px rgb(0 0 0 / 25%);
box-shadow: 0px 8px 10px 0px rgb(0 0 0 / 25%);
}

ul #whatsapp:hover{
    color: #075E54;
}

ul #ticket:hover{
    color: red;
}


ul #sugg:hover{
     color: #075E54 ;
}
   

/* Code to hide the number element controls */

/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}

/* Firefox */
input[type=number] {
-moz-appearance: textfield;
}


.right_col > div:nth-child(1) {
padding:1%;  
margin-top:6%;
}

@media only screen and (max-width: 768px) {

/* For mobile phones: */
.schoolheading{
margin-left: 10px; 
}
.bulkstyle{padding:7%;}
}

@media (min-width:801px)  { /* tablet, landscape iPad, lo-res laptops ands desktops */ 

.schoolheading{
margin: 17px 0px 0px -15px;   
}

.bulkstyle{padding:3%;}
.over {
/*position: fixed;*/
top: 42px;
background-color: white;
z-index: 902;
width: 670px;
padding: 10px;

}

}

@media only screen and (max-width: 768px) {

/* For mobile phones: */

.over {
/*position: fixed;*/
top: 100px;
background-color: white;
z-index: 902;

}


}

.top_nav .navbar-right li {

float: left;
padding: 0px;
margin-top: 10px;

}

</style>


<script>

function getDataForLoacalStorageLiveSearch(value,id) {

if(value !== null && value !== '') {

if (localStorage.getItem("Allstudents") === null) {


if (window.XMLHttpRequest) {

// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

} else { // code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4 && xmlhttp.status==200) {

var studentData=xmlhttp.responseText;


localStorage.setItem('Allstudents',studentData);


}

}

xmlhttp.open("GET","get_all_students_local_storage.php?branch="+id,true);

xmlhttp.send();

} else {

let arr=JSON.parse(localStorage.getItem('Allstudents'));
//arr.length = 15;
if(arr !=null){
let html='';
let sno=1;

for(let k in arr){

html=html+`

<ul class="liveSearchBar">
<li style='padding-left:0.5%;border-bottom:1px solid lightgray;text-align:left;'><a  href="student_profile.php?asdflkkd;lfkklmvirjgihfjdvkklscvmdkasfjifjdkklcdmdsfdhgkjklcdaadjsfadskfj&student=${arr[k].student_id}&qr=${arr[k].first_name}"><span>${arr[k].first_name} | ${arr[k].last_name} | ${arr[k].Class_Name} | ${arr[k].section_name} | ${arr[k].candidate_roll_no} | ${arr[k].cell_no} | ${arr[k].ref_no} | ${arr[k].family_code} </span></a><span style=''> <a href='pay_fee.php?asdflkkd;lfkklmvirjgihfjdvkklscvmdkasfjifjdkklcdmdsfdhgkjklcdaadjsfadskfj&student=${arr[k].student_id}&qr=${arr[k].first_name}&session=${arr[k].session_id}&dfjhasdkjhfkasdfkjhasdfhdjashfacnsjadshfjk#std_section'><b style='color:MediumSeaGreen;'>Fee History</b> </a> </span></li>

</ul>

`;          
}
document.getElementById('livesearch').innerHTML=html;

}

} // end else condition

} else { // array null when input value empty

document.getElementById('livesearch').innerHTML='No Suggestion...';

} // end else condition

} // end function


</script>



<input type="hidden" name="" id="sms_left" value="<?php echo $sms_credit-$total_sms_monthly_used;?>">
<!-- top navigation -->
<div class="top_nav">
<div class="nav_menu">
<nav>

<ul class="nav navbar-nav navbar-right"style="width: 100%;background-color: white;padding-top: 2%;">

<div class="nav toggle" style="width:50px; box-shadow: none;margin-top: 2px">
<a id="menu_toggle"><i class="fa fa-bars" style="color: gray;"></i></a>
</div>                

<!-- Search Section Start -->

<div class="col-md-5 col-sm-12 col-xs-12 schoolheading" >

    

<?php 

if ($brid[0]['feature_block']=="0") {
if (count($userSearchStudent)>0) { ?>

<span style="margin-left: 6%;font-size: 15px; color: #bebebe"><img src="navbar_icons/search.PNG" width="28px" height="auto" alt=""></span>
<input type="text" id="filter" class="form-control search text-input" placeholder="Search Student with | Name | Cell No | Roll No  | Adm No" onkeyup="getDataForLoacalStorageLiveSearch(this.value,<?php echo $_SESSION['branch'];?>)" name="" style="width: 100%;height: 30px; margin-left: 12%; margin-top: -7%;border: none; box-shadow: none; border-radius: 0; background: transparent; ">

<div class="over" id="livesearch"></div>
<?php } } else { ?>

    <div class="alert alert-danger" style="width:138%;" id="msg">
     <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
      <strong>Danger!</strong> <?php echo $brid[0]['feature_service_remarks'] ;?>
    </div>
<?php } ?>







</div>

<!-- Search Section End -->

<li class="" style="float: left; margin-left: 15%; font-size: 15px; margin-top: 1px;" >

<a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">

<span style="color:black;"><?php echo substr($userProfile[0]['user_fname'],0,7).".";?></span>

<?php if($brid[0]['logo']!=NULL){ ?>


<img src="<?php echo DOMAIN.AgentDirectory;?>staff_pics/<?php echo $userProfile[0]['attach_image'];?>" class="img-thumbnail" style="width:40px;height:40px;"   />


<?php }else { ?>   
<span class=" fa fa-angle-down"></span>
<img src="navbar_icons/icon.jpg" style="width:35px;height:auto;margin-top: 2px;" class="img-thumbnail" />

<?php } ?>  

<style type="text/css">

.Heading_2{background-color: #f8a106; color: white;height: 50px; padding-top: 8%; font-weight: 400; font-size: 16px; border-radius: 10px}

</style>        

</a>


<ul class="dropdown-menu dropdown-usermenu pull-right">
<h2 class="text-center Heading_2" style="border-radius: 0px"><?php echo substr($userProfile[0]['user_fname'],0,7).".";?></h2>

<li><a href="edit_user.php">Edit Profile</a></li>
<li><a href="print_staff_salary_history.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&session=<?php echo $_SESSION['current_session'];?>&staff=<?php echo $_SESSION['user_id'];?>">Salary History</a></li>
<li><a href="user_login_history.php">Login History</a></li>
<li><a data-toggle="modal" data-target="#changepass<?php echo $_SESSION['user_id'];?>" style="" href="#" class="">Change Password</a>
</li>
<li><a href="logout.php"><i class="fa fa-sign-out pull-right"></i> Log Out</a></li>
</ul>



<!-- User Change Password Popup start -->



<div id="changepass<?php echo $_SESSION['user_id'];?>" class="modal fade" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="border-bottom:none;">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title" style="text-align:center;"> Change Password:- (<?php echo $_SESSION['username']; ?>)  </h4>
</div>

<div class="modal-body">

<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">

<input type="hidden" name="action" value="ChangePassword"> 
<input type="hidden" name="cell_no" value="<?php echo $branch[0]['cell_no'];?>"> 
<div class="col-md-12" >
<div class="form-group" >

<label>  New Password </label>
<input style="height:40px;padding-left:1%;" id="password" type="password" value="<?php echo $WorkAssignListVal['user_fname'];?>"  class="form-control field" name="password"/>
</div>
</div>

<div class="col-md-12" >
<div class="form-group" >

<label>  Confirm Password </label>
<input style="height:40px;padding-left:1%;" id="confirm_password" type="password"  value="<?php echo $designation[0]['designation_name']; ?>"  class="form-control field" name="confirm_password"/><span ></span>
</div>
</div>

<div class="modal-footer">

<button type="submit" class="btn btn-primary" name="submit" >Submit </button>



</div>

</form>

</div>

</div>

</div>
</div>

<!-- User Change Password Popup End -->



</li>

<!-- Messages section Add -->


<!-- Customer Support Section Start -->

<li class="msg" style="float: left; margin-top: 5px" >

<a href="" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">

<img src="navbar_icons/custom_icon.PNG" class="icon-button" style="width:30px;height:auto; margin-top: 1%;"   />
<!-- <span class="icon-button1__badge"<?php echo count[''] ?>;>03</span>
 -->
</a>




<ul class="dropdown-menu dropdown-usermenu pull-right">
<h2 class="text-center Heading_2" style="background-color: #2ad7c5; color: white;height: 50px; padding-top: 8%; border-radius: 0px">Support Center</h2>

<a href="https://wa.me/+923099150606" target="_blank" id="whatsapp" >

    <li style="font-size: 13px;float: left;margin-left: 1em;border-bottom: 2px solid #d9d8d8;margin-bottom: 5%;width: 190px;"> 

        <i class="fa fa-whatsapp" aria-hidden="true" style="font-size: 16px;display: inline;margin-right:5px;"></i>

        Hira Nawaz
        </li>

</a>


<a href="https://wa.me/+923000227123" target="_blank" id="whatsapp" style="">

    <li style="font-size: 13px;float: left;margin-left: 1em;border-bottom: 2px solid #d9d8d8;margin-bottom: 5%;width: 190px;"> 
    <i class="fa fa-whatsapp" aria-hidden="true" style="font-size: 16px;display: inline;margin-right: 5px;"></i>
    Rabia Maskeen </li></a>


<a href="https://wa.me/+923000640545" target="_blank" id="whatsapp" style="">

    <i class="fa fa-whatsapp" aria-hidden="true" style="font-size: 16px;display: inline;margin-right: 5px;"></i>

    <li style="font-size: 13px;float: left;margin-left: 1em;border-bottom: 2px solid #d9d8d8;margin-bottom: 5%;width: 12em;"> Operation Manager

</li></a>


<a href="complaints_dashboard.php" target="_blank" style="" id="ticket">

    <li style="font-size: 13px;margin-bottom: 6px;margin-left: 1em; border-bottom: 2px solid #d9d8d8;margin-bottom: 5%; float: left;
width: 190px;"> 

<i class="fa fa-ticket" aria-hidden="true" style="font-size: 16px;margin-right: 5px ;"></i>

Complaints Center


 </li></a>


<a href="suggestions_dashboard.php" target="_blank" id="sugg">

    <li style="font-size: 13px;margin-bottom: 6px;margin-left: 1em;float: left;width: 12em; "> 

        <i class="fa fa-lightbulb-o" aria-hidden="true" style="font-size: 16px;margin-right: 5px ;"></i>
        Suggestions Center


 </li></a>



</ul>
</li>





<!-- Un Read NotificationBell Section Start -->

<li class="msg" style="float: left; margin-top: 0px" >

<a href="" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">

<img src="navbar_icons/bell.PNG" class="icon-button" style="width:17px;height:auto; margin-top: 7px;"/>

<?php if ($unseen_nots>0) { ?>
  <span class="icon-button__badge"><?php echo $unseen_nots;?></span>
<?php }?>

</a>


<ul class="dropdown-menu dropdown-usermenu pull-right" style="width:300px;">

 <li style="background: #5bc0de;color:white; text-align: center; padding: 5px; font-size: 18px;margin-top: 1%;margin-bottom: -2%;"> 
  
    <?php echo $unseen_nots;?> Unread Notifications</h2>

</li>   
      

<?php foreach($push_notifications as $notification) {
      // code to check if the notification is ready or unread
      $m->where("notif_id",$notification['notif_id']);
      $m->where("branch_id",$_SESSION['branch']);
      $records=$m->get('eduportal_push_notifications_read_details');


 ?>

<a href="push_notifications.php?<?php echo session_id().session_id().session_id();?>&id=<?php echo $notification['notif_id'];?>" >

<li style="background: <?php if(count($records)>0){echo "#f7f7f7;"; } else {echo "#d3d3d3;"; } ?> padding: 10px; height:80px; font-size: 12px;margin-top: 2%;"> 

    <span style="float: right;"> <i style="font-weight: bold;font-size: 12px;"> <?php echo date("d-M-Y",strtotime($notification['posted_date']));?> </i> </span> <br/>

    
        <span style="float:left;"> <?php echo substr($notification['title'],0,85);?>  </span>    
        

</li>

</a>


<?php } ?>

<li style="background: #5bc0de;text-align: center;
 padding: 10px; font-size: 12px;margin-top: 2%;"> 

   <a href="push_notifications.php" style="font-weight: bold;text-decoration: none;color:white;"> View All Notifications >> </a>
    

</li>   


</ul>

</li>

<!-- Bell Section End -->




<!-- Un Read NotificationBell Section Start -->

<li class="msg" style="float: left; margin-top: 0px" >

<a href="" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">

<!-- <img src="navbar_icons/bell.PNG" class="icon-button" style="width:17px;height:auto; margin-top: 7px;"/>
 -->
<i class="fa fa-lightbulb-o" aria-hidden="true" style="font-size: 23px;margin-top: 7px;color: gray;"></i>

<?php if ($unseen_updates>0) { ?>
  <span class="icon-button__badge"><?php echo $unseen_updates;?></span>
<?php }?>

</a>

<ul class="dropdown-menu dropdown-usermenu pull-right" style="width:300px;">

 <li style="background: #5bc0de;color:white; text-align: center; padding: 5px; font-size: 18px;margin-top: 1%;margin-bottom: -2%;"> 
  
    <?php echo $unseen_updates;?> Latest Updates </h2>

</li>   
      

<?php foreach($updates as $update) {
      // code to check if the notification is ready or unread
      $m->where("updates_id",$update['updates_id']);
      $m->where("branch_id",$_SESSION['branch']);
      $records=$m->get('eduportal_seen_updates');


 ?>

<a href="updates.php?<?php echo session_id().session_id().session_id();?>&id=<?php echo $update['updates_id'];?>" >

<li style="background: <?php if(count($records)>0){echo "#f7f7f7;"; } else {echo "#d3d3d3;"; } ?> padding: 10px; height:80px; font-size: 12px;margin-top: 2%;"> 

    <span style="float: right;"> <i style="font-weight: bold;font-size: 12px;"> <?php echo date("d-M-Y",strtotime($update['datetime']));?> </i> </span> <br/>

    
        <span style="float:left;"> <?php echo substr($update['title'],0,85);?>  </span>    
        

</li>

</a>


<?php } ?>

<li style="background: #5bc0de;text-align: center;
 padding: 10px; font-size: 12px;margin-top: 2%;"> 

   <a href="updates.php" style="font-weight: bold;text-decoration: none;color:white;"> View All Updates >> </a>
    

</li>   


</ul>

</li>

<!-- Bell Section End -->

<!-- Plus Envelope Section Start -->

<li class="msg" style="float: left; margin-top: 5px" >

<a href="" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">

<img src="navbar_icons/plus_envelope2.PNG" class="icon-button" style="width:24px;height:auto; margin-top: 5px"   />
<span class="icon-button2__badge">
<?php if (count($userSearchStudent)>0) { ?>

<?php echo $sms_credit-$total_sms_monthly_used;?>

<?php } ?></span>

</a>
<ul class="dropdown-menu dropdown-usermenu pull-right">
<h2 class="text-center Heading_2" style="background-color: dodgerblue; color: white;height: 50px; padding-top: 8%;border-radius:0px">SMS Limit </h2> <li>

<?php if (count($userSearchStudent)>0) { ?>

<a style="color: gray;font-weight: bold;font-family: arial;" href="">Monthly Limit: 

(<?php echo $sms_credit;?> SMS)</a>

<?php } ?>

</li>

<li>
<?php if (count($userSearchStudent)>1) { ?>
<a style="color: gray;font-weight: bold;font-family: arial;" href="">SMS Used:
(<?php echo $total_sms_monthly_used;?> SMS)</a>
<?php } ?>
</a></li>

<li>
<?php if (count($userSearchStudent)>0) { ?>
<a style="color: gray;font-weight: bold;font-family: arial;" href="">SMS Left: 
(<?php echo $sms_credit-$total_sms_monthly_used;?> SMS)</a>
<?php } ?>

</li>

<li>

<a style="color: gray;font-weight: bold;font-family: arial;" href="">WhatsApp Limit: 
(<?php echo $brid[0]['whatsapp_sms_limit'];?> SMS)</a>


</li>


<li>

<a style="color: gray;font-weight: bold;font-family: arial;" href="">WhatsApp SMS Left: 
(<?php echo $brid[0]['whatsapp_sms_limit']-count($usedWhatsappSMS);;?> SMS)</a>


</li>

</ul>

</li>



<!-- Plus Envelope End -->




<!-- Messages section end -->


</ul>
</li>
</ul>
</nav>
</div>
</div>
<!-- /top navigation -->



<!-- function for live search header --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function(){
    $("#filter").keyup(function(){
 
        // Retrieve the input field text and reset the count to zero
        var filter = $(this).val(), count = 0;
 
        // Loop through the comment list
        $("nav ul li").each(function(){
 
            // If the list item does not contain the text phrase fade it out
            if ($(this).text().search(new RegExp(filter, "i")) < 0) {
                $(this).fadeOut();
 
            // Show the list item if the phrase matches and increase the count by 1
            } else {
                $(this).show();
                count++;
            }
        });
 
        // Update the count
        /*var numberItems = count;
        $("#filter-count").text("Number of Filter = "+count);*/
    });
});

</script>