Files
crm.clientright.ru/modules/Project/tasks/SendReminder.service

54 lines
2.7 KiB
Desktop File
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include_once 'modules/Users/Users.php';
require_once 'include/Webservices/Utils.php';
require_once 'include/utils/WhatsApp.php';
require_once 'include/utils/Telegram.php';
require_once 'includes/Loader.php';
vimport ('includes.runtime.Globals');
vimport ('includes.runtime.BaseModel');
vimport ('includes.runtime.LanguageHandler');
require_once 'modules/Emails/mail.php';
global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $adb;
//$logstring = date('Y-m-d H:i:s').' - вошли в планировщик с отправками писем'.PHP_EOL;
//file_put_contents('schSendReminder.log', $logstring, FILE_APPEND);
$query = 'select p.projectname, cf.cf_1847 as link, cf.cf_1845 as starttime, p.linktoaccountscontacts as contactid, c.email, c.firstname
from vtiger_project p
left join vtiger_projectcf cf on cf.projectid = p.projectid
left join vtiger_contactdetails c on c.contactid = p.linktoaccountscontacts
left join vtiger_crmentity e on e.crmid = p.projectid
where e.deleted = 0 and cf.cf_1843 = CURDATE() and cf.cf_1847 is not null and time_to_sec(cf.cf_1845) - time_to_sec(now()) BETWEEN 60 and 1200';
$result = $adb->pquery($query);
if ($adb->num_rows($result) == 0) {
$logstring = date('Y-m-d H:i:s').' - в ближайшие 20 минут нет напоминаний о встречах'.PHP_EOL;
file_put_contents('schSendReminder.log', $logstring, FILE_APPEND);
} else {
$subject = 'У нас скоро видео встреча!';
for ($i == 0; $i < $adb->num_rows($result); $i++) {
$name = $adb->query_result($result, $i, "projectname");
$link = $adb->query_result($result, $i, "link");
$starttime = $adb->query_result($result, $i, "starttime");
$contactid = $adb->query_result($result, $i, "contactid");
$email = $adb->query_result($result, $i, "email");
$firstname = $adb->query_result($result, 0, "firstname");
$body = 'Добрый день, '.$firstname.'.<br><br>';
$body .= 'Напоминаю, что у нас запланирована видеовстреча сегодя в '.$starttime.'<br>';
$body .= 'Вот ссылка для подключения: <a href="'.$link.'">'.$link.'</a>';
$mail_status = send_mail('Contacts', $email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $body);
$logstring = date('Y-m-d H:i:s').' - отправка напоминания на '.$email.': '.$mail_status.PHP_EOL;
file_put_contents('schSendReminder.log', $logstring, FILE_APPEND);
}
}
//send_mail($module,$to_email,$from_name,$from_email,$subject,$contents,$cc='',$bcc='',$attachment='',$emailid='',$logo='', $useGivenFromEmailAddress=false,$useSignature = 'Yes',$inReplyToMessageId='')