Update for BeWellWell my account en media_upload

This commit is contained in:
“VeLiTi”
2025-08-29 15:01:30 +02:00
parent 010b23b0e5
commit f8e089ffcd
20 changed files with 603 additions and 22 deletions

150
api/v2/get/appointment.php Normal file
View File

@@ -0,0 +1,150 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Appointments
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//NEW ARRAY
$criterias = [];
//Check for $_GET variables and build up clause
if(isset($get_content) && $get_content!=''){
//GET VARIABLES FROM URL
$requests = explode("&", $get_content);
//Check for keys and values
foreach ($requests as $y){
$v = explode("=", $y);
//INCLUDE VARIABLES IN ARRAY
$criterias[$v[0]] = $v[1];
}
}
//GET SLOTS PER DEALER
if(isset($criterias['action']) && $criterias['action'] == 'get_slots' && isset($criterias['dealer_id']) && isset($criterias['year']) && isset($criterias['month'])){
//DECODE DEALER_ID
$dealer_id = decodeUuid($criterias['dealer_id']);
$year = (int)$criterias['year'];
$month = (int)$criterias['month'];
// Get the number of days in the month
$num_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
//GET OPENING_HOURS
$sql_opening_hours = 'SELECT opening_hours FROM dealers WHERE rowID = ?';
$stmt = $pdo->prepare($sql_opening_hours);
$stmt->execute([$dealer_id]);
$opening_hours = $stmt->fetch(PDO::FETCH_ASSOC);
$opening_hours = json_decode($opening_hours['opening_hours'],true);
if (empty($opening_hours)){
// Define opening hours
$opening_hours = [
1 => ['start' => '09:00', 'end' => '17:00'], // Monday
2 => ['start' => '09:00', 'end' => '17:00'], // Tuesday
3 => ['start' => '09:00', 'end' => '17:00'], // Wednesday
4 => ['start' => '09:00', 'end' => '17:00'], // Thursday
5 => ['start' => '09:00', 'end' => '17:00'], // Friday
6 => ['start' => '09:00', 'end' => '17:00'], // Saturday
7 => null // Sunday - Closed
];
} else {
// Convert all string "null" values to actual null
foreach ($opening_hours as $day => $hours) {
if ($hours === "null") {
$opening_hours[$day] = null;
}
}
}
// Initialize an array to store the available slots for the entire month
$all_available_slots = [];
// Initialize a counter for the slot IDs
$id_counter = 1;
// Iterate over each day in the month
for ($day = 1; $day <= $num_days; $day++) {
// Create a full date string
$full_date = sprintf("%04d-%02d-%02d", $year, $month, $day);
// Determine the day of the week (1 = Monday, 7 = Sunday)
$day_of_week = date('N', strtotime($full_date));
// Check if the day is open
if ($opening_hours[$day_of_week] === null) {
continue; // Skip closed days (Sunday)
}
// Get existing booked/unavailable slots for the day
$booked_slots_sql = "SELECT start_time, end_time FROM appointment_slots
WHERE DATE(start_time) = ? AND dealer_id = ? AND is_available = false";
$stmt = $pdo->prepare($booked_slots_sql);
$stmt->execute([$full_date, $dealer_id]);
$booked_result = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Store booked slots for the day
$booked_slots = [];
foreach ($booked_result as $row){
$booked_slots[] = [
'start' => substr($row['start_time'], 11, 5),
'end' => substr($row['end_time'], 11, 5)
];
}
// Generate all possible slots for the day
$start_time = new DateTime($full_date . ' ' . $opening_hours[$day_of_week]['start']);
$end_time = new DateTime($full_date . ' ' . $opening_hours[$day_of_week]['end']);
$interval = new DateInterval('PT1H');
// Iterate through each hour and check availability
while ($start_time < $end_time) {
$slot_end = clone $start_time;
$slot_end->add($interval);
// Check if this slot is booked
$is_available = true;
foreach ($booked_slots as $booked) {
$booked_start = new DateTime($full_date . ' ' . $booked['start']);
$booked_end = new DateTime($full_date . ' ' . $booked['end']);
if (($start_time >= $booked_start && $start_time < $booked_end) ||
($slot_end > $booked_start && $slot_end <= $booked_end)) {
$is_available = false;
break;
}
}
// If the slot is available, add it to the list
if ($is_available) {
$all_available_slots[] = [
'id' => $id_counter++,
'start_time' => $start_time->format('Y-m-d H:i:s'),
'end_time' => $slot_end->format('Y-m-d H:i:s')
];
}
$start_time->add($interval);
}
}
$messages = $all_available_slots;
} else {
$messages =['success' => false, 'slots' => ''];
}
//------------------------------------------
//JSON_ENCODE
//------------------------------------------
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
//Send results
echo $messages;
?>

