<?php  session_start(); error_reporting(0); 
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['name'])){ }else{ 
die(
"
<div class='alert alert-danger'> Error 101. Try again.</div>
"
);
}

$name = RMC($_POST["name"]); 
$msg = RMC($_POST["msg"]); 
$ref = RMC($_POST["ref"]); 
$old_password = RMC($_POST["old_password"]);
if(!empty($name) 
 && !empty($ref)
 && !empty($msg)
 && !empty($old_password)
 ){ //check if required field is not empty
	 
 }else{
	 die("<div class='alert alert-danger'> Please enter required field.</div>");
 } 
 
 
 $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>
    ");
}
 
$sql4="SELECT * from j_testimonials WHERE j_id='".$ref."' AND j_deleted < 1"; //check 
$result4 = runSQL($sql4);
$data4 = mysqli_fetch_array($result4);
$ref = $data4['j_id'];
$name_old = $data4['j_name'];
if(empty($ref)){
	die("<div class='alert alert-danger'> Invalid Reference.</div>");
}

$ip = getIPAddress();
$sql = "UPDATE j_testimonials SET
j_name ='".$name."',j_msg ='".$msg."'
WHERE j_id='".$ref."' AND j_deleted < 1
";
$result = runSQL($sql);
if(!$result){
	die("<div class='alert alert-danger'> Error 1004. Try again.</div>
	");
}

$u_message ="<p>WOW;</p> <p>Testimonial by $name_old has been updated successfully.
<br/><br/>
<a class='btn btn-primary' href=''>EDIT AGAIN</a>
</p>";
?>
<h4 align="center">
	<i class='fas fa-check-circle r_icon text-success'></i>
	<br/>
	Successful.
</h4>
<p>
	<?php echo $u_message; ?>
</p>
<script>
	$("#form").remove();
	$(".formR").remove();
	$("#submit").attr('disabled', '');
</script>