'; $CLIENT_SIGNATURE = isset($_POST['client_signature']) ? $_POST['client_signature'] : null; if ($CLIENT_SIGNATURE && substr($CLIENT_SIGNATURE, 0, 22) === 'data:image/png;base64,') { $CLIENT_SIGNATURE = ''; } /** The HTML code (and some PHP) is kept in PHP variables like $CONTRACT_HTML, $FOOTER, $CONTRACT_SIGNED_PHP, and $CLIENT_DATE_IP_COMPILED. **/ function headerWithTitle($title) { return ' ' . $title . '
'; } if($CLIENT_SIGNATURE==null) { /** ⌛ Waiting for Client to sign: include signature elements and javascript **/ $HEADER = headerWithTitle('Unsigned Contract'); $FOOTER = '
'; if ( $selfDelete && file_exists($htmlName) ) { header('Location: '.$htmlName.'#hk'); die(); } echo $HEADER; echo $CONTRACT_HTML; echo $DEV_SIGNATURE; eval (' ?>'. $FOOTER .' Signed on: ' . $devTimestamp . '
IP address: ' . $devIP . '
'; $DEV_SIGNATURE .= $DEV_DATE_IP; /** $CLIENT_DATE_IP_PHP is a string of php code, that gets compiled below, in $CLIENT_DATE_IP_COMPILED **/ $CLIENT_DATE_IP_PHP = $CONTRACT_SIGNED_PHP. '
Signed on:
IP address:
'; /** $CLIENT_DATE_IP_COMPILED executes the php code above **/ ob_start(); // https://cgd.io/2008/how-to-execute-php-code-in-a-php-string/ eval($CLIENT_DATE_IP_PHP); $CLIENT_DATE_IP_COMPILED = ob_get_contents(); ob_end_clean(); $CLIENT_SIGNATURE .= $CLIENT_DATE_IP_COMPILED; // Add names above signatures $DEV_SIGNATURE = ''.$devName.'' . $DEV_SIGNATURE; $CLIENT_SIGNATURE = ''.$clientName.'' . $CLIENT_SIGNATURE; $FOOTER = '
'.$DEV_SIGNATURE. '
'.$CLIENT_SIGNATURE.'
'; $output = $HEADER . $CONTRACT_HTML . $FOOTER; file_put_contents($htmlName, $output); /** ✉ Email client & dev **/ sendEmails($clientEmail, $devEmail); /** ➡ Delete php, redirect to html **/ if ($selfDelete) unlink(__FILE__); header('Location: '.$htmlName.'#hk'); die(); } // Function to email notifications; gets called when Client signs function sendEmails($clientEmail, $devEmail) { if ($clientEmail) { $headers = "From: " . $devEmail . "\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO-8859-1\r\n"; $msg = 'The contract was signed. You can view or download this contract from here.'; mail($clientEmail, 'Contract signed', $msg, $headers); } if ($devEmail) { $headers = "From: " . $clientEmail . "\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO-8859-1\r\n"; $msg = '

A new contract was signed. You can view or download this contract from here.

'; $msg .= 'The contract was signed by: ' . $clientEmail; mail($devEmail, 'Contract signed!', $msg, $headers); } } ?>