Current Path : /data/web/virtuals/51568/virtual/www/subdom/vypisy/php/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/vypisy/php/Vypisy.php |
<?php class Vypisy { private $db; public function __construct(){ $this->db = new DB(); } public function prihlaseni(){ $dlg = <<<HTML <div class="row justify-content-center mt-3"> <div id="dialog-login" class="card px-0 rounded-0 shadow" > <div class="card-header bg-primary text-white rounded-0">Přihlášení do evidence výpisů</div> <div class="card-body"> <div class="form-group mt-2 row"> <label for="pass">Heslo</label> <div class="input-group"> <input type="password" class="form-control rounded-0" name="password" id="password" required minlength="8" value="" > <span class="input-group-text" id="passVisible" pass-visible="0" style="cursor: pointer" onclick="passwordVisibility()"> <i class="far fa-eye"></i> </span> </div> </div> <div id="error-message" class="alert alert-danger my-2 py-1 rounded-0 d-none"></div> </div> <div class="card-footer"> <div class="d-flex"> <button type="submit" class="btn btn-primary rounded-0 ms-auto" onclick="prihlasit()">Přihlásit</button> </div> </div> </div> </div> HTML; return $dlg; } public function menu(){ if (!isset($_SESSION["account"])) { return false; } $menu = <<<HTML <nav class="navbar navbar-expand-md bg-primary navbar-dark "> <div class="container-fluid"> <button class="navbar-toggler ms-auto " type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerEditace" aria-controls="navbarTogglerEditace" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarTogglerEditace"> <div class="text-white" style="font-size: 1.5em;">EVIDENCE VÝPISŮ</div> <ul class="navbar-nav mb-2 mb-md-0 ms-auto "> <li class="nav-item" style="border-right: 1px solid white"> <a class="nav-link top-menu text-white" aria-current="page" onclick="bakalariObdobi()" href="#">Součty tříd z Bakalářů</a> </li> <li class="nav-item" style="border-right: 1px solid white"> <a class="nav-link top-menu text-white" aria-current="page" onclick="vypisy()" href="#">Výpisy</a> </li> <li class="nav-item" style="border-right: 1px solid white"> <a class="nav-link top-menu text-white" aria-current="page" onclick="importBakalari()">Import žáků z Bakalářů</a> </li> <li class="nav-item" style="border-right: 1px solid white"> <a class="nav-link top-menu text-white" aria-current="page" onclick="logout()" href="#">Odhlásit</a> </li> </ul> </div> </div> </nav> <div id="div-editace" class="row"> <div id="div-table" class="col-12 col-lg-4"> </div> <div id="div-dialog" class="col-12 col-lg-8 mt-2"></div> </div> <div id="div-modal"></div> HTML; return $menu; } public function vypisyPolozky(){ $sql = "SELECT `vypisy`.`id`, `oznaceni`, `vlozeno`, count(`vypisy_polozky`.`idvypis`) as polozek FROM `vypisy` left join `vypisy_polozky` on `vypisy_polozky`.`idvypis` = `vypisy`.`id` group by `vypisy`.`id` order by `vlozeno` desc limit 100"; $vypisy = $this->db->fetchAll($sql); $html = <<<HTML <div class="scroll-container-vysoky"> <table class="table mt-0"> <thead> <tr class="fw-bold alert alert-info"> <td>označení</td> <td class="text-right">vloženo</td> <td class="text-right">položek</td> <td class="width50">smaž</td> <td class="width50">detail</td> <td class="width50">tisk </td> </tr> </thead> <tr id="dotaz-delete-vypis" class="d-none" data-idvypis="0"> <td colspan="6" class="p-1"> <div class="alert alert-danger rounded-0 p-1 d-flex"> <div id="dotaz-delete-text" class="m-2"></div> <button class="btn btn-primary rounded-0 ms-auto me-2" onclick="vypisNesmaz()">Nemazat</button> <button class="btn btn-danger rounded-0" onclick="vypisSmaz()">Smazat</button> </div> </td> </tr> HTML; forEach($vypisy as $vypis){ if ($vypis->id > 0){ $html .= <<<HTML <tr id="tr-vypis{$vypis->id}"> <td>$vypis->oznaceni</td> <td>$vypis->vlozeno</td> <td class="text-center" >$vypis->polozek</td> <td class="text-center pointer" onclick="vypisSmazDotaz('$vypis->id', '$vypis->oznaceni')"><i class="fas fa-trash text-danger"></i></td> <td class="text-center pointer" onclick="vypisDetail($vypis->id)"><i class="fas fa-search-plus text-primary"></i></td> <td class="text-center pointer" onclick="vypisTisk($vypis->id)"><i class="fas fa-print"></i></td> </tr> HTML; } } $html .= <<<HTML </table> </div> HTML; return $html; } public function vypisy(){ $polozky = $this->vypisyPolozky(); $vrsek = <<<VRCH <div id="vypisy-top" class="mt-2 d-flex"> <!--button class="btn btn-outline-primary rounded-0 " id="button-soucty" onclick="souctyObdobiForma()">Součty za období</!--button--> <button class="btn btn-outline-primary rounded-0 ms-auto" id="button-jednani-nove" onclick="vypisNovy()">Nový výpis</button> </div> <div class="cara w-100 mt-2"></div> VRCH; return $vrsek.$polozky; } public function vypisNovy(){ $html = <<<HTML <script src="../../js/jquery.csv.min.js"></script> <div class="card m-2 rounded-0"> <div class="card-header h4 bg-white border border-dark text-dark rounded-0">Natažení nového výpisu</div> <div class="card-body rounded-0"> <form id="formSelectData" action="" method="POST" enctype="multipart/form-data"> <div id="import-instrukce" class="p-2 mb-2 primary-light"> <div class="form-group"> <small>Vyber CSV soubor s výpisem: </small> <input type="file" accept=".csv" class="form-control rounded-0" name="vypisCSV" id="vypisCSV" onchange="ukazTlacitko()"> </div> <div id="rowBtnSubmit" class="row d-none"> <div class="col-8"> <button id="btnSubmit" class="btn btn-primary mt-3 mb-2 rounded-0" type="submit" onclick="nactiVypis()">Načti výpis do databáze </button> </div> <div class="col-4 text-right pt-4" id="idPocetCSV"> </div> </div> </form> </div> </div> HTML; return $html; } public function vypisDetail($idvypis){ $oznaceni = $this->db->fetchOne("SELECT `oznaceni` from `vypisy` where `id` = :id", $idvypis)->oznaceni; $sql = "SELECT `vypisy_polozky`.`id`, `protiucet`, `nazev`, `castka`, `VS`, `SS` , `zaci`.`zak`, `zaci`.`trida`, `zaci`.`id` as idzak, `av1` FROM `vypisy_polozky` left join `zaci` on `zaci`.`rodnecislo`=`vypisy_polozky`.`VS` WHERE `vypisy_polozky`.`idvypis` = :idvypis order by `zaci`.`trida`, `zaci`.`zak`"; $polozky = $this->db->fetchAll($sql, $idvypis); $html = <<<HTML <div id="vypisy-top" class="d-flex"> <h4>$oznaceni</h4> </div> <div class="cara w-100 mt-2"></div> <div class="scroll-container-vysoky pe-4"> <table class="table "> <thead> <tr class="fw-bold alert alert-info" > <td></td> <td>žák</td> <td>třída</td> <td>VS</td> <td class="text-end">protiúčet</td> <td class="text-center">SS</td> <td class="text-center">částka</td> <td>edit</td> </tr> </thead> HTML; forEach($polozky as $polozka){ $castka = number_format($polozka->castka, 2, ',', ' '); $editaZak = ($polozka->idzak) ? '<td></td>' : '<td id="zak-edit'.$polozka->id.'" class="text-center pointer" onclick="polozkaNastavZaka(\''.$polozka->id.'\')"><i class="fas fa-sync text-success"></i></td>'; $html .= <<<HTML <tr id="tr-zak{$polozka->id}" data-vs="$polozka->VS"> $editaZak <td colspan="3" id="zak-select{$polozka->id}" class="d-none shadow border border-secondary p-1"></td> <td id="zak-zak{$polozka->id}">$polozka->zak</td> <td id="zak-trida{$polozka->id}">$polozka->trida</td> <td>$polozka->VS</td> <td class="text-end">$polozka->protiucet</td> <td class="text-center">$polozka->SS</td> <td class="text-end">$castka</td> <td class="text-center" onclick="polozkaDetailModal($polozka->id)"><i class="fas fa-edit text-primary"></i></td> </tr> HTML; } $html .= <<<HTML </table> </div> HTML; return $html; } function naplnSelect($vs){ $selecty = $this->db->fetchAll("SELECT `id`, `trida`, `zak` FROM `zaci` WHERE `rc6` = :rc6", $vs); $html = ""; forEach($selecty as $select){ $zak = $select->zak.' ('.$select->trida.')'; $html .= <<<HTML <option value="$select->id">$zak</option> HTML; } return $html; } public function zakSelectUloz($data){ $vs = $this->db->fetchOne("select `rodnecislo` from `zaci` where `id` = :id", $data->idzak)->rodnecislo; $idvypis = $this->db->fetchOne("select `idvypis` from `vypisy_polozky` where `id`=:id", $data->idpolozka)->idvypis; $this->db->query("UPDATE `vypisy_polozky` SET `VS`=:vs WHERE `id`=:id", $vs, $data->idpolozka); return $this->vypisDetail($idvypis); } public function vypisSmaz($idvypis){ $this->db->query("delete from vypisy where id = :id", $idvypis); return $this->vypisy(); } public function polozkaDetailModal($id){ $sql = "SELECT `vypisy_polozky`.`id`, `protiucet`, `nazev`, `castka`, `VS`, `SS` , `zaci`.`zak`, `zaci`.`trida`, `zaci`.`id` as idzak, `av1` FROM `vypisy_polozky` left join `zaci` on `zaci`.`rodnecislo`=`vypisy_polozky`.`VS` WHERE `vypisy_polozky`.`id` = :id"; $polozka = $this->db->fetchOne($sql, $id); $zak = ($polozka->zak) ? $polozka->zak.' - '.$polozka->trida : ""; $html = <<<HTML <div class="modal fade rounded-0" id="polozka-detail-modal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true" data-idradekvypis="{$id}"> <div class="modal-dialog modal-lg rounded-0"> <div class="modal-content"> <div class="modal-header bg-success text-white rounded-0"> <h5 class="modal-title" id="staticBackdropLabel">Detail položky výpisu</h5> <button id="modal-btn-close" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" ></button> </div> <div class="modal-body rounded-0 p-4" style="background-color: rgba(21,115,71, 0.07)"> <div class="form-group row align-items-center mb-2"> <label for="datum-edit" class=" col-3">Žák:</label> <div class="col-9"> <input type="text" class="form-control rounded-0" name="zak-edit" id="zak-edit" disabled value="{$zak}" data-idzaka="0"> </div> </div> <div class="form-group row align-items-center mb-2"> <label for="datum-edit" class=" col-3">Protiúčet:</label> <div class="col-4"> <input type="text" class="form-control rounded-0" name="protiucet-edit" id="protiucet-edit" disabled value="{$polozka->protiucet}" > </div> <label for="datum-edit" class=" col-2">Částka:</label> <div class="col-3"> <input type="text" class="form-control rounded-0" name="castka-edit" id="castka-edit" disabled value="{$polozka->castka}" > </div> </div> <div class="form-group row align-items-center mb-2"> <label for="datum-edit" class=" col-3">VS:</label> <div class="col-4"> <input type="text" class="form-control rounded-0 " name="vs-edit" disabled id="vs-edit" value="{$polozka->VS}" > </div> <label for="datum-edit" class=" col-2">SS:</label> <div class="col-3"> <input type="text" class="form-control rounded-0 editable" name="ss-edit" id="ss-edit" value="{$polozka->SS}" > </div> </div> <div class="form-group row align-items-center mb-2"> <label for="datum-edit" class=" col-3">Jméno protiúčtu:</label> <div class="col-9"> <input type="text" class="form-control rounded-0" name="nazev-edit" id="nazev-edit" disabled value="{$polozka->nazev}" > </div> </div> <div class="form-group row align-items-center mb-0"> <label for="datum-edit" class=" col-3">Avízo:</label> <div class="col-9"> <input type="text" class="form-control rounded-0" name="avizo-edit" id="avizo-edit" disabled value="{$polozka->av1}" > </div> </div> <div class="d-flex mt-4" > <button id="modal-btn-ulozit" type="button" class="btn btn-success shadow ms-auto" onclick="ulozAZavri()">Ulož a zavři</button> </div> </div> <div class="modal-body rounded-0 p-4 border-top" > <div class="form-group row align-items-center mb-3"> <label for="datum-edit" class=" col-3">Hledaný text:</label> <div class="col-9"> <input type="text" class="form-control rounded-0 editable" name="hledej-edit" id="hledej-edit" value="" > </div> </div> <div class="form-group row align-items-center mb-3"> <label class=" col-3">Prohledávané pole:</label> <div class="col-2"> <input type="radio" class="form-check-input" name="pole-select" id="pole-select-zak" value="zak"> <label for="pole-select-zak">jméno žáka</label> </div> <div class="col-2"> <input type="radio" class="form-check-input" name="pole-select" id="pole-select-rodnecislo" value="rodnecislo" checked> <label for="pole-select-rodnecislo">rodné číslo</label> </div> <div class="col-2"> <input type="radio" class="form-check-input" name="pole-select" id="pole-select-matka" value="matka"> <label for="pole-select-matka">jméno ZZ 1</label> </div> <div class="col-2"> <input type="radio" class="form-check-input" name="pole-select" id="pole-select-otec" value="otec"> <label for="pole-select-otec">jméno ZZ 2</label> </div> </div> <div class="form-group row align-items-center mb-2"> <label class=" col-3">Hledat jak:</label> <div class="col-2"> <input type="radio" class="form-check-input" name="kdehledat" id="hldetakdezacatek" value="0"> <label for="hldetakdezacatek">od začátku</label> </div> <div class="col-2"> <input type="radio" class="form-check-input" name="kdehledat" id="hldetakdevsude" value="1" checked> <label for="hldetakdevsude">kdekoliv</label> </div> <div class="col-2"> <input type="radio" class="form-check-input" name="kdehledat" id="hldetakdekonec" value="2"> <label for="hldetakdekonec">na konci</label> </div> <div class="col-3 text-end"> <button class="btn btn-outline-success shadow" onclick="hledej()">Hledej</button> </div> </div> <div id="hledej-err" class="alert alert-danger rounded-0 mb-0 py-1 d-none">zadej hledaný text</div> <div id="nalezeno" class="d-none"></div> </div> </div> </div> </div> </div> HTML; return $html; } public function hledej($data){ switch ($data->kde){ case '0': $zacatek = ""; $konec = "%"; break; case '1': $zacatek = "%"; $konec = "%"; break; case '2': $zacatek = "%"; $konec = ""; break; } $sql = "select * from `zaci` where ".$data->pole." like '".$zacatek.$data->retezec.$konec."' order by `zak`"; $nalezeno = $this->db->fetchAll($sql); $html = <<<HTML <hr> <div class="scroll-container-nalezeno mt-3"> <table class="table table-small table-striped"> HTML; $pocet = 0; forEach($nalezeno as $radek) { $pocet++; $html .= <<<HTML <tr> <td><input type="radio" name="dosadZaka" class="form-check-input" value="$radek->id" id="dosadZaka$radek->id"></td> <td><label id="oznacen-zak$radek->id" for="dosadZaka$radek->id">$radek->zak</label></td> <td><label for="dosadZaka$radek->id">$radek->trida</label></td> <td><label id="oznacen-rc$radek->id" for="dosadZaka$radek->id">$radek->rodnecislo</label></td> <td><label for="dosadZaka$radek->id">$radek->matka</label></td> <td><label for="dosadZaka$radek->id">$radek->otec</label></td> HTML; } $html .= <<<HTML </table> </div> HTML; if ($pocet){ $html .= <<<HTML <hr> <div class="d-flex"> <div id="hledej-oznac-err" class="alert alert-danger flex-grow-1 me-4 rounded-0 mb-0 py-1 d-none">nikdo není označen</div> <button class="btn btn-success ms-auto shadow" onclick="dosadVybraneho()">Dosaď vybraného</button> </div> HTML; } $return = new stdClass(); $return->pocet = $pocet; $return->html = $html; return json_encode($return); } public function ulozRadekVypis($data){ $idvypis = $this->db->fetchOne("select `idvypis` from `vypisy_polozky` where `id` = :id", $data->idradekvypis)->idvypis; $this->db->query("UPDATE `vypisy_polozky` SET `VS`= :VS,`SS`= :SS WHERE `id` = :id", $data->VS, $data->SS, $data->idradekvypis); return $this->vypisDetail($idvypis); } private function formatujDatum($datum){ [$den, $mesic, $rok] = explode('.', $datum); return trim($rok).'-'.trim($mesic).'-'.(($den<10) ? "0" : "").trim($den); } public function souctyObdobiForma($prvni, $posledni) { $prvni = $this->formatujDatum($prvni); $posledni = $this->formatujDatum($posledni); $html = <<<HTML <div class="card m-2 rounded-0"> <div class="card-header h4 bg-white border border-dark text-dark rounded-0">Součty položek za období</div> <div class="card-body rounded-0"> <div class="row"> <div class="col-4 mt-1"> <label for="" class="me-2">Od data:</label> <input type="date" name="oddataSoucty" id="oddataSoucty" style="min-width: 11rem;" value="$prvni"> </div> <div class="col-4 mt-1"> <label for="" class="me-2">Do data:</label> <input type="date" name="dodataSoucty" id="dodataSoucty" style="min-width: 11rem;" value="$posledni"> </div> <div class="col-4 text-end"> <button class="btn btn-primary shadow" onclick="souctyObdobiSpocitej()">Spočítej</button> </div> </div> <div id="souctyData" class="d-none"> <hr> <div class="row mt-3 p-2 gap-1"> <div class="col-2 bg-light p-2 border border-secondary"> Připsáno: </div> <div id="pripsano" class="col-3 me-5 p-2 text-end text-primary border border-primary fw-bold"> asd </div> <div class="col-2 bg-light p-2 border border-secondary"> Odepsáno: </div> <div id="odepsano" class="col-3 p-2 text-end text-danger border border-danger fw-bold"> sad </div> </div> </div> </div> </div> HTML; return $html; } public function souctyObdobiSpocitej($odData, $doData) { $soucty = new stdClass(); $sql = "SELECT sum(castka) as plus FROM `vypisy_polozky` left join `vypisy` on `vypisy`.`id`=`vypisy_polozky`.`idvypis` WHERE `vypisy`.`oznaceni`>=:prvniDen and `vypisy`.`oznaceni`<=:posledniDen and `vypisy_polozky`.`castka` > 0"; $soucty->plus = $this->db->fetchOne($sql, $odData, $doData)->plus; $sql = "SELECT sum(castka) as minus FROM `vypisy_polozky` left join `vypisy` on `vypisy`.`id`=`vypisy_polozky`.`idvypis` WHERE `vypisy`.`oznaceni`>=:prvniDen and `vypisy`.`oznaceni`<=:posledniDen and `vypisy_polozky`.`castka` < 0"; $soucty->minus = $this->db->fetchOne($sql, $odData, $doData)->minus; return json_encode($soucty); } }