0) { $this->_loadAndFillObject($src['ID'], self::TABLE_NAME, $src); } else { $this->_loadByRow($src, $stripSlashes); } } elseif (intval($src)) { $sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID = :id"; $query = $con->prepare($sql); $query->bindParam(":id", $src); try { $query->execute(); $it = $query->fetchAll(PDO::FETCH_ASSOC); Utils::FillObjectFromRow($this, $it[0]); } catch (Exception $exc) { $exc->getMessage(); } } } public static function Count($filter = null) { return parent::_count(self::TABLE_NAME, $filter); } public static function LoadDataTable($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0) { return parent::_loadDataTable(self::TABLE_NAME, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset); } public static function load($id = 0, $stato = "") { global $con, $LoggedAccount; $rows = array(); if (intval($id) > 0) { if (!empty($stato)) { $filter = "AND STATO = :stato "; } else { $filter = ""; } $sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID=:id " . $filter . " ORDER BY ID ASC "; $query = $con->prepare($sql); $query->bindParam(":id", $id); if (!empty($stato)) { $query->bindParam(":stato", $stato); } try { $query->execute(); $rows = $query->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $exc) { $exc->getMessage(); } } return $rows; } public static function loadFromDomanda($id_domanda = 0, $stato = "") { global $con, $LoggedAccount; $rows = array(); if (intval($id_domanda) > 0) { if (!empty($stato)) { $filter = "AND STATO = :stato "; } else { $filter = ""; } $integrazione = new RichiestaIntegrazione(); $sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID_DOMANDA_SCONTI=:id " . $filter . " ORDER BY ID ASC "; $query = $con->prepare($sql); $query->bindParam(":id", $id_domanda); if (!empty($stato)) { $query->bindParam(":stato", $stato); } try { $query->execute(); $rows = $query->fetch(PDO::FETCH_ASSOC); Utils::FillObjectFromRow($integrazione, $rows); } catch (Exception $exc) { $exc->getMessage(); } } return $integrazione; } public function Save() { global $con, $LoggedAccount; $vars = get_object_vars($this); unset($vars["DATA_RICHIESTA"]); $sql = Utils::prepareQuery(self::TABLE_NAME, $vars); /* Utils::print_array($sql); Utils::print_array($vars); */ $queryabi = $con->prepare($sql); foreach ($vars as $k => $v) { if ($k == "ID" && $v == 0) { continue; } $queryabi->bindValue(":" . $k, $v); } try { $it = parent::_Save($queryabi); if (trim($it['erroreCode']) == 'HY000') { $it['erroreDescrizione'] = 'Richiesta già inserita!
Non è possibile inviare una richiesta di integrazione per la stessa domanda di sconto.'; } } catch (Exception $exc) { $it['erroreDescrizione'] = $exc->getMessage(); } return $it; } public function Parse(&$record, $campo = "") { array_push($record, array("Campo" => $campo, "Valore" => $this->$campo)); } public function calcolaScadenzaDaInvio(): void { if (!empty($this->DATA_INVIO_NOTIFICA)) { try { $dataInvio = new DateTime($this->DATA_INVIO_NOTIFICA); $dataInvio->modify('+30 days'); $this->SCADENZA = $dataInvio->format('d-M-y'); $this->DATA_INVIO_NOTIFICA = Date::dateOracleDate($this->DATA_INVIO_NOTIFICA, 'd-M-y'); } catch (Exception $e) { // Gestione errore se la data è malformata error_log("Errore nel calcolo della scadenza: " . $e->getMessage()); $this->SCADENZA = null; } } else { // Nessuna data di invio => nessuna scadenza calcolabile $this->SCADENZA = null; } } } class CallSoapProtocollo { private string $wsdl; private string $location; private SoapClient $client; public function __construct(string $wsdl, string $location) { $this->wsdl = $wsdl; $this->location = $location; $this->client = new SoapClient($this->wsdl, [ 'location' => $this->location, 'style' => SOAP_RPC, 'use' => SOAP_ENCODED, 'soap_version' => SOAP_1_1, 'cache_wsdl' => WSDL_CACHE_NONE, 'connection_timeout' => 15, 'encoding' => 'UTF-8', 'exceptions' => true, 'stream_context' => stream_context_create([ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ]), 'trace' => 1 ]); } public function inviaRichiesta(string $funzione, array $parametri): ?array { try { // Chiamata SOAP $response = $this->client->__soapCall($funzione, $parametri); // echo "=== XML inviato ===\n"; // echo $this->client->__getLastRequest(); // Ultima risposta XML raw $lastResponse = $this->client->__getLastResponse(); if (empty($lastResponse)) { error_log("Risposta SOAP vuota."); return null; } // Carica XML SOAP $soap = simplexml_load_string($lastResponse); // Naviga nel corpo: soap:Body -> InserisciProtocolloEAnagraficheStringResponse -> InserisciProtocolloEAnagraficheStringResult $body = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')->Body; $risposta = $body->children('http://tempuri.org/')->InserisciProtocolloEAnagraficheStringResponse; $resultXmlEscaped = (string) $risposta->InserisciProtocolloEAnagraficheStringResult; // Decodifica da HTML entities a XML puro $resultXml = html_entity_decode($resultXmlEscaped); // Parsing XML interno $internalXml = simplexml_load_string($resultXml); if (!$internalXml) { error_log("Parsing XML interno fallito."); return null; } // Conversione in array return json_decode(json_encode($internalXml), true); } catch (SoapFault $e) { // Log o gestione errore SOAP // error_log("Errore SOAP: " . $e->getMessage()); // echo "
" . print_r($e, true) . "
"; return null; } catch (Exception $e) { // Errori generici // error_log("Errore generico: " . $e->getMessage()); // echo "
" . print_r($e, true) . "
"; return null; } } public function getUltimaRispostaRaw(): string { return $this->client->__getLastResponse(); } } class IntegrazioniEmailQueue extends DataClass { const TABLE_NAME = "INTEGRAZIONI_EMAIL_QUEUE"; const SEQ_NAME = 'SEQ_EMAIL_QUEUE'; public $ID = 0; public $ID_RICHIESTA = 0; public $DESTINATARIO = ""; public $OGGETTO = ""; public $CORPO = ""; public $STATO = 0; //-- 1 = INVIATA, 99 = ERRORE public $TENTATIVI = 0; public $ERRORE_MESSAGGIO = ""; public $DATA_INSERIMENTO = null; public $DATA_INVIO = null; public function __construct($src = null) { global $con; if ($src == null) { return; } $stripSlashes = 0; if (is_array($src)) { if (isset($src['ID']) && $src['ID'] > 0) { $this->_loadAndFillObject($src['ID'], self::TABLE_NAME, $src); } else { $this->_loadByRow($src, $stripSlashes); } } elseif (intval($src)) { $sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID = :id"; $query = $con->prepare($sql); $query->bindParam(":id", $src); try { $query->execute(); $it = $query->fetchAll(PDO::FETCH_ASSOC); Utils::FillObjectFromRow($this, $it[0]); } catch (Exception $exc) { $exc->getMessage(); } } } public static function load($id = 0, $stato = "") { global $con, $LoggedAccount; $rows = array(); if (intval($id) > 0) { if (!empty($stato)) { $filter = "AND STATO = :stato "; } else { $filter = ""; } $sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID=:id " . $filter . " ORDER BY ID ASC "; $query = $con->prepare($sql); $query->bindParam(":id", $id); if (!empty($stato)) { $query->bindParam(":stato", $stato); } try { $query->execute(); $rows = $query->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $exc) { $exc->getMessage(); } } return $rows; } public static function loadQueue($stato = 0) { global $con, $LoggedAccount; $rows = array(); if (!empty($stato)) { $filter = "AND STATO = :stato "; } else { $filter = ""; } $sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID > 0 " . $filter . " ORDER BY DATA_INSERIMENTO ASC "; $query = $con->prepare($sql); if (!empty($stato)) { $query->bindParam(":stato", $stato); } try { $query->execute(); $rows = $query->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $exc) { $exc->getMessage(); } return $rows; } public static function Count($filter = null) { return parent::_count(self::TABLE_NAME, $filter); } public function Save() { global $con, $LoggedAccount; $vars = get_object_vars($this); unset($vars["DATA_INSERIMENTO"]); $sql = Utils::prepareQuery(self::TABLE_NAME, $vars); /* Utils::print_array($sql); Utils::print_array($vars); */ $queryabi = $con->prepare($sql); foreach ($vars as $k => $v) { if ($k == "ID" && $v == 0) { continue; } $queryabi->bindValue(":" . $k, $v); } try { $it = parent::_Save($queryabi); if (trim($it['erroreCode']) == 'HY000') { $it['erroreDescrizione'] = 'Richiesta già inserita!
Non è possibile inviare una richiesta di integrazione per la stessa domanda di sconto.'; } } catch (Exception $exc) { $it['erroreDescrizione'] = $exc->getMessage(); } return $it; } public function Parse(&$record, $campo = "") { array_push($record, array("Campo" => $campo, "Valore" => $this->$campo)); } public function processaCodaEmail() { global $con, $LoggedAccount; $rows = $this->loadQueue(0); // Stato 0 = In attesa di invio foreach ($rows as $row) { $emailQueue = new IntegrazioniEmailQueue($row['ID']); $emailQueue->STATO = 1; // Imposta lo stato a "Inviata" $emailQueue->DATA_INVIO = date(FORMAT_TIMESTAMP_ORACLE); // Invia l'email (logica di invio email non implementata qui) // ... // Salva lo stato aggiornato $emailQueue->Save(); } } }