RegenArchiveView.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. // Архив Regen
  3. class RegenArchiveView extends LayoutView {
  4. protected $subjects;
  5. public function content():void { ?>
  6. <div class='text-center'>
  7. <h1>Архив отчётов</h1>
  8. <h3>Выбери дисциплину</h3>
  9. </div>
  10. <div class='card'>
  11. <div id='subjectsList'>
  12. <?php while ($subject = $this->subjects->fetchArray()) { ?>
  13. <div id='subject<?= $subject['id'] ?>' class='crud-item'>
  14. <p><?= $subject['name'] ?></p>
  15. <div class='crud-buttons'>
  16. <button onclick='document.location.href = "/regen/archive/<?=$subject['id']?>"'>Отчёты</button>
  17. <button onclick='crudUpdateShowWindow("subjects", {"Название": {type: "plain", name: "name", default: "<?=$subject['name']?>"}, "Шифр": {type: "plain", name: "code", default: "<?=$subject['code']?>"}, "Преподаватель": {type: "crudRead", name: "teacher_id", route: "teachers", default:<?=$subject['teacher_id']?>}, "ID": {type: "hidden", name: "id", default: <?=$subject['id']?>}}, "Обновление дисциплины", updateSubject)'>Изменить</button>
  18. <button onclick='crudDelete("subjects", <?= $subject['id'] ?>, "subject<?= $subject['id'] ?>")' class='danger'>Удалить</button>
  19. </div>
  20. </div>
  21. <?php } ?>
  22. </div>
  23. <button onclick='crudCreateShowWindow("subjects", {"Название": {type: "plain", name: "name"}, "Шифр": {type: "plain", name: "code"}, "Преподаватель": {type: "crudRead", name: "teacher_id", route: "teachers"}}, "Добавление дисциплины", createSubject)' class='createbutton form-control'>Добавить</button>
  24. </div>
  25. <script>
  26. function updateSubject(subject) {
  27. $("#subject"+subject.id).replaceWith(getSubject(subject));
  28. }
  29. function createSubject(subject) {
  30. const new_item = getSubject(subject);
  31. $("#subjectsList").append($(new_item));
  32. }
  33. function getSubject(subject) {
  34. return `
  35. <div id='subject`+subject.id+`' class='crud-item'>
  36. <p>`+subject.name+`</p>
  37. <div class='crud-buttons'>
  38. <button>Отчёты</button>
  39. <button onclick='crudUpdateShowWindow("subjects", {"Название": {type: "plain", name: "name", default: "`+subject.name+`"}, "Шифр": {type: "plain", name: "code", default: "`+subject.code+`"}, "Преподаватель": {type: "crudRead", name: "teacher_id", route: "teachers", default:`+subject.teacher_id+`}, "ID": {type: "hidden", name: "id", default: `+subject.id+`}}, "Обновление дисциплины", updateSubject)'>Изменить</button>
  40. <button onclick='crudDelete("subjects", `+subject.id+`, "subject`+subject.id+`")' class='danger'>Удалить</button>
  41. </div>
  42. </div>`;
  43. }
  44. </script>
  45. <?php }
  46. }