<?php include 'connection.php';

date_default_timezone_set('Asia/Calcutta');
$today = date("d-m-Y");
$time = date("h:i A"); 
$currentyear = date("Y");

function randomPassword() {
    $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 5; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
$unique_id = randomPassword();


?>
<?php 
$querylogin = "select * from  users where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_id = $row['user_id'];
$first_name = $row['first_name'];
$login_type=$row['login_type'];
}

?>



  
<?php




$event_name = $_REQUEST['event_name'];
$eventID = $_REQUEST['eventID'];
$child_name = $_POST['child_name'];
$std = $_POST['std'];
$mobile_no = $_POST['mobile_no'];
$age = $_POST['age'];
$year = $_POST['year'];
$school_name = $_POST['school_name'];
$parent_name = $_POST['parent_name'];
$address = $_POST['address'];


$past_history = isset($_POST['facing_problem']) ? implode(',', $_POST['facing_problem']) : '';

$facing_problem_Other = $_POST['facing_problem_Other'];
if (!empty($facing_problem)) {
    // If $facing_problem is not empty, concatenate with a comma and the new record
    $facing_problem .= ',' . $facing_problem_Other;
} else {
    // If $facing_problem is empty, assign the new record directly
    $facing_problem = $facing_problem_Other;
}


$querycon = "select * from  branch_master where branch_id = '1'";
$resultcon = mysqli_query($conn,$querycon);
while($row=mysqli_fetch_array($resultcon))
{
$branch_name = $row['branch_name'];
$branch_address = $row['branch_address'];
$helpline = $row['helpline'];
}


$query1 = "insert into event_more (event_name,eventID,child_name,std,mobile_no,age,year,school_name,parent_name,address,facing_problem) values ('$event_name','$eventID','$child_name','$std','$mobile_no','$age','$year','$school_name','$parent_name','$address','$facing_problem')";
//echo $query;
$result=mysqli_query($conn,$query1);



if($mobile_no!=''){
$mobile_nosa2 = "91".$mobile_no;

//$mobile_nosa1 = "919224328435";

$message1a2=nl2br("Thank you for your Registration,".'\n\n'."You are register under the event: ".$event_name.'\n\n'."Location: ".$branch_address.'\n\n'."Helpline: ".$helpline.'\n\n'."Website:".'\n'."www.kanakavedaayurveda.com");

$curlmessage = curl_init();
curl_setopt_array($curlmessage, [
CURLOPT_URL => "https://waapi.app/api/v1/instances/11656/client/action/send-message",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",


CURLOPT_POSTFIELDS => "{\"chatId\":\"".$mobile_nosa2."@c.us\",\"message\":\"".$message1a2 ."\",\"mentions\":[\"123456789@c.us\",\"987654321@c.us\"]}",

CURLOPT_HTTPHEADER => [
"Authorization: Bearer vJgrDNPuVKpht6lctgqJBQdjSDJsZMwWtcYlHEE6b1f275a0",
"content-type: application/json"
],
]);
$response = curl_exec($curlmessage);
$err = curl_error($curlmessage);
curl_close($curlmessage);
if ($err) {
//echo "cURL Error #:" . $err;
} else {
//echo $response;
}



}






//exit();

?>
<script>
javascript:window.location.href="thank_you.html";
</script>