<?php
require_once '../config.php';
require_once '../../../vendor/autoload.php';
require_once "/home/jobaajgroup/public_html/emp3.jobaaj.com/mail/mailLog.php";


date_default_timezone_set('Asia/Kolkata');

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



function resetPassword($data)
{

    list($name, $to, $employee_id) = $data;

    $key = password_hash($name . $to . $employee_id . date("YMDHis"), PASSWORD_BCRYPT);

    $query = mysqli_query($GLOBALS['db'], "INSERT INTO `reset_password_key` (`id`, `employee_id`, `key`) VALUES (NULL, '$employee_id', '$key');");

    if ($query) {

        $mail = new PHPMailer(true);
        try {

            $subject = 'Reset Employee Dashboard Password - Jobaaj';
            mailLog($subject, $to);

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

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

            $mail->addAddress($to);

            $mail->isHTML(true);
            $mail->Subject = $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 style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' 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>
                                                        <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                            <a href='http://employee.nishtyainfotech.com'>
                                                                <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                            <p>Hello $name,</p>
                                                            <p>
                                                                Please, Reset Your Employee Dashboard Password.
                                                            </p>
                                                            <p>
                                                                You can Login with your Employee Id:- <strong>$employee_id</strong> or E-mail Address:- <strong>$to</strong>
                                                            </p>
                                                            <p style='font-size:18px;'>
                                                                <a href='http://employee.nishtyainfotech.com/resetPassword?key=$key'>Click Here</a>
                                                            </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';
            // $mail->send();
            // if ($mail->send()) {
            //     return 1;
            // } else {
            //     return 2;
            // }
            // echo $mail->Body;
        } catch (Exception $e) {
            // echo "Message could not be sent. Mailer Error: {$e->ErrorInfo}";
        }
    } else {
        return mysqli_error($GLOBALS['db']);
    }
}



function sendEmployeeRequest($data)
{

    list($employee_id, $date, $type, $reason, $diffNum) = $data;
    $type = ($type == 'Absent') ? 'Leave' : $type;

    $q = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "SELECT t1.employee_id e_id, t1.name e_name, t1.email e_email, t2.employee_id l_id, t2.name l_name, t2.email l_email from users t1, users t2 where t1.employee_id = '$employee_id' and t2.employee_id = t1.leader "));

    $aq = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "SELECT t1.employee_id e_id, t1.name e_name, t1.email e_email, t2.employee_id l_id, t2.name l_name, t2.email l_email from users t1, users t2 where t1.employee_id = '$q[l_id]' and t2.employee_id = t1.leader "));

    if ($diffNum > 2) {

        $to = $aq['l_email'];
        $replyTo = $q['e_email'];
        $eName = $q['e_name'];
        $lName = $aq['l_name'];
    } else {

        $to = $q['l_email'];
        $replyTo = $q['e_email'];
        $eName = $q['e_name'];
        $lName = $q['l_name'];
    }


    if (!empty($type)) {

        $mailBody = "<p>
                <strong>$eName</strong> want <strong>$type</strong> on <strong>$date</strong>
            </p>
            <p>
                Reason: <strong>$reason</strong>
            </p>";
    } else {

        $pd = date('M d Y', strtotime(explode("to", $date)[0]));
        $preAttendance = '';
        $preAttendance = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from attendance where employee_id='$employee_id' and which_month='$pd'"));

        $mailBody = "<p>
                <strong>$eName</strong> has issue with <strong>$date</strong><br><br>
                Previous Attendace:-<br>
                Attendace Status:- <strong>$preAttendance[attendance_status]</strong><br>
                Punch In:- <strong>$preAttendance[punch_in]</strong><br>
                Punch Out:- <strong>$preAttendance[punch_out]</strong>
            </p>
            <p>
                Issue Reason: <strong>$reason</strong>
            </p>";
    }


    $mail = new PHPMailer(true);
    try {

        $subject = 'Request From Your Employee - Jobaaj';
        mailLog($subject, $to);

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

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

        $mail->AddReplyTo($replyTo);
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $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 style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' 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>
                                                            <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                                <a href='http://employee.nishtyainfotech.com/'>
                                                                    <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                                <p>Hello $lName,</p>
                                                                
                                                                $mailBody

                                                                <!-- <p style='font-size:18px;'>
                                                                    <a href='http://employee.nishtyainfotech.com/' style='text-decoration:none; border:1px solid #43d39e; background:rgba(67,211,158,.15); color:#43d39e; padding:0.5rem 1rem; border-radius:0.3rem; margin-right:1rem;'>Accept</a>
                                                                    <a href='http://employee.nishtyainfotech.com/' style='text-decoration:none; border:1px solid #ff5c75; background:rgba(255,92,117,.15); color:#ff5c75; padding:0.5rem 1rem; border-radius:0.3rem;'>Reject</a>
                                                                </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';
        // $mail->send();
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        // echo "Message could not be sent. Mailer Error: {$e->ErrorInfo}";
    }
}



