Current Path : /data/web/virtuals/51568/virtual/www/subdom/agenda/php/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/agenda/php/Tridy.php |
<?php //session_start(); if (!$_SESSION["account"]){ header("location:../login.php"); } require_once("DB.php"); class Tridy{ private $db; public function __construct(){ $this->db = new DB(); } public function tridy() { $sql = "SELECT `id`, `rok` FROM `jak_roky` WHERE aktualni_th = '1'"; $rok = ($result = $this->db->fetchOne($sql)) ? $result->rok : "???"; $idaktualni = $result->id; $html = <<<HTML <div class="d-flex"> <h4 class="border border-secondary mt-2 p-2 me-3 w-100">Třídy</h4> <button type="button" style="min-width: 170px;" class="btn btn-outline-primary my-2 ms-auto rounded-0 shadow" onclick="dlgRok('tridy')">Rok: $rok</button> </div> <div class="d-flex"><small class="ms-auto" style="position:relative; top:-7px">Je aktuální i pro učitele</small></div> <div class="d-flex"> <button class="btn btn-outline-secondary rounded-0" onclick="kopirujTridy($idaktualni)">Zkopíruj třídy z loňska</button> </div> <div class="cara w-100 mt-2"></div> <div class="scroll-container-vysoky"> <table id="table-ucitele" class="table table-sm"> <thead> <tr> <th>třída</th> <th>třídní</th> <th class="width50">edit</th> </tr> </thead> <tbody> HTML; $data = $this->db->fetchAll('SELECT `tridy` .`id`, `nazev`, `iducitel`, `users`.`prijmeni`, `users`.`jmeno` FROM `tridy` LEFT JOIN `users` on `users`.`id`=`tridy`.`iducitel` WHERE `idroky` = :id ORDER BY `nazev`', $idaktualni); foreach($data as $trida){ $html .= <<<HTML <tr id="trida-radek-$trida->id"> <td>$trida->nazev</td> <td id="tridni-{$trida->id}">$trida->prijmeni $trida->jmeno</td> <td class="text-center pointer" onclick="tridaEdituj($trida->id)"><i class="fas fa-edit text-primary"></i></td> </tr> HTML; } $html .= <<<HTML </tr> </tbody> </table> </div> HTML; return $html; } public function roky() { $result = $this->db->fetchAll("SELECT `id`, `rok`, `aktualni_th` FROM `jak_roky` order by `rok`desc"); $html = ""; forEach($result as $rok){ $checked = (trim($rok->aktualni_th) == '1') ? "checked" : ""; $oznaceni = $rok->rok; $html .= <<<HTML <tr> <td><label for="rok-nastav{$rok->id}">$oznaceni</label></td> <td style="text-align: center;"><input id="rok-nastav{$rok->id}" name="rok-nastav" class="form-check-input" type="radio" onclick="nastavRok($rok->id)" $checked></td> </tr> HTML; } return $html; } public function dlgRok($caller){ $roky = $this->roky(); $html = <<<HTML <div class="modal fade rounded-0" id="nastav-rok-dialog" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true" data-caller="{$caller}"> <div class="modal-dialog rounded-0 modal-dialog-scrollable"> <div class="modal-content"> <div class="modal-header text-primary rounded-0"> <h5 class="modal-title" id="dlg-head">Nastavení aktuálního roku</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body rounded-0"> <div id="roky-seznam" class="m-0 p-0"> <table class="table table-striped"> <thead> <tr> <td>rok</td> <td style="width: 80px;">aktuální</td> </tr> <thead> <tbody id="roky-body"> $roky </tbody> </table> <div class="d-flex "> <button type="button" class="btn btn-outline-primary rounded-0 " onclick=dlgRokNovy()>Nový rok</button> <button type="button" class="btn btn-primary rounded-0 ms-auto" data-bs-dismiss="modal" >Zavřít</button> </div> </div> <div id="dlg-novy-rok" class="d-none"> <div class="d-flex flex-row "> <div class="form-group me-2"> <label for="">Rok</label> <input type="text" id="novy-rok" name="novy-rok" class="form-control me-2 rounded-0" value="" disabled> </div> <div class="form-group me-2"> <label for="">Od data</label> <input type="date" id="oddata" name="oddata" class="form-control me-2 rounded-0" value="" disabled> </div> <div class="form-group"> <label for="">Do data</label> <input type="date" id="dodata" name="dodata" class="form-control rounded-0" value="" disabled> </div> </div> <div class="d-flex mt-3"> <button class="btn btn-success rounded-0 ms-auto" onclick="novyRokUloz()">Založ rok</button> <button class="btn btn-outline-secondary rounded-0 ms-2" onclick="novyRokStorno()">Storno</button> </div> </div> </div> </div> </div> <script> $('#nastav-rok-dialog').on('hidden.bs.modal', function (e) { const caller = $(this).data('caller'); switch (caller){ case 'tridy': tridy(); break; case 'hodiny': tridyHodiny(0); break; } }) </script> HTML; return $html; } public function maxRok() { $maxRok = $this->db->fetchOne("SELECT MAX(`rok`) as maxRok FROM `jak_roky`")->maxRok; list($prvni, $druhy) = explode('/', $maxRok); $prvni++; $druhy++; return json_encode(['rok' => $prvni.'/'.$druhy, 'oddata' => $prvni . '-09-01', 'dodata' => $druhy . '-06-30']); } public function novyRokUloz($data) { $this->db->query('INSERT INTO `jak_roky` (`rok`, `oddata`, `dodata`, `aktualni_th`) VALUES (:rok, :oddata, :dodata, :aktualni)', $data->rok, $data->oddata, $data->dodata, '0'); return $this->roky(); } public function nastavRok($id) { $this->db->query("UPDATE `jak_roky` SET `aktualni_th`='0'"); $this->db->query("UPDATE `jak_roky` SET `aktualni_th`='1' WHERE `id`=:id", $id); } private function seznamUcitelu($idtridy, $idtridniho){ $ucitele = $this->db->fetchAll("SELECT `id`, `prijmeni`, `jmeno` FROM `users` WHERE `id`<>59 ORDER BY `prijmeni`, `jmeno`"); $html = <<<HTML <div class="d-flex mb-2 "> <select class="form-control rounded-0 mb-2" name="tridni-select" id="tridni-select" onchange="zapisUciteleKeTride($idtridy)"> <option value="" selected disabled hidden>... zvol třídního ...</option> HTML; forEach($ucitele as $ucitel){ $selected = ($ucitel->id === $idtridniho) ? "selected" : ""; $html .= <<<HTML <option value="$ucitel->id" $selected >$ucitel->prijmeni $ucitel->jmeno</option> </div> HTML; } $html .= <<<HTML </select> </div> HTML; return $html; } public function tridaEdituj($idtridy) { $trida = $this->db->fetchOne("SELECT `nazev`, `iducitel` FROM `tridy` WHERE `id`=:id", $idtridy); $seznamUcitelu = $this->seznamUcitelu($idtridy, $trida->iducitel); $html = <<<HTML <div class="card rounded-0 shadow mr-2"> <div class="card-header bg-primary text-white rounded-0 h5">Informace o třídě</div> <div id="card-trida" class="card-body"> <div class="form-group row"> <label for="datum-edit" class="col-auto col-form-label">Třída:</label> <div class="col-auto"> <input type="text" class="form-control rounded-0" disabled value="$trida->nazev"> </div> <label for="tridni-edit" class="col-auto col-form-label">Třídní:</label> <div class="col-auto"> $seznamUcitelu </div> </div> <div class="d-flex border-top pt-2"> <div class="small">Změna třídního učitele se automaticky ukládá.</div> </div> </div> </div> HTML; return $html; } public function kopirujTridy($id) { $result = new \stdClass(); $pocet = $this->db->fetchOne("SELECT count(`id`) as 'pocet' FROM `tridy` WHERE `tridy`.`idroky`=:idroky", $id)->pocet; if ($pocet > 0) { $result->result = false; $result->msg = 'Pro tento rok jsou již třídy zavedeny.'; return json_encode($result); } $lastid = $this->db->fetchOne('select max(id) as lastid from `tridy` where `tridy`.`id`<:id', $id)->lastid; if ($lastid<1) { $result->result = false; $result->msg = 'Neexistuje rok, který by předcházel aktuálně nastavenému.'; return json_encode($result); } $tridy = $this->db->fetchAll('SELECT `nazev`, `iducitel` FROM `tridy` WHERE `idroky` = :idroky ORDER BY `nazev`', $lastid); if (!$tridy) { $result->result = false; $result->msg = 'Ani v předcházejícím roce nejsou zavedeny třídy.'; return json_encode($result); } else { $sql = "INSERT INTO `tridy`(`idroky`, `nazev`, `iducitel`) VALUES (:idroky, :nazev, :iducitel)"; $this->db->query($sql, $id, '1.A', 0); $this->db->query($sql, $id, '1.B', 0); $this->db->query($sql, $id, '6.A', 0); $this->db->query($sql, $id, '6.B', 0); $this->db->query($sql, $id, '6.C', 0); foreach($tridy as $trida) { list($rocnik, $pismeno) = explode('.', $trida->nazev); if (($rocnik < 9) && ($rocnik != '5')) { $rocnik++; $this->db->query($sql, $id, $rocnik . '.' . $pismeno, $trida->iducitel); } } $result->result = true; $result->tridy = $this->tridy(); return json_encode($result); } } public function zapisUciteleKeTride($data) { $this->db->query('UPDATE `tridy` SET `iducitel`= :iducitel WHERE `id` = :id', $data->idtridniho, $data->idtridy); return $this->db->fetchOne("SELECT concat(`prijmeni`, ' ', `jmeno`) as 'tridni' FROM `users` WHERE `id`= :id", $data->idtridniho)->tridni; } private function truncate($zkratit, $delka = 50, $append = "…") { if (mb_strlen($zkratit) > $delka) { $zkratit = mb_strimwidth($zkratit, 0, $delka); $pos = mb_strripos($zkratit, ' '); return mb_strimwidth($zkratit, 0, $pos) . $append; } else { return $zkratit; } } public function tridyHodiny($idtridy) { if ($idtridy > 0) { $koho = $this->db->fetchOne("SELECT `nazev` from `tridy` WHERE `id` = :id", $idtridy)->nazev; } else { $koho = ""; } $rokth = $this->db->fetchOne("SELECT `id`, `rok` FROM `jak_roky` WHERE `aktualni_th` = '1'"); $tridy = $this->db->fetchAll("SELECT `tridy`.`id`, `nazev`, `prijmeni` FROM `tridy` LEFT JOIN `users` ON `tridy`.`iducitel` = `users`.`id` WHERE `tridy`.`idroky`=:idrok ORDER BY `nazev`", $rokth->id); $selected = ($idtridy == '0') ? "selected" : ""; $selectTridu = <<<HTML <div class="row"> <label class="col-auto col-form-label" for="filtr-tridy">Filtr na třídy:</label> <div class="col-auto"> <select id="filtr-trida-hodiny" class="form-select rounded-0" onchange="filtrTridaHodiny()"> <option value="0" {$selected}>všechny třídy</option> HTML; foreach($tridy as $trida) { $selected = ($trida->id == $idtridy) ? "selected" : ""; $selectTridu .= <<<HTML <option value="{$trida->id}" {$selected}>{$trida->nazev} - {$trida->prijmeni}</option> HTML; } $selectTridu .= <<<HTML </select> </div> </div> HTML; $sqlSeznam = "SELECT `th_hodiny`.`id`, `datum`, `obsah`, `tridy`.`nazev`, `users`.`prijmeni` FROM `th_hodiny` left join `tridy` on `tridy`.`id`=`th_hodiny`.`idtridy` left join `users` on `users`.`id`=`tridy`.`iducitel` WHERE `tridy`.`idroky`=:idroky " . (($idtridy>0) ? " and `idtridy` = :idtridy" : " or `idtridy` > :idtridy") . " ORDER BY `datum` desc, `tridy`.`nazev`"; $seznam = $this->db->fetchAll($sqlSeznam, $rokth->id, $idtridy); $html = <<<HTML <div class="d-flex"> <div class="h4 border border-dark p-2 mt-2 w-100 me-2" id="seznam-th" data-idtridy="{$idtridy}">Přehled třídnických hodin {$koho}</div> <button type="button" style="min-width: 170px;" class="btn btn-outline-primary my-2 ms-auto rounded-0 shadow" onclick="dlgRok('hodiny')">Rok: $rokth->rok</button> </div> <div class="d-flex"><small class="ms-auto" style="position:relative; top:-7px">Je aktuální i pro učitele</small></div> <div class="d-flex border-bottom border-top py-1 border-dark"> <!-- <button class="btn btn-outline-secondary rounded-0">Tisk</button> --> <div class="ms-auto"> $selectTridu </div> </div> HTML; if ($idtridy == '0'){ $tridaTridni = <<<HTML <th>třída</th> <!-- <th>třídní</th> --> HTML; } else { $tridaTridni = ""; } if ($seznam){ $html .= <<<HTML <div class="scroll-container-hodiny-nova"> <table class="table"> <thead> <tr> <th style="width: 7rem;">datum</th> $tridaTridni <th>náplň</th> <th class="width50">detail</th> <th class="width50">smaž</th> </tr> </thead> <tbody> HTML; foreach($seznam as $th) { if ($idtridy == '0'){ $tridaTridni = <<<HTML <td class="text-center">$th->nazev</td> <!-- <td>$th->prijmeni</td> --> HTML; } else { $tridaTridni = ""; } list($rok, $mesic, $den) = explode('-', $th->datum); $obsah = $this->truncate($th->obsah); $html .= <<<HTML <tr id="th-tr-{$th->id}"> <td scope="row" class="text-end">$den.$mesic.$rok</td> $tridaTridni <td>$obsah</td> <td class="text-center pointer" onclick="detailTH($th->id, true)"><i class="fas fa-edit text-primary"></i></td> <td class="text-center pointer" onclick="dotazSmazatTH($th->id)"><i class="fas fa-trash-alt text-danger"></i></td> </tr> HTML; } $html .= <<<HTML </tbody> </table> </div> HTML; } else { $html .= <<<HTML <div class="h5 mt-3">Nekonala se žádná třídnická hodina.</div> HTML; } return $html; } public function dotazSmazatTH($idTH) { $hodina = $this->db->fetchOne("SELECT `datum`, `tridy`.`nazev` FROM `th_hodiny` left join `tridy` on `tridy`.`id`=`th_hodiny`.`idtridy` left join `users` on `users`.`id`=`tridy`.`iducitel` WHERE `th_hodiny`.`id` = :id", $idTH); $datum = explode('-', $hodina->datum); $datumTh = "$datum[2].$datum[1].$datum[0]"; $html = <<<HTML <div class="modal fade rounded-0" id="dotaz-smazat-th-dialog" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> <div class="modal-dialog rounded-0 modal-dialog-scrollable"> <div class="modal-content"> <div class="modal-header text-primary rounded-0"> <h5 class="modal-title" id="dlg-head">Smazat zápis o konání TH</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body rounded-0"> <div class="alert alert-warning"> <div class="form-check"> <input class="form-check-input rounded-0" type="checkbox" value="" id="dotaz-smazat" > <label class="form-check-label ms-1" for="dotaz-smazat"> ano, chci smazat třídnickou hodinu {$hodina->nazev} ze dne {$datumTh} </label> </div> </div> <div class="d-flex mt-3"> <button id="btn-smazat-th" class="btn btn-warning rounded-0 ms-auto" disabled onclick="smazTH($idTH)">Smazat</button> <button class="btn btn-outline-secondary rounded-0 ms-2" onclick="cancelSmazatTH()">Storno</button> </div> </div> </div> </div> </div> <script> $("#dotaz-smazat").on("change", function() { const stav = $(this).is(":checked"); $("#btn-smazat-th").prop('disabled', !stav); }) </script> HTML; return $html; } public function smazTH($idTH) { $this->db->query("DELETE FROM th_hodiny WHERE id = :id", $idTH); } }