First upload
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php require_once('Connections/bkngstm.php'); ?>
|
||||
<?php require_once('webassist/mysqli/rsobj.php'); ?>
|
||||
<?php require_once('webassist/mysqli/queryobj.php'); ?>
|
||||
<?php if (isset($_POST['propagatestartdate'])) { $propagatestartdate=$_POST['propagatestartdate']; } ?>
|
||||
<?php if (isset($_POST['propagateenddate'])) { $propagateenddate=$_POST['propagateenddate']; } ?>
|
||||
<?php if (isset($_POST['idservice'])) { $idservice=$_POST['idservice']; } ?>
|
||||
<?php if (isset($_POST['dayclass'])) { $dayclass=$_POST['dayclass']; } ?>
|
||||
<?php if (isset($_POST['timeclass'])) { $timeclass=$_POST['timeclass']; } ?>
|
||||
<?php if (isset($_POST['durationtime'])) { $durationtime=$_POST['durationtime']; }
|
||||
|
||||
?>
|
||||
<?php //propagate classes
|
||||
|
||||
// Create connection
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
?>
|
||||
<?php //fake variable
|
||||
//$propagateenddate="2024-12-01";
|
||||
//$dayclass="Tuesday";
|
||||
//$idservice="1";
|
||||
//$timeclass="18:30";
|
||||
//$durationtime="1";
|
||||
?>
|
||||
<?php
|
||||
//define next day
|
||||
|
||||
$nextClassDay = strtotime($propagatestartdate); // Utilizza la data di propagazione come data di inizio
|
||||
|
||||
$dayOfWeek = date('w', $nextClassDay); // Ottieni il giorno della settimana della data di partenza
|
||||
|
||||
// Mappa dei nomi dei giorni in inglese ai valori numerici dei giorni della settimana
|
||||
$daysOfWeek = array(
|
||||
"Sunday" => 0,
|
||||
"Monday" => 1,
|
||||
"Tuesday" => 2,
|
||||
"Wednesday" => 3,
|
||||
"Thursday" => 4,
|
||||
"Friday" => 5,
|
||||
"Saturday" => 6
|
||||
);
|
||||
|
||||
// Ottieni il valore numerico del giorno della settimana desiderato
|
||||
$desiredDayValue = $daysOfWeek[$dayclass];
|
||||
|
||||
// Calcola quanti giorni mancano fino al prossimo o stesso giorno della settimana desiderato
|
||||
$daysUntilNextDayClass = ($desiredDayValue + 7 - $dayOfWeek) % 7;
|
||||
|
||||
// Aggiungi il numero di giorni al timestamp della data di partenza per ottenere il primo giorno della settimana desiderato
|
||||
$firstDayClassTimestamp = $nextClassDay + $daysUntilNextDayClass * 24 * 60 * 60;
|
||||
|
||||
$firstDayClassDate = date('Y-m-d', $firstDayClassTimestamp);
|
||||
|
||||
|
||||
$datenext = $firstDayClassDate;
|
||||
$datenextTimestamp=strtotime($datenext);
|
||||
|
||||
$endClassDay = strtotime($propagateenddate); // Utilizza la data di propagazione come data di inizio
|
||||
|
||||
$dateend = date('Y-m-d', $endClassDay); // stop date
|
||||
|
||||
|
||||
|
||||
while ($datenext <= $dateend) {
|
||||
// merge time with date
|
||||
$datenextschedule=$datenext.' '.$timeclass;
|
||||
|
||||
//query to check if present
|
||||
$checkdateclass = new WA_MySQLi_RS("checkdateclass",$bkngstm,0);
|
||||
$checkdateclass->setQuery("SELECT * FROM serviceschedule WHERE serviceschedule.dateschedule='$datenextschedule' AND serviceschedule.idservice='$idservice'");
|
||||
$checkdateclass->execute();
|
||||
|
||||
// Query per verificare se il giorno è un giorno di pausa
|
||||
$checkdayoff = new WA_MySQLi_RS("checkdayoff", $bkngstm, 0);
|
||||
$checkdayoff->setQuery("SELECT * FROM dayoff WHERE dayoffdate = '$datenext'");
|
||||
$checkdayoff->execute();
|
||||
|
||||
|
||||
|
||||
if (empty($checkdateclass->getColumnVal("idserviceschedule")) && empty($checkdayoff->getColumnVal("iddayoff"))) {
|
||||
$sql = "INSERT INTO serviceschedule (idservice, dateschedule, scheduleday, startingtime, durationtime)
|
||||
VALUES ($idservice, '$datenextschedule', '$dayclass', '$timeclass', $durationtime)";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "New record created successfully";
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
|
||||
}
|
||||
$datenextTimestamp =strtotime("+7 day", $datenextTimestamp);
|
||||
$datenext=date('Y-m-d', $datenextTimestamp);
|
||||
echo $nextClassDay;
|
||||
echo $datenext;
|
||||
}
|
||||
|
||||
header("Location: admin-services.php?message=success"); ?>
|
||||
Reference in New Issue
Block a user