<?php


// ============== Send a record to the database ==============
require 'connection.php';
$conn        = Connect();
$name        = $conn->real_escape_string($_POST['full_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['ver']);
$reason      = $conn->real_escape_string($_POST['reason']);
$comments    = $conn->real_escape_string($_POST['comments']);
$status      = $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.
$query       = "INSERT into tb_cform (full_name,company,clientid,email,telephone,application,version,reason,comments,fbtype,status) VALUES('" . $name . "','" . $company . "','" . $clientid . "','" . $email . "','" . $telephone . "','" . $application . "','" . $version . "','" . $reason . "','" . $comments . "','" . $fbtype . "','" . $status . "')";

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

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


$success = $conn->query($query);

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

}

$conn->close();



//echo "<div style='font-family:Calibri; margin:0 auto; margin-top:50px; width: 500px'>
//		<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>";

// echo <div style="font-family:'Segoe UI', 'Segoe UI Light', Helvetica, Garuda, Arial, sans-serif; margin:0 auto; margin-top:50px; width: 500px"> ;
 //echo    <h2 style="color:rgb(110, 187, 31); font-family:'Segoe UI Light'">Thank you for contacting us.</h2>;
 //echo    <p>We value our customers and your opinion.</p>;

 //echo    <p>Please close this window to return to your session.</p>;

 //echo    <button type="button" onclick="window.open('', '_self', ''); window.close();">Close</button>;

 //echo</div>;



// ============== 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



$to = "WKFS-InfoDevSupport@wolterskluwer.com";
$subject = "InfoDev Feedback";
$email = $_POST['email'];

$file = "attachment/" . basename($_FILES['attachment']['name']);
if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
    if (sendemail('WKFS-InfoDevSupport@wolterskluwer.com', $email, $name, $comments, $file)) {
        // $msg = 'Your feedback has been sent. Thank you!';
        sendemail('kelly.mankenberg@wolterskluwer.com', 'WKFS-InfoDevSupport@wolterskluwer.com', 'InfoDev Feedback', $comments, $file);
    }
} else
    // $msg = 'Please check your attachment and try again.';

// 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 7.5pt 15pt;" valign="top">
                      <h2><span style="font-family: &quot;Fira Sans&quot;,sans-serif; color: rgb(0, 122, 195);">Application Feedback</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 feedback was received from the application detailed below.
                        </span></p>
                     </td>
                  </tr>
                  <tr>
                    <td colspan="2" style="padding: 15pt 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>Client ID: </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['clientid']) . '</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>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-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . strip_tags($_POST['application']) . '</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 version: </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['ver']) . '</span></td>'
                                    . '</tr>'
                                    . '<tr>'
                                        . '<td><span style="font-size: 10.5pt; font-family: &quot;Calibri&quot;,sans-serif; color: rgb(40, 40, 40);">'
                                            . '<b>Reason: </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['reason']) . '</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>";
} else{
    echo 'Unable to send email. Please try again.';
}


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

?>
