function code_peek() { if ($_SESSION['logged_in'] != "yes") { echo "Not logged in."; exit; } if ($_REQUEST['r_format'] == "COMPACT") { $current_format = "COMPACT"; $format_link = "<a href='' id='format-switch' data-resource='{$_REQUEST['r_resource']}' data-class='{$_REQUEST['r_class']}' data-format='COMPACT-DECODED'>Switch to COMPACT-DECODED</a>"; } else { $current_format = "COMPACT-DECODED"; $format_link = "<a href='' id='format-switch' data-resource='{$_REQUEST['r_resource']}' data-class='{$_REQUEST['r_class']}' data-format='COMPACT'>Switch to COMPACT</a>"; } // set things up $rets = new phRETS(); $rets->AddHeader("Accept", "*/*"); $rets->AddHeader("RETS-Version", "RETS/{$_SESSION['rets_version']}"); $rets->AddHeader("User-Agent", $_SESSION['user_agent']); $rets->SetParam("compression_enabled", true); if ($_SESSION['force_basic'] == "true") { $rets->SetParam("force_basic_authentication", true); } // make first connection $connect = $rets->Connect($_SESSION['login_url'], $_SESSION['username'], $_SESSION['password'], $_SESSION['ua_pwd']); if (!$connect) { $error_details = $rets->Error(); $error_text = strip_tags($error_details['text']); $error_type = strtoupper($error_details['type']); show_error_page("<center><span style='color:red;font-weight:bold;'>{$error_type} ({$error_details['code']}) {$error_text}</span></center>"); } $records = array(); $search = null; if (detect_capable_server($_SESSION['login_url']) === 1) { $search = $rets->SearchQuery($_REQUEST['r_resource'], $_REQUEST['r_class'], '*', array('Format' => $current_format, 'Limit' => 5, 'RestrictedIndicator' => 'RETSMDRESTR')); while ($rec = $rets->FetchRow($search)) { $records[] = $rec; } } elseif (detect_capable_server($_SESSION['login_url']) === 2) { $search = $rets->SearchQuery($_REQUEST['r_resource'], $_REQUEST['r_class'], "", array('Format' => $current_format, 'QueryType' => 'DMQL2', 'Limit' => 5, 'RestrictedIndicator' => 'RETSMDRESTR')); while ($rec = $rets->FetchRow($search)) { $records[] = $rec; } } else { } if (!$search) { $error_details = $rets->Error(); $error_text = strip_tags($error_details['text']); $error_type = strtoupper($error_details['type']); show_error_page("<center><span style='color:red;font-weight:bold;'>{$error_type} ({$error_details['code']}) {$error_text}</span></center>"); } ?> <div class='box'> <a name='md-details'></a> <div class='box_heading dark-bg'> <?php echo $_REQUEST['r_resource']; ?> :<?php echo $_REQUEST['r_class']; ?> - View Sample Data<br/> <small><?php echo $current_format; ?> format (<?php echo $format_link; ?> )</small> </div> <div class='box_content light-bg'> <div style="width: 100%; height: 250px; overflow: auto;"> <?php $field_list = $rets->SearchGetFields($search); $system_to_long = array(); $table_metadata = $rets->GetMetadataTable($_REQUEST['r_resource'], $_REQUEST['r_class']); foreach ($table_metadata as $fi) { $system_to_long["{$fi['SystemName']}"] = $fi['LongName']; } echo "<table border='1' cellpadding='2' cellspacing='0' width='100%' class='metadata_details_fields'>\n"; echo "<tr>\n"; foreach ($field_list as $fi) { echo "<td valign='top'><b>{$fi}</b><br/>{$system_to_long["{$fi}"]}</td>"; } echo "</tr>\n"; $field_bg = "white-bg"; foreach ($records as $rec) { echo "<tr class='{$field_bg}'>"; foreach ($field_list as $fi) { if ($rec[$fi] == "RETSMDRESTR") { $rec[$fi] = "<span style='color:red;'>RESTRICTED</span>"; } echo "<td valign='top'>{$rec[$fi]}</td>\n"; } echo "</tr>\n"; $field_bg = $field_bg == "light-bg" ? "white-bg" : "light-bg"; } echo "<tr>\n"; foreach ($field_list as $fi) { echo "<td valign='top'><b>{$fi}</b><br/>{$system_to_long["{$fi}"]}</td>"; } echo "</tr>\n"; echo "</table>\n"; $rets->Disconnect(); echo "\n\t\t</div>\n\t</div>\n</div>\n\n"; }
$fields_order = array(); while ($maxrows) { $query = "({$rets_modtimestamp_field}={$previous_start_time}+)"; // run RETS search if ($debugging) { echo " + Query: {$query} Limit: {$limit} Offset: {$offset}<br>\n"; } $search = $rets->SearchQuery($resource, $class, $query, array('Limit' => $limit, 'Offset' => $offset, 'Format' => 'COMPACT-DECODED', 'Count' => 1)); if ($rets->NumRows() > 0) { if ($offset == 1) { // print filename headers as first line $fields_order = $rets->SearchGetFields($search); fputcsv($fh, $fields_order); } // process results while ($record = $rets->FetchRow($search)) { $this_record = array(); foreach ($fields_order as $fo) { $this_record[] = $record[$fo]; } fputcsv($fh, $this_record); } $offset = $offset + $rets->NumRows(); } $maxrows = $rets->IsMaxrowsReached(); if ($debugging) { echo " + Total found: {$rets->TotalRecordsFound()}<br>\n"; } $rets->FreeResult($search); } fclose($fh);