View File

@@ -55,7 +55,8 @@ if(isset($get_content) && $get_content!=''){
//Define Query
if(isset($criterias['totals']) && $criterias['totals'] ==''){
//Request for total rows
$sql = 'SELECT count(*) as count FROM dealers d '.$whereclause.'';
$sql = 'SELECT count(*) as count FROM dealers d '.$whereclause;
}
elseif (isset($criterias['list']) && $criterias['list'] ==''){
$sql = 'SELECT d.* FROM dealers d '.$whereclause;
@@ -64,6 +65,7 @@ else {
//SQL for Paging
$sql = 'SELECT d.*, m.full_path FROM dealers d LEFT JOIN media m ON d.dealer_media = m.rowID '.$whereclause.' LIMIT :page,:num_products';
}
$stmt = $pdo->prepare($sql);
//Bind to query
@@ -95,8 +97,18 @@ if (!empty($criterias)){
//Add paging details
if(isset($criterias['totals']) && $criterias['totals']==''){
$stmt->execute();
$messages = $stmt->fetch();
$messages = $stmt->fetch();
$messages = $messages[0];
//No further data transformation need
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
//Send results
echo $messages;
//exit
exit();
}
elseif (isset($criterias['list']) && $criterias['list']==''){
//Excute Query
@@ -116,10 +128,20 @@ else {
}
//------------------------------------------
//CHANGE ROWID INTO UUID
//------------------------------------------
function updateRowID($row) {
$row['rowID'] = encodeUuid($row['rowID']);
return $row;
}
$updatedData = array_map('updateRowID', $messages);
//------------------------------------------
//JSON_ENCODE
//------------------------------------------
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
$messages = json_encode($updatedData, JSON_UNESCAPED_UNICODE);
//Send results
echo $messages;

View File

@@ -50,6 +50,11 @@ if(isset($get_content) && $get_content!=''){
}
}
//ASSIGN DEALER ID TO IDENTITY
if(isset($criterias['userkey'])){
checkAndInsertIdentityDealer($pdo, $criterias['userkey']);
}
if(isset($criterias['totals']) && $criterias['totals'] ==''){
//Request for total rows
$sql = 'SELECT count(*) as count from identity '.$whereclause.'';

View File

@@ -0,0 +1,59 @@
<?php
defined($security_key) or exit;
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//------------------------------------------
// dealers
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//NEW ARRAY
$criterias = [];
$messages = '';
//Check for $_GET variables and build up clause
if(isset($get_content) && $get_content!=''){
//GET VARIABLES FROM URL
$requests = explode("&", $get_content);
//Check for keys and values
foreach ($requests as $y){
$v = explode("=", $y);
//INCLUDE VARIABLES IN ARRAY
$criterias[$v[0]] = $v[1];
}
}
//IDENTITY REQUEST - override SQL
if(isset($criterias['identity_id'])){
$sql = 'SELECT d.*, m.full_path FROM identity_dealers id JOIN dealers d ON id.dealer_ID = d.rowID LEFT JOIN media m ON d.dealer_media = m.rowID WHERE identity_id='.$criterias['identity_id'].'';
$stmt = $pdo->prepare($sql);
//Excute Query
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
//------------------------------------------
//CHANGE ROWID INTO UUID
//------------------------------------------
function updateRowID($row) {
$row['rowID'] = encodeUuid($row['rowID']);
return $row;
}
$updatedData = array_map('updateRowID', $messages);
//------------------------------------------
//JSON_ENCODE
//------------------------------------------
$messages = json_encode($updatedData, JSON_UNESCAPED_UNICODE);
}
//Send results
echo $messages;
?>