prepare($sql); // Controlla se la preparazione della query ha avuto successo if ($stmt === false) { die('Errore nella preparazione della query: ' . $conn->error); } $stmt->bind_param("i", $idtd); // "i" indica che l'id è un intero $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); $statustd = $row['statustd']; $idtrftd = $row['idtrf']; $tdnumber = $row['tdnumber']; $tdrev = $row['td_rev']; $trfmod = $row['trfmod']; $namecompanyclient = $row['companyname_company']; $nameclient = $row['first_name']; $emailuserclient = $row['email']; $stmt->close(); if ($modifytrf == 'Y') { // Costruisci l'URL con il parametro GET $url = "https://www.cimac.it/modulo_certificazione/public/previewtrf.php?idtrf=" . urlencode($idtrf); // Recupera i cookie di sessione $cookies = ''; foreach ($_COOKIE as $key => $value) { $cookies .= $key . '=' . $value . '; '; } // Esegui il file previewtrf.php in background con cURL $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 15); // Timeout leggermente più lungo curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_COOKIE, $cookies); // Invia i cookie di sessione // Aggiungi gestione degli errori cURL $response = curl_exec($ch); if (curl_errno($ch)) { $error_msg = curl_error($ch); error_log("cURL error: " . $error_msg, 3, "../logfile.log"); // Sostituisci con il percorso del tuo file di log } else { // Registra la risposta per debug error_log("cURL response: " . $response, 3, "../logfile.log"); // Sostituisci con il percorso del tuo file di log } curl_close($ch); } // Assicurati che i valori richiesti non siano nulli if (!is_null($dateTrf) && !is_null($idtd) && !is_null($review)) { // Prepara la query di aggiornamento $sql = "UPDATE data_td SET statustd = ?, datelastmod = ?, trfmod = ? WHERE iddata_td = ?"; $stmt = $conn->prepare($sql); if ($stmt === false) { die('Errore nella preparazione della query: ' . $conn->error); } // 's' indica stringa, 'i' indica intero $stmt->bind_param('sssi', $review, $dateTrf, $modifytrf, $idtd); if ($stmt->execute()) { // send mail to Certification team require 'phpmailer/src/Exception.php'; require 'phpmailer/src/PHPMailer.php'; require 'phpmailer/src/SMTP.php'; $mail = new PHPMailer(true); $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $mailhost; // Specify main and backup server $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $mailusername; // SMTP username $mail->Password = $mailpassword; // SMTP password $mail->SMTPSecure = $mailmethod; // Enable encryption, 'ssl' also accepted $mail->Port = $mailport; $mail->From = $fromaddresssmail; $mail->FromName = 'CIMAC Technical File System'; if ($review == "Revision") { $htmlContent = "Hai una nuova Revisione da verificare. E' la numero " . $tdnumber . " - cliente " . $namecompanyclient; $mail->addAddress("info@claudiosironi.com"); // Add a recipient $mail->Subject = "Nuova Revisione: " . $tdnumber; $mail->Body = $htmlContent; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; error_log("Invio email per revisione: " . $htmlContent); } else { $htmlContent = "Buongiorno " . $nameclient . ", Hai un Technical file in attesa di firma. "; $htmlContent .= "E' il numero " . $tdnumber . ". "; $htmlContent .= "Collegati al portale CIMAC per procedere alla verifica ed alla firma. Grazie!"; $mail->addAddress($emailuserclient); // Add a recipient $mail->Subject = "Nuovo Technical File in attesa di Firma " . $tdnumber; $mail->Body = $htmlContent; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; error_log("Invio email per Technical File: " . $htmlContent); } try { $mail->send(); error_log("Email inviata con successo."); } catch (Exception $e) { error_log("Errore nell'invio dell'email: " . $mail->ErrorInfo); } // Reindirizza su archivetd.php se l'aggiornamento è riuscito header('Location: archivetd.php'); exit; } else { die('Errore nell\'esecuzione della query: ' . $stmt->error); } $stmt->close(); } else { // Gestisci il caso in cui alcuni dati richiesti non siano stati inviati echo "Dati mancanti."; // Qui potresti voler reindirizzare l'utente su una pagina di errore o visualizzare un messaggio } } $conn->close();