<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once '../config.php';
require_once '../../../vendor/autoload.php';


date_default_timezone_set('Asia/Kolkata');

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;



function send_letter($data)
{

    
    list($name, $to, $employee_id, $letter_table, $pdf_url, $position, $domain) = $data;
    $which_letter = str_replace('_', ' ', $letter_table);
    $which_letter = ucwords($which_letter);


    $letter_content = [
        'relieving_letter' => [
            'subject' => "Relieving Letter Confirmation - ($employee_id)",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>I hope this email finds you well.</p>
                    <p>We would like to extend our gratitude for your dedicated service and contributions during your time with us. Attached to this email, you will find your relieving letter.</p>
                    <p>We wish you the very best in your future endeavors and sincerely hope that your experience with us has been enriching and rewarding.</p>
                    <p>If you require any further assistance or documentation, please feel free to contact us.</p>
                </td>"
        ],
        'internship_complete_letter' => [
            'subject' => "Internship Completion Certificate $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>I hope this email finds you well.</p>
                    <p>We are pleased to inform you that you have successfully completed your internship with Jobaaj.com. It has been a pleasure having you as part of our team, and we would like to take this opportunity to acknowledge your dedication, hard work, and contribution during your internship.</p>
                    <p>Please find attached your Internship Completion Letter for your records.</p>
                    <p>We sincerely hope that your experience with us has been enriching and rewarding. We believe that you have gained valuable insights and skills that will serve you well in your future endeavors.</p>
                    <p>We wish you all the best in your academic and professional pursuits, and we are confident that you will continue to excel in your chosen field.</p>
                    <p>If you have any questions or require further assistance, please feel free to contact us.</p>
                </td>"
        ],
        'internship_letter' => [
            'subject' => "Internship Offer Letter $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>We are delighted to offer you the opportunity to join Jobaaj.com as an <strong>$position</strong> in the <strong>$domain</strong>.</p>
                    <p>As an intern with our organization, you will have the opportunity to gain valuable hands-on experience, work on meaningful projects, and contribute to our team's success. We believe that your skills, enthusiasm, and dedication will make a significant impact during your internship with us.</p>
                    <p>Please review the attached Internship Offer Letter, which outlines the terms and conditions of your internship, including your start date, duration, responsibilities, and applicable compensation details.</p>
                    <p>Congratulations once again, and welcome aboard!</p>
                </td>"
        ],
        'appraisal_letter' => [
            'subject' => "Appraisal Letter $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>We are pleased to acknowledge your consistent efforts and valuable contributions to the organization.</p>
                    <p>Your performance during the review period has been commendable and reflects your dedication, professionalism, and commitment to excellence.</p>
                    <p>Based on your performance, we are happy to inform you that your role and responsibilities are being enhanced, along with a corresponding revision in your compensation.</p>
                    <p>We appreciate your hard work and look forward to your continued growth and success with us.</p>
                </td>"
        ],
        'full_time_letter' => [
            'subject' => "Full Time Letter $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>I hope this email finds you well.</p>
                    <p>We are pleased to offer you the position of $position at Jobaaj Group.</p>
                    <p>Please find your official offer letter attached, which outlines your role, responsibilities, and employment terms.</p>
                    <p>We kindly request you to review the offer letter carefully and do confirm your acceptance.</p>
                    <p>If you have any questions or need further clarification, feel free to reach out to us.</p>
                    <p>We look forward to having you as part of our team!</p>
                </td>"
        ],
    ];

    $mail = new PHPMailer(true);
    try {


        $mail->SMTPDebug = 0;
        $mail->isSMTP();

        include __DIR__."/../../mail_send_credential.php";

        $mail->addAddress($to);
        $mail->addCC('hr@jobaaj.com');
        $mail->addAttachment($pdf_url);
        $mail->addReplyTo('hr@jobaaj.com');

        $mail->isHTML(true);
        $mail->Subject = $letter_content[$letter_table]['subject'];


        $mail->Body = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
        <html xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'>
        
        <head>
            <meta http-equiv='Content-type' content='text/html; charset=utf8' />
            <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1' />
            <meta http-equiv='X-UA-Compatible' content='IE=edge' />
            <meta name='format-detection' content='date=no' />
            <meta name='format-detection' content='address=no' />
            <meta name='format-detection' content='telephone=no' />
            <meta name='x-apple-disable-message-reformatting' />
            <link href='https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700,700i&display=swap' rel='stylesheet' />
            <title>Email Template</title>
        </head>
        <style>
            body{
                font-family: Arial, Helvetica, sans-serif;
            }
        </style>
        <body>
            <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='left' border='0' cellspacing='0' cellpadding='0'>
                <tr>
                    <td style='margin: 0; padding: 0; width: 100%; height: 100%;' align='center' valign='top'>
                        <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                            <tr>
                                <td>
                                    <!-- Container -->
                                    <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                                        <tr>
                                            <td>
                                                <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                                                
                                                <tr>
                                                    {$letter_content[$letter_table]['content']}
                                                </tr>
                                                <tr>
                                                    <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px; line-height: 0.5;'>
                                                        <p style='font-weight:bold; margin-bottom:0;'>Thanks & Regards</p>
                                                        <p style='font-weight:bold; margin-bottom:0;'>HR Team | Jobaaj Group</p>
                                                        <p style='font-weight:bold; margin-bottom:0;'>Staffing | Recruiting | Database | Jobaaj Learnings</p>
                                                        <p><img src='{$GLOBALS['url']}letters/get-the-job-done.png'/></p>
                                                        <p style='font-weight:bold; margin-bottom:0; line-height:1;'><a href='https://www.linkedin.com/company/jobaaj-com/'>LinkedIn</a> | <a href='https://www.instagram.com/jobaaj.com_/'>Instagram</a> | <a href='https://www.youtube.com/channel/UCwZd2VGQ-tHUgrhG5gJbT2A?sub_confirmation=1'>YouTube</a> | <a href='https://jobaajlearnings.com/'>Jobaaj Learnings</a> | <a href='https://stories.jobaaj.com/'>Jobaaj Stories</a></p>
                                                        <p style='font-weight:bold; margin-bottom:0;'>Pleasure Catching Up With You!!</p>
                                                        <p style='font-weight:bold; margin-bottom:0; line-height:1;'>India's leading job portal with deep expertise in the Accounting, Finance & Data Industries</p>
                                                    </td>
                                                </tr>
                                                

                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                    <!-- END Container -->
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </body>
        
        </html>    
    ";
        $mail->AltBody = 'Body in plain text for non-HTML mail clients';
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        return "Message could not be sent. Mailer Error: {$e->getMessage()}";
    }
}