function sendRequestStatus($data)
{

    list($id, $for) = $data;
    if ($for == 'IssueStatus') {
        $status = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from issue_with_date where id='$id' "));
        $st = ($status['issue_status'] == 1) ? 'Approved' : 'Rejected';
        $type = ($status['issue_type'] == 'Absent') ? 'Leave' : $status['issue_type'];
        $date = $status['issue_date'];
        $employee_id = $status['employee_id'];
        $reason = $status['remark'];
        $statusBy = $status['status_by'];
    } else if ($for == 'RequestStatus') {
        $status = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from request_leave where id='$id' "));
        $st = ($status['leave_status'] == 1) ? 'Approved' : 'Rejected';
        $type = ($status['leave_type'] == 'Absent') ? 'Leave' : $status['issue_type'];
        $date = $status['leave_date'];
        $employee_id = $status['employee_id'];
        $reason = $status['remark'];
        $statusBy = $status['status_by'];
    } else {
    }

    $q = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "SELECT t1.employee_id e_id, t1.name e_name, t1.email e_email, t2.employee_id l_id, t2.name l_name, t2.email l_email from users t1, users t2 where t1.employee_id = '$employee_id' and t2.employee_id = '$statusBy' "));

    $to = $q['e_email'];
    $replyTo = $q['l_email'];
    $eName = $q['e_name'];
    $lName = $q['l_name'];

    if ($for == 'IssueStatus') {

        $mailBody = "<p>Your issue with <strong>$date</strong> Request <strong>$st</strong> with <strong>$type</strong> by <strong>$lName</strong></p>
            <p><strong>Note by $lName:</strong> $reason</p>";
    } else if ($for == 'RequestStatus') {
        $mailBody = "<p>
                Your <strong>$type</strong> Request <strong>$st</strong> by <strong>$lName</strong> for <strong>$date</strong>
            </p>
            <p><strong>Note by $lName:</strong> $reason</p>";
    } else {
    }


    $mail = new PHPMailer(true);
    try {
        $subject = 'Request Status From Your Manager - Jobaaj';
        mailLog($subject, $to);

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

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

        $mail->AddReplyTo($replyTo);
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $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 style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' 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>
                                                            <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                                <a href='http://employee.nishtyainfotech.com/'>
                                                                    <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                                <p>Hello $eName,</p>
                                                                
                                                                $mailBody

                                                                <!-- <p style='font-size:18px;'>
                                                                    <a href='http://employee.nishtyainfotech.com/' style='text-decoration:none; border:1px solid #43d39e; background:rgba(67,211,158,.15); color:#43d39e; padding:0.5rem 1rem; border-radius:0.3rem; margin-right:1rem;'>Accept</a>
                                                                    <a href='http://employee.nishtyainfotech.com/' style='text-decoration:none; border:1px solid #ff5c75; background:rgba(255,92,117,.15); color:#ff5c75; padding:0.5rem 1rem; border-radius:0.3rem;'>Reject</a>
                                                                </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';
        // $mail->send();
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        // echo "Message could not be sent. Mailer Error: {$e->ErrorInfo}";
    }
}


