<?php


// ============== Send a record to the database ==============
require 'conn_feedback.php';
$conn             = Connect();
mysqli_query($conn, "SET SESSION sql_mode = ''");
$name        = $conn->real_escape_string($_POST['name']);
$fbType      = $conn->real_escape_string($_POST['fbtype']);
$company     = $conn->real_escape_string($_POST['company']);
$clientid    = $conn->real_escape_string($_POST['clientid']);
$email       = $conn->real_escape_string($_POST['email']);
$telephone   = $conn->real_escape_string($_POST['telephone']);
$application = $conn->real_escape_string($_POST['application']);
$version     = $conn->real_escape_string($_POST['version']);
$reason      = $conn->real_escape_string($_POST['reason']);
$comments    = $conn->real_escape_string($_POST['body']);
$status      = $conn->real_escape_string($_POST['status']);
//$sentTo      = $conn->real_escape_string($_POST['status']);
$fileName    = $_['userfile']['name'];              //The original name of the file on the client machine.
$tmpName     = $_FILES['userfile']['tmp_name'];     //The mime type of the file, if the browser provided this information. An example would be "image/gif".
$fileSize    = $_FILES['userfile']['size'];         //The size, in bytes, of the uploaded file.
$fileType    = $_FILES['userfile']['type'];         //The temporary filename of the file in which the uploaded file was stored on the server.
//$_FILES['userfile']['error']                        //The error code associated with this file upload. ['error'] was added in PHP 4.2.0

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

$status      = $conn->real_escape_string($_POST['status']);
$query       = "INSERT into tb_feedback (fbtype,full_name,company,clientid,email,telephone,application,version,reason,comments,attachment,filesize,filetype,content,status,sentto)
                VALUES('" . $fbType . "','" . $name . "','" . $company . "','" . $clientid . "','" . $email . "','" . $telephone . "','" . $application . "','" . $version . "',
                '" . $reason . "','" . $comments . "','" . $fileName . "','" . $fileSize . "','" . $fileType . "','" . $content . "','" . $status . "','" . $sentTo . "')";
$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="/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="/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='/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='/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 ==============

?>
