index.php 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // check for right of current admin on this module
  3. if (cfr('STREETS')) {
  4. $altCfg = $ubillingConfig->getAlter();
  5. if (isset($_POST['newstreetname'])) {
  6. $newstreetname = trim($_POST['newstreetname']);
  7. $newstreetname = zb_AddressFilterStreet($newstreetname);
  8. $newstreetcityid = $_POST['citysel'];
  9. if (isset($_POST['newstreetalias'])) {
  10. $newstreetalias = trim($_POST['newstreetalias']);
  11. } else {
  12. $newstreetalias = '';
  13. }
  14. if (!empty($newstreetname)) {
  15. $FoundStreetID = checkStreetInCityExists($newstreetname, $newstreetcityid);
  16. if ( empty($FoundStreetID) ) {
  17. //alias autogeneration
  18. if (empty($newstreetalias)) {
  19. if (isset($altCfg['STREETS_ALIAS_AUTOGEN'])) {
  20. if ($altCfg['STREETS_ALIAS_AUTOGEN']) {
  21. $aliasProposal = zb_TranslitString($newstreetname);
  22. $aliasProposal = str_replace(' ', '', $aliasProposal);
  23. $aliasProposal = str_replace('-', '', $aliasProposal);
  24. if (strlen($aliasProposal) > 5) {
  25. $newstreetalias = substr($aliasProposal, 0, 5);
  26. } else {
  27. $newstreetalias = $aliasProposal;
  28. }
  29. }
  30. }
  31. }
  32. zb_AddressCreateStreet($newstreetcityid, $newstreetname, $newstreetalias);
  33. die();
  34. } else {
  35. $messages = new UbillingMessageHelper();
  36. $errormes = $messages->getStyledMessage(__('Street with such name already exists in this city with ID: ') . $FoundStreetID, 'error', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  37. die(wf_modalAutoForm(__('Error'), $errormes, $_POST['errfrmid'], '', true));
  38. }
  39. }
  40. }
  41. if (isset($_GET['action'])) {
  42. if (isset($_GET['streetid'])) {
  43. $streetid = $_GET['streetid'];
  44. if ($_GET['action'] == 'delete') {
  45. if (!zb_AddressStreetProtected($streetid)) {
  46. zb_AddressDeleteStreet($streetid);
  47. die();
  48. } else {
  49. $messages = new UbillingMessageHelper();
  50. $errormes = $messages->getStyledMessage(__('You can not delete the street if it has existing buildings'), 'error', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  51. die(wf_modalAutoForm(__('Error'), $errormes, $_GET['errfrmid'], '', true));
  52. }
  53. }
  54. if ($_GET['action'] == 'edit') {
  55. if (isset($_POST['editstreetname'])) {
  56. if (!empty($_POST['editstreetname'])) {
  57. $FoundStreetID = checkStreetInCityExists($_POST['editstreetname'], $_GET['cityid'], $streetid);
  58. if ( empty($FoundStreetID) ) {
  59. zb_AddressChangeStreetName($streetid, $_POST['editstreetname']);
  60. } else {
  61. $messages = new UbillingMessageHelper();
  62. $errormes = $messages->getStyledMessage(__('Street with such name already exists in this city with ID: ') . $FoundStreetID, 'error', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  63. die(wf_modalAutoForm(__('Error'), $errormes, $_POST['errfrmid'], '', true));
  64. }
  65. }
  66. zb_AddressChangeStreetAlias($streetid, $_POST['editstreetalias']);
  67. die();
  68. }
  69. die(wf_modalAutoForm(__('Edit Street'), web_StreetEditForm($streetid, $_GET['ModalWID']), $_GET['ModalWID'], $_GET['ModalWBID'], true));
  70. }
  71. }
  72. }
  73. $FilterByCityID = ( wf_CheckGet(array('filterbycityid')) ) ? $_GET['filterbycityid'] : '';
  74. if ( wf_CheckGet(array('ajax')) ) {
  75. renderStreetJSON($FilterByCityID);
  76. }
  77. show_window(__('Available streets'), web_StreetLister($FilterByCityID));
  78. } else {
  79. show_error(__('You cant control this module'));
  80. }
  81. ?>