File: /home/imensosw/www/imenso.co/demo/individuals/groups/gapps_trigger.php
<?php
require '/var/www/html/functions.php';
$time = time();
$individuals = new Individuals();
$teachers = new Teachers();
$allvalidswaps = $individuals->getAllValidSwaps();
$count = $allvalidswaps->rowCount();
if ($count > 0) {
echo "<p>There are swaps</p>";
while ($data = $allvalidswaps->fetch(PDO::FETCH_LAZY)) {
$expiry = $data['expiry'];
$swapid = $data['swapid'];
if ($time >= $expiry) {
echo "<p>There are swaps to cancel</p>";
$accountid = $data['accountid'];
$setexpiry = $individuals->cancelSwap($swapid);
if ($setexpiry) {
$email = $teachers->getSpecificAccInfo($accountid,"email");
$secemail = $teachers->getSpecificAccInfo($accountid,"secemail");
$nlanguage = $teachers->getSpecificAccInfo($accountid,"nlanguage");
$fname = $teachers->getSpecificAccInfo($accountid,"fname");
if ($nlanguage == "Spanish") {
$subject = "Intercambio cancelado";
$msg = "Hola ";
$msg .= $fname;
$msg .= " <p>Su pedido para intercambiar clases con un colega se ha vencido. Desafortunadamente, nadie lo aceptó, y su clase sigue programada.</p>";
$msg .= "<p>Saludos Cordiales,<br>";
$msg .= "El Equipo de OCTB</p>";
$msg .= "<p>Swap ID: ";
$msg .= $swapid;
$msg .= "</p>";
} else {
$subject = "Swap Cancelled";
$msg = "Hello ";
$msg .= $fname;
$msg .= " <p>Your recent swap request has expired. Unfortunately, no one accepted it, and your class remains scheduled.</p>";
$msg .= "<p>Kind Regards,<br>";
$msg .= "OCTB Team</p>";
$msg .= "<p>Swap ID: ";
$msg .= $swapid;
$msg .= "</p>";
}
if (empty($secemail)) {
$to = $email;
} else {
$to = "".$email.",".$secemail."";
}
$teachers->emailTest("",$subject,$to,$msg);
echo "<p>$email emailed to cancel $swapid</p>";
}
} else {
echo "<p>$swapid has not expired.</p>";
}
}
} else {
echo "<p>There are no swaps</p>";
}
?>