<?php  session_start(); error_reporting(0); 
//if session
if(isset($_SESSION['j_admin'])){ }else{ 
    die(
    "
    <div class='alert alert-danger'> Error 100. Try again.</div>
    "
    );
}
require_once("../j_conn/url.php");
require_once("../j_conn/dbc.php");
require_once("../j_incs/functions.php");
if(isset($_POST['subject'])){ }else{ 
die(
"
<div class='alert alert-danger'> Error 101. Try again.</div>
"
);
}
?>
<script>
$('.rMe').each(function() {
	 if ($(this).val() == "") {
 	   $(this).css({"border-color": "brown", 
		 "border-width":"1px", 
		 "border-style":"solid"});
	 }else{
		$(this).css({"border-color": "#fafafa", 
		 "border-width":"0px", 
		 "border-style":"solid"});	 
	 }
});
</script>
<?php
$subject = RMC($_POST["subject"]);
//$desc = RMC_MSG($_POST["desc"]);
$desc = RMC($_POST["desc"]);
$old_password = RMC($_POST["old_password"]); 
 if(!empty($subject) 
 && !empty($desc)
 && !empty($old_password)
 ){ //check if required field is not empty
     
 }else{
     die(
        "
        <div class='alert alert-danger'> A required field is empty. Try again.</div>
        "
        );
 } 
 //die($desc);
//hash password
$old_password = base64_encode("$hash$old_password");  
//check password
$sql4="SELECT count(*) as sum from j_users WHERE j_id='".$id."' AND j_password='".$old_password."' AND  j_blocked < 1 AND j_deleted < 1"; //check 
$result4 = runSQL($sql4);
$data4 = mysqli_fetch_array($result4);
$sum4 = $data4['sum'];
if($sum4 > 0){
}else{
    die("<div class='alert alert-danger'> Invalid Current Password. Try again.</div>
    <script> $('[name=old_password]').css({'border-color': 'brown', 'border-width':'1px', 'border-style':'solid'});</script>
    ");
}
//
//$descx =  RMC($desc);
$descx =  $desc;
check_length ($descx,"5","5000","Description","desc");
//
$u_subject = $subject;
$u_message = $desc;
send_notify("",'*',$u_subject,$u_message);
//count students
$sql4="SELECT count(*) as sum from j_users WHERE j_deleted < 1"; //check 
$result4 = runSQL($sql4);
$data4 = mysqli_fetch_array($result4);
$students_num = $data4['sum'];
if($students_num > 1){ $stu = 'Users'; }else{$stu = 'User'; }
//Alert Message 
$alert="Message has been sent successfully to all $students_num $stu.";
?>
<script>
    $("#form").remove();
     $("#submit").attr('disabled', '');
</script>
<div class="card">
    <div class="card-body">
        <div class="container">
            <div class="row">
                 <div class="col-md-12" style="text-align:center;">
                    <div class="avatar avatar-image avatar-lg avatar-green">
                        <i class="anticon anticon-check"></i>
                     </div>
                     <p>
                        <?php echo $alert; ?>
                         <br/>
                    </p>
                    <a class="btn btn-success" href="<?php echo $dir; ?>notifications/"> Check Mail</a>
                    <a class="btn btn-primary" href="<?php echo $dir; ?>compose-mail/"> Compose Another </a>
                 </div>
            </div>
        </div>
    </div>
</div>
