$v) { if ($str) $str .=", "; $str .= "$k = '".addslashes($v)."'"; } $q = "replace into $tbl set $str"; mysql_query($q, $rLink); $q = "replace into `transaction_mstr_log` set tble='$tbl', tid='$tid', lastmod='$curRemMod', chgby = '{$snd['chgby']}'"; mysql_query($q, $rLink); // the info has to be put itno the regular trans-log as well so that it will be relayed to the server if this is a cross sync session $q = "replace into `transaction_log` set tble='$tbl', tid='$tid', lastmod='$curRemMod', chgby = '{$snd['chgby']}'"; mysql_query($q, $rLink); mysql_query("delete from `transaction_log` where tid='$tid'", $mLink); // remove from the log $doNotRcvList[] = $tid; } else { $q = "delete from `transaction_log` where tid='$tid'"; mysql_query($q, $mLink); } } else { $q = "delete from `transaction_log` where tid='$tid'"; mysql_query($q, $mLink); } } } // 20110912: receive collection moved to this point: see note above (line 255) // get the reference for all transactions newer than the last one received and NOT originating from THIS computer $rcvQuery = "select * from `transaction_mstr_log` where lastmod >= '$lastmod' and chgby != '{$_SESSION['instance']['prefix']}' order by lastmod asc, tid asc limit 250"; $toRcv = mysql_query($rcvQuery, $rLink); while ($rcv = mysql_fetch_assoc($toRcv)) { // block all receiving TID's that were just sent if (array_search($rcv['tid'], $doNotRcvList) === false) { $tbl = $rcv['tble']; $tid = $rcv['tid']; $lastmod = $rcv['lastmod']; $chgby = $rcv['chgby']; $r = mysql_query("show tables like '$tbl'", $mLink); if (mysql_num_rows($r)) { $str = ""; $q = "select * from $tbl where tid='$tid'"; if (($data = mysql_query($q, $rLink)) !== false) { $data = mysql_fetch_assoc($data); if (is_array($data)) { foreach ($data as $k => $v) { if ($str) $str .=", "; $str .= "$k = '".addslashes($v)."'"; } mysql_query("replace into $tbl set $str", $mLink); // mysql_query("replace into `transaction_log` set tid='$tid', lastmod = '$lastmod', tble = '$tbl', chgby = '$chgby'", $mLink); mysql_query("replace into `transaction_mstr_log` set tid='$tid', lastmod = '$lastmod', tble = '$tbl', chgby = '$chgby'", $mLink); mysql_query("update system set lastmod ='$lastmod'", $mLink); } } } else { mysql_query("replace into `transaction_backlog` set tid = '$tid', lastmod = '$lastmod', tble = '$tbl', chgby = '$chgby'", $mLink); } } } // to ensure that the block list ($doNotRcvList) resets every time, remove it now unset($sendList); } } if (($rLink = @mysql_connect($_SESSION['instance']['sdbIfce'], $_SESSION['instance']['sdbUser'], $_SESSION['instance']['sdbPass'], true)) !== false) { mysql_select_db($_SESSION['instance']['sdbName'], $rLink) or die("Could not select remote database"); // try to get sync backlog ... ONCE per session if (!isset($_SESSION['instance']['backlog'])) // we haven't tried to send backlog yet in this session { $_SESSION['instance']['backlog'] = true; $tList = mysql_query("select tble from `transaction_backlog` group by tble", $mLink); while ($l = mysql_fetch_assoc($tList)) { $r = mysql_query("show tables like '{$l['tble']}'", $mLink); if (mysql_num_rows($r)) { // this table now exists, so process these entries $pList = mysql_query("select * from `transaction_backlog` where tble = '{$l['tble']}' order by tid", $mLink); while (list($tid, $lastmod, , $chgby) = mysql_fetch_row($pList)) { $str = ""; $q = "select * from $tbl where tid='$tid'"; if (($data = mysql_query($q, $rLink)) !== false) { $data = mysql_fetch_assoc($data); if (is_array($data)) { foreach ($data as $k => $v) { if ($str) $str .=", "; $str .= "$k = '".addslashes($v)."'"; } mysql_query("replace into $tbl set $str", $mLink); // mysql_query("replace into `transaction_log` set tid='$tid', lastmod = '$lastmod', tble = '$tbl', chgby = '$chgby'", $mLink); mysql_query("replace into `transaction_mstr_log` set tid='$tid', lastmod = '$lastmod', tble = '$tbl', chgby = '$chgby'", $mLink); mysql_query("update system set lastmod ='$lastmod'", $mLink); } } } } } } } ?>