function outputXmlSessionFile($sessionid, $filenr, $bOcXmlTag, $bDocType, $bXmlDecl, $ziptype) { sql('UPDATE xmlsession SET last_use=NOW() WHERE id=&1', $sessionid); /* begin calculate which records to transfer */ $rs = sql('SELECT `users`, `caches`, `cachedescs`, `cachelogs`, `pictures`, `removedobjects` FROM `xmlsession` WHERE `id`=&1 AND `cleaned`=0', $sessionid + 0); if (mysql_num_rows($rs) == 0) { die('invalid sessionid'); } $rRecordsCount = sql_fetch_assoc($rs); mysql_free_result($rs); $startat = ($filenr - 1) * 500; if ($startat < 0 || $startat > $rRecordsCount['users'] + $rRecordsCount['caches'] + $rRecordsCount['cachedescs'] + $rRecordsCount['cachelogs'] + $rRecordsCount['pictures'] + $rRecordsCount['removedobjects'] - 1) { die('filenr out of range'); } $recordnr[0] = 0; $recordnr[1] = $rRecordsCount['users']; $recordnr[2] = $recordnr[1] + $rRecordsCount['caches']; $recordnr[3] = $recordnr[2] + $rRecordsCount['cachedescs']; $recordnr[4] = $recordnr[3] + $rRecordsCount['cachelogs']; $recordnr[5] = $recordnr[4] + $rRecordsCount['pictures']; $recordnr[6] = $recordnr[5] + $rRecordsCount['removedobjects']; if ($recordnr[6] > $startat + 500) { $endat = $startat + 500; } else { $endat = $recordnr[6] - $startat; } // echo $startat . ' ' . $endat . '<br /><br />'; // echo '<table>'; // echo '<tr><td>sql-start</td><td>sql-count</td><td>count</td><td>begin</td><td>end</td></tr>'; for ($i = 0; $i < 6; $i++) { if ($startat >= $recordnr[$i] && $startat + 500 < $recordnr[$i + 1]) { if ($recordnr[$i + 1] - $startat > 500) { $limits[$i] = array('start' => $startat - $recordnr[$i], 'count' => 500); } else { $limits[$i] = array('start' => $startat - $recordnr[$i], 'count' => $recordnr[$i + 1] - $startat); } //$limits[$i] = array('start' => 'a', 'count' => 'a'); } else { if ($startat >= $recordnr[$i] && $startat < $recordnr[$i + 1]) { $limits[$i] = array('start' => $startat - $recordnr[$i], 'count' => $recordnr[$i + 1] - $startat); //$limits[$i] = array('start' => 'b', 'count' => 'b'); } else { if ($startat + 500 >= $recordnr[$i] && $startat + 500 < $recordnr[$i + 1]) { if ($startat + 500 < $recordnr[$i + 1]) { $limits[$i] = array('start' => 0, 'count' => 500 - $recordnr[$i] + $startat); } else { $limits[$i] = array('start' => 0, 'count' => $recordnr[$i + 1] - $recordnr[$i]); } if ($limits[$i]['count'] < 0) { $limits[$i]['count'] = 0; } //$limits[$i] = array('start' => 'c', 'count' => 'c'); } else { if ($startat < $recordnr[$i] && $startat + 500 >= $recordnr[$i + 1]) { $limits[$i] = array('start' => 0, 'count' => $recordnr[$i + 1] - $recordnr[$i]); //$limits[$i] = array('start' => 'd', 'count' => 'd'); } else { $limits[$i] = array('start' => '0', 'count' => '0'); } } } } // echo '<tr><td>' . $limits[$i]['start'] . '</td><td>' . $limits[$i]['count'] . '</td><td>' . ($recordnr[$i + 1] - $recordnr[$i]) . '</td><td>' . $recordnr[$i] . '</td><td>' . $recordnr[$i + 1] . '</td></tr>'; } // echo '</table>'; // echo '<a href="ocxml11.php?sessionid=' . $sessionid . '&file=' . ($filenr - 1) . '">Zurück</a><br />'; // echo '<a href="ocxml11.php?sessionid=' . $sessionid . '&file=' . ($filenr + 1) . '">Vor</a>'; /* end calculate which records to transfer */ sql('CREATE TEMPORARY TABLE `tmpxml_users` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`=&1 AND `object_type`=4 LIMIT &2, &3', $sessionid, $limits[0]['start'], $limits[0]['count']); sql('CREATE TEMPORARY TABLE `tmpxml_caches` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`=&1 AND `object_type`=2 LIMIT &2, &3', $sessionid, $limits[1]['start'], $limits[1]['count']); sql('CREATE TEMPORARY TABLE `tmpxml_cachedescs` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`=&1 AND `object_type`=3 LIMIT &2, &3', $sessionid, $limits[2]['start'], $limits[2]['count']); sql('CREATE TEMPORARY TABLE `tmpxml_cachelogs` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`=&1 AND `object_type`=1 LIMIT &2, &3', $sessionid, $limits[3]['start'], $limits[3]['count']); sql('CREATE TEMPORARY TABLE `tmpxml_pictures` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`=&1 AND `object_type`=6 LIMIT &2, &3', $sessionid, $limits[4]['start'], $limits[4]['count']); sql('CREATE TEMPORARY TABLE `tmpxml_removedobjects` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`=&1 AND `object_type`=7 LIMIT &2, &3', $sessionid, $limits[5]['start'], $limits[5]['count']); outputXmlFile($sessionid, $filenr, $bXmlDecl, $bOcXmlTag, $bDocType, $ziptype); }
function outputXmlSessionFile($sessionid, $filenr, $bOcXmlTag, $bDocType, $bXmlDecl, $ziptype) { XDb::xSql('UPDATE xmlsession SET last_use=NOW() WHERE id= ? ', $sessionid); /* begin calculate which records to transfer */ $rs = XDb::xSql('SELECT `users`, `caches`, `cachedescs`, `cachelogs`, `pictures`, `removedobjects` FROM `xmlsession` WHERE `id`= ? AND `cleaned`=0', $sessionid); if (!($rRecordsCount = XDb::xFetchArray($rs))) { die('invalid sessionid'); } XDb::xFreeResults($rs); $startat = ($filenr - 1) * 500; if ($startat < 0 || $startat > $rRecordsCount['users'] + $rRecordsCount['caches'] + $rRecordsCount['cachedescs'] + $rRecordsCount['cachelogs'] + $rRecordsCount['pictures'] + $rRecordsCount['removedobjects'] - 1) { die('filenr out of range'); } $recordnr[0] = 0; $recordnr[1] = $rRecordsCount['users']; $recordnr[2] = $recordnr[1] + $rRecordsCount['caches']; $recordnr[3] = $recordnr[2] + $rRecordsCount['cachedescs']; $recordnr[4] = $recordnr[3] + $rRecordsCount['cachelogs']; $recordnr[5] = $recordnr[4] + $rRecordsCount['pictures']; $recordnr[6] = $recordnr[5] + $rRecordsCount['removedobjects']; if ($recordnr[6] > $startat + 500) { $endat = $startat + 500; } else { $endat = $recordnr[6] - $startat; } for ($i = 0; $i < 6; $i++) { if ($startat >= $recordnr[$i] && $startat + 500 < $recordnr[$i + 1]) { if ($recordnr[$i + 1] - $startat > 500) { $limits[$i] = array('start' => $startat - $recordnr[$i], 'count' => 500); } else { $limits[$i] = array('start' => $startat - $recordnr[$i], 'count' => $recordnr[$i + 1] - $startat); } //$limits[$i] = array('start' => 'a', 'count' => 'a'); } else { if ($startat >= $recordnr[$i] && $startat < $recordnr[$i + 1]) { $limits[$i] = array('start' => $startat - $recordnr[$i], 'count' => $recordnr[$i + 1] - $startat); //$limits[$i] = array('start' => 'b', 'count' => 'b'); } else { if ($startat + 500 >= $recordnr[$i] && $startat + 500 < $recordnr[$i + 1]) { if ($startat + 500 < $recordnr[$i + 1]) { $limits[$i] = array('start' => 0, 'count' => 500 - $recordnr[$i] + $startat); } else { $limits[$i] = array('start' => 0, 'count' => $recordnr[$i + 1] - $recordnr[$i]); } if ($limits[$i]['count'] < 0) { $limits[$i]['count'] = 0; } //$limits[$i] = array('start' => 'c', 'count' => 'c'); } else { if ($startat < $recordnr[$i] && $startat + 500 >= $recordnr[$i + 1]) { $limits[$i] = array('start' => 0, 'count' => $recordnr[$i + 1] - $recordnr[$i]); } else { $limits[$i] = array('start' => '0', 'count' => '0'); } } } } } /* end calculate which records to transfer */ XDb::xSql('CREATE TEMPORARY TABLE `tmpxml_users` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`= ? AND `object_type`=4 LIMIT ' . $limits[0]['start'] . ',' . $limits[0]['count'], $sessionid); XDb::xSql('CREATE TEMPORARY TABLE `tmpxml_caches` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`= ? AND `object_type`=2 LIMIT ' . $limits[1]['start'] . ',' . $limits[1]['count'], $sessionid); XDb::xSql('CREATE TEMPORARY TABLE `tmpxml_cachedescs` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`= ? AND `object_type`=3 LIMIT ' . $limits[2]['start'] . ',' . $limits[2]['count'], $sessionid); XDb::xSql('CREATE TEMPORARY TABLE `tmpxml_cachelogs` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`= ? AND `object_type`=1 LIMIT ' . $limits[3]['start'] . ',' . $limits[3]['count'], $sessionid); XDb::xSql('CREATE TEMPORARY TABLE `tmpxml_pictures` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`= ? AND `object_type`=6 LIMIT ' . $limits[4]['start'] . ',' . $limits[4]['count'], $sessionid); XDb::xSql('CREATE TEMPORARY TABLE `tmpxml_removedobjects` (`id` int(11), PRIMARY KEY (`id`)) SELECT `object_id` `id` FROM `xmlsession_data` WHERE `session_id`= ? AND `object_type`=7 LIMIT ' . $limits[5]['start'] . ',' . $limits[5]['count'], $sessionid); outputXmlFile($sessionid, $filenr, $bXmlDecl, $bOcXmlTag, $bDocType, $ziptype); }