contract_header.phpsrc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php /* ##########################
  2. [client_email]
  3. [dev_email]
  4. [dev_signature]
  5. [dev_ip]
  6. [dev_timestamp]
  7. [dev_timestamp_offset]
  8. [dev_name]
  9. [client_name]
  10. ###################################
  11. 1. The 2nd and 3rd lines above are the emails read by this PHP script from itself (used below as $lines[1] and $lines[2] respectively).
  12. 2. The 4th line ($lines[3] below) is the data for $DEV_SIGNATURE.
  13. 3. The $CLIENT_SIGNATURE is received by this script from itself when second person signs the contract.
  14. */
  15. $phpName = basename($_SERVER['PHP_SELF']) ? basename($_SERVER['PHP_SELF']) : 'index.php';
  16. $fileName = substr($phpName , 0, -4);
  17. $htmlName = $fileName.'.html';
  18. // If the filename is (or starts with) "test" or "demo" the PHP file won't delete itself, nor will it redirect to the HTML contract (when one exists)
  19. if ( substr($fileName,0,4) == 'test' || substr($fileName,0,4) == 'demo' ) {
  20. $selfDelete = 0;
  21. }
  22. else {
  23. $selfDelete = 1;
  24. }
  25. $lines = file(__FILE__);
  26. $clientEmail = format($lines[1]);
  27. $devEmail = format($lines[2]);
  28. $DEV_SIGNATURE = format($lines[3]);
  29. $devIP = format($lines[4]);
  30. $devTimestamp = format($lines[5]);
  31. $devTimeOffset = format($lines[6]);
  32. $devName = format($lines[7]);
  33. $clientName = format($lines[8]);
  34. // Trim and ignore [placeholders]
  35. function format($text) {
  36. $text = trim($text);
  37. $firstChar = substr($text, 0, 1);
  38. $lastChar = substr($text, -1, 1);
  39. if ($firstChar == '[' && $lastChar == ']')
  40. return '';
  41. else
  42. return $text;
  43. }
  44. // Gets the current file URL and replaces the .php extension with .html
  45. function getHtmlUrl() {
  46. $url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
  47. $url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
  48. $url .= $_SERVER["REQUEST_URI"];
  49. $url = substr($url,0,-4) . '.html';
  50. return $url;
  51. }
  52. /**
  53. The HTML code (and some PHP) is kept in PHP variables like $CONTRACT_HTML, $FOOTER, $CONTRACT_SIGNED_PHP, and $CLIENT_DATE_IP_COMPILED.
  54. **/
  55. // This gets executed when Client signs;
  56. // the functions are used in $CLIENT_DATE_IP_PHP
  57. $CONTRACT_SIGNED_PHP = '
  58. $phpName = basename($_SERVER["PHP_SELF"]) ? basename($_SERVER["PHP_SELF"]) : "index.php";
  59. $fileName = substr($phpName , 0, -4);
  60. $htmlName = $fileName.".html";
  61. $pdfName = $fileName.".pdf";
  62. // Function to get the client IP address
  63. function get_client_ip_env() {
  64. $ipaddress = "";
  65. if (getenv("HTTP_CLIENT_IP"))
  66. $ipaddress = getenv("HTTP_CLIENT_IP");
  67. else if(getenv("HTTP_X_FORWARDED_FOR"))
  68. $ipaddress = getenv("HTTP_X_FORWARDED_FOR");
  69. else if(getenv("HTTP_X_FORWARDED"))
  70. $ipaddress = getenv("HTTP_X_FORWARDED");
  71. else if(getenv("HTTP_FORWARDED_FOR"))
  72. $ipaddress = getenv("HTTP_FORWARDED_FOR");
  73. else if(getenv("HTTP_FORWARDED"))
  74. $ipaddress = getenv("HTTP_FORWARDED");
  75. else if(getenv("REMOTE_ADDR"))
  76. $ipaddress = getenv("REMOTE_ADDR");
  77. else
  78. $ipaddress = "UNKNOWN";
  79. return $ipaddress;
  80. }
  81. // Function to get the client date converted to the same GMT as the dev date
  82. function get_client_date($receivedOffset) {
  83. //$receivedOffset comes negative and in minutes, eg: -120 for GMT+2
  84. $offset = -1 * $receivedOffset / 60; // GMT offset
  85. $is_DST = FALSE; // observing daylight savings?
  86. $timezone_name = timezone_name_from_abbr("", $offset * 3600, $is_DST);
  87. date_default_timezone_set($timezone_name);
  88. return date("F j, Y") ." at ". date("g:i:s A") ." GMT" . sprintf("%+d", $offset);
  89. }
  90. ?>';