5_analyse.php 3.1 KB

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