function sendPaySlipRequest($data)
{
    $administrator = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from users where employee_id='NI01' "));

    if (sizeof($data) == 3) {
        list($byId, $sId, $month) = $data;
        $helloName = $administrator['name'];

        $requestId = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from users where employee_id='$byId' "));
        $slipId = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from users where employee_id='$sId' "));

        $rName = $requestId['name'];
        $sName = $slipId['name'];

        if ($byId == $sId) {
            $mailBody = "<p><strong>$rName</strong> Request for Pay Slip of <strong>$month</strong></p>";
        } else {
            $mailBody = "<p><strong>$rName</strong> Request for <strong>$sName's</strong> Pay Slip of <strong>$month</strong></p>";
        }

        $to = $administrator['email'];
        $replyTo = $requestId['email'];
    } else {
        list($id) = $data;
        $rSlip = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from request_slip where id='$id' "));
        $month = $rSlip['month'];
        $byId = $rSlip['request_id'];
        $sId = $rSlip['slip_id'];
        $status = ($rSlip['status'] == 1) ? 'Approved' : 'Rejected';

        $requestId = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from users where employee_id='$byId' "));
        $slipId = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from users where employee_id='$sId' "));
        $statusBy = mysqli_fetch_assoc(mysqli_query($GLOBALS['db'], "select * from users where employee_id='$rSlip[status_by]' "));

        $rName = $requestId['name'];
        $sName = $slipId['name'];

        $helloName = $rName;

        if ($byId == $sId) {
            $mailBody = "<p>Your Request for Pay Slip of <strong>$month</strong> is <strong>$status</strong> By <strong>$statusBy[name]</strong></p>";
        } else {
            $mailBody = "<p>Your Request for <strong>$sName's</strong> Pay Slip of <strong>$month</strong> is <strong>$status</strong> By <strong>$statusBy[name]</strong></p>";
        }

        $to = $requestId['email'];
        $replyTo = $statusBy['email'];
    }


    $mail = new PHPMailer(true);
    try {
        $subject = 'Request For Pay Slip - Jobaaj';
        mailLog($subject, $to);

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

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

        $mail->AddReplyTo($replyTo);
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $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 style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' 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>
                                                            <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                                <a href='http://employee.nishtyainfotech.com/'>
                                                                    <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                                <p>Hello $helloName,</p>
                                                                
                                                                $mailBody

                                                            </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';
        // $mail->send();
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        // echo "Message could not be sent. Mailer Error: {$e->ErrorInfo}";
    }
}


