5_analyse.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env php
  2. <?php
  3. $_SERVER['SERVER_NAME'] = "biuro.biall-net.pl";
  4. require("/Library/Server/Web/Data/Sites/Default/dev-bzyk/se-lib/bootstrap.php");
  5. #require("/Library/Server/Web/Data/Sites/SE-producition-git/SE/se-lib/bootstrap.php");
  6. date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions
  7. Lib::loadClass('V');
  8. if (!isset($argv[1])) die("Missing parameter\n");
  9. if ($argv[1] == "-") $data = stream_get_contents(STDIN);
  10. else {
  11. if (!is_file($argv[1])) die("File {$argv[1]} not found\n");
  12. $data = @file_get_contents($argv[1]);
  13. if (!$data) die("Error loading file\n");
  14. }
  15. //preg_match('/.*\.([[:alpha:]]*)$/', $argv[1], $match);
  16. //switch ($match[1]) {
  17. // case "data":
  18. $results = @json_decode(gzuncompress(base64_decode($data)), true);
  19. // break;
  20. // case "txt":
  21. // $results = unserialize($data);
  22. // break;
  23. // default:
  24. // die("Unknown file type\n");
  25. //}
  26. if (!$results) die("Error loading data\n");
  27. //echo "Liczba wyników: " . count($results) . "\n";
  28. foreach ($results as $result) echo implode("->", array_keys($result)) . "\n";
  29. //print_r($results);
  30. die();
  31. $TABLE = "BI_audit_ALL";
  32. //$query = "select `DATA` from BI_audit_ALL_results where ID=4";
  33. //$data = DB::getPDO()->fetchvalue($query);
  34. //$results = json_decode(gzuncompress(base64_decode($data)), true);
  35. $xmlRoot = "RelatedFeatureRoot";
  36. $xmlRoot2 = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA";
  37. $xmlElements = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row";
  38. $items_results = [];
  39. foreach ($results as $result) {
  40. $item_results = [];
  41. foreach ($result as $ID => $rel) {
  42. $query = "select REMOTE_TABLE, REMOTE_ID from {$TABLE} where ID = '{$ID}'";
  43. $row = DB::getPDO()->fetchFirst($query);
  44. $query = "select * from `{$row['REMOTE_TABLE']}` where ID = '{$row['REMOTE_ID']}'";
  45. $obj = DB::fetch(DB::query($query));
  46. $item_result = [$row['REMOTE_TABLE'] => (array) $obj];
  47. if ($rel) $item_result['relation_from'] = $rel;
  48. $item_results['object'][] = $item_result;
  49. if ($row['REMOTE_TABLE'] == "BI_audit_ENERGA_RUM_KONTRAHENCI") {
  50. $query = "select umowy.* from BI_audit_ENERGA_RUM_UMOWY umowy join `CRM__#REF_TABLE__23` ref on umowy.ID = ref.PRIMARY_KEY where ref.REMOTE_PRIMARY_KEY = '{$row['REMOTE_ID']}'";
  51. $res = DB::query($query);
  52. $umowy = [];
  53. $i = 0;
  54. while ($obj = DB::fetch($res)) {
  55. if (++$i > 50) {
  56. //$umowy[] = "Przekroczono limit 50 rekordów (pominięto " . (mysql_num_rows($res) - 50) . " z " . mysql_num_rows($res) . ")";
  57. break;
  58. }
  59. $umowy[] = (array) $obj;
  60. }
  61. if ($umowy) {
  62. $item_results['deal'] = $umowy;
  63. }
  64. } elseif ($row['REMOTE_TABLE'] == "BI_audit_KW_requested_person") {
  65. $query = "select kw.* from BI_audit_KW_requested kw join `CRM__#REF_TABLE__24` ref on kw.ID = ref.PRIMARY_KEY where ref.REMOTE_PRIMARY_KEY = '{$row['REMOTE_ID']}'";
  66. $res = DB::query($query);
  67. $kw = [];
  68. while ($obj = DB::fetch($res)) {
  69. $kw[] = (array) $obj;
  70. }
  71. if ($kw) {
  72. $item_results['kw'] = $kw;
  73. }
  74. }
  75. }
  76. $items_results[$xmlRoot2][$xmlElements][] = $item_results;
  77. }
  78. //print_r($items_results);
  79. $test = V::arrayToXML($items_results, true, $xmlRoot);
  80. echo $test;