<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Easy Verification E-mails</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>Exel</author>
        <file name="admin/view/template/sale/order_form.tpl">
            <operation info="Add e-mail verification / confirm verifcation buttons">
                    <search position="after"><![CDATA[
                    <div style="margin-top: 10px; text-align: right;"><a onclick="history();" id="history_button" class="button"><span><?php echo $button_add_history; ?></span></a></div></td>
                    ]]></search>
                    <add><![CDATA[
                    </tr>
                    <tr>
                        <td>Verification Tools</td>
                        <td>
                            <div style="margin-top: 10px;">
                                <a onclick="sendVerification();" id="send_verification" class="button"><span>Send Verification E-mail</span></a>
                                <a onclick="confirmVerification();" id="confirm_verification" class="button"><span>Confirm Verification</span></a>
                            </div>
                        </td>
                    ]]></add>
            </operation>
            <operation info="Add sendVerification() // confirmVerification() JS functions">
                    <search position="before"><![CDATA[
                    function history() {
                    ]]></search>
                    <add><![CDATA[

                    function confirmVerification() {

                        var store_name = '<?php echo $this->config->get('config_name'); ?>';
                        var order_id = '<?php echo $order_id; ?>';
                        
                        var msg = "Thank you for verifying your order with us.\n";
                        msg += "You order is marked complete and we have already requested for the shipping department to move forward on shipping your order.\n\n";
                        msg += "The Shipping Department will notify you via email of your tracking numbers.\n";
                        msg += "Your tracking numbers will also be noted within your account, online.\n\n";
                        msg += "Many thanks again for your patience and understanding.\n\n";
                        msg += "Sincerely,\n\n";
                        msg += "MADNESS Autoworks\n";
                        msg += "Online Verification Team\n\n";
                        msg += "AUS/ Spicewood, TX Location\n";
                        msg += "22108 State HW 71 W\n";
                        msg += "Spicewood, TX 78669\n";
                        msg += "512-982-9393";

                        $.ajax({
                            type: 'POST',
                            url: 'index.php?route=sale/order/history&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
                            dataType: 'json',
                            data: 'order_status_id=5&notify=1&append=1&smtp=1&comment=' + msg,
                            beforeSend: function() {
                                $('.success, .warning').remove();
                                $('#history_button').attr('disabled', 'disabled');
                                $('#tab_history .form').before('<div class="attention"><img src="view/image/loading_1.gif" alt="" /> <?php echo $text_wait; ?></div>');
                            },
                            complete: function() {
                                $('#history_button').attr('disabled', '');
                                $('.attention').remove();
                            },
                            success: function(data) {
                                if (data.error) {
                                    $('#tab_history .form').before('<div class="warning">' + data.error + '</div>');
                                }

                                if (data.success && $('input[name=\'append\']').attr('checked')) {
                                    html  = '<div class="history" style="display: none;">';
                                    html += '  <table class="list">';
                                    html += '    <thead>';
                                    html += '      <tr>';
                                    html += '        <td class="left" width="33.3%"><b><?php echo $column_date_added; ?></b></td>';
                                    html += '        <td class="left" width="33.3%"><b><?php echo $column_status; ?></b></td>';
                                    html += '        <td class="left" width="33.3%"><b><?php echo $column_notify; ?></b></td>';
                                    html += '      </tr>';
                                    html += '    </thead>';
                                    html += '    <tbody>';
                                    html += '      <tr>';
                                    html += '        <td class="left">' + data.date_added + '</td>';
                                    html += '        <td class="left">' + data.order_status + '</td>';
                                    html += '        <td class="left">' + data.notify + '</td>';
                                    html += '      </tr>';
                                    html += '    </tbody>';

                                    if (data.comment) {
                                        html += '    <thead>';
                                        html += '      <tr>';
                                        html += '        <td class="left" colspan="3"><b><?php echo $column_comment; ?></b></td>';
                                        html += '      </tr>';
                                        html += '    </thead>';
                                        html += '    <tbody>';
                                        html += '      <tr>';
                                        html += '        <td class="left" colspan="3">' + data.comment + '</td>';
                                        html += '      </tr>';
                                        html += '    </tbody>';
                                    }

                                    html += '  </table>';
                                    html += '</div>';

                                    $('#order_status').html(data.status);

                                    $('#tab_history .form').before(html);

                                    $('#tab_history .history').slideDown();

                                    $('#tab_history .form').before('<div class="success">' + data.success + '</div>');

                                    $('textarea[name=\'comment\']').val('');
                                }
                            }
                        });
                    }

                    function sendVerification() {

                        var store_name = '<?php echo $this->config->get('config_name'); ?>';
                        var order_id = '<?php echo $order_id; ?>';
                        
                        var msg = "Greetings and salutations from " + store_name + "!\n\n";
                        msg += "Thank you very much for your recent order " + order_id + " with us. We are reaching out to you today because we need to confirm your identity (card holder) before we can process your order.\n\n";
                        msg += "Our identity theft prevention system cannot authenticate your credit card billing address or your order was flagged because the shipping is different from your billing address.\n\n";
                        msg += "To help us quickly identify you as the holder of the card, please respond to this email at Verify@MADNESSAutoworks.com to confirm your identity by:\n\n";
                        msg += "Provide a copy of your photo ID, PLEASE black out your driver license number.\n";
                        msg += "Provide a picture of the front and back of credit card you are using. ***\n";
                        msg += "*** COVER ALL card numbers on the front and back, leaving just the last four visible for authentication on our side. Feel free to just use your smartphone and just smudge/ black out the important information or simply cover with a pen or pencil. We only need the last 4 digits.\n\n";
                        msg += "Please respond with this information to the Verify@MADNESSAutoworks.com email address. If you prefer to call, please call our TX location at 512-982-9393, and we will be glad to help you over the phone with any questions you have.\n\n";
                        msg += "If you choose to call, you will still need to submit the documents above, via email to still verify your order.\n\n";
                        msg += "We know this is an inconvenience and we appreciate your assistance. As consumers ourselves we understand the importance of protecting personal information online and as a business we seek to protect our customers as well as provide them with the best possible service.\n\n";
                        msg += "Thank you again for your purchase and your assistance in verifying your order so we may get it out the door.\n\n";
                        msg += "Sincerely,\n\n";
                        msg += "MADNESS Autoworks\n";
                        msg += "Online Verification Team\n\n";
                        msg += "AUS/ Spicewood, TX Location\n";
                        msg += "22108 State HW 71 W\n";
                        msg += "Spicewood, TX 78669\n";
                        msg += "512-982-9393";

                        $.ajax({
                            type: 'POST',
                            url: 'index.php?route=sale/order/history&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
                            dataType: 'json',
                            data: 'order_status_id=1&notify=1&append=1&smtp=1&comment=' + msg,
                            beforeSend: function() {
                                $('.success, .warning').remove();
                                $('#history_button').attr('disabled', 'disabled');
                                $('#tab_history .form').before('<div class="attention"><img src="view/image/loading_1.gif" alt="" /> <?php echo $text_wait; ?></div>');
                            },
                            complete: function() {
                                $('#history_button').attr('disabled', '');
                                $('.attention').remove();
                            },
                            success: function(data) {
                                if (data.error) {
                                    $('#tab_history .form').before('<div class="warning">' + data.error + '</div>');
                                }

                                if (data.success && $('input[name=\'append\']').attr('checked')) {
                                    html  = '<div class="history" style="display: none;">';
                                    html += '  <table class="list">';
                                    html += '    <thead>';
                                    html += '      <tr>';
                                    html += '        <td class="left" width="33.3%"><b><?php echo $column_date_added; ?></b></td>';
                                    html += '        <td class="left" width="33.3%"><b><?php echo $column_status; ?></b></td>';
                                    html += '        <td class="left" width="33.3%"><b><?php echo $column_notify; ?></b></td>';
                                    html += '      </tr>';
                                    html += '    </thead>';
                                    html += '    <tbody>';
                                    html += '      <tr>';
                                    html += '        <td class="left">' + data.date_added + '</td>';
                                    html += '        <td class="left">' + data.order_status + '</td>';
                                    html += '        <td class="left">' + data.notify + '</td>';
                                    html += '      </tr>';
                                    html += '    </tbody>';

                                    if (data.comment) {
                                        html += '    <thead>';
                                        html += '      <tr>';
                                        html += '        <td class="left" colspan="3"><b><?php echo $column_comment; ?></b></td>';
                                        html += '      </tr>';
                                        html += '    </thead>';
                                        html += '    <tbody>';
                                        html += '      <tr>';
                                        html += '        <td class="left" colspan="3">' + data.comment + '</td>';
                                        html += '      </tr>';
                                        html += '    </tbody>';
                                    }

                                    html += '  </table>';
                                    html += '</div>';

                                    $('#order_status').html(data.status);

                                    $('#tab_history .form').before(html);

                                    $('#tab_history .history').slideDown();

                                    $('#tab_history .form').before('<div class="success">' + data.success + '</div>');

                                    $('textarea[name=\'comment\']').val('');
                                }
                            }
                        });
                    }
                    ]]></add>
            </operation>
        </file>
        <file name="admin/model/sale/order.php">
            <operation info="Add smtp e-mail send">
                    <search position="before"><![CDATA[
                    if ($data['notify']) {
                    ]]></search>
                    <add><![CDATA[
                    if ($data['smtp']) {

                        $order_query = $this->db->query("SELECT *, os.name AS status FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_status os ON (o.order_status_id = os.order_status_id AND os.language_id = o.language_id) LEFT JOIN " . DB_PREFIX . "language l ON (o.language_id = l.language_id) WHERE o.order_id = '" . (int)$order_id . "'");

                        if ($order_query->num_rows) {

                            $store_name = $this->config->get('config_name');
                            $email_to = $order_query->row['email'];
                            $mail = new Mail();

                            $mail->protocol = 'smtp';
                            $mail->parameter = '';
                            $mail->hostname = 'smtpout.secureserver.net';
                            $mail->username = 'jaguilar@madnessautoworks.com';
                            $mail->password = '0r1152115';
                            $mail->port = '80';
                            $mail->timeout = '10';            
                            $mail->setTo($email_to);
                            $mail->setFrom("verify@madnessautoworks.com");
                            $mail->setSender($this->config->get('config_name'));

                            if($order_query->row['status'] == 'Pending') {

                            $mail->setSubject("Verification Needed - " . $this->config->get('config_name') . " " . $order_id);
                            
                            $msg = "Greetings and salutations from " . $store_name . "!\n\n";
                            $msg .= "Thank you very much for your recent order " . $order_id . " with us. We are reaching out to you today because we need to confirm your identity (card holder) before we can process your order.\n\n";
                            $msg .= "Our identity theft prevention system cannot authenticate your credit card billing address or your order was flagged because the shipping is different from your billing address.\n\n";
                            $msg .= "To help us quickly identify you as the holder of the card, please respond to this email at Verify@MADNESSAutoworks.com to confirm your identity by:\n\n";
                            $msg .= "Provide a copy of your photo ID, PLEASE black out your driver license number.\n";
                            $msg .= "Provide a picture of the front and back of credit card you are using. ***\n";
                            $msg .= "*** COVER ALL card numbers on the front and back, leaving just the last four visible for authentication on our side. Feel free to just use your smartphone and just smudge/ black out the important information or simply cover with a pen or pencil. We only need the last 4 digits.\n\n";
                            $msg .= "Please respond with this information to the Verify@MADNESSAutoworks.com email address. If you prefer to call, please call our TX location at 512-982-9393, and we will be glad to help you over the phone with any questions you have.\n\n";
                            $msg .= "If you choose to call, you will still need to submit the documents above, via email to still verify your order.\n\n";
                            $msg .= "We know this is an inconvenience and we appreciate your assistance. As consumers ourselves we understand the importance of protecting personal information online and as a business we seek to protect our customers as well as provide them with the best possible service.\n\n";
                            $msg .= "Thank you again for your purchase and your assistance in verifying your order so we may get it out the door.\n\n";
                            $msg .= "Sincerely,\n\n";
                            $msg .= "MADNESS Autoworks\n";
                            $msg .= "Online Verification Team\n\n";
                            $msg .= "AUS/ Spicewood, TX Location\n";
                            $msg .= "22108 State HW 71 W\n";
                            $msg .= "Spicewood, TX 78669\n";
                            $msg .= "512-982-9393";

                            } else {

                            $mail->setSubject("Order Succesfully Verified - " . $this->config->get('config_name') . " " . $order_id);
                            
                            $msg = "Greetings and salutations from " . $store_name . "!\n\n";
                            $msg .= "Thank you for verifying your order with us.\n";
                            $msg .= "You order is marked complete and we have already requested for the shipping department to move forward on shipping your order. \n\n";
                            $msg .= "The Shipping Department will notify you via email of your tracking numbers. \n";
                            $msg .= "Your tracking numbers will also be noted within your account, online.\n\n";
                            $msg .= "Many thanks again for your patience and understanding.\n\n";
                            $msg .= "Sincerely,\n\n";
                            $msg .= "MADNESS Autoworks\n";
                            $msg .= "Online Verification Team\n\n";
                            $msg .= "AUS/ Spicewood, TX Location\n";
                            $msg .= "22108 State HW 71 W\n";
                            $msg .= "Spicewood, TX 78669\n";
                            $msg .= "512-982-9393";

                            }

                            $mail->setText(strip_tags(html_entity_decode($msg, ENT_QUOTES, 'UTF-8')));

                            $mail->send();    

                        }

                    }
                    ]]></add>
            </operation>
            <operation info="Fix linebreaks in regular e-mails">
                    <search position="replace" offset="1"><![CDATA[
                    $message .= $language->get('text_comment') . "\n\n";
                    ]]></search>
                    <add><![CDATA[
                    $message .= $language->get('text_comment') . "<br><br>";
                    $message .= strip_tags(html_entity_decode($data['comment'], ENT_QUOTES, 'UTF-8'), "<br>") . "<br><br>";
                    ]]></add>
            </operation>
        </file>
</modification>