<?php
set_include_path("../");
include_once("server/class/BackOfficeManager.php");
include_once("server/class/User.php");

use PHPMailer\PHPMailer\PHPMailer;

header("Content-Type: text/html;charset=utf-8");

$lag['data'][0] = array('org' => 'Organizacion 1', 'machineName' => '05 VW 5746', 'machineMatricula' => 'SHC3524', 'lastMessage' => '15-02 14:28', 'lag' => '2545.5', 'status' => 'DELAYED');
$lag['data'][1] = array('org' => 'Organizacion 2', 'machineName' => '04 Hyundai 1731', 'machineMatricula' => 'SHC3524', 'lastMessage' => '15-02 14:28', 'lag' => '146985.5', 'status' => 'SNOOZED');
$lag['data'][2] = array('org' => 'Organizacion 3', 'machineName' => '01 Hyundai 6506', 'machineMatricula' => 'SHC8542', 'lastMessage' => '15-02 14:28', 'lag' => '128.3', 'status' => 'DELAYED');
$lag['resume']['delayed'] = 2;
$lag['resume']['snoozed'] = 1;
$lag['resume']['disconnected'] = 0;

$movement[0] = array('machineId' => '4568', 'org' => 'Organizacion 3', 'machineName' => '85 Hyundai 8541', 'machineMatricula' => 'SHC3524', 'machineImei' => '862894020875681');
$movement[1] = array('machineId' => '6668', 'org' => 'Organizacion 13', 'machineName' => '02 Kia 6479', 'machineMatricula' => 'SHC3524', 'machineImei' => '564654646659');

$vandalism[0] = array('machineId' => '3368', 'org' => 'Organizacion 22', 'machineName' => '85 Hyundai 8541', 'machineMatricula' => 'SHC3524', 'machineImei' => '862894020875681');
$vandalism[1] = array('machineId' => '8868', 'org' => 'Organizacion 14', 'machineName' => '02 Kia 6479', 'machineMatricula' => 'SHC3524', 'machineImei' => '456465421131');

$results['comunication'] = $lag;
$results['movement'] = $movement;
$results['vandalism'] = $vandalism;

$hoy = strtotime('today');

$usersWithEmail[0] = array('nombre' => 'Americo Patetta',  'email' => 'americo.patetta@roman-group.com'); //Usa el campo email_prueba de la BD
$usersWithEmail[1] = array('nombre' => 'Antonio Labarte',  'email' => 'antonio.labarte@roman-group.com'); //Usa el campo email_prueba de la BD$emailsToSend;

