<?php


// ============== Send a record to the database ==============
require 'connection.php';
$conn             = Connect();
$name             = $conn->real_escape_string($_POST['full_name']);
$company          = $conn->real_escape_string($_POST['company']);
$telephone        = $conn->real_escape_string($_POST['telephone']);
$email            = $conn->real_escape_string($_POST['email']);
$customernumber   = $conn->real_escape_string($_POST['customernumber']);
$product          = $conn->real_escape_string($_POST['product']);
$comments         = $conn->real_escape_string($_POST['comments']);
$status           = $conn->real_escape_string($_POST['status']);
$query            = "INSERT into tb_support (full_name,company,telephone,email,customernumber,product,comments,status)
                      VALUES('" . $name . "','" . $company . "','" . $telephone . "','" . $email . "','" . $customernumber . "',
                      '" . $product . "','" . $comments . "','" . $status . "')";
$success          = $conn->query($query);

if (!$success) {
    die("Couldn't enter data: ".$conn->error);
}

$conn->close();
// ============== End Send a record to the database ==============

// ============== Send Email ==============
// Comment out this entire section if you do not wish to send an email upon form submission

if ($product == 'Arta Lending') {
  $to = 'artalendingsup@wolterskluwer.com';
} elseif ($product == 'Cash Suite') {
  $to = 'CASHsupport@wolterskluwer.com';
} elseif ($product == 'ComplianceOne Deposit') {
  $to = 'complianceonesupport@wolterskluwer.com';
} elseif ($product == 'ComplianceOne Lending') {
  $to = 'ComplianceOneSupport@wolterskluwer.com';
} elseif ($product == 'ComplianceOne Interfaces') {
  $to = 'Complianceonesupport@wolterskluwer.com';
} elseif ($product == 'ComplianceOne manager') {
  $to = 'ComplianceOneManagerSupport@wolterskluwer.com';
} elseif ($product == 'ComplianceOne mortgage') {
  $to = 'ComplianceOneMortgageSupport@wolterskluwer.com';
} elseif ($product == 'Document Generation Services') {
  $to = 'ExpereIESupport@wolterskluwer.com';
} elseif ($product == 'Expere Document Services') {
  $to = 'ExpereIESupport@wolterskluwer.com';
} elseif ($product == 'Medici') {
  $to = 'medicisupport@wolterskluwer.com';
} elseif ($product == 'Requirements Editor') {
  $to = 'ExpereIESupport@wolterskluwer.com';
} elseif ($product == 'TSoftPlus') {
  $to = 'tsoftsup@wolterskluwer.com';
// } elseif ($product == 'Settlement Services') {
//   $to = 'WKFS-InfoDevSupport@wolterskluwer.com';
} else {
  $to = 'WKFS-InfoDevSupport@wolterskluwer.com';
}

$subject = "Customer Support Submission";
$email = $_POST['email'];

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Create email headers
$headers .= 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n". 'X-Mailer: PHP/' . phpversion();

// Compose a simple HTML email message
$message = '<html>';
$message .= '<head>';
$message .= '<script>
function downloadCSV(csv, filename) {
    var csvFile;
    var downloadLink;

    // CSV file
    csvFile = new Blob([csv], {type: "text/csv"});

    // Download link
    downloadLink = document.createElement("a");

    // File name
    downloadLink.download = filename;

    // Create a link to the file
    downloadLink.href = window.URL.createObjectURL(csvFile);

    // Hide download link
    downloadLink.style.display = "none";

    // Add the link to DOM
    document.body.appendChild(downloadLink);

    // Click download link
    downloadLink.click();
}

