Current Path : /data/web/virtuals/51568/virtual/www/subdom/agenda/php/zapisy/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/agenda/php/zapisy/Kolega.php |
<?php //session_start(); if (!$_SESSION["account"]){ header("location:../../login.php"); } require_once ("../DB.php"); require_once ("../Mailer.php"); class Kolega { private $db; private $ucitelId; public function __construct($id){ $this->db = new DB(); $this->ucitelId = $id; } public function jednaniKolega($kterekolegy = 0){ $terekolegy0 = ($kterekolegy == 0) ? "checked " : ""; $terekolegy1 = ($kterekolegy == 1) ? "checked " : ""; $btnNoveJednani = ($kterekolegy == 0) ? '<button class="btn btn-outline-primary rounded-0 ms-auto" id="button-jednani-nove" onclick="jednaniKolegaEdituj(0)">Nový záznam o jednání</button>' : ''; $vrsek = <<<HTML <div id="divProModal"></div> <h4 class="border border-secondary mt-2 p-2">Jednání s kolegou</h4> <div id="jednani-top" class="mt-2 d-flex"> <div class="me-3 mt-2 mb-2"> <input class="form-check-input" type="radio" name="rgkterekolegy" id="kterekolegy0" value="0" $terekolegy0 onclick="jednaniKolega(0)"> <label class="form-check-label" for="kterekolegy0">já jsem zapsal/a</label> </div> <div class="mt-2"> <input class="form-check-input" type="radio" name="rgkterekolegy" id="kterekolegy1" value="1" $terekolegy1 onclick="jednaniKolega(1)"> <label class="form-check-label" for="kterekolegy1">kde jsem uveden/a</label> </div> $btnNoveJednani </div> <div class="cara w-100 mt-2"></div> HTML; if ($kterekolegy == 0){ $jednani = $this->db->fetchOne("SELECT count(`id`) as pocet FROM `kolega` WHERE `idzapsal` = :id", $this->ucitelId); $sql = "SELECT `kolega`.`id`, `users`.`prijmeni`, `users`.`jmeno`, `kolega`.`datum` FROM `kolega` LEFT JOIN `users` on `kolega`.`idkolega` = `users`.`id` WHERE `kolega`.`idzapsal` = :idzapsal order by `kolega`.`datum` desc"; } else { $jednani = $this->db->fetchOne("SELECT count(`id`) as pocet FROM `kolega` WHERE `idkolega` = :id", $this->ucitelId); $sql = "SELECT `kolega`.`id`, `users`.`prijmeni`, `users`.`jmeno`, `kolega`.`datum` FROM `kolega` LEFT JOIN `users` on `kolega`.`idzapsal` = `users`.`id` WHERE `kolega`.`idkolega` = :idkolega order by `kolega`.`datum` desc"; } if ($jednani->pocet == 0){ $html = <<<HTML $vrsek <div class="alert alert-info h5 border-0 mt-3"> Žádný záznam o jednání s kolegy. </div> HTML; return $html; } $jednaniKolega = $this->db->fetchAll($sql, $this->ucitelId); $html = <<<HTML $vrsek <div class="scroll-container-vysoky"> <table class="table mt-3"> <thead> <tr class="fw-bold"> <td>kolega</td> <td class="text-center">datum</td> <td class="width50">detail</td> </tr> </thead> HTML; forEach($jednaniKolega as $jednani){ $kolega = $jednani->prijmeni.' '.$jednani->jmeno; $ikonaDetail = $this->ikonaDetail($kterekolegy, $jednani->id); $datum = date( 'd.m.Y H:i', strtotime($jednani->datum)); $html .= <<<HTML <tr id="jednaniRadek{$jednani->id}"> <td>$kolega</td> <td class="text-center">$datum</td> $ikonaDetail </tr> HTML; } $html .= <<<HTML </table> </div> HTML; return $html; } private function ikonaDetail($kterekolegy, $jednaniId){ if ($kterekolegy == 0) { $ikonaDetail = <<<HTML <td class="text-center pointer" onclick="jednaniKolegaEdituj($jednaniId)"><i class="fas fa-edit text-primary"></i></td> HTML; } else { $ikonaDetail = <<<HTML <td class="text-center pointer" onclick="jednaniKolegaDetail($jednaniId)"><i class="fas fa-search text-primary"></i></td> HTML; } return $ikonaDetail; } private function selectKolega($idkolega){ $ucHtml = '<option value="" selected disabled hidden>... zvol učitele ...</option>'; $ucitele = $this->db->fetchAll("SELECT `id`, `prijmeni`, `jmeno` FROM `users` WHERE `users`.`aktivni` = '1' and `users`.`id`<>59 order by `prijmeni`"); // $ucitele = $this->db->fetchAll("SELECT `id`, `prijmeni`, `jmeno` FROM `users` WHERE `users`.`aktivni` = '1' order by `prijmeni`"); forEach($ucitele as $ucitel){ $selected = ($idkolega == $ucitel->id) ? " selected" : ""; $ucHtml .= <<<HTML <option value="$ucitel->id" $selected>$ucitel->prijmeni $ucitel->jmeno</option> HTML; } return $ucHtml; } public function jednaniKolegaEdituj($idjednani){ if ($idjednani < 1){ $nadpis = "Nový záznam"; $bgcolor = "bg-success"; $jednani = new stdClass(); $jednani->idkolega = 0; $jednani->datum = ''; $jednani->forma = 0; $jednani->obsah = ''; $script = ""; } else { $nadpis = "Detail jednání s kolegou"; $bgcolor = "bg-primary"; $sql = "SELECT `id`, `idkolega`, `datum`, `forma`, `obsah` FROM `kolega` WHERE id = :id"; $jednani = $this->db->fetchOne($sql, $idjednani); $script = '<script> $(":input").on("change", function() { $("#zmena").removeClass("d-none"); }); </script>'; } $kolegove = $this->selectKolega($jednani->idkolega); $forma0 = ($jednani->forma == 0) ? "checked" : ""; $forma1 = ($jednani->forma == 1) ? "checked" : ""; $forma2 = ($jednani->forma == 2) ? "checked" : ""; $forma3 = ($jednani->forma == 3) ? "checked" : ""; $html = <<<HTML <div class="card shadow"> <div class="card-header $bgcolor text-white rounded-0 "> <div class="d-flex"> <div class="h4 mt-1"> $nadpis</div> <div id="zmena" class="alert alert-danger my-0 font-weight-bold text-danger d-none ms-auto rounded-0" style="padding: 6px 12px">ZMĚNA</div> </div> </div> <div class="card-body rounded-0 "> <div class="form-group row align-items-top mb-4"> <label class="col-sm-3 col-form-label pt-0"><strong>Kolega</strong></label> <div class="col-sm-9"> <select class="form-control rounded-0" name="kolega" id="kolega"> $kolegove </select> </div> </div> <div class="form-group row mb-4"> <label class="col-sm-3 col-form-label pt-0">Forma jednání</label> <div class="col-sm-9 d-flex "> <div class="me-3"> <input class="form-check-input" type="radio" name="rgforma" id="forma0" value="0" $forma0> <label class="form-check-label" for="forma0">osobně</label> </div> <div class="me-3"> <input class="form-check-input" type="radio" name="rgforma" id="forma1" value="1" $forma1> <label class="form-check-label" for="forma1">telefonicky</label> </div> <div> <input class="form-check-input" type="radio" name="rgforma" id="forma2" value="2" $forma2> <label class="form-check-label" for="forma2">e-mailem</label> </div> <div class="ms-3"> <input class="form-check-input" type="radio" name="rgforma" id="forma3" value="3" $forma3> <label class="form-check-label" for="forma3">vzájemná hospitace</label> </div> </div> </div> <div class="form-group row mb-4"> <label class="col-sm-3 col-form-label ">Datum a čas jednání</label> <div class="col-sm-9" style="max-width: 250px"> <input type="datetime-local" class="form-control rounded-0" name="datum" id="idDatum" value="$jednani->datum"> </div> </div> <div style="padding-left: 5px; "> <label for="idobsah" class="pt-0 mt-4"><strong>Obsah jednání:</strong></label> </div> <textarea class="form-control border border-secondary rounded-0" rows="4" name="obsah" id="idobsah">$jednani->obsah</textarea> </div> <div class="card-footer rounded-0 d-flex"> <div id="jednaniMsg" class="flex-grow-1 me-2"></div> <button class="btn btn-success ms-auto rounded-0" style="max-height: 38px" onclick="jednaniKolegaUlozit($idjednani)">Uložit</button> </div> </div> $script HTML; return $html; } public function jednaniKolegaDetail($idjednani){ $forma = ['osobně', 'telefonicky', 'e-mailem', 'vzájemná hospitace']; $sql = "SELECT `datum`, `forma`, `obsah`, `users`.`prijmeni`, `users`.`jmeno` FROM `kolega` left join `users` on `users`.`id`=`kolega`.`idzapsal` WHERE `kolega`.`id` = :idjednani"; $zaznam = $this->db->fetchOne($sql, $idjednani); $kolega = $zaznam->jmeno.' '.$zaznam->prijmeni; $datum = date( 'd.m.Y H:i', strtotime($zaznam->datum)); $formaJednani = $forma[$zaznam->forma]; $obsah = nl2br($zaznam->obsah); $html = <<<HTML <div class="card shadow"> <div class="card-header bg-primary text-white rounded-0 "> <div class="d-flex"> <div class="h4 mt-1">Detail jednání s kolegou</div> </div> </div> <div class="card-body rounded-0 "> <table class="table table-bordered"> <tr> <td class="w-25">Zapsal</td> <td>$kolega</td> </tr> <tr> <td>Datum jednání</td> <td>$datum</td> </tr> <tr> <td>Forma</td> <td>$formaJednani</td> </tr> <tr> <td>Obsah</td> <td>$obsah</td> </tr> </table> </div> </div> HTML; return $html; } private function formatujDatum($datum){ list($datumR, $casR) = explode('T', $datum); return $datumR.' '.$casR; } public function jednaniKolegaUlozit($data){ $return = new stdClass(); $datumCas = $this->formatujDatum($data->datum); if ($data->idjednani < 1){ $sql = "INSERT INTO `kolega`(`idzapsal`, `idkolega`, `datum`, `forma`, `obsah`) VALUES (:idzapsal, :idkolega, :datu, :forma, :obsah)"; $this->db->query($sql, $this->ucitelId, $data->kolega, $datumCas, $data->forma, $data->obsah); $data->idjednani = $this->db->lastInsertId(); $this->poslatEmail($data->idjednani); } else { $sql = "UPDATE `kolega` SET `idkolega`=:idkolega, `datum`=:datum, `forma`=:forma, `obsah`=:obsah WHERE `id`=:id"; $this->db->query($sql, $data->kolega, $datumCas, $data->forma, $data->obsah, $data->idjednani); } $return->seznam = $this->jednaniKolega(0); $return->detail = $this->jednaniKolegaEdituj($data->idjednani); $return->idjednani = $data->idjednani; return json_encode($return); } private function emailBody($idjednani){ $sql = "SELECT `datum`, `forma`, `obsah`, `users`.`prijmeni`, `users`.`jmeno` FROM `kolega` left join `users` on `users`.`id`=`kolega`.`idzapsal` WHERE `kolega`.`id` = :idjednani"; $zaznam = $this->db->fetchOne($sql, $idjednani); $kolega = $zaznam->jmeno.' '.$zaznam->prijmeni; $datum = date( 'd.m.Y H:i', strtotime($zaznam->datum)); $obsah = nl2br($zaznam->obsah); $html = <<<HTML <div style=" max-width: 600px; margin-left: auto; margin-right: auto;"> <div style="font-size: 24px;">Záznam o jednání s kolegou</div> <table style="border: 1px solid black; border-collapse: collapse; width: 100%"> <tr> <td style="border: 1px solid black; padding: 3px 5px; width: 25%">Kolega</td> <td style="border: 1px solid black; padding: 3px 5px;">$kolega</td> </tr> <tr> <td style="border: 1px solid black; padding: 3px 5px;">Datum jednání</td> <td style="border: 1px solid black; padding: 3px 5px;">$datum</td> </tr> <tr> <td style="border: 1px solid black; padding: 3px 5px; vertical-align: top;">Obsah</td> <td style="border: 1px solid black; padding: 3px 5px;">$obsah</td> </tr> </table> </div> HTML; return $html; } private function poslatEmail($idjednani){ $poslat = new Mailer(); $poslat->mail->Subject = 'Záznam o jednání s kolegou'; $poslat->mail->Body = $this->emailBody($idjednani); $idkolega = $this->db->fetchOne("select idkolega from kolega where id = :id", $idjednani)->idkolega; $email = $this->db->fetchOne("SELECT `email` FROM `users` WHERE `id` = :id", $idkolega)->email; $poslat->mail->clearAllRecipients(); $poslat->mail->addAddress($email); // $poslat->mail->addAddress('dvorak@gymzn.cz'); $poslat->mail->send(); } /*************************** SPRÁVCE *******************************************************/ public function jednaniMeziKolegy(){ $vrsek = <<<HTML <div id="divProModal"></div> <h4 class="border border-secondary mt-2 p-2">Jednání mezi kolegy</h4> <div class="cara w-100 mt-2"></div> HTML; $jednani = $this->db->fetchOne("SELECT count(`id`) as pocet FROM `kolega`"); if ($jednani->pocet == 0){ $html = <<<HTML $vrsek <div class="alert alert-info h5 border-0 mt-3"> Žádný záznam o jednání mezi kolegy. </div> HTML; return $html; } $sql = "SELECT `kolega`.`id`, z.`prijmeni` as prijmenizapsal, z.`jmeno` as jmenozapsal, `kolega`.`datum`, k.`prijmeni` as prijmenikolega, k.`jmeno` as jmenokolega FROM `kolega` LEFT JOIN `users` as k on `kolega`.`idkolega` = k.`id` left join `users` as z on `kolega`.`idzapsal` = z.`id` order by `kolega`.`datum` desc"; $jednaniKolega = $this->db->fetchAll($sql); $html = <<<HTML $vrsek <div class="scroll-container-vysoky"> <table class="table mt-3"> <thead> <tr class="fw-bold"> <td class="text-center" style="width: 10rem;">datum</td> <td>zapsal</td> <td>kolega</td> <td class="width50">detail</td> <td class="width50">smazat</td> </tr> </thead> HTML; forEach($jednaniKolega as $jednani){ $kolega = $jednani->prijmenikolega.' '.$jednani->jmenokolega; $zapsal = $jednani->prijmenizapsal.' '.$jednani->jmenozapsal; $datum = date( 'd.m.Y H:i', strtotime($jednani->datum)); $html .= <<<HTML <tr id="kolegaRadek{$jednani->id}"> <td id="kolegaDatum{$jednani->id}" class="text-center">$datum</td> <td id="kolegaZapsal{$jednani->id}">$zapsal</td> <td>$kolega</td> <td class="text-center pointer" onclick="jednaniMeziKolegyDetail($jednani->id)"><i class="fas fa-search text-primary"></i></td> <td class="text-center pointer" onclick="jednaniMeziKolegySmazatDotaz($jednani->id)"><i class="far fa-trash-alt text-danger"></i></td> </tr> HTML; } $html .= <<<HTML </table> </div> HTML; return $html; } public function jednaniMeziKolegyDetail($idjednani){ $forma = ['osobně', 'telefonicky', 'e-mailem']; $sql = "SELECT `kolega`.`id`, z.`prijmeni` as prijmenizapsal, z.`jmeno` as jmenozapsal, `kolega`.`datum`, k.`prijmeni` as prijmenikolega, k.`jmeno` as jmenokolega, `forma`, `obsah` FROM `kolega` LEFT JOIN `users` as k on `kolega`.`idkolega` = k.`id` left join `users` as z on `kolega`.`idzapsal` = z.`id` WHERE `kolega`.`id` = :idjednani"; $zaznam = $this->db->fetchOne($sql, $idjednani); $kolega = $zaznam->prijmenikolega.' '.$zaznam->jmenokolega; $zapsal = $zaznam->prijmenizapsal.' '.$zaznam->jmenozapsal; $datum = date( 'd.m.Y H:i', strtotime($zaznam->datum)); $formaJednani = $forma[$zaznam->forma]; $obsah = nl2br($zaznam->obsah); $html = <<<HTML <div class="card shadow"> <div class="card-header bg-primary text-white rounded-0 "> <div class="d-flex"> <div class="h4 mt-1">Detail jednání s kolegou</div> </div> </div> <div class="card-body rounded-0 "> <table class="table table-bordered"> <tr> <td class="w-25">Zapsal</td> <td>$zapsal</td> </tr> <tr> <td class="w-25">Kolega</td> <td>$kolega</td> </tr> <tr> <td>Datum jednání</td> <td>$datum</td> </tr> <tr> <td>Forma</td> <td>$formaJednani</td> </tr> <tr> <td>Obsah</td> <td>$obsah</td> </tr> </table> </div> </div> HTML; return $html; } public function jednaniMeziKolegySmazatSmazat($idjednani){ $this->db->query("delete FROM `kolega` where `id` = :id", $idjednani); return $this->jednaniMeziKolegy(); } }