Current Path : /data/web/virtuals/51568/virtual/www/subdom/agenda/php/zapisy/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/agenda/php/zapisy/JednaniZaznamy.php |
<?php session_start(); if (!$_SESSION["account"]){ header("location:../../login.php"); } require_once ("../DB.php"); class JednaniZaznamy { private $db; public function __construct(){ $this->db = new DB(); } public function jednaniZaznamyZaznamy($trideni){ $jakTridit = []; $btn = []; $jakTridit[0] = "`zak_prijmeni`, `zak_jmeno`, `jednani`.`datum` desc"; $jakTridit[1] = "`jednani`.`datum` desc"; $jakTridit[2] = "`users`.`prijmeni`, `users`.`jmeno`, `jednani`.`datum` desc"; for($i = 0; $i<3; $i++){ $btn[$i] = "btn-outline-secondary"; } $btn[$trideni] = "btn-secondary"; $sql = "SELECT `jednani`.`id` as idjednani, `jednani`.`datum`, `zapsalid`, `zak_jmeno`, `zak_prijmeni`, `zak_trida`, `users`.`prijmeni` as ucprijmeni, `users`.`jmeno` as ucjmeno FROM `jednani` left join `users` on `users`.`id`=`jednani`.`zapsalid` WHERE 1 order by {$jakTridit[$trideni]}"; $zaznamy = $this->db->fetchAll($sql); $html = <<<HTML <table class="table mt-1"> <thead> <tr class="fw-bold"> <td><button class="btn {$btn[0]} rounded-0 fw-bold" onclick="jednaniZaznamyTridit(0)">žák</button></td> <td class="text-center"><button class="btn {$btn[1]} rounded-0 fw-bold" onclick="jednaniZaznamyTridit(1)">datum</button></td> <td><button class="btn {$btn[2]} rounded-0 fw-bold" onclick="jednaniZaznamyTridit(2)">zapsal</button></td> <td class="width50 align-middle">detail</td> <td class="width50 align-middle">smaž</td> </tr> </thead> HTML; forEach($zaznamy as $zaznam){ $zak = $zaznam->zak_prijmeni.' '.$zaznam->zak_jmeno.' ('.$zaznam->zak_trida.')'; $datum = date( 'd.m.Y H:i', strtotime($zaznam->datum)); $zapsal = $zaznam->ucprijmeni.' '.substr($zaznam->ucjmeno, 0, 1).'.'; $html .= <<<HTML <tr id="jednaniRadek{$zaznam->idjednani}"> <td id="jednaniZak{$zaznam->idjednani}">$zak</td> <td class="text-center">$datum</td> <td>$zapsal</td> <td class="text-center pointer" onclick="jednaniZaznamyDetail($zaznam->idjednani)"><i class="fas fa-edit text-primary"></i></td> <td class="text-center pointer" onclick="jednaniZaznamySmazatDotaz($zaznam->idjednani)"><i class="fas fa-trash-alt text-danger"></i></td> </tr> HTML; } $html .= <<<HTML </table> HTML; return $html; } public function jednaniZaznamy(){ $account = json_decode($_SESSION["account"]); $btnDuvody = ($account->spravce == '1') ? '<button class="btn btn-outline-primary rounded-0 me-2" id="button-zaznamy-duvody" onclick="zaznamyDuvody()">Důvody</button>' : ""; $vrsek = <<<VRCH <h4 class="border border-secondary mt-2 p-2">Deník pedagogů</h4> <div id="supliky-top" class="mt-2 d-flex"> $btnDuvody </div> <div class="cara w-100 mt-2"></div> VRCH; $sql = "SELECT count(`jednani`.`id`) as pocet FROM `jednani` WHERE 1"; $zaznamy = $this->db->fetchOne($sql); if (!$zaznamy->pocet){ $html = <<<HTML $vrsek <div class="alert alert-info h5 border-0 mt-3"> Žádný zápis z jednání. </div> HTML; return $html; } $polozky = $this->jednaniZaznamyZaznamy(1); $html = <<<HTML $vrsek <div id="id-zaznamy-table" class="scroll-container-vysoky"> $polozky </div> HTML; return $html; } private function jednaniObsah($idjednani){ $html = <<<HTML <tr> <td colspan="2" class="fw-bold">Obsah jednání</td> </tr> HTML; $duvody = $this->db->fetchAll("select `jednani_duvody`.`id` as idduvod, `jednani_duvody`.`duvod`, `jednani_dovody_zapisy`.`popis`, `jednani_dovody_zapisy`.`id` as idzapis from `jednani_duvody` left join `jednani_dovody_zapisy` on `jednani_dovody_zapisy`.`idduvod` =`jednani_duvody`.`id` and `jednani_dovody_zapisy`.`idjednani`= :idjednani where `jednani_duvody`.`aktivni` = '1' and `jednani_duvody`.`duvod` > '' order by `jednani_duvody`.`duvod`", $idjednani); forEach($duvody as $duvod){ if (trim($duvod->popis)>''){ $popis = nl2br($duvod->popis); $html .= <<<HTML <tr> <td>{$duvod->duvod}</td> <td>{$popis}</td> HTML; } } return $html; } public function jednaniZaznamyDetail($idjednani){ $sql = "SELECT `zalozeno`, `editovano`, `typjednani`, `zz_jmeno`, `zz_prijmeni`, `zak_jmeno`, `zak_prijmeni`, `zak_trida`, `jednani`.`typjednani`, `typjednani_jinak`, `forma`, `forma_jinak`, `reseni`, `jednani`.`datum`, `users`.`prijmeni` as ucprijmeni, `users`.`jmeno` as ucjmeno FROM `jednani` left join `users` on `users`.`id`=`jednani`.`zapsalid` WHERE `jednani`.`id` = :idjednani"; $zaznam = $this->db->fetchOne($sql, $idjednani); $zak = $zaznam->zak_prijmeni.' '.$zaznam->zak_jmeno.' ('.$zaznam->zak_trida.')'; $datum = date( 'd.m.Y H:i', strtotime($zaznam->datum)); $zalozeno = date( 'd.m.Y H:i', strtotime($zaznam->zalozeno)); $editovano = date( 'd.m.Y H:i', strtotime($zaznam->editovano)); $zapsal = $zaznam->ucprijmeni.' '.$zaznam->ucjmeno; $typjednani = ""; if ($zaznam->typjednani[1] == '1'){ $typjednani .= "<tr><td>Spolúčast</td><td>zákonný zástupce: {$zaznam->zz_prijmeni} {$zaznam->zz_jmeno}</td></tr>"; } if ($zaznam->typjednani[2] == '1'){ if ($typjednani){ $typjednani .= "<tr><td></td><td>{$zaznam->typjednani_jinak}</td></tr>"; } else { $typjednani .= "<tr><td>Spolúčast</td><td>{$zaznam->typjednani_jinak}</td></tr>"; } } $pocetDalsiUcastnici = $this->db->fetchOne("select count(*) as pocet from jednani_osoby where idjednani = :idjednani", $idjednani)->pocet; if ($pocetDalsiUcastnici){ $typjednani .= ($typjednani) ? "<tr><td></td><td>" : "<tr><td>Spolúčast</td><td>"; $dalsi = $this->db->fetchAll("SELECT `osoba` FROM `jednani_osoby` WHERE `idjednani` = :idjednani", $idjednani); $htmlDalsi = ""; forEach($dalsi as $osobaDalsi){ $htmlDalsi .= '<div class="m-2">'.$osobaDalsi->osoba.'</div>'; } $typjednani .= $htmlDalsi."</td></tr>"; } $forma = "<tr><td>Forma jednání</td><td>"; switch ($zaznam->forma) { case 0: $forma .= "osobně"; break; case 1: $forma .= "telefonicky"; break; case 2: $forma .= "e-mailem"; break; case 3: $forma .= $zaznam->forma_jinak; break; } $forma .= "</td></tr>"; $obsah = $this->jednaniObsah($idjednani); $html = <<<HTML <div class="card shadow"> <div class="card-header bg-primary text-white rounded-0 ">Detail položky deníku</div> <div class="card-body rounded-0 "> <table class="table table-bordered"> <tr> <td class="fw-bold w-25">Žák</td> <td>$zak</td> </tr> <tr> <td>Zapsal</td> <td>$zapsal</td> </tr> <tr> <td>Datum jednání</td> <td>$datum</td> </tr> <tr> <td>Zapsáno/editace</td> <td>{$zalozeno} / {$editovano}</td> </tr> $typjednani $forma $obsah <tr> <td class="fw-bold">Závěr (řešení)</td> <td colspan="2">{$zaznam->reseni}</td> </tr> </table> </div> </div> HTML; return $html; } public function zaznamyDuvody(){ $sql = "SELECT `id`, `duvod`, `aktivni` FROM `jednani_duvody` WHERE 1"; $duvody = $this->db->fetchAll($sql); $html = <<<HTML <div class="d-flex"> <div class="h5 pt-2">Důvody zápisů z jednání</div> <button class="btn btn-outline-primary rounded-0 ms-auto" onclick="duvodNovy()">Nový důvod</button> </div> <div id="duvod-novy" class="my-2 d-flex d-none shadow border border-secondary p-2"> <input type="text" id="duvod-novy-nazev" value="" class="flex-grow-1 me-2"> <button class="btn btn-outline-success rounded-0 me-2" onclick="duvodNovyUloz()"><i class="far fa-save"></i></button> <button class="btn btn-outline-warning rounded-0" onclick="duvodNovyCancel()"><i class="fas fa-undo"></i></button> </div> <div id="duvod-novy-error" class="my-2 w-100 alert alert-danger d-none py-1 rounded-0"></div> <div class="cara w-100 mt-2"></div> <table class="table"> <thead> <tr class="fw-bold"> <td>důvod (max 50 znaků)</td> <td class="width50">edit</td> <td class="width50">aktivni</td> </tr> </thead> HTML; forEach($duvody as $duvod){ $aktivni = (trim ($duvod->aktivni) === '1') ? '<i class="far fa-eye"></i>' : '<i class="far fa-eye-slash"></i>'; $html .= <<<HTML <tr id="duvod-radek{$duvod->id}"> <td id="duvod-duvod{$duvod->id}">$duvod->duvod</td> <td class="text-center pointer" onclick="duvodEdituj($duvod->id)"><i class="fas fa-edit text-primary"></i></td> <td id="polozka-aktivni{$duvod->id}" class="text-center pointer" onclick="duvodAktivni($duvod->id)">$aktivni</td> </tr> HTML; } $html .= <<<HTML </table> HTML; return $html; } public function duvodNovyUloz($data){ $db = new DB(); $db->query('INSERT INTO `jednani_duvody` (`duvod`, `aktivni`) VALUES (:duvod, \'1\')', htmlSpecialChars($data->duvod)); return $this->zaznamyDuvody(); } public function jednaniZaznamySmazatSmazat($idjednani){ $db = new DB(); $db->query('DELETE FROM `jednani` WHERE id = :id', $idjednani); return $this->jednaniZaznamyZaznamy(1); } }