php
php
php
session_start();
date_default_timezone_set("Asia/Kolkata");
$response = '';
include "../../config/database.php";
include "../../config/config.php";
function convertAbsUrl($path) {
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$url = 'https://' . $_SERVER["HTTP_HOST"] . dirname($_SERVER['PHP_SELF']);
} else {
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
}
return $url[-1] == '/' ? $url . $path : $url . '/' . $path;
}
if (isset($_POST["data"][0]["mobile"])) {
$mobile = filterInput($_POST["data"][0]["mobile"]);
}
if (isset($_POST["data"][0]["email"])) {
$email = filterInput($_POST["data"][0]["email"]);
}
if (isset($_POST["data"][0]["fullname"])) {
$fullname = filterInput($_POST["data"][0]["fullname"]);
}
if (isset($_POST["data"][0]["gotra"])) {
$gotra = filterInput($_POST["data"][0]["gotra"]);
}
if (isset($_POST["data"][0]["paymentType"])) {
$paymentType = filterInput($_POST["data"][0]["paymentType"]);
$payment_query = mysqli_query($conn, "SELECT * FROM
`dadarmath_payment_type`");
while ($row = mysqli_fetch_assoc($payment_query)) {
if (strtolower($row['payment_type']) == strtolower($paymentType)) {
$paymentTypeId = $row['id'];
}
}
if ($paymentType == 'Cheque') {
if (isset($_POST["data"][0]["chequeno"])) $chequeno =
filterInput($_POST["data"][0]["chequeno"]);
if (isset($_POST["data"][0]["chequedate"])) $chequedate =
filterInput($_POST["data"][0]["chequedate"]);
if (isset($_POST["data"][0]["bankname"])) $bankname =
filterInput($_POST["data"][0]["bankname"]);
}
}
if (isset($_POST["data"][0]["abhishekType"])) {
$abhishekType = filterInput($_POST["data"][0]["abhishekType"]);
$type_query = mysqli_query($conn, "SELECT * FROM
`dadarmath_abhishek_type`");
while ($row = mysqli_fetch_assoc($type_query)) {
if (strtolower($row['abhishek_type']) == strtolower($abhishekType)) {
$abhishekTypeId = $row['id'];
}
}
if (isset($_POST["date"])) {
$abhishek_dates = filterInput($_POST["date"]);
$abhishek_dates = str_replace(' ', '', $abhishek_dates);
$dates = !empty($abhishek_dates) ? explode(',', $abhishek_dates) : [];
if ($abhishekType == 'Daily') {
$amount = count($dates) * $abhishek_price;
} elseif ($abhishekType == 'Monthly') {
$total_days = 0;
foreach ($dates as $date) {
$mmyyyy = preg_split("#/#", $date);
$total_days += cal_days_in_month(CAL_GREGORIAN, $mmyyyy[0],
$mmyyyy[1]);
}
$amount = $abhishek_price * $total_days;
} else {
$year = $dates[0];
$date = new DateTime("{$year}-01-01");
$num_thursdays = 0;
while ($date->format('Y') == $year) {
if ($date->format('N') == 4) {
$num_thursdays++;
}
$date->modify('+1 day');
}
$amount = $abhishek_price * $num_thursdays;
}
}
if (!empty($csrfResponse)) {
if (empty($fullname)) $response = ['status' => 'error', 'message' =>
'Please enter a full name'];
elseif (empty($gotra)) $response = ['status' => 'error', 'message' =>
'Please select gotra'];
elseif (count($dates) == 0) $response = ['status' => 'error', 'message' =>
'Please enter a date'];
elseif (empty($amount)) $response = ['status' => 'error', 'message' =>
'Please enter an amount'];
elseif (!empty($email) && !preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-
9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $email)) $response = ['status' => 'error',
'message' => 'Please Enter a Valid Email Address'];
elseif (empty($abhishekType)) $response = ['status' => 'error', 'message'
=> 'Invalid abhishek type'];
elseif (empty($paymentType)) $response = ['status' => 'error', 'message' =>
'Invalid payment type'];
elseif ($paymentType == 'Cheque' && (empty($chequeno) || empty($chequedate)
|| empty($bankname))) {
$response = empty($chequeno) ? ['status' => 'error', 'message' =>
'Please enter a cheque number']
: (empty($chequedate) ? ['status' => 'error', 'message' =>
'Please select cheque date']
: ['status' => 'error', 'message' => 'Please enter a cheque
bank name']);
} else {
if (!empty($chequedate)) {
$chequedate = date("Y-m-d", strtotime(str_replace('/', '-',
$chequedate)));
}
if ($_POST['action'] == 'add') {
// Code for adding the record here (same as your provided code)
$create_date = date("Y-m-d");
$create_time = date("h:i:s A");
$currentYear = date("y");
$prefix = 'WAD' . $currentYear . '-';
if ($abhishekType == 'Monthly') {
$prefix = 'WAM' . $currentYear . '-';
} else if ($abhishekType == 'Yearly') {
$prefix = 'WAY' . $currentYear . '-';
}
// send sms
if (getEnvVar('APP_ENV') == 'production') {
sendSMS($mobile, "Successfully Abhishek booked, Your payment receipt:
$receipt -SHRI AKKALKOT SWAMI SAMARTH MAHARAJAS MATHS");
}
// send email
if (getEnvVar('APP_ENV') == 'production') {
require_once '../../lib/MailService.php';
$mailService = new \Phppot\MailService\MailService ();
$mailService->mailId = $email;
$mailService->subject = 'Dadarmath Abhishek book';
$mailService->body = 'Successfully Abhishek booked, Your payment receipt:
' . $receipt;
$mailService->sendMail();
}
$response = ['status' => 'success', 'message' => 'Sucessfully Added', 'id' =>
$last_id];
} else {
$response = ['status' => 'error', 'message' => 'Internal Server Error'];
}
} elseif ($_POST['action'] == 'edit') {
// Code for updating the record here (same as your provided code)
$abhiskekId = $_POST["data"][0]["abhiskekId"];
$updated_date = date("Y-m-d");
$updated_time = date("h:i:s A");
function filterInput($data) {
return htmlspecialchars(stripslashes(trim($data)));
}
function getEnvVar($key)
{
$envFile = file('../../.env');
foreach ($envFile as $line) {
$line = trim($line);