superedit-S_ADDRESS_CHECK.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
  3. if (!defined('APP_PATH_ROOT')) define('APP_PATH_ROOT', dirname(__FILE__));
  4. if (!defined('APP_PATH_WWW')) define('APP_PATH_WWW', dirname(__FILE__));
  5. if (!defined('APP_PATH_CONFIG')) define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');
  6. function S_ADDRESS_CHECK() {
  7. require_once dirname(__FILE__) . '/' . 'se-lib' . '/' . 'Lib.php';
  8. Lib::loadClass('V');
  9. Lib::loadClass('User');
  10. Lib::loadClass('Config');
  11. Lib::loadClass('DB');
  12. SEF('MENU');
  13. MENU();
  14. echo '<h1>' . __FUNCTION__ . '</h1>';
  15. $addr_check = new AddressCheck();
  16. $addr_check->set_filters($_GET);
  17. $buildings_rows = $addr_check->get_buildings();
  18. $mieszkania_rows = $addr_check->get_mieszkania();
  19. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;display:none;">buildings_rows (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($buildings_rows);echo'</pre>';
  20. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;display:none;">mieszkania_rows (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mieszkania_rows);echo'</pre>';
  21. ?>
  22. <style type="text/css">
  23. .tbl-view td {vertical-align:top;}
  24. .tbl-view td {font-size:small;}
  25. #tbl_S_ADDRESS_CHECK {}
  26. #tbl_S_ADDRESS_CHECK .tbl-actions {text-align:left;}
  27. #tbl_S_ADDRESS_CHECK .klatki-0 {background:#FFCFCF;}
  28. #tbl_S_ADDRESS_CHECK .mieszk-0 {background:#FFCFCF;}
  29. #tbl_S_ADDRESS_CHECK .err-mieszk-count .mieszk-cnt {background:#FFCFCF;}
  30. .tbl-actions .all {display:none;}
  31. .tbl-actions .with_offers_only {display:inline;}
  32. .with_offers_only .tbl-actions .all {display:inline;}
  33. .with_offers_only .tbl-actions .with_offers_only {display:none;}
  34. .with_offers_only .building- {display:none;}
  35. .with_offers_only .building-WAITING {display:none;}
  36. .with_offers_only .building-NORMAL {}
  37. .with_offers_only .building-MONITOR {display:none;}
  38. .with_offers_only .building-WARNING {}
  39. .with_offers_only .building-OFF {display:none;}
  40. .with_offers_only .building-TO_OFF {display:none;}
  41. .with_offers_only .building-DELETED {display:none;}
  42. </style>
  43. <script type="text/javascript">
  44. jQuery(document).ready(function(){
  45. jQuery('#tbl_S_ADDRESS_CHECK').find('.tbl-actions button').click(function(e){
  46. console.log(e);
  47. var n=jQuery(e.target);
  48. if (n.hasClass('with_offers_only')) {
  49. jQuery('#tbl_S_ADDRESS_CHECK').removeClass('all');
  50. jQuery('#tbl_S_ADDRESS_CHECK').addClass('with_offers_only');
  51. } else {
  52. jQuery('#tbl_S_ADDRESS_CHECK').removeClass('with_offers_only');
  53. jQuery('#tbl_S_ADDRESS_CHECK').addClass('all');
  54. }
  55. })
  56. });
  57. </script>
  58. <table cellspacing="0" cellpadding="0" border="1" class="tbl-view" id="tbl_S_ADDRESS_CHECK">
  59. <caption class="tbl-actions">
  60. <button class="all">Wszystkie budynki</button>
  61. <button class="with_offers_only">Tylko budynki z ofertami</button>
  62. </caption>
  63. <thead>
  64. <tr>
  65. <th colspan="5">BUILDING</th>
  66. <th>USERS2_MARKETING</th>
  67. </tr>
  68. <tr>
  69. <th>A_STATUS</th>
  70. <th>P_ADDRESS_STREET</th>
  71. <th>S_ADDRESS_STREET</th>
  72. <th>KLATKI</th>
  73. <th>MIESZKANIA</th>
  74. <th>Ilość mieszkań</th>
  75. </tr>
  76. </thead>
  77. <tbody>
  78. <?php foreach ($buildings_rows as $b_id => $building) {
  79. $miekszania = array();
  80. if (array_key_exists($building->S_ADDRESS_STREET, $mieszkania_rows)) {
  81. $miekszania = $mieszkania_rows[$building->S_ADDRESS_STREET];
  82. unset($mieszkania_rows[$building->S_ADDRESS_STREET]);
  83. }
  84. ?>
  85. <tr class="<?php echo "building-{$building->A_STATUS}"; ?>">
  86. <td><?php echo $building->A_STATUS; ?></td>
  87. <td><?php echo $building->P_ADDRESS_STREET; ?></td>
  88. <td><?php echo $building->S_ADDRESS_STREET; ?>
  89. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=16#EDIT/<?php echo $b_id; ?>">Edytuj <?php echo $b_id; ?></a>
  90. </td>
  91. <td<?php echo ($building->T_BUILDING_KLATKI == 0)? ' class="klatki-0"' : ''; ?>><?php echo $building->T_BUILDING_KLATKI; ?></td>
  92. <td<?php echo ($building->T_BUILDING_MIESZKANIA == 0)? ' class="mieszk-0"' : ''; ?>><?php echo $building->T_BUILDING_MIESZKANIA; ?></td>
  93. <td<?php echo ($building->T_BUILDING_MIESZKANIA > 0 && $building->T_BUILDING_MIESZKANIA != count($miekszania))? ' class="err-mieszk-count"' : ''; ?>>
  94. <?php
  95. if (empty($miekszania)) {
  96. echo '<b style="color:red" title="' . "Brak mieszkań na danym budynku!" . '" class="mieszk-cnt">' . "(0)" . '</b>';
  97. } else {
  98. echo '<b class="mieszk-cnt">' . "(" . count($miekszania) . ")" . '</b>';
  99. $m_street_err = array();
  100. foreach ($miekszania as $m_id => $m_street) {
  101. if (substr($m_street, 0, strlen($building->S_ADDRESS_STREET)) !== $building->S_ADDRESS_STREET) {
  102. $m_street_err []= $m_id;
  103. }
  104. }
  105. if (!empty($m_street_err)) {
  106. echo '<b style="color:red">' . " " . count($m_street_err) . " błędnych adresów" . '</b>';
  107. }
  108. $js = "if(this.nextSibling.style.display=='block'){this.nextSibling.style.display='none'}else{this.nextSibling.style.display='block'};return false;";
  109. echo '<button onclick="' . $js . '" style="margin:0 3px;padding:0;">' . "więcej" . '</button>';
  110. echo '<div style="display:none">';
  111. foreach ($miekszania as $m_id => $m_street) {
  112. if (in_array($m_id, $m_street_err)) {
  113. echo '<b style="color:red">' . "{$m_street}" . '</b>';
  114. } else {
  115. echo "{$m_street}";
  116. }
  117. echo " " . '<a href="' . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=23#EDIT/{$m_id}" . '">' . "Edytuj $m_id" . '</a>';
  118. echo '<br />';
  119. }
  120. echo '</div>';
  121. }
  122. echo '</td>';
  123. echo '</tr>';
  124. }
  125. if (!empty($mieszkania_rows)) {
  126. $bad_mieszkania_rows_cnt = count($mieszkania_rows);
  127. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;display:none;"> (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mieszkania_rows);echo'</pre>';
  128. foreach ($mieszkania_rows as $b_street => $v_mieszkania) {
  129. echo '<tr>';
  130. echo '<td colspan="3" style="background:#FF9A9A;">' . '<b>' . ((empty($b_street))? "Brak danych" : $b_street) . '</b>' . '</td>';
  131. echo '<td colspan="3">';
  132. if (empty($v_mieszkania)) {
  133. echo '<b style="color:red" title="' . "Brak mieszkań na danym budynku!" . '">' . "(0)" . '</b>';
  134. } else {
  135. echo '<b>' . "(" . count($v_mieszkania) . ")" . '</b>';
  136. echo '<b style="color:red">' . " " . count($v_mieszkania) . " błędnych adresów" . '</b>';
  137. $js = "if(this.nextSibling.style.display=='block'){this.nextSibling.style.display='none'}else{this.nextSibling.style.display='block'};return false;";
  138. echo '<button onclick="' . $js . '" style="margin:0 3px;padding:0;">' . "więcej" . '</button>';
  139. echo '<div style="display:none">';
  140. foreach ($v_mieszkania as $m_id => $m_street) {
  141. echo '<b style="color:red">' . "{$m_street}" . '</b>';
  142. echo " " . '<a href="' . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=23#EDIT/{$m_id}" . '">' . "Edytuj $m_id" . '</a>';
  143. echo '<br />';
  144. }
  145. echo '</div>';
  146. }
  147. echo '</td>';
  148. echo '</tr>';
  149. }
  150. }
  151. echo '</tbody>';
  152. echo '</table>';
  153. echo '<p>' . "Podsumowanie:" . '<br />';
  154. if ($bad_mieszkania_rows_cnt > 0) {
  155. echo "$bad_mieszkania_rows_cnt błędnie przypisanych mieszkań";
  156. }
  157. echo '</p>';
  158. die('</body></html>');
  159. }
  160. class AddressCheck {
  161. var $_filters = array();
  162. function set_filters($filters) {
  163. $this->_filters = $filters;
  164. }
  165. function sort_mieszkania_callback($street_a, $street_b) {
  166. $a = array();
  167. $street_arr = explode('/', $street_a, 2);
  168. $nr_domu_a = intval( preg_replace('/[^0-9]/', '', end($street_arr)) );
  169. $b = array();
  170. $street_arr = explode('/', $street_b, 2);
  171. $nr_domu_b = intval( preg_replace('/[^0-9]/', '', end($street_arr)) );
  172. if ($nr_domu_a < $nr_domu_b) {
  173. return -1;
  174. } else if ($nr_domu_a > $nr_domu_b) {
  175. return 1;
  176. } else {
  177. return 0;
  178. }
  179. }
  180. function sort_buildings_callback($row_a, $row_b) {
  181. $a = array();
  182. $a['nr_domu'] = intval( preg_replace('/[^0-9]/', '', $row_a->S_ADDRESS_STREET) );
  183. $a['street_short'] = preg_replace('/[0-9]/', '', $row_a->S_ADDRESS_STREET);
  184. $b = array();
  185. $b['nr_domu'] = intval( preg_replace('/[^0-9]/', '', $row_b->S_ADDRESS_STREET) );
  186. $b['street_short'] = preg_replace('/[0-9]/', '', $row_b->S_ADDRESS_STREET);
  187. if ($a['street_short'] < $b['street_short']) {
  188. return -1;
  189. } else if ($a['street_short'] > $b['street_short']) {
  190. return 1;
  191. } else if ($a['nr_domu'] < $b['nr_domu']) {
  192. return -1;
  193. } else if ($a['nr_domu'] > $b['nr_domu']) {
  194. return 1;
  195. } else {
  196. return 0;
  197. }
  198. }
  199. function get_buildings() {
  200. $buildings = array();
  201. $db = DB::getDB();
  202. $sql_where = "b.`A_STATUS` not in ('DELETED')";
  203. $sql = "select
  204. b.`ID`
  205. , b.`A_STATUS`
  206. , b.`S_ADDRESS_STREET`
  207. , b.`P_ADDRESS_STREET`
  208. , b.`T_BUILDING_KLATKI`
  209. , b.`T_BUILDING_MIESZKANIA`
  210. from `BUILDINGS` as b
  211. where {$sql_where}
  212. order by b.`S_ADDRESS_STREET` ASC
  213. ";
  214. $res = $db->query($sql);
  215. while ($r = $db->fetch($res)) {
  216. $r->S_ADDRESS_STREET = $r->S_ADDRESS_STREET;
  217. $buildings [$r->ID]= $r;
  218. }
  219. uasort($buildings, array($this, 'sort_buildings_callback'));
  220. return $buildings;
  221. }
  222. function get_mieszkania() {
  223. $mieszkania = array();
  224. $db = DB::getDB();
  225. $sql = "select
  226. m.`ID`
  227. , m.`S_ADDRESS_STREET`
  228. , m.`T_TELBOX_BUILDING_IN`
  229. from `USERS2_MARKETING` as m
  230. where
  231. m.`A_STATUS` not in ('DELETED')
  232. ";
  233. $res = $db->query($sql);
  234. while ($r = $db->fetch($res)) {
  235. $r->T_TELBOX_BUILDING_IN = $r->T_TELBOX_BUILDING_IN;
  236. $r->S_ADDRESS_STREET = $r->S_ADDRESS_STREET;
  237. $mieszkania [$r->T_TELBOX_BUILDING_IN] [$r->ID] = $r->S_ADDRESS_STREET;
  238. }
  239. foreach ($mieszkania as $b_street => $v_arr) {
  240. uasort($mieszkania[$b_street], array($this, 'sort_mieszkania_callback'));
  241. }
  242. return $mieszkania;
  243. }
  244. }