} $sXML = ""; foreach ($_POST as $sKey => $sValue) { if (strncmp($sKey, "_", 1) != 0) { $sXML .= "<arg id=\"" . trim($sKey) . "\">" . trim(htmlspecialchars($sValue)) . "</arg>"; } } foreach ($_GET as $sKey => $sValue) { if (strncmp($sKey, "_", 1) != 0) { if (!isset($_POST[$sKey])) { $sXML .= "<arg id=\"" . trim($sKey) . "\">" . trim(htmlspecialchars($sValue)) . "</arg>"; } } } $sXML = "<args>" . $sXML . "</args>"; $oPending = new CRowtblpending(); $oPending->SetGroupId($nCommandGroup); $oPending->SetInTimestamp(date("Y-m-d H:i:s")); $oPending->SetInXML($sXML); $oPending->SetSource(0); $oPending->SetCompleted(2); $bError = !$oPending->Insert($oSession); if ($bError) { $sMessage = "<error><message>" . $oPending->GetErrorInfo() . "</message></error>"; } else { $nKey = $oPending->GetPendingId(); $nSleep = 0; do { if ($nSleep > 0) { sleep(1); }
function Synchronise($p_oMaster, $p_oNonMaster, $p_nSystemId = 0) { $this->m_nError = $this->m_nDBO_OK; $p_oMaster->SetSynchronising(true); $p_oNonMaster->SetSynchronising(true); $sOrder = "PENDINGID"; $this->SetOrder($sOrder); $this->Select($p_oMaster); $oNonMaster = new CRowtblpending(); $oNonMaster->SetOrder($sOrder); $oNonMaster->Select($p_oNonMaster); while (!($this->GetEof() && $oNonMaster->GetEof())) { $nCompare = 0; if ($this->GetEof()) { $nCompare = 1; } else { if ($oNonMaster->GetEof()) { $nCompare = -1; } else { if ($this->m_nPendingId > $oNonMaster->GetPendingId()) { $nCompare = 1; } else { if ($this->m_nPendingId < $oNonMaster->GetPendingId()) { $nCompare = -1; } } } } if ($nCompare == 0) { $nUpdate = 0; if ($nUpdate != 0) { if ($p_nSystemId == -1) { $nUpdate = 1; } else { if ($oNonMaster->GetPendingId() <= $p_nSystemId) { $nUpdate = 1; } } } if ($nUpdate == 1) { if (!$this->Update($p_oNonMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } else { if (!$oNonMaster->Update($p_oMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } $oNonMaster->MoveNext(); $this->MoveNext(); } else { if ($nCompare > 0) { if ($p_nSystemId == -1) { if (!$oNonMaster->Delete($p_oNonMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } else { if ($oNonMaster->GetPendingId() <= $p_nSystemId) { if (!$oNonMaster->Delete($p_oNonMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } else { if (!$oNonMaster->Insert($p_oMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } } $oNonMaster->MoveNext(); } else { if ($p_nSystemId == -1) { if (!$this->Insert($p_oNonMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } else { if ($this->m_nPendingId <= $p_nSystemId) { if (!$this->Insert($p_oNonMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } else { if (!$this->Delete($p_oMaster)) { $this->m_nError = $this->m_nDBO_SYNC_FAILURE; $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return false; } } } $this->MoveNext(); } } } $p_oMaster->SetSynchronising(false); $p_oNonMaster->SetSynchronising(false); return true; }