function exportTableToCSV(filename) {
    var csv = [];
	var rows = document.querySelectorAll("table tr");

    for (var i = 0; i < rows.length; i++) {
		var row = [], cols = rows[i].querySelectorAll("td, th");

        for (var j = 0; j < cols.length; j++)
            row.push(cols[j].innerText);

		csv.push(row.join(","));
	}

    // Download CSV file
    downloadCSV(csv.join("\n"), filename);
}
</script>';
$message .= '</head>';
$message .= '<body style="font-family:Calibri Regular">';
$message .= '<table border="0" cellspacing="0" cellpadding="0" width="100%" style="font-family:Calibri Regular">
  <tr>
    <td valign="top"><div align="center">
      <table border="0" cellspacing="0" cellpadding="0" width="600">
        <tr>
          <td>
            <table border="0" cellspacing="0" cellpadding="0" align="left">
              <tr>
                <td style="padding-left:50px"><p><img src="https://documentation.wolterskluwerfs.com/Help/resources/img/logos/Wolters-Kluwer-logo_wht.png" /></p>&nbsp;<p></p></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="padding: 0in; background: rgb(0, 122, 195) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
            <table style="border-collapse: collapse;" align="right" border="0" cellpadding="0" cellspacing="0">
                <tr bgcolor="#0007ac3">
                    <td  style="padding: 7.5pt; background: rgb(133, 188, 32) none repeat scroll 0% 50%; width: 70%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="70%"><p style="text-align: center;" align="center"><span style="font-family: &quot;Fira Sans&quot;,sans-serif; color: white;">Financial Services</p></td>
                </tr>
            </table>
          </td>
        </tr>
        <!--<tr>
          <td colspan="2" style="padding: 15pt 30pt;"><p><span style="font-size: 18pt; font-family: &quot;Fira Sans&quot;,sans-serif;">Information Development</span><span style="font-size: 12pt; font-family: &quot;Fira Sans&quot;,sans-serif;"><o:p></o:p></span></p></td>
        </tr>-->
        <tr>
          <td style="padding: 0in; background: rgb(230, 231, 233) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
            <p align="center"><img width="526" height="150" src="https://documentation.wolterskluwerfs.com/Help/resources/img/mockups/MacMock_WebHelp-1.png" alt="Wolters Kluwer" /></p></td>
          <td></td>
        </tr>
        <tr>
          <td style="padding: 0in 30pt 30pt; background: rgb(230, 231, 233) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" valign="top">
            <div align="center"><span style="font-size: 10.5pt; font-family: &quot;Fira Sans&quot;,sans-serif; color: rgb(40, 40, 40);">
            <table style="background: white none repeat scroll 0% 50%; width: 100%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; border-collapse: collapse;" align="left" border="0" cellpadding="0" cellspacing="0" width="100%">
              <tr>
                <td valign="top"><table border="0" cellspacing="0" cellpadding="0" align="left" width="100%">
                  <tr>
                    <td colspan="2" style="padding: 15pt 30pt 5pt 15pt;" valign="top">
                      <h2><span style="font-family: &quot;Fira Sans&quot;,sans-serif; color: rgb(0, 122, 195);">Customer Support Submission</span></h2>
                      <p style="line-height: 15pt;">
                        <span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">
                        The following request for support was received regarding the application detailed below.
                        </span></p>
                     </td>
                  </tr>
                  <tr>
                    <td colspan="2" style="padding: 0pt 30pt 7.5pt 15pt;" valign="top">';
                        $message .= '<table>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Date and Time: </b></span></td>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . date('m/d/Y, H:i:s') . '</span></td>'
                                    . '</tr>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Name: </b></span></td>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['full_name']) . '</span></td>'
                                    . '</tr>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Company: </b></span></td>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['company']) . '</span></td>'
                                    . '</tr>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Telephone: </b></span></td>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['telephone']) . '</span></td>'
                                    . '</tr>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Email: </b></span></td>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['email']) . '</span></td>'
                                    . '</tr>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Customer Number: </b></span></td>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['customernumber']) . '</span></td>'
                                    . '</tr>'


                                    // . '<tr>'
                                    //     . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                    //         . '<b>Contact me?: </b></span></td>'
                                    //     . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                    //         . strip_tags($_POST['contactme']) . '</span></td>'
                                    // . '</tr>'


                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Product: </b></span></td>'
                                        . '<td><span style="font-weight: normal; font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['product']) . '</span></td>'
                                    . '</tr>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Comments: </b></span></td>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['comments']) . '</span></td>'
                                    . '</tr>'
                                 . '</table>';
                        $message .= '
                    </td>
                  </tr>';
                    $message .= '</table></span>
                    </td>
                    <td></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td>
                    <div align="center">

                    </div>
                </td>
              </tr>
            </table>
          </div></td>
          <td></td>
        </tr>
      </table>
    </div></td>
  </tr>
</table>';



$message .= '</body></html>';



// Sending email
if(mail($to, $subject, $message, $headers)){
    echo "<div style='font-family:Calibri; margin:0 auto; margin-top:50px; width: 600px'>
            <img src='https://documentation.wolterskluwerfs.com/Help/resources/img/checkbox-720.png' style='width:200px; display:block; margin:auto' /><br />
            <div style='text-align:center'>
                <h2 style='color:rgb(0, 122, 195);font-size:32px'>Thank you for contacting us.</h2>
                <p style='font-size:22px'>We value our customers and your opinion.<br />
                You can now close this window.</p>
            </div>
            <div style='text-align:right'>
                <hr/>
                <img src='https://documentation.wolterskluwerfs.com/Help/resources/img/logos/Wolters-Kluwer-logo_wht.png' />
            </div>
          </div>";
    // echo "<h2>$product</h2>";
    // echo "<p>Emailing to: $to</p>";
} else{
    echo 'Unable to send email. Please try again.';
    echo $product;
}


// ============== End of Send Email ==============

?>
