contract_footer.phpsrc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php die(); /* no direct access */
  2. $DEV_SIGNATURE = '<img id="dev_signature" src="' . $DEV_SIGNATURE . '" >';
  3. $CLIENT_SIGNATURE = isset($_POST['client_signature']) ? $_POST['client_signature'] : null;
  4. if ($CLIENT_SIGNATURE && substr($CLIENT_SIGNATURE, 0, 22) === 'data:image/png;base64,') {
  5. $CLIENT_SIGNATURE = '<img id="hk" src="' . htmlspecialchars($CLIENT_SIGNATURE) . '" >';
  6. }
  7. /**
  8. The HTML code (and some PHP) is kept in PHP variables like $CONTRACT_HTML, $FOOTER, $CONTRACT_SIGNED_PHP, and $CLIENT_DATE_IP_COMPILED.
  9. **/
  10. function headerWithTitle($title) {
  11. return '<!DOCTYPE html>
  12. <html>
  13. <head>
  14. <meta charset="UTF-8">
  15. <title>' . $title . '</title>
  16. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
  17. <meta name="robots" content="noindex">
  18. <link rel="preconnect" href="https://cdn.skypack.dev">
  19. <link rel="preconnect" href="https://fonts.gstatic.com">
  20. <link rel="preconnect" href="https://fonts.googleapis.com">
  21. <style></style>
  22. </head>
  23. <body>
  24. <div id="content" class="ql-editor">
  25. ';
  26. }
  27. if($CLIENT_SIGNATURE==null) {
  28. /**
  29. ⌛ Waiting for Client to sign: include signature elements and javascript
  30. **/
  31. $HEADER = headerWithTitle('Unsigned Contract');
  32. $FOOTER = '
  33. <div id="ui-unsigned"></div>
  34. </div> <!-- #content -->
  35. <script id="contract_script_unsigned" type="module"></script>
  36. <script id="qr_code_script" type="module"></script>
  37. </body>
  38. </html>';
  39. if ( $selfDelete && file_exists($htmlName) ) {
  40. header('Location: '.$htmlName.'#hk');
  41. die();
  42. }
  43. echo $HEADER;
  44. echo $CONTRACT_HTML;
  45. echo $DEV_SIGNATURE;
  46. eval (' ?>'. $FOOTER .'<?php '); // php variables can be used inside
  47. }
  48. else {
  49. /**
  50. ✅ Contract was just signed: put $CLIENT_SIGNATURE and the other parts in the .html file
  51. **/
  52. $HEADER = headerWithTitle('Signed Contract');
  53. $DEV_DATE_IP = '
  54. <div class="date-ip">
  55. <strong>Signed on:</strong> ' . $devTimestamp . '
  56. <br><strong>IP address:</strong> ' . $devIP . ' <br>
  57. </div>';
  58. $DEV_SIGNATURE .= $DEV_DATE_IP;
  59. /**
  60. $CLIENT_DATE_IP_PHP is a string of php code,
  61. that gets compiled below, in $CLIENT_DATE_IP_COMPILED
  62. **/
  63. $CLIENT_DATE_IP_PHP = $CONTRACT_SIGNED_PHP. '
  64. <div id="date-ip" class="date-ip">
  65. <strong>Signed on:</strong> <?php echo get_client_date($devTimeOffset); ?>
  66. <br><strong>IP address:</strong> <?php echo get_client_ip_env(); ?><br>
  67. </div>
  68. ';
  69. /**
  70. $CLIENT_DATE_IP_COMPILED executes the php code above
  71. **/
  72. ob_start(); // https://cgd.io/2008/how-to-execute-php-code-in-a-php-string/
  73. eval($CLIENT_DATE_IP_PHP);
  74. $CLIENT_DATE_IP_COMPILED = ob_get_contents();
  75. ob_end_clean();
  76. $CLIENT_SIGNATURE .= $CLIENT_DATE_IP_COMPILED;
  77. // Add names above signatures
  78. $DEV_SIGNATURE = '<strong>'.$devName.'</strong>' . $DEV_SIGNATURE;
  79. $CLIENT_SIGNATURE = '<strong>'.$clientName.'</strong>' . $CLIENT_SIGNATURE;
  80. $FOOTER = '
  81. <div class="compiled-signatures">
  82. <div class="compiled-signature">'.$DEV_SIGNATURE. '</div><!--.compiled-signature-->
  83. <div class="compiled-signature">'.$CLIENT_SIGNATURE.'</div><!--.compiled-signature-->
  84. </div><!--.compiled-signatures-->
  85. <div id="ui-signed"></div>
  86. </div> <!--#content-->
  87. <script id="contract_script_signed"></script>
  88. </body>
  89. </html>';
  90. $output = $HEADER . $CONTRACT_HTML . $FOOTER;
  91. file_put_contents($htmlName, $output);
  92. /**
  93. ✉ Email client & dev
  94. **/
  95. sendEmails($clientEmail, $devEmail);
  96. /**
  97. ➡ Delete php, redirect to html
  98. **/
  99. if ($selfDelete) unlink(__FILE__);
  100. header('Location: '.$htmlName.'#hk');
  101. die();
  102. }
  103. // Function to email notifications; gets called when Client signs
  104. function sendEmails($clientEmail, $devEmail)
  105. {
  106. if ($clientEmail) {
  107. $headers = "From: " . $devEmail . "\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO-8859-1\r\n";
  108. $msg = 'The contract was signed. You can <a href="' . getHtmlUrl() . '">view or download this contract from here</a>.';
  109. mail($clientEmail, 'Contract signed', $msg, $headers);
  110. }
  111. if ($devEmail) {
  112. $headers = "From: " . $clientEmail . "\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO-8859-1\r\n";
  113. $msg = '<p>A new contract was signed. You can <a href="' . getHtmlUrl() . '">view or download this contract from here</a>.</p>';
  114. $msg .= 'The contract was signed by: ' . $clientEmail;
  115. mail($devEmail, 'Contract signed!', $msg, $headers);
  116. }
  117. }
  118. ?>