function birthday($data)
{

    $to = $data['e_email'];
    $current_year = date('Y');

    $mail = new PHPMailer(true);
    try {
        $subject = "🎉 Happy Birthday! 🎂 ";
        mailLog($subject, $to);

        $mail->SMTPDebug = 0;
        $mail->isSMTP();
        $mail->CharSet = "UTF-8";

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

        // $mail->AddReplyTo($replyTo);
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $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>Happy Birthday from Jobaaj</title>
                    <style type='text/css'>
                        /* Client-specific resets */
                        body,
                        table,
                        td,
                        a {
                            -webkit-text-size-adjust: 100%;
                            -ms-text-size-adjust: 100%;
                        }
                        table,
                        td {
                            mso-table-lspace: 0pt;
                            mso-table-rspace: 0pt;
                        }
                        img {
                            -ms-interpolation-mode: bicubic;
                            border: 0;
                            height: auto;
                            line-height: 100%;
                            outline: none;
                            text-decoration: none;
                        }
                        table {
                            border-collapse: collapse !important;
                        }
                        body {
                            height: 100% !important;
                            margin: 0 !important;
                            padding: 0 !important;
                            width: 100% !important;
                        }

                        /* iOS blue links */
                        a[x-apple-data-detectors] {
                            color: inherit !important;
                            text-decoration: none !important;
                            font-size: inherit !important;
                            font-family: inherit !important;
                            font-weight: inherit !important;
                            line-height: inherit !important;
                        }

                        /* Gmail blue links */
                        u + #body a {
                            color: inherit;
                            text-decoration: none;
                            font-size: inherit;
                            font-family: inherit;
                            font-weight: inherit;
                            line-height: inherit;
                        }

                        /* Universal styles */
                        body {
                            font-family: Arial, Helvetica, sans-serif;
                            line-height: 1.6;
                            color: #333333;
                        }
                    </style>
                </head>
                <body style='background:#f3f7f5;'>
                    <!-- Email wrapper -->
                    <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' border='0' cellspacing='0' cellpadding='0'>
                        <tr>
                            <td align='center' valign='top' style='padding: 20px 10px'>
                                <!-- Email container -->
                                <table border='0' cellpadding='0' cellspacing='0' width='600' role='presentation' style='max-width: 600px; margin: 0 auto; background-color: #ffffff; border-radius: 8px;' bgcolor='#ffffff'>
                                    <!-- Header -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 30px 20px 0px 20px'>
                                            <img src='https://www.jobaaj.com/mail/images/logo.png' alt='Jobaaj Logo' width='200' style=' width: 180px; height: auto; display: block; margin: 0 auto;' border='0'/>
                                        </td>
                                    </tr>

                                    <!-- Main heading -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 10px 20px 20px 20px'>
                                            <h1 style='margin: 0; font-family: Arial, sans-serif; font-size: 28px; line-height: 36px; color: #333333; font-weight: bold;'> Happy Birthday $data[e_name] ! </h1>
                                        </td>
                                    </tr>

                                    <!-- Main image -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 0 20px 20px 20px'>
                                            <img src='{$GLOBALS['url']}mail/birthday_image.gif' alt='Birthday Celebration' width='500' style='width: 500px; max-width: 100%; height: auto; display: block; margin: 0 auto; border-radius: 5px;' border='0' />
                                        </td>
                                    </tr>

                                    <!-- Birthday wish -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 20px 20px 10px 20px'>
                                            <p style='margin: 0; font-family: Arial, sans-serif; font-size: 20px; line-height: 28px; color: #333333; font-weight: 700;'>
                                                Wishing you a very happy and blessed birthday!! 🎂 ❤️
                                            </p>
                                        </td>
                                    </tr>

                                    <!-- Main message -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 10px 40px 30px 40px'>
                                            <p style='margin: 0; font-family: Arial, sans-serif; font-size: 16px; line-height: 26px; color: #333333; text-align: center;'>
                                                Just like Jobaaj empowers people to transform their careers, we
                                                hope this year empowers you fo chase your dreams, level up your
                                                skills, and unlock amazing new opportunities! 😍
                                            </p>
                                        </td>
                                    </tr>

                                    <!-- Divider -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 0 20px'>
                                            <table border='0' cellpadding='0' cellspacing='0' width='100%' role='presentation'>
                                                <tr>
                                                    <td height='1' style='font-size: 1px; line-height: 1px; background-color: #dddddd;' bgcolor='#dddddd'>&nbsp;</td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>

                                    <!-- Social media section -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 30px 20px 20px 20px'>
                                            <table border='0' cellpadding='0' cellspacing='0' width='100%' role='presentation'>
                                                <tr>
                                                    <td valign='top' style='padding: 0 10px'>
                                                        <table border='0' cellpadding='0' cellspacing='0' width='100%' role='presentation'>
                                                            <tr>
                                                                <td align='center' valign='top' style='padding: 0 10px'>
                                                                    <img src='https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-jGUqcAbisIa9i31vyVcT9BGgb8eJ3U.png' alt='Instagram' width='170' style='width: 170px; max-width: 100%; height: auto; display: block; margin: 0 auto;' border='0'/>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                    <td valign='top' style='padding: 0 10px'>
                                                        <table border='0' cellpadding='0' cellspacing='0' width='100%' role='presentation'>
                                                            <tr>
                                                                <td align='left' valign='top' style='padding: 0 10px'>
                                                                    <h3 style='margin: 0 0 10px 0; font-family: Arial, sans-serif; font-size: 18px; line-height: 24px; color: #333333; font-weight: bold;'>Say Hi to Us on Instagram!</h3>
                                                                    <p style='margin: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 22px; color: #333333;'>
                                                                        Follow us on Insta
                                                                        <a href='https://instagram.com/jobaaj.com_' target='_blank' style='color: #0066cc; text-decoration: underline;'>@jobaaj.com_</a>
                                                                        to stay in the loop with your teammates, alumni, behind-the-scenes fun, and everything happening in our world—from celebrations to career wins! 🎉
                                                                    </p>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>

                                    <!-- Divider -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 0 20px'>
                                            <table border='0' cellpadding='0' cellspacing='0' width='100%' role='presentation'>
                                                <tr>
                                                    <td height='1' style='font-size: 1px; line-height: 1px; background-color: #dddddd;' bgcolor='#dddddd'>&nbsp;</td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>

                                    <!-- Footer -->
                                    <tr>
                                        <td align='center' valign='top' style='padding: 20px; background-color: #f5f5f5' bgcolor='#f5f5f5'>
                                            <p
                                                style='margin: 0; font-family: Arial, sans-serif; font-size: 12px; line-height: 18px; color: #666666;'>
                                                &copy; $current_year Nishiya Infotech Pvt. Ltd., Rohini, Delhi. All rights reserved.<br />
                                                <a href='https://www.jobaaj.com' target='_blank' style='color: #666666; text-decoration: underline' >www.jobaaj.com</a>
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </body>
            </html> 
        ";
        $mail->AltBody = 'Body in plain text for non-HTML mail clients';
        // $mail->send();
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        // return "Message could not be sent. Mailer Error: {$e}";
    }
}