function send_signed_letter($data)
{

    
    list($name, $to, $employee_id, $letter_table, $pdf_url, $position, $domain) = $data;
    $which_letter = str_replace('_', ' ', $letter_table);
    $which_letter = ucwords($which_letter);


    $letter_content = [
        'relieving_letter' => [
            'subject' => "Relieving Letter Confirmation - ($employee_id)",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>I hope this email finds you well.</p>
                    <p>We would like to extend our gratitude for your dedicated service and contributions during your time with us. Attached to this email, you will find your relieving letter.</p>
                    <p>We wish you the very best in your future endeavors and sincerely hope that your experience with us has been enriching and rewarding.</p>
                    <p>If you require any further assistance or documentation, please feel free to contact us.</p>
                </td>"
        ],
        'internship_complete_letter' => [
            'subject' => "Internship Completion Certificate $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>I hope this email finds you well.</p>
                    <p>We are pleased to inform you that you have successfully completed your internship with Jobaaj.com. It has been a pleasure having you as part of our team, and we would like to take this opportunity to acknowledge your dedication, hard work, and contribution during your internship.</p>
                    <p>Please find attached your Internship Completion Letter for your records.</p>
                    <p>We sincerely hope that your experience with us has been enriching and rewarding. We believe that you have gained valuable insights and skills that will serve you well in your future endeavors.</p>
                    <p>We wish you all the best in your academic and professional pursuits, and we are confident that you will continue to excel in your chosen field.</p>
                    <p>If you have any questions or require further assistance, please feel free to contact us.</p>
                </td>"
        ],
        'internship_letter' => [
            'subject' => "Internship Offer Letter $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>We are delighted to offer you the opportunity to join Jobaaj.com as an <strong>$position</strong> in the <strong>$domain</strong>.</p>
                    <p>As an intern with our organization, you will have the opportunity to gain valuable hands-on experience, work on meaningful projects, and contribute to our team's success. We believe that your skills, enthusiasm, and dedication will make a significant impact during your internship with us.</p>
                    <p>Please review the attached Internship Offer Letter, which outlines the terms and conditions of your internship, including your start date, duration, responsibilities, and applicable compensation details.</p>
                    <p>Congratulations once again, and welcome aboard!</p>
                </td>"
        ],
        'appraisal_letter' => [
            'subject' => "Appraisal Letter $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>We are pleased to acknowledge your consistent efforts and valuable contributions to the organization.</p>
                    <p>Your performance during the review period has been commendable and reflects your dedication, professionalism, and commitment to excellence.</p>
                    <p>Based on your performance, we are happy to inform you that your role and responsibilities are being enhanced, along with a corresponding revision in your compensation.</p>
                    <p>We appreciate your hard work and look forward to your continued growth and success with us.</p>
                </td>"
        ],
        'full_time_letter' => [
            'subject' => "Full Time Letter $name - Jobaaj Group",
            'content' => "<td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px;'>
                    <p>Dear $name,</p>
                    <p>I hope this email finds you well.</p>
                    <p>We are pleased to offer you the position of <strong>$position</strong> with a letter at Jobaaj Group. Attached is your official offer letter, which includes details about the role, responsibilities, and terms of employment.</p>
                    <p>We kindly request you to review the offer letter carefully and do confirm your acceptance.</p>
                    <p>If you have any questions or need further clarification, feel free to reach out to us.</p>
                    <p>We look forward to having you as part of our team!</p>
                </td>"
        ],
    ];

    $mail = new PHPMailer(true);
    try {


        $mail->SMTPDebug = 0;
        $mail->isSMTP();

        include __DIR__."/../../mail_send_credential.php";

        $mail->addAddress($to);
        $mail->addCC('hr@jobaaj.com');
        $mail->addAttachment($pdf_url);
        $mail->addReplyTo('hr@jobaaj.com');

        $mail->isHTML(true);
        $mail->Subject = $letter_content[$letter_table]['subject'];


        $mail->Body = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
        <html xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'>
        
        <head>
            <meta http-equiv='Content-type' content='text/html; charset=utf8' />
            <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1' />
            <meta http-equiv='X-UA-Compatible' content='IE=edge' />
            <meta name='format-detection' content='date=no' />
            <meta name='format-detection' content='address=no' />
            <meta name='format-detection' content='telephone=no' />
            <meta name='x-apple-disable-message-reformatting' />
            <link href='https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700,700i&display=swap' rel='stylesheet' />
            <title>Email Template</title>
        </head>
        <style>
            body{
                font-family: Arial, Helvetica, sans-serif;
            }
        </style>
        <body>
            <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='left' border='0' cellspacing='0' cellpadding='0'>
                <tr>
                    <td style='margin: 0; padding: 0; width: 100%; height: 100%;' align='center' valign='top'>
                        <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                            <tr>
                                <td>
                                    <!-- Container -->
                                    <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                                        <tr>
                                            <td>
                                                <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                                                
                                                <tr>
                                                    {$letter_content[$letter_table]['content']}
                                                </tr>
                                                <tr>
                                                    <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px; font-size:16px; line-height: 0.5;'>
                                                        <p style='font-weight:bold; margin-bottom:0;'>Thanks & Regards</p>
                                                        <p style='font-weight:bold; margin-bottom:0;'>HR Team | Jobaaj Group</p>
                                                        <p style='font-weight:bold; margin-bottom:0;'>Staffing | Recruiting | Database | Jobaaj Learnings</p>
                                                        <p><img src='{$GLOBALS['url']}letters/get-the-job-done.png'/></p>
                                                        <p style='font-weight:bold; margin-bottom:0; line-height:1;'><a href='https://www.linkedin.com/company/jobaaj-com/'>LinkedIn</a> | <a href='https://www.instagram.com/jobaaj.com_/'>Instagram</a> | <a href='https://www.youtube.com/channel/UCwZd2VGQ-tHUgrhG5gJbT2A?sub_confirmation=1'>YouTube</a> | <a href='https://jobaajlearnings.com/'>Jobaaj Learnings</a> | <a href='https://stories.jobaaj.com/'>Jobaaj Stories</a></p>
                                                        <p style='font-weight:bold; margin-bottom:0;'>Pleasure Catching Up With You!!</p>
                                                        <p style='font-weight:bold; margin-bottom:0; line-height:1;'>India's leading job portal with deep expertise in the Accounting, Finance & Data Industries</p>
                                                    </td>
                                                </tr>
                                                

                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                    <!-- END Container -->
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </body>
        
        </html>    
    ";
        $mail->AltBody = 'Body in plain text for non-HTML mail clients';
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        return "Message could not be sent. Mailer Error: {$e->getMessage()}";
    }
}

// echo send_letter(['Iqbal Shah', 'iqbalshah9368@gmail.com', 'NI72', 'relieving_letter', '../generated_pdf/relieving_68722a3e1a8b23.08765828_20250712_145622.pdf']);