Advertisement
Guest User

Untitled

a guest
Jun 8th, 2013
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $rets_login_url = "http://maxebrdi.rets.fnismls.com/Rets/FNISRETS.aspx/MAXEBRDI/login?&rets-version=rets/1.5";
  4. $rets_username = "myuser";
  5. $rets_password = "mypass";
  6.  
  7. // use http://retsmd.com to help determine the SystemName of the DateTime field which
  8. // designates when a record was last modified
  9. $rets_status_field = "L_StatusCatID";
  10. $rets_city_field = "L_City";
  11.  
  12. // use http://retsmd.com to help determine the names of the classes you want to pull.
  13. // these might be something like RE_1, RES, RESI, 1, etc.
  14. //"RE_1"
  15. $property_classes = array("LR_5");
  16.  
  17. // DateTime which is used to determine how far back to retrieve records.
  18. // using a really old date so we can get everything
  19. $listing_status = 1;
  20.  
  21. $listing_city = "OAKLAND";
  22.  
  23. //////////////////////////////
  24.  
  25. require_once("phrets.php");
  26.  
  27. // start rets connection
  28. $rets = new phRETS;
  29.  
  30. echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
  31. $connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);
  32.  
  33. if ($connect) {
  34.         echo "  + Connected<br>\n";
  35. }
  36. else {
  37.         echo "  + Not connected:<br>\n";
  38.         print_r($rets->Error());
  39.         exit;
  40. }
  41.  
  42. foreach ($property_classes as $class) {
  43.  
  44.         echo "+ Property:{$class}<br>\n";
  45.  
  46.         $file_name = strtolower("property_{$class}.csv");
  47.         $fh = fopen($file_name, "w+");
  48.  
  49.         $maxrows = true;
  50.         $offset = 1;
  51.         $limit = 1000;
  52.         $fields_order = array();
  53.  
  54.         while ($maxrows) {
  55.  
  56.                 $query = "({$rets_status_field}={$listing_status}),({$rets_city_field}={$listing_city})";
  57.  
  58.                 // run RETS search
  59.                 echo "   + Query: {$query}  Limit: {$limit}  Offset: {$offset}<br>\n";
  60.                 $search = $rets->SearchQuery("Property", $class, $query, array("Limit" => $limit, "Offset" => $offset, "Format" => "COMPACT", "Select" => "L_ListingID,L_Class,L_Type_,L_Status,L_AskingPrice,L_Keyword2,L_Keyword3,L_Keyword4,L_SquareFeet,L_Remarks,L_Address,L_City,L_State,LO1_OrganizationName,LA1_AgentLicenseID,LA1_UserFirstName,LA1_UserLastName,L_PictureCount", "Count" => 1));
  61.  
  62.                 if ($rets->NumRows() > 0) {
  63.  
  64.                         if ($offset == 1) {
  65.                                 // print filename headers as first line
  66.                                 $fields_order = $rets->SearchGetFields($search);
  67.                                 fputcsv($fh, $fields_order);
  68.                         }
  69.  
  70.                         // process results
  71.                         while ($record = $rets->FetchRow($search)) {
  72.                                 $this_record = array();
  73.                                 foreach ($fields_order as $fo) {
  74.                                         $this_record[] = $record[$fo];
  75.                                 }
  76.                                 fputcsv($fh, $this_record);
  77.  
  78.                                 $photos = $rets->GetObject("Property", "Photo", $record['L_ListingID']);
  79.                                 foreach ($photos as $photo)
  80.                                 {
  81.                                     $listing = $photo['Content-ID'];
  82.                                     $number = $photo['Object-ID'];
  83.  
  84.                                     if ($photo['Success'] == true) {
  85.                                         file_put_contents("photos/{$listing}-{$number}.jpg", $photo['Data']);                
  86.                                     }
  87.                                     else {
  88.                                         echo "Error ({$photo['Content-ID']}-{$photo['Object-ID']}";
  89.                                     }
  90.                                }
  91.                         }
  92.  
  93.                         $offset = ($offset + $rets->NumRows());
  94.            
  95.                 }
  96.  
  97.                 $maxrows = $rets->IsMaxrowsReached();
  98.                 echo "    + Total found: {$rets->TotalRecordsFound()}<br>\n";
  99.  
  100.                 $rets->FreeResult($search);
  101.         }
  102.  
  103.         fclose($fh);
  104.         echo "  - done<br>\n";
  105.  
  106. }
  107.  
  108.          
  109. echo "+ Disconnecting<br>\n";
  110. $rets->Disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement