Current Path : /data/web/virtuals/51568/virtual/www/www/plany/ |
Current File : /data/web/virtuals/51568/virtual/www/www/plany/planEmaily.php |
<?php //javascript je v planyPlany.php include ('DBPDO.php'); if (file_exists('DbConnect.php')){ require_once('DbConnect.php'); } if (file_exists('funkce/DbConnect.php')){ require_once('funkce/DbConnect.php'); } use PHPMailer\PHPMailer\PHPMailer; if (file_exists('vendor/PHPMailer/src/Exception.php')) { require 'vendor/PHPMailer/src/Exception.php'; require 'vendor/PHPMailer/src/PHPMailer.php'; require 'vendor/PHPMailer/src/SMTP.php'; } elseif (file_exists('../../vendor/PHPMailer/src/Exception.php')) { require '../../vendor/PHPMailer/src/Exception.php'; require '../../vendor/PHPMailer/src/PHPMailer.php'; require '../../vendor/PHPMailer/src/SMTP.php'; } $data = (isset($_POST['data'])) ? $_POST['data'] : ""; if (!$data){ return false; } $data = json_decode($data); switch ($data->command){ case 'modal':{ echo modal($data->idPlan); break; }; case 'rozesliPlan':{ return rozesliPlan($data, $conn); break; } } function pripravMail(){ $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Mailer = "smtp"; $mail->setLanguage('cs'); $mail->CharSet = PHPMailer::CHARSET_UTF8; $mail->SMTPDebug = 0; $mail->SMTPAuth = TRUE; $mail->SMTPSecure = "tls"; $mail->Port = 587; $mail->Host = "wes1-smtp.wedos.net"; $mail->Username = "mailer@zsrepubliky.cz"; $mail->Password = "Mail*er*2022"; $mail->SetFrom("mailer@zsrepubliky.cz", "Mailer zsrepubliky.cz"); $mail->isHTML(TRUE); return $mail; } function ucitele(){ $dbpdo = new DBPDO(); $sql = "SELECT `id`, `prijmeni`, `jmeno`, `email` FROM `users` WHERE `aktivni` = '1' ORDER BY `prijmeni`, `jmeno`"; $ucitele = $dbpdo->fetchAll($sql); $html = <<<HTML <table class="table table-striped table-sm"> HTML; forEach($ucitele as $ucitel){ $html .= <<<HTML <tr> <td style="width: 4rem;" class="text-center"> <input class="" type="checkbox" id="email-cb-{$ucitel->id}" checked> </td> <td><label for="email-cb-{$ucitel->id}">{$ucitel->prijmeni} {$ucitel->jmeno}</label></td> <td>{$ucitel->email}</td> </tr> HTML; } $html .= <<<HTML </table> <hr> HTML; return $html; } function byloPoslano($idPlan){ $result = mysqli_query($GLOBALS["conn"], "SELECT `poslano` FROM `pl_poslano` WHERE `idplan` = $idPlan order by `poslano` desc"); $html = ""; if ($row = mysqli_fetch_object($result)){ $html .= <<<HTML <h5>Již posláno</h5> <table class="table table-sm table-bordered"> HTML; do { $html .= <<<HTML <tr > <td>{$row->poslano}</td> </tr> HTML; } while ($row = mysqli_fetch_object($result)); $html .= <<<HTML </table> <hr> HTML; } return $html; } function modal($idPlan){ $ucitele = ucitele(); $byloPoslano = byloPoslano($idPlan); $html = <<<HTML <div class="modal fade" id="email-dialog" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered modal-lg modal-dialog-scrollable"> <div class="modal-content rounded-0"> <div class="modal-header text-primary rounded-0"> <h5 class="modal-title" id="staticBackdropLabel">Poslat plány emailem</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body border-top border-primary" id="detailData" > $byloPoslano <div class="mb-4">Seznam příjemců lze editovat v seznamu učitelů v agendě.</div> $ucitele </div> <div class="card-footer rounded-0 border-top border-primary"> <div class="d-flex my-2"> <button class="btn btn-outline-primary btn-sm rounded-0 mr-2" onclick="emailHromadneOznac('1')">Vyber všechny</button> <button class="btn btn-outline-primary btn-sm rounded-0 " onclick="emailHromadneOznac('0')">Odoznač všechny</button> <div id="alertOdesilam" class="alert alert-success rounded-0 ml-auto mr-2 d-none mb-0">Odesílám emaily ...</div> <button id="btnRozesliPlany" class="btn btn-primary rounded-0 ml-auto" onclick="rozesliPlan($idPlan)">Rozešli plán</button> </div> </div> </div> </div> </div> HTML; return $html; } function rozesliPlan($data, $conn){ $mail = pripravMail(); $result = mysqli_query($GLOBALS["conn"], "SELECT count(id) as pocet FROM `pl_poslano` WHERE idplan = $data->idPlan"); // if ($result){ // $pocetPoslani = mysqli_fetch_object($result)->pocet; // } else { // $pocetPoslani = 0; // } // $mail->Subject = 'PLÁN školy na období '.$data->termin.(($pocetPoslani) ? " (verze ".($pocetPoslani+1).")" : ""); $mail->Subject = 'PLÁN školy na období '; $mail->Body = $data->plan; $mail->AltBody = strip_tags($mail->Body); $mail->ClearAttachments(); $targetDir = "../../ftp/plany/"; mysqli_query($GLOBALS["conn"], "INSERT INTO `pl_poslano`(`idplan`) VALUES ($data->idPlan)"); $dbpdo = new DBPDO(); $sql = "SELECT `pl_attach`.`id`, `origname`, `ext`, `popis` FROM `pl_plany` LEFT JOIN `pl_tydny` on `pl_plany`.`id`=`pl_tydny`.`idplan` left join `pl_attach` on `pl_attach`.`idtyden`=`pl_tydny`.`id` WHERE `pl_plany`.`id` = $data->idPlan"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_object($result)) { $attachSoubor = $targetDir.$row->origname.'_'.$row->id.'.'.$row->ext; // $mail->AddAttachment($attachSoubor, $row->origname.'.'.$row->ext); $popis = ($row->popis) ? $row->popis : $row->origname.'.'.$row->ext; $mail->AddAttachment($attachSoubor, $popis); } $sql = "SELECT `email` FROM `users` WHERE `aktivni` = '1' and `email` > '' and `id` in ($data->kodyStr) ORDER BY `prijmeni`, `jmeno`"; $ucitele = $dbpdo->fetchAll($sql); forEach($ucitele as $ucitel){ try { $mail->clearAllRecipients(); $mail->addAddress($ucitel->email); // $mail->addAddress('stasiv@seznam.cz'); // $mail->addAddress('dvorak.primetice@seznam.cz'); // $mail->addAddress('stasiv@zsrepubliky.cz'); // $mail->addAddress('dvorak@gymzn.cz'); $mail->send(); } catch (Exception $e) { } catch (\Exception $e) { } } }