index.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Configuration section
  4. */
  5. define('UBILLING_SERIAL', 'UBxxxxxxxxxxxxxxxxxx'); // your Ubilling instance serial number
  6. define('UBILLING_URL', 'http://localhost/billing/'); //your Ubilling URL
  7. define('BACK_URL_OK', 'http://ubilling.net.ua/'); // URL to redirect user after succefull saving call request
  8. define('BACK_URL_FAIL', 'http://ubilling.net.ua/?fail=true'); // URL to redirect user after some fail occurred
  9. define('BOT_PROTECTION', true); // enable spam-bot protection?
  10. define('BOT_CATCH', 'lastname'); // name of invisible POST field to catch for bots detection
  11. define('CATCHFIELD', 'callmebackmobile'); // name of POST variable for catching input phone number
  12. /**
  13. * End of config
  14. */
  15. if (!function_exists('rcms_redirect')) {
  16. /**
  17. * Shows redirection javascript.
  18. *
  19. * @param string $url
  20. * @param bool $header
  21. */
  22. function rcms_redirect($url, $header = false) {
  23. if ($header) {
  24. @header('Location: ' . $url);
  25. } else {
  26. echo '<script language="javascript">document.location.href="' . $url . '";</script>';
  27. }
  28. }
  29. }
  30. //primary controller part
  31. if (isset($_POST[CATCHFIELD])) {
  32. if (!empty($_POST[CATCHFIELD])) {
  33. $phoneNumber = $_POST[CATCHFIELD];
  34. $phoneNumber = preg_replace('/\0/s', '', $phoneNumber);
  35. $phoneNumber = preg_replace("#[^0-9]#Uis", '', $phoneNumber);
  36. if (!empty($phoneNumber)) {
  37. $everythingOk = true; // default allow flag
  38. if (BOT_PROTECTION) {
  39. if (isset($_POST[BOT_CATCH])) {
  40. if (!empty($_POST[BOT_CATCH])) {
  41. $everythingOk = false;
  42. }
  43. }
  44. }
  45. //performing
  46. if ($everythingOk) {
  47. $apiUrl = UBILLING_URL . '/?module=remoteapi&key=' . UBILLING_SERIAL . '&action=callmeback&param=' . $phoneNumber;
  48. @$apiResult = file_get_contents($apiUrl);
  49. rcms_redirect(BACK_URL_OK);
  50. } else {
  51. rcms_redirect(BACK_URL_FAIL);
  52. }
  53. } else {
  54. rcms_redirect(BACK_URL_FAIL);
  55. }
  56. } else {
  57. rcms_redirect(BACK_URL_FAIL);
  58. }
  59. }