function yearComplete($data)
{

    $to = $data['e_email'];

    $count = date("Y") - date("Y",strtotime($data['joining_date']));

    $mail = new PHPMailer(true);
    try {
        $subject = "🎉 Happy Work Anniversary! 🎉 ";
        mailLog($subject, $to);

        $mail->SMTPDebug = 0;
        $mail->isSMTP();
        $mail->CharSet = "UTF-8";

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

        // $mail->AddReplyTo($replyTo);
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $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 style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' 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>
                                                            <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                                <a href='http://employee.nishtyainfotech.com/'>
                                                                    <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                            <p>Dear <strong>$data[e_name]</strong>,</p>

                                                            <p>Today marks a very special day - your work anniversary! We can hardly believe it's been $count year since you joined our team. We want to thank you for your hard work, dedication, and contributions to our company over the past few years.</p>

                                                            <p>Your positive attitude, passion, and commitment to excellence have been an inspiration to all of us. We are grateful to have you as a part of our team, and look forward to work together for many more years to come.</p>

                                                            <p>👏 Congratulations 👏 on this special day, and here's to a bright future ahead!</p>
                                                            
                                                            <p>Regards,<br>
                                                                Team Jobaaj
                                                            </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';
        // $mail->send();
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        // return "Message could not be sent. Mailer Error: {$e}";
    }
}


function newJoining($data)
{

    $to = $data['e_email'];

    $mail = new PHPMailer(true);
    try {
        $subject = "Welcome to Jobaaj! ";
        mailLog($subject, $to);

        $mail->SMTPDebug = 0;
        $mail->isSMTP();
        $mail->CharSet = "UTF-8";

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

        // $mail->AddReplyTo($replyTo);
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $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 style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' 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>
                                                            <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                                <a href='http://employee.nishtyainfotech.com/'>
                                                                    <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                            <p>Dear <strong>$data[e_name]</strong>,</p>

                                                            <p>Welcome to Jobaaj! We're thrilled to have you join our team.</p>

                                                            <p>Our company culture is focused on collaboration and teamwork, and we look forward to working with you to achieve our goals. If you have any questions or concerns, feel free to reach out to your manager or HR representative.</p>

                                                            <p>Once again, welcome aboard!</p>
                                                            
                                                            <p>Warm Regards,<br>
                                                                Team Jobaaj
                                                            </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';
        // $mail->send();
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        // return "Message could not be sent. Mailer Error: {$e}";
    }
}


function probation($data)
{

    $to = $data['l_email'];

    $mail = new PHPMailer(true);
    try {
        $subject = "Completion of $data[e_name]'s Probation - Jobaaj";
        mailLog($subject, $to);

        $mail->SMTPDebug = 0;
        $mail->isSMTP();
        $mail->CharSet = "UTF-8";

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

        // $mail->AddReplyTo($replyTo);
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $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 style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' 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>
                                                            <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                                <a href='http://employee.nishtyainfotech.com/'>
                                                                    <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                            <p>Dear <strong>$data[l_name]</strong>,</p>

                                                            <p>This is to inform you that <strong>$data[e_name]</strong> has successfully completed their probation period.</p>

                                                            <p>Regards,<br>
                                                                Team Jobaaj
                                                            </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';
        // $mail->send();
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        // echo $mail->Body;
    } catch (Exception $e) {
        // return "Message could not be sent. Mailer Error: {$e}";
    }
}

// echo yearComplete(['e_name'=>'Iqbal Shah','e_email'=>'iqbalshah9368@gmail.com', 'joining_date'=>'2020-03-03']);
// sendReuest('iqbalshah9368@gmail.com', '');
