5_generate_xml.php.ok 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. $TABLE = "BI_audit_ALL";
  28. //$query = "select `DATA` from BI_audit_ALL_results where ID=4";
  29. //$data = DB::getPDO()->fetchvalue($query);
  30. //$results = json_decode(gzuncompress(base64_decode($data)), true);
  31. $xmlRoot = "RelatedFeatureRoot";
  32. $xmlRoot2 = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA";
  33. $xmlElements = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row";
  34. $items_results = [];
  35. foreach ($results as $result) {
  36. $item_results = [];
  37. foreach ($result as $ID => $rel) {
  38. $query = "select REMOTE_TABLE, REMOTE_ID from {$TABLE} where ID = '{$ID}'";
  39. $row = DB::getPDO()->fetchFirst($query);
  40. $query = "select * from `{$row['REMOTE_TABLE']}` where ID = '{$row['REMOTE_ID']}'";
  41. $obj = DB::fetch(DB::query($query));
  42. $item_result = [$row['REMOTE_TABLE'] => (array) $obj];
  43. if ($rel) $item_result['relation_from'] = $rel;
  44. $item_results['object'][] = $item_result;
  45. if ($row['REMOTE_TABLE'] == "BI_audit_ENERGA_RUM_KONTRAHENCI") {
  46. $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']}'";
  47. $res = DB::query($query);
  48. $umowy = [];
  49. $i = 0;
  50. while ($obj = DB::fetch($res)) {
  51. if (++$i > 50) {
  52. //$umowy[] = "Przekroczono limit 50 rekordów (pominięto " . (mysql_num_rows($res) - 50) . " z " . mysql_num_rows($res) . ")";
  53. break;
  54. }
  55. $umowy[] = (array) $obj;
  56. }
  57. if ($umowy) {
  58. $item_results['deal'] = $umowy;
  59. }
  60. } elseif ($row['REMOTE_TABLE'] == "BI_audit_KW_requested_person") {
  61. $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']}'";
  62. $res = DB::query($query);
  63. $kw = [];
  64. while ($obj = DB::fetch($res)) {
  65. $kw[] = (array) $obj;
  66. }
  67. if ($kw) {
  68. $item_results['kw'] = $kw;
  69. }
  70. }
  71. }
  72. $items_results[$xmlRoot2][$xmlElements][] = $item_results;
  73. }
  74. //print_r($items_results);
  75. $test = V::arrayToXML($items_results, true, $xmlRoot);
  76. echo $test;