if (is_array($usersWithEmail) && count($usersWithEmail)) {

    for ($i = 0; $i < count($usersWithEmail); $i++) {

        $userName = $usersWithEmail[$i]['nombre'];
        $userEmailToSend = $usersWithEmail[$i]['email'];

        $fechaHoy = gmdate("d-m-Y", $hoy);
        $reporte_rango_fechas = 'Al ' . $fechaHoy;

        $comunication_container = '';
        $movements_container = '';
        $vandalisms_container = '';

        if (!is_null($results['comunication']['data'])) {

            for ($ii = 0; $ii < count($results['comunication']['data']); $ii++) {
                $unit = $results['comunication']['data'][$ii];
                $unitOrg = $unit['org'];
                $unitName = $unit['machineName']; // $results['details'][$i]['machineName'];
                $unitMatricula = ($unit['machineMatricula']) ? ' (' . $unit['machineMatricula'] . ')' : '';
                $unitLastMessage = $unit['lastMessage'];
                $unitLag = $unit['lag'];
                $unitStatus = $unit['status'];

                $resumenDelayed = $results['comunication']['resume']['delayed'];
                $resumenSnoozed = $results['comunication']['resume']['snoozed'];
                $resumenDisconnected = $results['comunication']['resume']['disconnected'];

                $comunicationResumen = 'Delayed: ' . $resumenDelayed . '&nbsp;&nbsp;&nbsp;Snoozed: ' . $resumenSnoozed . '&nbsp;&nbsp;&nbsp;Disconnected: ' . $resumenDisconnected;

                $comunication_container .= '
                                        <tr>
                                            <td class="column column-1" width="25%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-left: 2px; padding-right: 2px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitOrg . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-2" width="30%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitName . $unitMatricula . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-3" width="15%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: center; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitLastMessage . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-4" width="15%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: right; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitLag . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-5" width="15%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: center; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitStatus . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    ';
            }

            for ($iii = 0; $iii < count($results['movement']); $iii++) {
                $unit = $results['movement'][$iii];
                $unitId = $unit['machineId'];
                $unitOrg = $unit['org'];
                $unitName = $unit['machineName']; // $results['details'][$i]['machineName'];
                $unitImei = $unit['machineImei']; // $results['details'][$i]['machineName'];
                $unitMatricula = ($unit['machineMatricula']) ? ' (' . $unit['machineMatricula'] . ')' : '';
                $movementResumen = 'Total: ' . count($results['movement']);
                $movements_container .= '
                                        <tr>
                                            <td class="column column-1" width="15%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-left: 2px; padding-right: 2px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: center; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitId . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-2" width="30%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitOrg . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-2" width="35%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitName . $unitMatricula . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-2" width="20%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitImei . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>';
            }

            for ($iiii = 0; $iiii < count($results['vandalism']); $iiii++) {
                $unit = $results['vandalism'][$iiii];
                $unitId = $unit['machineId'];
                $unitOrg = $unit['org'];
                $unitName = $unit['machineName']; // $results['details'][$i]['machineName'];
                $unitMatricula = ($unit['machineMatricula']) ? ' (' . $unit['machineMatricula'] . ')' : '';
                $unitImei = $unit['machineImei']; // $results['details'][$i]['machineName'];
                $vandalismResumen = 'Total: ' . count($results['vandalism']);
                $vandalisms_container .= '
                                        <tr>
                                            <td class="column column-1" width="15%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-left: 2px; padding-right: 2px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: center; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitId . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-2" width="30%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitOrg . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-2" width="35%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitName . $unitMatricula . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="column column-2" width="20%"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                                <table class="text_block block-1" width="100%" border="0"
                                                    cellpadding="5" cellspacing="0" role="presentation"
                                                    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                    <tr>
                                                        <td class="pad">
                                                            <div style="font-family: sans-serif">
                                                                <div class
                                                                    style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                    <p dir="ltr"
                                                                        style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                        <span style="font-size:14px;">' . $unitImei . '</span>
                                                                    </p>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>';
            }
        } else {
            $comunication_container .= '<tr>
                                        <td class="column column-1" width="100%"
                                            style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-left: 10px; padding-right: 10px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                            <table class="text_block block-1" width="100%" border="0"
                                                cellpadding="10" cellspacing="0" role="presentation"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                <tr>
                                                    <td class="pad">
                                                        <div style="font-family: sans-serif">
                                                            <div class
                                                                style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                <p dir="ltr"
                                                                    style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                    <span style="font-size:14px;">No hay unidades sin comunicar.</span>
                                                                </p>
                                                            </div>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>';
            $movements_container .= '<tr>
                                        <td class="column column-1" width="100%"
                                            style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-left: 10px; padding-right: 10px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                            <table class="text_block block-1" width="100%" border="0"
                                                cellpadding="10" cellspacing="0" role="presentation"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                <tr>
                                                    <td class="pad">
                                                        <div style="font-family: sans-serif">
                                                            <div class
                                                                style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                <p dir="ltr"
                                                                    style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                    <span style="font-size:14px;">No se encontraron datos.</span>
                                                                </p>
                                                            </div>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>';
            $vandalisms_container .= '<tr>
                                        <td class="column column-1" width="100%"
                                            style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; background-color: #ffffff; padding-bottom: 0px; padding-left: 10px; padding-right: 10px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;">
                                            <table class="text_block block-1" width="100%" border="0"
                                                cellpadding="10" cellspacing="0" role="presentation"
                                                style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;">
                                                <tr>
                                                    <td class="pad">
                                                        <div style="font-family: sans-serif">
                                                            <div class
                                                                style="font-size: 12px; font-family: \'Roboto\', Tahoma, Verdana, Segoe, sans-serif; mso-line-height-alt: 14.399999999999999px; color: #4b4b4d; line-height: 1.2;">
                                                                <p dir="ltr"
                                                                    style="margin: 0; font-size: 12px; text-align: left; mso-line-height-alt: 14.399999999999999px;">
                                                                    <span style="font-size:14px;">No se encontraron datos.</span>
                                                                </p>
                                                            </div>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>';
        }

        $reportHtml = file_get_contents("template/reporte_interno.html");
        $imgLogo = '<img src="https://www.protracking.com.uy/images/logo-protracking.png" style="display: block; height: auto; border: 0; width: 207px; max-width: 207px;" width="207">';

        $reportHtml = str_replace('{logo_image}', $imgLogo, $reportHtml);
        $reportHtml = str_replace('{logo_image1}', $imgLogo, $reportHtml);
        $reportHtml = str_replace('{reporte_rango_fechas}', $reporte_rango_fechas, $reportHtml);
        $reportHtml = str_replace('{comunication_container}', $comunication_container, $reportHtml);
        $reportHtml = str_replace('{comunicationResumen}', $comunicationResumen, $reportHtml);
        $reportHtml = str_replace('{movements_container}', $movements_container, $reportHtml);
        $reportHtml = str_replace('{movementResumen}', $movementResumen, $reportHtml);
        $reportHtml = str_replace('{vandalisms_container}', $vandalisms_container, $reportHtml);
        $reportHtml = str_replace('{vandalismResumen}', $vandalismResumen, $reportHtml);

        //registro el reporte
        //$reportId = $borr->registerSending("SEM", $reportHtml);

        //echo $reportHtml;

        require_once "../PHPMailer/Exception.php";
        require_once "../PHPMailer/PHPMailer.php";
        require_once "../PHPMailer/SMTP.php";

        $mail = new PHPMailer();

        //Server settings
        $mail->isSMTP();
        //$mail->SMTPDebug = 1;
        $mail->Host = 'smtpout.secureserver.net';
        $mail->SMTPAuth = true;
        $mail->Username = 'noresponder@protracking.com.uy';
        $mail->Password = 'NoResponder1024!';
        $mail->SMTPSecure = 'smtp';
        $mail->Port = 80;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom("noresponder@protracking.com.uy", "Protracking");
        $mail->addAddress($userEmailToSend, $userName);
        $mail->clearReplyTos();
        $mail->addReplyTo("comercial@protracking.com.uy", "Protracking");

        // Content
        $mail->isHTML(true);
        $mail->Subject = 'Reporte diario Protracking - ' . $userName;
        $mail->Body = $reportHtml;

        $mail->AltBody = 'Reporte diario Protracking - ' . $userName;

        if (!$mail->send()) {
            echo "Error al enviar a: " . $userEmailToSend . "<br>";
        } else {
            echo "Enviado a: " . $userEmailToSend . "<br>";
        }
    }
}

function getLastSaturdaysTimestamp()
{
    $hoy = strtotime('today');          // Obtener la fecha de hoy a las 0 horas
    $diaSemana = date('N', $hoy);       // Obtener el número del día de la semana (1 para lunes, 7 para domingo)                                  
    if ($diaSemana == 6) {              // Si hoy es sábado, devolver el timestamp de hoy mismo a las 0 horas
        return $hoy;
    } else {                            // Obtener el timestamp del sábado anterior
        $sabadoAnterior = strtotime('last Saturday', $hoy);
        return $sabadoAnterior;
    }
}
