building.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. if (getPOST("remove")) {
  5. $fid = getPOST("f_id", null, []);
  6. $valid_ids = array_filter(array_map('intval', $fid), fn($id) => $id > 1);
  7. foreach ($valid_ids as $val) {
  8. delete_record($db_link, "building", "id=?", [$val]);
  9. }
  10. header("Location: " . $_SERVER["REQUEST_URI"]);
  11. exit;
  12. }
  13. if (getPOST("save")) {
  14. $r_id = getPOST("r_id",null, []);
  15. $f_building_name = getPOST("f_building_name", null, []);
  16. $f_building_description = getPOST("f_building_description", null, []);
  17. $save_flags = getPOST("save", null, []);
  18. $r_id = array_map('intval', $r_id);
  19. $save_flags = array_map('intval', $save_flags);
  20. foreach ($save_flags as $i => $save_id) {
  21. if ($save_id <= 0) continue;
  22. $found_index = array_search($save_id, $r_id, true);
  23. if ($found_index === false) continue;
  24. $name = trim($f_building_name[$found_index] ?? '');
  25. $description = trim($f_building_description[$found_index] ?? '');
  26. if ($name !== '') {
  27. $new = ['name' => $name, 'description' => $description];
  28. update_record($db_link, "building", "id=?", $new, [$save_id]);
  29. }
  30. }
  31. header("Location: " . $_SERVER["REQUEST_URI"]);
  32. exit;
  33. }
  34. if (getPOST("create")) {
  35. $building_name = trim(getPOST("new_building", null, ''));
  36. if ($building_name !== '') {
  37. $new = ['name' => $building_name];
  38. insert_record($db_link, "building", $new);
  39. }
  40. header("Location: " . $_SERVER["REQUEST_URI"]);
  41. exit;
  42. }
  43. unset($_POST);
  44. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  45. print_control_submenu($page_url);
  46. ?>
  47. <div id="cont">
  48. <form name="def" action="building.php" method="post">
  49. <table class="data">
  50. <tr align="center">
  51. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  52. <td><b>id</b></td>
  53. <td><b><?php echo WEB_cell_name; ?></b></td>
  54. <td><b><?php echo WEB_cell_description; ?></b></td>
  55. <td>
  56. <input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="remove" value="<?php print WEB_btn_remove; ?>">
  57. </td>
  58. </tr>
  59. <?php
  60. $t_building = get_records_sql($db_link,'SELECT * FROM building ORDER BY name');
  61. foreach ($t_building as $row) {
  62. print "<tr align=center>\n";
  63. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  64. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  65. print "<td class=\"data\"><input type=\"text\" name='f_building_name[]' value='{$row['name']}'></td>\n";
  66. print "<td class=\"data\"><input type=\"text\" name='f_building_description[]' value='{$row['description']}'></td>\n";
  67. print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
  68. print "</tr>\n";
  69. }
  70. ?>
  71. </table>
  72. <table>
  73. <tr>
  74. <td><input type=text name=new_building value="Unknown"></td>
  75. <td>
  76. <input type="submit" name="create" value="<?php print WEB_btn_add; ?>">
  77. </td>
  78. <td align="right"></td>
  79. </tr>
  80. </table>
  81. </form>
  82. <?php
  83. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  84. ?>